sn_sal.h 30 KB

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