[IA64] Avoid "u64 foo : 32;" for gcc3 vs. gcc4 compatibility
[linux-2.6] / arch / ia64 / kernel / sal.c
1 /*
2  * System Abstraction Layer (SAL) interface routines.
3  *
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  */
9 #include <linux/config.h>
10
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/module.h>
14 #include <linux/spinlock.h>
15 #include <linux/string.h>
16
17 #include <asm/delay.h>
18 #include <asm/page.h>
19 #include <asm/sal.h>
20 #include <asm/pal.h>
21
22  __cacheline_aligned DEFINE_SPINLOCK(sal_lock);
23 unsigned long sal_platform_features;
24
25 unsigned short sal_revision;
26 unsigned short sal_version;
27
28 #define SAL_MAJOR(x) ((x) >> 8)
29 #define SAL_MINOR(x) ((x) & 0xff)
30
31 static struct {
32         void *addr;     /* function entry point */
33         void *gpval;    /* gp value to use */
34 } pdesc;
35
36 static long
37 default_handler (void)
38 {
39         return -1;
40 }
41
42 ia64_sal_handler ia64_sal = (ia64_sal_handler) default_handler;
43 ia64_sal_desc_ptc_t *ia64_ptc_domain_info;
44
45 const char *
46 ia64_sal_strerror (long status)
47 {
48         const char *str;
49         switch (status) {
50               case 0: str = "Call completed without error"; break;
51               case 1: str = "Effect a warm boot of the system to complete "
52                               "the update"; break;
53               case -1: str = "Not implemented"; break;
54               case -2: str = "Invalid argument"; break;
55               case -3: str = "Call completed with error"; break;
56               case -4: str = "Virtual address not registered"; break;
57               case -5: str = "No information available"; break;
58               case -6: str = "Insufficient space to add the entry"; break;
59               case -7: str = "Invalid entry_addr value"; break;
60               case -8: str = "Invalid interrupt vector"; break;
61               case -9: str = "Requested memory not available"; break;
62               case -10: str = "Unable to write to the NVM device"; break;
63               case -11: str = "Invalid partition type specified"; break;
64               case -12: str = "Invalid NVM_Object id specified"; break;
65               case -13: str = "NVM_Object already has the maximum number "
66                                 "of partitions"; break;
67               case -14: str = "Insufficient space in partition for the "
68                                 "requested write sub-function"; break;
69               case -15: str = "Insufficient data buffer space for the "
70                                 "requested read record sub-function"; break;
71               case -16: str = "Scratch buffer required for the write/delete "
72                                 "sub-function"; break;
73               case -17: str = "Insufficient space in the NVM_Object for the "
74                                 "requested create sub-function"; break;
75               case -18: str = "Invalid value specified in the partition_rec "
76                                 "argument"; break;
77               case -19: str = "Record oriented I/O not supported for this "
78                                 "partition"; break;
79               case -20: str = "Bad format of record to be written or "
80                                 "required keyword variable not "
81                                 "specified"; break;
82               default: str = "Unknown SAL status code"; break;
83         }
84         return str;
85 }
86
87 void __init
88 ia64_sal_handler_init (void *entry_point, void *gpval)
89 {
90         /* fill in the SAL procedure descriptor and point ia64_sal to it: */
91         pdesc.addr = entry_point;
92         pdesc.gpval = gpval;
93         ia64_sal = (ia64_sal_handler) &pdesc;
94 }
95
96 static void __init
97 check_versions (struct ia64_sal_systab *systab)
98 {
99         sal_revision = (systab->sal_rev_major << 8) | systab->sal_rev_minor;
100         sal_version = (systab->sal_b_rev_major << 8) | systab->sal_b_rev_minor;
101
102         /* Check for broken firmware */
103         if ((sal_revision == SAL_VERSION_CODE(49, 29))
104             && (sal_version == SAL_VERSION_CODE(49, 29)))
105         {
106                 /*
107                  * Old firmware for zx2000 prototypes have this weird version number,
108                  * reset it to something sane.
109                  */
110                 sal_revision = SAL_VERSION_CODE(2, 8);
111                 sal_version = SAL_VERSION_CODE(0, 0);
112         }
113 }
114
115 static void __init
116 sal_desc_entry_point (void *p)
117 {
118         struct ia64_sal_desc_entry_point *ep = p;
119         ia64_pal_handler_init(__va(ep->pal_proc));
120         ia64_sal_handler_init(__va(ep->sal_proc), __va(ep->gp));
121 }
122
123 #ifdef CONFIG_SMP
124 static void __init
125 set_smp_redirect (int flag)
126 {
127 #ifndef CONFIG_HOTPLUG_CPU
128         if (no_int_routing)
129                 smp_int_redirect &= ~flag;
130         else
131                 smp_int_redirect |= flag;
132 #else
133         /*
134          * For CPU Hotplug we dont want to do any chipset supported
135          * interrupt redirection. The reason is this would require that
136          * All interrupts be stopped and hard bind the irq to a cpu.
137          * Later when the interrupt is fired we need to set the redir hint
138          * on again in the vector. This is combersome for something that the
139          * user mode irq balancer will solve anyways.
140          */
141         no_int_routing=1;
142         smp_int_redirect &= ~flag;
143 #endif
144 }
145 #else
146 #define set_smp_redirect(flag)  do { } while (0)
147 #endif
148
149 static void __init
150 sal_desc_platform_feature (void *p)
151 {
152         struct ia64_sal_desc_platform_feature *pf = p;
153         sal_platform_features = pf->feature_mask;
154
155         printk(KERN_INFO "SAL Platform features:");
156         if (!sal_platform_features) {
157                 printk(" None\n");
158                 return;
159         }
160
161         if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_BUS_LOCK)
162                 printk(" BusLock");
163         if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_IRQ_REDIR_HINT) {
164                 printk(" IRQ_Redirection");
165                 set_smp_redirect(SMP_IRQ_REDIRECTION);
166         }
167         if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_IPI_REDIR_HINT) {
168                 printk(" IPI_Redirection");
169                 set_smp_redirect(SMP_IPI_REDIRECTION);
170         }
171         if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT)
172                 printk(" ITC_Drift");
173         printk("\n");
174 }
175
176 #ifdef CONFIG_SMP
177 static void __init
178 sal_desc_ap_wakeup (void *p)
179 {
180         struct ia64_sal_desc_ap_wakeup *ap = p;
181
182         switch (ap->mechanism) {
183         case IA64_SAL_AP_EXTERNAL_INT:
184                 ap_wakeup_vector = ap->vector;
185                 printk(KERN_INFO "SAL: AP wakeup using external interrupt "
186                                 "vector 0x%lx\n", ap_wakeup_vector);
187                 break;
188         default:
189                 printk(KERN_ERR "SAL: AP wakeup mechanism unsupported!\n");
190                 break;
191         }
192 }
193
194 static void __init
195 chk_nointroute_opt(void)
196 {
197         char *cp;
198         extern char saved_command_line[];
199
200         for (cp = saved_command_line; *cp; ) {
201                 if (memcmp(cp, "nointroute", 10) == 0) {
202                         no_int_routing = 1;
203                         printk ("no_int_routing on\n");
204                         break;
205                 } else {
206                         while (*cp != ' ' && *cp)
207                                 ++cp;
208                         while (*cp == ' ')
209                                 ++cp;
210                 }
211         }
212 }
213
214 #else
215 static void __init sal_desc_ap_wakeup(void *p) { }
216 #endif
217
218 /*
219  * HP rx5670 firmware polls for interrupts during SAL_CACHE_FLUSH by reading
220  * cr.ivr, but it never writes cr.eoi.  This leaves any interrupt marked as
221  * "in-service" and masks other interrupts of equal or lower priority.
222  *
223  * HP internal defect reports: F1859, F2775, F3031.
224  */
225 static int sal_cache_flush_drops_interrupts;
226
227 static void __init
228 check_sal_cache_flush (void)
229 {
230         unsigned long flags, itv;
231         int cpu;
232         u64 vector;
233
234         cpu = get_cpu();
235         local_irq_save(flags);
236
237         /*
238          * Schedule a timer interrupt, wait until it's reported, and see if
239          * SAL_CACHE_FLUSH drops it.
240          */
241         itv = ia64_get_itv();
242         BUG_ON((itv & (1 << 16)) == 0);
243
244         ia64_set_itv(IA64_TIMER_VECTOR);
245         ia64_set_itm(ia64_get_itc() + 1000);
246
247         while (!ia64_get_irr(IA64_TIMER_VECTOR))
248                 cpu_relax();
249
250         ia64_sal_cache_flush(3);
251
252         if (ia64_get_irr(IA64_TIMER_VECTOR)) {
253                 vector = ia64_get_ivr();
254                 ia64_eoi();
255                 WARN_ON(vector != IA64_TIMER_VECTOR);
256         } else {
257                 sal_cache_flush_drops_interrupts = 1;
258                 printk(KERN_ERR "SAL: SAL_CACHE_FLUSH drops interrupts; "
259                         "PAL_CACHE_FLUSH will be used instead\n");
260                 ia64_eoi();
261         }
262
263         ia64_set_itv(itv);
264         local_irq_restore(flags);
265         put_cpu();
266 }
267
268 s64
269 ia64_sal_cache_flush (u64 cache_type)
270 {
271         struct ia64_sal_retval isrv;
272
273         if (sal_cache_flush_drops_interrupts) {
274                 unsigned long flags;
275                 u64 progress;
276                 s64 rc;
277
278                 progress = 0;
279                 local_irq_save(flags);
280                 rc = ia64_pal_cache_flush(cache_type,
281                         PAL_CACHE_FLUSH_INVALIDATE, &progress, NULL);
282                 local_irq_restore(flags);
283                 return rc;
284         }
285
286         SAL_CALL(isrv, SAL_CACHE_FLUSH, cache_type, 0, 0, 0, 0, 0, 0);
287         return isrv.status;
288 }
289
290 void __init
291 ia64_sal_init (struct ia64_sal_systab *systab)
292 {
293         char *p;
294         int i;
295
296         if (!systab) {
297                 printk(KERN_WARNING "Hmm, no SAL System Table.\n");
298                 return;
299         }
300
301         if (strncmp(systab->signature, "SST_", 4) != 0)
302                 printk(KERN_ERR "bad signature in system table!");
303
304         check_versions(systab);
305 #ifdef CONFIG_SMP
306         chk_nointroute_opt();
307 #endif
308
309         /* revisions are coded in BCD, so %x does the job for us */
310         printk(KERN_INFO "SAL %x.%x: %.32s %.32s%sversion %x.%x\n",
311                         SAL_MAJOR(sal_revision), SAL_MINOR(sal_revision),
312                         systab->oem_id, systab->product_id,
313                         systab->product_id[0] ? " " : "",
314                         SAL_MAJOR(sal_version), SAL_MINOR(sal_version));
315
316         p = (char *) (systab + 1);
317         for (i = 0; i < systab->entry_count; i++) {
318                 /*
319                  * The first byte of each entry type contains the type
320                  * descriptor.
321                  */
322                 switch (*p) {
323                 case SAL_DESC_ENTRY_POINT:
324                         sal_desc_entry_point(p);
325                         break;
326                 case SAL_DESC_PLATFORM_FEATURE:
327                         sal_desc_platform_feature(p);
328                         break;
329                 case SAL_DESC_PTC:
330                         ia64_ptc_domain_info = (ia64_sal_desc_ptc_t *)p;
331                         break;
332                 case SAL_DESC_AP_WAKEUP:
333                         sal_desc_ap_wakeup(p);
334                         break;
335                 }
336                 p += SAL_DESC_SIZE(*p);
337         }
338
339         check_sal_cache_flush();
340 }
341
342 int
343 ia64_sal_oemcall(struct ia64_sal_retval *isrvp, u64 oemfunc, u64 arg1,
344                  u64 arg2, u64 arg3, u64 arg4, u64 arg5, u64 arg6, u64 arg7)
345 {
346         if (oemfunc < IA64_SAL_OEMFUNC_MIN || oemfunc > IA64_SAL_OEMFUNC_MAX)
347                 return -1;
348         SAL_CALL(*isrvp, oemfunc, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
349         return 0;
350 }
351 EXPORT_SYMBOL(ia64_sal_oemcall);
352
353 int
354 ia64_sal_oemcall_nolock(struct ia64_sal_retval *isrvp, u64 oemfunc, u64 arg1,
355                         u64 arg2, u64 arg3, u64 arg4, u64 arg5, u64 arg6,
356                         u64 arg7)
357 {
358         if (oemfunc < IA64_SAL_OEMFUNC_MIN || oemfunc > IA64_SAL_OEMFUNC_MAX)
359                 return -1;
360         SAL_CALL_NOLOCK(*isrvp, oemfunc, arg1, arg2, arg3, arg4, arg5, arg6,
361                         arg7);
362         return 0;
363 }
364 EXPORT_SYMBOL(ia64_sal_oemcall_nolock);
365
366 int
367 ia64_sal_oemcall_reentrant(struct ia64_sal_retval *isrvp, u64 oemfunc,
368                            u64 arg1, u64 arg2, u64 arg3, u64 arg4, u64 arg5,
369                            u64 arg6, u64 arg7)
370 {
371         if (oemfunc < IA64_SAL_OEMFUNC_MIN || oemfunc > IA64_SAL_OEMFUNC_MAX)
372                 return -1;
373         SAL_CALL_REENTRANT(*isrvp, oemfunc, arg1, arg2, arg3, arg4, arg5, arg6,
374                            arg7);
375         return 0;
376 }
377 EXPORT_SYMBOL(ia64_sal_oemcall_reentrant);