uv_hub.h 15 KB

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