x2apic_uv_x.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035
  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 = uv_send_IPI_one,
  334. .send_IPI_mask = uv_send_IPI_mask,
  335. .send_IPI_mask_allbutself = uv_send_IPI_mask_allbutself,
  336. .send_IPI_allbutself = uv_send_IPI_allbutself,
  337. .send_IPI_all = uv_send_IPI_all,
  338. .send_IPI_self = uv_send_IPI_self,
  339. .wakeup_secondary_cpu = uv_wakeup_secondary,
  340. .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 unsigned char get_n_lshift(int m_val)
  375. {
  376. union uv3h_gr0_gam_gr_config_u m_gr_config;
  377. if (is_uv1_hub())
  378. return m_val;
  379. if (is_uv2_hub())
  380. return m_val == 40 ? 40 : 39;
  381. m_gr_config.v = uv_read_local_mmr(UV3H_GR0_GAM_GR_CONFIG);
  382. return m_gr_config.s3.m_skt;
  383. }
  384. static __init void get_lowmem_redirect(unsigned long *base, unsigned long *size)
  385. {
  386. union uvh_rh_gam_alias210_overlay_config_2_mmr_u alias;
  387. union uvh_rh_gam_alias210_redirect_config_2_mmr_u redirect;
  388. int i;
  389. for (i = 0; i < ARRAY_SIZE(redir_addrs); i++) {
  390. alias.v = uv_read_local_mmr(redir_addrs[i].alias);
  391. if (alias.s.enable && alias.s.base == 0) {
  392. *size = (1UL << alias.s.m_alias);
  393. redirect.v = uv_read_local_mmr(redir_addrs[i].redirect);
  394. *base = (unsigned long)redirect.s.dest_base << DEST_SHIFT;
  395. return;
  396. }
  397. }
  398. *base = *size = 0;
  399. }
  400. enum map_type {map_wb, map_uc};
  401. static __init void map_high(char *id, unsigned long base, int pshift,
  402. int bshift, int max_pnode, enum map_type map_type)
  403. {
  404. unsigned long bytes, paddr;
  405. paddr = base << pshift;
  406. bytes = (1UL << bshift) * (max_pnode + 1);
  407. if (!paddr) {
  408. pr_info("UV: Map %s_HI base address NULL\n", id);
  409. return;
  410. }
  411. pr_debug("UV: Map %s_HI 0x%lx - 0x%lx\n", id, paddr, paddr + bytes);
  412. if (map_type == map_uc)
  413. init_extra_mapping_uc(paddr, bytes);
  414. else
  415. init_extra_mapping_wb(paddr, bytes);
  416. }
  417. static __init void map_gru_distributed(unsigned long c)
  418. {
  419. union uvh_rh_gam_gru_overlay_config_mmr_u gru;
  420. u64 paddr;
  421. unsigned long bytes;
  422. int nid;
  423. gru.v = c;
  424. /* only base bits 42:28 relevant in dist mode */
  425. gru_dist_base = gru.v & 0x000007fff0000000UL;
  426. if (!gru_dist_base) {
  427. pr_info("UV: Map GRU_DIST base address NULL\n");
  428. return;
  429. }
  430. bytes = 1UL << UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_BASE_SHFT;
  431. gru_dist_lmask = ((1UL << uv_hub_info->m_val) - 1) & ~(bytes - 1);
  432. gru_dist_umask = ~((1UL << uv_hub_info->m_val) - 1);
  433. gru_dist_base &= gru_dist_lmask; /* Clear bits above M */
  434. for_each_online_node(nid) {
  435. paddr = ((u64)uv_node_to_pnode(nid) << uv_hub_info->m_val) |
  436. gru_dist_base;
  437. init_extra_mapping_wb(paddr, bytes);
  438. gru_first_node_paddr = min(paddr, gru_first_node_paddr);
  439. gru_last_node_paddr = max(paddr, gru_last_node_paddr);
  440. }
  441. /* Save upper (63:M) bits of address only for is_GRU_range */
  442. gru_first_node_paddr &= gru_dist_umask;
  443. gru_last_node_paddr &= gru_dist_umask;
  444. pr_debug("UV: Map GRU_DIST base 0x%016llx 0x%016llx - 0x%016llx\n",
  445. gru_dist_base, gru_first_node_paddr, gru_last_node_paddr);
  446. }
  447. static __init void map_gru_high(int max_pnode)
  448. {
  449. union uvh_rh_gam_gru_overlay_config_mmr_u gru;
  450. int shift = UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_BASE_SHFT;
  451. gru.v = uv_read_local_mmr(UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR);
  452. if (!gru.s.enable) {
  453. pr_info("UV: GRU disabled\n");
  454. return;
  455. }
  456. if (is_uv3_hub() && gru.s3.mode) {
  457. map_gru_distributed(gru.v);
  458. return;
  459. }
  460. map_high("GRU", gru.s.base, shift, shift, max_pnode, map_wb);
  461. gru_start_paddr = ((u64)gru.s.base << shift);
  462. gru_end_paddr = gru_start_paddr + (1UL << shift) * (max_pnode + 1);
  463. }
  464. static __init void map_mmr_high(int max_pnode)
  465. {
  466. union uvh_rh_gam_mmr_overlay_config_mmr_u mmr;
  467. int shift = UVH_RH_GAM_MMR_OVERLAY_CONFIG_MMR_BASE_SHFT;
  468. mmr.v = uv_read_local_mmr(UVH_RH_GAM_MMR_OVERLAY_CONFIG_MMR);
  469. if (mmr.s.enable)
  470. map_high("MMR", mmr.s.base, shift, shift, max_pnode, map_uc);
  471. else
  472. pr_info("UV: MMR disabled\n");
  473. }
  474. /*
  475. * This commonality works because both 0 & 1 versions of the MMIOH OVERLAY
  476. * and REDIRECT MMR regs are exactly the same on UV3.
  477. */
  478. struct mmioh_config {
  479. unsigned long overlay;
  480. unsigned long redirect;
  481. char *id;
  482. };
  483. static __initdata struct mmioh_config mmiohs[] = {
  484. {
  485. UV3H_RH_GAM_MMIOH_OVERLAY_CONFIG0_MMR,
  486. UV3H_RH_GAM_MMIOH_REDIRECT_CONFIG0_MMR,
  487. "MMIOH0"
  488. },
  489. {
  490. UV3H_RH_GAM_MMIOH_OVERLAY_CONFIG1_MMR,
  491. UV3H_RH_GAM_MMIOH_REDIRECT_CONFIG1_MMR,
  492. "MMIOH1"
  493. },
  494. };
  495. static __init void map_mmioh_high_uv3(int index, int min_pnode, int max_pnode)
  496. {
  497. union uv3h_rh_gam_mmioh_overlay_config0_mmr_u overlay;
  498. unsigned long mmr;
  499. unsigned long base;
  500. int i, n, shift, m_io, max_io;
  501. int nasid, lnasid, fi, li;
  502. char *id;
  503. id = mmiohs[index].id;
  504. overlay.v = uv_read_local_mmr(mmiohs[index].overlay);
  505. pr_info("UV: %s overlay 0x%lx base:0x%x m_io:%d\n",
  506. id, overlay.v, overlay.s3.base, overlay.s3.m_io);
  507. if (!overlay.s3.enable) {
  508. pr_info("UV: %s disabled\n", id);
  509. return;
  510. }
  511. shift = UV3H_RH_GAM_MMIOH_OVERLAY_CONFIG0_MMR_BASE_SHFT;
  512. base = (unsigned long)overlay.s3.base;
  513. m_io = overlay.s3.m_io;
  514. mmr = mmiohs[index].redirect;
  515. n = UV3H_RH_GAM_MMIOH_REDIRECT_CONFIG0_MMR_DEPTH;
  516. min_pnode *= 2; /* convert to NASID */
  517. max_pnode *= 2;
  518. max_io = lnasid = fi = li = -1;
  519. for (i = 0; i < n; i++) {
  520. union uv3h_rh_gam_mmioh_redirect_config0_mmr_u redirect;
  521. redirect.v = uv_read_local_mmr(mmr + i * 8);
  522. nasid = redirect.s3.nasid;
  523. if (nasid < min_pnode || max_pnode < nasid)
  524. nasid = -1; /* invalid NASID */
  525. if (nasid == lnasid) {
  526. li = i;
  527. if (i != n-1) /* last entry check */
  528. continue;
  529. }
  530. /* check if we have a cached (or last) redirect to print */
  531. if (lnasid != -1 || (i == n-1 && nasid != -1)) {
  532. unsigned long addr1, addr2;
  533. int f, l;
  534. if (lnasid == -1) {
  535. f = l = i;
  536. lnasid = nasid;
  537. } else {
  538. f = fi;
  539. l = li;
  540. }
  541. addr1 = (base << shift) +
  542. f * (unsigned long)(1 << m_io);
  543. addr2 = (base << shift) +
  544. (l + 1) * (unsigned long)(1 << m_io);
  545. pr_info("UV: %s[%03d..%03d] NASID 0x%04x ADDR 0x%016lx - 0x%016lx\n",
  546. id, fi, li, lnasid, addr1, addr2);
  547. if (max_io < l)
  548. max_io = l;
  549. }
  550. fi = li = i;
  551. lnasid = nasid;
  552. }
  553. pr_info("UV: %s base:0x%lx shift:%d M_IO:%d MAX_IO:%d\n",
  554. id, base, shift, m_io, max_io);
  555. if (max_io >= 0)
  556. map_high(id, base, shift, m_io, max_io, map_uc);
  557. }
  558. static __init void map_mmioh_high(int min_pnode, int max_pnode)
  559. {
  560. union uvh_rh_gam_mmioh_overlay_config_mmr_u mmioh;
  561. unsigned long mmr, base;
  562. int shift, enable, m_io, n_io;
  563. if (is_uv3_hub()) {
  564. /* Map both MMIOH Regions */
  565. map_mmioh_high_uv3(0, min_pnode, max_pnode);
  566. map_mmioh_high_uv3(1, min_pnode, max_pnode);
  567. return;
  568. }
  569. if (is_uv1_hub()) {
  570. mmr = UV1H_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR;
  571. shift = UV1H_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR_BASE_SHFT;
  572. mmioh.v = uv_read_local_mmr(mmr);
  573. enable = !!mmioh.s1.enable;
  574. base = mmioh.s1.base;
  575. m_io = mmioh.s1.m_io;
  576. n_io = mmioh.s1.n_io;
  577. } else if (is_uv2_hub()) {
  578. mmr = UV2H_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR;
  579. shift = UV2H_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR_BASE_SHFT;
  580. mmioh.v = uv_read_local_mmr(mmr);
  581. enable = !!mmioh.s2.enable;
  582. base = mmioh.s2.base;
  583. m_io = mmioh.s2.m_io;
  584. n_io = mmioh.s2.n_io;
  585. } else
  586. return;
  587. if (enable) {
  588. max_pnode &= (1 << n_io) - 1;
  589. pr_info(
  590. "UV: base:0x%lx shift:%d N_IO:%d M_IO:%d max_pnode:0x%x\n",
  591. base, shift, m_io, n_io, max_pnode);
  592. map_high("MMIOH", base, shift, m_io, max_pnode, map_uc);
  593. } else {
  594. pr_info("UV: MMIOH disabled\n");
  595. }
  596. }
  597. static __init void map_low_mmrs(void)
  598. {
  599. init_extra_mapping_uc(UV_GLOBAL_MMR32_BASE, UV_GLOBAL_MMR32_SIZE);
  600. init_extra_mapping_uc(UV_LOCAL_MMR_BASE, UV_LOCAL_MMR_SIZE);
  601. }
  602. static __init void uv_rtc_init(void)
  603. {
  604. long status;
  605. u64 ticks_per_sec;
  606. status = uv_bios_freq_base(BIOS_FREQ_BASE_REALTIME_CLOCK,
  607. &ticks_per_sec);
  608. if (status != BIOS_STATUS_SUCCESS || ticks_per_sec < 100000) {
  609. printk(KERN_WARNING
  610. "unable to determine platform RTC clock frequency, "
  611. "guessing.\n");
  612. /* BIOS gives wrong value for clock freq. so guess */
  613. sn_rtc_cycles_per_second = 1000000000000UL / 30000UL;
  614. } else
  615. sn_rtc_cycles_per_second = ticks_per_sec;
  616. }
  617. /*
  618. * percpu heartbeat timer
  619. */
  620. static void uv_heartbeat(unsigned long ignored)
  621. {
  622. struct timer_list *timer = &uv_hub_info->scir.timer;
  623. unsigned char bits = uv_hub_info->scir.state;
  624. /* flip heartbeat bit */
  625. bits ^= SCIR_CPU_HEARTBEAT;
  626. /* is this cpu idle? */
  627. if (idle_cpu(raw_smp_processor_id()))
  628. bits &= ~SCIR_CPU_ACTIVITY;
  629. else
  630. bits |= SCIR_CPU_ACTIVITY;
  631. /* update system controller interface reg */
  632. uv_set_scir_bits(bits);
  633. /* enable next timer period */
  634. mod_timer_pinned(timer, jiffies + SCIR_CPU_HB_INTERVAL);
  635. }
  636. static void uv_heartbeat_enable(int cpu)
  637. {
  638. while (!uv_cpu_hub_info(cpu)->scir.enabled) {
  639. struct timer_list *timer = &uv_cpu_hub_info(cpu)->scir.timer;
  640. uv_set_cpu_scir_bits(cpu, SCIR_CPU_HEARTBEAT|SCIR_CPU_ACTIVITY);
  641. setup_timer(timer, uv_heartbeat, cpu);
  642. timer->expires = jiffies + SCIR_CPU_HB_INTERVAL;
  643. add_timer_on(timer, cpu);
  644. uv_cpu_hub_info(cpu)->scir.enabled = 1;
  645. /* also ensure that boot cpu is enabled */
  646. cpu = 0;
  647. }
  648. }
  649. #ifdef CONFIG_HOTPLUG_CPU
  650. static void uv_heartbeat_disable(int cpu)
  651. {
  652. if (uv_cpu_hub_info(cpu)->scir.enabled) {
  653. uv_cpu_hub_info(cpu)->scir.enabled = 0;
  654. del_timer(&uv_cpu_hub_info(cpu)->scir.timer);
  655. }
  656. uv_set_cpu_scir_bits(cpu, 0xff);
  657. }
  658. /*
  659. * cpu hotplug notifier
  660. */
  661. static int uv_scir_cpu_notify(struct notifier_block *self, unsigned long action,
  662. void *hcpu)
  663. {
  664. long cpu = (long)hcpu;
  665. switch (action) {
  666. case CPU_ONLINE:
  667. uv_heartbeat_enable(cpu);
  668. break;
  669. case CPU_DOWN_PREPARE:
  670. uv_heartbeat_disable(cpu);
  671. break;
  672. default:
  673. break;
  674. }
  675. return NOTIFY_OK;
  676. }
  677. static __init void uv_scir_register_cpu_notifier(void)
  678. {
  679. hotcpu_notifier(uv_scir_cpu_notify, 0);
  680. }
  681. #else /* !CONFIG_HOTPLUG_CPU */
  682. static __init void uv_scir_register_cpu_notifier(void)
  683. {
  684. }
  685. static __init int uv_init_heartbeat(void)
  686. {
  687. int cpu;
  688. if (is_uv_system())
  689. for_each_online_cpu(cpu)
  690. uv_heartbeat_enable(cpu);
  691. return 0;
  692. }
  693. late_initcall(uv_init_heartbeat);
  694. #endif /* !CONFIG_HOTPLUG_CPU */
  695. /* Direct Legacy VGA I/O traffic to designated IOH */
  696. int uv_set_vga_state(struct pci_dev *pdev, bool decode,
  697. unsigned int command_bits, u32 flags)
  698. {
  699. int domain, bus, rc;
  700. PR_DEVEL("devfn %x decode %d cmd %x flags %d\n",
  701. pdev->devfn, decode, command_bits, flags);
  702. if (!(flags & PCI_VGA_STATE_CHANGE_BRIDGE))
  703. return 0;
  704. if ((command_bits & PCI_COMMAND_IO) == 0)
  705. return 0;
  706. domain = pci_domain_nr(pdev->bus);
  707. bus = pdev->bus->number;
  708. rc = uv_bios_set_legacy_vga_target(decode, domain, bus);
  709. PR_DEVEL("vga decode %d %x:%x, rc: %d\n", decode, domain, bus, rc);
  710. return rc;
  711. }
  712. /*
  713. * Called on each cpu to initialize the per_cpu UV data area.
  714. * FIXME: hotplug not supported yet
  715. */
  716. void uv_cpu_init(void)
  717. {
  718. /* CPU 0 initilization will be done via uv_system_init. */
  719. if (!uv_blade_info)
  720. return;
  721. uv_blade_info[uv_numa_blade_id()].nr_online_cpus++;
  722. if (get_uv_system_type() == UV_NON_UNIQUE_APIC)
  723. set_x2apic_extra_bits(uv_hub_info->pnode);
  724. }
  725. void __init uv_system_init(void)
  726. {
  727. union uvh_rh_gam_config_mmr_u m_n_config;
  728. union uvh_node_id_u node_id;
  729. unsigned long gnode_upper, lowmem_redir_base, lowmem_redir_size;
  730. int bytes, nid, cpu, lcpu, pnode, blade, i, j, m_val, n_val;
  731. int gnode_extra, min_pnode = 999999, max_pnode = -1;
  732. unsigned long mmr_base, present, paddr;
  733. unsigned short pnode_mask;
  734. unsigned char n_lshift;
  735. char *hub = (is_uv1_hub() ? "UV100/1000" :
  736. (is_uv2_hub() ? "UV2000/3000" :
  737. (is_uv3_hub() ? "UV300" : NULL)));
  738. if (!hub) {
  739. pr_err("UV: Unknown/unsupported UV hub\n");
  740. return;
  741. }
  742. pr_info("UV: Found %s hub\n", hub);
  743. /* We now only need to map the MMRs on UV1 */
  744. if (is_uv1_hub())
  745. map_low_mmrs();
  746. m_n_config.v = uv_read_local_mmr(UVH_RH_GAM_CONFIG_MMR );
  747. m_val = m_n_config.s.m_skt;
  748. n_val = m_n_config.s.n_skt;
  749. pnode_mask = (1 << n_val) - 1;
  750. n_lshift = get_n_lshift(m_val);
  751. mmr_base =
  752. uv_read_local_mmr(UVH_RH_GAM_MMR_OVERLAY_CONFIG_MMR) &
  753. ~UV_MMR_ENABLE;
  754. node_id.v = uv_read_local_mmr(UVH_NODE_ID);
  755. gnode_extra = (node_id.s.node_id & ~((1 << n_val) - 1)) >> 1;
  756. gnode_upper = ((unsigned long)gnode_extra << m_val);
  757. pr_info("UV: N:%d M:%d pnode_mask:0x%x gnode_upper/extra:0x%lx/0x%x n_lshift 0x%x\n",
  758. n_val, m_val, pnode_mask, gnode_upper, gnode_extra,
  759. n_lshift);
  760. pr_info("UV: global MMR base 0x%lx\n", mmr_base);
  761. for(i = 0; i < UVH_NODE_PRESENT_TABLE_DEPTH; i++)
  762. uv_possible_blades +=
  763. hweight64(uv_read_local_mmr( UVH_NODE_PRESENT_TABLE + i * 8));
  764. /* uv_num_possible_blades() is really the hub count */
  765. pr_info("UV: Found %d blades, %d hubs\n",
  766. is_uv1_hub() ? uv_num_possible_blades() :
  767. (uv_num_possible_blades() + 1) / 2,
  768. uv_num_possible_blades());
  769. bytes = sizeof(struct uv_blade_info) * uv_num_possible_blades();
  770. uv_blade_info = kzalloc(bytes, GFP_KERNEL);
  771. BUG_ON(!uv_blade_info);
  772. for (blade = 0; blade < uv_num_possible_blades(); blade++)
  773. uv_blade_info[blade].memory_nid = -1;
  774. get_lowmem_redirect(&lowmem_redir_base, &lowmem_redir_size);
  775. bytes = sizeof(uv_node_to_blade[0]) * num_possible_nodes();
  776. uv_node_to_blade = kmalloc(bytes, GFP_KERNEL);
  777. BUG_ON(!uv_node_to_blade);
  778. memset(uv_node_to_blade, 255, bytes);
  779. bytes = sizeof(uv_cpu_to_blade[0]) * num_possible_cpus();
  780. uv_cpu_to_blade = kmalloc(bytes, GFP_KERNEL);
  781. BUG_ON(!uv_cpu_to_blade);
  782. memset(uv_cpu_to_blade, 255, bytes);
  783. blade = 0;
  784. for (i = 0; i < UVH_NODE_PRESENT_TABLE_DEPTH; i++) {
  785. present = uv_read_local_mmr(UVH_NODE_PRESENT_TABLE + i * 8);
  786. for (j = 0; j < 64; j++) {
  787. if (!test_bit(j, &present))
  788. continue;
  789. pnode = (i * 64 + j) & pnode_mask;
  790. uv_blade_info[blade].pnode = pnode;
  791. uv_blade_info[blade].nr_possible_cpus = 0;
  792. uv_blade_info[blade].nr_online_cpus = 0;
  793. spin_lock_init(&uv_blade_info[blade].nmi_lock);
  794. min_pnode = min(pnode, min_pnode);
  795. max_pnode = max(pnode, max_pnode);
  796. blade++;
  797. }
  798. }
  799. uv_bios_init();
  800. uv_bios_get_sn_info(0, &uv_type, &sn_partition_id, &sn_coherency_id,
  801. &sn_region_size, &system_serial_number);
  802. uv_rtc_init();
  803. for_each_present_cpu(cpu) {
  804. int apicid = per_cpu(x86_cpu_to_apicid, cpu);
  805. nid = cpu_to_node(cpu);
  806. /*
  807. * apic_pnode_shift must be set before calling uv_apicid_to_pnode();
  808. */
  809. uv_cpu_hub_info(cpu)->pnode_mask = pnode_mask;
  810. uv_cpu_hub_info(cpu)->apic_pnode_shift = uvh_apicid.s.pnode_shift;
  811. uv_cpu_hub_info(cpu)->hub_revision = uv_hub_info->hub_revision;
  812. uv_cpu_hub_info(cpu)->m_shift = 64 - m_val;
  813. uv_cpu_hub_info(cpu)->n_lshift = n_lshift;
  814. pnode = uv_apicid_to_pnode(apicid);
  815. blade = boot_pnode_to_blade(pnode);
  816. lcpu = uv_blade_info[blade].nr_possible_cpus;
  817. uv_blade_info[blade].nr_possible_cpus++;
  818. /* Any node on the blade, else will contain -1. */
  819. uv_blade_info[blade].memory_nid = nid;
  820. uv_cpu_hub_info(cpu)->lowmem_remap_base = lowmem_redir_base;
  821. uv_cpu_hub_info(cpu)->lowmem_remap_top = lowmem_redir_size;
  822. uv_cpu_hub_info(cpu)->m_val = m_val;
  823. uv_cpu_hub_info(cpu)->n_val = n_val;
  824. uv_cpu_hub_info(cpu)->numa_blade_id = blade;
  825. uv_cpu_hub_info(cpu)->blade_processor_id = lcpu;
  826. uv_cpu_hub_info(cpu)->pnode = pnode;
  827. uv_cpu_hub_info(cpu)->gpa_mask = (1UL << (m_val + n_val)) - 1;
  828. uv_cpu_hub_info(cpu)->gnode_upper = gnode_upper;
  829. uv_cpu_hub_info(cpu)->gnode_extra = gnode_extra;
  830. uv_cpu_hub_info(cpu)->global_mmr_base = mmr_base;
  831. uv_cpu_hub_info(cpu)->coherency_domain_number = sn_coherency_id;
  832. uv_cpu_hub_info(cpu)->scir.offset = uv_scir_offset(apicid);
  833. uv_node_to_blade[nid] = blade;
  834. uv_cpu_to_blade[cpu] = blade;
  835. }
  836. /* Add blade/pnode info for nodes without cpus */
  837. for_each_online_node(nid) {
  838. if (uv_node_to_blade[nid] >= 0)
  839. continue;
  840. paddr = node_start_pfn(nid) << PAGE_SHIFT;
  841. pnode = uv_gpa_to_pnode(uv_soc_phys_ram_to_gpa(paddr));
  842. blade = boot_pnode_to_blade(pnode);
  843. uv_node_to_blade[nid] = blade;
  844. }
  845. map_gru_high(max_pnode);
  846. map_mmr_high(max_pnode);
  847. map_mmioh_high(min_pnode, max_pnode);
  848. uv_nmi_setup();
  849. uv_cpu_init();
  850. uv_scir_register_cpu_notifier();
  851. proc_mkdir("sgi_uv", NULL);
  852. /* register Legacy VGA I/O redirection handler */
  853. pci_register_set_vga_state(uv_set_vga_state);
  854. /*
  855. * For a kdump kernel the reset must be BOOT_ACPI, not BOOT_EFI, as
  856. * EFI is not enabled in the kdump kernel.
  857. */
  858. if (is_kdump_kernel())
  859. reboot_type = BOOT_ACPI;
  860. }
  861. apic_driver(apic_x2apic_uv_x);