uv_hub.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  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-2014 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. * GPA - (global physical address) a socket physical address converted
  46. * so that it can be used by the GRU as a global address. Socket
  47. * physical addresses 1) need additional NASID (node) bits added
  48. * to the high end of the address, and 2) unaliased if the
  49. * partition does not have a physical address 0. In addition, on
  50. * UV2 rev 1, GPAs need the gnode left shifted to bits 39 or 40.
  51. *
  52. *
  53. * NumaLink Global Physical Address Format:
  54. * +--------------------------------+---------------------+
  55. * |00..000| GNODE | NodeOffset |
  56. * +--------------------------------+---------------------+
  57. * |<-------53 - M bits --->|<--------M bits ----->
  58. *
  59. * M - number of node offset bits (35 .. 40)
  60. *
  61. *
  62. * Memory/UV-HUB Processor Socket Address Format:
  63. * +----------------+---------------+---------------------+
  64. * |00..000000000000| PNODE | NodeOffset |
  65. * +----------------+---------------+---------------------+
  66. * <--- N bits --->|<--------M bits ----->
  67. *
  68. * M - number of node offset bits (35 .. 40)
  69. * N - number of PNODE bits (0 .. 10)
  70. *
  71. * Note: M + N cannot currently exceed 44 (x86_64) or 46 (IA64).
  72. * The actual values are configuration dependent and are set at
  73. * boot time. M & N values are set by the hardware/BIOS at boot.
  74. *
  75. *
  76. * APICID format
  77. * NOTE!!!!!! This is the current format of the APICID. However, code
  78. * should assume that this will change in the future. Use functions
  79. * in this file for all APICID bit manipulations and conversion.
  80. *
  81. * 1111110000000000
  82. * 5432109876543210
  83. * pppppppppplc0cch Nehalem-EX (12 bits in hdw reg)
  84. * ppppppppplcc0cch Westmere-EX (12 bits in hdw reg)
  85. * pppppppppppcccch SandyBridge (15 bits in hdw reg)
  86. * sssssssssss
  87. *
  88. * p = pnode bits
  89. * l = socket number on board
  90. * c = core
  91. * h = hyperthread
  92. * s = bits that are in the SOCKET_ID CSR
  93. *
  94. * Note: Processor may support fewer bits in the APICID register. The ACPI
  95. * tables hold all 16 bits. Software needs to be aware of this.
  96. *
  97. * Unless otherwise specified, all references to APICID refer to
  98. * the FULL value contained in ACPI tables, not the subset in the
  99. * processor APICID register.
  100. */
  101. /*
  102. * Maximum number of bricks in all partitions and in all coherency domains.
  103. * This is the total number of bricks accessible in the numalink fabric. It
  104. * includes all C & M bricks. Routers are NOT included.
  105. *
  106. * This value is also the value of the maximum number of non-router NASIDs
  107. * in the numalink fabric.
  108. *
  109. * NOTE: a brick may contain 1 or 2 OS nodes. Don't get these confused.
  110. */
  111. #define UV_MAX_NUMALINK_BLADES 16384
  112. /*
  113. * Maximum number of C/Mbricks within a software SSI (hardware may support
  114. * more).
  115. */
  116. #define UV_MAX_SSI_BLADES 256
  117. /*
  118. * The largest possible NASID of a C or M brick (+ 2)
  119. */
  120. #define UV_MAX_NASID_VALUE (UV_MAX_NUMALINK_BLADES * 2)
  121. struct uv_scir_s {
  122. struct timer_list timer;
  123. unsigned long offset;
  124. unsigned long last;
  125. unsigned long idle_on;
  126. unsigned long idle_off;
  127. unsigned char state;
  128. unsigned char enabled;
  129. };
  130. /*
  131. * The following defines attributes of the HUB chip. These attributes are
  132. * frequently referenced and are kept in the per-cpu data areas of each cpu.
  133. * They are kept together in a struct to minimize cache misses.
  134. */
  135. struct uv_hub_info_s {
  136. unsigned long global_mmr_base;
  137. unsigned long gpa_mask;
  138. unsigned int gnode_extra;
  139. unsigned char hub_revision;
  140. unsigned char apic_pnode_shift;
  141. unsigned char m_shift;
  142. unsigned char n_lshift;
  143. unsigned long gnode_upper;
  144. unsigned long lowmem_remap_top;
  145. unsigned long lowmem_remap_base;
  146. unsigned short pnode;
  147. unsigned short pnode_mask;
  148. unsigned short coherency_domain_number;
  149. unsigned short numa_blade_id;
  150. unsigned char blade_processor_id;
  151. unsigned char m_val;
  152. unsigned char n_val;
  153. struct uv_scir_s scir;
  154. };
  155. DECLARE_PER_CPU(struct uv_hub_info_s, __uv_hub_info);
  156. #define uv_hub_info this_cpu_ptr(&__uv_hub_info)
  157. #define uv_cpu_hub_info(cpu) (&per_cpu(__uv_hub_info, cpu))
  158. /*
  159. * Hub revisions less than UV2_HUB_REVISION_BASE are UV1 hubs. All UV2
  160. * hubs have revision numbers greater than or equal to UV2_HUB_REVISION_BASE.
  161. * This is a software convention - NOT the hardware revision numbers in
  162. * the hub chip.
  163. */
  164. #define UV1_HUB_REVISION_BASE 1
  165. #define UV2_HUB_REVISION_BASE 3
  166. #define UV3_HUB_REVISION_BASE 5
  167. static inline int is_uv1_hub(void)
  168. {
  169. return uv_hub_info->hub_revision < UV2_HUB_REVISION_BASE;
  170. }
  171. static inline int is_uv2_hub(void)
  172. {
  173. return ((uv_hub_info->hub_revision >= UV2_HUB_REVISION_BASE) &&
  174. (uv_hub_info->hub_revision < UV3_HUB_REVISION_BASE));
  175. }
  176. static inline int is_uv3_hub(void)
  177. {
  178. return uv_hub_info->hub_revision >= UV3_HUB_REVISION_BASE;
  179. }
  180. static inline int is_uv_hub(void)
  181. {
  182. return uv_hub_info->hub_revision;
  183. }
  184. /* code common to uv2 and uv3 only */
  185. static inline int is_uvx_hub(void)
  186. {
  187. return uv_hub_info->hub_revision >= UV2_HUB_REVISION_BASE;
  188. }
  189. union uvh_apicid {
  190. unsigned long v;
  191. struct uvh_apicid_s {
  192. unsigned long local_apic_mask : 24;
  193. unsigned long local_apic_shift : 5;
  194. unsigned long unused1 : 3;
  195. unsigned long pnode_mask : 24;
  196. unsigned long pnode_shift : 5;
  197. unsigned long unused2 : 3;
  198. } s;
  199. };
  200. /*
  201. * Local & Global MMR space macros.
  202. * Note: macros are intended to be used ONLY by inline functions
  203. * in this file - not by other kernel code.
  204. * n - NASID (full 15-bit global nasid)
  205. * g - GNODE (full 15-bit global nasid, right shifted 1)
  206. * p - PNODE (local part of nsids, right shifted 1)
  207. */
  208. #define UV_NASID_TO_PNODE(n) (((n) >> 1) & uv_hub_info->pnode_mask)
  209. #define UV_PNODE_TO_GNODE(p) ((p) |uv_hub_info->gnode_extra)
  210. #define UV_PNODE_TO_NASID(p) (UV_PNODE_TO_GNODE(p) << 1)
  211. #define UV1_LOCAL_MMR_BASE 0xf4000000UL
  212. #define UV1_GLOBAL_MMR32_BASE 0xf8000000UL
  213. #define UV1_LOCAL_MMR_SIZE (64UL * 1024 * 1024)
  214. #define UV1_GLOBAL_MMR32_SIZE (64UL * 1024 * 1024)
  215. #define UV2_LOCAL_MMR_BASE 0xfa000000UL
  216. #define UV2_GLOBAL_MMR32_BASE 0xfc000000UL
  217. #define UV2_LOCAL_MMR_SIZE (32UL * 1024 * 1024)
  218. #define UV2_GLOBAL_MMR32_SIZE (32UL * 1024 * 1024)
  219. #define UV3_LOCAL_MMR_BASE 0xfa000000UL
  220. #define UV3_GLOBAL_MMR32_BASE 0xfc000000UL
  221. #define UV3_LOCAL_MMR_SIZE (32UL * 1024 * 1024)
  222. #define UV3_GLOBAL_MMR32_SIZE (32UL * 1024 * 1024)
  223. #define UV_LOCAL_MMR_BASE (is_uv1_hub() ? UV1_LOCAL_MMR_BASE : \
  224. (is_uv2_hub() ? UV2_LOCAL_MMR_BASE : \
  225. UV3_LOCAL_MMR_BASE))
  226. #define UV_GLOBAL_MMR32_BASE (is_uv1_hub() ? UV1_GLOBAL_MMR32_BASE :\
  227. (is_uv2_hub() ? UV2_GLOBAL_MMR32_BASE :\
  228. UV3_GLOBAL_MMR32_BASE))
  229. #define UV_LOCAL_MMR_SIZE (is_uv1_hub() ? UV1_LOCAL_MMR_SIZE : \
  230. (is_uv2_hub() ? UV2_LOCAL_MMR_SIZE : \
  231. UV3_LOCAL_MMR_SIZE))
  232. #define UV_GLOBAL_MMR32_SIZE (is_uv1_hub() ? UV1_GLOBAL_MMR32_SIZE :\
  233. (is_uv2_hub() ? UV2_GLOBAL_MMR32_SIZE :\
  234. UV3_GLOBAL_MMR32_SIZE))
  235. #define UV_GLOBAL_MMR64_BASE (uv_hub_info->global_mmr_base)
  236. #define UV_GLOBAL_GRU_MMR_BASE 0x4000000
  237. #define UV_GLOBAL_MMR32_PNODE_SHIFT 15
  238. #define UV_GLOBAL_MMR64_PNODE_SHIFT 26
  239. #define UV_GLOBAL_MMR32_PNODE_BITS(p) ((p) << (UV_GLOBAL_MMR32_PNODE_SHIFT))
  240. #define UV_GLOBAL_MMR64_PNODE_BITS(p) \
  241. (((unsigned long)(p)) << UV_GLOBAL_MMR64_PNODE_SHIFT)
  242. #define UVH_APICID 0x002D0E00L
  243. #define UV_APIC_PNODE_SHIFT 6
  244. #define UV_APICID_HIBIT_MASK 0xffff0000
  245. /* Local Bus from cpu's perspective */
  246. #define LOCAL_BUS_BASE 0x1c00000
  247. #define LOCAL_BUS_SIZE (4 * 1024 * 1024)
  248. /*
  249. * System Controller Interface Reg
  250. *
  251. * Note there are NO leds on a UV system. This register is only
  252. * used by the system controller to monitor system-wide operation.
  253. * There are 64 regs per node. With Nahelem cpus (2 cores per node,
  254. * 8 cpus per core, 2 threads per cpu) there are 32 cpu threads on
  255. * a node.
  256. *
  257. * The window is located at top of ACPI MMR space
  258. */
  259. #define SCIR_WINDOW_COUNT 64
  260. #define SCIR_LOCAL_MMR_BASE (LOCAL_BUS_BASE + \
  261. LOCAL_BUS_SIZE - \
  262. SCIR_WINDOW_COUNT)
  263. #define SCIR_CPU_HEARTBEAT 0x01 /* timer interrupt */
  264. #define SCIR_CPU_ACTIVITY 0x02 /* not idle */
  265. #define SCIR_CPU_HB_INTERVAL (HZ) /* once per second */
  266. /* Loop through all installed blades */
  267. #define for_each_possible_blade(bid) \
  268. for ((bid) = 0; (bid) < uv_num_possible_blades(); (bid)++)
  269. /*
  270. * Macros for converting between kernel virtual addresses, socket local physical
  271. * addresses, and UV global physical addresses.
  272. * Note: use the standard __pa() & __va() macros for converting
  273. * between socket virtual and socket physical addresses.
  274. */
  275. /* socket phys RAM --> UV global physical address */
  276. static inline unsigned long uv_soc_phys_ram_to_gpa(unsigned long paddr)
  277. {
  278. if (paddr < uv_hub_info->lowmem_remap_top)
  279. paddr |= uv_hub_info->lowmem_remap_base;
  280. paddr |= uv_hub_info->gnode_upper;
  281. paddr = ((paddr << uv_hub_info->m_shift) >> uv_hub_info->m_shift) |
  282. ((paddr >> uv_hub_info->m_val) << uv_hub_info->n_lshift);
  283. return paddr;
  284. }
  285. /* socket virtual --> UV global physical address */
  286. static inline unsigned long uv_gpa(void *v)
  287. {
  288. return uv_soc_phys_ram_to_gpa(__pa(v));
  289. }
  290. /* Top two bits indicate the requested address is in MMR space. */
  291. static inline int
  292. uv_gpa_in_mmr_space(unsigned long gpa)
  293. {
  294. return (gpa >> 62) == 0x3UL;
  295. }
  296. /* UV global physical address --> socket phys RAM */
  297. static inline unsigned long uv_gpa_to_soc_phys_ram(unsigned long gpa)
  298. {
  299. unsigned long paddr;
  300. unsigned long remap_base = uv_hub_info->lowmem_remap_base;
  301. unsigned long remap_top = uv_hub_info->lowmem_remap_top;
  302. gpa = ((gpa << uv_hub_info->m_shift) >> uv_hub_info->m_shift) |
  303. ((gpa >> uv_hub_info->n_lshift) << uv_hub_info->m_val);
  304. paddr = gpa & uv_hub_info->gpa_mask;
  305. if (paddr >= remap_base && paddr < remap_base + remap_top)
  306. paddr -= remap_base;
  307. return paddr;
  308. }
  309. /* gpa -> pnode */
  310. static inline unsigned long uv_gpa_to_gnode(unsigned long gpa)
  311. {
  312. return gpa >> uv_hub_info->n_lshift;
  313. }
  314. /* gpa -> pnode */
  315. static inline int uv_gpa_to_pnode(unsigned long gpa)
  316. {
  317. unsigned long n_mask = (1UL << uv_hub_info->n_val) - 1;
  318. return uv_gpa_to_gnode(gpa) & n_mask;
  319. }
  320. /* gpa -> node offset*/
  321. static inline unsigned long uv_gpa_to_offset(unsigned long gpa)
  322. {
  323. return (gpa << uv_hub_info->m_shift) >> uv_hub_info->m_shift;
  324. }
  325. /* pnode, offset --> socket virtual */
  326. static inline void *uv_pnode_offset_to_vaddr(int pnode, unsigned long offset)
  327. {
  328. return __va(((unsigned long)pnode << uv_hub_info->m_val) | offset);
  329. }
  330. /*
  331. * Extract a PNODE from an APICID (full apicid, not processor subset)
  332. */
  333. static inline int uv_apicid_to_pnode(int apicid)
  334. {
  335. return (apicid >> uv_hub_info->apic_pnode_shift);
  336. }
  337. /*
  338. * Convert an apicid to the socket number on the blade
  339. */
  340. static inline int uv_apicid_to_socket(int apicid)
  341. {
  342. if (is_uv1_hub())
  343. return (apicid >> (uv_hub_info->apic_pnode_shift - 1)) & 1;
  344. else
  345. return 0;
  346. }
  347. /*
  348. * Access global MMRs using the low memory MMR32 space. This region supports
  349. * faster MMR access but not all MMRs are accessible in this space.
  350. */
  351. static inline unsigned long *uv_global_mmr32_address(int pnode, unsigned long offset)
  352. {
  353. return __va(UV_GLOBAL_MMR32_BASE |
  354. UV_GLOBAL_MMR32_PNODE_BITS(pnode) | offset);
  355. }
  356. static inline void uv_write_global_mmr32(int pnode, unsigned long offset, unsigned long val)
  357. {
  358. writeq(val, uv_global_mmr32_address(pnode, offset));
  359. }
  360. static inline unsigned long uv_read_global_mmr32(int pnode, unsigned long offset)
  361. {
  362. return readq(uv_global_mmr32_address(pnode, offset));
  363. }
  364. /*
  365. * Access Global MMR space using the MMR space located at the top of physical
  366. * memory.
  367. */
  368. static inline volatile void __iomem *uv_global_mmr64_address(int pnode, unsigned long offset)
  369. {
  370. return __va(UV_GLOBAL_MMR64_BASE |
  371. UV_GLOBAL_MMR64_PNODE_BITS(pnode) | offset);
  372. }
  373. static inline void uv_write_global_mmr64(int pnode, unsigned long offset, unsigned long val)
  374. {
  375. writeq(val, uv_global_mmr64_address(pnode, offset));
  376. }
  377. static inline unsigned long uv_read_global_mmr64(int pnode, unsigned long offset)
  378. {
  379. return readq(uv_global_mmr64_address(pnode, offset));
  380. }
  381. /*
  382. * Global MMR space addresses when referenced by the GRU. (GRU does
  383. * NOT use socket addressing).
  384. */
  385. static inline unsigned long uv_global_gru_mmr_address(int pnode, unsigned long offset)
  386. {
  387. return UV_GLOBAL_GRU_MMR_BASE | offset |
  388. ((unsigned long)pnode << uv_hub_info->m_val);
  389. }
  390. static inline void uv_write_global_mmr8(int pnode, unsigned long offset, unsigned char val)
  391. {
  392. writeb(val, uv_global_mmr64_address(pnode, offset));
  393. }
  394. static inline unsigned char uv_read_global_mmr8(int pnode, unsigned long offset)
  395. {
  396. return readb(uv_global_mmr64_address(pnode, offset));
  397. }
  398. /*
  399. * Access hub local MMRs. Faster than using global space but only local MMRs
  400. * are accessible.
  401. */
  402. static inline unsigned long *uv_local_mmr_address(unsigned long offset)
  403. {
  404. return __va(UV_LOCAL_MMR_BASE | offset);
  405. }
  406. static inline unsigned long uv_read_local_mmr(unsigned long offset)
  407. {
  408. return readq(uv_local_mmr_address(offset));
  409. }
  410. static inline void uv_write_local_mmr(unsigned long offset, unsigned long val)
  411. {
  412. writeq(val, uv_local_mmr_address(offset));
  413. }
  414. static inline unsigned char uv_read_local_mmr8(unsigned long offset)
  415. {
  416. return readb(uv_local_mmr_address(offset));
  417. }
  418. static inline void uv_write_local_mmr8(unsigned long offset, unsigned char val)
  419. {
  420. writeb(val, uv_local_mmr_address(offset));
  421. }
  422. /*
  423. * Structures and definitions for converting between cpu, node, pnode, and blade
  424. * numbers.
  425. */
  426. struct uv_blade_info {
  427. unsigned short nr_possible_cpus;
  428. unsigned short nr_online_cpus;
  429. unsigned short pnode;
  430. short memory_nid;
  431. spinlock_t nmi_lock; /* obsolete, see uv_hub_nmi */
  432. unsigned long nmi_count; /* obsolete, see uv_hub_nmi */
  433. };
  434. extern struct uv_blade_info *uv_blade_info;
  435. extern short *uv_node_to_blade;
  436. extern short *uv_cpu_to_blade;
  437. extern short uv_possible_blades;
  438. /* Blade-local cpu number of current cpu. Numbered 0 .. <# cpus on the blade> */
  439. static inline int uv_blade_processor_id(void)
  440. {
  441. return uv_hub_info->blade_processor_id;
  442. }
  443. /* Blade number of current cpu. Numnbered 0 .. <#blades -1> */
  444. static inline int uv_numa_blade_id(void)
  445. {
  446. return uv_hub_info->numa_blade_id;
  447. }
  448. /* Convert a cpu number to the the UV blade number */
  449. static inline int uv_cpu_to_blade_id(int cpu)
  450. {
  451. return uv_cpu_to_blade[cpu];
  452. }
  453. /* Convert linux node number to the UV blade number */
  454. static inline int uv_node_to_blade_id(int nid)
  455. {
  456. return uv_node_to_blade[nid];
  457. }
  458. /* Convert a blade id to the PNODE of the blade */
  459. static inline int uv_blade_to_pnode(int bid)
  460. {
  461. return uv_blade_info[bid].pnode;
  462. }
  463. /* Nid of memory node on blade. -1 if no blade-local memory */
  464. static inline int uv_blade_to_memory_nid(int bid)
  465. {
  466. return uv_blade_info[bid].memory_nid;
  467. }
  468. /* Determine the number of possible cpus on a blade */
  469. static inline int uv_blade_nr_possible_cpus(int bid)
  470. {
  471. return uv_blade_info[bid].nr_possible_cpus;
  472. }
  473. /* Determine the number of online cpus on a blade */
  474. static inline int uv_blade_nr_online_cpus(int bid)
  475. {
  476. return uv_blade_info[bid].nr_online_cpus;
  477. }
  478. /* Convert a cpu id to the PNODE of the blade containing the cpu */
  479. static inline int uv_cpu_to_pnode(int cpu)
  480. {
  481. return uv_blade_info[uv_cpu_to_blade_id(cpu)].pnode;
  482. }
  483. /* Convert a linux node number to the PNODE of the blade */
  484. static inline int uv_node_to_pnode(int nid)
  485. {
  486. return uv_blade_info[uv_node_to_blade_id(nid)].pnode;
  487. }
  488. /* Maximum possible number of blades */
  489. static inline int uv_num_possible_blades(void)
  490. {
  491. return uv_possible_blades;
  492. }
  493. /* Per Hub NMI support */
  494. extern void uv_nmi_setup(void);
  495. /* BMC sets a bit this MMR non-zero before sending an NMI */
  496. #define UVH_NMI_MMR UVH_SCRATCH5
  497. #define UVH_NMI_MMR_CLEAR UVH_SCRATCH5_ALIAS
  498. #define UVH_NMI_MMR_SHIFT 63
  499. #define UVH_NMI_MMR_TYPE "SCRATCH5"
  500. /* Newer SMM NMI handler, not present in all systems */
  501. #define UVH_NMI_MMRX UVH_EVENT_OCCURRED0
  502. #define UVH_NMI_MMRX_CLEAR UVH_EVENT_OCCURRED0_ALIAS
  503. #define UVH_NMI_MMRX_SHIFT (is_uv1_hub() ? \
  504. UV1H_EVENT_OCCURRED0_EXTIO_INT0_SHFT :\
  505. UVXH_EVENT_OCCURRED0_EXTIO_INT0_SHFT)
  506. #define UVH_NMI_MMRX_TYPE "EXTIO_INT0"
  507. /* Non-zero indicates newer SMM NMI handler present */
  508. #define UVH_NMI_MMRX_SUPPORTED UVH_EXTIO_INT0_BROADCAST
  509. /* Indicates to BIOS that we want to use the newer SMM NMI handler */
  510. #define UVH_NMI_MMRX_REQ UVH_SCRATCH5_ALIAS_2
  511. #define UVH_NMI_MMRX_REQ_SHIFT 62
  512. struct uv_hub_nmi_s {
  513. raw_spinlock_t nmi_lock;
  514. atomic_t in_nmi; /* flag this node in UV NMI IRQ */
  515. atomic_t cpu_owner; /* last locker of this struct */
  516. atomic_t read_mmr_count; /* count of MMR reads */
  517. atomic_t nmi_count; /* count of true UV NMIs */
  518. unsigned long nmi_value; /* last value read from NMI MMR */
  519. };
  520. struct uv_cpu_nmi_s {
  521. struct uv_hub_nmi_s *hub;
  522. int state;
  523. int pinging;
  524. int queries;
  525. int pings;
  526. };
  527. DECLARE_PER_CPU(struct uv_cpu_nmi_s, uv_cpu_nmi);
  528. #define uv_hub_nmi (uv_cpu_nmi.hub)
  529. #define uv_cpu_nmi_per(cpu) (per_cpu(uv_cpu_nmi, cpu))
  530. #define uv_hub_nmi_per(cpu) (uv_cpu_nmi_per(cpu).hub)
  531. /* uv_cpu_nmi_states */
  532. #define UV_NMI_STATE_OUT 0
  533. #define UV_NMI_STATE_IN 1
  534. #define UV_NMI_STATE_DUMP 2
  535. #define UV_NMI_STATE_DUMP_DONE 3
  536. /* Update SCIR state */
  537. static inline void uv_set_scir_bits(unsigned char value)
  538. {
  539. if (uv_hub_info->scir.state != value) {
  540. uv_hub_info->scir.state = value;
  541. uv_write_local_mmr8(uv_hub_info->scir.offset, value);
  542. }
  543. }
  544. static inline unsigned long uv_scir_offset(int apicid)
  545. {
  546. return SCIR_LOCAL_MMR_BASE | (apicid & 0x3f);
  547. }
  548. static inline void uv_set_cpu_scir_bits(int cpu, unsigned char value)
  549. {
  550. if (uv_cpu_hub_info(cpu)->scir.state != value) {
  551. uv_write_global_mmr8(uv_cpu_to_pnode(cpu),
  552. uv_cpu_hub_info(cpu)->scir.offset, value);
  553. uv_cpu_hub_info(cpu)->scir.state = value;
  554. }
  555. }
  556. extern unsigned int uv_apicid_hibits;
  557. static unsigned long uv_hub_ipi_value(int apicid, int vector, int mode)
  558. {
  559. apicid |= uv_apicid_hibits;
  560. return (1UL << UVH_IPI_INT_SEND_SHFT) |
  561. ((apicid) << UVH_IPI_INT_APIC_ID_SHFT) |
  562. (mode << UVH_IPI_INT_DELIVERY_MODE_SHFT) |
  563. (vector << UVH_IPI_INT_VECTOR_SHFT);
  564. }
  565. static inline void uv_hub_send_ipi(int pnode, int apicid, int vector)
  566. {
  567. unsigned long val;
  568. unsigned long dmode = dest_Fixed;
  569. if (vector == NMI_VECTOR)
  570. dmode = dest_NMI;
  571. val = uv_hub_ipi_value(apicid, vector, dmode);
  572. uv_write_global_mmr64(pnode, UVH_IPI_INT, val);
  573. }
  574. /*
  575. * Get the minimum revision number of the hub chips within the partition.
  576. * 1 - UV1 rev 1.0 initial silicon
  577. * 2 - UV1 rev 2.0 production silicon
  578. * 3 - UV2 rev 1.0 initial silicon
  579. * 5 - UV3 rev 1.0 initial silicon
  580. */
  581. static inline int uv_get_min_hub_revision_id(void)
  582. {
  583. return uv_hub_info->hub_revision;
  584. }
  585. #endif /* CONFIG_X86_64 */
  586. #endif /* _ASM_X86_UV_UV_HUB_H */