Linux 2.6.25-rc4
[linux-2.6/next.git] / arch / ia64 / kernel / sal.c
bloba3022dc48ef8432a437256948d5a25080b1cf24d
1 /*
2 * System Abstraction Layer (SAL) interface routines.
4 * Copyright (C) 1998, 1999, 2001, 2003 Hewlett-Packard Co
5 * David Mosberger-Tang <davidm@hpl.hp.com>
6 * Copyright (C) 1999 VA Linux Systems
7 * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
8 */
10 #include <linux/kernel.h>
11 #include <linux/init.h>
12 #include <linux/module.h>
13 #include <linux/spinlock.h>
14 #include <linux/string.h>
16 #include <asm/delay.h>
17 #include <asm/page.h>
18 #include <asm/sal.h>
19 #include <asm/pal.h>
21 __cacheline_aligned DEFINE_SPINLOCK(sal_lock);
22 unsigned long sal_platform_features;
24 unsigned short sal_revision;
25 unsigned short sal_version;
27 #define SAL_MAJOR(x) ((x) >> 8)
28 #define SAL_MINOR(x) ((x) & 0xff)
30 static struct {
31 void *addr; /* function entry point */
32 void *gpval; /* gp value to use */
33 } pdesc;
35 static long
36 default_handler (void)
38 return -1;
41 ia64_sal_handler ia64_sal = (ia64_sal_handler) default_handler;
42 ia64_sal_desc_ptc_t *ia64_ptc_domain_info;
44 const char *
45 ia64_sal_strerror (long status)
47 const char *str;
48 switch (status) {
49 case 0: str = "Call completed without error"; break;
50 case 1: str = "Effect a warm boot of the system to complete "
51 "the update"; break;
52 case -1: str = "Not implemented"; break;
53 case -2: str = "Invalid argument"; break;
54 case -3: str = "Call completed with error"; break;
55 case -4: str = "Virtual address not registered"; break;
56 case -5: str = "No information available"; break;
57 case -6: str = "Insufficient space to add the entry"; break;
58 case -7: str = "Invalid entry_addr value"; break;
59 case -8: str = "Invalid interrupt vector"; break;
60 case -9: str = "Requested memory not available"; break;
61 case -10: str = "Unable to write to the NVM device"; break;
62 case -11: str = "Invalid partition type specified"; break;
63 case -12: str = "Invalid NVM_Object id specified"; break;
64 case -13: str = "NVM_Object already has the maximum number "
65 "of partitions"; break;
66 case -14: str = "Insufficient space in partition for the "
67 "requested write sub-function"; break;
68 case -15: str = "Insufficient data buffer space for the "
69 "requested read record sub-function"; break;
70 case -16: str = "Scratch buffer required for the write/delete "
71 "sub-function"; break;
72 case -17: str = "Insufficient space in the NVM_Object for the "
73 "requested create sub-function"; break;
74 case -18: str = "Invalid value specified in the partition_rec "
75 "argument"; break;
76 case -19: str = "Record oriented I/O not supported for this "
77 "partition"; break;
78 case -20: str = "Bad format of record to be written or "
79 "required keyword variable not "
80 "specified"; break;
81 default: str = "Unknown SAL status code"; break;
83 return str;
86 void __init
87 ia64_sal_handler_init (void *entry_point, void *gpval)
89 /* fill in the SAL procedure descriptor and point ia64_sal to it: */
90 pdesc.addr = entry_point;
91 pdesc.gpval = gpval;
92 ia64_sal = (ia64_sal_handler) &pdesc;
95 static void __init
96 check_versions (struct ia64_sal_systab *systab)
98 sal_revision = (systab->sal_rev_major << 8) | systab->sal_rev_minor;
99 sal_version = (systab->sal_b_rev_major << 8) | systab->sal_b_rev_minor;
101 /* Check for broken firmware */
102 if ((sal_revision == SAL_VERSION_CODE(49, 29))
103 && (sal_version == SAL_VERSION_CODE(49, 29)))
106 * Old firmware for zx2000 prototypes have this weird version number,
107 * reset it to something sane.
109 sal_revision = SAL_VERSION_CODE(2, 8);
110 sal_version = SAL_VERSION_CODE(0, 0);
113 if (ia64_platform_is("sn2") && (sal_revision == SAL_VERSION_CODE(2, 9)))
115 * SGI Altix has hard-coded version 2.9 in their prom
116 * but they actually implement 3.2, so let's fix it here.
118 sal_revision = SAL_VERSION_CODE(3, 2);
121 static void __init
122 sal_desc_entry_point (void *p)
124 struct ia64_sal_desc_entry_point *ep = p;
125 ia64_pal_handler_init(__va(ep->pal_proc));
126 ia64_sal_handler_init(__va(ep->sal_proc), __va(ep->gp));
129 #ifdef CONFIG_SMP
130 static void __init
131 set_smp_redirect (int flag)
133 #ifndef CONFIG_HOTPLUG_CPU
134 if (no_int_routing)
135 smp_int_redirect &= ~flag;
136 else
137 smp_int_redirect |= flag;
138 #else
140 * For CPU Hotplug we dont want to do any chipset supported
141 * interrupt redirection. The reason is this would require that
142 * All interrupts be stopped and hard bind the irq to a cpu.
143 * Later when the interrupt is fired we need to set the redir hint
144 * on again in the vector. This is cumbersome for something that the
145 * user mode irq balancer will solve anyways.
147 no_int_routing=1;
148 smp_int_redirect &= ~flag;
149 #endif
151 #else
152 #define set_smp_redirect(flag) do { } while (0)
153 #endif
155 static void __init
156 sal_desc_platform_feature (void *p)
158 struct ia64_sal_desc_platform_feature *pf = p;
159 sal_platform_features = pf->feature_mask;
161 printk(KERN_INFO "SAL Platform features:");
162 if (!sal_platform_features) {
163 printk(" None\n");
164 return;
167 if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_BUS_LOCK)
168 printk(" BusLock");
169 if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_IRQ_REDIR_HINT) {
170 printk(" IRQ_Redirection");
171 set_smp_redirect(SMP_IRQ_REDIRECTION);
173 if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_IPI_REDIR_HINT) {
174 printk(" IPI_Redirection");
175 set_smp_redirect(SMP_IPI_REDIRECTION);
177 if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT)
178 printk(" ITC_Drift");
179 printk("\n");
182 #ifdef CONFIG_SMP
183 static void __init
184 sal_desc_ap_wakeup (void *p)
186 struct ia64_sal_desc_ap_wakeup *ap = p;
188 switch (ap->mechanism) {
189 case IA64_SAL_AP_EXTERNAL_INT:
190 ap_wakeup_vector = ap->vector;
191 printk(KERN_INFO "SAL: AP wakeup using external interrupt "
192 "vector 0x%lx\n", ap_wakeup_vector);
193 break;
194 default:
195 printk(KERN_ERR "SAL: AP wakeup mechanism unsupported!\n");
196 break;
200 static void __init
201 chk_nointroute_opt(void)
203 char *cp;
205 for (cp = boot_command_line; *cp; ) {
206 if (memcmp(cp, "nointroute", 10) == 0) {
207 no_int_routing = 1;
208 printk ("no_int_routing on\n");
209 break;
210 } else {
211 while (*cp != ' ' && *cp)
212 ++cp;
213 while (*cp == ' ')
214 ++cp;
219 #else
220 static void __init sal_desc_ap_wakeup(void *p) { }
221 #endif
224 * HP rx5670 firmware polls for interrupts during SAL_CACHE_FLUSH by reading
225 * cr.ivr, but it never writes cr.eoi. This leaves any interrupt marked as
226 * "in-service" and masks other interrupts of equal or lower priority.
228 * HP internal defect reports: F1859, F2775, F3031.
230 static int sal_cache_flush_drops_interrupts;
232 void __init
233 check_sal_cache_flush (void)
235 unsigned long flags;
236 int cpu;
237 u64 vector, cache_type = 3;
238 struct ia64_sal_retval isrv;
240 cpu = get_cpu();
241 local_irq_save(flags);
244 * Schedule a timer interrupt, wait until it's reported, and see if
245 * SAL_CACHE_FLUSH drops it.
247 ia64_set_itv(IA64_TIMER_VECTOR);
248 ia64_set_itm(ia64_get_itc() + 1000);
250 while (!ia64_get_irr(IA64_TIMER_VECTOR))
251 cpu_relax();
253 SAL_CALL(isrv, SAL_CACHE_FLUSH, cache_type, 0, 0, 0, 0, 0, 0);
255 if (isrv.status)
256 printk(KERN_ERR "SAL_CAL_FLUSH failed with %ld\n", isrv.status);
258 if (ia64_get_irr(IA64_TIMER_VECTOR)) {
259 vector = ia64_get_ivr();
260 ia64_eoi();
261 WARN_ON(vector != IA64_TIMER_VECTOR);
262 } else {
263 sal_cache_flush_drops_interrupts = 1;
264 printk(KERN_ERR "SAL: SAL_CACHE_FLUSH drops interrupts; "
265 "PAL_CACHE_FLUSH will be used instead\n");
266 ia64_eoi();
269 local_irq_restore(flags);
270 put_cpu();
274 ia64_sal_cache_flush (u64 cache_type)
276 struct ia64_sal_retval isrv;
278 if (sal_cache_flush_drops_interrupts) {
279 unsigned long flags;
280 u64 progress;
281 s64 rc;
283 progress = 0;
284 local_irq_save(flags);
285 rc = ia64_pal_cache_flush(cache_type,
286 PAL_CACHE_FLUSH_INVALIDATE, &progress, NULL);
287 local_irq_restore(flags);
288 return rc;
291 SAL_CALL(isrv, SAL_CACHE_FLUSH, cache_type, 0, 0, 0, 0, 0, 0);
292 return isrv.status;
294 EXPORT_SYMBOL_GPL(ia64_sal_cache_flush);
296 void __init
297 ia64_sal_init (struct ia64_sal_systab *systab)
299 char *p;
300 int i;
302 if (!systab) {
303 printk(KERN_WARNING "Hmm, no SAL System Table.\n");
304 return;
307 if (strncmp(systab->signature, "SST_", 4) != 0)
308 printk(KERN_ERR "bad signature in system table!");
310 check_versions(systab);
311 #ifdef CONFIG_SMP
312 chk_nointroute_opt();
313 #endif
315 /* revisions are coded in BCD, so %x does the job for us */
316 printk(KERN_INFO "SAL %x.%x: %.32s %.32s%sversion %x.%x\n",
317 SAL_MAJOR(sal_revision), SAL_MINOR(sal_revision),
318 systab->oem_id, systab->product_id,
319 systab->product_id[0] ? " " : "",
320 SAL_MAJOR(sal_version), SAL_MINOR(sal_version));
322 p = (char *) (systab + 1);
323 for (i = 0; i < systab->entry_count; i++) {
325 * The first byte of each entry type contains the type
326 * descriptor.
328 switch (*p) {
329 case SAL_DESC_ENTRY_POINT:
330 sal_desc_entry_point(p);
331 break;
332 case SAL_DESC_PLATFORM_FEATURE:
333 sal_desc_platform_feature(p);
334 break;
335 case SAL_DESC_PTC:
336 ia64_ptc_domain_info = (ia64_sal_desc_ptc_t *)p;
337 break;
338 case SAL_DESC_AP_WAKEUP:
339 sal_desc_ap_wakeup(p);
340 break;
342 p += SAL_DESC_SIZE(*p);
348 ia64_sal_oemcall(struct ia64_sal_retval *isrvp, u64 oemfunc, u64 arg1,
349 u64 arg2, u64 arg3, u64 arg4, u64 arg5, u64 arg6, u64 arg7)
351 if (oemfunc < IA64_SAL_OEMFUNC_MIN || oemfunc > IA64_SAL_OEMFUNC_MAX)
352 return -1;
353 SAL_CALL(*isrvp, oemfunc, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
354 return 0;
356 EXPORT_SYMBOL(ia64_sal_oemcall);
359 ia64_sal_oemcall_nolock(struct ia64_sal_retval *isrvp, u64 oemfunc, u64 arg1,
360 u64 arg2, u64 arg3, u64 arg4, u64 arg5, u64 arg6,
361 u64 arg7)
363 if (oemfunc < IA64_SAL_OEMFUNC_MIN || oemfunc > IA64_SAL_OEMFUNC_MAX)
364 return -1;
365 SAL_CALL_NOLOCK(*isrvp, oemfunc, arg1, arg2, arg3, arg4, arg5, arg6,
366 arg7);
367 return 0;
369 EXPORT_SYMBOL(ia64_sal_oemcall_nolock);
372 ia64_sal_oemcall_reentrant(struct ia64_sal_retval *isrvp, u64 oemfunc,
373 u64 arg1, u64 arg2, u64 arg3, u64 arg4, u64 arg5,
374 u64 arg6, u64 arg7)
376 if (oemfunc < IA64_SAL_OEMFUNC_MIN || oemfunc > IA64_SAL_OEMFUNC_MAX)
377 return -1;
378 SAL_CALL_REENTRANT(*isrvp, oemfunc, arg1, arg2, arg3, arg4, arg5, arg6,
379 arg7);
380 return 0;
382 EXPORT_SYMBOL(ia64_sal_oemcall_reentrant);
384 long
385 ia64_sal_freq_base (unsigned long which, unsigned long *ticks_per_second,
386 unsigned long *drift_info)
388 struct ia64_sal_retval isrv;
390 SAL_CALL(isrv, SAL_FREQ_BASE, which, 0, 0, 0, 0, 0, 0);
391 *ticks_per_second = isrv.v0;
392 *drift_info = isrv.v1;
393 return isrv.status;
395 EXPORT_SYMBOL_GPL(ia64_sal_freq_base);