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