numaq_32.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  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. 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. u64 start = (u64)(eq->hi_shrd_mem_start - eq->priv_mem_size) << 20;
  73. u64 end = (u64)(eq->hi_shrd_mem_start + eq->hi_shrd_mem_size) << 20;
  74. int ret;
  75. node_set(node, numa_nodes_parsed);
  76. ret = numa_add_memblk(node, start, end);
  77. BUG_ON(ret < 0);
  78. }
  79. /*
  80. * Function: smp_dump_qct()
  81. *
  82. * Description: gets memory layout from the quad config table. This
  83. * function also updates numa_nodes_parsed with the nodes (quads) present.
  84. */
  85. static void __init smp_dump_qct(void)
  86. {
  87. struct sys_cfg_data *scd;
  88. int node;
  89. scd = (void *)__va(SYS_CFG_DATA_PRIV_ADDR);
  90. for_each_node(node) {
  91. if (scd->quads_present31_0 & (1 << node))
  92. numaq_register_node(node, scd);
  93. }
  94. }
  95. void __cpuinit numaq_tsc_disable(void)
  96. {
  97. if (!found_numaq)
  98. return;
  99. if (num_online_nodes() > 1) {
  100. printk(KERN_DEBUG "NUMAQ: disabling TSC\n");
  101. setup_clear_cpu_cap(X86_FEATURE_TSC);
  102. }
  103. }
  104. static void __init numaq_tsc_init(void)
  105. {
  106. numaq_tsc_disable();
  107. }
  108. static inline int generate_logical_apicid(int quad, int phys_apicid)
  109. {
  110. return (quad << 4) + (phys_apicid ? phys_apicid << 1 : 1);
  111. }
  112. /* x86_quirks member */
  113. static int mpc_apic_id(struct mpc_cpu *m)
  114. {
  115. int quad = translation_table[mpc_record]->trans_quad;
  116. int logical_apicid = generate_logical_apicid(quad, m->apicid);
  117. printk(KERN_DEBUG
  118. "Processor #%d %u:%u APIC version %d (quad %d, apic %d)\n",
  119. m->apicid, (m->cpufeature & CPU_FAMILY_MASK) >> 8,
  120. (m->cpufeature & CPU_MODEL_MASK) >> 4,
  121. m->apicver, quad, logical_apicid);
  122. return logical_apicid;
  123. }
  124. /* x86_quirks member */
  125. static void mpc_oem_bus_info(struct mpc_bus *m, char *name)
  126. {
  127. int quad = translation_table[mpc_record]->trans_quad;
  128. int local = translation_table[mpc_record]->trans_local;
  129. mp_bus_id_to_node[m->busid] = quad;
  130. mp_bus_id_to_local[m->busid] = local;
  131. printk(KERN_INFO "Bus #%d is %s (node %d)\n", m->busid, name, quad);
  132. }
  133. /* x86_quirks member */
  134. static void mpc_oem_pci_bus(struct mpc_bus *m)
  135. {
  136. int quad = translation_table[mpc_record]->trans_quad;
  137. int local = translation_table[mpc_record]->trans_local;
  138. quad_local_to_mp_bus_id[quad][local] = m->busid;
  139. }
  140. /*
  141. * Called from mpparse code.
  142. * mode = 0: prescan
  143. * mode = 1: one mpc entry scanned
  144. */
  145. static void numaq_mpc_record(unsigned int mode)
  146. {
  147. if (!mode)
  148. mpc_record = 0;
  149. else
  150. mpc_record++;
  151. }
  152. static void __init MP_translation_info(struct mpc_trans *m)
  153. {
  154. printk(KERN_INFO
  155. "Translation: record %d, type %d, quad %d, global %d, local %d\n",
  156. mpc_record, m->trans_type, m->trans_quad, m->trans_global,
  157. m->trans_local);
  158. if (mpc_record >= MAX_MPC_ENTRY)
  159. printk(KERN_ERR "MAX_MPC_ENTRY exceeded!\n");
  160. else
  161. translation_table[mpc_record] = m; /* stash this for later */
  162. if (m->trans_quad < MAX_NUMNODES && !node_online(m->trans_quad))
  163. node_set_online(m->trans_quad);
  164. }
  165. static int __init mpf_checksum(unsigned char *mp, int len)
  166. {
  167. int sum = 0;
  168. while (len--)
  169. sum += *mp++;
  170. return sum & 0xFF;
  171. }
  172. /*
  173. * Read/parse the MPC oem tables
  174. */
  175. static void __init smp_read_mpc_oem(struct mpc_table *mpc)
  176. {
  177. struct mpc_oemtable *oemtable = (void *)(long)mpc->oemptr;
  178. int count = sizeof(*oemtable); /* the header size */
  179. unsigned char *oemptr = ((unsigned char *)oemtable) + count;
  180. mpc_record = 0;
  181. printk(KERN_INFO
  182. "Found an OEM MPC table at %8p - parsing it...\n", oemtable);
  183. if (memcmp(oemtable->signature, MPC_OEM_SIGNATURE, 4)) {
  184. printk(KERN_WARNING
  185. "SMP mpc oemtable: bad signature [%c%c%c%c]!\n",
  186. oemtable->signature[0], oemtable->signature[1],
  187. oemtable->signature[2], oemtable->signature[3]);
  188. return;
  189. }
  190. if (mpf_checksum((unsigned char *)oemtable, oemtable->length)) {
  191. printk(KERN_WARNING "SMP oem mptable: checksum error!\n");
  192. return;
  193. }
  194. while (count < oemtable->length) {
  195. switch (*oemptr) {
  196. case MP_TRANSLATION:
  197. {
  198. struct mpc_trans *m = (void *)oemptr;
  199. MP_translation_info(m);
  200. oemptr += sizeof(*m);
  201. count += sizeof(*m);
  202. ++mpc_record;
  203. break;
  204. }
  205. default:
  206. printk(KERN_WARNING
  207. "Unrecognised OEM table entry type! - %d\n",
  208. (int)*oemptr);
  209. return;
  210. }
  211. }
  212. }
  213. static __init void early_check_numaq(void)
  214. {
  215. /*
  216. * get boot-time SMP configuration:
  217. */
  218. if (smp_found_config)
  219. early_get_smp_config();
  220. if (found_numaq) {
  221. x86_init.mpparse.mpc_record = numaq_mpc_record;
  222. x86_init.mpparse.setup_ioapic_ids = x86_init_noop;
  223. x86_init.mpparse.mpc_apic_id = mpc_apic_id;
  224. x86_init.mpparse.smp_read_mpc_oem = smp_read_mpc_oem;
  225. x86_init.mpparse.mpc_oem_pci_bus = mpc_oem_pci_bus;
  226. x86_init.mpparse.mpc_oem_bus_info = mpc_oem_bus_info;
  227. x86_init.timers.tsc_pre_init = numaq_tsc_init;
  228. x86_init.pci.init = pci_numaq_init;
  229. }
  230. }
  231. int __init numaq_numa_init(void)
  232. {
  233. early_check_numaq();
  234. if (!found_numaq)
  235. return -ENOENT;
  236. smp_dump_qct();
  237. return 0;
  238. }
  239. #define NUMAQ_APIC_DFR_VALUE (APIC_DFR_CLUSTER)
  240. static inline unsigned int numaq_get_apic_id(unsigned long x)
  241. {
  242. return (x >> 24) & 0x0F;
  243. }
  244. static inline void numaq_send_IPI_mask(const struct cpumask *mask, int vector)
  245. {
  246. default_send_IPI_mask_sequence_logical(mask, vector);
  247. }
  248. static inline void numaq_send_IPI_allbutself(int vector)
  249. {
  250. default_send_IPI_mask_allbutself_logical(cpu_online_mask, vector);
  251. }
  252. static inline void numaq_send_IPI_all(int vector)
  253. {
  254. numaq_send_IPI_mask(cpu_online_mask, vector);
  255. }
  256. #define NUMAQ_TRAMPOLINE_PHYS_LOW (0x8)
  257. #define NUMAQ_TRAMPOLINE_PHYS_HIGH (0xa)
  258. /*
  259. * Because we use NMIs rather than the INIT-STARTUP sequence to
  260. * bootstrap the CPUs, the APIC may be in a weird state. Kick it:
  261. */
  262. static inline void numaq_smp_callin_clear_local_apic(void)
  263. {
  264. clear_local_APIC();
  265. }
  266. static inline const struct cpumask *numaq_target_cpus(void)
  267. {
  268. return cpu_all_mask;
  269. }
  270. static unsigned long numaq_check_apicid_used(physid_mask_t *map, int apicid)
  271. {
  272. return physid_isset(apicid, *map);
  273. }
  274. static inline unsigned long numaq_check_apicid_present(int bit)
  275. {
  276. return physid_isset(bit, phys_cpu_present_map);
  277. }
  278. static inline int numaq_apic_id_registered(void)
  279. {
  280. return 1;
  281. }
  282. static inline void numaq_init_apic_ldr(void)
  283. {
  284. /* Already done in NUMA-Q firmware */
  285. }
  286. static inline void numaq_setup_apic_routing(void)
  287. {
  288. printk(KERN_INFO
  289. "Enabling APIC mode: NUMA-Q. Using %d I/O APICs\n",
  290. nr_ioapics);
  291. }
  292. /*
  293. * Skip adding the timer int on secondary nodes, which causes
  294. * a small but painful rift in the time-space continuum.
  295. */
  296. static inline int numaq_multi_timer_check(int apic, int irq)
  297. {
  298. return apic != 0 && irq == 0;
  299. }
  300. static inline void numaq_ioapic_phys_id_map(physid_mask_t *phys_map, physid_mask_t *retmap)
  301. {
  302. /* We don't have a good way to do this yet - hack */
  303. return physids_promote(0xFUL, retmap);
  304. }
  305. /*
  306. * Supporting over 60 cpus on NUMA-Q requires a locality-dependent
  307. * cpu to APIC ID relation to properly interact with the intelligent
  308. * mode of the cluster controller.
  309. */
  310. static inline int numaq_cpu_present_to_apicid(int mps_cpu)
  311. {
  312. if (mps_cpu < 60)
  313. return ((mps_cpu >> 2) << 4) | (1 << (mps_cpu & 0x3));
  314. else
  315. return BAD_APICID;
  316. }
  317. static inline int numaq_apicid_to_node(int logical_apicid)
  318. {
  319. return logical_apicid >> 4;
  320. }
  321. static int numaq_numa_cpu_node(int cpu)
  322. {
  323. int logical_apicid = early_per_cpu(x86_cpu_to_logical_apicid, cpu);
  324. if (logical_apicid != BAD_APICID)
  325. return numaq_apicid_to_node(logical_apicid);
  326. return NUMA_NO_NODE;
  327. }
  328. static void numaq_apicid_to_cpu_present(int logical_apicid, physid_mask_t *retmap)
  329. {
  330. int node = numaq_apicid_to_node(logical_apicid);
  331. int cpu = __ffs(logical_apicid & 0xf);
  332. physid_set_mask_of_physid(cpu + 4*node, retmap);
  333. }
  334. /* Where the IO area was mapped on multiquad, always 0 otherwise */
  335. void *xquad_portio;
  336. static inline int numaq_check_phys_apicid_present(int phys_apicid)
  337. {
  338. return 1;
  339. }
  340. /*
  341. * We use physical apicids here, not logical, so just return the default
  342. * physical broadcast to stop people from breaking us
  343. */
  344. static unsigned int numaq_cpu_mask_to_apicid(const struct cpumask *cpumask)
  345. {
  346. return 0x0F;
  347. }
  348. static inline unsigned int
  349. numaq_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
  350. const struct cpumask *andmask)
  351. {
  352. return 0x0F;
  353. }
  354. /* No NUMA-Q box has a HT CPU, but it can't hurt to use the default code. */
  355. static inline int numaq_phys_pkg_id(int cpuid_apic, int index_msb)
  356. {
  357. return cpuid_apic >> index_msb;
  358. }
  359. static int
  360. numaq_mps_oem_check(struct mpc_table *mpc, char *oem, char *productid)
  361. {
  362. if (strncmp(oem, "IBM NUMA", 8))
  363. printk(KERN_ERR "Warning! Not a NUMA-Q system!\n");
  364. else
  365. found_numaq = 1;
  366. return found_numaq;
  367. }
  368. static int probe_numaq(void)
  369. {
  370. /* already know from get_memcfg_numaq() */
  371. return found_numaq;
  372. }
  373. static void numaq_vector_allocation_domain(int cpu, struct cpumask *retmask)
  374. {
  375. /* Careful. Some cpus do not strictly honor the set of cpus
  376. * specified in the interrupt destination when using lowest
  377. * priority interrupt delivery mode.
  378. *
  379. * In particular there was a hyperthreading cpu observed to
  380. * deliver interrupts to the wrong hyperthread when only one
  381. * hyperthread was specified in the interrupt desitination.
  382. */
  383. cpumask_clear(retmask);
  384. cpumask_bits(retmask)[0] = APIC_ALL_CPUS;
  385. }
  386. static void numaq_setup_portio_remap(void)
  387. {
  388. int num_quads = num_online_nodes();
  389. if (num_quads <= 1)
  390. return;
  391. printk(KERN_INFO
  392. "Remapping cross-quad port I/O for %d quads\n", num_quads);
  393. xquad_portio = ioremap(XQUAD_PORTIO_BASE, num_quads*XQUAD_PORTIO_QUAD);
  394. printk(KERN_INFO
  395. "xquad_portio vaddr 0x%08lx, len %08lx\n",
  396. (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
  397. }
  398. /* Use __refdata to keep false positive warning calm. */
  399. static struct apic __refdata apic_numaq = {
  400. .name = "NUMAQ",
  401. .probe = probe_numaq,
  402. .acpi_madt_oem_check = NULL,
  403. .apic_id_valid = default_apic_id_valid,
  404. .apic_id_registered = numaq_apic_id_registered,
  405. .irq_delivery_mode = dest_LowestPrio,
  406. /* physical delivery on LOCAL quad: */
  407. .irq_dest_mode = 0,
  408. .target_cpus = numaq_target_cpus,
  409. .disable_esr = 1,
  410. .dest_logical = APIC_DEST_LOGICAL,
  411. .check_apicid_used = numaq_check_apicid_used,
  412. .check_apicid_present = numaq_check_apicid_present,
  413. .vector_allocation_domain = numaq_vector_allocation_domain,
  414. .init_apic_ldr = numaq_init_apic_ldr,
  415. .ioapic_phys_id_map = numaq_ioapic_phys_id_map,
  416. .setup_apic_routing = numaq_setup_apic_routing,
  417. .multi_timer_check = numaq_multi_timer_check,
  418. .cpu_present_to_apicid = numaq_cpu_present_to_apicid,
  419. .apicid_to_cpu_present = numaq_apicid_to_cpu_present,
  420. .setup_portio_remap = numaq_setup_portio_remap,
  421. .check_phys_apicid_present = numaq_check_phys_apicid_present,
  422. .enable_apic_mode = NULL,
  423. .phys_pkg_id = numaq_phys_pkg_id,
  424. .mps_oem_check = numaq_mps_oem_check,
  425. .get_apic_id = numaq_get_apic_id,
  426. .set_apic_id = NULL,
  427. .apic_id_mask = 0x0F << 24,
  428. .cpu_mask_to_apicid = numaq_cpu_mask_to_apicid,
  429. .cpu_mask_to_apicid_and = numaq_cpu_mask_to_apicid_and,
  430. .send_IPI_mask = numaq_send_IPI_mask,
  431. .send_IPI_mask_allbutself = NULL,
  432. .send_IPI_allbutself = numaq_send_IPI_allbutself,
  433. .send_IPI_all = numaq_send_IPI_all,
  434. .send_IPI_self = default_send_IPI_self,
  435. .wakeup_secondary_cpu = wakeup_secondary_cpu_via_nmi,
  436. .trampoline_phys_low = NUMAQ_TRAMPOLINE_PHYS_LOW,
  437. .trampoline_phys_high = NUMAQ_TRAMPOLINE_PHYS_HIGH,
  438. /* We don't do anything here because we use NMI's to boot instead */
  439. .wait_for_init_deassert = NULL,
  440. .smp_callin_clear_local_apic = numaq_smp_callin_clear_local_apic,
  441. .inquire_remote_apic = NULL,
  442. .read = native_apic_mem_read,
  443. .write = native_apic_mem_write,
  444. .icr_read = native_apic_icr_read,
  445. .icr_write = native_apic_icr_write,
  446. .wait_icr_idle = native_apic_wait_icr_idle,
  447. .safe_wait_icr_idle = native_safe_apic_wait_icr_idle,
  448. .x86_32_early_logical_apicid = noop_x86_32_early_logical_apicid,
  449. .x86_32_numa_cpu_node = numaq_numa_cpu_node,
  450. };
  451. apic_driver(apic_numaq);