]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - arch/x86_64/kernel/mpparse.c
Merge /spare/repo/linux-2.6/
[mirror_ubuntu-artful-kernel.git] / arch / x86_64 / kernel / mpparse.c
1 /*
2 * Intel Multiprocessor Specification 1.1 and 1.4
3 * compliant MP-table parsing routines.
4 *
5 * (c) 1995 Alan Cox, Building #3 <alan@redhat.com>
6 * (c) 1998, 1999, 2000 Ingo Molnar <mingo@redhat.com>
7 *
8 * Fixes
9 * Erich Boleyn : MP v1.4 and additional changes.
10 * Alan Cox : Added EBDA scanning
11 * Ingo Molnar : various cleanups and rewrites
12 * Maciej W. Rozycki: Bits for default MP configurations
13 * Paul Diefenbaugh: Added full ACPI support
14 */
15
16 #include <linux/mm.h>
17 #include <linux/irq.h>
18 #include <linux/init.h>
19 #include <linux/delay.h>
20 #include <linux/config.h>
21 #include <linux/bootmem.h>
22 #include <linux/smp_lock.h>
23 #include <linux/kernel_stat.h>
24 #include <linux/mc146818rtc.h>
25 #include <linux/acpi.h>
26 #include <linux/module.h>
27
28 #include <asm/smp.h>
29 #include <asm/mtrr.h>
30 #include <asm/mpspec.h>
31 #include <asm/pgalloc.h>
32 #include <asm/io_apic.h>
33 #include <asm/proto.h>
34 #include <asm/acpi.h>
35
36 /* Have we found an MP table */
37 int smp_found_config;
38 unsigned int __initdata maxcpus = NR_CPUS;
39
40 int acpi_found_madt;
41
42 /*
43 * Various Linux-internal data structures created from the
44 * MP-table.
45 */
46 int apic_version [MAX_APICS];
47 unsigned char mp_bus_id_to_type [MAX_MP_BUSSES] = { [0 ... MAX_MP_BUSSES-1] = -1 };
48 int mp_bus_id_to_pci_bus [MAX_MP_BUSSES] = { [0 ... MAX_MP_BUSSES-1] = -1 };
49 unsigned char pci_bus_to_node [256];
50 EXPORT_SYMBOL(pci_bus_to_node);
51
52 static int mp_current_pci_id = 0;
53 /* I/O APIC entries */
54 struct mpc_config_ioapic mp_ioapics[MAX_IO_APICS];
55
56 /* # of MP IRQ source entries */
57 struct mpc_config_intsrc mp_irqs[MAX_IRQ_SOURCES];
58
59 /* MP IRQ source entries */
60 int mp_irq_entries;
61
62 int nr_ioapics;
63 int pic_mode;
64 unsigned long mp_lapic_addr = 0;
65
66
67
68 /* Processor that is doing the boot up */
69 unsigned int boot_cpu_id = -1U;
70 /* Internal processor count */
71 static unsigned int num_processors = 0;
72
73 /* Bitmask of physically existing CPUs */
74 physid_mask_t phys_cpu_present_map = PHYSID_MASK_NONE;
75
76 /* ACPI MADT entry parsing functions */
77 #ifdef CONFIG_ACPI_BOOT
78 extern struct acpi_boot_flags acpi_boot;
79 #ifdef CONFIG_X86_LOCAL_APIC
80 extern int acpi_parse_lapic (acpi_table_entry_header *header);
81 extern int acpi_parse_lapic_addr_ovr (acpi_table_entry_header *header);
82 extern int acpi_parse_lapic_nmi (acpi_table_entry_header *header);
83 #endif /*CONFIG_X86_LOCAL_APIC*/
84 #ifdef CONFIG_X86_IO_APIC
85 extern int acpi_parse_ioapic (acpi_table_entry_header *header);
86 #endif /*CONFIG_X86_IO_APIC*/
87 #endif /*CONFIG_ACPI_BOOT*/
88
89 u8 bios_cpu_apicid[NR_CPUS] = { [0 ... NR_CPUS-1] = BAD_APICID };
90
91
92 /*
93 * Intel MP BIOS table parsing routines:
94 */
95
96 /*
97 * Checksum an MP configuration block.
98 */
99
100 static int __init mpf_checksum(unsigned char *mp, int len)
101 {
102 int sum = 0;
103
104 while (len--)
105 sum += *mp++;
106
107 return sum & 0xFF;
108 }
109
110 static void __init MP_processor_info (struct mpc_config_processor *m)
111 {
112 int ver, cpu;
113 static int found_bsp=0;
114
115 if (!(m->mpc_cpuflag & CPU_ENABLED))
116 return;
117
118 printk(KERN_INFO "Processor #%d %d:%d APIC version %d\n",
119 m->mpc_apicid,
120 (m->mpc_cpufeature & CPU_FAMILY_MASK)>>8,
121 (m->mpc_cpufeature & CPU_MODEL_MASK)>>4,
122 m->mpc_apicver);
123
124 if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
125 Dprintk(" Bootup CPU\n");
126 boot_cpu_id = m->mpc_apicid;
127 }
128 if (num_processors >= NR_CPUS) {
129 printk(KERN_WARNING "WARNING: NR_CPUS limit of %i reached."
130 " Processor ignored.\n", NR_CPUS);
131 return;
132 }
133
134 cpu = num_processors++;
135
136 if (m->mpc_apicid > MAX_APICS) {
137 printk(KERN_ERR "Processor #%d INVALID. (Max ID: %d).\n",
138 m->mpc_apicid, MAX_APICS);
139 return;
140 }
141 ver = m->mpc_apicver;
142
143 physid_set(m->mpc_apicid, phys_cpu_present_map);
144 /*
145 * Validate version
146 */
147 if (ver == 0x0) {
148 printk(KERN_ERR "BIOS bug, APIC version is 0 for CPU#%d! fixing up to 0x10. (tell your hw vendor)\n", m->mpc_apicid);
149 ver = 0x10;
150 }
151 apic_version[m->mpc_apicid] = ver;
152 if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
153 /*
154 * bios_cpu_apicid is required to have processors listed
155 * in same order as logical cpu numbers. Hence the first
156 * entry is BSP, and so on.
157 */
158 cpu = 0;
159
160 bios_cpu_apicid[0] = m->mpc_apicid;
161 x86_cpu_to_apicid[0] = m->mpc_apicid;
162 found_bsp = 1;
163 } else
164 cpu = num_processors - found_bsp;
165 bios_cpu_apicid[cpu] = m->mpc_apicid;
166 x86_cpu_to_apicid[cpu] = m->mpc_apicid;
167
168 cpu_set(cpu, cpu_possible_map);
169 cpu_set(cpu, cpu_present_map);
170 }
171
172 static void __init MP_bus_info (struct mpc_config_bus *m)
173 {
174 char str[7];
175
176 memcpy(str, m->mpc_bustype, 6);
177 str[6] = 0;
178 Dprintk("Bus #%d is %s\n", m->mpc_busid, str);
179
180 if (strncmp(str, "ISA", 3) == 0) {
181 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA;
182 } else if (strncmp(str, "EISA", 4) == 0) {
183 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA;
184 } else if (strncmp(str, "PCI", 3) == 0) {
185 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI;
186 mp_bus_id_to_pci_bus[m->mpc_busid] = mp_current_pci_id;
187 mp_current_pci_id++;
188 } else if (strncmp(str, "MCA", 3) == 0) {
189 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_MCA;
190 } else {
191 printk(KERN_ERR "Unknown bustype %s\n", str);
192 }
193 }
194
195 static void __init MP_ioapic_info (struct mpc_config_ioapic *m)
196 {
197 if (!(m->mpc_flags & MPC_APIC_USABLE))
198 return;
199
200 printk("I/O APIC #%d Version %d at 0x%X.\n",
201 m->mpc_apicid, m->mpc_apicver, m->mpc_apicaddr);
202 if (nr_ioapics >= MAX_IO_APICS) {
203 printk(KERN_ERR "Max # of I/O APICs (%d) exceeded (found %d).\n",
204 MAX_IO_APICS, nr_ioapics);
205 panic("Recompile kernel with bigger MAX_IO_APICS!.\n");
206 }
207 if (!m->mpc_apicaddr) {
208 printk(KERN_ERR "WARNING: bogus zero I/O APIC address"
209 " found in MP table, skipping!\n");
210 return;
211 }
212 mp_ioapics[nr_ioapics] = *m;
213 nr_ioapics++;
214 }
215
216 static void __init MP_intsrc_info (struct mpc_config_intsrc *m)
217 {
218 mp_irqs [mp_irq_entries] = *m;
219 Dprintk("Int: type %d, pol %d, trig %d, bus %d,"
220 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
221 m->mpc_irqtype, m->mpc_irqflag & 3,
222 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
223 m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
224 if (++mp_irq_entries == MAX_IRQ_SOURCES)
225 panic("Max # of irq sources exceeded!!\n");
226 }
227
228 static void __init MP_lintsrc_info (struct mpc_config_lintsrc *m)
229 {
230 Dprintk("Lint: type %d, pol %d, trig %d, bus %d,"
231 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
232 m->mpc_irqtype, m->mpc_irqflag & 3,
233 (m->mpc_irqflag >> 2) &3, m->mpc_srcbusid,
234 m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint);
235 /*
236 * Well it seems all SMP boards in existence
237 * use ExtINT/LVT1 == LINT0 and
238 * NMI/LVT2 == LINT1 - the following check
239 * will show us if this assumptions is false.
240 * Until then we do not have to add baggage.
241 */
242 if ((m->mpc_irqtype == mp_ExtINT) &&
243 (m->mpc_destapiclint != 0))
244 BUG();
245 if ((m->mpc_irqtype == mp_NMI) &&
246 (m->mpc_destapiclint != 1))
247 BUG();
248 }
249
250 /*
251 * Read/parse the MPC
252 */
253
254 static int __init smp_read_mpc(struct mp_config_table *mpc)
255 {
256 char str[16];
257 int count=sizeof(*mpc);
258 unsigned char *mpt=((unsigned char *)mpc)+count;
259
260 if (memcmp(mpc->mpc_signature,MPC_SIGNATURE,4)) {
261 printk("SMP mptable: bad signature [%c%c%c%c]!\n",
262 mpc->mpc_signature[0],
263 mpc->mpc_signature[1],
264 mpc->mpc_signature[2],
265 mpc->mpc_signature[3]);
266 return 0;
267 }
268 if (mpf_checksum((unsigned char *)mpc,mpc->mpc_length)) {
269 printk("SMP mptable: checksum error!\n");
270 return 0;
271 }
272 if (mpc->mpc_spec!=0x01 && mpc->mpc_spec!=0x04) {
273 printk(KERN_ERR "SMP mptable: bad table version (%d)!!\n",
274 mpc->mpc_spec);
275 return 0;
276 }
277 if (!mpc->mpc_lapic) {
278 printk(KERN_ERR "SMP mptable: null local APIC address!\n");
279 return 0;
280 }
281 memcpy(str,mpc->mpc_oem,8);
282 str[8]=0;
283 printk(KERN_INFO "OEM ID: %s ",str);
284
285 memcpy(str,mpc->mpc_productid,12);
286 str[12]=0;
287 printk(KERN_INFO "Product ID: %s ",str);
288
289 printk(KERN_INFO "APIC at: 0x%X\n",mpc->mpc_lapic);
290
291 /* save the local APIC address, it might be non-default */
292 if (!acpi_lapic)
293 mp_lapic_addr = mpc->mpc_lapic;
294
295 /*
296 * Now process the configuration blocks.
297 */
298 while (count < mpc->mpc_length) {
299 switch(*mpt) {
300 case MP_PROCESSOR:
301 {
302 struct mpc_config_processor *m=
303 (struct mpc_config_processor *)mpt;
304 if (!acpi_lapic)
305 MP_processor_info(m);
306 mpt += sizeof(*m);
307 count += sizeof(*m);
308 break;
309 }
310 case MP_BUS:
311 {
312 struct mpc_config_bus *m=
313 (struct mpc_config_bus *)mpt;
314 MP_bus_info(m);
315 mpt += sizeof(*m);
316 count += sizeof(*m);
317 break;
318 }
319 case MP_IOAPIC:
320 {
321 struct mpc_config_ioapic *m=
322 (struct mpc_config_ioapic *)mpt;
323 MP_ioapic_info(m);
324 mpt+=sizeof(*m);
325 count+=sizeof(*m);
326 break;
327 }
328 case MP_INTSRC:
329 {
330 struct mpc_config_intsrc *m=
331 (struct mpc_config_intsrc *)mpt;
332
333 MP_intsrc_info(m);
334 mpt+=sizeof(*m);
335 count+=sizeof(*m);
336 break;
337 }
338 case MP_LINTSRC:
339 {
340 struct mpc_config_lintsrc *m=
341 (struct mpc_config_lintsrc *)mpt;
342 MP_lintsrc_info(m);
343 mpt+=sizeof(*m);
344 count+=sizeof(*m);
345 break;
346 }
347 }
348 }
349 clustered_apic_check();
350 if (!num_processors)
351 printk(KERN_ERR "SMP mptable: no processors registered!\n");
352 return num_processors;
353 }
354
355 static int __init ELCR_trigger(unsigned int irq)
356 {
357 unsigned int port;
358
359 port = 0x4d0 + (irq >> 3);
360 return (inb(port) >> (irq & 7)) & 1;
361 }
362
363 static void __init construct_default_ioirq_mptable(int mpc_default_type)
364 {
365 struct mpc_config_intsrc intsrc;
366 int i;
367 int ELCR_fallback = 0;
368
369 intsrc.mpc_type = MP_INTSRC;
370 intsrc.mpc_irqflag = 0; /* conforming */
371 intsrc.mpc_srcbus = 0;
372 intsrc.mpc_dstapic = mp_ioapics[0].mpc_apicid;
373
374 intsrc.mpc_irqtype = mp_INT;
375
376 /*
377 * If true, we have an ISA/PCI system with no IRQ entries
378 * in the MP table. To prevent the PCI interrupts from being set up
379 * incorrectly, we try to use the ELCR. The sanity check to see if
380 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
381 * never be level sensitive, so we simply see if the ELCR agrees.
382 * If it does, we assume it's valid.
383 */
384 if (mpc_default_type == 5) {
385 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... falling back to ELCR\n");
386
387 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) || ELCR_trigger(13))
388 printk(KERN_ERR "ELCR contains invalid data... not using ELCR\n");
389 else {
390 printk(KERN_INFO "Using ELCR to identify PCI interrupts\n");
391 ELCR_fallback = 1;
392 }
393 }
394
395 for (i = 0; i < 16; i++) {
396 switch (mpc_default_type) {
397 case 2:
398 if (i == 0 || i == 13)
399 continue; /* IRQ0 & IRQ13 not connected */
400 /* fall through */
401 default:
402 if (i == 2)
403 continue; /* IRQ2 is never connected */
404 }
405
406 if (ELCR_fallback) {
407 /*
408 * If the ELCR indicates a level-sensitive interrupt, we
409 * copy that information over to the MP table in the
410 * irqflag field (level sensitive, active high polarity).
411 */
412 if (ELCR_trigger(i))
413 intsrc.mpc_irqflag = 13;
414 else
415 intsrc.mpc_irqflag = 0;
416 }
417
418 intsrc.mpc_srcbusirq = i;
419 intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
420 MP_intsrc_info(&intsrc);
421 }
422
423 intsrc.mpc_irqtype = mp_ExtINT;
424 intsrc.mpc_srcbusirq = 0;
425 intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */
426 MP_intsrc_info(&intsrc);
427 }
428
429 static inline void __init construct_default_ISA_mptable(int mpc_default_type)
430 {
431 struct mpc_config_processor processor;
432 struct mpc_config_bus bus;
433 struct mpc_config_ioapic ioapic;
434 struct mpc_config_lintsrc lintsrc;
435 int linttypes[2] = { mp_ExtINT, mp_NMI };
436 int i;
437
438 /*
439 * local APIC has default address
440 */
441 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
442
443 /*
444 * 2 CPUs, numbered 0 & 1.
445 */
446 processor.mpc_type = MP_PROCESSOR;
447 /* Either an integrated APIC or a discrete 82489DX. */
448 processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
449 processor.mpc_cpuflag = CPU_ENABLED;
450 processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
451 (boot_cpu_data.x86_model << 4) |
452 boot_cpu_data.x86_mask;
453 processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
454 processor.mpc_reserved[0] = 0;
455 processor.mpc_reserved[1] = 0;
456 for (i = 0; i < 2; i++) {
457 processor.mpc_apicid = i;
458 MP_processor_info(&processor);
459 }
460
461 bus.mpc_type = MP_BUS;
462 bus.mpc_busid = 0;
463 switch (mpc_default_type) {
464 default:
465 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
466 mpc_default_type);
467 /* fall through */
468 case 1:
469 case 5:
470 memcpy(bus.mpc_bustype, "ISA ", 6);
471 break;
472 case 2:
473 case 6:
474 case 3:
475 memcpy(bus.mpc_bustype, "EISA ", 6);
476 break;
477 case 4:
478 case 7:
479 memcpy(bus.mpc_bustype, "MCA ", 6);
480 }
481 MP_bus_info(&bus);
482 if (mpc_default_type > 4) {
483 bus.mpc_busid = 1;
484 memcpy(bus.mpc_bustype, "PCI ", 6);
485 MP_bus_info(&bus);
486 }
487
488 ioapic.mpc_type = MP_IOAPIC;
489 ioapic.mpc_apicid = 2;
490 ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
491 ioapic.mpc_flags = MPC_APIC_USABLE;
492 ioapic.mpc_apicaddr = 0xFEC00000;
493 MP_ioapic_info(&ioapic);
494
495 /*
496 * We set up most of the low 16 IO-APIC pins according to MPS rules.
497 */
498 construct_default_ioirq_mptable(mpc_default_type);
499
500 lintsrc.mpc_type = MP_LINTSRC;
501 lintsrc.mpc_irqflag = 0; /* conforming */
502 lintsrc.mpc_srcbusid = 0;
503 lintsrc.mpc_srcbusirq = 0;
504 lintsrc.mpc_destapic = MP_APIC_ALL;
505 for (i = 0; i < 2; i++) {
506 lintsrc.mpc_irqtype = linttypes[i];
507 lintsrc.mpc_destapiclint = i;
508 MP_lintsrc_info(&lintsrc);
509 }
510 }
511
512 static struct intel_mp_floating *mpf_found;
513
514 /*
515 * Scan the memory blocks for an SMP configuration block.
516 */
517 void __init get_smp_config (void)
518 {
519 struct intel_mp_floating *mpf = mpf_found;
520
521 /*
522 * ACPI may be used to obtain the entire SMP configuration or just to
523 * enumerate/configure processors (CONFIG_ACPI_BOOT). Note that
524 * ACPI supports both logical (e.g. Hyper-Threading) and physical
525 * processors, where MPS only supports physical.
526 */
527 if (acpi_lapic && acpi_ioapic) {
528 printk(KERN_INFO "Using ACPI (MADT) for SMP configuration information\n");
529 return;
530 }
531 else if (acpi_lapic)
532 printk(KERN_INFO "Using ACPI for processor (LAPIC) configuration information\n");
533
534 printk("Intel MultiProcessor Specification v1.%d\n", mpf->mpf_specification);
535 if (mpf->mpf_feature2 & (1<<7)) {
536 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
537 pic_mode = 1;
538 } else {
539 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
540 pic_mode = 0;
541 }
542
543 /*
544 * Now see if we need to read further.
545 */
546 if (mpf->mpf_feature1 != 0) {
547
548 printk(KERN_INFO "Default MP configuration #%d\n", mpf->mpf_feature1);
549 construct_default_ISA_mptable(mpf->mpf_feature1);
550
551 } else if (mpf->mpf_physptr) {
552
553 /*
554 * Read the physical hardware table. Anything here will
555 * override the defaults.
556 */
557 if (!smp_read_mpc((void *)(unsigned long)mpf->mpf_physptr)) {
558 smp_found_config = 0;
559 printk(KERN_ERR "BIOS bug, MP table errors detected!...\n");
560 printk(KERN_ERR "... disabling SMP support. (tell your hw vendor)\n");
561 return;
562 }
563 /*
564 * If there are no explicit MP IRQ entries, then we are
565 * broken. We set up most of the low 16 IO-APIC pins to
566 * ISA defaults and hope it will work.
567 */
568 if (!mp_irq_entries) {
569 struct mpc_config_bus bus;
570
571 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, using default mptable. (tell your hw vendor)\n");
572
573 bus.mpc_type = MP_BUS;
574 bus.mpc_busid = 0;
575 memcpy(bus.mpc_bustype, "ISA ", 6);
576 MP_bus_info(&bus);
577
578 construct_default_ioirq_mptable(0);
579 }
580
581 } else
582 BUG();
583
584 printk(KERN_INFO "Processors: %d\n", num_processors);
585 /*
586 * Only use the first configuration found.
587 */
588 }
589
590 static int __init smp_scan_config (unsigned long base, unsigned long length)
591 {
592 extern void __bad_mpf_size(void);
593 unsigned int *bp = phys_to_virt(base);
594 struct intel_mp_floating *mpf;
595
596 Dprintk("Scan SMP from %p for %ld bytes.\n", bp,length);
597 if (sizeof(*mpf) != 16)
598 __bad_mpf_size();
599
600 while (length > 0) {
601 mpf = (struct intel_mp_floating *)bp;
602 if ((*bp == SMP_MAGIC_IDENT) &&
603 (mpf->mpf_length == 1) &&
604 !mpf_checksum((unsigned char *)bp, 16) &&
605 ((mpf->mpf_specification == 1)
606 || (mpf->mpf_specification == 4)) ) {
607
608 smp_found_config = 1;
609 reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE);
610 if (mpf->mpf_physptr)
611 reserve_bootmem_generic(mpf->mpf_physptr, PAGE_SIZE);
612 mpf_found = mpf;
613 return 1;
614 }
615 bp += 4;
616 length -= 16;
617 }
618 return 0;
619 }
620
621 void __init find_intel_smp (void)
622 {
623 unsigned int address;
624
625 /*
626 * FIXME: Linux assumes you have 640K of base ram..
627 * this continues the error...
628 *
629 * 1) Scan the bottom 1K for a signature
630 * 2) Scan the top 1K of base RAM
631 * 3) Scan the 64K of bios
632 */
633 if (smp_scan_config(0x0,0x400) ||
634 smp_scan_config(639*0x400,0x400) ||
635 smp_scan_config(0xF0000,0x10000))
636 return;
637 /*
638 * If it is an SMP machine we should know now, unless the
639 * configuration is in an EISA/MCA bus machine with an
640 * extended bios data area.
641 *
642 * there is a real-mode segmented pointer pointing to the
643 * 4K EBDA area at 0x40E, calculate and scan it here.
644 *
645 * NOTE! There are Linux loaders that will corrupt the EBDA
646 * area, and as such this kind of SMP config may be less
647 * trustworthy, simply because the SMP table may have been
648 * stomped on during early boot. These loaders are buggy and
649 * should be fixed.
650 */
651
652 address = *(unsigned short *)phys_to_virt(0x40E);
653 address <<= 4;
654 if (smp_scan_config(address, 0x1000))
655 return;
656
657 /* If we have come this far, we did not find an MP table */
658 printk(KERN_INFO "No mptable found.\n");
659 }
660
661 /*
662 * - Intel MP Configuration Table
663 */
664 void __init find_smp_config (void)
665 {
666 #ifdef CONFIG_X86_LOCAL_APIC
667 find_intel_smp();
668 #endif
669 }
670
671
672 /* --------------------------------------------------------------------------
673 ACPI-based MP Configuration
674 -------------------------------------------------------------------------- */
675
676 #ifdef CONFIG_ACPI_BOOT
677
678 void __init mp_register_lapic_address (
679 u64 address)
680 {
681 mp_lapic_addr = (unsigned long) address;
682
683 set_fixmap_nocache(FIX_APIC_BASE, mp_lapic_addr);
684
685 if (boot_cpu_id == -1U)
686 boot_cpu_id = GET_APIC_ID(apic_read(APIC_ID));
687
688 Dprintk("Boot CPU = %d\n", boot_cpu_physical_apicid);
689 }
690
691
692 void __init mp_register_lapic (
693 u8 id,
694 u8 enabled)
695 {
696 struct mpc_config_processor processor;
697 int boot_cpu = 0;
698
699 if (id >= MAX_APICS) {
700 printk(KERN_WARNING "Processor #%d invalid (max %d)\n",
701 id, MAX_APICS);
702 return;
703 }
704
705 if (id == boot_cpu_physical_apicid)
706 boot_cpu = 1;
707
708 processor.mpc_type = MP_PROCESSOR;
709 processor.mpc_apicid = id;
710 processor.mpc_apicver = 0x10; /* TBD: lapic version */
711 processor.mpc_cpuflag = (enabled ? CPU_ENABLED : 0);
712 processor.mpc_cpuflag |= (boot_cpu ? CPU_BOOTPROCESSOR : 0);
713 processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
714 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
715 processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
716 processor.mpc_reserved[0] = 0;
717 processor.mpc_reserved[1] = 0;
718
719 MP_processor_info(&processor);
720 }
721
722 #ifdef CONFIG_X86_IO_APIC
723
724 #define MP_ISA_BUS 0
725 #define MP_MAX_IOAPIC_PIN 127
726
727 static struct mp_ioapic_routing {
728 int apic_id;
729 int gsi_start;
730 int gsi_end;
731 u32 pin_programmed[4];
732 } mp_ioapic_routing[MAX_IO_APICS];
733
734
735 static int mp_find_ioapic (
736 int gsi)
737 {
738 int i = 0;
739
740 /* Find the IOAPIC that manages this GSI. */
741 for (i = 0; i < nr_ioapics; i++) {
742 if ((gsi >= mp_ioapic_routing[i].gsi_start)
743 && (gsi <= mp_ioapic_routing[i].gsi_end))
744 return i;
745 }
746
747 printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %d\n", gsi);
748
749 return -1;
750 }
751
752
753 void __init mp_register_ioapic (
754 u8 id,
755 u32 address,
756 u32 gsi_base)
757 {
758 int idx = 0;
759
760 if (nr_ioapics >= MAX_IO_APICS) {
761 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
762 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
763 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
764 }
765 if (!address) {
766 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
767 " found in MADT table, skipping!\n");
768 return;
769 }
770
771 idx = nr_ioapics++;
772
773 mp_ioapics[idx].mpc_type = MP_IOAPIC;
774 mp_ioapics[idx].mpc_flags = MPC_APIC_USABLE;
775 mp_ioapics[idx].mpc_apicaddr = address;
776
777 set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
778 mp_ioapics[idx].mpc_apicid = id;
779 mp_ioapics[idx].mpc_apicver = io_apic_get_version(idx);
780
781 /*
782 * Build basic IRQ lookup table to facilitate gsi->io_apic lookups
783 * and to prevent reprogramming of IOAPIC pins (PCI IRQs).
784 */
785 mp_ioapic_routing[idx].apic_id = mp_ioapics[idx].mpc_apicid;
786 mp_ioapic_routing[idx].gsi_start = gsi_base;
787 mp_ioapic_routing[idx].gsi_end = gsi_base +
788 io_apic_get_redir_entries(idx);
789
790 printk(KERN_INFO "IOAPIC[%d]: apic_id %d, version %d, address 0x%x, "
791 "GSI %d-%d\n", idx, mp_ioapics[idx].mpc_apicid,
792 mp_ioapics[idx].mpc_apicver, mp_ioapics[idx].mpc_apicaddr,
793 mp_ioapic_routing[idx].gsi_start,
794 mp_ioapic_routing[idx].gsi_end);
795
796 return;
797 }
798
799
800 void __init mp_override_legacy_irq (
801 u8 bus_irq,
802 u8 polarity,
803 u8 trigger,
804 u32 gsi)
805 {
806 struct mpc_config_intsrc intsrc;
807 int ioapic = -1;
808 int pin = -1;
809
810 /*
811 * Convert 'gsi' to 'ioapic.pin'.
812 */
813 ioapic = mp_find_ioapic(gsi);
814 if (ioapic < 0)
815 return;
816 pin = gsi - mp_ioapic_routing[ioapic].gsi_start;
817
818 /*
819 * TBD: This check is for faulty timer entries, where the override
820 * erroneously sets the trigger to level, resulting in a HUGE
821 * increase of timer interrupts!
822 */
823 if ((bus_irq == 0) && (trigger == 3))
824 trigger = 1;
825
826 intsrc.mpc_type = MP_INTSRC;
827 intsrc.mpc_irqtype = mp_INT;
828 intsrc.mpc_irqflag = (trigger << 2) | polarity;
829 intsrc.mpc_srcbus = MP_ISA_BUS;
830 intsrc.mpc_srcbusirq = bus_irq; /* IRQ */
831 intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid; /* APIC ID */
832 intsrc.mpc_dstirq = pin; /* INTIN# */
833
834 Dprintk("Int: type %d, pol %d, trig %d, bus %d, irq %d, %d-%d\n",
835 intsrc.mpc_irqtype, intsrc.mpc_irqflag & 3,
836 (intsrc.mpc_irqflag >> 2) & 3, intsrc.mpc_srcbus,
837 intsrc.mpc_srcbusirq, intsrc.mpc_dstapic, intsrc.mpc_dstirq);
838
839 mp_irqs[mp_irq_entries] = intsrc;
840 if (++mp_irq_entries == MAX_IRQ_SOURCES)
841 panic("Max # of irq sources exceeded!\n");
842
843 return;
844 }
845
846
847 void __init mp_config_acpi_legacy_irqs (void)
848 {
849 struct mpc_config_intsrc intsrc;
850 int i = 0;
851 int ioapic = -1;
852
853 /*
854 * Fabricate the legacy ISA bus (bus #31).
855 */
856 mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
857 Dprintk("Bus #%d is ISA\n", MP_ISA_BUS);
858
859 /*
860 * Locate the IOAPIC that manages the ISA IRQs (0-15).
861 */
862 ioapic = mp_find_ioapic(0);
863 if (ioapic < 0)
864 return;
865
866 intsrc.mpc_type = MP_INTSRC;
867 intsrc.mpc_irqflag = 0; /* Conforming */
868 intsrc.mpc_srcbus = MP_ISA_BUS;
869 intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid;
870
871 /*
872 * Use the default configuration for the IRQs 0-15. Unless
873 * overridden by (MADT) interrupt source override entries.
874 */
875 for (i = 0; i < 16; i++) {
876 int idx;
877
878 for (idx = 0; idx < mp_irq_entries; idx++) {
879 struct mpc_config_intsrc *irq = mp_irqs + idx;
880
881 /* Do we already have a mapping for this ISA IRQ? */
882 if (irq->mpc_srcbus == MP_ISA_BUS && irq->mpc_srcbusirq == i)
883 break;
884
885 /* Do we already have a mapping for this IOAPIC pin */
886 if ((irq->mpc_dstapic == intsrc.mpc_dstapic) &&
887 (irq->mpc_dstirq == i))
888 break;
889 }
890
891 if (idx != mp_irq_entries) {
892 printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
893 continue; /* IRQ already used */
894 }
895
896 intsrc.mpc_irqtype = mp_INT;
897 intsrc.mpc_srcbusirq = i; /* Identity mapped */
898 intsrc.mpc_dstirq = i;
899
900 Dprintk("Int: type %d, pol %d, trig %d, bus %d, irq %d, "
901 "%d-%d\n", intsrc.mpc_irqtype, intsrc.mpc_irqflag & 3,
902 (intsrc.mpc_irqflag >> 2) & 3, intsrc.mpc_srcbus,
903 intsrc.mpc_srcbusirq, intsrc.mpc_dstapic,
904 intsrc.mpc_dstirq);
905
906 mp_irqs[mp_irq_entries] = intsrc;
907 if (++mp_irq_entries == MAX_IRQ_SOURCES)
908 panic("Max # of irq sources exceeded!\n");
909 }
910
911 return;
912 }
913
914 #define MAX_GSI_NUM 4096
915
916 int mp_register_gsi(u32 gsi, int edge_level, int active_high_low)
917 {
918 int ioapic = -1;
919 int ioapic_pin = 0;
920 int idx, bit = 0;
921 static int pci_irq = 16;
922 /*
923 * Mapping between Global System Interrupts, which
924 * represent all possible interrupts, to the IRQs
925 * assigned to actual devices.
926 */
927 static int gsi_to_irq[MAX_GSI_NUM];
928
929 if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC)
930 return gsi;
931
932 #ifdef CONFIG_ACPI_BUS
933 /* Don't set up the ACPI SCI because it's already set up */
934 if (acpi_fadt.sci_int == gsi)
935 return gsi;
936 #endif
937
938 ioapic = mp_find_ioapic(gsi);
939 if (ioapic < 0) {
940 printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
941 return gsi;
942 }
943
944 ioapic_pin = gsi - mp_ioapic_routing[ioapic].gsi_start;
945
946 /*
947 * Avoid pin reprogramming. PRTs typically include entries
948 * with redundant pin->gsi mappings (but unique PCI devices);
949 * we only program the IOAPIC on the first.
950 */
951 bit = ioapic_pin % 32;
952 idx = (ioapic_pin < 32) ? 0 : (ioapic_pin / 32);
953 if (idx > 3) {
954 printk(KERN_ERR "Invalid reference to IOAPIC pin "
955 "%d-%d\n", mp_ioapic_routing[ioapic].apic_id,
956 ioapic_pin);
957 return gsi;
958 }
959 if ((1<<bit) & mp_ioapic_routing[ioapic].pin_programmed[idx]) {
960 Dprintk(KERN_DEBUG "Pin %d-%d already programmed\n",
961 mp_ioapic_routing[ioapic].apic_id, ioapic_pin);
962 return gsi_to_irq[gsi];
963 }
964
965 mp_ioapic_routing[ioapic].pin_programmed[idx] |= (1<<bit);
966
967 if (edge_level) {
968 /*
969 * For PCI devices assign IRQs in order, avoiding gaps
970 * due to unused I/O APIC pins.
971 */
972 int irq = gsi;
973 if (gsi < MAX_GSI_NUM) {
974 if (gsi > 15)
975 gsi = pci_irq++;
976 #ifdef CONFIG_ACPI_BUS
977 /*
978 * Don't assign IRQ used by ACPI SCI
979 */
980 if (gsi == acpi_fadt.sci_int)
981 gsi = pci_irq++;
982 #endif
983 gsi_to_irq[irq] = gsi;
984 } else {
985 printk(KERN_ERR "GSI %u is too high\n", gsi);
986 return gsi;
987 }
988 }
989
990 io_apic_set_pci_routing(ioapic, ioapic_pin, gsi,
991 edge_level == ACPI_EDGE_SENSITIVE ? 0 : 1,
992 active_high_low == ACPI_ACTIVE_HIGH ? 0 : 1);
993 return gsi;
994 }
995
996 #endif /*CONFIG_X86_IO_APIC*/
997 #endif /*CONFIG_ACPI_BOOT*/