uv_hub.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  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. #define UV_APICID_HIBIT_MASK 0xffff0000
  183. /* Local Bus from cpu's perspective */
  184. #define LOCAL_BUS_BASE 0x1c00000
  185. #define LOCAL_BUS_SIZE (4 * 1024 * 1024)
  186. /*
  187. * System Controller Interface Reg
  188. *
  189. * Note there are NO leds on a UV system. This register is only
  190. * used by the system controller to monitor system-wide operation.
  191. * There are 64 regs per node. With Nahelem cpus (2 cores per node,
  192. * 8 cpus per core, 2 threads per cpu) there are 32 cpu threads on
  193. * a node.
  194. *
  195. * The window is located at top of ACPI MMR space
  196. */
  197. #define SCIR_WINDOW_COUNT 64
  198. #define SCIR_LOCAL_MMR_BASE (LOCAL_BUS_BASE + \
  199. LOCAL_BUS_SIZE - \
  200. SCIR_WINDOW_COUNT)
  201. #define SCIR_CPU_HEARTBEAT 0x01 /* timer interrupt */
  202. #define SCIR_CPU_ACTIVITY 0x02 /* not idle */
  203. #define SCIR_CPU_HB_INTERVAL (HZ) /* once per second */
  204. /* Loop through all installed blades */
  205. #define for_each_possible_blade(bid) \
  206. for ((bid) = 0; (bid) < uv_num_possible_blades(); (bid)++)
  207. /*
  208. * Macros for converting between kernel virtual addresses, socket local physical
  209. * addresses, and UV global physical addresses.
  210. * Note: use the standard __pa() & __va() macros for converting
  211. * between socket virtual and socket physical addresses.
  212. */
  213. /* socket phys RAM --> UV global physical address */
  214. static inline unsigned long uv_soc_phys_ram_to_gpa(unsigned long paddr)
  215. {
  216. if (paddr < uv_hub_info->lowmem_remap_top)
  217. paddr |= uv_hub_info->lowmem_remap_base;
  218. return paddr | uv_hub_info->gnode_upper;
  219. }
  220. /* socket virtual --> UV global physical address */
  221. static inline unsigned long uv_gpa(void *v)
  222. {
  223. return uv_soc_phys_ram_to_gpa(__pa(v));
  224. }
  225. /* Top two bits indicate the requested address is in MMR space. */
  226. static inline int
  227. uv_gpa_in_mmr_space(unsigned long gpa)
  228. {
  229. return (gpa >> 62) == 0x3UL;
  230. }
  231. /* UV global physical address --> socket phys RAM */
  232. static inline unsigned long uv_gpa_to_soc_phys_ram(unsigned long gpa)
  233. {
  234. unsigned long paddr = gpa & uv_hub_info->gpa_mask;
  235. unsigned long remap_base = uv_hub_info->lowmem_remap_base;
  236. unsigned long remap_top = uv_hub_info->lowmem_remap_top;
  237. if (paddr >= remap_base && paddr < remap_base + remap_top)
  238. paddr -= remap_base;
  239. return paddr;
  240. }
  241. /* gnode -> pnode */
  242. static inline unsigned long uv_gpa_to_gnode(unsigned long gpa)
  243. {
  244. return gpa >> uv_hub_info->m_val;
  245. }
  246. /* gpa -> pnode */
  247. static inline int uv_gpa_to_pnode(unsigned long gpa)
  248. {
  249. unsigned long n_mask = (1UL << uv_hub_info->n_val) - 1;
  250. return uv_gpa_to_gnode(gpa) & n_mask;
  251. }
  252. /* pnode, offset --> socket virtual */
  253. static inline void *uv_pnode_offset_to_vaddr(int pnode, unsigned long offset)
  254. {
  255. return __va(((unsigned long)pnode << uv_hub_info->m_val) | offset);
  256. }
  257. /*
  258. * Extract a PNODE from an APICID (full apicid, not processor subset)
  259. */
  260. static inline int uv_apicid_to_pnode(int apicid)
  261. {
  262. return (apicid >> uv_hub_info->apic_pnode_shift);
  263. }
  264. /*
  265. * Access global MMRs using the low memory MMR32 space. This region supports
  266. * faster MMR access but not all MMRs are accessible in this space.
  267. */
  268. static inline unsigned long *uv_global_mmr32_address(int pnode, unsigned long offset)
  269. {
  270. return __va(UV_GLOBAL_MMR32_BASE |
  271. UV_GLOBAL_MMR32_PNODE_BITS(pnode) | offset);
  272. }
  273. static inline void uv_write_global_mmr32(int pnode, unsigned long offset, unsigned long val)
  274. {
  275. writeq(val, uv_global_mmr32_address(pnode, offset));
  276. }
  277. static inline unsigned long uv_read_global_mmr32(int pnode, unsigned long offset)
  278. {
  279. return readq(uv_global_mmr32_address(pnode, offset));
  280. }
  281. /*
  282. * Access Global MMR space using the MMR space located at the top of physical
  283. * memory.
  284. */
  285. static inline volatile void __iomem *uv_global_mmr64_address(int pnode, unsigned long offset)
  286. {
  287. return __va(UV_GLOBAL_MMR64_BASE |
  288. UV_GLOBAL_MMR64_PNODE_BITS(pnode) | offset);
  289. }
  290. static inline void uv_write_global_mmr64(int pnode, unsigned long offset, unsigned long val)
  291. {
  292. writeq(val, uv_global_mmr64_address(pnode, offset));
  293. }
  294. static inline unsigned long uv_read_global_mmr64(int pnode, unsigned long offset)
  295. {
  296. return readq(uv_global_mmr64_address(pnode, offset));
  297. }
  298. /*
  299. * Global MMR space addresses when referenced by the GRU. (GRU does
  300. * NOT use socket addressing).
  301. */
  302. static inline unsigned long uv_global_gru_mmr_address(int pnode, unsigned long offset)
  303. {
  304. return UV_GLOBAL_GRU_MMR_BASE | offset |
  305. ((unsigned long)pnode << uv_hub_info->m_val);
  306. }
  307. static inline void uv_write_global_mmr8(int pnode, unsigned long offset, unsigned char val)
  308. {
  309. writeb(val, uv_global_mmr64_address(pnode, offset));
  310. }
  311. static inline unsigned char uv_read_global_mmr8(int pnode, unsigned long offset)
  312. {
  313. return readb(uv_global_mmr64_address(pnode, offset));
  314. }
  315. /*
  316. * Access hub local MMRs. Faster than using global space but only local MMRs
  317. * are accessible.
  318. */
  319. static inline unsigned long *uv_local_mmr_address(unsigned long offset)
  320. {
  321. return __va(UV_LOCAL_MMR_BASE | offset);
  322. }
  323. static inline unsigned long uv_read_local_mmr(unsigned long offset)
  324. {
  325. return readq(uv_local_mmr_address(offset));
  326. }
  327. static inline void uv_write_local_mmr(unsigned long offset, unsigned long val)
  328. {
  329. writeq(val, uv_local_mmr_address(offset));
  330. }
  331. static inline unsigned char uv_read_local_mmr8(unsigned long offset)
  332. {
  333. return readb(uv_local_mmr_address(offset));
  334. }
  335. static inline void uv_write_local_mmr8(unsigned long offset, unsigned char val)
  336. {
  337. writeb(val, uv_local_mmr_address(offset));
  338. }
  339. /*
  340. * Structures and definitions for converting between cpu, node, pnode, and blade
  341. * numbers.
  342. */
  343. struct uv_blade_info {
  344. unsigned short nr_possible_cpus;
  345. unsigned short nr_online_cpus;
  346. unsigned short pnode;
  347. short memory_nid;
  348. };
  349. extern struct uv_blade_info *uv_blade_info;
  350. extern short *uv_node_to_blade;
  351. extern short *uv_cpu_to_blade;
  352. extern short uv_possible_blades;
  353. /* Blade-local cpu number of current cpu. Numbered 0 .. <# cpus on the blade> */
  354. static inline int uv_blade_processor_id(void)
  355. {
  356. return uv_hub_info->blade_processor_id;
  357. }
  358. /* Blade number of current cpu. Numnbered 0 .. <#blades -1> */
  359. static inline int uv_numa_blade_id(void)
  360. {
  361. return uv_hub_info->numa_blade_id;
  362. }
  363. /* Convert a cpu number to the the UV blade number */
  364. static inline int uv_cpu_to_blade_id(int cpu)
  365. {
  366. return uv_cpu_to_blade[cpu];
  367. }
  368. /* Convert linux node number to the UV blade number */
  369. static inline int uv_node_to_blade_id(int nid)
  370. {
  371. return uv_node_to_blade[nid];
  372. }
  373. /* Convert a blade id to the PNODE of the blade */
  374. static inline int uv_blade_to_pnode(int bid)
  375. {
  376. return uv_blade_info[bid].pnode;
  377. }
  378. /* Nid of memory node on blade. -1 if no blade-local memory */
  379. static inline int uv_blade_to_memory_nid(int bid)
  380. {
  381. return uv_blade_info[bid].memory_nid;
  382. }
  383. /* Determine the number of possible cpus on a blade */
  384. static inline int uv_blade_nr_possible_cpus(int bid)
  385. {
  386. return uv_blade_info[bid].nr_possible_cpus;
  387. }
  388. /* Determine the number of online cpus on a blade */
  389. static inline int uv_blade_nr_online_cpus(int bid)
  390. {
  391. return uv_blade_info[bid].nr_online_cpus;
  392. }
  393. /* Convert a cpu id to the PNODE of the blade containing the cpu */
  394. static inline int uv_cpu_to_pnode(int cpu)
  395. {
  396. return uv_blade_info[uv_cpu_to_blade_id(cpu)].pnode;
  397. }
  398. /* Convert a linux node number to the PNODE of the blade */
  399. static inline int uv_node_to_pnode(int nid)
  400. {
  401. return uv_blade_info[uv_node_to_blade_id(nid)].pnode;
  402. }
  403. /* Maximum possible number of blades */
  404. static inline int uv_num_possible_blades(void)
  405. {
  406. return uv_possible_blades;
  407. }
  408. /* Update SCIR state */
  409. static inline void uv_set_scir_bits(unsigned char value)
  410. {
  411. if (uv_hub_info->scir.state != value) {
  412. uv_hub_info->scir.state = value;
  413. uv_write_local_mmr8(uv_hub_info->scir.offset, value);
  414. }
  415. }
  416. static inline unsigned long uv_scir_offset(int apicid)
  417. {
  418. return SCIR_LOCAL_MMR_BASE | (apicid & 0x3f);
  419. }
  420. static inline void uv_set_cpu_scir_bits(int cpu, unsigned char value)
  421. {
  422. if (uv_cpu_hub_info(cpu)->scir.state != value) {
  423. uv_write_global_mmr8(uv_cpu_to_pnode(cpu),
  424. uv_cpu_hub_info(cpu)->scir.offset, value);
  425. uv_cpu_hub_info(cpu)->scir.state = value;
  426. }
  427. }
  428. extern unsigned int uv_apicid_hibits;
  429. static unsigned long uv_hub_ipi_value(int apicid, int vector, int mode)
  430. {
  431. apicid |= uv_apicid_hibits;
  432. return (1UL << UVH_IPI_INT_SEND_SHFT) |
  433. ((apicid) << UVH_IPI_INT_APIC_ID_SHFT) |
  434. (mode << UVH_IPI_INT_DELIVERY_MODE_SHFT) |
  435. (vector << UVH_IPI_INT_VECTOR_SHFT);
  436. }
  437. static inline void uv_hub_send_ipi(int pnode, int apicid, int vector)
  438. {
  439. unsigned long val;
  440. unsigned long dmode = dest_Fixed;
  441. if (vector == NMI_VECTOR)
  442. dmode = dest_NMI;
  443. val = uv_hub_ipi_value(apicid, vector, dmode);
  444. uv_write_global_mmr64(pnode, UVH_IPI_INT, val);
  445. }
  446. /*
  447. * Get the minimum revision number of the hub chips within the partition.
  448. * 1 - initial rev 1.0 silicon
  449. * 2 - rev 2.0 production silicon
  450. */
  451. static inline int uv_get_min_hub_revision_id(void)
  452. {
  453. extern int uv_min_hub_revision_id;
  454. return uv_min_hub_revision_id;
  455. }
  456. #endif /* CONFIG_X86_64 */
  457. #endif /* _ASM_X86_UV_UV_HUB_H */