addrs.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1992 - 1997, 1999, 2000 Silicon Graphics, Inc.
  7. * Copyright (C) 1999, 2000 by Ralf Baechle
  8. */
  9. #ifndef _ASM_SN_ADDRS_H
  10. #define _ASM_SN_ADDRS_H
  11. #ifndef __ASSEMBLY__
  12. #include <linux/types.h>
  13. #endif /* !__ASSEMBLY__ */
  14. #include <asm/addrspace.h>
  15. #include <asm/sn/kldir.h>
  16. #if defined(CONFIG_SGI_IP27)
  17. #include <asm/sn/sn0/addrs.h>
  18. #elif defined(CONFIG_SGI_IP35)
  19. #include <asm/sn/sn1/addrs.h>
  20. #endif
  21. #ifndef __ASSEMBLY__
  22. #define PS_UINT_CAST (unsigned long)
  23. #define UINT64_CAST (unsigned long)
  24. #define HUBREG_CAST (volatile hubreg_t *)
  25. #else /* __ASSEMBLY__ */
  26. #define PS_UINT_CAST
  27. #define UINT64_CAST
  28. #define HUBREG_CAST
  29. #endif /* __ASSEMBLY__ */
  30. #define NASID_GET_META(_n) ((_n) >> NASID_LOCAL_BITS)
  31. #ifdef CONFIG_SGI_IP27
  32. #define NASID_GET_LOCAL(_n) ((_n) & 0xf)
  33. #endif
  34. #define NASID_MAKE(_m, _l) (((_m) << NASID_LOCAL_BITS) | (_l))
  35. #define NODE_ADDRSPACE_MASK (NODE_ADDRSPACE_SIZE - 1)
  36. #define TO_NODE_ADDRSPACE(_pa) (UINT64_CAST (_pa) & NODE_ADDRSPACE_MASK)
  37. #define CHANGE_ADDR_NASID(_pa, _nasid) \
  38. ((UINT64_CAST(_pa) & ~NASID_MASK) | \
  39. (UINT64_CAST(_nasid) << NASID_SHFT))
  40. /*
  41. * The following macros are used to index to the beginning of a specific
  42. * node's address space.
  43. */
  44. #define NODE_OFFSET(_n) (UINT64_CAST (_n) << NODE_SIZE_BITS)
  45. #define NODE_CAC_BASE(_n) (CAC_BASE + NODE_OFFSET(_n))
  46. #define NODE_HSPEC_BASE(_n) (HSPEC_BASE + NODE_OFFSET(_n))
  47. #define NODE_IO_BASE(_n) (IO_BASE + NODE_OFFSET(_n))
  48. #define NODE_MSPEC_BASE(_n) (MSPEC_BASE + NODE_OFFSET(_n))
  49. #define NODE_UNCAC_BASE(_n) (UNCAC_BASE + NODE_OFFSET(_n))
  50. #define TO_NODE(_n, _x) (NODE_OFFSET(_n) | ((_x) ))
  51. #define TO_NODE_CAC(_n, _x) (NODE_CAC_BASE(_n) | ((_x) & TO_PHYS_MASK))
  52. #define TO_NODE_UNCAC(_n, _x) (NODE_UNCAC_BASE(_n) | ((_x) & TO_PHYS_MASK))
  53. #define TO_NODE_MSPEC(_n, _x) (NODE_MSPEC_BASE(_n) | ((_x) & TO_PHYS_MASK))
  54. #define TO_NODE_HSPEC(_n, _x) (NODE_HSPEC_BASE(_n) | ((_x) & TO_PHYS_MASK))
  55. #define RAW_NODE_SWIN_BASE(nasid, widget) \
  56. (NODE_IO_BASE(nasid) + (UINT64_CAST(widget) << SWIN_SIZE_BITS))
  57. #define WIDGETID_GET(addr) ((unsigned char)((addr >> SWIN_SIZE_BITS) & 0xff))
  58. /*
  59. * The following definitions pertain to the IO special address
  60. * space. They define the location of the big and little windows
  61. * of any given node.
  62. */
  63. #define SWIN_SIZE_BITS 24
  64. #define SWIN_SIZE (UINT64_CAST 1 << 24)
  65. #define SWIN_SIZEMASK (SWIN_SIZE - 1)
  66. #define SWIN_WIDGET_MASK 0xF
  67. /*
  68. * Convert smallwindow address to xtalk address.
  69. *
  70. * 'addr' can be physical or virtual address, but will be converted
  71. * to Xtalk address in the range 0 -> SWINZ_SIZEMASK
  72. */
  73. #define SWIN_WIDGETADDR(addr) ((addr) & SWIN_SIZEMASK)
  74. #define SWIN_WIDGETNUM(addr) (((addr) >> SWIN_SIZE_BITS) & SWIN_WIDGET_MASK)
  75. /*
  76. * Verify if addr belongs to small window address on node with "nasid"
  77. *
  78. *
  79. * NOTE: "addr" is expected to be XKPHYS address, and NOT physical
  80. * address
  81. *
  82. *
  83. */
  84. #define NODE_SWIN_ADDR(nasid, addr) \
  85. (((addr) >= NODE_SWIN_BASE(nasid, 0)) && \
  86. ((addr) < (NODE_SWIN_BASE(nasid, HUB_NUM_WIDGET) + SWIN_SIZE)\
  87. ))
  88. /*
  89. * The following define the major position-independent aliases used
  90. * in SN.
  91. * UALIAS -- 256MB in size, reads in the UALIAS result in
  92. * uncached references to the memory of the reader's node.
  93. * CPU_UALIAS -- 128kb in size, the bottom part of UALIAS is flipped
  94. * depending on which CPU does the access to provide
  95. * all CPUs with unique uncached memory at low addresses.
  96. * LBOOT -- 256MB in size, reads in the LBOOT area result in
  97. * uncached references to the local hub's boot prom and
  98. * other directory-bus connected devices.
  99. * IALIAS -- 8MB in size, reads in the IALIAS result in uncached
  100. * references to the local hub's registers.
  101. */
  102. #define UALIAS_BASE HSPEC_BASE
  103. #define UALIAS_SIZE 0x10000000 /* 256 Megabytes */
  104. #define UALIAS_LIMIT (UALIAS_BASE + UALIAS_SIZE)
  105. /*
  106. * The bottom of ualias space is flipped depending on whether you're
  107. * processor 0 or 1 within a node.
  108. */
  109. #ifdef CONFIG_SGI_IP27
  110. #define UALIAS_FLIP_BASE UALIAS_BASE
  111. #define UALIAS_FLIP_SIZE 0x20000
  112. #define UALIAS_FLIP_BIT 0x10000
  113. #define UALIAS_FLIP_ADDR(_x) (cputoslice(smp_processor_id()) ? \
  114. (_x) ^ UALIAS_FLIP_BIT : (_x))
  115. #define LBOOT_BASE (HSPEC_BASE + 0x10000000)
  116. #define LBOOT_SIZE 0x10000000
  117. #define LBOOT_LIMIT (LBOOT_BASE + LBOOT_SIZE)
  118. #define LBOOT_STRIDE 0 /* IP27 has only one CPU PROM */
  119. #endif
  120. #define HUB_REGISTER_WIDGET 1
  121. #define IALIAS_BASE NODE_SWIN_BASE(0, HUB_REGISTER_WIDGET)
  122. #define IALIAS_SIZE 0x800000 /* 8 Megabytes */
  123. #define IS_IALIAS(_a) (((_a) >= IALIAS_BASE) && \
  124. ((_a) < (IALIAS_BASE + IALIAS_SIZE)))
  125. /*
  126. * Macro for referring to Hub's RBOOT space
  127. */
  128. #ifdef CONFIG_SGI_IP27
  129. #define RBOOT_SIZE 0x10000000 /* 256 Megabytes */
  130. #define NODE_RBOOT_BASE(_n) (NODE_HSPEC_BASE(_n) + 0x30000000)
  131. #define NODE_RBOOT_LIMIT(_n) (NODE_RBOOT_BASE(_n) + RBOOT_SIZE)
  132. #endif
  133. /*
  134. * Macros for referring the Hub's back door space
  135. *
  136. * These macros correctly process addresses in any node's space.
  137. * WARNING: They won't work in assembler.
  138. *
  139. * BDDIR_ENTRY_LO returns the address of the low double-word of the dir
  140. * entry corresponding to a physical (Cac or Uncac) address.
  141. * BDDIR_ENTRY_HI returns the address of the high double-word of the entry.
  142. * BDPRT_ENTRY returns the address of the double-word protection entry
  143. * corresponding to the page containing the physical address.
  144. * BDPRT_ENTRY_S Stores the value into the protection entry.
  145. * BDPRT_ENTRY_L Load the value from the protection entry.
  146. * BDECC_ENTRY returns the address of the ECC byte corresponding to a
  147. * double-word at a specified physical address.
  148. * BDECC_ENTRY_H returns the address of the two ECC bytes corresponding to a
  149. * quad-word at a specified physical address.
  150. */
  151. #define NODE_BDOOR_BASE(_n) (NODE_HSPEC_BASE(_n) + (NODE_ADDRSPACE_SIZE/2))
  152. #define NODE_BDECC_BASE(_n) (NODE_BDOOR_BASE(_n))
  153. #define NODE_BDDIR_BASE(_n) (NODE_BDOOR_BASE(_n) + (NODE_ADDRSPACE_SIZE/4))
  154. #ifdef CONFIG_SGI_IP27
  155. #define BDDIR_ENTRY_LO(_pa) ((HSPEC_BASE + \
  156. NODE_ADDRSPACE_SIZE * 3 / 4 + \
  157. 0x200) | \
  158. UINT64_CAST(_pa) & NASID_MASK | \
  159. UINT64_CAST(_pa) >> 2 & BDDIR_UPPER_MASK | \
  160. UINT64_CAST(_pa) >> 3 & 0x1f << 4)
  161. #define BDDIR_ENTRY_HI(_pa) ((HSPEC_BASE + \
  162. NODE_ADDRSPACE_SIZE * 3 / 4 + \
  163. 0x208) | \
  164. UINT64_CAST(_pa) & NASID_MASK | \
  165. UINT64_CAST(_pa) >> 2 & BDDIR_UPPER_MASK | \
  166. UINT64_CAST(_pa) >> 3 & 0x1f << 4)
  167. #define BDPRT_ENTRY(_pa, _rgn) ((HSPEC_BASE + \
  168. NODE_ADDRSPACE_SIZE * 3 / 4) | \
  169. UINT64_CAST(_pa) & NASID_MASK | \
  170. UINT64_CAST(_pa) >> 2 & BDDIR_UPPER_MASK | \
  171. (_rgn) << 3)
  172. #define BDPRT_ENTRY_ADDR(_pa, _rgn) (BDPRT_ENTRY((_pa), (_rgn)))
  173. #define BDPRT_ENTRY_S(_pa, _rgn, _val) (*(__psunsigned_t *)BDPRT_ENTRY((_pa), (_rgn))=(_val))
  174. #define BDPRT_ENTRY_L(_pa, _rgn) (*(__psunsigned_t *)BDPRT_ENTRY((_pa), (_rgn)))
  175. #define BDECC_ENTRY(_pa) ((HSPEC_BASE + \
  176. NODE_ADDRSPACE_SIZE / 2) | \
  177. UINT64_CAST(_pa) & NASID_MASK | \
  178. UINT64_CAST(_pa) >> 2 & BDECC_UPPER_MASK | \
  179. UINT64_CAST(_pa) >> 3 & 3)
  180. /*
  181. * Macro to convert a back door directory or protection address into the
  182. * raw physical address of the associated cache line or protection page.
  183. */
  184. #define BDADDR_IS_DIR(_ba) ((UINT64_CAST (_ba) & 0x200) != 0)
  185. #define BDADDR_IS_PRT(_ba) ((UINT64_CAST (_ba) & 0x200) == 0)
  186. #define BDDIR_TO_MEM(_ba) (UINT64_CAST (_ba) & NASID_MASK | \
  187. (UINT64_CAST(_ba) & BDDIR_UPPER_MASK)<<2 | \
  188. (UINT64_CAST(_ba) & 0x1f << 4) << 3)
  189. #define BDPRT_TO_MEM(_ba) (UINT64_CAST (_ba) & NASID_MASK | \
  190. (UINT64_CAST(_ba) & BDDIR_UPPER_MASK)<<2)
  191. #define BDECC_TO_MEM(_ba) (UINT64_CAST (_ba) & NASID_MASK | \
  192. (UINT64_CAST(_ba) & BDECC_UPPER_MASK)<<2 | \
  193. (UINT64_CAST(_ba) & 3) << 3)
  194. #endif /* CONFIG_SGI_IP27 */
  195. /*
  196. * The following macros produce the correct base virtual address for
  197. * the hub registers. The LOCAL_HUB_* macros produce the appropriate
  198. * address for the local registers. The REMOTE_HUB_* macro produce
  199. * the address for the specified hub's registers. The intent is
  200. * that the appropriate PI, MD, NI, or II register would be substituted
  201. * for _x.
  202. */
  203. /*
  204. * WARNING:
  205. * When certain Hub chip workaround are defined, it's not sufficient
  206. * to dereference the *_HUB_ADDR() macros. You should instead use
  207. * HUB_L() and HUB_S() if you must deal with pointers to hub registers.
  208. * Otherwise, the recommended approach is to use *_HUB_L() and *_HUB_S().
  209. * They're always safe.
  210. */
  211. #define LOCAL_HUB_ADDR(_x) (HUBREG_CAST (IALIAS_BASE + (_x)))
  212. #define REMOTE_HUB_ADDR(_n, _x) (HUBREG_CAST (NODE_SWIN_BASE(_n, 1) + \
  213. 0x800000 + (_x)))
  214. #ifdef CONFIG_SGI_IP27
  215. #define REMOTE_HUB_PI_ADDR(_n, _sn, _x) (HUBREG_CAST (NODE_SWIN_BASE(_n, 1) + \
  216. 0x800000 + (_x)))
  217. #endif /* CONFIG_SGI_IP27 */
  218. #ifndef __ASSEMBLY__
  219. #define HUB_L(_a) *(_a)
  220. #define HUB_S(_a, _d) *(_a) = (_d)
  221. #define LOCAL_HUB_L(_r) HUB_L(LOCAL_HUB_ADDR(_r))
  222. #define LOCAL_HUB_S(_r, _d) HUB_S(LOCAL_HUB_ADDR(_r), (_d))
  223. #define REMOTE_HUB_L(_n, _r) HUB_L(REMOTE_HUB_ADDR((_n), (_r)))
  224. #define REMOTE_HUB_S(_n, _r, _d) HUB_S(REMOTE_HUB_ADDR((_n), (_r)), (_d))
  225. #define REMOTE_HUB_PI_L(_n, _sn, _r) HUB_L(REMOTE_HUB_PI_ADDR((_n), (_sn), (_r)))
  226. #define REMOTE_HUB_PI_S(_n, _sn, _r, _d) HUB_S(REMOTE_HUB_PI_ADDR((_n), (_sn), (_r)), (_d))
  227. #endif /* !__ASSEMBLY__ */
  228. /*
  229. * The following macros are used to get to a hub/bridge register, given
  230. * the base of the register space.
  231. */
  232. #define HUB_REG_PTR(_base, _off) \
  233. (HUBREG_CAST((__psunsigned_t)(_base) + (__psunsigned_t)(_off)))
  234. #define HUB_REG_PTR_L(_base, _off) \
  235. HUB_L(HUB_REG_PTR((_base), (_off)))
  236. #define HUB_REG_PTR_S(_base, _off, _data) \
  237. HUB_S(HUB_REG_PTR((_base), (_off)), (_data))
  238. /*
  239. * Software structure locations -- permanently fixed
  240. * See diagram in kldir.h
  241. */
  242. #define PHYS_RAMBASE 0x0
  243. #define K0_RAMBASE PHYS_TO_K0(PHYS_RAMBASE)
  244. #define EX_HANDLER_OFFSET(slice) ((slice) << 16)
  245. #define EX_HANDLER_ADDR(nasid, slice) \
  246. PHYS_TO_K0(NODE_OFFSET(nasid) | EX_HANDLER_OFFSET(slice))
  247. #define EX_HANDLER_SIZE 0x0400
  248. #define EX_FRAME_OFFSET(slice) ((slice) << 16 | 0x400)
  249. #define EX_FRAME_ADDR(nasid, slice) \
  250. PHYS_TO_K0(NODE_OFFSET(nasid) | EX_FRAME_OFFSET(slice))
  251. #define EX_FRAME_SIZE 0x0c00
  252. #define ARCS_SPB_OFFSET 0x1000
  253. #define ARCS_SPB_ADDR(nasid) \
  254. PHYS_TO_K0(NODE_OFFSET(nasid) | ARCS_SPB_OFFSET)
  255. #define ARCS_SPB_SIZE 0x0400
  256. #define KLDIR_OFFSET 0x2000
  257. #define KLDIR_ADDR(nasid) \
  258. TO_NODE_UNCAC((nasid), KLDIR_OFFSET)
  259. #define KLDIR_SIZE 0x0400
  260. /*
  261. * Software structure locations -- indirected through KLDIR
  262. * See diagram in kldir.h
  263. *
  264. * Important: All low memory structures must only be accessed
  265. * uncached, except for the symmon stacks.
  266. */
  267. #define KLI_LAUNCH 0 /* Dir. entries */
  268. #define KLI_KLCONFIG 1
  269. #define KLI_NMI 2
  270. #define KLI_GDA 3
  271. #define KLI_FREEMEM 4
  272. #define KLI_SYMMON_STK 5
  273. #define KLI_PI_ERROR 6
  274. #define KLI_KERN_VARS 7
  275. #define KLI_KERN_XP 8
  276. #define KLI_KERN_PARTID 9
  277. #ifndef __ASSEMBLY__
  278. #define KLD_BASE(nasid) ((kldir_ent_t *) KLDIR_ADDR(nasid))
  279. #define KLD_LAUNCH(nasid) (KLD_BASE(nasid) + KLI_LAUNCH)
  280. #define KLD_NMI(nasid) (KLD_BASE(nasid) + KLI_NMI)
  281. #define KLD_KLCONFIG(nasid) (KLD_BASE(nasid) + KLI_KLCONFIG)
  282. #define KLD_PI_ERROR(nasid) (KLD_BASE(nasid) + KLI_PI_ERROR)
  283. #define KLD_GDA(nasid) (KLD_BASE(nasid) + KLI_GDA)
  284. #define KLD_SYMMON_STK(nasid) (KLD_BASE(nasid) + KLI_SYMMON_STK)
  285. #define KLD_FREEMEM(nasid) (KLD_BASE(nasid) + KLI_FREEMEM)
  286. #define KLD_KERN_VARS(nasid) (KLD_BASE(nasid) + KLI_KERN_VARS)
  287. #define KLD_KERN_XP(nasid) (KLD_BASE(nasid) + KLI_KERN_XP)
  288. #define KLD_KERN_PARTID(nasid) (KLD_BASE(nasid) + KLI_KERN_PARTID)
  289. #define LAUNCH_OFFSET(nasid, slice) \
  290. (KLD_LAUNCH(nasid)->offset + \
  291. KLD_LAUNCH(nasid)->stride * (slice))
  292. #define LAUNCH_ADDR(nasid, slice) \
  293. TO_NODE_UNCAC((nasid), LAUNCH_OFFSET(nasid, slice))
  294. #define LAUNCH_SIZE(nasid) KLD_LAUNCH(nasid)->size
  295. #define SN_NMI_OFFSET(nasid, slice) \
  296. (KLD_NMI(nasid)->offset + \
  297. KLD_NMI(nasid)->stride * (slice))
  298. #define NMI_ADDR(nasid, slice) \
  299. TO_NODE_UNCAC((nasid), SN_NMI_OFFSET(nasid, slice))
  300. #define NMI_SIZE(nasid) KLD_NMI(nasid)->size
  301. #define KLCONFIG_OFFSET(nasid) KLD_KLCONFIG(nasid)->offset
  302. #define KLCONFIG_ADDR(nasid) \
  303. TO_NODE_UNCAC((nasid), KLCONFIG_OFFSET(nasid))
  304. #define KLCONFIG_SIZE(nasid) KLD_KLCONFIG(nasid)->size
  305. #define GDA_ADDR(nasid) KLD_GDA(nasid)->pointer
  306. #define GDA_SIZE(nasid) KLD_GDA(nasid)->size
  307. #define SYMMON_STK_OFFSET(nasid, slice) \
  308. (KLD_SYMMON_STK(nasid)->offset + \
  309. KLD_SYMMON_STK(nasid)->stride * (slice))
  310. #define SYMMON_STK_STRIDE(nasid) KLD_SYMMON_STK(nasid)->stride
  311. #define SYMMON_STK_ADDR(nasid, slice) \
  312. TO_NODE_CAC((nasid), SYMMON_STK_OFFSET(nasid, slice))
  313. #define SYMMON_STK_SIZE(nasid) KLD_SYMMON_STK(nasid)->stride
  314. #define SYMMON_STK_END(nasid) (SYMMON_STK_ADDR(nasid, 0) + KLD_SYMMON_STK(nasid)->size)
  315. /* loading symmon 4k below UNIX. the arcs loader needs the topaddr for a
  316. * relocatable program
  317. */
  318. #define UNIX_DEBUG_LOADADDR 0x300000
  319. #define SYMMON_LOADADDR(nasid) \
  320. TO_NODE(nasid, PHYS_TO_K0(UNIX_DEBUG_LOADADDR - 0x1000))
  321. #define FREEMEM_OFFSET(nasid) KLD_FREEMEM(nasid)->offset
  322. #define FREEMEM_ADDR(nasid) SYMMON_STK_END(nasid)
  323. /*
  324. * XXX
  325. * Fix this. FREEMEM_ADDR should be aware of if symmon is loaded.
  326. * Also, it should take into account what prom thinks to be a safe
  327. * address
  328. PHYS_TO_K0(NODE_OFFSET(nasid) + FREEMEM_OFFSET(nasid))
  329. */
  330. #define FREEMEM_SIZE(nasid) KLD_FREEMEM(nasid)->size
  331. #define PI_ERROR_OFFSET(nasid) KLD_PI_ERROR(nasid)->offset
  332. #define PI_ERROR_ADDR(nasid) \
  333. TO_NODE_UNCAC((nasid), PI_ERROR_OFFSET(nasid))
  334. #define PI_ERROR_SIZE(nasid) KLD_PI_ERROR(nasid)->size
  335. #define NODE_OFFSET_TO_K0(_nasid, _off) \
  336. PHYS_TO_K0((NODE_OFFSET(_nasid) + (_off)) | CAC_BASE)
  337. #define NODE_OFFSET_TO_K1(_nasid, _off) \
  338. TO_UNCAC((NODE_OFFSET(_nasid) + (_off)) | UNCAC_BASE)
  339. #define K0_TO_NODE_OFFSET(_k0addr) \
  340. ((__psunsigned_t)(_k0addr) & NODE_ADDRSPACE_MASK)
  341. #define KERN_VARS_ADDR(nasid) KLD_KERN_VARS(nasid)->pointer
  342. #define KERN_VARS_SIZE(nasid) KLD_KERN_VARS(nasid)->size
  343. #define KERN_XP_ADDR(nasid) KLD_KERN_XP(nasid)->pointer
  344. #define KERN_XP_SIZE(nasid) KLD_KERN_XP(nasid)->size
  345. #define GPDA_ADDR(nasid) TO_NODE_CAC(nasid, GPDA_OFFSET)
  346. #endif /* !__ASSEMBLY__ */
  347. #endif /* _ASM_SN_ADDRS_H */