addrs.h 14 KB

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