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_SYSTEM_POWER_DOWN 0x0200003b
  55. #define SN_SAL_GET_MASTER_BASEIO_NASID 0x0200003c
  56. #define SN_SAL_COHERENCE 0x0200003d
  57. #define SN_SAL_MEMPROTECT 0x0200003e
  58. #define SN_SAL_SYSCTL_FRU_CAPTURE 0x0200003f
  59. #define SN_SAL_SYSCTL_IOBRICK_PCI_OP 0x02000042 // reentrant
  60. #define SN_SAL_IROUTER_OP 0x02000043
  61. #define SN_SAL_SYSCTL_EVENT 0x02000044
  62. #define SN_SAL_IOIF_INTERRUPT 0x0200004a
  63. #define SN_SAL_HWPERF_OP 0x02000050 // lock
  64. #define SN_SAL_IOIF_ERROR_INTERRUPT 0x02000051
  65. #define SN_SAL_IOIF_SLOT_ENABLE 0x02000053
  66. #define SN_SAL_IOIF_SLOT_DISABLE 0x02000054
  67. #define SN_SAL_IOIF_GET_HUBDEV_INFO 0x02000055
  68. #define SN_SAL_IOIF_GET_PCIBUS_INFO 0x02000056
  69. #define SN_SAL_IOIF_GET_PCIDEV_INFO 0x02000057
  70. #define SN_SAL_IOIF_GET_WIDGET_DMAFLUSH_LIST 0x02000058
  71. #define SN_SAL_HUB_ERROR_INTERRUPT 0x02000060
  72. #define SN_SAL_BTE_RECOVER 0x02000061
  73. #define SN_SAL_RESERVED_DO_NOT_USE 0x02000062
  74. #define SN_SAL_IOIF_GET_PCI_TOPOLOGY 0x02000064
  75. /*
  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 physical address of the partition's reserved page through
  508. * an iterative number of calls.
  509. *
  510. * On first call, 'cookie' and 'len' should be set to 0, and 'addr'
  511. * set to the nasid of the partition whose reserved page's address is
  512. * being sought.
  513. * On subsequent calls, pass the values, that were passed back on the
  514. * previous call.
  515. *
  516. * While the return status equals SALRET_MORE_PASSES, keep calling
  517. * this function after first copying 'len' bytes starting at 'addr'
  518. * into 'buf'. Once the return status equals SALRET_OK, 'addr' will
  519. * be the physical address of the partition's reserved page. If the
  520. * return status equals neither of these, an error as occurred.
  521. */
  522. static inline s64
  523. sn_partition_reserved_page_pa(u64 buf, u64 *cookie, u64 *addr, u64 *len)
  524. {
  525. struct ia64_sal_retval rv;
  526. ia64_sal_oemcall_reentrant(&rv, SN_SAL_GET_PARTITION_ADDR, *cookie,
  527. *addr, buf, *len, 0, 0, 0);
  528. *cookie = rv.v0;
  529. *addr = rv.v1;
  530. *len = rv.v2;
  531. return rv.status;
  532. }
  533. /*
  534. * Register or unregister a physical address range being referenced across
  535. * a partition boundary for which certain SAL errors should be scanned for,
  536. * cleaned up and ignored. This is of value for kernel partitioning code only.
  537. * Values for the operation argument:
  538. * 1 = register this address range with SAL
  539. * 0 = unregister this address range with SAL
  540. *
  541. * SAL maintains a reference count on an address range in case it is registered
  542. * multiple times.
  543. *
  544. * On success, returns the reference count of the address range after the SAL
  545. * call has performed the current registration/unregistration. Returns a
  546. * negative value if an error occurred.
  547. */
  548. static inline int
  549. sn_register_xp_addr_region(u64 paddr, u64 len, int operation)
  550. {
  551. struct ia64_sal_retval ret_stuff;
  552. ia64_sal_oemcall(&ret_stuff, SN_SAL_XP_ADDR_REGION, paddr, len,
  553. (u64)operation, 0, 0, 0, 0);
  554. return ret_stuff.status;
  555. }
  556. /*
  557. * Register or unregister an instruction range for which SAL errors should
  558. * be ignored. If an error occurs while in the registered range, SAL jumps
  559. * to return_addr after ignoring the error. Values for the operation argument:
  560. * 1 = register this instruction range with SAL
  561. * 0 = unregister this instruction range with SAL
  562. *
  563. * Returns 0 on success, or a negative value if an error occurred.
  564. */
  565. static inline int
  566. sn_register_nofault_code(u64 start_addr, u64 end_addr, u64 return_addr,
  567. int virtual, int operation)
  568. {
  569. struct ia64_sal_retval ret_stuff;
  570. u64 call;
  571. if (virtual) {
  572. call = SN_SAL_NO_FAULT_ZONE_VIRTUAL;
  573. } else {
  574. call = SN_SAL_NO_FAULT_ZONE_PHYSICAL;
  575. }
  576. ia64_sal_oemcall(&ret_stuff, call, start_addr, end_addr, return_addr,
  577. (u64)1, 0, 0, 0);
  578. return ret_stuff.status;
  579. }
  580. /*
  581. * Change or query the coherence domain for this partition. Each cpu-based
  582. * nasid is represented by a bit in an array of 64-bit words:
  583. * 0 = not in this partition's coherency domain
  584. * 1 = in this partition's coherency domain
  585. *
  586. * It is not possible for the local system's nasids to be removed from
  587. * the coherency domain. Purpose of the domain arguments:
  588. * new_domain = set the coherence domain to the given nasids
  589. * old_domain = return the current coherence domain
  590. *
  591. * Returns 0 on success, or a negative value if an error occurred.
  592. */
  593. static inline int
  594. sn_change_coherence(u64 *new_domain, u64 *old_domain)
  595. {
  596. struct ia64_sal_retval ret_stuff;
  597. ia64_sal_oemcall(&ret_stuff, SN_SAL_COHERENCE, (u64)new_domain,
  598. (u64)old_domain, 0, 0, 0, 0, 0);
  599. return ret_stuff.status;
  600. }
  601. /*
  602. * Change memory access protections for a physical address range.
  603. * nasid_array is not used on Altix, but may be in future architectures.
  604. * Available memory protection access classes are defined after the function.
  605. */
  606. static inline int
  607. sn_change_memprotect(u64 paddr, u64 len, u64 perms, u64 *nasid_array)
  608. {
  609. struct ia64_sal_retval ret_stuff;
  610. int cnodeid;
  611. unsigned long irq_flags;
  612. cnodeid = nasid_to_cnodeid(get_node_number(paddr));
  613. // spin_lock(&NODEPDA(cnodeid)->bist_lock);
  614. local_irq_save(irq_flags);
  615. ia64_sal_oemcall_nolock(&ret_stuff, SN_SAL_MEMPROTECT, paddr, len,
  616. (u64)nasid_array, perms, 0, 0, 0);
  617. local_irq_restore(irq_flags);
  618. // spin_unlock(&NODEPDA(cnodeid)->bist_lock);
  619. return ret_stuff.status;
  620. }
  621. #define SN_MEMPROT_ACCESS_CLASS_0 0x14a080
  622. #define SN_MEMPROT_ACCESS_CLASS_1 0x2520c2
  623. #define SN_MEMPROT_ACCESS_CLASS_2 0x14a1ca
  624. #define SN_MEMPROT_ACCESS_CLASS_3 0x14a290
  625. #define SN_MEMPROT_ACCESS_CLASS_6 0x084080
  626. #define SN_MEMPROT_ACCESS_CLASS_7 0x021080
  627. /*
  628. * Turns off system power.
  629. */
  630. static inline void
  631. ia64_sn_power_down(void)
  632. {
  633. struct ia64_sal_retval ret_stuff;
  634. SAL_CALL(ret_stuff, SN_SAL_SYSTEM_POWER_DOWN, 0, 0, 0, 0, 0, 0, 0);
  635. while(1)
  636. cpu_relax();
  637. /* never returns */
  638. }
  639. /**
  640. * ia64_sn_fru_capture - tell the system controller to capture hw state
  641. *
  642. * This routine will call the SAL which will tell the system controller(s)
  643. * to capture hw mmr information from each SHub in the system.
  644. */
  645. static inline u64
  646. ia64_sn_fru_capture(void)
  647. {
  648. struct ia64_sal_retval isrv;
  649. SAL_CALL(isrv, SN_SAL_SYSCTL_FRU_CAPTURE, 0, 0, 0, 0, 0, 0, 0);
  650. if (isrv.status)
  651. return 0;
  652. return isrv.v0;
  653. }
  654. /*
  655. * Performs an operation on a PCI bus or slot -- power up, power down
  656. * or reset.
  657. */
  658. static inline u64
  659. ia64_sn_sysctl_iobrick_pci_op(nasid_t n, u64 connection_type,
  660. u64 bus, char slot,
  661. u64 action)
  662. {
  663. struct ia64_sal_retval rv = {0, 0, 0, 0};
  664. SAL_CALL_NOLOCK(rv, SN_SAL_SYSCTL_IOBRICK_PCI_OP, connection_type, n, action,
  665. bus, (u64) slot, 0, 0);
  666. if (rv.status)
  667. return rv.v0;
  668. return 0;
  669. }
  670. /*
  671. * Open a subchannel for sending arbitrary data to the system
  672. * controller network via the system controller device associated with
  673. * 'nasid'. Return the subchannel number or a negative error code.
  674. */
  675. static inline int
  676. ia64_sn_irtr_open(nasid_t nasid)
  677. {
  678. struct ia64_sal_retval rv;
  679. SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_OPEN, nasid,
  680. 0, 0, 0, 0, 0);
  681. return (int) rv.v0;
  682. }
  683. /*
  684. * Close system controller subchannel 'subch' previously opened on 'nasid'.
  685. */
  686. static inline int
  687. ia64_sn_irtr_close(nasid_t nasid, int subch)
  688. {
  689. struct ia64_sal_retval rv;
  690. SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_CLOSE,
  691. (u64) nasid, (u64) subch, 0, 0, 0, 0);
  692. return (int) rv.status;
  693. }
  694. /*
  695. * Read data from system controller associated with 'nasid' on
  696. * subchannel 'subch'. The buffer to be filled is pointed to by
  697. * 'buf', and its capacity is in the integer pointed to by 'len'. The
  698. * referent of 'len' is set to the number of bytes read by the SAL
  699. * call. The return value is either SALRET_OK (for bytes read) or
  700. * SALRET_ERROR (for error or "no data available").
  701. */
  702. static inline int
  703. ia64_sn_irtr_recv(nasid_t nasid, int subch, char *buf, int *len)
  704. {
  705. struct ia64_sal_retval rv;
  706. SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_RECV,
  707. (u64) nasid, (u64) subch, (u64) buf, (u64) len,
  708. 0, 0);
  709. return (int) rv.status;
  710. }
  711. /*
  712. * Write data to the system controller network via the system
  713. * controller associated with 'nasid' on suchannel 'subch'. The
  714. * buffer to be written out is pointed to by 'buf', and 'len' is the
  715. * number of bytes to be written. The return value is either the
  716. * number of bytes written (which could be zero) or a negative error
  717. * code.
  718. */
  719. static inline int
  720. ia64_sn_irtr_send(nasid_t nasid, int subch, char *buf, int len)
  721. {
  722. struct ia64_sal_retval rv;
  723. SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_SEND,
  724. (u64) nasid, (u64) subch, (u64) buf, (u64) len,
  725. 0, 0);
  726. return (int) rv.v0;
  727. }
  728. /*
  729. * Check whether any interrupts are pending for the system controller
  730. * associated with 'nasid' and its subchannel 'subch'. The return
  731. * value is a mask of pending interrupts (SAL_IROUTER_INTR_XMIT and/or
  732. * SAL_IROUTER_INTR_RECV).
  733. */
  734. static inline int
  735. ia64_sn_irtr_intr(nasid_t nasid, int subch)
  736. {
  737. struct ia64_sal_retval rv;
  738. SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_INTR_STATUS,
  739. (u64) nasid, (u64) subch, 0, 0, 0, 0);
  740. return (int) rv.v0;
  741. }
  742. /*
  743. * Enable the interrupt indicated by the intr parameter (either
  744. * SAL_IROUTER_INTR_XMIT or SAL_IROUTER_INTR_RECV).
  745. */
  746. static inline int
  747. ia64_sn_irtr_intr_enable(nasid_t nasid, int subch, u64 intr)
  748. {
  749. struct ia64_sal_retval rv;
  750. SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_INTR_ON,
  751. (u64) nasid, (u64) subch, intr, 0, 0, 0);
  752. return (int) rv.v0;
  753. }
  754. /*
  755. * Disable the interrupt indicated by the intr parameter (either
  756. * SAL_IROUTER_INTR_XMIT or SAL_IROUTER_INTR_RECV).
  757. */
  758. static inline int
  759. ia64_sn_irtr_intr_disable(nasid_t nasid, int subch, u64 intr)
  760. {
  761. struct ia64_sal_retval rv;
  762. SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_INTR_OFF,
  763. (u64) nasid, (u64) subch, intr, 0, 0, 0);
  764. return (int) rv.v0;
  765. }
  766. /*
  767. * Set up a node as the point of contact for system controller
  768. * environmental event delivery.
  769. */
  770. static inline int
  771. ia64_sn_sysctl_event_init(nasid_t nasid)
  772. {
  773. struct ia64_sal_retval rv;
  774. SAL_CALL_REENTRANT(rv, SN_SAL_SYSCTL_EVENT, (u64) nasid,
  775. 0, 0, 0, 0, 0, 0);
  776. return (int) rv.v0;
  777. }
  778. /**
  779. * ia64_sn_get_fit_compt - read a FIT entry from the PROM header
  780. * @nasid: NASID of node to read
  781. * @index: FIT entry index to be retrieved (0..n)
  782. * @fitentry: 16 byte buffer where FIT entry will be stored.
  783. * @banbuf: optional buffer for retrieving banner
  784. * @banlen: length of banner buffer
  785. *
  786. * Access to the physical PROM chips needs to be serialized since reads and
  787. * writes can't occur at the same time, so we need to call into the SAL when
  788. * we want to look at the FIT entries on the chips.
  789. *
  790. * Returns:
  791. * %SALRET_OK if ok
  792. * %SALRET_INVALID_ARG if index too big
  793. * %SALRET_NOT_IMPLEMENTED if running on older PROM
  794. * ??? if nasid invalid OR banner buffer not large enough
  795. */
  796. static inline int
  797. ia64_sn_get_fit_compt(u64 nasid, u64 index, void *fitentry, void *banbuf,
  798. u64 banlen)
  799. {
  800. struct ia64_sal_retval rv;
  801. SAL_CALL_NOLOCK(rv, SN_SAL_GET_FIT_COMPT, nasid, index, fitentry,
  802. banbuf, banlen, 0, 0);
  803. return (int) rv.status;
  804. }
  805. /*
  806. * Initialize the SAL components of the system controller
  807. * communication driver; specifically pass in a sizable buffer that
  808. * can be used for allocation of subchannel queues as new subchannels
  809. * are opened. "buf" points to the buffer, and "len" specifies its
  810. * length.
  811. */
  812. static inline int
  813. ia64_sn_irtr_init(nasid_t nasid, void *buf, int len)
  814. {
  815. struct ia64_sal_retval rv;
  816. SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_INIT,
  817. (u64) nasid, (u64) buf, (u64) len, 0, 0, 0);
  818. return (int) rv.status;
  819. }
  820. /*
  821. * Returns the nasid, subnode & slice corresponding to a SAPIC ID
  822. *
  823. * In:
  824. * arg0 - SN_SAL_GET_SAPIC_INFO
  825. * arg1 - sapicid (lid >> 16)
  826. * Out:
  827. * v0 - nasid
  828. * v1 - subnode
  829. * v2 - slice
  830. */
  831. static inline u64
  832. ia64_sn_get_sapic_info(int sapicid, int *nasid, int *subnode, int *slice)
  833. {
  834. struct ia64_sal_retval ret_stuff;
  835. ret_stuff.status = 0;
  836. ret_stuff.v0 = 0;
  837. ret_stuff.v1 = 0;
  838. ret_stuff.v2 = 0;
  839. SAL_CALL_NOLOCK(ret_stuff, SN_SAL_GET_SAPIC_INFO, sapicid, 0, 0, 0, 0, 0, 0);
  840. /***** BEGIN HACK - temp til old proms no longer supported ********/
  841. if (ret_stuff.status == SALRET_NOT_IMPLEMENTED) {
  842. if (nasid) *nasid = sapicid & 0xfff;
  843. if (subnode) *subnode = (sapicid >> 13) & 1;
  844. if (slice) *slice = (sapicid >> 12) & 3;
  845. return 0;
  846. }
  847. /***** END HACK *******/
  848. if (ret_stuff.status < 0)
  849. return ret_stuff.status;
  850. if (nasid) *nasid = (int) ret_stuff.v0;
  851. if (subnode) *subnode = (int) ret_stuff.v1;
  852. if (slice) *slice = (int) ret_stuff.v2;
  853. return 0;
  854. }
  855. /*
  856. * Returns information about the HUB/SHUB.
  857. * In:
  858. * arg0 - SN_SAL_GET_SN_INFO
  859. * arg1 - 0 (other values reserved for future use)
  860. * Out:
  861. * v0
  862. * [7:0] - shub type (0=shub1, 1=shub2)
  863. * [15:8] - Log2 max number of nodes in entire system (includes
  864. * C-bricks, I-bricks, etc)
  865. * [23:16] - Log2 of nodes per sharing domain
  866. * [31:24] - partition ID
  867. * [39:32] - coherency_id
  868. * [47:40] - regionsize
  869. * v1
  870. * [15:0] - nasid mask (ex., 0x7ff for 11 bit nasid)
  871. * [23:15] - bit position of low nasid bit
  872. */
  873. static inline u64
  874. ia64_sn_get_sn_info(int fc, u8 *shubtype, u16 *nasid_bitmask, u8 *nasid_shift,
  875. u8 *systemsize, u8 *sharing_domain_size, u8 *partid, u8 *coher, u8 *reg)
  876. {
  877. struct ia64_sal_retval ret_stuff;
  878. ret_stuff.status = 0;
  879. ret_stuff.v0 = 0;
  880. ret_stuff.v1 = 0;
  881. ret_stuff.v2 = 0;
  882. SAL_CALL_NOLOCK(ret_stuff, SN_SAL_GET_SN_INFO, fc, 0, 0, 0, 0, 0, 0);
  883. if (ret_stuff.status < 0)
  884. return ret_stuff.status;
  885. if (shubtype) *shubtype = ret_stuff.v0 & 0xff;
  886. if (systemsize) *systemsize = (ret_stuff.v0 >> 8) & 0xff;
  887. if (sharing_domain_size) *sharing_domain_size = (ret_stuff.v0 >> 16) & 0xff;
  888. if (partid) *partid = (ret_stuff.v0 >> 24) & 0xff;
  889. if (coher) *coher = (ret_stuff.v0 >> 32) & 0xff;
  890. if (reg) *reg = (ret_stuff.v0 >> 40) & 0xff;
  891. if (nasid_bitmask) *nasid_bitmask = (ret_stuff.v1 & 0xffff);
  892. if (nasid_shift) *nasid_shift = (ret_stuff.v1 >> 16) & 0xff;
  893. return 0;
  894. }
  895. /*
  896. * This is the access point to the Altix PROM hardware performance
  897. * and status monitoring interface. For info on using this, see
  898. * include/asm-ia64/sn/sn2/sn_hwperf.h
  899. */
  900. static inline int
  901. ia64_sn_hwperf_op(nasid_t nasid, u64 opcode, u64 a0, u64 a1, u64 a2,
  902. u64 a3, u64 a4, int *v0)
  903. {
  904. struct ia64_sal_retval rv;
  905. SAL_CALL_NOLOCK(rv, SN_SAL_HWPERF_OP, (u64)nasid,
  906. opcode, a0, a1, a2, a3, a4);
  907. if (v0)
  908. *v0 = (int) rv.v0;
  909. return (int) rv.status;
  910. }
  911. static inline int
  912. ia64_sn_ioif_get_pci_topology(u64 buf, u64 len)
  913. {
  914. struct ia64_sal_retval rv;
  915. SAL_CALL_NOLOCK(rv, SN_SAL_IOIF_GET_PCI_TOPOLOGY, buf, len, 0, 0, 0, 0, 0);
  916. return (int) rv.status;
  917. }
  918. /*
  919. * BTE error recovery is implemented in SAL
  920. */
  921. static inline int
  922. ia64_sn_bte_recovery(nasid_t nasid)
  923. {
  924. struct ia64_sal_retval rv;
  925. rv.status = 0;
  926. SAL_CALL_NOLOCK(rv, SN_SAL_BTE_RECOVER, 0, 0, 0, 0, 0, 0, 0);
  927. if (rv.status == SALRET_NOT_IMPLEMENTED)
  928. return 0;
  929. return (int) rv.status;
  930. }
  931. static inline int
  932. ia64_sn_is_fake_prom(void)
  933. {
  934. struct ia64_sal_retval rv;
  935. SAL_CALL_NOLOCK(rv, SN_SAL_FAKE_PROM, 0, 0, 0, 0, 0, 0, 0);
  936. return (rv.status == 0);
  937. }
  938. #endif /* _ASM_IA64_SN_SN_SAL_H */