x2apic_uv_x.c 28 KB

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