sn_sal.h 30 KB

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