uv_hub.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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. * SGI UV architectural definitions
  7. *
  8. * Copyright (C) 2007-2008 Silicon Graphics, Inc. All rights reserved.
  9. */
  10. #ifndef _ASM_X86_UV_UV_HUB_H
  11. #define _ASM_X86_UV_UV_HUB_H
  12. #include <linux/numa.h>
  13. #include <linux/percpu.h>
  14. #include <linux/timer.h>
  15. #include <asm/types.h>
  16. #include <asm/percpu.h>
  17. /*
  18. * Addressing Terminology
  19. *
  20. * M - The low M bits of a physical address represent the offset
  21. * into the blade local memory. RAM memory on a blade is physically
  22. * contiguous (although various IO spaces may punch holes in
  23. * it)..
  24. *
  25. * N - Number of bits in the node portion of a socket physical
  26. * address.
  27. *
  28. * NASID - network ID of a router, Mbrick or Cbrick. Nasid values of
  29. * routers always have low bit of 1, C/MBricks have low bit
  30. * equal to 0. Most addressing macros that target UV hub chips
  31. * right shift the NASID by 1 to exclude the always-zero bit.
  32. * NASIDs contain up to 15 bits.
  33. *
  34. * GNODE - NASID right shifted by 1 bit. Most mmrs contain gnodes instead
  35. * of nasids.
  36. *
  37. * PNODE - the low N bits of the GNODE. The PNODE is the most useful variant
  38. * of the nasid for socket usage.
  39. *
  40. *
  41. * NumaLink Global Physical Address Format:
  42. * +--------------------------------+---------------------+
  43. * |00..000| GNODE | NodeOffset |
  44. * +--------------------------------+---------------------+
  45. * |<-------53 - M bits --->|<--------M bits ----->
  46. *
  47. * M - number of node offset bits (35 .. 40)
  48. *
  49. *
  50. * Memory/UV-HUB Processor Socket Address Format:
  51. * +----------------+---------------+---------------------+
  52. * |00..000000000000| PNODE | NodeOffset |
  53. * +----------------+---------------+---------------------+
  54. * <--- N bits --->|<--------M bits ----->
  55. *
  56. * M - number of node offset bits (35 .. 40)
  57. * N - number of PNODE bits (0 .. 10)
  58. *
  59. * Note: M + N cannot currently exceed 44 (x86_64) or 46 (IA64).
  60. * The actual values are configuration dependent and are set at
  61. * boot time. M & N values are set by the hardware/BIOS at boot.
  62. *
  63. *
  64. * APICID format
  65. * NOTE!!!!!! This is the current format of the APICID. However, code
  66. * should assume that this will change in the future. Use functions
  67. * in this file for all APICID bit manipulations and conversion.
  68. *
  69. * 1111110000000000
  70. * 5432109876543210
  71. * pppppppppplc0cch
  72. * sssssssssss
  73. *
  74. * p = pnode bits
  75. * l = socket number on board
  76. * c = core
  77. * h = hyperthread
  78. * s = bits that are in the SOCKET_ID CSR
  79. *
  80. * Note: Processor only supports 12 bits in the APICID register. The ACPI
  81. * tables hold all 16 bits. Software needs to be aware of this.
  82. *
  83. * Unless otherwise specified, all references to APICID refer to
  84. * the FULL value contained in ACPI tables, not the subset in the
  85. * processor APICID register.
  86. */
  87. /*
  88. * Maximum number of bricks in all partitions and in all coherency domains.
  89. * This is the total number of bricks accessible in the numalink fabric. It
  90. * includes all C & M bricks. Routers are NOT included.
  91. *
  92. * This value is also the value of the maximum number of non-router NASIDs
  93. * in the numalink fabric.
  94. *
  95. * NOTE: a brick may contain 1 or 2 OS nodes. Don't get these confused.
  96. */
  97. #define UV_MAX_NUMALINK_BLADES 16384
  98. /*
  99. * Maximum number of C/Mbricks within a software SSI (hardware may support
  100. * more).
  101. */
  102. #define UV_MAX_SSI_BLADES 256
  103. /*
  104. * The largest possible NASID of a C or M brick (+ 2)
  105. */
  106. #define UV_MAX_NASID_VALUE (UV_MAX_NUMALINK_NODES * 2)
  107. struct uv_scir_s {
  108. struct timer_list timer;
  109. unsigned long offset;
  110. unsigned long last;
  111. unsigned long idle_on;
  112. unsigned long idle_off;
  113. unsigned char state;
  114. unsigned char enabled;
  115. };
  116. /*
  117. * The following defines attributes of the HUB chip. These attributes are
  118. * frequently referenced and are kept in the per-cpu data areas of each cpu.
  119. * They are kept together in a struct to minimize cache misses.
  120. */
  121. struct uv_hub_info_s {
  122. unsigned long global_mmr_base;
  123. unsigned long gpa_mask;
  124. unsigned long gnode_upper;
  125. unsigned long lowmem_remap_top;
  126. unsigned long lowmem_remap_base;
  127. unsigned short pnode;
  128. unsigned short pnode_mask;
  129. unsigned short coherency_domain_number;
  130. unsigned short numa_blade_id;
  131. unsigned char blade_processor_id;
  132. unsigned char m_val;
  133. unsigned char n_val;
  134. struct uv_scir_s scir;
  135. };
  136. DECLARE_PER_CPU(struct uv_hub_info_s, __uv_hub_info);
  137. #define uv_hub_info (&__get_cpu_var(__uv_hub_info))
  138. #define uv_cpu_hub_info(cpu) (&per_cpu(__uv_hub_info, cpu))
  139. /*
  140. * Local & Global MMR space macros.
  141. * Note: macros are intended to be used ONLY by inline functions
  142. * in this file - not by other kernel code.
  143. * n - NASID (full 15-bit global nasid)
  144. * g - GNODE (full 15-bit global nasid, right shifted 1)
  145. * p - PNODE (local part of nsids, right shifted 1)
  146. */
  147. #define UV_NASID_TO_PNODE(n) (((n) >> 1) & uv_hub_info->pnode_mask)
  148. #define UV_PNODE_TO_NASID(p) (((p) << 1) | uv_hub_info->gnode_upper)
  149. #define UV_LOCAL_MMR_BASE 0xf4000000UL
  150. #define UV_GLOBAL_MMR32_BASE 0xf8000000UL
  151. #define UV_GLOBAL_MMR64_BASE (uv_hub_info->global_mmr_base)
  152. #define UV_LOCAL_MMR_SIZE (64UL * 1024 * 1024)
  153. #define UV_GLOBAL_MMR32_SIZE (64UL * 1024 * 1024)
  154. #define UV_GLOBAL_MMR32_PNODE_SHIFT 15
  155. #define UV_GLOBAL_MMR64_PNODE_SHIFT 26
  156. #define UV_GLOBAL_MMR32_PNODE_BITS(p) ((p) << (UV_GLOBAL_MMR32_PNODE_SHIFT))
  157. #define UV_GLOBAL_MMR64_PNODE_BITS(p) \
  158. ((unsigned long)(p) << UV_GLOBAL_MMR64_PNODE_SHIFT)
  159. #define UV_APIC_PNODE_SHIFT 6
  160. /* Local Bus from cpu's perspective */
  161. #define LOCAL_BUS_BASE 0x1c00000
  162. #define LOCAL_BUS_SIZE (4 * 1024 * 1024)
  163. /*
  164. * System Controller Interface Reg
  165. *
  166. * Note there are NO leds on a UV system. This register is only
  167. * used by the system controller to monitor system-wide operation.
  168. * There are 64 regs per node. With Nahelem cpus (2 cores per node,
  169. * 8 cpus per core, 2 threads per cpu) there are 32 cpu threads on
  170. * a node.
  171. *
  172. * The window is located at top of ACPI MMR space
  173. */
  174. #define SCIR_WINDOW_COUNT 64
  175. #define SCIR_LOCAL_MMR_BASE (LOCAL_BUS_BASE + \
  176. LOCAL_BUS_SIZE - \
  177. SCIR_WINDOW_COUNT)
  178. #define SCIR_CPU_HEARTBEAT 0x01 /* timer interrupt */
  179. #define SCIR_CPU_ACTIVITY 0x02 /* not idle */
  180. #define SCIR_CPU_HB_INTERVAL (HZ) /* once per second */
  181. /* Loop through all installed blades */
  182. #define for_each_possible_blade(bid) \
  183. for ((bid) = 0; (bid) < uv_num_possible_blades(); (bid)++)
  184. /*
  185. * Macros for converting between kernel virtual addresses, socket local physical
  186. * addresses, and UV global physical addresses.
  187. * Note: use the standard __pa() & __va() macros for converting
  188. * between socket virtual and socket physical addresses.
  189. */
  190. /* socket phys RAM --> UV global physical address */
  191. static inline unsigned long uv_soc_phys_ram_to_gpa(unsigned long paddr)
  192. {
  193. if (paddr < uv_hub_info->lowmem_remap_top)
  194. paddr |= uv_hub_info->lowmem_remap_base;
  195. return paddr | uv_hub_info->gnode_upper;
  196. }
  197. /* socket virtual --> UV global physical address */
  198. static inline unsigned long uv_gpa(void *v)
  199. {
  200. return uv_soc_phys_ram_to_gpa(__pa(v));
  201. }
  202. /* pnode, offset --> socket virtual */
  203. static inline void *uv_pnode_offset_to_vaddr(int pnode, unsigned long offset)
  204. {
  205. return __va(((unsigned long)pnode << uv_hub_info->m_val) | offset);
  206. }
  207. /*
  208. * Extract a PNODE from an APICID (full apicid, not processor subset)
  209. */
  210. static inline int uv_apicid_to_pnode(int apicid)
  211. {
  212. return (apicid >> UV_APIC_PNODE_SHIFT);
  213. }
  214. /*
  215. * Access global MMRs using the low memory MMR32 space. This region supports
  216. * faster MMR access but not all MMRs are accessible in this space.
  217. */
  218. static inline unsigned long *uv_global_mmr32_address(int pnode,
  219. unsigned long offset)
  220. {
  221. return __va(UV_GLOBAL_MMR32_BASE |
  222. UV_GLOBAL_MMR32_PNODE_BITS(pnode) | offset);
  223. }
  224. static inline void uv_write_global_mmr32(int pnode, unsigned long offset,
  225. unsigned long val)
  226. {
  227. *uv_global_mmr32_address(pnode, offset) = val;
  228. }
  229. static inline unsigned long uv_read_global_mmr32(int pnode,
  230. unsigned long offset)
  231. {
  232. return *uv_global_mmr32_address(pnode, offset);
  233. }
  234. /*
  235. * Access Global MMR space using the MMR space located at the top of physical
  236. * memory.
  237. */
  238. static inline unsigned long *uv_global_mmr64_address(int pnode,
  239. unsigned long offset)
  240. {
  241. return __va(UV_GLOBAL_MMR64_BASE |
  242. UV_GLOBAL_MMR64_PNODE_BITS(pnode) | offset);
  243. }
  244. static inline void uv_write_global_mmr64(int pnode, unsigned long offset,
  245. unsigned long val)
  246. {
  247. *uv_global_mmr64_address(pnode, offset) = val;
  248. }
  249. static inline unsigned long uv_read_global_mmr64(int pnode,
  250. unsigned long offset)
  251. {
  252. return *uv_global_mmr64_address(pnode, offset);
  253. }
  254. /*
  255. * Access hub local MMRs. Faster than using global space but only local MMRs
  256. * are accessible.
  257. */
  258. static inline unsigned long *uv_local_mmr_address(unsigned long offset)
  259. {
  260. return __va(UV_LOCAL_MMR_BASE | offset);
  261. }
  262. static inline unsigned long uv_read_local_mmr(unsigned long offset)
  263. {
  264. return *uv_local_mmr_address(offset);
  265. }
  266. static inline void uv_write_local_mmr(unsigned long offset, unsigned long val)
  267. {
  268. *uv_local_mmr_address(offset) = val;
  269. }
  270. static inline unsigned char uv_read_local_mmr8(unsigned long offset)
  271. {
  272. return *((unsigned char *)uv_local_mmr_address(offset));
  273. }
  274. static inline void uv_write_local_mmr8(unsigned long offset, unsigned char val)
  275. {
  276. *((unsigned char *)uv_local_mmr_address(offset)) = val;
  277. }
  278. /*
  279. * Structures and definitions for converting between cpu, node, pnode, and blade
  280. * numbers.
  281. */
  282. struct uv_blade_info {
  283. unsigned short nr_possible_cpus;
  284. unsigned short nr_online_cpus;
  285. unsigned short pnode;
  286. };
  287. extern struct uv_blade_info *uv_blade_info;
  288. extern short *uv_node_to_blade;
  289. extern short *uv_cpu_to_blade;
  290. extern short uv_possible_blades;
  291. /* Blade-local cpu number of current cpu. Numbered 0 .. <# cpus on the blade> */
  292. static inline int uv_blade_processor_id(void)
  293. {
  294. return uv_hub_info->blade_processor_id;
  295. }
  296. /* Blade number of current cpu. Numnbered 0 .. <#blades -1> */
  297. static inline int uv_numa_blade_id(void)
  298. {
  299. return uv_hub_info->numa_blade_id;
  300. }
  301. /* Convert a cpu number to the the UV blade number */
  302. static inline int uv_cpu_to_blade_id(int cpu)
  303. {
  304. return uv_cpu_to_blade[cpu];
  305. }
  306. /* Convert linux node number to the UV blade number */
  307. static inline int uv_node_to_blade_id(int nid)
  308. {
  309. return uv_node_to_blade[nid];
  310. }
  311. /* Convert a blade id to the PNODE of the blade */
  312. static inline int uv_blade_to_pnode(int bid)
  313. {
  314. return uv_blade_info[bid].pnode;
  315. }
  316. /* Determine the number of possible cpus on a blade */
  317. static inline int uv_blade_nr_possible_cpus(int bid)
  318. {
  319. return uv_blade_info[bid].nr_possible_cpus;
  320. }
  321. /* Determine the number of online cpus on a blade */
  322. static inline int uv_blade_nr_online_cpus(int bid)
  323. {
  324. return uv_blade_info[bid].nr_online_cpus;
  325. }
  326. /* Convert a cpu id to the PNODE of the blade containing the cpu */
  327. static inline int uv_cpu_to_pnode(int cpu)
  328. {
  329. return uv_blade_info[uv_cpu_to_blade_id(cpu)].pnode;
  330. }
  331. /* Convert a linux node number to the PNODE of the blade */
  332. static inline int uv_node_to_pnode(int nid)
  333. {
  334. return uv_blade_info[uv_node_to_blade_id(nid)].pnode;
  335. }
  336. /* Maximum possible number of blades */
  337. static inline int uv_num_possible_blades(void)
  338. {
  339. return uv_possible_blades;
  340. }
  341. /* Update SCIR state */
  342. static inline void uv_set_scir_bits(unsigned char value)
  343. {
  344. if (uv_hub_info->scir.state != value) {
  345. uv_hub_info->scir.state = value;
  346. uv_write_local_mmr8(uv_hub_info->scir.offset, value);
  347. }
  348. }
  349. static inline void uv_set_cpu_scir_bits(int cpu, unsigned char value)
  350. {
  351. if (uv_cpu_hub_info(cpu)->scir.state != value) {
  352. uv_cpu_hub_info(cpu)->scir.state = value;
  353. uv_write_local_mmr8(uv_cpu_hub_info(cpu)->scir.offset, value);
  354. }
  355. }
  356. #endif /* _ASM_X86_UV_UV_HUB_H */