uv_hub.h 14 KB

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