sn_sal.h 29 KB

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