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