numaq_32.c 14 KB

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