blob: 831d57f257db5092ab7cf2622762843d7ae1355c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
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>
15
Bjorn Helgaasa5878692006-01-30 16:32:31 -070016#include <asm/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <asm/page.h>
18#include <asm/sal.h>
19#include <asm/pal.h>
20
21 __cacheline_aligned DEFINE_SPINLOCK(sal_lock);
22unsigned long sal_platform_features;
23
24unsigned short sal_revision;
25unsigned short sal_version;
26
27#define SAL_MAJOR(x) ((x) >> 8)
28#define SAL_MINOR(x) ((x) & 0xff)
29
30static struct {
31 void *addr; /* function entry point */
32 void *gpval; /* gp value to use */
33} pdesc;
34
35static long
36default_handler (void)
37{
38 return -1;
39}
40
41ia64_sal_handler ia64_sal = (ia64_sal_handler) default_handler;
42ia64_sal_desc_ptc_t *ia64_ptc_domain_info;
43
44const char *
45ia64_sal_strerror (long status)
46{
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;
82 }
83 return str;
84}
85
86void __init
87ia64_sal_handler_init (void *entry_point, void *gpval)
88{
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;
93}
94
95static void __init
96check_versions (struct ia64_sal_systab *systab)
97{
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;
100
101 /* Check for broken firmware */
102 if ((sal_revision == SAL_VERSION_CODE(49, 29))
103 && (sal_version == SAL_VERSION_CODE(49, 29)))
104 {
105 /*
106 * Old firmware for zx2000 prototypes have this weird version number,
107 * reset it to something sane.
108 */
109 sal_revision = SAL_VERSION_CODE(2, 8);
110 sal_version = SAL_VERSION_CODE(0, 0);
111 }
112}
113
114static void __init
115sal_desc_entry_point (void *p)
116{
117 struct ia64_sal_desc_entry_point *ep = p;
118 ia64_pal_handler_init(__va(ep->pal_proc));
119 ia64_sal_handler_init(__va(ep->sal_proc), __va(ep->gp));
120}
121
122#ifdef CONFIG_SMP
123static void __init
124set_smp_redirect (int flag)
125{
126#ifndef CONFIG_HOTPLUG_CPU
127 if (no_int_routing)
128 smp_int_redirect &= ~flag;
129 else
130 smp_int_redirect |= flag;
131#else
132 /*
133 * For CPU Hotplug we dont want to do any chipset supported
134 * interrupt redirection. The reason is this would require that
135 * All interrupts be stopped and hard bind the irq to a cpu.
136 * Later when the interrupt is fired we need to set the redir hint
137 * on again in the vector. This is combersome for something that the
138 * user mode irq balancer will solve anyways.
139 */
140 no_int_routing=1;
141 smp_int_redirect &= ~flag;
142#endif
143}
144#else
145#define set_smp_redirect(flag) do { } while (0)
146#endif
147
148static void __init
149sal_desc_platform_feature (void *p)
150{
151 struct ia64_sal_desc_platform_feature *pf = p;
152 sal_platform_features = pf->feature_mask;
153
154 printk(KERN_INFO "SAL Platform features:");
155 if (!sal_platform_features) {
156 printk(" None\n");
157 return;
158 }
159
160 if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_BUS_LOCK)
161 printk(" BusLock");
162 if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_IRQ_REDIR_HINT) {
163 printk(" IRQ_Redirection");
164 set_smp_redirect(SMP_IRQ_REDIRECTION);
165 }
166 if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_IPI_REDIR_HINT) {
167 printk(" IPI_Redirection");
168 set_smp_redirect(SMP_IPI_REDIRECTION);
169 }
170 if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT)
171 printk(" ITC_Drift");
172 printk("\n");
173}
174
175#ifdef CONFIG_SMP
176static void __init
177sal_desc_ap_wakeup (void *p)
178{
179 struct ia64_sal_desc_ap_wakeup *ap = p;
180
181 switch (ap->mechanism) {
182 case IA64_SAL_AP_EXTERNAL_INT:
183 ap_wakeup_vector = ap->vector;
184 printk(KERN_INFO "SAL: AP wakeup using external interrupt "
185 "vector 0x%lx\n", ap_wakeup_vector);
186 break;
187 default:
188 printk(KERN_ERR "SAL: AP wakeup mechanism unsupported!\n");
189 break;
190 }
191}
192
Alon Bar-Leva8d91b82007-02-12 00:54:12 -0800193extern char __initdata boot_command_line[];
194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195static void __init
196chk_nointroute_opt(void)
197{
198 char *cp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Alon Bar-Leva8d91b82007-02-12 00:54:12 -0800200 for (cp = boot_command_line; *cp; ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 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
215static void __init sal_desc_ap_wakeup(void *p) { }
216#endif
217
Bjorn Helgaasa5878692006-01-30 16:32:31 -0700218/*
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 */
225static int sal_cache_flush_drops_interrupts;
226
Troy Heberfa1d19e2006-10-25 14:46:15 -0600227void __init
Bjorn Helgaasa5878692006-01-30 16:32:31 -0700228check_sal_cache_flush (void)
229{
Ian Wienand9ba89332006-06-21 10:33:04 +1000230 unsigned long flags;
Bjorn Helgaasa5878692006-01-30 16:32:31 -0700231 int cpu;
Troy Heberfa1d19e2006-10-25 14:46:15 -0600232 u64 vector, cache_type = 3;
233 struct ia64_sal_retval isrv;
Bjorn Helgaasa5878692006-01-30 16:32:31 -0700234
235 cpu = get_cpu();
236 local_irq_save(flags);
237
238 /*
239 * Schedule a timer interrupt, wait until it's reported, and see if
240 * SAL_CACHE_FLUSH drops it.
241 */
Bjorn Helgaasa5878692006-01-30 16:32:31 -0700242 ia64_set_itv(IA64_TIMER_VECTOR);
243 ia64_set_itm(ia64_get_itc() + 1000);
244
245 while (!ia64_get_irr(IA64_TIMER_VECTOR))
246 cpu_relax();
247
Troy Heberfa1d19e2006-10-25 14:46:15 -0600248 SAL_CALL(isrv, SAL_CACHE_FLUSH, cache_type, 0, 0, 0, 0, 0, 0);
249
250 if (isrv.status)
251 printk(KERN_ERR "SAL_CAL_FLUSH failed with %ld\n", isrv.status);
Bjorn Helgaasa5878692006-01-30 16:32:31 -0700252
253 if (ia64_get_irr(IA64_TIMER_VECTOR)) {
254 vector = ia64_get_ivr();
255 ia64_eoi();
256 WARN_ON(vector != IA64_TIMER_VECTOR);
257 } else {
258 sal_cache_flush_drops_interrupts = 1;
259 printk(KERN_ERR "SAL: SAL_CACHE_FLUSH drops interrupts; "
260 "PAL_CACHE_FLUSH will be used instead\n");
261 ia64_eoi();
262 }
263
Bjorn Helgaasa5878692006-01-30 16:32:31 -0700264 local_irq_restore(flags);
265 put_cpu();
266}
267
268s64
269ia64_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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290void __init
291ia64_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 }
Bjorn Helgaasa5878692006-01-30 16:32:31 -0700338
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339}
340
341int
342ia64_sal_oemcall(struct ia64_sal_retval *isrvp, u64 oemfunc, u64 arg1,
343 u64 arg2, u64 arg3, u64 arg4, u64 arg5, u64 arg6, u64 arg7)
344{
345 if (oemfunc < IA64_SAL_OEMFUNC_MIN || oemfunc > IA64_SAL_OEMFUNC_MAX)
346 return -1;
347 SAL_CALL(*isrvp, oemfunc, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
348 return 0;
349}
350EXPORT_SYMBOL(ia64_sal_oemcall);
351
352int
353ia64_sal_oemcall_nolock(struct ia64_sal_retval *isrvp, u64 oemfunc, u64 arg1,
354 u64 arg2, u64 arg3, u64 arg4, u64 arg5, u64 arg6,
355 u64 arg7)
356{
357 if (oemfunc < IA64_SAL_OEMFUNC_MIN || oemfunc > IA64_SAL_OEMFUNC_MAX)
358 return -1;
359 SAL_CALL_NOLOCK(*isrvp, oemfunc, arg1, arg2, arg3, arg4, arg5, arg6,
360 arg7);
361 return 0;
362}
363EXPORT_SYMBOL(ia64_sal_oemcall_nolock);
364
365int
366ia64_sal_oemcall_reentrant(struct ia64_sal_retval *isrvp, u64 oemfunc,
367 u64 arg1, u64 arg2, u64 arg3, u64 arg4, u64 arg5,
368 u64 arg6, u64 arg7)
369{
370 if (oemfunc < IA64_SAL_OEMFUNC_MIN || oemfunc > IA64_SAL_OEMFUNC_MAX)
371 return -1;
372 SAL_CALL_REENTRANT(*isrvp, oemfunc, arg1, arg2, arg3, arg4, arg5, arg6,
373 arg7);
374 return 0;
375}
376EXPORT_SYMBOL(ia64_sal_oemcall_reentrant);