sn_sal.h 30 KB

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