]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/x86/kernel/mpparse.c
83dfd6696c2a25e3ce09de6eb84992e082f0285b
[linux-2.6-omap-h63xx.git] / arch / x86 / 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  *      (c) 2008 Alexey Starikovskiy <astarikovskiy@suse.de>
8  */
9
10 #include <linux/mm.h>
11 #include <linux/init.h>
12 #include <linux/delay.h>
13 #include <linux/bootmem.h>
14 #include <linux/kernel_stat.h>
15 #include <linux/mc146818rtc.h>
16 #include <linux/bitops.h>
17 #include <linux/acpi.h>
18 #include <linux/module.h>
19
20 #include <asm/smp.h>
21 #include <asm/mtrr.h>
22 #include <asm/mpspec.h>
23 #include <asm/pgalloc.h>
24 #include <asm/io_apic.h>
25 #include <asm/proto.h>
26 #include <asm/acpi.h>
27 #include <asm/bios_ebda.h>
28
29 #include <mach_apic.h>
30 #ifdef CONFIG_X86_32
31 #include <mach_apicdef.h>
32 #include <mach_mpparse.h>
33 #endif
34
35 /*
36  * Various Linux-internal data structures created from the
37  * MP-table.
38  */
39 #if defined (CONFIG_MCA) || defined (CONFIG_EISA)
40 int mp_bus_id_to_type[MAX_MP_BUSSES];
41 #endif
42
43 DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES);
44
45 /*
46  * Checksum an MP configuration block.
47  */
48
49 static int __init mpf_checksum(unsigned char *mp, int len)
50 {
51         int sum = 0;
52
53         while (len--)
54                 sum += *mp++;
55
56         return sum & 0xFF;
57 }
58
59 #ifdef CONFIG_X86_NUMAQ
60 /*
61  * Have to match translation table entries to main table entries by counter
62  * hence the mpc_record variable .... can't see a less disgusting way of
63  * doing this ....
64  */
65
66 static int mpc_record;
67 static struct mpc_config_translation *translation_table[MAX_MPC_ENTRY]
68     __cpuinitdata;
69 #endif
70
71 static void __cpuinit MP_processor_info(struct mpc_config_processor *m)
72 {
73         int apicid;
74         char *bootup_cpu = "";
75
76         if (!(m->mpc_cpuflag & CPU_ENABLED)) {
77                 disabled_cpus++;
78                 return;
79         }
80 #ifdef CONFIG_X86_NUMAQ
81         apicid = mpc_apic_id(m, translation_table[mpc_record]);
82 #else
83         apicid = m->mpc_apicid;
84 #endif
85         if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
86                 bootup_cpu = " (Bootup-CPU)";
87                 boot_cpu_physical_apicid = m->mpc_apicid;
88         }
89
90         printk(KERN_INFO "Processor #%d%s\n", m->mpc_apicid, bootup_cpu);
91         generic_processor_info(apicid, m->mpc_apicver);
92 }
93
94 static void __init MP_bus_info(struct mpc_config_bus *m)
95 {
96         char str[7];
97         memcpy(str, m->mpc_bustype, 6);
98         str[6] = 0;
99
100 #ifdef CONFIG_X86_NUMAQ
101         mpc_oem_bus_info(m, str, translation_table[mpc_record]);
102 #else
103         printk(KERN_INFO "Bus #%d is %s\n", m->mpc_busid, str);
104 #endif
105
106 #if MAX_MP_BUSSES < 256
107         if (m->mpc_busid >= MAX_MP_BUSSES) {
108                 printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
109                        " is too large, max. supported is %d\n",
110                        m->mpc_busid, str, MAX_MP_BUSSES - 1);
111                 return;
112         }
113 #endif
114
115         if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
116                  set_bit(m->mpc_busid, mp_bus_not_pci);
117 #if defined(CONFIG_EISA) || defined (CONFIG_MCA)
118                 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA;
119 #endif
120         } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
121 #ifdef CONFIG_X86_NUMAQ
122                 mpc_oem_pci_bus(m, translation_table[mpc_record]);
123 #endif
124                 clear_bit(m->mpc_busid, mp_bus_not_pci);
125 #if defined(CONFIG_EISA) || defined (CONFIG_MCA)
126                 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI;
127         } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
128                 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA;
129         } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
130                 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_MCA;
131 #endif
132         } else
133                 printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
134 }
135
136 #ifdef CONFIG_X86_IO_APIC
137
138 static int bad_ioapic(unsigned long address)
139 {
140         if (nr_ioapics >= MAX_IO_APICS) {
141                 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
142                        "(found %d)\n", MAX_IO_APICS, nr_ioapics);
143                 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
144         }
145         if (!address) {
146                 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
147                        " found in table, skipping!\n");
148                 return 1;
149         }
150         return 0;
151 }
152
153 static void __init MP_ioapic_info(struct mpc_config_ioapic *m)
154 {
155         if (!(m->mpc_flags & MPC_APIC_USABLE))
156                 return;
157
158         printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
159                m->mpc_apicid, m->mpc_apicver, m->mpc_apicaddr);
160
161         if (bad_ioapic(m->mpc_apicaddr))
162                 return;
163
164         mp_ioapics[nr_ioapics].mp_apicaddr = m->mpc_apicaddr;
165         mp_ioapics[nr_ioapics].mp_apicid = m->mpc_apicid;
166         mp_ioapics[nr_ioapics].mp_type = m->mpc_type;
167         mp_ioapics[nr_ioapics].mp_apicver = m->mpc_apicver;
168         mp_ioapics[nr_ioapics].mp_flags = m->mpc_flags;
169         nr_ioapics++;
170 }
171
172 static void __init MP_intsrc_info(struct mpc_config_intsrc *m)
173 {
174         printk(KERN_INFO "Int: type %d, pol %d, trig %d, bus %02x,"
175                 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
176                 m->mpc_irqtype, m->mpc_irqflag & 3,
177                 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
178                 m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
179         mp_irqs[mp_irq_entries].mp_dstapic = m->mpc_dstapic;
180         mp_irqs[mp_irq_entries].mp_type = m->mpc_type;
181         mp_irqs[mp_irq_entries].mp_irqtype = m->mpc_irqtype;
182         mp_irqs[mp_irq_entries].mp_irqflag = m->mpc_irqflag;
183         mp_irqs[mp_irq_entries].mp_srcbus = m->mpc_srcbus;
184         mp_irqs[mp_irq_entries].mp_srcbusirq = m->mpc_srcbusirq;
185         mp_irqs[mp_irq_entries].mp_dstirq = m->mpc_dstirq;
186         if (++mp_irq_entries == MAX_IRQ_SOURCES)
187                 panic("Max # of irq sources exceeded!!\n");
188 }
189
190 #endif
191
192 static void __init MP_lintsrc_info(struct mpc_config_lintsrc *m)
193 {
194         printk(KERN_INFO "Lint: type %d, pol %d, trig %d, bus %02x,"
195                 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
196                 m->mpc_irqtype, m->mpc_irqflag & 3,
197                 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbusid,
198                 m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint);
199 }
200
201 #ifdef CONFIG_X86_NUMAQ
202 static void __init MP_translation_info(struct mpc_config_translation *m)
203 {
204         printk(KERN_INFO
205                "Translation: record %d, type %d, quad %d, global %d, local %d\n",
206                mpc_record, m->trans_type, m->trans_quad, m->trans_global,
207                m->trans_local);
208
209         if (mpc_record >= MAX_MPC_ENTRY)
210                 printk(KERN_ERR "MAX_MPC_ENTRY exceeded!\n");
211         else
212                 translation_table[mpc_record] = m;      /* stash this for later */
213         if (m->trans_quad < MAX_NUMNODES && !node_online(m->trans_quad))
214                 node_set_online(m->trans_quad);
215 }
216
217 /*
218  * Read/parse the MPC oem tables
219  */
220
221 static void __init smp_read_mpc_oem(struct mp_config_oemtable *oemtable,
222                                     unsigned short oemsize)
223 {
224         int count = sizeof(*oemtable);  /* the header size */
225         unsigned char *oemptr = ((unsigned char *)oemtable) + count;
226
227         mpc_record = 0;
228         printk(KERN_INFO "Found an OEM MPC table at %8p - parsing it ... \n",
229                oemtable);
230         if (memcmp(oemtable->oem_signature, MPC_OEM_SIGNATURE, 4)) {
231                 printk(KERN_WARNING
232                        "SMP mpc oemtable: bad signature [%c%c%c%c]!\n",
233                        oemtable->oem_signature[0], oemtable->oem_signature[1],
234                        oemtable->oem_signature[2], oemtable->oem_signature[3]);
235                 return;
236         }
237         if (mpf_checksum((unsigned char *)oemtable, oemtable->oem_length)) {
238                 printk(KERN_WARNING "SMP oem mptable: checksum error!\n");
239                 return;
240         }
241         while (count < oemtable->oem_length) {
242                 switch (*oemptr) {
243                 case MP_TRANSLATION:
244                         {
245                                 struct mpc_config_translation *m =
246                                     (struct mpc_config_translation *)oemptr;
247                                 MP_translation_info(m);
248                                 oemptr += sizeof(*m);
249                                 count += sizeof(*m);
250                                 ++mpc_record;
251                                 break;
252                         }
253                 default:
254                         {
255                                 printk(KERN_WARNING
256                                        "Unrecognised OEM table entry type! - %d\n",
257                                        (int)*oemptr);
258                                 return;
259                         }
260                 }
261         }
262 }
263
264 static inline void mps_oem_check(struct mp_config_table *mpc, char *oem,
265                                  char *productid)
266 {
267         if (strncmp(oem, "IBM NUMA", 8))
268                 printk("Warning!  May not be a NUMA-Q system!\n");
269         if (mpc->mpc_oemptr)
270                 smp_read_mpc_oem((struct mp_config_oemtable *)mpc->mpc_oemptr,
271                                  mpc->mpc_oemsize);
272 }
273 #endif /* CONFIG_X86_NUMAQ */
274
275 /*
276  * Read/parse the MPC
277  */
278
279 static int __init smp_read_mpc(struct mp_config_table *mpc, unsigned early)
280 {
281         char str[16];
282         char oem[10];
283         int count = sizeof(*mpc);
284         unsigned char *mpt = ((unsigned char *)mpc) + count;
285
286         if (memcmp(mpc->mpc_signature, MPC_SIGNATURE, 4)) {
287                 printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
288                        mpc->mpc_signature[0], mpc->mpc_signature[1],
289                        mpc->mpc_signature[2], mpc->mpc_signature[3]);
290                 return 0;
291         }
292         if (mpf_checksum((unsigned char *)mpc, mpc->mpc_length)) {
293                 printk(KERN_ERR "MPTABLE: checksum error!\n");
294                 return 0;
295         }
296         if (mpc->mpc_spec != 0x01 && mpc->mpc_spec != 0x04) {
297                 printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
298                        mpc->mpc_spec);
299                 return 0;
300         }
301         if (!mpc->mpc_lapic) {
302                 printk(KERN_ERR "MPTABLE: null local APIC address!\n");
303                 return 0;
304         }
305         memcpy(oem, mpc->mpc_oem, 8);
306         oem[8] = 0;
307         printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
308
309         memcpy(str, mpc->mpc_productid, 12);
310         str[12] = 0;
311
312 #ifdef CONFIG_X86_32
313         mps_oem_check(mpc, oem, str);
314 #endif
315         printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
316
317         printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->mpc_lapic);
318
319         /* save the local APIC address, it might be non-default */
320         if (!acpi_lapic)
321                 mp_lapic_addr = mpc->mpc_lapic;
322
323         if (early)
324                 return 1;
325
326         /*
327          *      Now process the configuration blocks.
328          */
329 #ifdef CONFIG_X86_NUMAQ
330         mpc_record = 0;
331 #endif
332         while (count < mpc->mpc_length) {
333                 switch (*mpt) {
334                 case MP_PROCESSOR:
335                         {
336                                 struct mpc_config_processor *m =
337                                     (struct mpc_config_processor *)mpt;
338                                 /* ACPI may have already provided this data */
339                                 if (!acpi_lapic)
340                                         MP_processor_info(m);
341                                 mpt += sizeof(*m);
342                                 count += sizeof(*m);
343                                 break;
344                         }
345                 case MP_BUS:
346                         {
347                                 struct mpc_config_bus *m =
348                                     (struct mpc_config_bus *)mpt;
349                                 MP_bus_info(m);
350                                 mpt += sizeof(*m);
351                                 count += sizeof(*m);
352                                 break;
353                         }
354                 case MP_IOAPIC:
355                         {
356 #ifdef CONFIG_X86_IO_APIC
357                                 struct mpc_config_ioapic *m =
358                                     (struct mpc_config_ioapic *)mpt;
359                                 MP_ioapic_info(m);
360 #endif
361                                 mpt += sizeof(struct mpc_config_ioapic);
362                                 count += sizeof(struct mpc_config_ioapic);
363                                 break;
364                         }
365                 case MP_INTSRC:
366                         {
367 #ifdef CONFIG_X86_IO_APIC
368                                 struct mpc_config_intsrc *m =
369                                     (struct mpc_config_intsrc *)mpt;
370
371                                 MP_intsrc_info(m);
372 #endif
373                                 mpt += sizeof(struct mpc_config_intsrc);
374                                 count += sizeof(struct mpc_config_intsrc);
375                                 break;
376                         }
377                 case MP_LINTSRC:
378                         {
379                                 struct mpc_config_lintsrc *m =
380                                     (struct mpc_config_lintsrc *)mpt;
381                                 MP_lintsrc_info(m);
382                                 mpt += sizeof(*m);
383                                 count += sizeof(*m);
384                                 break;
385                         }
386                 default:
387                         /* wrong mptable */
388                         printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
389                         printk(KERN_ERR "type %x\n", *mpt);
390                         print_hex_dump(KERN_ERR, "  ", DUMP_PREFIX_ADDRESS, 16,
391                                         1, mpc, mpc->mpc_length, 1);
392                         count = mpc->mpc_length;
393                         break;
394                 }
395 #ifdef CONFIG_X86_NUMAQ
396                 ++mpc_record;
397 #endif
398         }
399         setup_apic_routing();
400         if (!num_processors)
401                 printk(KERN_ERR "MPTABLE: no processors registered!\n");
402         return num_processors;
403 }
404
405 #ifdef CONFIG_X86_IO_APIC
406
407 static int __init ELCR_trigger(unsigned int irq)
408 {
409         unsigned int port;
410
411         port = 0x4d0 + (irq >> 3);
412         return (inb(port) >> (irq & 7)) & 1;
413 }
414
415 static void __init construct_default_ioirq_mptable(int mpc_default_type)
416 {
417         struct mpc_config_intsrc intsrc;
418         int i;
419         int ELCR_fallback = 0;
420
421         intsrc.mpc_type = MP_INTSRC;
422         intsrc.mpc_irqflag = 0; /* conforming */
423         intsrc.mpc_srcbus = 0;
424         intsrc.mpc_dstapic = mp_ioapics[0].mp_apicid;
425
426         intsrc.mpc_irqtype = mp_INT;
427
428         /*
429          *  If true, we have an ISA/PCI system with no IRQ entries
430          *  in the MP table. To prevent the PCI interrupts from being set up
431          *  incorrectly, we try to use the ELCR. The sanity check to see if
432          *  there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
433          *  never be level sensitive, so we simply see if the ELCR agrees.
434          *  If it does, we assume it's valid.
435          */
436         if (mpc_default_type == 5) {
437                 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
438                        "falling back to ELCR\n");
439
440                 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
441                     ELCR_trigger(13))
442                         printk(KERN_ERR "ELCR contains invalid data... "
443                                "not using ELCR\n");
444                 else {
445                         printk(KERN_INFO
446                                "Using ELCR to identify PCI interrupts\n");
447                         ELCR_fallback = 1;
448                 }
449         }
450
451         for (i = 0; i < 16; i++) {
452                 switch (mpc_default_type) {
453                 case 2:
454                         if (i == 0 || i == 13)
455                                 continue;       /* IRQ0 & IRQ13 not connected */
456                         /* fall through */
457                 default:
458                         if (i == 2)
459                                 continue;       /* IRQ2 is never connected */
460                 }
461
462                 if (ELCR_fallback) {
463                         /*
464                          *  If the ELCR indicates a level-sensitive interrupt, we
465                          *  copy that information over to the MP table in the
466                          *  irqflag field (level sensitive, active high polarity).
467                          */
468                         if (ELCR_trigger(i))
469                                 intsrc.mpc_irqflag = 13;
470                         else
471                                 intsrc.mpc_irqflag = 0;
472                 }
473
474                 intsrc.mpc_srcbusirq = i;
475                 intsrc.mpc_dstirq = i ? i : 2;  /* IRQ0 to INTIN2 */
476                 MP_intsrc_info(&intsrc);
477         }
478
479         intsrc.mpc_irqtype = mp_ExtINT;
480         intsrc.mpc_srcbusirq = 0;
481         intsrc.mpc_dstirq = 0;  /* 8259A to INTIN0 */
482         MP_intsrc_info(&intsrc);
483 }
484
485 #endif
486
487 static inline void __init construct_default_ISA_mptable(int mpc_default_type)
488 {
489         struct mpc_config_processor processor;
490         struct mpc_config_bus bus;
491 #ifdef CONFIG_X86_IO_APIC
492         struct mpc_config_ioapic ioapic;
493 #endif
494         struct mpc_config_lintsrc lintsrc;
495         int linttypes[2] = { mp_ExtINT, mp_NMI };
496         int i;
497
498         /*
499          * local APIC has default address
500          */
501         mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
502
503         /*
504          * 2 CPUs, numbered 0 & 1.
505          */
506         processor.mpc_type = MP_PROCESSOR;
507         /* Either an integrated APIC or a discrete 82489DX. */
508         processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
509         processor.mpc_cpuflag = CPU_ENABLED;
510         processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
511             (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
512         processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
513         processor.mpc_reserved[0] = 0;
514         processor.mpc_reserved[1] = 0;
515         for (i = 0; i < 2; i++) {
516                 processor.mpc_apicid = i;
517                 MP_processor_info(&processor);
518         }
519
520         bus.mpc_type = MP_BUS;
521         bus.mpc_busid = 0;
522         switch (mpc_default_type) {
523         default:
524                 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
525                        mpc_default_type);
526                 /* fall through */
527         case 1:
528         case 5:
529                 memcpy(bus.mpc_bustype, "ISA   ", 6);
530                 break;
531         case 2:
532         case 6:
533         case 3:
534                 memcpy(bus.mpc_bustype, "EISA  ", 6);
535                 break;
536         case 4:
537         case 7:
538                 memcpy(bus.mpc_bustype, "MCA   ", 6);
539         }
540         MP_bus_info(&bus);
541         if (mpc_default_type > 4) {
542                 bus.mpc_busid = 1;
543                 memcpy(bus.mpc_bustype, "PCI   ", 6);
544                 MP_bus_info(&bus);
545         }
546
547 #ifdef CONFIG_X86_IO_APIC
548         ioapic.mpc_type = MP_IOAPIC;
549         ioapic.mpc_apicid = 2;
550         ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
551         ioapic.mpc_flags = MPC_APIC_USABLE;
552         ioapic.mpc_apicaddr = 0xFEC00000;
553         MP_ioapic_info(&ioapic);
554
555         /*
556          * We set up most of the low 16 IO-APIC pins according to MPS rules.
557          */
558         construct_default_ioirq_mptable(mpc_default_type);
559 #endif
560         lintsrc.mpc_type = MP_LINTSRC;
561         lintsrc.mpc_irqflag = 0;        /* conforming */
562         lintsrc.mpc_srcbusid = 0;
563         lintsrc.mpc_srcbusirq = 0;
564         lintsrc.mpc_destapic = MP_APIC_ALL;
565         for (i = 0; i < 2; i++) {
566                 lintsrc.mpc_irqtype = linttypes[i];
567                 lintsrc.mpc_destapiclint = i;
568                 MP_lintsrc_info(&lintsrc);
569         }
570 }
571
572 static struct intel_mp_floating *mpf_found;
573
574 /*
575  * Scan the memory blocks for an SMP configuration block.
576  */
577 static void __init __get_smp_config(unsigned early)
578 {
579         struct intel_mp_floating *mpf = mpf_found;
580
581         if (acpi_lapic && early)
582                 return;
583         /*
584          * ACPI supports both logical (e.g. Hyper-Threading) and physical
585          * processors, where MPS only supports physical.
586          */
587         if (acpi_lapic && acpi_ioapic) {
588                 printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
589                        "information\n");
590                 return;
591         } else if (acpi_lapic)
592                 printk(KERN_INFO "Using ACPI for processor (LAPIC) "
593                        "configuration information\n");
594
595         printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
596                mpf->mpf_specification);
597 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
598         if (mpf->mpf_feature2 & (1 << 7)) {
599                 printk(KERN_INFO "    IMCR and PIC compatibility mode.\n");
600                 pic_mode = 1;
601         } else {
602                 printk(KERN_INFO "    Virtual Wire compatibility mode.\n");
603                 pic_mode = 0;
604         }
605 #endif
606         /*
607          * Now see if we need to read further.
608          */
609         if (mpf->mpf_feature1 != 0) {
610                 if (early) {
611                         /*
612                          * local APIC has default address
613                          */
614                         mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
615                         return;
616                 }
617
618                 printk(KERN_INFO "Default MP configuration #%d\n",
619                        mpf->mpf_feature1);
620                 construct_default_ISA_mptable(mpf->mpf_feature1);
621
622         } else if (mpf->mpf_physptr) {
623
624                 /*
625                  * Read the physical hardware table.  Anything here will
626                  * override the defaults.
627                  */
628                 if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr), early)) {
629 #ifdef CONFIG_X86_LOCAL_APIC
630                         smp_found_config = 0;
631 #endif
632                         printk(KERN_ERR
633                                "BIOS bug, MP table errors detected!...\n");
634                         printk(KERN_ERR "... disabling SMP support. "
635                                "(tell your hw vendor)\n");
636                         return;
637                 }
638
639                 if (early)
640                         return;
641 #ifdef CONFIG_X86_IO_APIC
642                 /*
643                  * If there are no explicit MP IRQ entries, then we are
644                  * broken.  We set up most of the low 16 IO-APIC pins to
645                  * ISA defaults and hope it will work.
646                  */
647                 if (!mp_irq_entries) {
648                         struct mpc_config_bus bus;
649
650                         printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
651                                "using default mptable. "
652                                "(tell your hw vendor)\n");
653
654                         bus.mpc_type = MP_BUS;
655                         bus.mpc_busid = 0;
656                         memcpy(bus.mpc_bustype, "ISA   ", 6);
657                         MP_bus_info(&bus);
658
659                         construct_default_ioirq_mptable(0);
660                 }
661 #endif
662         } else
663                 BUG();
664
665         if (!early)
666                 printk(KERN_INFO "Processors: %d\n", num_processors);
667         /*
668          * Only use the first configuration found.
669          */
670 }
671
672 void __init early_get_smp_config(void)
673 {
674         __get_smp_config(1);
675 }
676
677 void __init get_smp_config(void)
678 {
679         __get_smp_config(0);
680 }
681
682 static int __init smp_scan_config(unsigned long base, unsigned long length,
683                                   unsigned reserve)
684 {
685         unsigned int *bp = phys_to_virt(base);
686         struct intel_mp_floating *mpf;
687
688         printk(KERN_DEBUG "Scan SMP from %p for %ld bytes.\n", bp, length);
689         BUILD_BUG_ON(sizeof(*mpf) != 16);
690
691         while (length > 0) {
692                 mpf = (struct intel_mp_floating *)bp;
693                 if ((*bp == SMP_MAGIC_IDENT) &&
694                     (mpf->mpf_length == 1) &&
695                     !mpf_checksum((unsigned char *)bp, 16) &&
696                     ((mpf->mpf_specification == 1)
697                      || (mpf->mpf_specification == 4))) {
698 #ifdef CONFIG_X86_LOCAL_APIC
699                         smp_found_config = 1;
700 #endif
701                         mpf_found = mpf;
702 #ifdef CONFIG_X86_32
703                         printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
704                                mpf, virt_to_phys(mpf));
705                         reserve_bootmem(virt_to_phys(mpf), PAGE_SIZE,
706                                         BOOTMEM_DEFAULT);
707                         if (mpf->mpf_physptr) {
708                                 /*
709                                  * We cannot access to MPC table to compute
710                                  * table size yet, as only few megabytes from
711                                  * the bottom is mapped now.
712                                  * PC-9800's MPC table places on the very last
713                                  * of physical memory; so that simply reserving
714                                  * PAGE_SIZE from mpg->mpf_physptr yields BUG()
715                                  * in reserve_bootmem.
716                                  */
717                                 unsigned long size = PAGE_SIZE;
718                                 unsigned long end = max_low_pfn * PAGE_SIZE;
719                                 if (mpf->mpf_physptr + size > end)
720                                         size = end - mpf->mpf_physptr;
721                                 reserve_bootmem(mpf->mpf_physptr, size,
722                                                 BOOTMEM_DEFAULT);
723                         }
724
725 #else
726                         if (!reserve)
727                                 return 1;
728
729                         reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE);
730                         if (mpf->mpf_physptr)
731                                 reserve_bootmem_generic(mpf->mpf_physptr,
732                                                         PAGE_SIZE);
733 #endif
734                 return 1;
735                 }
736                 bp += 4;
737                 length -= 16;
738         }
739         return 0;
740 }
741
742 static void __init __find_smp_config(unsigned reserve)
743 {
744         unsigned int address;
745
746         /*
747          * FIXME: Linux assumes you have 640K of base ram..
748          * this continues the error...
749          *
750          * 1) Scan the bottom 1K for a signature
751          * 2) Scan the top 1K of base RAM
752          * 3) Scan the 64K of bios
753          */
754         if (smp_scan_config(0x0, 0x400, reserve) ||
755             smp_scan_config(639 * 0x400, 0x400, reserve) ||
756             smp_scan_config(0xF0000, 0x10000, reserve))
757                 return;
758         /*
759          * If it is an SMP machine we should know now, unless the
760          * configuration is in an EISA/MCA bus machine with an
761          * extended bios data area.
762          *
763          * there is a real-mode segmented pointer pointing to the
764          * 4K EBDA area at 0x40E, calculate and scan it here.
765          *
766          * NOTE! There are Linux loaders that will corrupt the EBDA
767          * area, and as such this kind of SMP config may be less
768          * trustworthy, simply because the SMP table may have been
769          * stomped on during early boot. These loaders are buggy and
770          * should be fixed.
771          *
772          * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
773          */
774
775         address = get_bios_ebda();
776         if (address)
777                 smp_scan_config(address, 0x400, reserve);
778 }
779
780 void __init early_find_smp_config(void)
781 {
782         __find_smp_config(0);
783 }
784
785 void __init find_smp_config(void)
786 {
787         __find_smp_config(1);
788 }