x2apic_uv_x.c 26 KB

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