numaq_32.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. /*
  2. * Written by: Patricia Gaughen, IBM Corporation
  3. *
  4. * Copyright (C) 2002, IBM Corp.
  5. * Copyright (C) 2009, Red Hat, Inc., Ingo Molnar
  6. *
  7. * All rights reserved.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  17. * NON INFRINGEMENT. See the GNU General Public License for more
  18. * details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. *
  24. * Send feedback to <gone@us.ibm.com>
  25. */
  26. #include <linux/nodemask.h>
  27. #include <linux/topology.h>
  28. #include <linux/bootmem.h>
  29. #include <linux/threads.h>
  30. #include <linux/cpumask.h>
  31. #include <linux/kernel.h>
  32. #include <linux/mmzone.h>
  33. #include <linux/module.h>
  34. #include <linux/string.h>
  35. #include <linux/init.h>
  36. #include <linux/numa.h>
  37. #include <linux/smp.h>
  38. #include <linux/io.h>
  39. #include <linux/mm.h>
  40. #include <asm/processor.h>
  41. #include <asm/fixmap.h>
  42. #include <asm/mpspec.h>
  43. #include <asm/numaq.h>
  44. #include <asm/setup.h>
  45. #include <asm/apic.h>
  46. #include <asm/e820.h>
  47. #include <asm/ipi.h>
  48. #define MB_TO_PAGES(addr) ((addr) << (20 - PAGE_SHIFT))
  49. int found_numaq;
  50. /*
  51. * Have to match translation table entries to main table entries by counter
  52. * hence the mpc_record variable .... can't see a less disgusting way of
  53. * doing this ....
  54. */
  55. struct mpc_trans {
  56. unsigned char mpc_type;
  57. unsigned char trans_len;
  58. unsigned char trans_type;
  59. unsigned char trans_quad;
  60. unsigned char trans_global;
  61. unsigned char trans_local;
  62. unsigned short trans_reserved;
  63. };
  64. static int mpc_record;
  65. static struct mpc_trans *translation_table[MAX_MPC_ENTRY];
  66. int mp_bus_id_to_node[MAX_MP_BUSSES];
  67. int mp_bus_id_to_local[MAX_MP_BUSSES];
  68. int quad_local_to_mp_bus_id[NR_CPUS/4][4];
  69. static inline void numaq_register_node(int node, struct sys_cfg_data *scd)
  70. {
  71. struct eachquadmem *eq = scd->eq + node;
  72. node_set_online(node);
  73. /* Convert to pages */
  74. node_start_pfn[node] =
  75. MB_TO_PAGES(eq->hi_shrd_mem_start - eq->priv_mem_size);
  76. node_end_pfn[node] =
  77. MB_TO_PAGES(eq->hi_shrd_mem_start + eq->hi_shrd_mem_size);
  78. e820_register_active_regions(node, node_start_pfn[node],
  79. node_end_pfn[node]);
  80. memory_present(node, node_start_pfn[node], node_end_pfn[node]);
  81. node_remap_size[node] = node_memmap_size_bytes(node,
  82. node_start_pfn[node],
  83. node_end_pfn[node]);
  84. }
  85. /*
  86. * Function: smp_dump_qct()
  87. *
  88. * Description: gets memory layout from the quad config table. This
  89. * function also updates node_online_map with the nodes (quads) present.
  90. */
  91. static void __init smp_dump_qct(void)
  92. {
  93. struct sys_cfg_data *scd;
  94. int node;
  95. scd = (void *)__va(SYS_CFG_DATA_PRIV_ADDR);
  96. nodes_clear(node_online_map);
  97. for_each_node(node) {
  98. if (scd->quads_present31_0 & (1 << node))
  99. numaq_register_node(node, scd);
  100. }
  101. }
  102. void __cpuinit numaq_tsc_disable(void)
  103. {
  104. if (!found_numaq)
  105. return;
  106. if (num_online_nodes() > 1) {
  107. printk(KERN_DEBUG "NUMAQ: disabling TSC\n");
  108. setup_clear_cpu_cap(X86_FEATURE_TSC);
  109. }
  110. }
  111. static int __init numaq_pre_time_init(void)
  112. {
  113. numaq_tsc_disable();
  114. return 0;
  115. }
  116. static inline int generate_logical_apicid(int quad, int phys_apicid)
  117. {
  118. return (quad << 4) + (phys_apicid ? phys_apicid << 1 : 1);
  119. }
  120. /* x86_quirks member */
  121. static int mpc_apic_id(struct mpc_cpu *m)
  122. {
  123. int quad = translation_table[mpc_record]->trans_quad;
  124. int logical_apicid = generate_logical_apicid(quad, m->apicid);
  125. printk(KERN_DEBUG
  126. "Processor #%d %u:%u APIC version %d (quad %d, apic %d)\n",
  127. m->apicid, (m->cpufeature & CPU_FAMILY_MASK) >> 8,
  128. (m->cpufeature & CPU_MODEL_MASK) >> 4,
  129. m->apicver, quad, logical_apicid);
  130. return logical_apicid;
  131. }
  132. /* x86_quirks member */
  133. static void mpc_oem_bus_info(struct mpc_bus *m, char *name)
  134. {
  135. int quad = translation_table[mpc_record]->trans_quad;
  136. int local = translation_table[mpc_record]->trans_local;
  137. mp_bus_id_to_node[m->busid] = quad;
  138. mp_bus_id_to_local[m->busid] = local;
  139. printk(KERN_INFO "Bus #%d is %s (node %d)\n", m->busid, name, quad);
  140. }
  141. /* x86_quirks member */
  142. static void mpc_oem_pci_bus(struct mpc_bus *m)
  143. {
  144. int quad = translation_table[mpc_record]->trans_quad;
  145. int local = translation_table[mpc_record]->trans_local;
  146. quad_local_to_mp_bus_id[quad][local] = m->busid;
  147. }
  148. /*
  149. * Called from mpparse code.
  150. * mode = 0: prescan
  151. * mode = 1: one mpc entry scanned
  152. */
  153. static void numaq_mpc_record(unsigned int mode)
  154. {
  155. if (!mode)
  156. mpc_record = 0;
  157. else
  158. mpc_record++;
  159. }
  160. static void __init MP_translation_info(struct mpc_trans *m)
  161. {
  162. printk(KERN_INFO
  163. "Translation: record %d, type %d, quad %d, global %d, local %d\n",
  164. mpc_record, m->trans_type, m->trans_quad, m->trans_global,
  165. m->trans_local);
  166. if (mpc_record >= MAX_MPC_ENTRY)
  167. printk(KERN_ERR "MAX_MPC_ENTRY exceeded!\n");
  168. else
  169. translation_table[mpc_record] = m; /* stash this for later */
  170. if (m->trans_quad < MAX_NUMNODES && !node_online(m->trans_quad))
  171. node_set_online(m->trans_quad);
  172. }
  173. static int __init mpf_checksum(unsigned char *mp, int len)
  174. {
  175. int sum = 0;
  176. while (len--)
  177. sum += *mp++;
  178. return sum & 0xFF;
  179. }
  180. /*
  181. * Read/parse the MPC oem tables
  182. */
  183. static void __init smp_read_mpc_oem(struct mpc_table *mpc)
  184. {
  185. struct mpc_oemtable *oemtable = (void *)(long)mpc->oemptr;
  186. int count = sizeof(*oemtable); /* the header size */
  187. unsigned char *oemptr = ((unsigned char *)oemtable) + count;
  188. mpc_record = 0;
  189. printk(KERN_INFO
  190. "Found an OEM MPC table at %8p - parsing it ... \n", oemtable);
  191. if (memcmp(oemtable->signature, MPC_OEM_SIGNATURE, 4)) {
  192. printk(KERN_WARNING
  193. "SMP mpc oemtable: bad signature [%c%c%c%c]!\n",
  194. oemtable->signature[0], oemtable->signature[1],
  195. oemtable->signature[2], oemtable->signature[3]);
  196. return;
  197. }
  198. if (mpf_checksum((unsigned char *)oemtable, oemtable->length)) {
  199. printk(KERN_WARNING "SMP oem mptable: checksum error!\n");
  200. return;
  201. }
  202. while (count < oemtable->length) {
  203. switch (*oemptr) {
  204. case MP_TRANSLATION:
  205. {
  206. struct mpc_trans *m = (void *)oemptr;
  207. MP_translation_info(m);
  208. oemptr += sizeof(*m);
  209. count += sizeof(*m);
  210. ++mpc_record;
  211. break;
  212. }
  213. default:
  214. printk(KERN_WARNING
  215. "Unrecognised OEM table entry type! - %d\n",
  216. (int)*oemptr);
  217. return;
  218. }
  219. }
  220. }
  221. static struct x86_quirks numaq_x86_quirks __initdata = {
  222. .arch_pre_time_init = numaq_pre_time_init,
  223. .arch_time_init = NULL,
  224. };
  225. static __init void early_check_numaq(void)
  226. {
  227. /*
  228. * Find possible boot-time SMP configuration:
  229. */
  230. early_find_smp_config();
  231. /*
  232. * get boot-time SMP configuration:
  233. */
  234. if (smp_found_config)
  235. early_get_smp_config();
  236. if (found_numaq) {
  237. x86_quirks = &numaq_x86_quirks;
  238. x86_init.mpparse.mpc_record = numaq_mpc_record;
  239. x86_init.mpparse.setup_ioapic_ids = x86_init_noop;
  240. x86_init.mpparse.mpc_apic_id = mpc_apic_id;
  241. x86_init.mpparse.smp_read_mpc_oem = smp_read_mpc_oem;
  242. x86_init.mpparse.mpc_oem_pci_bus = mpc_oem_pci_bus;
  243. x86_init.mpparse.mpc_oem_bus_info = mpc_oem_bus_info;
  244. }
  245. }
  246. int __init get_memcfg_numaq(void)
  247. {
  248. early_check_numaq();
  249. if (!found_numaq)
  250. return 0;
  251. smp_dump_qct();
  252. return 1;
  253. }
  254. #define NUMAQ_APIC_DFR_VALUE (APIC_DFR_CLUSTER)
  255. static inline unsigned int numaq_get_apic_id(unsigned long x)
  256. {
  257. return (x >> 24) & 0x0F;
  258. }
  259. static inline void numaq_send_IPI_mask(const struct cpumask *mask, int vector)
  260. {
  261. default_send_IPI_mask_sequence_logical(mask, vector);
  262. }
  263. static inline void numaq_send_IPI_allbutself(int vector)
  264. {
  265. default_send_IPI_mask_allbutself_logical(cpu_online_mask, vector);
  266. }
  267. static inline void numaq_send_IPI_all(int vector)
  268. {
  269. numaq_send_IPI_mask(cpu_online_mask, vector);
  270. }
  271. #define NUMAQ_TRAMPOLINE_PHYS_LOW (0x8)
  272. #define NUMAQ_TRAMPOLINE_PHYS_HIGH (0xa)
  273. /*
  274. * Because we use NMIs rather than the INIT-STARTUP sequence to
  275. * bootstrap the CPUs, the APIC may be in a weird state. Kick it:
  276. */
  277. static inline void numaq_smp_callin_clear_local_apic(void)
  278. {
  279. clear_local_APIC();
  280. }
  281. static inline const struct cpumask *numaq_target_cpus(void)
  282. {
  283. return cpu_all_mask;
  284. }
  285. static inline unsigned long
  286. numaq_check_apicid_used(physid_mask_t bitmap, int apicid)
  287. {
  288. return physid_isset(apicid, bitmap);
  289. }
  290. static inline unsigned long numaq_check_apicid_present(int bit)
  291. {
  292. return physid_isset(bit, phys_cpu_present_map);
  293. }
  294. static inline int numaq_apic_id_registered(void)
  295. {
  296. return 1;
  297. }
  298. static inline void numaq_init_apic_ldr(void)
  299. {
  300. /* Already done in NUMA-Q firmware */
  301. }
  302. static inline void numaq_setup_apic_routing(void)
  303. {
  304. printk(KERN_INFO
  305. "Enabling APIC mode: NUMA-Q. Using %d I/O APICs\n",
  306. nr_ioapics);
  307. }
  308. /*
  309. * Skip adding the timer int on secondary nodes, which causes
  310. * a small but painful rift in the time-space continuum.
  311. */
  312. static inline int numaq_multi_timer_check(int apic, int irq)
  313. {
  314. return apic != 0 && irq == 0;
  315. }
  316. static inline physid_mask_t numaq_ioapic_phys_id_map(physid_mask_t phys_map)
  317. {
  318. /* We don't have a good way to do this yet - hack */
  319. return physids_promote(0xFUL);
  320. }
  321. static inline int numaq_cpu_to_logical_apicid(int cpu)
  322. {
  323. if (cpu >= nr_cpu_ids)
  324. return BAD_APICID;
  325. return cpu_2_logical_apicid[cpu];
  326. }
  327. /*
  328. * Supporting over 60 cpus on NUMA-Q requires a locality-dependent
  329. * cpu to APIC ID relation to properly interact with the intelligent
  330. * mode of the cluster controller.
  331. */
  332. static inline int numaq_cpu_present_to_apicid(int mps_cpu)
  333. {
  334. if (mps_cpu < 60)
  335. return ((mps_cpu >> 2) << 4) | (1 << (mps_cpu & 0x3));
  336. else
  337. return BAD_APICID;
  338. }
  339. static inline int numaq_apicid_to_node(int logical_apicid)
  340. {
  341. return logical_apicid >> 4;
  342. }
  343. static inline physid_mask_t numaq_apicid_to_cpu_present(int logical_apicid)
  344. {
  345. int node = numaq_apicid_to_node(logical_apicid);
  346. int cpu = __ffs(logical_apicid & 0xf);
  347. return physid_mask_of_physid(cpu + 4*node);
  348. }
  349. /* Where the IO area was mapped on multiquad, always 0 otherwise */
  350. void *xquad_portio;
  351. static inline int numaq_check_phys_apicid_present(int boot_cpu_physical_apicid)
  352. {
  353. return 1;
  354. }
  355. /*
  356. * We use physical apicids here, not logical, so just return the default
  357. * physical broadcast to stop people from breaking us
  358. */
  359. static unsigned int numaq_cpu_mask_to_apicid(const struct cpumask *cpumask)
  360. {
  361. return 0x0F;
  362. }
  363. static inline unsigned int
  364. numaq_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
  365. const struct cpumask *andmask)
  366. {
  367. return 0x0F;
  368. }
  369. /* No NUMA-Q box has a HT CPU, but it can't hurt to use the default code. */
  370. static inline int numaq_phys_pkg_id(int cpuid_apic, int index_msb)
  371. {
  372. return cpuid_apic >> index_msb;
  373. }
  374. static int
  375. numaq_mps_oem_check(struct mpc_table *mpc, char *oem, char *productid)
  376. {
  377. if (strncmp(oem, "IBM NUMA", 8))
  378. printk(KERN_ERR "Warning! Not a NUMA-Q system!\n");
  379. else
  380. found_numaq = 1;
  381. return found_numaq;
  382. }
  383. static int probe_numaq(void)
  384. {
  385. /* already know from get_memcfg_numaq() */
  386. return found_numaq;
  387. }
  388. static void numaq_vector_allocation_domain(int cpu, struct cpumask *retmask)
  389. {
  390. /* Careful. Some cpus do not strictly honor the set of cpus
  391. * specified in the interrupt destination when using lowest
  392. * priority interrupt delivery mode.
  393. *
  394. * In particular there was a hyperthreading cpu observed to
  395. * deliver interrupts to the wrong hyperthread when only one
  396. * hyperthread was specified in the interrupt desitination.
  397. */
  398. cpumask_clear(retmask);
  399. cpumask_bits(retmask)[0] = APIC_ALL_CPUS;
  400. }
  401. static void numaq_setup_portio_remap(void)
  402. {
  403. int num_quads = num_online_nodes();
  404. if (num_quads <= 1)
  405. return;
  406. printk(KERN_INFO
  407. "Remapping cross-quad port I/O for %d quads\n", num_quads);
  408. xquad_portio = ioremap(XQUAD_PORTIO_BASE, num_quads*XQUAD_PORTIO_QUAD);
  409. printk(KERN_INFO
  410. "xquad_portio vaddr 0x%08lx, len %08lx\n",
  411. (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
  412. }
  413. /* Use __refdata to keep false positive warning calm. */
  414. struct apic __refdata apic_numaq = {
  415. .name = "NUMAQ",
  416. .probe = probe_numaq,
  417. .acpi_madt_oem_check = NULL,
  418. .apic_id_registered = numaq_apic_id_registered,
  419. .irq_delivery_mode = dest_LowestPrio,
  420. /* physical delivery on LOCAL quad: */
  421. .irq_dest_mode = 0,
  422. .target_cpus = numaq_target_cpus,
  423. .disable_esr = 1,
  424. .dest_logical = APIC_DEST_LOGICAL,
  425. .check_apicid_used = numaq_check_apicid_used,
  426. .check_apicid_present = numaq_check_apicid_present,
  427. .vector_allocation_domain = numaq_vector_allocation_domain,
  428. .init_apic_ldr = numaq_init_apic_ldr,
  429. .ioapic_phys_id_map = numaq_ioapic_phys_id_map,
  430. .setup_apic_routing = numaq_setup_apic_routing,
  431. .multi_timer_check = numaq_multi_timer_check,
  432. .apicid_to_node = numaq_apicid_to_node,
  433. .cpu_to_logical_apicid = numaq_cpu_to_logical_apicid,
  434. .cpu_present_to_apicid = numaq_cpu_present_to_apicid,
  435. .apicid_to_cpu_present = numaq_apicid_to_cpu_present,
  436. .setup_portio_remap = numaq_setup_portio_remap,
  437. .check_phys_apicid_present = numaq_check_phys_apicid_present,
  438. .enable_apic_mode = NULL,
  439. .phys_pkg_id = numaq_phys_pkg_id,
  440. .mps_oem_check = numaq_mps_oem_check,
  441. .get_apic_id = numaq_get_apic_id,
  442. .set_apic_id = NULL,
  443. .apic_id_mask = 0x0F << 24,
  444. .cpu_mask_to_apicid = numaq_cpu_mask_to_apicid,
  445. .cpu_mask_to_apicid_and = numaq_cpu_mask_to_apicid_and,
  446. .send_IPI_mask = numaq_send_IPI_mask,
  447. .send_IPI_mask_allbutself = NULL,
  448. .send_IPI_allbutself = numaq_send_IPI_allbutself,
  449. .send_IPI_all = numaq_send_IPI_all,
  450. .send_IPI_self = default_send_IPI_self,
  451. .wakeup_secondary_cpu = wakeup_secondary_cpu_via_nmi,
  452. .trampoline_phys_low = NUMAQ_TRAMPOLINE_PHYS_LOW,
  453. .trampoline_phys_high = NUMAQ_TRAMPOLINE_PHYS_HIGH,
  454. /* We don't do anything here because we use NMI's to boot instead */
  455. .wait_for_init_deassert = NULL,
  456. .smp_callin_clear_local_apic = numaq_smp_callin_clear_local_apic,
  457. .inquire_remote_apic = NULL,
  458. .read = native_apic_mem_read,
  459. .write = native_apic_mem_write,
  460. .icr_read = native_apic_icr_read,
  461. .icr_write = native_apic_icr_write,
  462. .wait_icr_idle = native_apic_wait_icr_idle,
  463. .safe_wait_icr_idle = native_safe_apic_wait_icr_idle,
  464. };