numaq_32.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  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/memblock.h>
  30. #include <linux/threads.h>
  31. #include <linux/cpumask.h>
  32. #include <linux/kernel.h>
  33. #include <linux/mmzone.h>
  34. #include <linux/module.h>
  35. #include <linux/string.h>
  36. #include <linux/init.h>
  37. #include <linux/numa.h>
  38. #include <linux/smp.h>
  39. #include <linux/io.h>
  40. #include <linux/mm.h>
  41. #include <asm/processor.h>
  42. #include <asm/fixmap.h>
  43. #include <asm/mpspec.h>
  44. #include <asm/numaq.h>
  45. #include <asm/setup.h>
  46. #include <asm/apic.h>
  47. #include <asm/e820.h>
  48. #include <asm/ipi.h>
  49. #define MB_TO_PAGES(addr) ((addr) << (20 - PAGE_SHIFT))
  50. int found_numaq;
  51. /*
  52. * Have to match translation table entries to main table entries by counter
  53. * hence the mpc_record variable .... can't see a less disgusting way of
  54. * doing this ....
  55. */
  56. struct mpc_trans {
  57. unsigned char mpc_type;
  58. unsigned char trans_len;
  59. unsigned char trans_type;
  60. unsigned char trans_quad;
  61. unsigned char trans_global;
  62. unsigned char trans_local;
  63. unsigned short trans_reserved;
  64. };
  65. static int mpc_record;
  66. static struct mpc_trans *translation_table[MAX_MPC_ENTRY];
  67. int mp_bus_id_to_node[MAX_MP_BUSSES];
  68. int mp_bus_id_to_local[MAX_MP_BUSSES];
  69. int quad_local_to_mp_bus_id[NR_CPUS/4][4];
  70. static inline void numaq_register_node(int node, struct sys_cfg_data *scd)
  71. {
  72. struct eachquadmem *eq = scd->eq + node;
  73. node_set_online(node);
  74. /* Convert to pages */
  75. node_start_pfn[node] =
  76. MB_TO_PAGES(eq->hi_shrd_mem_start - eq->priv_mem_size);
  77. node_end_pfn[node] =
  78. MB_TO_PAGES(eq->hi_shrd_mem_start + eq->hi_shrd_mem_size);
  79. memblock_x86_register_active_regions(node, node_start_pfn[node],
  80. node_end_pfn[node]);
  81. memory_present(node, node_start_pfn[node], node_end_pfn[node]);
  82. node_remap_size[node] = node_memmap_size_bytes(node,
  83. node_start_pfn[node],
  84. node_end_pfn[node]);
  85. }
  86. /*
  87. * Function: smp_dump_qct()
  88. *
  89. * Description: gets memory layout from the quad config table. This
  90. * function also updates node_online_map with the nodes (quads) present.
  91. */
  92. static void __init smp_dump_qct(void)
  93. {
  94. struct sys_cfg_data *scd;
  95. int node;
  96. scd = (void *)__va(SYS_CFG_DATA_PRIV_ADDR);
  97. nodes_clear(node_online_map);
  98. for_each_node(node) {
  99. if (scd->quads_present31_0 & (1 << node))
  100. numaq_register_node(node, scd);
  101. }
  102. }
  103. void __cpuinit numaq_tsc_disable(void)
  104. {
  105. if (!found_numaq)
  106. return;
  107. if (num_online_nodes() > 1) {
  108. printk(KERN_DEBUG "NUMAQ: disabling TSC\n");
  109. setup_clear_cpu_cap(X86_FEATURE_TSC);
  110. }
  111. }
  112. static void __init numaq_tsc_init(void)
  113. {
  114. numaq_tsc_disable();
  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 __init void early_check_numaq(void)
  222. {
  223. /*
  224. * get boot-time SMP configuration:
  225. */
  226. if (smp_found_config)
  227. early_get_smp_config();
  228. if (found_numaq) {
  229. x86_init.mpparse.mpc_record = numaq_mpc_record;
  230. x86_init.mpparse.setup_ioapic_ids = x86_init_noop;
  231. x86_init.mpparse.mpc_apic_id = mpc_apic_id;
  232. x86_init.mpparse.smp_read_mpc_oem = smp_read_mpc_oem;
  233. x86_init.mpparse.mpc_oem_pci_bus = mpc_oem_pci_bus;
  234. x86_init.mpparse.mpc_oem_bus_info = mpc_oem_bus_info;
  235. x86_init.timers.tsc_pre_init = numaq_tsc_init;
  236. x86_init.pci.init = pci_numaq_init;
  237. }
  238. }
  239. int __init get_memcfg_numaq(void)
  240. {
  241. early_check_numaq();
  242. if (!found_numaq)
  243. return 0;
  244. smp_dump_qct();
  245. return 1;
  246. }
  247. #define NUMAQ_APIC_DFR_VALUE (APIC_DFR_CLUSTER)
  248. static inline unsigned int numaq_get_apic_id(unsigned long x)
  249. {
  250. return (x >> 24) & 0x0F;
  251. }
  252. static inline void numaq_send_IPI_mask(const struct cpumask *mask, int vector)
  253. {
  254. default_send_IPI_mask_sequence_logical(mask, vector);
  255. }
  256. static inline void numaq_send_IPI_allbutself(int vector)
  257. {
  258. default_send_IPI_mask_allbutself_logical(cpu_online_mask, vector);
  259. }
  260. static inline void numaq_send_IPI_all(int vector)
  261. {
  262. numaq_send_IPI_mask(cpu_online_mask, vector);
  263. }
  264. #define NUMAQ_TRAMPOLINE_PHYS_LOW (0x8)
  265. #define NUMAQ_TRAMPOLINE_PHYS_HIGH (0xa)
  266. /*
  267. * Because we use NMIs rather than the INIT-STARTUP sequence to
  268. * bootstrap the CPUs, the APIC may be in a weird state. Kick it:
  269. */
  270. static inline void numaq_smp_callin_clear_local_apic(void)
  271. {
  272. clear_local_APIC();
  273. }
  274. static inline const struct cpumask *numaq_target_cpus(void)
  275. {
  276. return cpu_all_mask;
  277. }
  278. static unsigned long numaq_check_apicid_used(physid_mask_t *map, int apicid)
  279. {
  280. return physid_isset(apicid, *map);
  281. }
  282. static inline unsigned long numaq_check_apicid_present(int bit)
  283. {
  284. return physid_isset(bit, phys_cpu_present_map);
  285. }
  286. static inline int numaq_apic_id_registered(void)
  287. {
  288. return 1;
  289. }
  290. static inline void numaq_init_apic_ldr(void)
  291. {
  292. /* Already done in NUMA-Q firmware */
  293. }
  294. static inline void numaq_setup_apic_routing(void)
  295. {
  296. printk(KERN_INFO
  297. "Enabling APIC mode: NUMA-Q. Using %d I/O APICs\n",
  298. nr_ioapics);
  299. }
  300. /*
  301. * Skip adding the timer int on secondary nodes, which causes
  302. * a small but painful rift in the time-space continuum.
  303. */
  304. static inline int numaq_multi_timer_check(int apic, int irq)
  305. {
  306. return apic != 0 && irq == 0;
  307. }
  308. static inline void numaq_ioapic_phys_id_map(physid_mask_t *phys_map, physid_mask_t *retmap)
  309. {
  310. /* We don't have a good way to do this yet - hack */
  311. return physids_promote(0xFUL, retmap);
  312. }
  313. /*
  314. * Supporting over 60 cpus on NUMA-Q requires a locality-dependent
  315. * cpu to APIC ID relation to properly interact with the intelligent
  316. * mode of the cluster controller.
  317. */
  318. static inline int numaq_cpu_present_to_apicid(int mps_cpu)
  319. {
  320. if (mps_cpu < 60)
  321. return ((mps_cpu >> 2) << 4) | (1 << (mps_cpu & 0x3));
  322. else
  323. return BAD_APICID;
  324. }
  325. static inline int numaq_apicid_to_node(int logical_apicid)
  326. {
  327. return logical_apicid >> 4;
  328. }
  329. static int numaq_numa_cpu_node(int cpu)
  330. {
  331. int logical_apicid = early_per_cpu(x86_cpu_to_logical_apicid, cpu);
  332. if (logical_apicid != BAD_APICID)
  333. return numaq_apicid_to_node(logical_apicid);
  334. return NUMA_NO_NODE;
  335. }
  336. static void numaq_apicid_to_cpu_present(int logical_apicid, physid_mask_t *retmap)
  337. {
  338. int node = numaq_apicid_to_node(logical_apicid);
  339. int cpu = __ffs(logical_apicid & 0xf);
  340. physid_set_mask_of_physid(cpu + 4*node, retmap);
  341. }
  342. /* Where the IO area was mapped on multiquad, always 0 otherwise */
  343. void *xquad_portio;
  344. static inline int numaq_check_phys_apicid_present(int phys_apicid)
  345. {
  346. return 1;
  347. }
  348. /*
  349. * We use physical apicids here, not logical, so just return the default
  350. * physical broadcast to stop people from breaking us
  351. */
  352. static unsigned int numaq_cpu_mask_to_apicid(const struct cpumask *cpumask)
  353. {
  354. return 0x0F;
  355. }
  356. static inline unsigned int
  357. numaq_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
  358. const struct cpumask *andmask)
  359. {
  360. return 0x0F;
  361. }
  362. /* No NUMA-Q box has a HT CPU, but it can't hurt to use the default code. */
  363. static inline int numaq_phys_pkg_id(int cpuid_apic, int index_msb)
  364. {
  365. return cpuid_apic >> index_msb;
  366. }
  367. static int
  368. numaq_mps_oem_check(struct mpc_table *mpc, char *oem, char *productid)
  369. {
  370. if (strncmp(oem, "IBM NUMA", 8))
  371. printk(KERN_ERR "Warning! Not a NUMA-Q system!\n");
  372. else
  373. found_numaq = 1;
  374. return found_numaq;
  375. }
  376. static int probe_numaq(void)
  377. {
  378. /* already know from get_memcfg_numaq() */
  379. return found_numaq;
  380. }
  381. static void numaq_vector_allocation_domain(int cpu, struct cpumask *retmask)
  382. {
  383. /* Careful. Some cpus do not strictly honor the set of cpus
  384. * specified in the interrupt destination when using lowest
  385. * priority interrupt delivery mode.
  386. *
  387. * In particular there was a hyperthreading cpu observed to
  388. * deliver interrupts to the wrong hyperthread when only one
  389. * hyperthread was specified in the interrupt desitination.
  390. */
  391. cpumask_clear(retmask);
  392. cpumask_bits(retmask)[0] = APIC_ALL_CPUS;
  393. }
  394. static void numaq_setup_portio_remap(void)
  395. {
  396. int num_quads = num_online_nodes();
  397. if (num_quads <= 1)
  398. return;
  399. printk(KERN_INFO
  400. "Remapping cross-quad port I/O for %d quads\n", num_quads);
  401. xquad_portio = ioremap(XQUAD_PORTIO_BASE, num_quads*XQUAD_PORTIO_QUAD);
  402. printk(KERN_INFO
  403. "xquad_portio vaddr 0x%08lx, len %08lx\n",
  404. (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
  405. }
  406. /* Use __refdata to keep false positive warning calm. */
  407. struct apic __refdata apic_numaq = {
  408. .name = "NUMAQ",
  409. .probe = probe_numaq,
  410. .acpi_madt_oem_check = NULL,
  411. .apic_id_registered = numaq_apic_id_registered,
  412. .irq_delivery_mode = dest_LowestPrio,
  413. /* physical delivery on LOCAL quad: */
  414. .irq_dest_mode = 0,
  415. .target_cpus = numaq_target_cpus,
  416. .disable_esr = 1,
  417. .dest_logical = APIC_DEST_LOGICAL,
  418. .check_apicid_used = numaq_check_apicid_used,
  419. .check_apicid_present = numaq_check_apicid_present,
  420. .vector_allocation_domain = numaq_vector_allocation_domain,
  421. .init_apic_ldr = numaq_init_apic_ldr,
  422. .ioapic_phys_id_map = numaq_ioapic_phys_id_map,
  423. .setup_apic_routing = numaq_setup_apic_routing,
  424. .multi_timer_check = numaq_multi_timer_check,
  425. .cpu_present_to_apicid = numaq_cpu_present_to_apicid,
  426. .apicid_to_cpu_present = numaq_apicid_to_cpu_present,
  427. .setup_portio_remap = numaq_setup_portio_remap,
  428. .check_phys_apicid_present = numaq_check_phys_apicid_present,
  429. .enable_apic_mode = NULL,
  430. .phys_pkg_id = numaq_phys_pkg_id,
  431. .mps_oem_check = numaq_mps_oem_check,
  432. .get_apic_id = numaq_get_apic_id,
  433. .set_apic_id = NULL,
  434. .apic_id_mask = 0x0F << 24,
  435. .cpu_mask_to_apicid = numaq_cpu_mask_to_apicid,
  436. .cpu_mask_to_apicid_and = numaq_cpu_mask_to_apicid_and,
  437. .send_IPI_mask = numaq_send_IPI_mask,
  438. .send_IPI_mask_allbutself = NULL,
  439. .send_IPI_allbutself = numaq_send_IPI_allbutself,
  440. .send_IPI_all = numaq_send_IPI_all,
  441. .send_IPI_self = default_send_IPI_self,
  442. .wakeup_secondary_cpu = wakeup_secondary_cpu_via_nmi,
  443. .trampoline_phys_low = NUMAQ_TRAMPOLINE_PHYS_LOW,
  444. .trampoline_phys_high = NUMAQ_TRAMPOLINE_PHYS_HIGH,
  445. /* We don't do anything here because we use NMI's to boot instead */
  446. .wait_for_init_deassert = NULL,
  447. .smp_callin_clear_local_apic = numaq_smp_callin_clear_local_apic,
  448. .inquire_remote_apic = NULL,
  449. .read = native_apic_mem_read,
  450. .write = native_apic_mem_write,
  451. .icr_read = native_apic_icr_read,
  452. .icr_write = native_apic_icr_write,
  453. .wait_icr_idle = native_apic_wait_icr_idle,
  454. .safe_wait_icr_idle = native_safe_apic_wait_icr_idle,
  455. .x86_32_early_logical_apicid = noop_x86_32_early_logical_apicid,
  456. .x86_32_numa_cpu_node = numaq_numa_cpu_node,
  457. };