numaq_32.c 14 KB

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