sal.c 10 KB

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