sn_sal.h 28 KB

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