x2apic_uv_x.c 26 KB

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