sal.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. #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/page.h>
  16. #include <asm/sal.h>
  17. #include <asm/pal.h>
  18. __cacheline_aligned DEFINE_SPINLOCK(sal_lock);
  19. unsigned long sal_platform_features;
  20. unsigned short sal_revision;
  21. unsigned short sal_version;
  22. #define SAL_MAJOR(x) ((x) >> 8)
  23. #define SAL_MINOR(x) ((x) & 0xff)
  24. static struct {
  25. void *addr; /* function entry point */
  26. void *gpval; /* gp value to use */
  27. } pdesc;
  28. static long
  29. default_handler (void)
  30. {
  31. return -1;
  32. }
  33. ia64_sal_handler ia64_sal = (ia64_sal_handler) default_handler;
  34. ia64_sal_desc_ptc_t *ia64_ptc_domain_info;
  35. const char *
  36. ia64_sal_strerror (long status)
  37. {
  38. const char *str;
  39. switch (status) {
  40. case 0: str = "Call completed without error"; break;
  41. case 1: str = "Effect a warm boot of the system to complete "
  42. "the update"; break;
  43. case -1: str = "Not implemented"; break;
  44. case -2: str = "Invalid argument"; break;
  45. case -3: str = "Call completed with error"; break;
  46. case -4: str = "Virtual address not registered"; break;
  47. case -5: str = "No information available"; break;
  48. case -6: str = "Insufficient space to add the entry"; break;
  49. case -7: str = "Invalid entry_addr value"; break;
  50. case -8: str = "Invalid interrupt vector"; break;
  51. case -9: str = "Requested memory not available"; break;
  52. case -10: str = "Unable to write to the NVM device"; break;
  53. case -11: str = "Invalid partition type specified"; break;
  54. case -12: str = "Invalid NVM_Object id specified"; break;
  55. case -13: str = "NVM_Object already has the maximum number "
  56. "of partitions"; break;
  57. case -14: str = "Insufficient space in partition for the "
  58. "requested write sub-function"; break;
  59. case -15: str = "Insufficient data buffer space for the "
  60. "requested read record sub-function"; break;
  61. case -16: str = "Scratch buffer required for the write/delete "
  62. "sub-function"; break;
  63. case -17: str = "Insufficient space in the NVM_Object for the "
  64. "requested create sub-function"; break;
  65. case -18: str = "Invalid value specified in the partition_rec "
  66. "argument"; break;
  67. case -19: str = "Record oriented I/O not supported for this "
  68. "partition"; break;
  69. case -20: str = "Bad format of record to be written or "
  70. "required keyword variable not "
  71. "specified"; break;
  72. default: str = "Unknown SAL status code"; break;
  73. }
  74. return str;
  75. }
  76. void __init
  77. ia64_sal_handler_init (void *entry_point, void *gpval)
  78. {
  79. /* fill in the SAL procedure descriptor and point ia64_sal to it: */
  80. pdesc.addr = entry_point;
  81. pdesc.gpval = gpval;
  82. ia64_sal = (ia64_sal_handler) &pdesc;
  83. }
  84. static void __init
  85. check_versions (struct ia64_sal_systab *systab)
  86. {
  87. sal_revision = (systab->sal_rev_major << 8) | systab->sal_rev_minor;
  88. sal_version = (systab->sal_b_rev_major << 8) | systab->sal_b_rev_minor;
  89. /* Check for broken firmware */
  90. if ((sal_revision == SAL_VERSION_CODE(49, 29))
  91. && (sal_version == SAL_VERSION_CODE(49, 29)))
  92. {
  93. /*
  94. * Old firmware for zx2000 prototypes have this weird version number,
  95. * reset it to something sane.
  96. */
  97. sal_revision = SAL_VERSION_CODE(2, 8);
  98. sal_version = SAL_VERSION_CODE(0, 0);
  99. }
  100. }
  101. static void __init
  102. sal_desc_entry_point (void *p)
  103. {
  104. struct ia64_sal_desc_entry_point *ep = p;
  105. ia64_pal_handler_init(__va(ep->pal_proc));
  106. ia64_sal_handler_init(__va(ep->sal_proc), __va(ep->gp));
  107. }
  108. #ifdef CONFIG_SMP
  109. static void __init
  110. set_smp_redirect (int flag)
  111. {
  112. #ifndef CONFIG_HOTPLUG_CPU
  113. if (no_int_routing)
  114. smp_int_redirect &= ~flag;
  115. else
  116. smp_int_redirect |= flag;
  117. #else
  118. /*
  119. * For CPU Hotplug we dont want to do any chipset supported
  120. * interrupt redirection. The reason is this would require that
  121. * All interrupts be stopped and hard bind the irq to a cpu.
  122. * Later when the interrupt is fired we need to set the redir hint
  123. * on again in the vector. This is combersome for something that the
  124. * user mode irq balancer will solve anyways.
  125. */
  126. no_int_routing=1;
  127. smp_int_redirect &= ~flag;
  128. #endif
  129. }
  130. #else
  131. #define set_smp_redirect(flag) do { } while (0)
  132. #endif
  133. static void __init
  134. sal_desc_platform_feature (void *p)
  135. {
  136. struct ia64_sal_desc_platform_feature *pf = p;
  137. sal_platform_features = pf->feature_mask;
  138. printk(KERN_INFO "SAL Platform features:");
  139. if (!sal_platform_features) {
  140. printk(" None\n");
  141. return;
  142. }
  143. if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_BUS_LOCK)
  144. printk(" BusLock");
  145. if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_IRQ_REDIR_HINT) {
  146. printk(" IRQ_Redirection");
  147. set_smp_redirect(SMP_IRQ_REDIRECTION);
  148. }
  149. if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_IPI_REDIR_HINT) {
  150. printk(" IPI_Redirection");
  151. set_smp_redirect(SMP_IPI_REDIRECTION);
  152. }
  153. if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT)
  154. printk(" ITC_Drift");
  155. printk("\n");
  156. }
  157. #ifdef CONFIG_SMP
  158. static void __init
  159. sal_desc_ap_wakeup (void *p)
  160. {
  161. struct ia64_sal_desc_ap_wakeup *ap = p;
  162. switch (ap->mechanism) {
  163. case IA64_SAL_AP_EXTERNAL_INT:
  164. ap_wakeup_vector = ap->vector;
  165. printk(KERN_INFO "SAL: AP wakeup using external interrupt "
  166. "vector 0x%lx\n", ap_wakeup_vector);
  167. break;
  168. default:
  169. printk(KERN_ERR "SAL: AP wakeup mechanism unsupported!\n");
  170. break;
  171. }
  172. }
  173. static void __init
  174. chk_nointroute_opt(void)
  175. {
  176. char *cp;
  177. extern char saved_command_line[];
  178. for (cp = saved_command_line; *cp; ) {
  179. if (memcmp(cp, "nointroute", 10) == 0) {
  180. no_int_routing = 1;
  181. printk ("no_int_routing on\n");
  182. break;
  183. } else {
  184. while (*cp != ' ' && *cp)
  185. ++cp;
  186. while (*cp == ' ')
  187. ++cp;
  188. }
  189. }
  190. }
  191. #else
  192. static void __init sal_desc_ap_wakeup(void *p) { }
  193. #endif
  194. void __init
  195. ia64_sal_init (struct ia64_sal_systab *systab)
  196. {
  197. char *p;
  198. int i;
  199. if (!systab) {
  200. printk(KERN_WARNING "Hmm, no SAL System Table.\n");
  201. return;
  202. }
  203. if (strncmp(systab->signature, "SST_", 4) != 0)
  204. printk(KERN_ERR "bad signature in system table!");
  205. check_versions(systab);
  206. #ifdef CONFIG_SMP
  207. chk_nointroute_opt();
  208. #endif
  209. /* revisions are coded in BCD, so %x does the job for us */
  210. printk(KERN_INFO "SAL %x.%x: %.32s %.32s%sversion %x.%x\n",
  211. SAL_MAJOR(sal_revision), SAL_MINOR(sal_revision),
  212. systab->oem_id, systab->product_id,
  213. systab->product_id[0] ? " " : "",
  214. SAL_MAJOR(sal_version), SAL_MINOR(sal_version));
  215. p = (char *) (systab + 1);
  216. for (i = 0; i < systab->entry_count; i++) {
  217. /*
  218. * The first byte of each entry type contains the type
  219. * descriptor.
  220. */
  221. switch (*p) {
  222. case SAL_DESC_ENTRY_POINT:
  223. sal_desc_entry_point(p);
  224. break;
  225. case SAL_DESC_PLATFORM_FEATURE:
  226. sal_desc_platform_feature(p);
  227. break;
  228. case SAL_DESC_PTC:
  229. ia64_ptc_domain_info = (ia64_sal_desc_ptc_t *)p;
  230. break;
  231. case SAL_DESC_AP_WAKEUP:
  232. sal_desc_ap_wakeup(p);
  233. break;
  234. }
  235. p += SAL_DESC_SIZE(*p);
  236. }
  237. }
  238. int
  239. ia64_sal_oemcall(struct ia64_sal_retval *isrvp, u64 oemfunc, u64 arg1,
  240. u64 arg2, u64 arg3, u64 arg4, u64 arg5, u64 arg6, u64 arg7)
  241. {
  242. if (oemfunc < IA64_SAL_OEMFUNC_MIN || oemfunc > IA64_SAL_OEMFUNC_MAX)
  243. return -1;
  244. SAL_CALL(*isrvp, oemfunc, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
  245. return 0;
  246. }
  247. EXPORT_SYMBOL(ia64_sal_oemcall);
  248. int
  249. ia64_sal_oemcall_nolock(struct ia64_sal_retval *isrvp, u64 oemfunc, u64 arg1,
  250. u64 arg2, u64 arg3, u64 arg4, u64 arg5, u64 arg6,
  251. u64 arg7)
  252. {
  253. if (oemfunc < IA64_SAL_OEMFUNC_MIN || oemfunc > IA64_SAL_OEMFUNC_MAX)
  254. return -1;
  255. SAL_CALL_NOLOCK(*isrvp, oemfunc, arg1, arg2, arg3, arg4, arg5, arg6,
  256. arg7);
  257. return 0;
  258. }
  259. EXPORT_SYMBOL(ia64_sal_oemcall_nolock);
  260. int
  261. ia64_sal_oemcall_reentrant(struct ia64_sal_retval *isrvp, u64 oemfunc,
  262. u64 arg1, u64 arg2, u64 arg3, u64 arg4, u64 arg5,
  263. u64 arg6, u64 arg7)
  264. {
  265. if (oemfunc < IA64_SAL_OEMFUNC_MIN || oemfunc > IA64_SAL_OEMFUNC_MAX)
  266. return -1;
  267. SAL_CALL_REENTRANT(*isrvp, oemfunc, arg1, arg2, arg3, arg4, arg5, arg6,
  268. arg7);
  269. return 0;
  270. }
  271. EXPORT_SYMBOL(ia64_sal_oemcall_reentrant);