sn_sal.h 29 KB

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