uv_hub.h 12 KB

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