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