addrs.h 13 KB

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