numaq_32.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  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. #define APIC_DEFINITION 1
  261. #include <linux/threads.h>
  262. #include <linux/cpumask.h>
  263. #include <asm/mpspec.h>
  264. #include <asm/fixmap.h>
  265. #include <asm/apicdef.h>
  266. #include <asm/ipi.h>
  267. #include <linux/kernel.h>
  268. #include <linux/string.h>
  269. #include <linux/init.h>
  270. #include <linux/numa.h>
  271. #include <linux/smp.h>
  272. #include <asm/numaq.h>
  273. #include <asm/io.h>
  274. #include <linux/mmzone.h>
  275. #include <linux/nodemask.h>
  276. #define NUMAQ_APIC_DFR_VALUE (APIC_DFR_CLUSTER)
  277. static inline unsigned int numaq_get_apic_id(unsigned long x)
  278. {
  279. return (x >> 24) & 0x0F;
  280. }
  281. static inline void numaq_send_IPI_mask(const struct cpumask *mask, int vector)
  282. {
  283. default_send_IPI_mask_sequence_logical(mask, vector);
  284. }
  285. static inline void numaq_send_IPI_allbutself(int vector)
  286. {
  287. default_send_IPI_mask_allbutself_logical(cpu_online_mask, vector);
  288. }
  289. static inline void numaq_send_IPI_all(int vector)
  290. {
  291. numaq_send_IPI_mask(cpu_online_mask, vector);
  292. }
  293. extern void numaq_mps_oem_check(struct mpc_table *, char *, char *);
  294. #define NUMAQ_TRAMPOLINE_PHYS_LOW (0x8)
  295. #define NUMAQ_TRAMPOLINE_PHYS_HIGH (0xa)
  296. /*
  297. * Because we use NMIs rather than the INIT-STARTUP sequence to
  298. * bootstrap the CPUs, the APIC may be in a weird state. Kick it:
  299. */
  300. static inline void numaq_smp_callin_clear_local_apic(void)
  301. {
  302. clear_local_APIC();
  303. }
  304. static inline void
  305. numaq_store_NMI_vector(unsigned short *high, unsigned short *low)
  306. {
  307. printk("Storing NMI vector\n");
  308. *high =
  309. *((volatile unsigned short *)phys_to_virt(NUMAQ_TRAMPOLINE_PHYS_HIGH));
  310. *low =
  311. *((volatile unsigned short *)phys_to_virt(NUMAQ_TRAMPOLINE_PHYS_LOW));
  312. }
  313. static inline const cpumask_t *numaq_target_cpus(void)
  314. {
  315. return &CPU_MASK_ALL;
  316. }
  317. static inline unsigned long
  318. numaq_check_apicid_used(physid_mask_t bitmap, int apicid)
  319. {
  320. return physid_isset(apicid, bitmap);
  321. }
  322. static inline unsigned long numaq_check_apicid_present(int bit)
  323. {
  324. return physid_isset(bit, phys_cpu_present_map);
  325. }
  326. #define apicid_cluster(apicid) (apicid & 0xF0)
  327. static inline int numaq_apic_id_registered(void)
  328. {
  329. return 1;
  330. }
  331. static inline void numaq_init_apic_ldr(void)
  332. {
  333. /* Already done in NUMA-Q firmware */
  334. }
  335. static inline void numaq_setup_apic_routing(void)
  336. {
  337. printk("Enabling APIC mode: %s. Using %d I/O APICs\n",
  338. "NUMA-Q", nr_ioapics);
  339. }
  340. /*
  341. * Skip adding the timer int on secondary nodes, which causes
  342. * a small but painful rift in the time-space continuum.
  343. */
  344. static inline int numaq_multi_timer_check(int apic, int irq)
  345. {
  346. return apic != 0 && irq == 0;
  347. }
  348. static inline physid_mask_t numaq_ioapic_phys_id_map(physid_mask_t phys_map)
  349. {
  350. /* We don't have a good way to do this yet - hack */
  351. return physids_promote(0xFUL);
  352. }
  353. /* Mapping from cpu number to logical apicid */
  354. extern u8 cpu_2_logical_apicid[];
  355. static inline int numaq_cpu_to_logical_apicid(int cpu)
  356. {
  357. if (cpu >= nr_cpu_ids)
  358. return BAD_APICID;
  359. return (int)cpu_2_logical_apicid[cpu];
  360. }
  361. /*
  362. * Supporting over 60 cpus on NUMA-Q requires a locality-dependent
  363. * cpu to APIC ID relation to properly interact with the intelligent
  364. * mode of the cluster controller.
  365. */
  366. static inline int numaq_cpu_present_to_apicid(int mps_cpu)
  367. {
  368. if (mps_cpu < 60)
  369. return ((mps_cpu >> 2) << 4) | (1 << (mps_cpu & 0x3));
  370. else
  371. return BAD_APICID;
  372. }
  373. static inline int numaq_apicid_to_node(int logical_apicid)
  374. {
  375. return logical_apicid >> 4;
  376. }
  377. static inline physid_mask_t numaq_apicid_to_cpu_present(int logical_apicid)
  378. {
  379. int node = numaq_apicid_to_node(logical_apicid);
  380. int cpu = __ffs(logical_apicid & 0xf);
  381. return physid_mask_of_physid(cpu + 4*node);
  382. }
  383. /* Where the IO area was mapped on multiquad, always 0 otherwise */
  384. void *xquad_portio;
  385. static inline int numaq_check_phys_apicid_present(int boot_cpu_physical_apicid)
  386. {
  387. return 1;
  388. }
  389. /*
  390. * We use physical apicids here, not logical, so just return the default
  391. * physical broadcast to stop people from breaking us
  392. */
  393. static inline unsigned int numaq_cpu_mask_to_apicid(const cpumask_t *cpumask)
  394. {
  395. return 0x0F;
  396. }
  397. static inline unsigned int
  398. numaq_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
  399. const struct cpumask *andmask)
  400. {
  401. return 0x0F;
  402. }
  403. /* No NUMA-Q box has a HT CPU, but it can't hurt to use the default code. */
  404. static inline int numaq_phys_pkg_id(int cpuid_apic, int index_msb)
  405. {
  406. return cpuid_apic >> index_msb;
  407. }
  408. static int __numaq_mps_oem_check(struct mpc_table *mpc, char *oem, char *productid)
  409. {
  410. numaq_mps_oem_check(mpc, oem, productid);
  411. return found_numaq;
  412. }
  413. static int probe_numaq(void)
  414. {
  415. /* already know from get_memcfg_numaq() */
  416. return found_numaq;
  417. }
  418. static void numaq_vector_allocation_domain(int cpu, cpumask_t *retmask)
  419. {
  420. /* Careful. Some cpus do not strictly honor the set of cpus
  421. * specified in the interrupt destination when using lowest
  422. * priority interrupt delivery mode.
  423. *
  424. * In particular there was a hyperthreading cpu observed to
  425. * deliver interrupts to the wrong hyperthread when only one
  426. * hyperthread was specified in the interrupt desitination.
  427. */
  428. *retmask = (cpumask_t){ { [0] = APIC_ALL_CPUS, } };
  429. }
  430. static void numaq_setup_portio_remap(void)
  431. {
  432. int num_quads = num_online_nodes();
  433. if (num_quads <= 1)
  434. return;
  435. printk("Remapping cross-quad port I/O for %d quads\n", num_quads);
  436. xquad_portio = ioremap(XQUAD_PORTIO_BASE, num_quads*XQUAD_PORTIO_QUAD);
  437. printk("xquad_portio vaddr 0x%08lx, len %08lx\n",
  438. (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
  439. }
  440. struct genapic apic_numaq = {
  441. .name = "NUMAQ",
  442. .probe = probe_numaq,
  443. .acpi_madt_oem_check = NULL,
  444. .apic_id_registered = numaq_apic_id_registered,
  445. .irq_delivery_mode = dest_LowestPrio,
  446. /* physical delivery on LOCAL quad: */
  447. .irq_dest_mode = 0,
  448. .target_cpus = numaq_target_cpus,
  449. .disable_esr = 1,
  450. .dest_logical = APIC_DEST_LOGICAL,
  451. .check_apicid_used = numaq_check_apicid_used,
  452. .check_apicid_present = numaq_check_apicid_present,
  453. .vector_allocation_domain = numaq_vector_allocation_domain,
  454. .init_apic_ldr = numaq_init_apic_ldr,
  455. .ioapic_phys_id_map = numaq_ioapic_phys_id_map,
  456. .setup_apic_routing = numaq_setup_apic_routing,
  457. .multi_timer_check = numaq_multi_timer_check,
  458. .apicid_to_node = numaq_apicid_to_node,
  459. .cpu_to_logical_apicid = numaq_cpu_to_logical_apicid,
  460. .cpu_present_to_apicid = numaq_cpu_present_to_apicid,
  461. .apicid_to_cpu_present = numaq_apicid_to_cpu_present,
  462. .setup_portio_remap = numaq_setup_portio_remap,
  463. .check_phys_apicid_present = numaq_check_phys_apicid_present,
  464. .enable_apic_mode = NULL,
  465. .phys_pkg_id = numaq_phys_pkg_id,
  466. .mps_oem_check = __numaq_mps_oem_check,
  467. .get_apic_id = numaq_get_apic_id,
  468. .set_apic_id = NULL,
  469. .apic_id_mask = 0x0F << 24,
  470. .cpu_mask_to_apicid = numaq_cpu_mask_to_apicid,
  471. .cpu_mask_to_apicid_and = numaq_cpu_mask_to_apicid_and,
  472. .send_IPI_mask = numaq_send_IPI_mask,
  473. .send_IPI_mask_allbutself = NULL,
  474. .send_IPI_allbutself = numaq_send_IPI_allbutself,
  475. .send_IPI_all = numaq_send_IPI_all,
  476. .send_IPI_self = default_send_IPI_self,
  477. .wakeup_cpu = NULL,
  478. .trampoline_phys_low = NUMAQ_TRAMPOLINE_PHYS_LOW,
  479. .trampoline_phys_high = NUMAQ_TRAMPOLINE_PHYS_HIGH,
  480. /* We don't do anything here because we use NMI's to boot instead */
  481. .wait_for_init_deassert = NULL,
  482. .smp_callin_clear_local_apic = numaq_smp_callin_clear_local_apic,
  483. .store_NMI_vector = numaq_store_NMI_vector,
  484. .inquire_remote_apic = NULL,
  485. .read = native_apic_mem_read,
  486. .write = native_apic_mem_write,
  487. .icr_read = native_apic_icr_read,
  488. .icr_write = native_apic_icr_write,
  489. .wait_icr_idle = native_apic_wait_icr_idle,
  490. .safe_wait_icr_idle = native_safe_apic_wait_icr_idle,
  491. };