sn_sal.h 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055
  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. * SAL Error Codes
  107. */
  108. #define SALRET_MORE_PASSES 1
  109. #define SALRET_OK 0
  110. #define SALRET_NOT_IMPLEMENTED (-1)
  111. #define SALRET_INVALID_ARG (-2)
  112. #define SALRET_ERROR (-3)
  113. /**
  114. * sn_sal_rev_major - get the major SGI SAL revision number
  115. *
  116. * The SGI PROM stores its version in sal_[ab]_rev_(major|minor).
  117. * This routine simply extracts the major value from the
  118. * @ia64_sal_systab structure constructed by ia64_sal_init().
  119. */
  120. static inline int
  121. sn_sal_rev_major(void)
  122. {
  123. struct ia64_sal_systab *systab = efi.sal_systab;
  124. return (int)systab->sal_b_rev_major;
  125. }
  126. /**
  127. * sn_sal_rev_minor - get the minor SGI SAL revision number
  128. *
  129. * The SGI PROM stores its version in sal_[ab]_rev_(major|minor).
  130. * This routine simply extracts the minor value from the
  131. * @ia64_sal_systab structure constructed by ia64_sal_init().
  132. */
  133. static inline int
  134. sn_sal_rev_minor(void)
  135. {
  136. struct ia64_sal_systab *systab = efi.sal_systab;
  137. return (int)systab->sal_b_rev_minor;
  138. }
  139. /*
  140. * Specify the minimum PROM revsion required for this kernel.
  141. * Note that they're stored in hex format...
  142. */
  143. #define SN_SAL_MIN_MAJOR 0x4 /* SN2 kernels need at least PROM 4.0 */
  144. #define SN_SAL_MIN_MINOR 0x0
  145. /*
  146. * Returns the master console nasid, if the call fails, return an illegal
  147. * value.
  148. */
  149. static inline u64
  150. ia64_sn_get_console_nasid(void)
  151. {
  152. struct ia64_sal_retval ret_stuff;
  153. ret_stuff.status = 0;
  154. ret_stuff.v0 = 0;
  155. ret_stuff.v1 = 0;
  156. ret_stuff.v2 = 0;
  157. SAL_CALL(ret_stuff, SN_SAL_GET_MASTER_NASID, 0, 0, 0, 0, 0, 0, 0);
  158. if (ret_stuff.status < 0)
  159. return ret_stuff.status;
  160. /* Master console nasid is in 'v0' */
  161. return ret_stuff.v0;
  162. }
  163. /*
  164. * Returns the master baseio nasid, if the call fails, return an illegal
  165. * value.
  166. */
  167. static inline u64
  168. ia64_sn_get_master_baseio_nasid(void)
  169. {
  170. struct ia64_sal_retval ret_stuff;
  171. ret_stuff.status = 0;
  172. ret_stuff.v0 = 0;
  173. ret_stuff.v1 = 0;
  174. ret_stuff.v2 = 0;
  175. SAL_CALL(ret_stuff, SN_SAL_GET_MASTER_BASEIO_NASID, 0, 0, 0, 0, 0, 0, 0);
  176. if (ret_stuff.status < 0)
  177. return ret_stuff.status;
  178. /* Master baseio nasid is in 'v0' */
  179. return ret_stuff.v0;
  180. }
  181. static inline char *
  182. ia64_sn_get_klconfig_addr(nasid_t nasid)
  183. {
  184. struct ia64_sal_retval ret_stuff;
  185. int cnodeid;
  186. cnodeid = nasid_to_cnodeid(nasid);
  187. ret_stuff.status = 0;
  188. ret_stuff.v0 = 0;
  189. ret_stuff.v1 = 0;
  190. ret_stuff.v2 = 0;
  191. SAL_CALL(ret_stuff, SN_SAL_GET_KLCONFIG_ADDR, (u64)nasid, 0, 0, 0, 0, 0, 0);
  192. /*
  193. * We should panic if a valid cnode nasid does not produce
  194. * a klconfig address.
  195. */
  196. if (ret_stuff.status != 0) {
  197. panic("ia64_sn_get_klconfig_addr: Returned error %lx\n", ret_stuff.status);
  198. }
  199. return ret_stuff.v0 ? __va(ret_stuff.v0) : NULL;
  200. }
  201. /*
  202. * Returns the next console character.
  203. */
  204. static inline u64
  205. ia64_sn_console_getc(int *ch)
  206. {
  207. struct ia64_sal_retval ret_stuff;
  208. ret_stuff.status = 0;
  209. ret_stuff.v0 = 0;
  210. ret_stuff.v1 = 0;
  211. ret_stuff.v2 = 0;
  212. SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_GETC, 0, 0, 0, 0, 0, 0, 0);
  213. /* character is in 'v0' */
  214. *ch = (int)ret_stuff.v0;
  215. return ret_stuff.status;
  216. }
  217. /*
  218. * Read a character from the SAL console device, after a previous interrupt
  219. * or poll operation has given us to know that a character is available
  220. * to be read.
  221. */
  222. static inline u64
  223. ia64_sn_console_readc(void)
  224. {
  225. struct ia64_sal_retval ret_stuff;
  226. ret_stuff.status = 0;
  227. ret_stuff.v0 = 0;
  228. ret_stuff.v1 = 0;
  229. ret_stuff.v2 = 0;
  230. SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_READC, 0, 0, 0, 0, 0, 0, 0);
  231. /* character is in 'v0' */
  232. return ret_stuff.v0;
  233. }
  234. /*
  235. * Sends the given character to the console.
  236. */
  237. static inline u64
  238. ia64_sn_console_putc(char ch)
  239. {
  240. struct ia64_sal_retval ret_stuff;
  241. ret_stuff.status = 0;
  242. ret_stuff.v0 = 0;
  243. ret_stuff.v1 = 0;
  244. ret_stuff.v2 = 0;
  245. SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_PUTC, (uint64_t)ch, 0, 0, 0, 0, 0, 0);
  246. return ret_stuff.status;
  247. }
  248. /*
  249. * Sends the given buffer to the console.
  250. */
  251. static inline u64
  252. ia64_sn_console_putb(const char *buf, int len)
  253. {
  254. struct ia64_sal_retval ret_stuff;
  255. ret_stuff.status = 0;
  256. ret_stuff.v0 = 0;
  257. ret_stuff.v1 = 0;
  258. ret_stuff.v2 = 0;
  259. SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_PUTB, (uint64_t)buf, (uint64_t)len, 0, 0, 0, 0, 0);
  260. if ( ret_stuff.status == 0 ) {
  261. return ret_stuff.v0;
  262. }
  263. return (u64)0;
  264. }
  265. /*
  266. * Print a platform error record
  267. */
  268. static inline u64
  269. ia64_sn_plat_specific_err_print(int (*hook)(const char*, ...), char *rec)
  270. {
  271. struct ia64_sal_retval ret_stuff;
  272. ret_stuff.status = 0;
  273. ret_stuff.v0 = 0;
  274. ret_stuff.v1 = 0;
  275. ret_stuff.v2 = 0;
  276. SAL_CALL_REENTRANT(ret_stuff, SN_SAL_PRINT_ERROR, (uint64_t)hook, (uint64_t)rec, 0, 0, 0, 0, 0);
  277. return ret_stuff.status;
  278. }
  279. /*
  280. * Check for Platform errors
  281. */
  282. static inline u64
  283. ia64_sn_plat_cpei_handler(void)
  284. {
  285. struct ia64_sal_retval ret_stuff;
  286. ret_stuff.status = 0;
  287. ret_stuff.v0 = 0;
  288. ret_stuff.v1 = 0;
  289. ret_stuff.v2 = 0;
  290. SAL_CALL_NOLOCK(ret_stuff, SN_SAL_LOG_CE, 0, 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(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. SAL_CALL(ret_stuff, SN_SAL_PARTITION_SERIAL_GET, 0, 0, 0, 0, 0, 0, 0);
  482. if (ret_stuff.status != 0)
  483. return 0;
  484. return ret_stuff.v0;
  485. }
  486. static inline u64
  487. sn_partition_serial_number_val(void) {
  488. if (sn_partition_serial_number) {
  489. return(sn_partition_serial_number);
  490. } else {
  491. return(sn_partition_serial_number = ia64_sn_partition_serial_get());
  492. }
  493. }
  494. /*
  495. * Returns the partition id of the nasid passed in as an argument,
  496. * or INVALID_PARTID if the partition id cannot be retrieved.
  497. */
  498. static inline partid_t
  499. ia64_sn_sysctl_partition_get(nasid_t nasid)
  500. {
  501. struct ia64_sal_retval ret_stuff;
  502. SAL_CALL(ret_stuff, SN_SAL_SYSCTL_PARTITION_GET, nasid,
  503. 0, 0, 0, 0, 0, 0);
  504. if (ret_stuff.status != 0)
  505. return INVALID_PARTID;
  506. return ((partid_t)ret_stuff.v0);
  507. }
  508. /*
  509. * Returns the partition id of the current processor.
  510. */
  511. extern partid_t sn_partid;
  512. static inline partid_t
  513. sn_local_partid(void) {
  514. if (sn_partid < 0) {
  515. return (sn_partid = ia64_sn_sysctl_partition_get(cpuid_to_nasid(smp_processor_id())));
  516. } else {
  517. return sn_partid;
  518. }
  519. }
  520. /*
  521. * Register or unregister a physical address range being referenced across
  522. * a partition boundary for which certain SAL errors should be scanned for,
  523. * cleaned up and ignored. This is of value for kernel partitioning code only.
  524. * Values for the operation argument:
  525. * 1 = register this address range with SAL
  526. * 0 = unregister this address range with SAL
  527. *
  528. * SAL maintains a reference count on an address range in case it is registered
  529. * multiple times.
  530. *
  531. * On success, returns the reference count of the address range after the SAL
  532. * call has performed the current registration/unregistration. Returns a
  533. * negative value if an error occurred.
  534. */
  535. static inline int
  536. sn_register_xp_addr_region(u64 paddr, u64 len, int operation)
  537. {
  538. struct ia64_sal_retval ret_stuff;
  539. SAL_CALL(ret_stuff, SN_SAL_XP_ADDR_REGION, paddr, len, (u64)operation,
  540. 0, 0, 0, 0);
  541. return ret_stuff.status;
  542. }
  543. /*
  544. * Register or unregister an instruction range for which SAL errors should
  545. * be ignored. If an error occurs while in the registered range, SAL jumps
  546. * to return_addr after ignoring the error. Values for the operation argument:
  547. * 1 = register this instruction range with SAL
  548. * 0 = unregister this instruction range with SAL
  549. *
  550. * Returns 0 on success, or a negative value if an error occurred.
  551. */
  552. static inline int
  553. sn_register_nofault_code(u64 start_addr, u64 end_addr, u64 return_addr,
  554. int virtual, int operation)
  555. {
  556. struct ia64_sal_retval ret_stuff;
  557. u64 call;
  558. if (virtual) {
  559. call = SN_SAL_NO_FAULT_ZONE_VIRTUAL;
  560. } else {
  561. call = SN_SAL_NO_FAULT_ZONE_PHYSICAL;
  562. }
  563. SAL_CALL(ret_stuff, call, start_addr, end_addr, return_addr, (u64)1,
  564. 0, 0, 0);
  565. return ret_stuff.status;
  566. }
  567. /*
  568. * Change or query the coherence domain for this partition. Each cpu-based
  569. * nasid is represented by a bit in an array of 64-bit words:
  570. * 0 = not in this partition's coherency domain
  571. * 1 = in this partition's coherency domain
  572. *
  573. * It is not possible for the local system's nasids to be removed from
  574. * the coherency domain. Purpose of the domain arguments:
  575. * new_domain = set the coherence domain to the given nasids
  576. * old_domain = return the current coherence domain
  577. *
  578. * Returns 0 on success, or a negative value if an error occurred.
  579. */
  580. static inline int
  581. sn_change_coherence(u64 *new_domain, u64 *old_domain)
  582. {
  583. struct ia64_sal_retval ret_stuff;
  584. SAL_CALL(ret_stuff, SN_SAL_COHERENCE, new_domain, old_domain, 0, 0,
  585. 0, 0, 0);
  586. return ret_stuff.status;
  587. }
  588. /*
  589. * Change memory access protections for a physical address range.
  590. * nasid_array is not used on Altix, but may be in future architectures.
  591. * Available memory protection access classes are defined after the function.
  592. */
  593. static inline int
  594. sn_change_memprotect(u64 paddr, u64 len, u64 perms, u64 *nasid_array)
  595. {
  596. struct ia64_sal_retval ret_stuff;
  597. int cnodeid;
  598. unsigned long irq_flags;
  599. cnodeid = nasid_to_cnodeid(get_node_number(paddr));
  600. // spin_lock(&NODEPDA(cnodeid)->bist_lock);
  601. local_irq_save(irq_flags);
  602. SAL_CALL_NOLOCK(ret_stuff, SN_SAL_MEMPROTECT, paddr, len, nasid_array,
  603. perms, 0, 0, 0);
  604. local_irq_restore(irq_flags);
  605. // spin_unlock(&NODEPDA(cnodeid)->bist_lock);
  606. return ret_stuff.status;
  607. }
  608. #define SN_MEMPROT_ACCESS_CLASS_0 0x14a080
  609. #define SN_MEMPROT_ACCESS_CLASS_1 0x2520c2
  610. #define SN_MEMPROT_ACCESS_CLASS_2 0x14a1ca
  611. #define SN_MEMPROT_ACCESS_CLASS_3 0x14a290
  612. #define SN_MEMPROT_ACCESS_CLASS_6 0x084080
  613. #define SN_MEMPROT_ACCESS_CLASS_7 0x021080
  614. /*
  615. * Turns off system power.
  616. */
  617. static inline void
  618. ia64_sn_power_down(void)
  619. {
  620. struct ia64_sal_retval ret_stuff;
  621. SAL_CALL(ret_stuff, SN_SAL_SYSTEM_POWER_DOWN, 0, 0, 0, 0, 0, 0, 0);
  622. while(1);
  623. /* never returns */
  624. }
  625. /**
  626. * ia64_sn_fru_capture - tell the system controller to capture hw state
  627. *
  628. * This routine will call the SAL which will tell the system controller(s)
  629. * to capture hw mmr information from each SHub in the system.
  630. */
  631. static inline u64
  632. ia64_sn_fru_capture(void)
  633. {
  634. struct ia64_sal_retval isrv;
  635. SAL_CALL(isrv, SN_SAL_SYSCTL_FRU_CAPTURE, 0, 0, 0, 0, 0, 0, 0);
  636. if (isrv.status)
  637. return 0;
  638. return isrv.v0;
  639. }
  640. /*
  641. * Performs an operation on a PCI bus or slot -- power up, power down
  642. * or reset.
  643. */
  644. static inline u64
  645. ia64_sn_sysctl_iobrick_pci_op(nasid_t n, u64 connection_type,
  646. u64 bus, char slot,
  647. u64 action)
  648. {
  649. struct ia64_sal_retval rv = {0, 0, 0, 0};
  650. SAL_CALL_NOLOCK(rv, SN_SAL_SYSCTL_IOBRICK_PCI_OP, connection_type, n, action,
  651. bus, (u64) slot, 0, 0);
  652. if (rv.status)
  653. return rv.v0;
  654. return 0;
  655. }
  656. /*
  657. * Open a subchannel for sending arbitrary data to the system
  658. * controller network via the system controller device associated with
  659. * 'nasid'. Return the subchannel number or a negative error code.
  660. */
  661. static inline int
  662. ia64_sn_irtr_open(nasid_t nasid)
  663. {
  664. struct ia64_sal_retval rv;
  665. SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_OPEN, nasid,
  666. 0, 0, 0, 0, 0);
  667. return (int) rv.v0;
  668. }
  669. /*
  670. * Close system controller subchannel 'subch' previously opened on 'nasid'.
  671. */
  672. static inline int
  673. ia64_sn_irtr_close(nasid_t nasid, int subch)
  674. {
  675. struct ia64_sal_retval rv;
  676. SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_CLOSE,
  677. (u64) nasid, (u64) subch, 0, 0, 0, 0);
  678. return (int) rv.status;
  679. }
  680. /*
  681. * Read data from system controller associated with 'nasid' on
  682. * subchannel 'subch'. The buffer to be filled is pointed to by
  683. * 'buf', and its capacity is in the integer pointed to by 'len'. The
  684. * referent of 'len' is set to the number of bytes read by the SAL
  685. * call. The return value is either SALRET_OK (for bytes read) or
  686. * SALRET_ERROR (for error or "no data available").
  687. */
  688. static inline int
  689. ia64_sn_irtr_recv(nasid_t nasid, int subch, char *buf, int *len)
  690. {
  691. struct ia64_sal_retval rv;
  692. SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_RECV,
  693. (u64) nasid, (u64) subch, (u64) buf, (u64) len,
  694. 0, 0);
  695. return (int) rv.status;
  696. }
  697. /*
  698. * Write data to the system controller network via the system
  699. * controller associated with 'nasid' on suchannel 'subch'. The
  700. * buffer to be written out is pointed to by 'buf', and 'len' is the
  701. * number of bytes to be written. The return value is either the
  702. * number of bytes written (which could be zero) or a negative error
  703. * code.
  704. */
  705. static inline int
  706. ia64_sn_irtr_send(nasid_t nasid, int subch, char *buf, int len)
  707. {
  708. struct ia64_sal_retval rv;
  709. SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_SEND,
  710. (u64) nasid, (u64) subch, (u64) buf, (u64) len,
  711. 0, 0);
  712. return (int) rv.v0;
  713. }
  714. /*
  715. * Check whether any interrupts are pending for the system controller
  716. * associated with 'nasid' and its subchannel 'subch'. The return
  717. * value is a mask of pending interrupts (SAL_IROUTER_INTR_XMIT and/or
  718. * SAL_IROUTER_INTR_RECV).
  719. */
  720. static inline int
  721. ia64_sn_irtr_intr(nasid_t nasid, int subch)
  722. {
  723. struct ia64_sal_retval rv;
  724. SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_INTR_STATUS,
  725. (u64) nasid, (u64) subch, 0, 0, 0, 0);
  726. return (int) rv.v0;
  727. }
  728. /*
  729. * Enable the interrupt indicated by the intr parameter (either
  730. * SAL_IROUTER_INTR_XMIT or SAL_IROUTER_INTR_RECV).
  731. */
  732. static inline int
  733. ia64_sn_irtr_intr_enable(nasid_t nasid, int subch, u64 intr)
  734. {
  735. struct ia64_sal_retval rv;
  736. SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_INTR_ON,
  737. (u64) nasid, (u64) subch, intr, 0, 0, 0);
  738. return (int) rv.v0;
  739. }
  740. /*
  741. * Disable the interrupt indicated by the intr parameter (either
  742. * SAL_IROUTER_INTR_XMIT or SAL_IROUTER_INTR_RECV).
  743. */
  744. static inline int
  745. ia64_sn_irtr_intr_disable(nasid_t nasid, int subch, u64 intr)
  746. {
  747. struct ia64_sal_retval rv;
  748. SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_INTR_OFF,
  749. (u64) nasid, (u64) subch, intr, 0, 0, 0);
  750. return (int) rv.v0;
  751. }
  752. /*
  753. * Set up a node as the point of contact for system controller
  754. * environmental event delivery.
  755. */
  756. static inline int
  757. ia64_sn_sysctl_event_init(nasid_t nasid)
  758. {
  759. struct ia64_sal_retval rv;
  760. SAL_CALL_REENTRANT(rv, SN_SAL_SYSCTL_EVENT, (u64) nasid,
  761. 0, 0, 0, 0, 0, 0);
  762. return (int) rv.v0;
  763. }
  764. /**
  765. * ia64_sn_get_fit_compt - read a FIT entry from the PROM header
  766. * @nasid: NASID of node to read
  767. * @index: FIT entry index to be retrieved (0..n)
  768. * @fitentry: 16 byte buffer where FIT entry will be stored.
  769. * @banbuf: optional buffer for retrieving banner
  770. * @banlen: length of banner buffer
  771. *
  772. * Access to the physical PROM chips needs to be serialized since reads and
  773. * writes can't occur at the same time, so we need to call into the SAL when
  774. * we want to look at the FIT entries on the chips.
  775. *
  776. * Returns:
  777. * %SALRET_OK if ok
  778. * %SALRET_INVALID_ARG if index too big
  779. * %SALRET_NOT_IMPLEMENTED if running on older PROM
  780. * ??? if nasid invalid OR banner buffer not large enough
  781. */
  782. static inline int
  783. ia64_sn_get_fit_compt(u64 nasid, u64 index, void *fitentry, void *banbuf,
  784. u64 banlen)
  785. {
  786. struct ia64_sal_retval rv;
  787. SAL_CALL_NOLOCK(rv, SN_SAL_GET_FIT_COMPT, nasid, index, fitentry,
  788. banbuf, banlen, 0, 0);
  789. return (int) rv.status;
  790. }
  791. /*
  792. * Initialize the SAL components of the system controller
  793. * communication driver; specifically pass in a sizable buffer that
  794. * can be used for allocation of subchannel queues as new subchannels
  795. * are opened. "buf" points to the buffer, and "len" specifies its
  796. * length.
  797. */
  798. static inline int
  799. ia64_sn_irtr_init(nasid_t nasid, void *buf, int len)
  800. {
  801. struct ia64_sal_retval rv;
  802. SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_INIT,
  803. (u64) nasid, (u64) buf, (u64) len, 0, 0, 0);
  804. return (int) rv.status;
  805. }
  806. /*
  807. * Returns the nasid, subnode & slice corresponding to a SAPIC ID
  808. *
  809. * In:
  810. * arg0 - SN_SAL_GET_SAPIC_INFO
  811. * arg1 - sapicid (lid >> 16)
  812. * Out:
  813. * v0 - nasid
  814. * v1 - subnode
  815. * v2 - slice
  816. */
  817. static inline u64
  818. ia64_sn_get_sapic_info(int sapicid, int *nasid, int *subnode, int *slice)
  819. {
  820. struct ia64_sal_retval ret_stuff;
  821. ret_stuff.status = 0;
  822. ret_stuff.v0 = 0;
  823. ret_stuff.v1 = 0;
  824. ret_stuff.v2 = 0;
  825. SAL_CALL_NOLOCK(ret_stuff, SN_SAL_GET_SAPIC_INFO, sapicid, 0, 0, 0, 0, 0, 0);
  826. /***** BEGIN HACK - temp til old proms no longer supported ********/
  827. if (ret_stuff.status == SALRET_NOT_IMPLEMENTED) {
  828. if (nasid) *nasid = sapicid & 0xfff;
  829. if (subnode) *subnode = (sapicid >> 13) & 1;
  830. if (slice) *slice = (sapicid >> 12) & 3;
  831. return 0;
  832. }
  833. /***** END HACK *******/
  834. if (ret_stuff.status < 0)
  835. return ret_stuff.status;
  836. if (nasid) *nasid = (int) ret_stuff.v0;
  837. if (subnode) *subnode = (int) ret_stuff.v1;
  838. if (slice) *slice = (int) ret_stuff.v2;
  839. return 0;
  840. }
  841. /*
  842. * Returns information about the HUB/SHUB.
  843. * In:
  844. * arg0 - SN_SAL_GET_SN_INFO
  845. * arg1 - 0 (other values reserved for future use)
  846. * Out:
  847. * v0
  848. * [7:0] - shub type (0=shub1, 1=shub2)
  849. * [15:8] - Log2 max number of nodes in entire system (includes
  850. * C-bricks, I-bricks, etc)
  851. * [23:16] - Log2 of nodes per sharing domain
  852. * [31:24] - partition ID
  853. * [39:32] - coherency_id
  854. * [47:40] - regionsize
  855. * v1
  856. * [15:0] - nasid mask (ex., 0x7ff for 11 bit nasid)
  857. * [23:15] - bit position of low nasid bit
  858. */
  859. static inline u64
  860. ia64_sn_get_sn_info(int fc, u8 *shubtype, u16 *nasid_bitmask, u8 *nasid_shift,
  861. u8 *systemsize, u8 *sharing_domain_size, u8 *partid, u8 *coher, u8 *reg)
  862. {
  863. struct ia64_sal_retval ret_stuff;
  864. ret_stuff.status = 0;
  865. ret_stuff.v0 = 0;
  866. ret_stuff.v1 = 0;
  867. ret_stuff.v2 = 0;
  868. SAL_CALL_NOLOCK(ret_stuff, SN_SAL_GET_SN_INFO, fc, 0, 0, 0, 0, 0, 0);
  869. /***** BEGIN HACK - temp til old proms no longer supported ********/
  870. if (ret_stuff.status == SALRET_NOT_IMPLEMENTED) {
  871. int nasid = get_sapicid() & 0xfff;;
  872. #define SH_SHUB_ID_NODES_PER_BIT_MASK 0x001f000000000000UL
  873. #define SH_SHUB_ID_NODES_PER_BIT_SHFT 48
  874. if (shubtype) *shubtype = 0;
  875. if (nasid_bitmask) *nasid_bitmask = 0x7ff;
  876. if (nasid_shift) *nasid_shift = 38;
  877. if (systemsize) *systemsize = 11;
  878. if (sharing_domain_size) *sharing_domain_size = 9;
  879. if (partid) *partid = ia64_sn_sysctl_partition_get(nasid);
  880. if (coher) *coher = nasid >> 9;
  881. if (reg) *reg = (HUB_L((u64 *) LOCAL_MMR_ADDR(SH1_SHUB_ID)) & SH_SHUB_ID_NODES_PER_BIT_MASK) >>
  882. SH_SHUB_ID_NODES_PER_BIT_SHFT;
  883. return 0;
  884. }
  885. /***** END HACK *******/
  886. if (ret_stuff.status < 0)
  887. return ret_stuff.status;
  888. if (shubtype) *shubtype = ret_stuff.v0 & 0xff;
  889. if (systemsize) *systemsize = (ret_stuff.v0 >> 8) & 0xff;
  890. if (sharing_domain_size) *sharing_domain_size = (ret_stuff.v0 >> 16) & 0xff;
  891. if (partid) *partid = (ret_stuff.v0 >> 24) & 0xff;
  892. if (coher) *coher = (ret_stuff.v0 >> 32) & 0xff;
  893. if (reg) *reg = (ret_stuff.v0 >> 40) & 0xff;
  894. if (nasid_bitmask) *nasid_bitmask = (ret_stuff.v1 & 0xffff);
  895. if (nasid_shift) *nasid_shift = (ret_stuff.v1 >> 16) & 0xff;
  896. return 0;
  897. }
  898. /*
  899. * This is the access point to the Altix PROM hardware performance
  900. * and status monitoring interface. For info on using this, see
  901. * include/asm-ia64/sn/sn2/sn_hwperf.h
  902. */
  903. static inline int
  904. ia64_sn_hwperf_op(nasid_t nasid, u64 opcode, u64 a0, u64 a1, u64 a2,
  905. u64 a3, u64 a4, int *v0)
  906. {
  907. struct ia64_sal_retval rv;
  908. SAL_CALL_NOLOCK(rv, SN_SAL_HWPERF_OP, (u64)nasid,
  909. opcode, a0, a1, a2, a3, a4);
  910. if (v0)
  911. *v0 = (int) rv.v0;
  912. return (int) rv.status;
  913. }
  914. static inline int
  915. ia64_sn_ioif_get_pci_topology(u64 rack, u64 bay, u64 slot, u64 slab,
  916. u64 buf, u64 len)
  917. {
  918. struct ia64_sal_retval rv;
  919. SAL_CALL_NOLOCK(rv, SN_SAL_IOIF_GET_PCI_TOPOLOGY,
  920. rack, bay, slot, slab, buf, len, 0);
  921. return (int) rv.status;
  922. }
  923. /*
  924. * BTE error recovery is implemented in SAL
  925. */
  926. static inline int
  927. ia64_sn_bte_recovery(nasid_t nasid)
  928. {
  929. struct ia64_sal_retval rv;
  930. rv.status = 0;
  931. SAL_CALL_NOLOCK(rv, SN_SAL_BTE_RECOVER, 0, 0, 0, 0, 0, 0, 0);
  932. if (rv.status == SALRET_NOT_IMPLEMENTED)
  933. return 0;
  934. return (int) rv.status;
  935. }
  936. #endif /* _ASM_IA64_SN_SN_SAL_H */