addrs.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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-1999,2001-2005 Silicon Graphics, Inc. All rights reserved.
  7. */
  8. #ifndef _ASM_IA64_SN_ADDRS_H
  9. #define _ASM_IA64_SN_ADDRS_H
  10. #include <asm/percpu.h>
  11. #include <asm/sn/types.h>
  12. #include <asm/sn/arch.h>
  13. #include <asm/sn/pda.h>
  14. /*
  15. * Memory/SHUB Address Format:
  16. * +-+---------+--+--------------+
  17. * |0| NASID |AS| NodeOffset |
  18. * +-+---------+--+--------------+
  19. *
  20. * NASID: (low NASID bit is 0) Memory and SHUB MMRs
  21. * AS: 2-bit Address Space Identifier. Used only if low NASID bit is 0
  22. * 00: Local Resources and MMR space
  23. * Top bit of NodeOffset
  24. * 0: Local resources space
  25. * node id:
  26. * 0: IA64/NT compatibility space
  27. * 2: Local MMR Space
  28. * 4: Local memory, regardless of local node id
  29. * 1: Global MMR space
  30. * 01: GET space.
  31. * 10: AMO space.
  32. * 11: Cacheable memory space.
  33. *
  34. * NodeOffset: byte offset
  35. *
  36. *
  37. * TIO address format:
  38. * +-+----------+--+--------------+
  39. * |0| NASID |AS| Nodeoffset |
  40. * +-+----------+--+--------------+
  41. *
  42. * NASID: (low NASID bit is 1) TIO
  43. * AS: 2-bit Chiplet Identifier
  44. * 00: TIO LB (Indicates TIO MMR access.)
  45. * 01: TIO ICE (indicates coretalk space access.)
  46. *
  47. * NodeOffset: top bit must be set.
  48. *
  49. *
  50. * Note that in both of the above address formats, the low
  51. * NASID bit indicates if the reference is to the SHUB or TIO MMRs.
  52. */
  53. /*
  54. * Define basic shift & mask constants for manipulating NASIDs and AS values.
  55. */
  56. #define NASID_BITMASK (sn_hub_info->nasid_bitmask)
  57. #define NASID_SHIFT (sn_hub_info->nasid_shift)
  58. #define AS_SHIFT (sn_hub_info->as_shift)
  59. #define AS_BITMASK 0x3UL
  60. #define NASID_MASK ((u64)NASID_BITMASK << NASID_SHIFT)
  61. #define AS_MASK ((u64)AS_BITMASK << AS_SHIFT)
  62. /*
  63. * AS values. These are the same on both SHUB1 & SHUB2.
  64. */
  65. #define AS_GET_VAL 1UL
  66. #define AS_AMO_VAL 2UL
  67. #define AS_CAC_VAL 3UL
  68. #define AS_GET_SPACE (AS_GET_VAL << AS_SHIFT)
  69. #define AS_AMO_SPACE (AS_AMO_VAL << AS_SHIFT)
  70. #define AS_CAC_SPACE (AS_CAC_VAL << AS_SHIFT)
  71. /*
  72. * Virtual Mode Local & Global MMR space.
  73. */
  74. #define SH1_LOCAL_MMR_OFFSET 0x8000000000UL
  75. #define SH2_LOCAL_MMR_OFFSET 0x0200000000UL
  76. #define LOCAL_MMR_OFFSET (is_shub2() ? SH2_LOCAL_MMR_OFFSET : SH1_LOCAL_MMR_OFFSET)
  77. #define LOCAL_MMR_SPACE (__IA64_UNCACHED_OFFSET | LOCAL_MMR_OFFSET)
  78. #define LOCAL_PHYS_MMR_SPACE (RGN_BASE(RGN_HPAGE) | LOCAL_MMR_OFFSET)
  79. #define SH1_GLOBAL_MMR_OFFSET 0x0800000000UL
  80. #define SH2_GLOBAL_MMR_OFFSET 0x0300000000UL
  81. #define GLOBAL_MMR_OFFSET (is_shub2() ? SH2_GLOBAL_MMR_OFFSET : SH1_GLOBAL_MMR_OFFSET)
  82. #define GLOBAL_MMR_SPACE (__IA64_UNCACHED_OFFSET | GLOBAL_MMR_OFFSET)
  83. /*
  84. * Physical mode addresses
  85. */
  86. #define GLOBAL_PHYS_MMR_SPACE (RGN_BASE(RGN_HPAGE) | GLOBAL_MMR_OFFSET)
  87. /*
  88. * Clear region & AS bits.
  89. */
  90. #define TO_PHYS_MASK (~(RGN_BITS | AS_MASK))
  91. /*
  92. * Misc NASID manipulation.
  93. */
  94. #define NASID_SPACE(n) ((u64)(n) << NASID_SHIFT)
  95. #define REMOTE_ADDR(n,a) (NASID_SPACE(n) | (a))
  96. #define NODE_OFFSET(x) ((x) & (NODE_ADDRSPACE_SIZE - 1))
  97. #define NODE_ADDRSPACE_SIZE (1UL << AS_SHIFT)
  98. #define NASID_GET(x) (int) (((u64) (x) >> NASID_SHIFT) & NASID_BITMASK)
  99. #define LOCAL_MMR_ADDR(a) (LOCAL_MMR_SPACE | (a))
  100. #define GLOBAL_MMR_ADDR(n,a) (GLOBAL_MMR_SPACE | REMOTE_ADDR(n,a))
  101. #define GLOBAL_MMR_PHYS_ADDR(n,a) (GLOBAL_PHYS_MMR_SPACE | REMOTE_ADDR(n,a))
  102. #define GLOBAL_CAC_ADDR(n,a) (CAC_BASE | REMOTE_ADDR(n,a))
  103. #define CHANGE_NASID(n,x) ((void *)(((u64)(x) & ~NASID_MASK) | NASID_SPACE(n)))
  104. #define IS_TIO_NASID(n) ((n) & 1)
  105. /* non-II mmr's start at top of big window space (4G) */
  106. #define BWIN_TOP 0x0000000100000000UL
  107. /*
  108. * general address defines
  109. */
  110. #define CAC_BASE (PAGE_OFFSET | AS_CAC_SPACE)
  111. #define AMO_BASE (__IA64_UNCACHED_OFFSET | AS_AMO_SPACE)
  112. #define AMO_PHYS_BASE (RGN_BASE(RGN_HPAGE) | AS_AMO_SPACE)
  113. #define GET_BASE (PAGE_OFFSET | AS_GET_SPACE)
  114. /*
  115. * Convert Memory addresses between various addressing modes.
  116. */
  117. #define TO_PHYS(x) (TO_PHYS_MASK & (x))
  118. #define TO_CAC(x) (CAC_BASE | TO_PHYS(x))
  119. #ifdef CONFIG_SGI_SN
  120. #define TO_AMO(x) (AMO_BASE | TO_PHYS(x))
  121. #define TO_GET(x) (GET_BASE | TO_PHYS(x))
  122. #else
  123. #define TO_AMO(x) ({ BUG(); x; })
  124. #define TO_GET(x) ({ BUG(); x; })
  125. #endif
  126. /*
  127. * Covert from processor physical address to II/TIO physical address:
  128. * II - squeeze out the AS bits
  129. * TIO- requires a chiplet id in bits 38-39. For DMA to memory,
  130. * the chiplet id is zero. If we implement TIO-TIO dma, we might need
  131. * to insert a chiplet id into this macro. However, it is our belief
  132. * right now that this chiplet id will be ICE, which is also zero.
  133. */
  134. #define SH1_TIO_PHYS_TO_DMA(x) \
  135. ((((u64)(NASID_GET(x))) << 40) | NODE_OFFSET(x))
  136. #define SH2_NETWORK_BANK_OFFSET(x) \
  137. ((u64)(x) & ((1UL << (sn_hub_info->nasid_shift - 4)) -1))
  138. #define SH2_NETWORK_BANK_SELECT(x) \
  139. ((((u64)(x) & (0x3UL << (sn_hub_info->nasid_shift - 4))) \
  140. >> (sn_hub_info->nasid_shift - 4)) << 36)
  141. #define SH2_NETWORK_ADDRESS(x) \
  142. (SH2_NETWORK_BANK_OFFSET(x) | SH2_NETWORK_BANK_SELECT(x))
  143. #define SH2_TIO_PHYS_TO_DMA(x) \
  144. (((u64)(NASID_GET(x)) << 40) | SH2_NETWORK_ADDRESS(x))
  145. #define PHYS_TO_TIODMA(x) \
  146. (is_shub1() ? SH1_TIO_PHYS_TO_DMA(x) : SH2_TIO_PHYS_TO_DMA(x))
  147. #define PHYS_TO_DMA(x) \
  148. ((((u64)(x) & NASID_MASK) >> 2) | NODE_OFFSET(x))
  149. /*
  150. * Macros to test for address type.
  151. */
  152. #define IS_AMO_ADDRESS(x) (((u64)(x) & (RGN_BITS | AS_MASK)) == AMO_BASE)
  153. #define IS_AMO_PHYS_ADDRESS(x) (((u64)(x) & (RGN_BITS | AS_MASK)) == AMO_PHYS_BASE)
  154. /*
  155. * The following definitions pertain to the IO special address
  156. * space. They define the location of the big and little windows
  157. * of any given node.
  158. */
  159. #define BWIN_SIZE_BITS 29 /* big window size: 512M */
  160. #define TIO_BWIN_SIZE_BITS 30 /* big window size: 1G */
  161. #define NODE_SWIN_BASE(n, w) ((w == 0) ? NODE_BWIN_BASE((n), SWIN0_BIGWIN) \
  162. : RAW_NODE_SWIN_BASE(n, w))
  163. #define TIO_SWIN_BASE(n, w) (TIO_IO_BASE(n) + \
  164. ((u64) (w) << TIO_SWIN_SIZE_BITS))
  165. #define NODE_IO_BASE(n) (GLOBAL_MMR_SPACE | NASID_SPACE(n))
  166. #define TIO_IO_BASE(n) (__IA64_UNCACHED_OFFSET | NASID_SPACE(n))
  167. #define BWIN_SIZE (1UL << BWIN_SIZE_BITS)
  168. #define NODE_BWIN_BASE0(n) (NODE_IO_BASE(n) + BWIN_SIZE)
  169. #define NODE_BWIN_BASE(n, w) (NODE_BWIN_BASE0(n) + ((u64) (w) << BWIN_SIZE_BITS))
  170. #define RAW_NODE_SWIN_BASE(n, w) (NODE_IO_BASE(n) + ((u64) (w) << SWIN_SIZE_BITS))
  171. #define BWIN_WIDGET_MASK 0x7
  172. #define BWIN_WINDOWNUM(x) (((x) >> BWIN_SIZE_BITS) & BWIN_WIDGET_MASK)
  173. #define SH1_IS_BIG_WINDOW_ADDR(x) ((x) & BWIN_TOP)
  174. #define TIO_BWIN_WINDOW_SELECT_MASK 0x7
  175. #define TIO_BWIN_WINDOWNUM(x) (((x) >> TIO_BWIN_SIZE_BITS) & TIO_BWIN_WINDOW_SELECT_MASK)
  176. #define TIO_HWIN_SHIFT_BITS 33
  177. #define TIO_HWIN(x) (NODE_OFFSET(x) >> TIO_HWIN_SHIFT_BITS)
  178. /*
  179. * The following definitions pertain to the IO special address
  180. * space. They define the location of the big and little windows
  181. * of any given node.
  182. */
  183. #define SWIN_SIZE_BITS 24
  184. #define SWIN_WIDGET_MASK 0xF
  185. #define TIO_SWIN_SIZE_BITS 28
  186. #define TIO_SWIN_SIZE (1UL << TIO_SWIN_SIZE_BITS)
  187. #define TIO_SWIN_WIDGET_MASK 0x3
  188. /*
  189. * Convert smallwindow address to xtalk address.
  190. *
  191. * 'addr' can be physical or virtual address, but will be converted
  192. * to Xtalk address in the range 0 -> SWINZ_SIZEMASK
  193. */
  194. #define SWIN_WIDGETNUM(x) (((x) >> SWIN_SIZE_BITS) & SWIN_WIDGET_MASK)
  195. #define TIO_SWIN_WIDGETNUM(x) (((x) >> TIO_SWIN_SIZE_BITS) & TIO_SWIN_WIDGET_MASK)
  196. /*
  197. * The following macros produce the correct base virtual address for
  198. * the hub 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. * WARNING:
  204. * When certain Hub chip workaround are defined, it's not sufficient
  205. * to dereference the *_HUB_ADDR() macros. You should instead use
  206. * HUB_L() and HUB_S() if you must deal with pointers to hub registers.
  207. * Otherwise, the recommended approach is to use *_HUB_L() and *_HUB_S().
  208. * They're always safe.
  209. */
  210. /* Shub1 TIO & MMR addressing macros */
  211. #define SH1_TIO_IOSPACE_ADDR(n,x) \
  212. GLOBAL_MMR_ADDR(n,x)
  213. #define SH1_REMOTE_BWIN_MMR(n,x) \
  214. GLOBAL_MMR_ADDR(n,x)
  215. #define SH1_REMOTE_SWIN_MMR(n,x) \
  216. (NODE_SWIN_BASE(n,1) + 0x800000UL + (x))
  217. #define SH1_REMOTE_MMR(n,x) \
  218. (SH1_IS_BIG_WINDOW_ADDR(x) ? SH1_REMOTE_BWIN_MMR(n,x) : \
  219. SH1_REMOTE_SWIN_MMR(n,x))
  220. /* Shub1 TIO & MMR addressing macros */
  221. #define SH2_TIO_IOSPACE_ADDR(n,x) \
  222. ((__IA64_UNCACHED_OFFSET | REMOTE_ADDR(n,x) | 1UL << (NASID_SHIFT - 2)))
  223. #define SH2_REMOTE_MMR(n,x) \
  224. GLOBAL_MMR_ADDR(n,x)
  225. /* TIO & MMR addressing macros that work on both shub1 & shub2 */
  226. #define TIO_IOSPACE_ADDR(n,x) \
  227. ((u64 *)(is_shub1() ? SH1_TIO_IOSPACE_ADDR(n,x) : \
  228. SH2_TIO_IOSPACE_ADDR(n,x)))
  229. #define SH_REMOTE_MMR(n,x) \
  230. (is_shub1() ? SH1_REMOTE_MMR(n,x) : SH2_REMOTE_MMR(n,x))
  231. #define REMOTE_HUB_ADDR(n,x) \
  232. (IS_TIO_NASID(n) ? ((volatile u64*)TIO_IOSPACE_ADDR(n,x)) : \
  233. ((volatile u64*)SH_REMOTE_MMR(n,x)))
  234. #define HUB_L(x) (*((volatile typeof(*x) *)x))
  235. #define HUB_S(x,d) (*((volatile typeof(*x) *)x) = (d))
  236. #define REMOTE_HUB_L(n, a) HUB_L(REMOTE_HUB_ADDR((n), (a)))
  237. #define REMOTE_HUB_S(n, a, d) HUB_S(REMOTE_HUB_ADDR((n), (a)), (d))
  238. /*
  239. * Coretalk address breakdown
  240. */
  241. #define CTALK_NASID_SHFT 40
  242. #define CTALK_NASID_MASK (0x3FFFULL << CTALK_NASID_SHFT)
  243. #define CTALK_CID_SHFT 38
  244. #define CTALK_CID_MASK (0x3ULL << CTALK_CID_SHFT)
  245. #define CTALK_NODE_OFFSET 0x3FFFFFFFFF
  246. #endif /* _ASM_IA64_SN_ADDRS_H */