numaq_32.c 15 KB

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