x2apic_uv_x.c 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013
  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 APIC functions (note: not an Intel compatible APIC)
  7. *
  8. * Copyright (C) 2007-2013 Silicon Graphics, Inc. All rights reserved.
  9. */
  10. #include <linux/cpumask.h>
  11. #include <linux/hardirq.h>
  12. #include <linux/proc_fs.h>
  13. #include <linux/threads.h>
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/string.h>
  17. #include <linux/ctype.h>
  18. #include <linux/sched.h>
  19. #include <linux/timer.h>
  20. #include <linux/slab.h>
  21. #include <linux/cpu.h>
  22. #include <linux/init.h>
  23. #include <linux/io.h>
  24. #include <linux/pci.h>
  25. #include <linux/kdebug.h>
  26. #include <linux/delay.h>
  27. #include <linux/crash_dump.h>
  28. #include <asm/uv/uv_mmrs.h>
  29. #include <asm/uv/uv_hub.h>
  30. #include <asm/current.h>
  31. #include <asm/pgtable.h>
  32. #include <asm/uv/bios.h>
  33. #include <asm/uv/uv.h>
  34. #include <asm/apic.h>
  35. #include <asm/ipi.h>
  36. #include <asm/smp.h>
  37. #include <asm/x86_init.h>
  38. #include <asm/emergency-restart.h>
  39. #include <asm/nmi.h>
  40. /* BMC sets a bit this MMR non-zero before sending an NMI */
  41. #define UVH_NMI_MMR UVH_SCRATCH5
  42. #define UVH_NMI_MMR_CLEAR (UVH_NMI_MMR + 8)
  43. #define UV_NMI_PENDING_MASK (1UL << 63)
  44. DEFINE_PER_CPU(unsigned long, cpu_last_nmi_count);
  45. DEFINE_PER_CPU(int, x2apic_extra_bits);
  46. #define PR_DEVEL(fmt, args...) pr_devel("%s: " fmt, __func__, args)
  47. static enum uv_system_type uv_system_type;
  48. static u64 gru_start_paddr, gru_end_paddr;
  49. static union uvh_apicid uvh_apicid;
  50. int uv_min_hub_revision_id;
  51. EXPORT_SYMBOL_GPL(uv_min_hub_revision_id);
  52. unsigned int uv_apicid_hibits;
  53. EXPORT_SYMBOL_GPL(uv_apicid_hibits);
  54. static DEFINE_SPINLOCK(uv_nmi_lock);
  55. static struct apic apic_x2apic_uv_x;
  56. static unsigned long __init uv_early_read_mmr(unsigned long addr)
  57. {
  58. unsigned long val, *mmr;
  59. mmr = early_ioremap(UV_LOCAL_MMR_BASE | addr, sizeof(*mmr));
  60. val = *mmr;
  61. early_iounmap(mmr, sizeof(*mmr));
  62. return val;
  63. }
  64. static inline bool is_GRU_range(u64 start, u64 end)
  65. {
  66. return start >= gru_start_paddr && end <= gru_end_paddr;
  67. }
  68. static bool uv_is_untracked_pat_range(u64 start, u64 end)
  69. {
  70. return is_ISA_range(start, end) || is_GRU_range(start, end);
  71. }
  72. static int __init early_get_pnodeid(void)
  73. {
  74. union uvh_node_id_u node_id;
  75. union uvh_rh_gam_config_mmr_u m_n_config;
  76. int pnode;
  77. /* Currently, all blades have same revision number */
  78. node_id.v = uv_early_read_mmr(UVH_NODE_ID);
  79. m_n_config.v = uv_early_read_mmr(UVH_RH_GAM_CONFIG_MMR);
  80. uv_min_hub_revision_id = node_id.s.revision;
  81. switch (node_id.s.part_number) {
  82. case UV2_HUB_PART_NUMBER:
  83. case UV2_HUB_PART_NUMBER_X:
  84. uv_min_hub_revision_id += UV2_HUB_REVISION_BASE - 1;
  85. break;
  86. case UV3_HUB_PART_NUMBER:
  87. case UV3_HUB_PART_NUMBER_X:
  88. uv_min_hub_revision_id += UV3_HUB_REVISION_BASE - 1;
  89. break;
  90. }
  91. uv_hub_info->hub_revision = uv_min_hub_revision_id;
  92. pnode = (node_id.s.node_id >> 1) & ((1 << m_n_config.s.n_skt) - 1);
  93. return pnode;
  94. }
  95. static void __init early_get_apic_pnode_shift(void)
  96. {
  97. uvh_apicid.v = uv_early_read_mmr(UVH_APICID);
  98. if (!uvh_apicid.v)
  99. /*
  100. * Old bios, use default value
  101. */
  102. uvh_apicid.s.pnode_shift = UV_APIC_PNODE_SHIFT;
  103. }
  104. /*
  105. * Add an extra bit as dictated by bios to the destination apicid of
  106. * interrupts potentially passing through the UV HUB. This prevents
  107. * a deadlock between interrupts and IO port operations.
  108. */
  109. static void __init uv_set_apicid_hibit(void)
  110. {
  111. union uv1h_lb_target_physical_apic_id_mask_u apicid_mask;
  112. if (is_uv1_hub()) {
  113. apicid_mask.v =
  114. uv_early_read_mmr(UV1H_LB_TARGET_PHYSICAL_APIC_ID_MASK);
  115. uv_apicid_hibits =
  116. apicid_mask.s1.bit_enables & UV_APICID_HIBIT_MASK;
  117. }
  118. }
  119. static int __init uv_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
  120. {
  121. int pnodeid, is_uv1, is_uv2, is_uv3;
  122. is_uv1 = !strcmp(oem_id, "SGI");
  123. is_uv2 = !strcmp(oem_id, "SGI2");
  124. is_uv3 = !strncmp(oem_id, "SGI3", 4); /* there are varieties of UV3 */
  125. if (is_uv1 || is_uv2 || is_uv3) {
  126. uv_hub_info->hub_revision =
  127. (is_uv1 ? UV1_HUB_REVISION_BASE :
  128. (is_uv2 ? UV2_HUB_REVISION_BASE :
  129. UV3_HUB_REVISION_BASE));
  130. pnodeid = early_get_pnodeid();
  131. early_get_apic_pnode_shift();
  132. x86_platform.is_untracked_pat_range = uv_is_untracked_pat_range;
  133. x86_platform.nmi_init = uv_nmi_init;
  134. if (!strcmp(oem_table_id, "UVL"))
  135. uv_system_type = UV_LEGACY_APIC;
  136. else if (!strcmp(oem_table_id, "UVX"))
  137. uv_system_type = UV_X2APIC;
  138. else if (!strcmp(oem_table_id, "UVH")) {
  139. __this_cpu_write(x2apic_extra_bits,
  140. pnodeid << uvh_apicid.s.pnode_shift);
  141. uv_system_type = UV_NON_UNIQUE_APIC;
  142. uv_set_apicid_hibit();
  143. return 1;
  144. }
  145. }
  146. return 0;
  147. }
  148. enum uv_system_type get_uv_system_type(void)
  149. {
  150. return uv_system_type;
  151. }
  152. int is_uv_system(void)
  153. {
  154. return uv_system_type != UV_NONE;
  155. }
  156. EXPORT_SYMBOL_GPL(is_uv_system);
  157. DEFINE_PER_CPU(struct uv_hub_info_s, __uv_hub_info);
  158. EXPORT_PER_CPU_SYMBOL_GPL(__uv_hub_info);
  159. struct uv_blade_info *uv_blade_info;
  160. EXPORT_SYMBOL_GPL(uv_blade_info);
  161. short *uv_node_to_blade;
  162. EXPORT_SYMBOL_GPL(uv_node_to_blade);
  163. short *uv_cpu_to_blade;
  164. EXPORT_SYMBOL_GPL(uv_cpu_to_blade);
  165. short uv_possible_blades;
  166. EXPORT_SYMBOL_GPL(uv_possible_blades);
  167. unsigned long sn_rtc_cycles_per_second;
  168. EXPORT_SYMBOL(sn_rtc_cycles_per_second);
  169. static int __cpuinit uv_wakeup_secondary(int phys_apicid, unsigned long start_rip)
  170. {
  171. #ifdef CONFIG_SMP
  172. unsigned long val;
  173. int pnode;
  174. pnode = uv_apicid_to_pnode(phys_apicid);
  175. phys_apicid |= uv_apicid_hibits;
  176. val = (1UL << UVH_IPI_INT_SEND_SHFT) |
  177. (phys_apicid << UVH_IPI_INT_APIC_ID_SHFT) |
  178. ((start_rip << UVH_IPI_INT_VECTOR_SHFT) >> 12) |
  179. APIC_DM_INIT;
  180. uv_write_global_mmr64(pnode, UVH_IPI_INT, val);
  181. val = (1UL << UVH_IPI_INT_SEND_SHFT) |
  182. (phys_apicid << UVH_IPI_INT_APIC_ID_SHFT) |
  183. ((start_rip << UVH_IPI_INT_VECTOR_SHFT) >> 12) |
  184. APIC_DM_STARTUP;
  185. uv_write_global_mmr64(pnode, UVH_IPI_INT, val);
  186. atomic_set(&init_deasserted, 1);
  187. #endif
  188. return 0;
  189. }
  190. static void uv_send_IPI_one(int cpu, int vector)
  191. {
  192. unsigned long apicid;
  193. int pnode;
  194. apicid = per_cpu(x86_cpu_to_apicid, cpu);
  195. pnode = uv_apicid_to_pnode(apicid);
  196. uv_hub_send_ipi(pnode, apicid, vector);
  197. }
  198. static void uv_send_IPI_mask(const struct cpumask *mask, int vector)
  199. {
  200. unsigned int cpu;
  201. for_each_cpu(cpu, mask)
  202. uv_send_IPI_one(cpu, vector);
  203. }
  204. static void uv_send_IPI_mask_allbutself(const struct cpumask *mask, int vector)
  205. {
  206. unsigned int this_cpu = smp_processor_id();
  207. unsigned int cpu;
  208. for_each_cpu(cpu, mask) {
  209. if (cpu != this_cpu)
  210. uv_send_IPI_one(cpu, vector);
  211. }
  212. }
  213. static void uv_send_IPI_allbutself(int vector)
  214. {
  215. unsigned int this_cpu = smp_processor_id();
  216. unsigned int cpu;
  217. for_each_online_cpu(cpu) {
  218. if (cpu != this_cpu)
  219. uv_send_IPI_one(cpu, vector);
  220. }
  221. }
  222. static void uv_send_IPI_all(int vector)
  223. {
  224. uv_send_IPI_mask(cpu_online_mask, vector);
  225. }
  226. static int uv_apic_id_valid(int apicid)
  227. {
  228. return 1;
  229. }
  230. static int uv_apic_id_registered(void)
  231. {
  232. return 1;
  233. }
  234. static void uv_init_apic_ldr(void)
  235. {
  236. }
  237. static int
  238. uv_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
  239. const struct cpumask *andmask,
  240. unsigned int *apicid)
  241. {
  242. int unsigned cpu;
  243. /*
  244. * We're using fixed IRQ delivery, can only return one phys APIC ID.
  245. * May as well be the first.
  246. */
  247. for_each_cpu_and(cpu, cpumask, andmask) {
  248. if (cpumask_test_cpu(cpu, cpu_online_mask))
  249. break;
  250. }
  251. if (likely(cpu < nr_cpu_ids)) {
  252. *apicid = per_cpu(x86_cpu_to_apicid, cpu) | uv_apicid_hibits;
  253. return 0;
  254. }
  255. return -EINVAL;
  256. }
  257. static unsigned int x2apic_get_apic_id(unsigned long x)
  258. {
  259. unsigned int id;
  260. WARN_ON(preemptible() && num_online_cpus() > 1);
  261. id = x | __this_cpu_read(x2apic_extra_bits);
  262. return id;
  263. }
  264. static unsigned long set_apic_id(unsigned int id)
  265. {
  266. unsigned long x;
  267. /* maskout x2apic_extra_bits ? */
  268. x = id;
  269. return x;
  270. }
  271. static unsigned int uv_read_apic_id(void)
  272. {
  273. return x2apic_get_apic_id(apic_read(APIC_ID));
  274. }
  275. static int uv_phys_pkg_id(int initial_apicid, int index_msb)
  276. {
  277. return uv_read_apic_id() >> index_msb;
  278. }
  279. static void uv_send_IPI_self(int vector)
  280. {
  281. apic_write(APIC_SELF_IPI, vector);
  282. }
  283. static int uv_probe(void)
  284. {
  285. return apic == &apic_x2apic_uv_x;
  286. }
  287. static struct apic __refdata apic_x2apic_uv_x = {
  288. .name = "UV large system",
  289. .probe = uv_probe,
  290. .acpi_madt_oem_check = uv_acpi_madt_oem_check,
  291. .apic_id_valid = uv_apic_id_valid,
  292. .apic_id_registered = uv_apic_id_registered,
  293. .irq_delivery_mode = dest_Fixed,
  294. .irq_dest_mode = 0, /* physical */
  295. .target_cpus = online_target_cpus,
  296. .disable_esr = 0,
  297. .dest_logical = APIC_DEST_LOGICAL,
  298. .check_apicid_used = NULL,
  299. .check_apicid_present = NULL,
  300. .vector_allocation_domain = default_vector_allocation_domain,
  301. .init_apic_ldr = uv_init_apic_ldr,
  302. .ioapic_phys_id_map = NULL,
  303. .setup_apic_routing = NULL,
  304. .multi_timer_check = NULL,
  305. .cpu_present_to_apicid = default_cpu_present_to_apicid,
  306. .apicid_to_cpu_present = NULL,
  307. .setup_portio_remap = NULL,
  308. .check_phys_apicid_present = default_check_phys_apicid_present,
  309. .enable_apic_mode = NULL,
  310. .phys_pkg_id = uv_phys_pkg_id,
  311. .mps_oem_check = NULL,
  312. .get_apic_id = x2apic_get_apic_id,
  313. .set_apic_id = set_apic_id,
  314. .apic_id_mask = 0xFFFFFFFFu,
  315. .cpu_mask_to_apicid_and = uv_cpu_mask_to_apicid_and,
  316. .send_IPI_mask = uv_send_IPI_mask,
  317. .send_IPI_mask_allbutself = uv_send_IPI_mask_allbutself,
  318. .send_IPI_allbutself = uv_send_IPI_allbutself,
  319. .send_IPI_all = uv_send_IPI_all,
  320. .send_IPI_self = uv_send_IPI_self,
  321. .wakeup_secondary_cpu = uv_wakeup_secondary,
  322. .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
  323. .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
  324. .wait_for_init_deassert = NULL,
  325. .smp_callin_clear_local_apic = NULL,
  326. .inquire_remote_apic = NULL,
  327. .read = native_apic_msr_read,
  328. .write = native_apic_msr_write,
  329. .eoi_write = native_apic_msr_eoi_write,
  330. .icr_read = native_x2apic_icr_read,
  331. .icr_write = native_x2apic_icr_write,
  332. .wait_icr_idle = native_x2apic_wait_icr_idle,
  333. .safe_wait_icr_idle = native_safe_x2apic_wait_icr_idle,
  334. };
  335. static __cpuinit void set_x2apic_extra_bits(int pnode)
  336. {
  337. __this_cpu_write(x2apic_extra_bits, pnode << uvh_apicid.s.pnode_shift);
  338. }
  339. /*
  340. * Called on boot cpu.
  341. */
  342. static __init int boot_pnode_to_blade(int pnode)
  343. {
  344. int blade;
  345. for (blade = 0; blade < uv_num_possible_blades(); blade++)
  346. if (pnode == uv_blade_info[blade].pnode)
  347. return blade;
  348. BUG();
  349. }
  350. struct redir_addr {
  351. unsigned long redirect;
  352. unsigned long alias;
  353. };
  354. #define DEST_SHIFT UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_0_MMR_DEST_BASE_SHFT
  355. static __initdata struct redir_addr redir_addrs[] = {
  356. {UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_0_MMR, UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_0_MMR},
  357. {UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_1_MMR, UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_1_MMR},
  358. {UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_2_MMR, UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_2_MMR},
  359. };
  360. static __init void get_lowmem_redirect(unsigned long *base, unsigned long *size)
  361. {
  362. union uvh_rh_gam_alias210_overlay_config_2_mmr_u alias;
  363. union uvh_rh_gam_alias210_redirect_config_2_mmr_u redirect;
  364. int i;
  365. for (i = 0; i < ARRAY_SIZE(redir_addrs); i++) {
  366. alias.v = uv_read_local_mmr(redir_addrs[i].alias);
  367. if (alias.s.enable && alias.s.base == 0) {
  368. *size = (1UL << alias.s.m_alias);
  369. redirect.v = uv_read_local_mmr(redir_addrs[i].redirect);
  370. *base = (unsigned long)redirect.s.dest_base << DEST_SHIFT;
  371. return;
  372. }
  373. }
  374. *base = *size = 0;
  375. }
  376. enum map_type {map_wb, map_uc};
  377. static __init void map_high(char *id, unsigned long base, int pshift,
  378. int bshift, int max_pnode, enum map_type map_type)
  379. {
  380. unsigned long bytes, paddr;
  381. paddr = base << pshift;
  382. bytes = (1UL << bshift) * (max_pnode + 1);
  383. if (!paddr) {
  384. pr_info("UV: Map %s_HI base address NULL\n", id);
  385. return;
  386. }
  387. pr_info("UV: Map %s_HI 0x%lx - 0x%lx\n", id, paddr, paddr + bytes);
  388. if (map_type == map_uc)
  389. init_extra_mapping_uc(paddr, bytes);
  390. else
  391. init_extra_mapping_wb(paddr, bytes);
  392. }
  393. static __init void map_gru_high(int max_pnode)
  394. {
  395. union uvh_rh_gam_gru_overlay_config_mmr_u gru;
  396. int shift = UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_BASE_SHFT;
  397. gru.v = uv_read_local_mmr(UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR);
  398. if (gru.s.enable) {
  399. map_high("GRU", gru.s.base, shift, shift, max_pnode, map_wb);
  400. gru_start_paddr = ((u64)gru.s.base << shift);
  401. gru_end_paddr = gru_start_paddr + (1UL << shift) * (max_pnode + 1);
  402. } else {
  403. pr_info("UV: GRU disabled\n");
  404. }
  405. }
  406. static __init void map_mmr_high(int max_pnode)
  407. {
  408. union uvh_rh_gam_mmr_overlay_config_mmr_u mmr;
  409. int shift = UVH_RH_GAM_MMR_OVERLAY_CONFIG_MMR_BASE_SHFT;
  410. mmr.v = uv_read_local_mmr(UVH_RH_GAM_MMR_OVERLAY_CONFIG_MMR);
  411. if (mmr.s.enable)
  412. map_high("MMR", mmr.s.base, shift, shift, max_pnode, map_uc);
  413. else
  414. pr_info("UV: MMR disabled\n");
  415. }
  416. /*
  417. * This commonality works because both 0 & 1 versions of the MMIOH OVERLAY
  418. * and REDIRECT MMR regs are exactly the same on UV3.
  419. */
  420. struct mmioh_config {
  421. unsigned long overlay;
  422. unsigned long redirect;
  423. char *id;
  424. };
  425. static __initdata struct mmioh_config mmiohs[] = {
  426. {
  427. UV3H_RH_GAM_MMIOH_OVERLAY_CONFIG0_MMR,
  428. UV3H_RH_GAM_MMIOH_REDIRECT_CONFIG0_MMR,
  429. "MMIOH0"
  430. },
  431. {
  432. UV3H_RH_GAM_MMIOH_OVERLAY_CONFIG1_MMR,
  433. UV3H_RH_GAM_MMIOH_REDIRECT_CONFIG1_MMR,
  434. "MMIOH1"
  435. },
  436. };
  437. static __init void map_mmioh_high_uv3(int index, int min_pnode, int max_pnode)
  438. {
  439. union uv3h_rh_gam_mmioh_overlay_config0_mmr_u overlay;
  440. unsigned long mmr;
  441. unsigned long base;
  442. int i, n, shift, m_io, max_io;
  443. int nasid, lnasid, fi, li;
  444. char *id;
  445. id = mmiohs[index].id;
  446. overlay.v = uv_read_local_mmr(mmiohs[index].overlay);
  447. pr_info("UV: %s overlay 0x%lx base:0x%x m_io:%d\n",
  448. id, overlay.v, overlay.s3.base, overlay.s3.m_io);
  449. if (!overlay.s3.enable) {
  450. pr_info("UV: %s disabled\n", id);
  451. return;
  452. }
  453. shift = UV3H_RH_GAM_MMIOH_OVERLAY_CONFIG0_MMR_BASE_SHFT;
  454. base = (unsigned long)overlay.s3.base;
  455. m_io = overlay.s3.m_io;
  456. mmr = mmiohs[index].redirect;
  457. n = UV3H_RH_GAM_MMIOH_REDIRECT_CONFIG0_MMR_DEPTH;
  458. min_pnode *= 2; /* convert to NASID */
  459. max_pnode *= 2;
  460. max_io = lnasid = fi = li = -1;
  461. for (i = 0; i < n; i++) {
  462. union uv3h_rh_gam_mmioh_redirect_config0_mmr_u redirect;
  463. redirect.v = uv_read_local_mmr(mmr + i * 8);
  464. nasid = redirect.s3.nasid;
  465. if (nasid < min_pnode || max_pnode < nasid)
  466. nasid = -1; /* invalid NASID */
  467. if (nasid == lnasid) {
  468. li = i;
  469. if (i != n-1) /* last entry check */
  470. continue;
  471. }
  472. /* check if we have a cached (or last) redirect to print */
  473. if (lnasid != -1 || (i == n-1 && nasid != -1)) {
  474. unsigned long addr1, addr2;
  475. int f, l;
  476. if (lnasid == -1) {
  477. f = l = i;
  478. lnasid = nasid;
  479. } else {
  480. f = fi;
  481. l = li;
  482. }
  483. addr1 = (base << shift) +
  484. f * (unsigned long)(1 << m_io);
  485. addr2 = (base << shift) +
  486. (l + 1) * (unsigned long)(1 << m_io);
  487. pr_info("UV: %s[%03d..%03d] NASID 0x%04x ADDR 0x%016lx - 0x%016lx\n",
  488. id, fi, li, lnasid, addr1, addr2);
  489. if (max_io < l)
  490. max_io = l;
  491. }
  492. fi = li = i;
  493. lnasid = nasid;
  494. }
  495. pr_info("UV: %s base:0x%lx shift:%d M_IO:%d MAX_IO:%d\n",
  496. id, base, shift, m_io, max_io);
  497. if (max_io >= 0)
  498. map_high(id, base, shift, m_io, max_io, map_uc);
  499. }
  500. static __init void map_mmioh_high(int min_pnode, int max_pnode)
  501. {
  502. union uvh_rh_gam_mmioh_overlay_config_mmr_u mmioh;
  503. unsigned long mmr, base;
  504. int shift, enable, m_io, n_io;
  505. if (is_uv3_hub()) {
  506. /* Map both MMIOH Regions */
  507. map_mmioh_high_uv3(0, min_pnode, max_pnode);
  508. map_mmioh_high_uv3(1, min_pnode, max_pnode);
  509. return;
  510. }
  511. if (is_uv1_hub()) {
  512. mmr = UV1H_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR;
  513. shift = UV1H_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR_BASE_SHFT;
  514. mmioh.v = uv_read_local_mmr(mmr);
  515. enable = !!mmioh.s1.enable;
  516. base = mmioh.s1.base;
  517. m_io = mmioh.s1.m_io;
  518. n_io = mmioh.s1.n_io;
  519. } else if (is_uv2_hub()) {
  520. mmr = UV2H_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR;
  521. shift = UV2H_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR_BASE_SHFT;
  522. mmioh.v = uv_read_local_mmr(mmr);
  523. enable = !!mmioh.s2.enable;
  524. base = mmioh.s2.base;
  525. m_io = mmioh.s2.m_io;
  526. n_io = mmioh.s2.n_io;
  527. } else
  528. return;
  529. if (enable) {
  530. max_pnode &= (1 << n_io) - 1;
  531. pr_info(
  532. "UV: base:0x%lx shift:%d N_IO:%d M_IO:%d max_pnode:0x%x\n",
  533. base, shift, m_io, n_io, max_pnode);
  534. map_high("MMIOH", base, shift, m_io, max_pnode, map_uc);
  535. } else {
  536. pr_info("UV: MMIOH disabled\n");
  537. }
  538. }
  539. static __init void map_low_mmrs(void)
  540. {
  541. init_extra_mapping_uc(UV_GLOBAL_MMR32_BASE, UV_GLOBAL_MMR32_SIZE);
  542. init_extra_mapping_uc(UV_LOCAL_MMR_BASE, UV_LOCAL_MMR_SIZE);
  543. }
  544. static __init void uv_rtc_init(void)
  545. {
  546. long status;
  547. u64 ticks_per_sec;
  548. status = uv_bios_freq_base(BIOS_FREQ_BASE_REALTIME_CLOCK,
  549. &ticks_per_sec);
  550. if (status != BIOS_STATUS_SUCCESS || ticks_per_sec < 100000) {
  551. printk(KERN_WARNING
  552. "unable to determine platform RTC clock frequency, "
  553. "guessing.\n");
  554. /* BIOS gives wrong value for clock freq. so guess */
  555. sn_rtc_cycles_per_second = 1000000000000UL / 30000UL;
  556. } else
  557. sn_rtc_cycles_per_second = ticks_per_sec;
  558. }
  559. /*
  560. * percpu heartbeat timer
  561. */
  562. static void uv_heartbeat(unsigned long ignored)
  563. {
  564. struct timer_list *timer = &uv_hub_info->scir.timer;
  565. unsigned char bits = uv_hub_info->scir.state;
  566. /* flip heartbeat bit */
  567. bits ^= SCIR_CPU_HEARTBEAT;
  568. /* is this cpu idle? */
  569. if (idle_cpu(raw_smp_processor_id()))
  570. bits &= ~SCIR_CPU_ACTIVITY;
  571. else
  572. bits |= SCIR_CPU_ACTIVITY;
  573. /* update system controller interface reg */
  574. uv_set_scir_bits(bits);
  575. /* enable next timer period */
  576. mod_timer_pinned(timer, jiffies + SCIR_CPU_HB_INTERVAL);
  577. }
  578. static void __cpuinit uv_heartbeat_enable(int cpu)
  579. {
  580. while (!uv_cpu_hub_info(cpu)->scir.enabled) {
  581. struct timer_list *timer = &uv_cpu_hub_info(cpu)->scir.timer;
  582. uv_set_cpu_scir_bits(cpu, SCIR_CPU_HEARTBEAT|SCIR_CPU_ACTIVITY);
  583. setup_timer(timer, uv_heartbeat, cpu);
  584. timer->expires = jiffies + SCIR_CPU_HB_INTERVAL;
  585. add_timer_on(timer, cpu);
  586. uv_cpu_hub_info(cpu)->scir.enabled = 1;
  587. /* also ensure that boot cpu is enabled */
  588. cpu = 0;
  589. }
  590. }
  591. #ifdef CONFIG_HOTPLUG_CPU
  592. static void __cpuinit uv_heartbeat_disable(int cpu)
  593. {
  594. if (uv_cpu_hub_info(cpu)->scir.enabled) {
  595. uv_cpu_hub_info(cpu)->scir.enabled = 0;
  596. del_timer(&uv_cpu_hub_info(cpu)->scir.timer);
  597. }
  598. uv_set_cpu_scir_bits(cpu, 0xff);
  599. }
  600. /*
  601. * cpu hotplug notifier
  602. */
  603. static __cpuinit int uv_scir_cpu_notify(struct notifier_block *self,
  604. unsigned long action, void *hcpu)
  605. {
  606. long cpu = (long)hcpu;
  607. switch (action) {
  608. case CPU_ONLINE:
  609. uv_heartbeat_enable(cpu);
  610. break;
  611. case CPU_DOWN_PREPARE:
  612. uv_heartbeat_disable(cpu);
  613. break;
  614. default:
  615. break;
  616. }
  617. return NOTIFY_OK;
  618. }
  619. static __init void uv_scir_register_cpu_notifier(void)
  620. {
  621. hotcpu_notifier(uv_scir_cpu_notify, 0);
  622. }
  623. #else /* !CONFIG_HOTPLUG_CPU */
  624. static __init void uv_scir_register_cpu_notifier(void)
  625. {
  626. }
  627. static __init int uv_init_heartbeat(void)
  628. {
  629. int cpu;
  630. if (is_uv_system())
  631. for_each_online_cpu(cpu)
  632. uv_heartbeat_enable(cpu);
  633. return 0;
  634. }
  635. late_initcall(uv_init_heartbeat);
  636. #endif /* !CONFIG_HOTPLUG_CPU */
  637. /* Direct Legacy VGA I/O traffic to designated IOH */
  638. int uv_set_vga_state(struct pci_dev *pdev, bool decode,
  639. unsigned int command_bits, u32 flags)
  640. {
  641. int domain, bus, rc;
  642. PR_DEVEL("devfn %x decode %d cmd %x flags %d\n",
  643. pdev->devfn, decode, command_bits, flags);
  644. if (!(flags & PCI_VGA_STATE_CHANGE_BRIDGE))
  645. return 0;
  646. if ((command_bits & PCI_COMMAND_IO) == 0)
  647. return 0;
  648. domain = pci_domain_nr(pdev->bus);
  649. bus = pdev->bus->number;
  650. rc = uv_bios_set_legacy_vga_target(decode, domain, bus);
  651. PR_DEVEL("vga decode %d %x:%x, rc: %d\n", decode, domain, bus, rc);
  652. return rc;
  653. }
  654. /*
  655. * Called on each cpu to initialize the per_cpu UV data area.
  656. * FIXME: hotplug not supported yet
  657. */
  658. void __cpuinit uv_cpu_init(void)
  659. {
  660. /* CPU 0 initilization will be done via uv_system_init. */
  661. if (!uv_blade_info)
  662. return;
  663. uv_blade_info[uv_numa_blade_id()].nr_online_cpus++;
  664. if (get_uv_system_type() == UV_NON_UNIQUE_APIC)
  665. set_x2apic_extra_bits(uv_hub_info->pnode);
  666. }
  667. /*
  668. * When NMI is received, print a stack trace.
  669. */
  670. int uv_handle_nmi(unsigned int reason, struct pt_regs *regs)
  671. {
  672. unsigned long real_uv_nmi;
  673. int bid;
  674. /*
  675. * Each blade has an MMR that indicates when an NMI has been sent
  676. * to cpus on the blade. If an NMI is detected, atomically
  677. * clear the MMR and update a per-blade NMI count used to
  678. * cause each cpu on the blade to notice a new NMI.
  679. */
  680. bid = uv_numa_blade_id();
  681. real_uv_nmi = (uv_read_local_mmr(UVH_NMI_MMR) & UV_NMI_PENDING_MASK);
  682. if (unlikely(real_uv_nmi)) {
  683. spin_lock(&uv_blade_info[bid].nmi_lock);
  684. real_uv_nmi = (uv_read_local_mmr(UVH_NMI_MMR) & UV_NMI_PENDING_MASK);
  685. if (real_uv_nmi) {
  686. uv_blade_info[bid].nmi_count++;
  687. uv_write_local_mmr(UVH_NMI_MMR_CLEAR, UV_NMI_PENDING_MASK);
  688. }
  689. spin_unlock(&uv_blade_info[bid].nmi_lock);
  690. }
  691. if (likely(__get_cpu_var(cpu_last_nmi_count) == uv_blade_info[bid].nmi_count))
  692. return NMI_DONE;
  693. __get_cpu_var(cpu_last_nmi_count) = uv_blade_info[bid].nmi_count;
  694. /*
  695. * Use a lock so only one cpu prints at a time.
  696. * This prevents intermixed output.
  697. */
  698. spin_lock(&uv_nmi_lock);
  699. pr_info("UV NMI stack dump cpu %u:\n", smp_processor_id());
  700. dump_stack();
  701. spin_unlock(&uv_nmi_lock);
  702. return NMI_HANDLED;
  703. }
  704. void uv_register_nmi_notifier(void)
  705. {
  706. if (register_nmi_handler(NMI_UNKNOWN, uv_handle_nmi, 0, "uv"))
  707. printk(KERN_WARNING "UV NMI handler failed to register\n");
  708. }
  709. void uv_nmi_init(void)
  710. {
  711. unsigned int value;
  712. /*
  713. * Unmask NMI on all cpus
  714. */
  715. value = apic_read(APIC_LVT1) | APIC_DM_NMI;
  716. value &= ~APIC_LVT_MASKED;
  717. apic_write(APIC_LVT1, value);
  718. }
  719. void __init uv_system_init(void)
  720. {
  721. union uvh_rh_gam_config_mmr_u m_n_config;
  722. union uvh_node_id_u node_id;
  723. unsigned long gnode_upper, lowmem_redir_base, lowmem_redir_size;
  724. int bytes, nid, cpu, lcpu, pnode, blade, i, j, m_val, n_val;
  725. int gnode_extra, min_pnode = 999999, max_pnode = -1;
  726. unsigned long mmr_base, present, paddr;
  727. unsigned short pnode_mask;
  728. char *hub = (is_uv1_hub() ? "UV1" :
  729. (is_uv2_hub() ? "UV2" :
  730. "UV3"));
  731. pr_info("UV: Found %s hub\n", hub);
  732. map_low_mmrs();
  733. m_n_config.v = uv_read_local_mmr(UVH_RH_GAM_CONFIG_MMR );
  734. m_val = m_n_config.s.m_skt;
  735. n_val = m_n_config.s.n_skt;
  736. pnode_mask = (1 << n_val) - 1;
  737. mmr_base =
  738. uv_read_local_mmr(UVH_RH_GAM_MMR_OVERLAY_CONFIG_MMR) &
  739. ~UV_MMR_ENABLE;
  740. node_id.v = uv_read_local_mmr(UVH_NODE_ID);
  741. gnode_extra = (node_id.s.node_id & ~((1 << n_val) - 1)) >> 1;
  742. gnode_upper = ((unsigned long)gnode_extra << m_val);
  743. pr_info("UV: N:%d M:%d pnode_mask:0x%x gnode_upper/extra:0x%lx/0x%x\n",
  744. n_val, m_val, pnode_mask, gnode_upper, gnode_extra);
  745. pr_info("UV: global MMR base 0x%lx\n", mmr_base);
  746. for(i = 0; i < UVH_NODE_PRESENT_TABLE_DEPTH; i++)
  747. uv_possible_blades +=
  748. hweight64(uv_read_local_mmr( UVH_NODE_PRESENT_TABLE + i * 8));
  749. /* uv_num_possible_blades() is really the hub count */
  750. pr_info("UV: Found %d blades, %d hubs\n",
  751. is_uv1_hub() ? uv_num_possible_blades() :
  752. (uv_num_possible_blades() + 1) / 2,
  753. uv_num_possible_blades());
  754. bytes = sizeof(struct uv_blade_info) * uv_num_possible_blades();
  755. uv_blade_info = kzalloc(bytes, GFP_KERNEL);
  756. BUG_ON(!uv_blade_info);
  757. for (blade = 0; blade < uv_num_possible_blades(); blade++)
  758. uv_blade_info[blade].memory_nid = -1;
  759. get_lowmem_redirect(&lowmem_redir_base, &lowmem_redir_size);
  760. bytes = sizeof(uv_node_to_blade[0]) * num_possible_nodes();
  761. uv_node_to_blade = kmalloc(bytes, GFP_KERNEL);
  762. BUG_ON(!uv_node_to_blade);
  763. memset(uv_node_to_blade, 255, bytes);
  764. bytes = sizeof(uv_cpu_to_blade[0]) * num_possible_cpus();
  765. uv_cpu_to_blade = kmalloc(bytes, GFP_KERNEL);
  766. BUG_ON(!uv_cpu_to_blade);
  767. memset(uv_cpu_to_blade, 255, bytes);
  768. blade = 0;
  769. for (i = 0; i < UVH_NODE_PRESENT_TABLE_DEPTH; i++) {
  770. present = uv_read_local_mmr(UVH_NODE_PRESENT_TABLE + i * 8);
  771. for (j = 0; j < 64; j++) {
  772. if (!test_bit(j, &present))
  773. continue;
  774. pnode = (i * 64 + j) & pnode_mask;
  775. uv_blade_info[blade].pnode = pnode;
  776. uv_blade_info[blade].nr_possible_cpus = 0;
  777. uv_blade_info[blade].nr_online_cpus = 0;
  778. spin_lock_init(&uv_blade_info[blade].nmi_lock);
  779. min_pnode = min(pnode, min_pnode);
  780. max_pnode = max(pnode, max_pnode);
  781. blade++;
  782. }
  783. }
  784. uv_bios_init();
  785. uv_bios_get_sn_info(0, &uv_type, &sn_partition_id, &sn_coherency_id,
  786. &sn_region_size, &system_serial_number);
  787. uv_rtc_init();
  788. for_each_present_cpu(cpu) {
  789. int apicid = per_cpu(x86_cpu_to_apicid, cpu);
  790. nid = cpu_to_node(cpu);
  791. /*
  792. * apic_pnode_shift must be set before calling uv_apicid_to_pnode();
  793. */
  794. uv_cpu_hub_info(cpu)->pnode_mask = pnode_mask;
  795. uv_cpu_hub_info(cpu)->apic_pnode_shift = uvh_apicid.s.pnode_shift;
  796. uv_cpu_hub_info(cpu)->hub_revision = uv_hub_info->hub_revision;
  797. uv_cpu_hub_info(cpu)->m_shift = 64 - m_val;
  798. uv_cpu_hub_info(cpu)->n_lshift = is_uv2_1_hub() ?
  799. (m_val == 40 ? 40 : 39) : m_val;
  800. pnode = uv_apicid_to_pnode(apicid);
  801. blade = boot_pnode_to_blade(pnode);
  802. lcpu = uv_blade_info[blade].nr_possible_cpus;
  803. uv_blade_info[blade].nr_possible_cpus++;
  804. /* Any node on the blade, else will contain -1. */
  805. uv_blade_info[blade].memory_nid = nid;
  806. uv_cpu_hub_info(cpu)->lowmem_remap_base = lowmem_redir_base;
  807. uv_cpu_hub_info(cpu)->lowmem_remap_top = lowmem_redir_size;
  808. uv_cpu_hub_info(cpu)->m_val = m_val;
  809. uv_cpu_hub_info(cpu)->n_val = n_val;
  810. uv_cpu_hub_info(cpu)->numa_blade_id = blade;
  811. uv_cpu_hub_info(cpu)->blade_processor_id = lcpu;
  812. uv_cpu_hub_info(cpu)->pnode = pnode;
  813. uv_cpu_hub_info(cpu)->gpa_mask = (1UL << (m_val + n_val)) - 1;
  814. uv_cpu_hub_info(cpu)->gnode_upper = gnode_upper;
  815. uv_cpu_hub_info(cpu)->gnode_extra = gnode_extra;
  816. uv_cpu_hub_info(cpu)->global_mmr_base = mmr_base;
  817. uv_cpu_hub_info(cpu)->coherency_domain_number = sn_coherency_id;
  818. uv_cpu_hub_info(cpu)->scir.offset = uv_scir_offset(apicid);
  819. uv_node_to_blade[nid] = blade;
  820. uv_cpu_to_blade[cpu] = blade;
  821. }
  822. /* Add blade/pnode info for nodes without cpus */
  823. for_each_online_node(nid) {
  824. if (uv_node_to_blade[nid] >= 0)
  825. continue;
  826. paddr = node_start_pfn(nid) << PAGE_SHIFT;
  827. pnode = uv_gpa_to_pnode(uv_soc_phys_ram_to_gpa(paddr));
  828. blade = boot_pnode_to_blade(pnode);
  829. uv_node_to_blade[nid] = blade;
  830. }
  831. map_gru_high(max_pnode);
  832. map_mmr_high(max_pnode);
  833. map_mmioh_high(min_pnode, max_pnode);
  834. uv_cpu_init();
  835. uv_scir_register_cpu_notifier();
  836. uv_register_nmi_notifier();
  837. proc_mkdir("sgi_uv", NULL);
  838. /* register Legacy VGA I/O redirection handler */
  839. pci_register_set_vga_state(uv_set_vga_state);
  840. /*
  841. * For a kdump kernel the reset must be BOOT_ACPI, not BOOT_EFI, as
  842. * EFI is not enabled in the kdump kernel.
  843. */
  844. if (is_kdump_kernel())
  845. reboot_type = BOOT_ACPI;
  846. }
  847. apic_driver(apic_x2apic_uv_x);