x2apic_uv_x.c 26 KB

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