uv_hub.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  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 (12 bits in hdw reg)
  77. * ppppppppplcc0cch Westmere-EX (12 bits in hdw reg)
  78. * pppppppppppcccch SandyBridge (15 bits in hdw reg)
  79. * sssssssssss
  80. *
  81. * p = pnode bits
  82. * l = socket number on board
  83. * c = core
  84. * h = hyperthread
  85. * s = bits that are in the SOCKET_ID CSR
  86. *
  87. * Note: Processor may support fewer bits in the APICID register. The ACPI
  88. * tables hold all 16 bits. Software needs to be aware of this.
  89. *
  90. * Unless otherwise specified, all references to APICID refer to
  91. * the FULL value contained in ACPI tables, not the subset in the
  92. * processor APICID register.
  93. */
  94. /*
  95. * Maximum number of bricks in all partitions and in all coherency domains.
  96. * This is the total number of bricks accessible in the numalink fabric. It
  97. * includes all C & M bricks. Routers are NOT included.
  98. *
  99. * This value is also the value of the maximum number of non-router NASIDs
  100. * in the numalink fabric.
  101. *
  102. * NOTE: a brick may contain 1 or 2 OS nodes. Don't get these confused.
  103. */
  104. #define UV_MAX_NUMALINK_BLADES 16384
  105. /*
  106. * Maximum number of C/Mbricks within a software SSI (hardware may support
  107. * more).
  108. */
  109. #define UV_MAX_SSI_BLADES 256
  110. /*
  111. * The largest possible NASID of a C or M brick (+ 2)
  112. */
  113. #define UV_MAX_NASID_VALUE (UV_MAX_NUMALINK_BLADES * 2)
  114. struct uv_scir_s {
  115. struct timer_list timer;
  116. unsigned long offset;
  117. unsigned long last;
  118. unsigned long idle_on;
  119. unsigned long idle_off;
  120. unsigned char state;
  121. unsigned char enabled;
  122. };
  123. /*
  124. * The following defines attributes of the HUB chip. These attributes are
  125. * frequently referenced and are kept in the per-cpu data areas of each cpu.
  126. * They are kept together in a struct to minimize cache misses.
  127. */
  128. struct uv_hub_info_s {
  129. unsigned long global_mmr_base;
  130. unsigned long gpa_mask;
  131. unsigned int gnode_extra;
  132. unsigned char hub_revision;
  133. unsigned char apic_pnode_shift;
  134. unsigned long gnode_upper;
  135. unsigned long lowmem_remap_top;
  136. unsigned long lowmem_remap_base;
  137. unsigned short pnode;
  138. unsigned short pnode_mask;
  139. unsigned short coherency_domain_number;
  140. unsigned short numa_blade_id;
  141. unsigned char blade_processor_id;
  142. unsigned char m_val;
  143. unsigned char n_val;
  144. struct uv_scir_s scir;
  145. };
  146. DECLARE_PER_CPU(struct uv_hub_info_s, __uv_hub_info);
  147. #define uv_hub_info (&__get_cpu_var(__uv_hub_info))
  148. #define uv_cpu_hub_info(cpu) (&per_cpu(__uv_hub_info, cpu))
  149. /*
  150. * Hub revisions less than UV2_HUB_REVISION_BASE are UV1 hubs. All UV2
  151. * hubs have revision numbers greater than or equal to UV2_HUB_REVISION_BASE.
  152. * This is a software convention - NOT the hardware revision numbers in
  153. * the hub chip.
  154. */
  155. #define UV1_HUB_REVISION_BASE 1
  156. #define UV2_HUB_REVISION_BASE 3
  157. static inline int is_uv1_hub(void)
  158. {
  159. return uv_hub_info->hub_revision < UV2_HUB_REVISION_BASE;
  160. }
  161. static inline int is_uv2_hub(void)
  162. {
  163. return uv_hub_info->hub_revision >= UV2_HUB_REVISION_BASE;
  164. }
  165. union uvh_apicid {
  166. unsigned long v;
  167. struct uvh_apicid_s {
  168. unsigned long local_apic_mask : 24;
  169. unsigned long local_apic_shift : 5;
  170. unsigned long unused1 : 3;
  171. unsigned long pnode_mask : 24;
  172. unsigned long pnode_shift : 5;
  173. unsigned long unused2 : 3;
  174. } s;
  175. };
  176. /*
  177. * Local & Global MMR space macros.
  178. * Note: macros are intended to be used ONLY by inline functions
  179. * in this file - not by other kernel code.
  180. * n - NASID (full 15-bit global nasid)
  181. * g - GNODE (full 15-bit global nasid, right shifted 1)
  182. * p - PNODE (local part of nsids, right shifted 1)
  183. */
  184. #define UV_NASID_TO_PNODE(n) (((n) >> 1) & uv_hub_info->pnode_mask)
  185. #define UV_PNODE_TO_GNODE(p) ((p) |uv_hub_info->gnode_extra)
  186. #define UV_PNODE_TO_NASID(p) (UV_PNODE_TO_GNODE(p) << 1)
  187. #define UV1_LOCAL_MMR_BASE 0xf4000000UL
  188. #define UV1_GLOBAL_MMR32_BASE 0xf8000000UL
  189. #define UV1_LOCAL_MMR_SIZE (64UL * 1024 * 1024)
  190. #define UV1_GLOBAL_MMR32_SIZE (64UL * 1024 * 1024)
  191. #define UV2_LOCAL_MMR_BASE 0xfa000000UL
  192. #define UV2_GLOBAL_MMR32_BASE 0xfc000000UL
  193. #define UV2_LOCAL_MMR_SIZE (32UL * 1024 * 1024)
  194. #define UV2_GLOBAL_MMR32_SIZE (32UL * 1024 * 1024)
  195. #define UV_LOCAL_MMR_BASE (is_uv1_hub() ? UV1_LOCAL_MMR_BASE \
  196. : UV2_LOCAL_MMR_BASE)
  197. #define UV_GLOBAL_MMR32_BASE (is_uv1_hub() ? UV1_GLOBAL_MMR32_BASE \
  198. : UV2_GLOBAL_MMR32_BASE)
  199. #define UV_LOCAL_MMR_SIZE (is_uv1_hub() ? UV1_LOCAL_MMR_SIZE : \
  200. UV2_LOCAL_MMR_SIZE)
  201. #define UV_GLOBAL_MMR32_SIZE (is_uv1_hub() ? UV1_GLOBAL_MMR32_SIZE :\
  202. UV2_GLOBAL_MMR32_SIZE)
  203. #define UV_GLOBAL_MMR64_BASE (uv_hub_info->global_mmr_base)
  204. #define UV_GLOBAL_GRU_MMR_BASE 0x4000000
  205. #define UV_GLOBAL_MMR32_PNODE_SHIFT 15
  206. #define UV_GLOBAL_MMR64_PNODE_SHIFT 26
  207. #define UV_GLOBAL_MMR32_PNODE_BITS(p) ((p) << (UV_GLOBAL_MMR32_PNODE_SHIFT))
  208. #define UV_GLOBAL_MMR64_PNODE_BITS(p) \
  209. (((unsigned long)(p)) << UV_GLOBAL_MMR64_PNODE_SHIFT)
  210. #define UVH_APICID 0x002D0E00L
  211. #define UV_APIC_PNODE_SHIFT 6
  212. #define UV_APICID_HIBIT_MASK 0xffff0000
  213. /* Local Bus from cpu's perspective */
  214. #define LOCAL_BUS_BASE 0x1c00000
  215. #define LOCAL_BUS_SIZE (4 * 1024 * 1024)
  216. /*
  217. * System Controller Interface Reg
  218. *
  219. * Note there are NO leds on a UV system. This register is only
  220. * used by the system controller to monitor system-wide operation.
  221. * There are 64 regs per node. With Nahelem cpus (2 cores per node,
  222. * 8 cpus per core, 2 threads per cpu) there are 32 cpu threads on
  223. * a node.
  224. *
  225. * The window is located at top of ACPI MMR space
  226. */
  227. #define SCIR_WINDOW_COUNT 64
  228. #define SCIR_LOCAL_MMR_BASE (LOCAL_BUS_BASE + \
  229. LOCAL_BUS_SIZE - \
  230. SCIR_WINDOW_COUNT)
  231. #define SCIR_CPU_HEARTBEAT 0x01 /* timer interrupt */
  232. #define SCIR_CPU_ACTIVITY 0x02 /* not idle */
  233. #define SCIR_CPU_HB_INTERVAL (HZ) /* once per second */
  234. /* Loop through all installed blades */
  235. #define for_each_possible_blade(bid) \
  236. for ((bid) = 0; (bid) < uv_num_possible_blades(); (bid)++)
  237. /*
  238. * Macros for converting between kernel virtual addresses, socket local physical
  239. * addresses, and UV global physical addresses.
  240. * Note: use the standard __pa() & __va() macros for converting
  241. * between socket virtual and socket physical addresses.
  242. */
  243. /* socket phys RAM --> UV global physical address */
  244. static inline unsigned long uv_soc_phys_ram_to_gpa(unsigned long paddr)
  245. {
  246. if (paddr < uv_hub_info->lowmem_remap_top)
  247. paddr |= uv_hub_info->lowmem_remap_base;
  248. return paddr | uv_hub_info->gnode_upper;
  249. }
  250. /* socket virtual --> UV global physical address */
  251. static inline unsigned long uv_gpa(void *v)
  252. {
  253. return uv_soc_phys_ram_to_gpa(__pa(v));
  254. }
  255. /* Top two bits indicate the requested address is in MMR space. */
  256. static inline int
  257. uv_gpa_in_mmr_space(unsigned long gpa)
  258. {
  259. return (gpa >> 62) == 0x3UL;
  260. }
  261. /* UV global physical address --> socket phys RAM */
  262. static inline unsigned long uv_gpa_to_soc_phys_ram(unsigned long gpa)
  263. {
  264. unsigned long paddr = gpa & uv_hub_info->gpa_mask;
  265. unsigned long remap_base = uv_hub_info->lowmem_remap_base;
  266. unsigned long remap_top = uv_hub_info->lowmem_remap_top;
  267. if (paddr >= remap_base && paddr < remap_base + remap_top)
  268. paddr -= remap_base;
  269. return paddr;
  270. }
  271. /* gnode -> pnode */
  272. static inline unsigned long uv_gpa_to_gnode(unsigned long gpa)
  273. {
  274. return gpa >> uv_hub_info->m_val;
  275. }
  276. /* gpa -> pnode */
  277. static inline int uv_gpa_to_pnode(unsigned long gpa)
  278. {
  279. unsigned long n_mask = (1UL << uv_hub_info->n_val) - 1;
  280. return uv_gpa_to_gnode(gpa) & n_mask;
  281. }
  282. /* pnode, offset --> socket virtual */
  283. static inline void *uv_pnode_offset_to_vaddr(int pnode, unsigned long offset)
  284. {
  285. return __va(((unsigned long)pnode << uv_hub_info->m_val) | offset);
  286. }
  287. /*
  288. * Extract a PNODE from an APICID (full apicid, not processor subset)
  289. */
  290. static inline int uv_apicid_to_pnode(int apicid)
  291. {
  292. return (apicid >> uv_hub_info->apic_pnode_shift);
  293. }
  294. /*
  295. * Convert an apicid to the socket number on the blade
  296. */
  297. static inline int uv_apicid_to_socket(int apicid)
  298. {
  299. if (is_uv1_hub())
  300. return (apicid >> (uv_hub_info->apic_pnode_shift - 1)) & 1;
  301. else
  302. return 0;
  303. }
  304. /*
  305. * Access global MMRs using the low memory MMR32 space. This region supports
  306. * faster MMR access but not all MMRs are accessible in this space.
  307. */
  308. static inline unsigned long *uv_global_mmr32_address(int pnode, unsigned long offset)
  309. {
  310. return __va(UV_GLOBAL_MMR32_BASE |
  311. UV_GLOBAL_MMR32_PNODE_BITS(pnode) | offset);
  312. }
  313. static inline void uv_write_global_mmr32(int pnode, unsigned long offset, unsigned long val)
  314. {
  315. writeq(val, uv_global_mmr32_address(pnode, offset));
  316. }
  317. static inline unsigned long uv_read_global_mmr32(int pnode, unsigned long offset)
  318. {
  319. return readq(uv_global_mmr32_address(pnode, offset));
  320. }
  321. /*
  322. * Access Global MMR space using the MMR space located at the top of physical
  323. * memory.
  324. */
  325. static inline volatile void __iomem *uv_global_mmr64_address(int pnode, unsigned long offset)
  326. {
  327. return __va(UV_GLOBAL_MMR64_BASE |
  328. UV_GLOBAL_MMR64_PNODE_BITS(pnode) | offset);
  329. }
  330. static inline void uv_write_global_mmr64(int pnode, unsigned long offset, unsigned long val)
  331. {
  332. writeq(val, uv_global_mmr64_address(pnode, offset));
  333. }
  334. static inline unsigned long uv_read_global_mmr64(int pnode, unsigned long offset)
  335. {
  336. return readq(uv_global_mmr64_address(pnode, offset));
  337. }
  338. /*
  339. * Global MMR space addresses when referenced by the GRU. (GRU does
  340. * NOT use socket addressing).
  341. */
  342. static inline unsigned long uv_global_gru_mmr_address(int pnode, unsigned long offset)
  343. {
  344. return UV_GLOBAL_GRU_MMR_BASE | offset |
  345. ((unsigned long)pnode << uv_hub_info->m_val);
  346. }
  347. static inline void uv_write_global_mmr8(int pnode, unsigned long offset, unsigned char val)
  348. {
  349. writeb(val, uv_global_mmr64_address(pnode, offset));
  350. }
  351. static inline unsigned char uv_read_global_mmr8(int pnode, unsigned long offset)
  352. {
  353. return readb(uv_global_mmr64_address(pnode, offset));
  354. }
  355. /*
  356. * Access hub local MMRs. Faster than using global space but only local MMRs
  357. * are accessible.
  358. */
  359. static inline unsigned long *uv_local_mmr_address(unsigned long offset)
  360. {
  361. return __va(UV_LOCAL_MMR_BASE | offset);
  362. }
  363. static inline unsigned long uv_read_local_mmr(unsigned long offset)
  364. {
  365. return readq(uv_local_mmr_address(offset));
  366. }
  367. static inline void uv_write_local_mmr(unsigned long offset, unsigned long val)
  368. {
  369. writeq(val, uv_local_mmr_address(offset));
  370. }
  371. static inline unsigned char uv_read_local_mmr8(unsigned long offset)
  372. {
  373. return readb(uv_local_mmr_address(offset));
  374. }
  375. static inline void uv_write_local_mmr8(unsigned long offset, unsigned char val)
  376. {
  377. writeb(val, uv_local_mmr_address(offset));
  378. }
  379. /*
  380. * Structures and definitions for converting between cpu, node, pnode, and blade
  381. * numbers.
  382. */
  383. struct uv_blade_info {
  384. unsigned short nr_possible_cpus;
  385. unsigned short nr_online_cpus;
  386. unsigned short pnode;
  387. short memory_nid;
  388. spinlock_t nmi_lock;
  389. unsigned long nmi_count;
  390. };
  391. extern struct uv_blade_info *uv_blade_info;
  392. extern short *uv_node_to_blade;
  393. extern short *uv_cpu_to_blade;
  394. extern short uv_possible_blades;
  395. /* Blade-local cpu number of current cpu. Numbered 0 .. <# cpus on the blade> */
  396. static inline int uv_blade_processor_id(void)
  397. {
  398. return uv_hub_info->blade_processor_id;
  399. }
  400. /* Blade number of current cpu. Numnbered 0 .. <#blades -1> */
  401. static inline int uv_numa_blade_id(void)
  402. {
  403. return uv_hub_info->numa_blade_id;
  404. }
  405. /* Convert a cpu number to the the UV blade number */
  406. static inline int uv_cpu_to_blade_id(int cpu)
  407. {
  408. return uv_cpu_to_blade[cpu];
  409. }
  410. /* Convert linux node number to the UV blade number */
  411. static inline int uv_node_to_blade_id(int nid)
  412. {
  413. return uv_node_to_blade[nid];
  414. }
  415. /* Convert a blade id to the PNODE of the blade */
  416. static inline int uv_blade_to_pnode(int bid)
  417. {
  418. return uv_blade_info[bid].pnode;
  419. }
  420. /* Nid of memory node on blade. -1 if no blade-local memory */
  421. static inline int uv_blade_to_memory_nid(int bid)
  422. {
  423. return uv_blade_info[bid].memory_nid;
  424. }
  425. /* Determine the number of possible cpus on a blade */
  426. static inline int uv_blade_nr_possible_cpus(int bid)
  427. {
  428. return uv_blade_info[bid].nr_possible_cpus;
  429. }
  430. /* Determine the number of online cpus on a blade */
  431. static inline int uv_blade_nr_online_cpus(int bid)
  432. {
  433. return uv_blade_info[bid].nr_online_cpus;
  434. }
  435. /* Convert a cpu id to the PNODE of the blade containing the cpu */
  436. static inline int uv_cpu_to_pnode(int cpu)
  437. {
  438. return uv_blade_info[uv_cpu_to_blade_id(cpu)].pnode;
  439. }
  440. /* Convert a linux node number to the PNODE of the blade */
  441. static inline int uv_node_to_pnode(int nid)
  442. {
  443. return uv_blade_info[uv_node_to_blade_id(nid)].pnode;
  444. }
  445. /* Maximum possible number of blades */
  446. static inline int uv_num_possible_blades(void)
  447. {
  448. return uv_possible_blades;
  449. }
  450. /* Update SCIR state */
  451. static inline void uv_set_scir_bits(unsigned char value)
  452. {
  453. if (uv_hub_info->scir.state != value) {
  454. uv_hub_info->scir.state = value;
  455. uv_write_local_mmr8(uv_hub_info->scir.offset, value);
  456. }
  457. }
  458. static inline unsigned long uv_scir_offset(int apicid)
  459. {
  460. return SCIR_LOCAL_MMR_BASE | (apicid & 0x3f);
  461. }
  462. static inline void uv_set_cpu_scir_bits(int cpu, unsigned char value)
  463. {
  464. if (uv_cpu_hub_info(cpu)->scir.state != value) {
  465. uv_write_global_mmr8(uv_cpu_to_pnode(cpu),
  466. uv_cpu_hub_info(cpu)->scir.offset, value);
  467. uv_cpu_hub_info(cpu)->scir.state = value;
  468. }
  469. }
  470. extern unsigned int uv_apicid_hibits;
  471. static unsigned long uv_hub_ipi_value(int apicid, int vector, int mode)
  472. {
  473. apicid |= uv_apicid_hibits;
  474. return (1UL << UVH_IPI_INT_SEND_SHFT) |
  475. ((apicid) << UVH_IPI_INT_APIC_ID_SHFT) |
  476. (mode << UVH_IPI_INT_DELIVERY_MODE_SHFT) |
  477. (vector << UVH_IPI_INT_VECTOR_SHFT);
  478. }
  479. static inline void uv_hub_send_ipi(int pnode, int apicid, int vector)
  480. {
  481. unsigned long val;
  482. unsigned long dmode = dest_Fixed;
  483. if (vector == NMI_VECTOR)
  484. dmode = dest_NMI;
  485. val = uv_hub_ipi_value(apicid, vector, dmode);
  486. uv_write_global_mmr64(pnode, UVH_IPI_INT, val);
  487. }
  488. /*
  489. * Get the minimum revision number of the hub chips within the partition.
  490. * 1 - UV1 rev 1.0 initial silicon
  491. * 2 - UV1 rev 2.0 production silicon
  492. * 3 - UV2 rev 1.0 initial silicon
  493. */
  494. static inline int uv_get_min_hub_revision_id(void)
  495. {
  496. return uv_hub_info->hub_revision;
  497. }
  498. #endif /* CONFIG_X86_64 */
  499. #endif /* _ASM_X86_UV_UV_HUB_H */