sn_sal.h 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108
  1. #ifndef _ASM_IA64_SN_SN_SAL_H
  2. #define _ASM_IA64_SN_SN_SAL_H
  3. /*
  4. * System Abstraction Layer definitions for IA64
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. *
  10. * Copyright (c) 2000-2005 Silicon Graphics, Inc. All rights reserved.
  11. */
  12. #include <linux/config.h>
  13. #include <asm/sal.h>
  14. #include <asm/sn/sn_cpuid.h>
  15. #include <asm/sn/arch.h>
  16. #include <asm/sn/geo.h>
  17. #include <asm/sn/nodepda.h>
  18. #include <asm/sn/shub_mmr.h>
  19. // SGI Specific Calls
  20. #define SN_SAL_POD_MODE 0x02000001
  21. #define SN_SAL_SYSTEM_RESET 0x02000002
  22. #define SN_SAL_PROBE 0x02000003
  23. #define SN_SAL_GET_MASTER_NASID 0x02000004
  24. #define SN_SAL_GET_KLCONFIG_ADDR 0x02000005
  25. #define SN_SAL_LOG_CE 0x02000006
  26. #define SN_SAL_REGISTER_CE 0x02000007
  27. #define SN_SAL_GET_PARTITION_ADDR 0x02000009
  28. #define SN_SAL_XP_ADDR_REGION 0x0200000f
  29. #define SN_SAL_NO_FAULT_ZONE_VIRTUAL 0x02000010
  30. #define SN_SAL_NO_FAULT_ZONE_PHYSICAL 0x02000011
  31. #define SN_SAL_PRINT_ERROR 0x02000012
  32. #define SN_SAL_SET_ERROR_HANDLING_FEATURES 0x0200001a // reentrant
  33. #define SN_SAL_GET_FIT_COMPT 0x0200001b // reentrant
  34. #define SN_SAL_GET_SAPIC_INFO 0x0200001d
  35. #define SN_SAL_GET_SN_INFO 0x0200001e
  36. #define SN_SAL_CONSOLE_PUTC 0x02000021
  37. #define SN_SAL_CONSOLE_GETC 0x02000022
  38. #define SN_SAL_CONSOLE_PUTS 0x02000023
  39. #define SN_SAL_CONSOLE_GETS 0x02000024
  40. #define SN_SAL_CONSOLE_GETS_TIMEOUT 0x02000025
  41. #define SN_SAL_CONSOLE_POLL 0x02000026
  42. #define SN_SAL_CONSOLE_INTR 0x02000027
  43. #define SN_SAL_CONSOLE_PUTB 0x02000028
  44. #define SN_SAL_CONSOLE_XMIT_CHARS 0x0200002a
  45. #define SN_SAL_CONSOLE_READC 0x0200002b
  46. #define SN_SAL_SYSCTL_MODID_GET 0x02000031
  47. #define SN_SAL_SYSCTL_GET 0x02000032
  48. #define SN_SAL_SYSCTL_IOBRICK_MODULE_GET 0x02000033
  49. #define SN_SAL_SYSCTL_IO_PORTSPEED_GET 0x02000035
  50. #define SN_SAL_SYSCTL_SLAB_GET 0x02000036
  51. #define SN_SAL_BUS_CONFIG 0x02000037
  52. #define SN_SAL_SYS_SERIAL_GET 0x02000038
  53. #define SN_SAL_PARTITION_SERIAL_GET 0x02000039
  54. #define SN_SAL_SYSCTL_PARTITION_GET 0x0200003a
  55. #define SN_SAL_SYSTEM_POWER_DOWN 0x0200003b
  56. #define SN_SAL_GET_MASTER_BASEIO_NASID 0x0200003c
  57. #define SN_SAL_COHERENCE 0x0200003d
  58. #define SN_SAL_MEMPROTECT 0x0200003e
  59. #define SN_SAL_SYSCTL_FRU_CAPTURE 0x0200003f
  60. #define SN_SAL_SYSCTL_IOBRICK_PCI_OP 0x02000042 // reentrant
  61. #define SN_SAL_IROUTER_OP 0x02000043
  62. #define SN_SAL_SYSCTL_EVENT 0x02000044
  63. #define SN_SAL_IOIF_INTERRUPT 0x0200004a
  64. #define SN_SAL_HWPERF_OP 0x02000050 // lock
  65. #define SN_SAL_IOIF_ERROR_INTERRUPT 0x02000051
  66. #define SN_SAL_IOIF_SLOT_ENABLE 0x02000053
  67. #define SN_SAL_IOIF_SLOT_DISABLE 0x02000054
  68. #define SN_SAL_IOIF_GET_HUBDEV_INFO 0x02000055
  69. #define SN_SAL_IOIF_GET_PCIBUS_INFO 0x02000056
  70. #define SN_SAL_IOIF_GET_PCIDEV_INFO 0x02000057
  71. #define SN_SAL_IOIF_GET_WIDGET_DMAFLUSH_LIST 0x02000058
  72. #define SN_SAL_HUB_ERROR_INTERRUPT 0x02000060
  73. #define SN_SAL_BTE_RECOVER 0x02000061
  74. #define SN_SAL_IOIF_GET_PCI_TOPOLOGY 0x02000062
  75. /*
  76. * Service-specific constants
  77. */
  78. /* Console interrupt manipulation */
  79. /* action codes */
  80. #define SAL_CONSOLE_INTR_OFF 0 /* turn the interrupt off */
  81. #define SAL_CONSOLE_INTR_ON 1 /* turn the interrupt on */
  82. #define SAL_CONSOLE_INTR_STATUS 2 /* retrieve the interrupt status */
  83. /* interrupt specification & status return codes */
  84. #define SAL_CONSOLE_INTR_XMIT 1 /* output interrupt */
  85. #define SAL_CONSOLE_INTR_RECV 2 /* input interrupt */
  86. /* interrupt handling */
  87. #define SAL_INTR_ALLOC 1
  88. #define SAL_INTR_FREE 2
  89. /*
  90. * IRouter (i.e. generalized system controller) operations
  91. */
  92. #define SAL_IROUTER_OPEN 0 /* open a subchannel */
  93. #define SAL_IROUTER_CLOSE 1 /* close a subchannel */
  94. #define SAL_IROUTER_SEND 2 /* send part of an IRouter packet */
  95. #define SAL_IROUTER_RECV 3 /* receive part of an IRouter packet */
  96. #define SAL_IROUTER_INTR_STATUS 4 /* check the interrupt status for
  97. * an open subchannel
  98. */
  99. #define SAL_IROUTER_INTR_ON 5 /* enable an interrupt */
  100. #define SAL_IROUTER_INTR_OFF 6 /* disable an interrupt */
  101. #define SAL_IROUTER_INIT 7 /* initialize IRouter driver */
  102. /* IRouter interrupt mask bits */
  103. #define SAL_IROUTER_INTR_XMIT SAL_CONSOLE_INTR_XMIT
  104. #define SAL_IROUTER_INTR_RECV SAL_CONSOLE_INTR_RECV
  105. /*
  106. * Error Handling Features
  107. */
  108. #define SAL_ERR_FEAT_MCA_SLV_TO_OS_INIT_SLV 0x1
  109. #define SAL_ERR_FEAT_LOG_SBES 0x2
  110. #define SAL_ERR_FEAT_MFR_OVERRIDE 0x4
  111. #define SAL_ERR_FEAT_SBE_THRESHOLD 0xffff0000
  112. /*
  113. * SAL Error Codes
  114. */
  115. #define SALRET_MORE_PASSES 1
  116. #define SALRET_OK 0
  117. #define SALRET_NOT_IMPLEMENTED (-1)
  118. #define SALRET_INVALID_ARG (-2)
  119. #define SALRET_ERROR (-3)
  120. /**
  121. * sn_sal_rev_major - get the major SGI SAL revision number
  122. *
  123. * The SGI PROM stores its version in sal_[ab]_rev_(major|minor).
  124. * This routine simply extracts the major value from the
  125. * @ia64_sal_systab structure constructed by ia64_sal_init().
  126. */
  127. static inline int
  128. sn_sal_rev_major(void)
  129. {
  130. struct ia64_sal_systab *systab = efi.sal_systab;
  131. return (int)systab->sal_b_rev_major;
  132. }
  133. /**
  134. * sn_sal_rev_minor - get the minor SGI SAL revision number
  135. *
  136. * The SGI PROM stores its version in sal_[ab]_rev_(major|minor).
  137. * This routine simply extracts the minor value from the
  138. * @ia64_sal_systab structure constructed by ia64_sal_init().
  139. */
  140. static inline int
  141. sn_sal_rev_minor(void)
  142. {
  143. struct ia64_sal_systab *systab = efi.sal_systab;
  144. return (int)systab->sal_b_rev_minor;
  145. }
  146. /*
  147. * Specify the minimum PROM revsion required for this kernel.
  148. * Note that they're stored in hex format...
  149. */
  150. #define SN_SAL_MIN_MAJOR 0x4 /* SN2 kernels need at least PROM 4.0 */
  151. #define SN_SAL_MIN_MINOR 0x0
  152. /*
  153. * Returns the master console nasid, if the call fails, return an illegal
  154. * value.
  155. */
  156. static inline u64
  157. ia64_sn_get_console_nasid(void)
  158. {
  159. struct ia64_sal_retval ret_stuff;
  160. ret_stuff.status = 0;
  161. ret_stuff.v0 = 0;
  162. ret_stuff.v1 = 0;
  163. ret_stuff.v2 = 0;
  164. SAL_CALL(ret_stuff, SN_SAL_GET_MASTER_NASID, 0, 0, 0, 0, 0, 0, 0);
  165. if (ret_stuff.status < 0)
  166. return ret_stuff.status;
  167. /* Master console nasid is in 'v0' */
  168. return ret_stuff.v0;
  169. }
  170. /*
  171. * Returns the master baseio nasid, if the call fails, return an illegal
  172. * value.
  173. */
  174. static inline u64
  175. ia64_sn_get_master_baseio_nasid(void)
  176. {
  177. struct ia64_sal_retval ret_stuff;
  178. ret_stuff.status = 0;
  179. ret_stuff.v0 = 0;
  180. ret_stuff.v1 = 0;
  181. ret_stuff.v2 = 0;
  182. SAL_CALL(ret_stuff, SN_SAL_GET_MASTER_BASEIO_NASID, 0, 0, 0, 0, 0, 0, 0);
  183. if (ret_stuff.status < 0)
  184. return ret_stuff.status;
  185. /* Master baseio nasid is in 'v0' */
  186. return ret_stuff.v0;
  187. }
  188. static inline char *
  189. ia64_sn_get_klconfig_addr(nasid_t nasid)
  190. {
  191. struct ia64_sal_retval ret_stuff;
  192. int cnodeid;
  193. cnodeid = nasid_to_cnodeid(nasid);
  194. ret_stuff.status = 0;
  195. ret_stuff.v0 = 0;
  196. ret_stuff.v1 = 0;
  197. ret_stuff.v2 = 0;
  198. SAL_CALL(ret_stuff, SN_SAL_GET_KLCONFIG_ADDR, (u64)nasid, 0, 0, 0, 0, 0, 0);
  199. /*
  200. * We should panic if a valid cnode nasid does not produce
  201. * a klconfig address.
  202. */
  203. if (ret_stuff.status != 0) {
  204. panic("ia64_sn_get_klconfig_addr: Returned error %lx\n", ret_stuff.status);
  205. }
  206. return ret_stuff.v0 ? __va(ret_stuff.v0) : NULL;
  207. }
  208. /*
  209. * Returns the next console character.
  210. */
  211. static inline u64
  212. ia64_sn_console_getc(int *ch)
  213. {
  214. struct ia64_sal_retval ret_stuff;
  215. ret_stuff.status = 0;
  216. ret_stuff.v0 = 0;
  217. ret_stuff.v1 = 0;
  218. ret_stuff.v2 = 0;
  219. SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_GETC, 0, 0, 0, 0, 0, 0, 0);
  220. /* character is in 'v0' */
  221. *ch = (int)ret_stuff.v0;
  222. return ret_stuff.status;
  223. }
  224. /*
  225. * Read a character from the SAL console device, after a previous interrupt
  226. * or poll operation has given us to know that a character is available
  227. * to be read.
  228. */
  229. static inline u64
  230. ia64_sn_console_readc(void)
  231. {
  232. struct ia64_sal_retval ret_stuff;
  233. ret_stuff.status = 0;
  234. ret_stuff.v0 = 0;
  235. ret_stuff.v1 = 0;
  236. ret_stuff.v2 = 0;
  237. SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_READC, 0, 0, 0, 0, 0, 0, 0);
  238. /* character is in 'v0' */
  239. return ret_stuff.v0;
  240. }
  241. /*
  242. * Sends the given character to the console.
  243. */
  244. static inline u64
  245. ia64_sn_console_putc(char ch)
  246. {
  247. struct ia64_sal_retval ret_stuff;
  248. ret_stuff.status = 0;
  249. ret_stuff.v0 = 0;
  250. ret_stuff.v1 = 0;
  251. ret_stuff.v2 = 0;
  252. SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_PUTC, (uint64_t)ch, 0, 0, 0, 0, 0, 0);
  253. return ret_stuff.status;
  254. }
  255. /*
  256. * Sends the given buffer to the console.
  257. */
  258. static inline u64
  259. ia64_sn_console_putb(const char *buf, int len)
  260. {
  261. struct ia64_sal_retval ret_stuff;
  262. ret_stuff.status = 0;
  263. ret_stuff.v0 = 0;
  264. ret_stuff.v1 = 0;
  265. ret_stuff.v2 = 0;
  266. SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_PUTB, (uint64_t)buf, (uint64_t)len, 0, 0, 0, 0, 0);
  267. if ( ret_stuff.status == 0 ) {
  268. return ret_stuff.v0;
  269. }
  270. return (u64)0;
  271. }
  272. /*
  273. * Print a platform error record
  274. */
  275. static inline u64
  276. ia64_sn_plat_specific_err_print(int (*hook)(const char*, ...), char *rec)
  277. {
  278. struct ia64_sal_retval ret_stuff;
  279. ret_stuff.status = 0;
  280. ret_stuff.v0 = 0;
  281. ret_stuff.v1 = 0;
  282. ret_stuff.v2 = 0;
  283. SAL_CALL_REENTRANT(ret_stuff, SN_SAL_PRINT_ERROR, (uint64_t)hook, (uint64_t)rec, 0, 0, 0, 0, 0);
  284. return ret_stuff.status;
  285. }
  286. /*
  287. * Check for Platform errors
  288. */
  289. static inline u64
  290. ia64_sn_plat_cpei_handler(void)
  291. {
  292. struct ia64_sal_retval ret_stuff;
  293. ret_stuff.status = 0;
  294. ret_stuff.v0 = 0;
  295. ret_stuff.v1 = 0;
  296. ret_stuff.v2 = 0;
  297. SAL_CALL_NOLOCK(ret_stuff, SN_SAL_LOG_CE, 0, 0, 0, 0, 0, 0, 0);
  298. return ret_stuff.status;
  299. }
  300. /*
  301. * Set Error Handling Features
  302. */
  303. static inline u64
  304. ia64_sn_plat_set_error_handling_features(void)
  305. {
  306. struct ia64_sal_retval ret_stuff;
  307. ret_stuff.status = 0;
  308. ret_stuff.v0 = 0;
  309. ret_stuff.v1 = 0;
  310. ret_stuff.v2 = 0;
  311. SAL_CALL_REENTRANT(ret_stuff, SN_SAL_SET_ERROR_HANDLING_FEATURES,
  312. (SAL_ERR_FEAT_MCA_SLV_TO_OS_INIT_SLV | SAL_ERR_FEAT_LOG_SBES),
  313. 0, 0, 0, 0, 0, 0);
  314. return ret_stuff.status;
  315. }
  316. /*
  317. * Checks for console input.
  318. */
  319. static inline u64
  320. ia64_sn_console_check(int *result)
  321. {
  322. struct ia64_sal_retval ret_stuff;
  323. ret_stuff.status = 0;
  324. ret_stuff.v0 = 0;
  325. ret_stuff.v1 = 0;
  326. ret_stuff.v2 = 0;
  327. SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_POLL, 0, 0, 0, 0, 0, 0, 0);
  328. /* result is in 'v0' */
  329. *result = (int)ret_stuff.v0;
  330. return ret_stuff.status;
  331. }
  332. /*
  333. * Checks console interrupt status
  334. */
  335. static inline u64
  336. ia64_sn_console_intr_status(void)
  337. {
  338. struct ia64_sal_retval ret_stuff;
  339. ret_stuff.status = 0;
  340. ret_stuff.v0 = 0;
  341. ret_stuff.v1 = 0;
  342. ret_stuff.v2 = 0;
  343. SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_INTR,
  344. 0, SAL_CONSOLE_INTR_STATUS,
  345. 0, 0, 0, 0, 0);
  346. if (ret_stuff.status == 0) {
  347. return ret_stuff.v0;
  348. }
  349. return 0;
  350. }
  351. /*
  352. * Enable an interrupt on the SAL console device.
  353. */
  354. static inline void
  355. ia64_sn_console_intr_enable(uint64_t intr)
  356. {
  357. struct ia64_sal_retval ret_stuff;
  358. ret_stuff.status = 0;
  359. ret_stuff.v0 = 0;
  360. ret_stuff.v1 = 0;
  361. ret_stuff.v2 = 0;
  362. SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_INTR,
  363. intr, SAL_CONSOLE_INTR_ON,
  364. 0, 0, 0, 0, 0);
  365. }
  366. /*
  367. * Disable an interrupt on the SAL console device.
  368. */
  369. static inline void
  370. ia64_sn_console_intr_disable(uint64_t intr)
  371. {
  372. struct ia64_sal_retval ret_stuff;
  373. ret_stuff.status = 0;
  374. ret_stuff.v0 = 0;
  375. ret_stuff.v1 = 0;
  376. ret_stuff.v2 = 0;
  377. SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_INTR,
  378. intr, SAL_CONSOLE_INTR_OFF,
  379. 0, 0, 0, 0, 0);
  380. }
  381. /*
  382. * Sends a character buffer to the console asynchronously.
  383. */
  384. static inline u64
  385. ia64_sn_console_xmit_chars(char *buf, int len)
  386. {
  387. struct ia64_sal_retval ret_stuff;
  388. ret_stuff.status = 0;
  389. ret_stuff.v0 = 0;
  390. ret_stuff.v1 = 0;
  391. ret_stuff.v2 = 0;
  392. SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_XMIT_CHARS,
  393. (uint64_t)buf, (uint64_t)len,
  394. 0, 0, 0, 0, 0);
  395. if (ret_stuff.status == 0) {
  396. return ret_stuff.v0;
  397. }
  398. return 0;
  399. }
  400. /*
  401. * Returns the iobrick module Id
  402. */
  403. static inline u64
  404. ia64_sn_sysctl_iobrick_module_get(nasid_t nasid, int *result)
  405. {
  406. struct ia64_sal_retval ret_stuff;
  407. ret_stuff.status = 0;
  408. ret_stuff.v0 = 0;
  409. ret_stuff.v1 = 0;
  410. ret_stuff.v2 = 0;
  411. SAL_CALL_NOLOCK(ret_stuff, SN_SAL_SYSCTL_IOBRICK_MODULE_GET, nasid, 0, 0, 0, 0, 0, 0);
  412. /* result is in 'v0' */
  413. *result = (int)ret_stuff.v0;
  414. return ret_stuff.status;
  415. }
  416. /**
  417. * ia64_sn_pod_mode - call the SN_SAL_POD_MODE function
  418. *
  419. * SN_SAL_POD_MODE actually takes an argument, but it's always
  420. * 0 when we call it from the kernel, so we don't have to expose
  421. * it to the caller.
  422. */
  423. static inline u64
  424. ia64_sn_pod_mode(void)
  425. {
  426. struct ia64_sal_retval isrv;
  427. SAL_CALL_REENTRANT(isrv, SN_SAL_POD_MODE, 0, 0, 0, 0, 0, 0, 0);
  428. if (isrv.status)
  429. return 0;
  430. return isrv.v0;
  431. }
  432. /**
  433. * ia64_sn_probe_mem - read from memory safely
  434. * @addr: address to probe
  435. * @size: number bytes to read (1,2,4,8)
  436. * @data_ptr: address to store value read by probe (-1 returned if probe fails)
  437. *
  438. * Call into the SAL to do a memory read. If the read generates a machine
  439. * check, this routine will recover gracefully and return -1 to the caller.
  440. * @addr is usually a kernel virtual address in uncached space (i.e. the
  441. * address starts with 0xc), but if called in physical mode, @addr should
  442. * be a physical address.
  443. *
  444. * Return values:
  445. * 0 - probe successful
  446. * 1 - probe failed (generated MCA)
  447. * 2 - Bad arg
  448. * <0 - PAL error
  449. */
  450. static inline u64
  451. ia64_sn_probe_mem(long addr, long size, void *data_ptr)
  452. {
  453. struct ia64_sal_retval isrv;
  454. SAL_CALL(isrv, SN_SAL_PROBE, addr, size, 0, 0, 0, 0, 0);
  455. if (data_ptr) {
  456. switch (size) {
  457. case 1:
  458. *((u8*)data_ptr) = (u8)isrv.v0;
  459. break;
  460. case 2:
  461. *((u16*)data_ptr) = (u16)isrv.v0;
  462. break;
  463. case 4:
  464. *((u32*)data_ptr) = (u32)isrv.v0;
  465. break;
  466. case 8:
  467. *((u64*)data_ptr) = (u64)isrv.v0;
  468. break;
  469. default:
  470. isrv.status = 2;
  471. }
  472. }
  473. return isrv.status;
  474. }
  475. /*
  476. * Retrieve the system serial number as an ASCII string.
  477. */
  478. static inline u64
  479. ia64_sn_sys_serial_get(char *buf)
  480. {
  481. struct ia64_sal_retval ret_stuff;
  482. SAL_CALL_NOLOCK(ret_stuff, SN_SAL_SYS_SERIAL_GET, buf, 0, 0, 0, 0, 0, 0);
  483. return ret_stuff.status;
  484. }
  485. extern char sn_system_serial_number_string[];
  486. extern u64 sn_partition_serial_number;
  487. static inline char *
  488. sn_system_serial_number(void) {
  489. if (sn_system_serial_number_string[0]) {
  490. return(sn_system_serial_number_string);
  491. } else {
  492. ia64_sn_sys_serial_get(sn_system_serial_number_string);
  493. return(sn_system_serial_number_string);
  494. }
  495. }
  496. /*
  497. * Returns a unique id number for this system and partition (suitable for
  498. * use with license managers), based in part on the system serial number.
  499. */
  500. static inline u64
  501. ia64_sn_partition_serial_get(void)
  502. {
  503. struct ia64_sal_retval ret_stuff;
  504. ia64_sal_oemcall_reentrant(&ret_stuff, SN_SAL_PARTITION_SERIAL_GET, 0,
  505. 0, 0, 0, 0, 0, 0);
  506. if (ret_stuff.status != 0)
  507. return 0;
  508. return ret_stuff.v0;
  509. }
  510. static inline u64
  511. sn_partition_serial_number_val(void) {
  512. if (unlikely(sn_partition_serial_number == 0)) {
  513. sn_partition_serial_number = ia64_sn_partition_serial_get();
  514. }
  515. return sn_partition_serial_number;
  516. }
  517. /*
  518. * Returns the partition id of the nasid passed in as an argument,
  519. * or INVALID_PARTID if the partition id cannot be retrieved.
  520. */
  521. static inline partid_t
  522. ia64_sn_sysctl_partition_get(nasid_t nasid)
  523. {
  524. struct ia64_sal_retval ret_stuff;
  525. ia64_sal_oemcall_nolock(&ret_stuff, SN_SAL_SYSCTL_PARTITION_GET, nasid,
  526. 0, 0, 0, 0, 0, 0);
  527. if (ret_stuff.status != 0)
  528. return INVALID_PARTID;
  529. return ((partid_t)ret_stuff.v0);
  530. }
  531. /*
  532. * Returns the partition id of the current processor.
  533. */
  534. extern partid_t sn_partid;
  535. static inline partid_t
  536. sn_local_partid(void) {
  537. if (unlikely(sn_partid < 0)) {
  538. sn_partid = ia64_sn_sysctl_partition_get(cpuid_to_nasid(smp_processor_id()));
  539. }
  540. return sn_partid;
  541. }
  542. /*
  543. * Returns the physical address of the partition's reserved page through
  544. * an iterative number of calls.
  545. *
  546. * On first call, 'cookie' and 'len' should be set to 0, and 'addr'
  547. * set to the nasid of the partition whose reserved page's address is
  548. * being sought.
  549. * On subsequent calls, pass the values, that were passed back on the
  550. * previous call.
  551. *
  552. * While the return status equals SALRET_MORE_PASSES, keep calling
  553. * this function after first copying 'len' bytes starting at 'addr'
  554. * into 'buf'. Once the return status equals SALRET_OK, 'addr' will
  555. * be the physical address of the partition's reserved page. If the
  556. * return status equals neither of these, an error as occurred.
  557. */
  558. static inline s64
  559. sn_partition_reserved_page_pa(u64 buf, u64 *cookie, u64 *addr, u64 *len)
  560. {
  561. struct ia64_sal_retval rv;
  562. ia64_sal_oemcall_reentrant(&rv, SN_SAL_GET_PARTITION_ADDR, *cookie,
  563. *addr, buf, *len, 0, 0, 0);
  564. *cookie = rv.v0;
  565. *addr = rv.v1;
  566. *len = rv.v2;
  567. return rv.status;
  568. }
  569. /*
  570. * Register or unregister a physical address range being referenced across
  571. * a partition boundary for which certain SAL errors should be scanned for,
  572. * cleaned up and ignored. This is of value for kernel partitioning code only.
  573. * Values for the operation argument:
  574. * 1 = register this address range with SAL
  575. * 0 = unregister this address range with SAL
  576. *
  577. * SAL maintains a reference count on an address range in case it is registered
  578. * multiple times.
  579. *
  580. * On success, returns the reference count of the address range after the SAL
  581. * call has performed the current registration/unregistration. Returns a
  582. * negative value if an error occurred.
  583. */
  584. static inline int
  585. sn_register_xp_addr_region(u64 paddr, u64 len, int operation)
  586. {
  587. struct ia64_sal_retval ret_stuff;
  588. ia64_sal_oemcall(&ret_stuff, SN_SAL_XP_ADDR_REGION, paddr, len,
  589. (u64)operation, 0, 0, 0, 0);
  590. return ret_stuff.status;
  591. }
  592. /*
  593. * Register or unregister an instruction range for which SAL errors should
  594. * be ignored. If an error occurs while in the registered range, SAL jumps
  595. * to return_addr after ignoring the error. Values for the operation argument:
  596. * 1 = register this instruction range with SAL
  597. * 0 = unregister this instruction range with SAL
  598. *
  599. * Returns 0 on success, or a negative value if an error occurred.
  600. */
  601. static inline int
  602. sn_register_nofault_code(u64 start_addr, u64 end_addr, u64 return_addr,
  603. int virtual, int operation)
  604. {
  605. struct ia64_sal_retval ret_stuff;
  606. u64 call;
  607. if (virtual) {
  608. call = SN_SAL_NO_FAULT_ZONE_VIRTUAL;
  609. } else {
  610. call = SN_SAL_NO_FAULT_ZONE_PHYSICAL;
  611. }
  612. ia64_sal_oemcall(&ret_stuff, call, start_addr, end_addr, return_addr,
  613. (u64)1, 0, 0, 0);
  614. return ret_stuff.status;
  615. }
  616. /*
  617. * Change or query the coherence domain for this partition. Each cpu-based
  618. * nasid is represented by a bit in an array of 64-bit words:
  619. * 0 = not in this partition's coherency domain
  620. * 1 = in this partition's coherency domain
  621. *
  622. * It is not possible for the local system's nasids to be removed from
  623. * the coherency domain. Purpose of the domain arguments:
  624. * new_domain = set the coherence domain to the given nasids
  625. * old_domain = return the current coherence domain
  626. *
  627. * Returns 0 on success, or a negative value if an error occurred.
  628. */
  629. static inline int
  630. sn_change_coherence(u64 *new_domain, u64 *old_domain)
  631. {
  632. struct ia64_sal_retval ret_stuff;
  633. ia64_sal_oemcall(&ret_stuff, SN_SAL_COHERENCE, (u64)new_domain,
  634. (u64)old_domain, 0, 0, 0, 0, 0);
  635. return ret_stuff.status;
  636. }
  637. /*
  638. * Change memory access protections for a physical address range.
  639. * nasid_array is not used on Altix, but may be in future architectures.
  640. * Available memory protection access classes are defined after the function.
  641. */
  642. static inline int
  643. sn_change_memprotect(u64 paddr, u64 len, u64 perms, u64 *nasid_array)
  644. {
  645. struct ia64_sal_retval ret_stuff;
  646. int cnodeid;
  647. unsigned long irq_flags;
  648. cnodeid = nasid_to_cnodeid(get_node_number(paddr));
  649. // spin_lock(&NODEPDA(cnodeid)->bist_lock);
  650. local_irq_save(irq_flags);
  651. ia64_sal_oemcall_nolock(&ret_stuff, SN_SAL_MEMPROTECT, paddr, len,
  652. (u64)nasid_array, perms, 0, 0, 0);
  653. local_irq_restore(irq_flags);
  654. // spin_unlock(&NODEPDA(cnodeid)->bist_lock);
  655. return ret_stuff.status;
  656. }
  657. #define SN_MEMPROT_ACCESS_CLASS_0 0x14a080
  658. #define SN_MEMPROT_ACCESS_CLASS_1 0x2520c2
  659. #define SN_MEMPROT_ACCESS_CLASS_2 0x14a1ca
  660. #define SN_MEMPROT_ACCESS_CLASS_3 0x14a290
  661. #define SN_MEMPROT_ACCESS_CLASS_6 0x084080
  662. #define SN_MEMPROT_ACCESS_CLASS_7 0x021080
  663. /*
  664. * Turns off system power.
  665. */
  666. static inline void
  667. ia64_sn_power_down(void)
  668. {
  669. struct ia64_sal_retval ret_stuff;
  670. SAL_CALL(ret_stuff, SN_SAL_SYSTEM_POWER_DOWN, 0, 0, 0, 0, 0, 0, 0);
  671. while(1);
  672. /* never returns */
  673. }
  674. /**
  675. * ia64_sn_fru_capture - tell the system controller to capture hw state
  676. *
  677. * This routine will call the SAL which will tell the system controller(s)
  678. * to capture hw mmr information from each SHub in the system.
  679. */
  680. static inline u64
  681. ia64_sn_fru_capture(void)
  682. {
  683. struct ia64_sal_retval isrv;
  684. SAL_CALL(isrv, SN_SAL_SYSCTL_FRU_CAPTURE, 0, 0, 0, 0, 0, 0, 0);
  685. if (isrv.status)
  686. return 0;
  687. return isrv.v0;
  688. }
  689. /*
  690. * Performs an operation on a PCI bus or slot -- power up, power down
  691. * or reset.
  692. */
  693. static inline u64
  694. ia64_sn_sysctl_iobrick_pci_op(nasid_t n, u64 connection_type,
  695. u64 bus, char slot,
  696. u64 action)
  697. {
  698. struct ia64_sal_retval rv = {0, 0, 0, 0};
  699. SAL_CALL_NOLOCK(rv, SN_SAL_SYSCTL_IOBRICK_PCI_OP, connection_type, n, action,
  700. bus, (u64) slot, 0, 0);
  701. if (rv.status)
  702. return rv.v0;
  703. return 0;
  704. }
  705. /*
  706. * Open a subchannel for sending arbitrary data to the system
  707. * controller network via the system controller device associated with
  708. * 'nasid'. Return the subchannel number or a negative error code.
  709. */
  710. static inline int
  711. ia64_sn_irtr_open(nasid_t nasid)
  712. {
  713. struct ia64_sal_retval rv;
  714. SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_OPEN, nasid,
  715. 0, 0, 0, 0, 0);
  716. return (int) rv.v0;
  717. }
  718. /*
  719. * Close system controller subchannel 'subch' previously opened on 'nasid'.
  720. */
  721. static inline int
  722. ia64_sn_irtr_close(nasid_t nasid, int subch)
  723. {
  724. struct ia64_sal_retval rv;
  725. SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_CLOSE,
  726. (u64) nasid, (u64) subch, 0, 0, 0, 0);
  727. return (int) rv.status;
  728. }
  729. /*
  730. * Read data from system controller associated with 'nasid' on
  731. * subchannel 'subch'. The buffer to be filled is pointed to by
  732. * 'buf', and its capacity is in the integer pointed to by 'len'. The
  733. * referent of 'len' is set to the number of bytes read by the SAL
  734. * call. The return value is either SALRET_OK (for bytes read) or
  735. * SALRET_ERROR (for error or "no data available").
  736. */
  737. static inline int
  738. ia64_sn_irtr_recv(nasid_t nasid, int subch, char *buf, int *len)
  739. {
  740. struct ia64_sal_retval rv;
  741. SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_RECV,
  742. (u64) nasid, (u64) subch, (u64) buf, (u64) len,
  743. 0, 0);
  744. return (int) rv.status;
  745. }
  746. /*
  747. * Write data to the system controller network via the system
  748. * controller associated with 'nasid' on suchannel 'subch'. The
  749. * buffer to be written out is pointed to by 'buf', and 'len' is the
  750. * number of bytes to be written. The return value is either the
  751. * number of bytes written (which could be zero) or a negative error
  752. * code.
  753. */
  754. static inline int
  755. ia64_sn_irtr_send(nasid_t nasid, int subch, char *buf, int len)
  756. {
  757. struct ia64_sal_retval rv;
  758. SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_SEND,
  759. (u64) nasid, (u64) subch, (u64) buf, (u64) len,
  760. 0, 0);
  761. return (int) rv.v0;
  762. }
  763. /*
  764. * Check whether any interrupts are pending for the system controller
  765. * associated with 'nasid' and its subchannel 'subch'. The return
  766. * value is a mask of pending interrupts (SAL_IROUTER_INTR_XMIT and/or
  767. * SAL_IROUTER_INTR_RECV).
  768. */
  769. static inline int
  770. ia64_sn_irtr_intr(nasid_t nasid, int subch)
  771. {
  772. struct ia64_sal_retval rv;
  773. SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_INTR_STATUS,
  774. (u64) nasid, (u64) subch, 0, 0, 0, 0);
  775. return (int) rv.v0;
  776. }
  777. /*
  778. * Enable the interrupt indicated by the intr parameter (either
  779. * SAL_IROUTER_INTR_XMIT or SAL_IROUTER_INTR_RECV).
  780. */
  781. static inline int
  782. ia64_sn_irtr_intr_enable(nasid_t nasid, int subch, u64 intr)
  783. {
  784. struct ia64_sal_retval rv;
  785. SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_INTR_ON,
  786. (u64) nasid, (u64) subch, intr, 0, 0, 0);
  787. return (int) rv.v0;
  788. }
  789. /*
  790. * Disable the interrupt indicated by the intr parameter (either
  791. * SAL_IROUTER_INTR_XMIT or SAL_IROUTER_INTR_RECV).
  792. */
  793. static inline int
  794. ia64_sn_irtr_intr_disable(nasid_t nasid, int subch, u64 intr)
  795. {
  796. struct ia64_sal_retval rv;
  797. SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_INTR_OFF,
  798. (u64) nasid, (u64) subch, intr, 0, 0, 0);
  799. return (int) rv.v0;
  800. }
  801. /*
  802. * Set up a node as the point of contact for system controller
  803. * environmental event delivery.
  804. */
  805. static inline int
  806. ia64_sn_sysctl_event_init(nasid_t nasid)
  807. {
  808. struct ia64_sal_retval rv;
  809. SAL_CALL_REENTRANT(rv, SN_SAL_SYSCTL_EVENT, (u64) nasid,
  810. 0, 0, 0, 0, 0, 0);
  811. return (int) rv.v0;
  812. }
  813. /**
  814. * ia64_sn_get_fit_compt - read a FIT entry from the PROM header
  815. * @nasid: NASID of node to read
  816. * @index: FIT entry index to be retrieved (0..n)
  817. * @fitentry: 16 byte buffer where FIT entry will be stored.
  818. * @banbuf: optional buffer for retrieving banner
  819. * @banlen: length of banner buffer
  820. *
  821. * Access to the physical PROM chips needs to be serialized since reads and
  822. * writes can't occur at the same time, so we need to call into the SAL when
  823. * we want to look at the FIT entries on the chips.
  824. *
  825. * Returns:
  826. * %SALRET_OK if ok
  827. * %SALRET_INVALID_ARG if index too big
  828. * %SALRET_NOT_IMPLEMENTED if running on older PROM
  829. * ??? if nasid invalid OR banner buffer not large enough
  830. */
  831. static inline int
  832. ia64_sn_get_fit_compt(u64 nasid, u64 index, void *fitentry, void *banbuf,
  833. u64 banlen)
  834. {
  835. struct ia64_sal_retval rv;
  836. SAL_CALL_NOLOCK(rv, SN_SAL_GET_FIT_COMPT, nasid, index, fitentry,
  837. banbuf, banlen, 0, 0);
  838. return (int) rv.status;
  839. }
  840. /*
  841. * Initialize the SAL components of the system controller
  842. * communication driver; specifically pass in a sizable buffer that
  843. * can be used for allocation of subchannel queues as new subchannels
  844. * are opened. "buf" points to the buffer, and "len" specifies its
  845. * length.
  846. */
  847. static inline int
  848. ia64_sn_irtr_init(nasid_t nasid, void *buf, int len)
  849. {
  850. struct ia64_sal_retval rv;
  851. SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_INIT,
  852. (u64) nasid, (u64) buf, (u64) len, 0, 0, 0);
  853. return (int) rv.status;
  854. }
  855. /*
  856. * Returns the nasid, subnode & slice corresponding to a SAPIC ID
  857. *
  858. * In:
  859. * arg0 - SN_SAL_GET_SAPIC_INFO
  860. * arg1 - sapicid (lid >> 16)
  861. * Out:
  862. * v0 - nasid
  863. * v1 - subnode
  864. * v2 - slice
  865. */
  866. static inline u64
  867. ia64_sn_get_sapic_info(int sapicid, int *nasid, int *subnode, int *slice)
  868. {
  869. struct ia64_sal_retval ret_stuff;
  870. ret_stuff.status = 0;
  871. ret_stuff.v0 = 0;
  872. ret_stuff.v1 = 0;
  873. ret_stuff.v2 = 0;
  874. SAL_CALL_NOLOCK(ret_stuff, SN_SAL_GET_SAPIC_INFO, sapicid, 0, 0, 0, 0, 0, 0);
  875. /***** BEGIN HACK - temp til old proms no longer supported ********/
  876. if (ret_stuff.status == SALRET_NOT_IMPLEMENTED) {
  877. if (nasid) *nasid = sapicid & 0xfff;
  878. if (subnode) *subnode = (sapicid >> 13) & 1;
  879. if (slice) *slice = (sapicid >> 12) & 3;
  880. return 0;
  881. }
  882. /***** END HACK *******/
  883. if (ret_stuff.status < 0)
  884. return ret_stuff.status;
  885. if (nasid) *nasid = (int) ret_stuff.v0;
  886. if (subnode) *subnode = (int) ret_stuff.v1;
  887. if (slice) *slice = (int) ret_stuff.v2;
  888. return 0;
  889. }
  890. /*
  891. * Returns information about the HUB/SHUB.
  892. * In:
  893. * arg0 - SN_SAL_GET_SN_INFO
  894. * arg1 - 0 (other values reserved for future use)
  895. * Out:
  896. * v0
  897. * [7:0] - shub type (0=shub1, 1=shub2)
  898. * [15:8] - Log2 max number of nodes in entire system (includes
  899. * C-bricks, I-bricks, etc)
  900. * [23:16] - Log2 of nodes per sharing domain
  901. * [31:24] - partition ID
  902. * [39:32] - coherency_id
  903. * [47:40] - regionsize
  904. * v1
  905. * [15:0] - nasid mask (ex., 0x7ff for 11 bit nasid)
  906. * [23:15] - bit position of low nasid bit
  907. */
  908. static inline u64
  909. ia64_sn_get_sn_info(int fc, u8 *shubtype, u16 *nasid_bitmask, u8 *nasid_shift,
  910. u8 *systemsize, u8 *sharing_domain_size, u8 *partid, u8 *coher, u8 *reg)
  911. {
  912. struct ia64_sal_retval ret_stuff;
  913. ret_stuff.status = 0;
  914. ret_stuff.v0 = 0;
  915. ret_stuff.v1 = 0;
  916. ret_stuff.v2 = 0;
  917. SAL_CALL_NOLOCK(ret_stuff, SN_SAL_GET_SN_INFO, fc, 0, 0, 0, 0, 0, 0);
  918. /***** BEGIN HACK - temp til old proms no longer supported ********/
  919. if (ret_stuff.status == SALRET_NOT_IMPLEMENTED) {
  920. int nasid = get_sapicid() & 0xfff;;
  921. #define SH_SHUB_ID_NODES_PER_BIT_MASK 0x001f000000000000UL
  922. #define SH_SHUB_ID_NODES_PER_BIT_SHFT 48
  923. if (shubtype) *shubtype = 0;
  924. if (nasid_bitmask) *nasid_bitmask = 0x7ff;
  925. if (nasid_shift) *nasid_shift = 38;
  926. if (systemsize) *systemsize = 11;
  927. if (sharing_domain_size) *sharing_domain_size = 9;
  928. if (partid) *partid = ia64_sn_sysctl_partition_get(nasid);
  929. if (coher) *coher = nasid >> 9;
  930. if (reg) *reg = (HUB_L((u64 *) LOCAL_MMR_ADDR(SH1_SHUB_ID)) & SH_SHUB_ID_NODES_PER_BIT_MASK) >>
  931. SH_SHUB_ID_NODES_PER_BIT_SHFT;
  932. return 0;
  933. }
  934. /***** END HACK *******/
  935. if (ret_stuff.status < 0)
  936. return ret_stuff.status;
  937. if (shubtype) *shubtype = ret_stuff.v0 & 0xff;
  938. if (systemsize) *systemsize = (ret_stuff.v0 >> 8) & 0xff;
  939. if (sharing_domain_size) *sharing_domain_size = (ret_stuff.v0 >> 16) & 0xff;
  940. if (partid) *partid = (ret_stuff.v0 >> 24) & 0xff;
  941. if (coher) *coher = (ret_stuff.v0 >> 32) & 0xff;
  942. if (reg) *reg = (ret_stuff.v0 >> 40) & 0xff;
  943. if (nasid_bitmask) *nasid_bitmask = (ret_stuff.v1 & 0xffff);
  944. if (nasid_shift) *nasid_shift = (ret_stuff.v1 >> 16) & 0xff;
  945. return 0;
  946. }
  947. /*
  948. * This is the access point to the Altix PROM hardware performance
  949. * and status monitoring interface. For info on using this, see
  950. * include/asm-ia64/sn/sn2/sn_hwperf.h
  951. */
  952. static inline int
  953. ia64_sn_hwperf_op(nasid_t nasid, u64 opcode, u64 a0, u64 a1, u64 a2,
  954. u64 a3, u64 a4, int *v0)
  955. {
  956. struct ia64_sal_retval rv;
  957. SAL_CALL_NOLOCK(rv, SN_SAL_HWPERF_OP, (u64)nasid,
  958. opcode, a0, a1, a2, a3, a4);
  959. if (v0)
  960. *v0 = (int) rv.v0;
  961. return (int) rv.status;
  962. }
  963. static inline int
  964. ia64_sn_ioif_get_pci_topology(u64 rack, u64 bay, u64 slot, u64 slab,
  965. u64 buf, u64 len)
  966. {
  967. struct ia64_sal_retval rv;
  968. SAL_CALL_NOLOCK(rv, SN_SAL_IOIF_GET_PCI_TOPOLOGY,
  969. rack, bay, slot, slab, buf, len, 0);
  970. return (int) rv.status;
  971. }
  972. /*
  973. * BTE error recovery is implemented in SAL
  974. */
  975. static inline int
  976. ia64_sn_bte_recovery(nasid_t nasid)
  977. {
  978. struct ia64_sal_retval rv;
  979. rv.status = 0;
  980. SAL_CALL_NOLOCK(rv, SN_SAL_BTE_RECOVER, 0, 0, 0, 0, 0, 0, 0);
  981. if (rv.status == SALRET_NOT_IMPLEMENTED)
  982. return 0;
  983. return (int) rv.status;
  984. }
  985. #endif /* _ASM_IA64_SN_SN_SAL_H */