x86: introduce max_physical_apicid for bigsmp switching
[deliverable/linux.git] / arch / x86 / kernel / mpparse.c
CommitLineData
1da177e4 1/*
11113f84 2 * Intel Multiprocessor Specification 1.1 and 1.4
1da177e4
LT
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>
85bdddec 7 * (c) 2008 Alexey Starikovskiy <astarikovskiy@suse.de>
1da177e4
LT
8 */
9
10#include <linux/mm.h>
1da177e4 11#include <linux/init.h>
1da177e4 12#include <linux/delay.h>
1da177e4 13#include <linux/bootmem.h>
1da177e4
LT
14#include <linux/kernel_stat.h>
15#include <linux/mc146818rtc.h>
16#include <linux/bitops.h>
85bdddec
AS
17#include <linux/acpi.h>
18#include <linux/module.h>
1da177e4
LT
19
20#include <asm/smp.h>
1da177e4
LT
21#include <asm/mtrr.h>
22#include <asm/mpspec.h>
85bdddec 23#include <asm/pgalloc.h>
1da177e4 24#include <asm/io_apic.h>
85bdddec
AS
25#include <asm/proto.h>
26#include <asm/acpi.h>
ce3fe6b2 27#include <asm/bios_ebda.h>
2944e16b
YL
28#include <asm/e820.h>
29#include <asm/trampoline.h>
1da177e4
LT
30
31#include <mach_apic.h>
85bdddec 32#ifdef CONFIG_X86_32
874c4fe3 33#include <mach_apicdef.h>
1da177e4 34#include <mach_mpparse.h>
85bdddec 35#endif
1da177e4 36
1da177e4
LT
37/*
38 * Checksum an MP configuration block.
39 */
40
41static int __init mpf_checksum(unsigned char *mp, int len)
42{
43 int sum = 0;
44
45 while (len--)
46 sum += *mp++;
47
48 return sum & 0xFF;
49}
50
86420506 51#ifdef CONFIG_X86_NUMAQ
1da177e4
LT
52/*
53 * Have to match translation table entries to main table entries by counter
54 * hence the mpc_record variable .... can't see a less disgusting way of
55 * doing this ....
56 */
57
4ef81297
AS
58static int mpc_record;
59static struct mpc_config_translation *translation_table[MAX_MPC_ENTRY]
60 __cpuinitdata;
86420506 61#endif
1da177e4 62
c853c676
AS
63static void __cpuinit MP_processor_info(struct mpc_config_processor *m)
64{
65 int apicid;
746f2244 66 char *bootup_cpu = "";
c853c676 67
7b1292e2
GC
68 if (!(m->mpc_cpuflag & CPU_ENABLED)) {
69 disabled_cpus++;
1da177e4 70 return;
7b1292e2 71 }
4655c7de 72#ifdef CONFIG_X86_NUMAQ
ab530e1f
YL
73 if (found_numaq)
74 apicid = mpc_apic_id(m, translation_table[mpc_record]);
75 else
76 apicid = m->mpc_apicid;
4655c7de 77#else
4655c7de
AS
78 apicid = m->mpc_apicid;
79#endif
1da177e4 80 if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
746f2244 81 bootup_cpu = " (Bootup-CPU)";
1da177e4 82 boot_cpu_physical_apicid = m->mpc_apicid;
1da177e4
LT
83 }
84
746f2244 85 printk(KERN_INFO "Processor #%d%s\n", m->mpc_apicid, bootup_cpu);
c853c676 86 generic_processor_info(apicid, m->mpc_apicver);
1da177e4
LT
87}
88
85cc35fa 89#ifdef CONFIG_X86_IO_APIC
4ef81297 90static void __init MP_bus_info(struct mpc_config_bus *m)
1da177e4
LT
91{
92 char str[7];
1da177e4
LT
93 memcpy(str, m->mpc_bustype, 6);
94 str[6] = 0;
95
0ec153af 96#ifdef CONFIG_X86_NUMAQ
ab530e1f
YL
97 if (found_numaq)
98 mpc_oem_bus_info(m, str, translation_table[mpc_record]);
0ec153af 99#else
11a62a05 100 printk(KERN_INFO "Bus #%d is %s\n", m->mpc_busid, str);
0ec153af 101#endif
1da177e4 102
5e4edbb7 103#if MAX_MP_BUSSES < 256
c0ec31ad
RD
104 if (m->mpc_busid >= MAX_MP_BUSSES) {
105 printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
4ef81297
AS
106 " is too large, max. supported is %d\n",
107 m->mpc_busid, str, MAX_MP_BUSSES - 1);
c0ec31ad
RD
108 return;
109 }
5e4edbb7 110#endif
c0ec31ad 111
f8924e77
AS
112 if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
113 set_bit(m->mpc_busid, mp_bus_not_pci);
114#if defined(CONFIG_EISA) || defined (CONFIG_MCA)
115 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA;
116#endif
117 } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
d285e338 118#ifdef CONFIG_X86_NUMAQ
ab530e1f
YL
119 if (found_numaq)
120 mpc_oem_pci_bus(m, translation_table[mpc_record]);
d285e338 121#endif
a6333c3c 122 clear_bit(m->mpc_busid, mp_bus_not_pci);
c0a282c2
AS
123#if defined(CONFIG_EISA) || defined (CONFIG_MCA)
124 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI;
4ef81297 125 } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
9e0a2de2 126 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA;
4ef81297 127 } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
1da177e4 128 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_MCA;
c0a282c2 129#endif
f8924e77
AS
130 } else
131 printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
1da177e4 132}
85cc35fa 133#endif
1da177e4 134
61048c63
AS
135#ifdef CONFIG_X86_IO_APIC
136
857033a6
AS
137static int bad_ioapic(unsigned long address)
138{
139 if (nr_ioapics >= MAX_IO_APICS) {
140 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
141 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
142 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
143 }
144 if (!address) {
145 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
146 " found in table, skipping!\n");
147 return 1;
148 }
149 return 0;
150}
151
4ef81297 152static void __init MP_ioapic_info(struct mpc_config_ioapic *m)
1da177e4
LT
153{
154 if (!(m->mpc_flags & MPC_APIC_USABLE))
155 return;
156
64883ab0 157 printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
4ef81297 158 m->mpc_apicid, m->mpc_apicver, m->mpc_apicaddr);
857033a6
AS
159
160 if (bad_ioapic(m->mpc_apicaddr))
1da177e4 161 return;
857033a6 162
ec2cd0a2
AS
163 mp_ioapics[nr_ioapics].mp_apicaddr = m->mpc_apicaddr;
164 mp_ioapics[nr_ioapics].mp_apicid = m->mpc_apicid;
165 mp_ioapics[nr_ioapics].mp_type = m->mpc_type;
166 mp_ioapics[nr_ioapics].mp_apicver = m->mpc_apicver;
167 mp_ioapics[nr_ioapics].mp_flags = m->mpc_flags;
1da177e4
LT
168 nr_ioapics++;
169}
170
2944e16b 171static void print_MP_intsrc_info(struct mpc_config_intsrc *m)
1da177e4 172{
2944e16b 173 printk(KERN_CONT "Int: type %d, pol %d, trig %d, bus %02x,"
1da177e4 174 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
4ef81297
AS
175 m->mpc_irqtype, m->mpc_irqflag & 3,
176 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
177 m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
2944e16b
YL
178}
179
180static void __init print_mp_irq_info(struct mp_config_intsrc *mp_irq)
181{
182 printk(KERN_CONT "Int: type %d, pol %d, trig %d, bus %02x,"
183 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
184 mp_irq->mp_irqtype, mp_irq->mp_irqflag & 3,
185 (mp_irq->mp_irqflag >> 2) & 3, mp_irq->mp_srcbus,
186 mp_irq->mp_srcbusirq, mp_irq->mp_dstapic, mp_irq->mp_dstirq);
187}
188
189static void assign_to_mp_irq(struct mpc_config_intsrc *m,
190 struct mp_config_intsrc *mp_irq)
191{
192 mp_irq->mp_dstapic = m->mpc_dstapic;
193 mp_irq->mp_type = m->mpc_type;
194 mp_irq->mp_irqtype = m->mpc_irqtype;
195 mp_irq->mp_irqflag = m->mpc_irqflag;
196 mp_irq->mp_srcbus = m->mpc_srcbus;
197 mp_irq->mp_srcbusirq = m->mpc_srcbusirq;
198 mp_irq->mp_dstirq = m->mpc_dstirq;
199}
200
201static void __init assign_to_mpc_intsrc(struct mp_config_intsrc *mp_irq,
202 struct mpc_config_intsrc *m)
203{
204 m->mpc_dstapic = mp_irq->mp_dstapic;
205 m->mpc_type = mp_irq->mp_type;
206 m->mpc_irqtype = mp_irq->mp_irqtype;
207 m->mpc_irqflag = mp_irq->mp_irqflag;
208 m->mpc_srcbus = mp_irq->mp_srcbus;
209 m->mpc_srcbusirq = mp_irq->mp_srcbusirq;
210 m->mpc_dstirq = mp_irq->mp_dstirq;
211}
212
213static int mp_irq_mpc_intsrc_cmp(struct mp_config_intsrc *mp_irq,
214 struct mpc_config_intsrc *m)
215{
216 if (mp_irq->mp_dstapic != m->mpc_dstapic)
217 return 1;
218 if (mp_irq->mp_type != m->mpc_type)
219 return 2;
220 if (mp_irq->mp_irqtype != m->mpc_irqtype)
221 return 3;
222 if (mp_irq->mp_irqflag != m->mpc_irqflag)
223 return 4;
224 if (mp_irq->mp_srcbus != m->mpc_srcbus)
225 return 5;
226 if (mp_irq->mp_srcbusirq != m->mpc_srcbusirq)
227 return 6;
228 if (mp_irq->mp_dstirq != m->mpc_dstirq)
229 return 7;
230
231 return 0;
232}
233
234void MP_intsrc_info(struct mpc_config_intsrc *m)
235{
236 int i;
237
238 print_MP_intsrc_info(m);
239
240 for (i = 0; i < mp_irq_entries; i++) {
241 if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m))
242 return;
243 }
244
245 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
1da177e4
LT
246 if (++mp_irq_entries == MAX_IRQ_SOURCES)
247 panic("Max # of irq sources exceeded!!\n");
248}
249
61048c63
AS
250#endif
251
4ef81297 252static void __init MP_lintsrc_info(struct mpc_config_lintsrc *m)
1da177e4 253{
11a62a05 254 printk(KERN_INFO "Lint: type %d, pol %d, trig %d, bus %02x,"
1da177e4 255 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
4ef81297
AS
256 m->mpc_irqtype, m->mpc_irqflag & 3,
257 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbusid,
258 m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint);
1da177e4
LT
259}
260
261#ifdef CONFIG_X86_NUMAQ
4ef81297 262static void __init MP_translation_info(struct mpc_config_translation *m)
1da177e4 263{
4ef81297
AS
264 printk(KERN_INFO
265 "Translation: record %d, type %d, quad %d, global %d, local %d\n",
266 mpc_record, m->trans_type, m->trans_quad, m->trans_global,
267 m->trans_local);
1da177e4 268
4ef81297 269 if (mpc_record >= MAX_MPC_ENTRY)
1da177e4
LT
270 printk(KERN_ERR "MAX_MPC_ENTRY exceeded!\n");
271 else
4ef81297 272 translation_table[mpc_record] = m; /* stash this for later */
1da177e4
LT
273 if (m->trans_quad < MAX_NUMNODES && !node_online(m->trans_quad))
274 node_set_online(m->trans_quad);
275}
276
277/*
278 * Read/parse the MPC oem tables
279 */
280
4ef81297
AS
281static void __init smp_read_mpc_oem(struct mp_config_oemtable *oemtable,
282 unsigned short oemsize)
1da177e4 283{
4ef81297
AS
284 int count = sizeof(*oemtable); /* the header size */
285 unsigned char *oemptr = ((unsigned char *)oemtable) + count;
286
1da177e4 287 mpc_record = 0;
4ef81297
AS
288 printk(KERN_INFO "Found an OEM MPC table at %8p - parsing it ... \n",
289 oemtable);
290 if (memcmp(oemtable->oem_signature, MPC_OEM_SIGNATURE, 4)) {
291 printk(KERN_WARNING
292 "SMP mpc oemtable: bad signature [%c%c%c%c]!\n",
293 oemtable->oem_signature[0], oemtable->oem_signature[1],
294 oemtable->oem_signature[2], oemtable->oem_signature[3]);
1da177e4
LT
295 return;
296 }
4ef81297 297 if (mpf_checksum((unsigned char *)oemtable, oemtable->oem_length)) {
1da177e4
LT
298 printk(KERN_WARNING "SMP oem mptable: checksum error!\n");
299 return;
300 }
301 while (count < oemtable->oem_length) {
302 switch (*oemptr) {
4ef81297 303 case MP_TRANSLATION:
1da177e4 304 {
4ef81297
AS
305 struct mpc_config_translation *m =
306 (struct mpc_config_translation *)oemptr;
1da177e4
LT
307 MP_translation_info(m);
308 oemptr += sizeof(*m);
309 count += sizeof(*m);
310 ++mpc_record;
311 break;
312 }
4ef81297 313 default:
1da177e4 314 {
4ef81297
AS
315 printk(KERN_WARNING
316 "Unrecognised OEM table entry type! - %d\n",
317 (int)*oemptr);
1da177e4
LT
318 return;
319 }
320 }
4ef81297 321 }
1da177e4
LT
322}
323
324static inline void mps_oem_check(struct mp_config_table *mpc, char *oem,
4ef81297 325 char *productid)
1da177e4
LT
326{
327 if (strncmp(oem, "IBM NUMA", 8))
328 printk("Warning! May not be a NUMA-Q system!\n");
ab530e1f
YL
329 else
330 found_numaq = 1;
331
1da177e4 332 if (mpc->mpc_oemptr)
4ef81297
AS
333 smp_read_mpc_oem((struct mp_config_oemtable *)mpc->mpc_oemptr,
334 mpc->mpc_oemsize);
1da177e4 335}
4ef81297 336#endif /* CONFIG_X86_NUMAQ */
1da177e4
LT
337
338/*
339 * Read/parse the MPC
340 */
341
2944e16b
YL
342static int __init smp_check_mpc(struct mp_config_table *mpc, char *oem,
343 char *str)
1da177e4 344{
1da177e4 345
4ef81297 346 if (memcmp(mpc->mpc_signature, MPC_SIGNATURE, 4)) {
e950bea8
AS
347 printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
348 mpc->mpc_signature[0], mpc->mpc_signature[1],
349 mpc->mpc_signature[2], mpc->mpc_signature[3]);
1da177e4
LT
350 return 0;
351 }
4ef81297 352 if (mpf_checksum((unsigned char *)mpc, mpc->mpc_length)) {
e950bea8 353 printk(KERN_ERR "MPTABLE: checksum error!\n");
1da177e4
LT
354 return 0;
355 }
4ef81297 356 if (mpc->mpc_spec != 0x01 && mpc->mpc_spec != 0x04) {
e950bea8 357 printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
4ef81297 358 mpc->mpc_spec);
1da177e4
LT
359 return 0;
360 }
361 if (!mpc->mpc_lapic) {
e950bea8 362 printk(KERN_ERR "MPTABLE: null local APIC address!\n");
1da177e4
LT
363 return 0;
364 }
4ef81297
AS
365 memcpy(oem, mpc->mpc_oem, 8);
366 oem[8] = 0;
11a62a05 367 printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
1da177e4 368
4ef81297
AS
369 memcpy(str, mpc->mpc_productid, 12);
370 str[12] = 0;
1da177e4 371
11a62a05 372 printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
1da177e4 373
e950bea8 374 printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->mpc_lapic);
1da177e4 375
2944e16b
YL
376 return 1;
377}
378
379static int __init smp_read_mpc(struct mp_config_table *mpc, unsigned early)
380{
381 char str[16];
382 char oem[10];
383
384 int count = sizeof(*mpc);
385 unsigned char *mpt = ((unsigned char *)mpc) + count;
386
387 if (!smp_check_mpc(mpc, oem, str))
388 return 0;
389
390#ifdef CONFIG_X86_32
391 mps_oem_check(mpc, oem, str);
392#endif
393
e950bea8 394 /* save the local APIC address, it might be non-default */
1da177e4
LT
395 if (!acpi_lapic)
396 mp_lapic_addr = mpc->mpc_lapic;
397
888032cd
AS
398 if (early)
399 return 1;
400
1da177e4 401 /*
4ef81297 402 * Now process the configuration blocks.
1da177e4 403 */
86420506 404#ifdef CONFIG_X86_NUMAQ
1da177e4 405 mpc_record = 0;
86420506 406#endif
1da177e4 407 while (count < mpc->mpc_length) {
4ef81297
AS
408 switch (*mpt) {
409 case MP_PROCESSOR:
1da177e4 410 {
4ef81297
AS
411 struct mpc_config_processor *m =
412 (struct mpc_config_processor *)mpt;
1da177e4
LT
413 /* ACPI may have already provided this data */
414 if (!acpi_lapic)
415 MP_processor_info(m);
416 mpt += sizeof(*m);
417 count += sizeof(*m);
418 break;
419 }
4ef81297 420 case MP_BUS:
1da177e4 421 {
4ef81297
AS
422 struct mpc_config_bus *m =
423 (struct mpc_config_bus *)mpt;
85cc35fa 424#ifdef CONFIG_X86_IO_APIC
1da177e4 425 MP_bus_info(m);
85cc35fa 426#endif
1da177e4
LT
427 mpt += sizeof(*m);
428 count += sizeof(*m);
429 break;
430 }
4ef81297 431 case MP_IOAPIC:
1da177e4 432 {
61048c63 433#ifdef CONFIG_X86_IO_APIC
4ef81297
AS
434 struct mpc_config_ioapic *m =
435 (struct mpc_config_ioapic *)mpt;
1da177e4 436 MP_ioapic_info(m);
61048c63 437#endif
4ef81297
AS
438 mpt += sizeof(struct mpc_config_ioapic);
439 count += sizeof(struct mpc_config_ioapic);
1da177e4
LT
440 break;
441 }
4ef81297 442 case MP_INTSRC:
1da177e4 443 {
61048c63 444#ifdef CONFIG_X86_IO_APIC
4ef81297
AS
445 struct mpc_config_intsrc *m =
446 (struct mpc_config_intsrc *)mpt;
1da177e4
LT
447
448 MP_intsrc_info(m);
61048c63 449#endif
4ef81297
AS
450 mpt += sizeof(struct mpc_config_intsrc);
451 count += sizeof(struct mpc_config_intsrc);
1da177e4
LT
452 break;
453 }
4ef81297 454 case MP_LINTSRC:
1da177e4 455 {
4ef81297
AS
456 struct mpc_config_lintsrc *m =
457 (struct mpc_config_lintsrc *)mpt;
1da177e4 458 MP_lintsrc_info(m);
4ef81297
AS
459 mpt += sizeof(*m);
460 count += sizeof(*m);
1da177e4
LT
461 break;
462 }
4ef81297 463 default:
711554db
YL
464 /* wrong mptable */
465 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
466 printk(KERN_ERR "type %x\n", *mpt);
467 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
468 1, mpc, mpc->mpc_length, 1);
469 count = mpc->mpc_length;
470 break;
1da177e4 471 }
86420506 472#ifdef CONFIG_X86_NUMAQ
1da177e4 473 ++mpc_record;
86420506 474#endif
1da177e4 475 }
e0da3364
YL
476
477#ifdef CONFIG_X86_GENERICARCH
478 generic_bigsmp_probe();
479#endif
480
3c43f039 481 setup_apic_routing();
1da177e4 482 if (!num_processors)
e950bea8 483 printk(KERN_ERR "MPTABLE: no processors registered!\n");
1da177e4
LT
484 return num_processors;
485}
486
61048c63
AS
487#ifdef CONFIG_X86_IO_APIC
488
1da177e4
LT
489static int __init ELCR_trigger(unsigned int irq)
490{
491 unsigned int port;
492
493 port = 0x4d0 + (irq >> 3);
494 return (inb(port) >> (irq & 7)) & 1;
495}
496
497static void __init construct_default_ioirq_mptable(int mpc_default_type)
498{
499 struct mpc_config_intsrc intsrc;
500 int i;
501 int ELCR_fallback = 0;
502
503 intsrc.mpc_type = MP_INTSRC;
4ef81297 504 intsrc.mpc_irqflag = 0; /* conforming */
1da177e4 505 intsrc.mpc_srcbus = 0;
ec2cd0a2 506 intsrc.mpc_dstapic = mp_ioapics[0].mp_apicid;
1da177e4
LT
507
508 intsrc.mpc_irqtype = mp_INT;
509
510 /*
511 * If true, we have an ISA/PCI system with no IRQ entries
512 * in the MP table. To prevent the PCI interrupts from being set up
513 * incorrectly, we try to use the ELCR. The sanity check to see if
514 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
515 * never be level sensitive, so we simply see if the ELCR agrees.
516 * If it does, we assume it's valid.
517 */
518 if (mpc_default_type == 5) {
62441bf1
AS
519 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
520 "falling back to ELCR\n");
1da177e4 521
62441bf1
AS
522 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
523 ELCR_trigger(13))
524 printk(KERN_ERR "ELCR contains invalid data... "
525 "not using ELCR\n");
1da177e4 526 else {
4ef81297
AS
527 printk(KERN_INFO
528 "Using ELCR to identify PCI interrupts\n");
1da177e4
LT
529 ELCR_fallback = 1;
530 }
531 }
532
533 for (i = 0; i < 16; i++) {
534 switch (mpc_default_type) {
535 case 2:
536 if (i == 0 || i == 13)
537 continue; /* IRQ0 & IRQ13 not connected */
538 /* fall through */
539 default:
540 if (i == 2)
541 continue; /* IRQ2 is never connected */
542 }
543
544 if (ELCR_fallback) {
545 /*
546 * If the ELCR indicates a level-sensitive interrupt, we
547 * copy that information over to the MP table in the
548 * irqflag field (level sensitive, active high polarity).
549 */
550 if (ELCR_trigger(i))
551 intsrc.mpc_irqflag = 13;
552 else
553 intsrc.mpc_irqflag = 0;
554 }
555
556 intsrc.mpc_srcbusirq = i;
4ef81297 557 intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
1da177e4
LT
558 MP_intsrc_info(&intsrc);
559 }
560
561 intsrc.mpc_irqtype = mp_ExtINT;
562 intsrc.mpc_srcbusirq = 0;
4ef81297 563 intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */
1da177e4
LT
564 MP_intsrc_info(&intsrc);
565}
566
61048c63 567
85cc35fa 568static void construct_ioapic_table(int mpc_default_type)
1da177e4 569{
1da177e4 570 struct mpc_config_ioapic ioapic;
85cc35fa 571 struct mpc_config_bus bus;
1da177e4
LT
572
573 bus.mpc_type = MP_BUS;
574 bus.mpc_busid = 0;
575 switch (mpc_default_type) {
4ef81297 576 default:
62441bf1 577 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
4ef81297
AS
578 mpc_default_type);
579 /* fall through */
580 case 1:
581 case 5:
582 memcpy(bus.mpc_bustype, "ISA ", 6);
583 break;
584 case 2:
585 case 6:
586 case 3:
587 memcpy(bus.mpc_bustype, "EISA ", 6);
588 break;
589 case 4:
590 case 7:
591 memcpy(bus.mpc_bustype, "MCA ", 6);
1da177e4
LT
592 }
593 MP_bus_info(&bus);
594 if (mpc_default_type > 4) {
595 bus.mpc_busid = 1;
596 memcpy(bus.mpc_bustype, "PCI ", 6);
597 MP_bus_info(&bus);
598 }
599
600 ioapic.mpc_type = MP_IOAPIC;
601 ioapic.mpc_apicid = 2;
602 ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
603 ioapic.mpc_flags = MPC_APIC_USABLE;
604 ioapic.mpc_apicaddr = 0xFEC00000;
605 MP_ioapic_info(&ioapic);
606
607 /*
608 * We set up most of the low 16 IO-APIC pins according to MPS rules.
609 */
610 construct_default_ioirq_mptable(mpc_default_type);
85cc35fa
TG
611}
612#else
613static inline void construct_ioapic_table(int mpc_default_type) { }
61048c63 614#endif
85cc35fa
TG
615
616static inline void __init construct_default_ISA_mptable(int mpc_default_type)
617{
618 struct mpc_config_processor processor;
619 struct mpc_config_lintsrc lintsrc;
620 int linttypes[2] = { mp_ExtINT, mp_NMI };
621 int i;
622
623 /*
624 * local APIC has default address
625 */
626 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
627
628 /*
629 * 2 CPUs, numbered 0 & 1.
630 */
631 processor.mpc_type = MP_PROCESSOR;
632 /* Either an integrated APIC or a discrete 82489DX. */
633 processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
634 processor.mpc_cpuflag = CPU_ENABLED;
635 processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
636 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
637 processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
638 processor.mpc_reserved[0] = 0;
639 processor.mpc_reserved[1] = 0;
640 for (i = 0; i < 2; i++) {
641 processor.mpc_apicid = i;
642 MP_processor_info(&processor);
643 }
644
645 construct_ioapic_table(mpc_default_type);
646
1da177e4 647 lintsrc.mpc_type = MP_LINTSRC;
4ef81297 648 lintsrc.mpc_irqflag = 0; /* conforming */
1da177e4
LT
649 lintsrc.mpc_srcbusid = 0;
650 lintsrc.mpc_srcbusirq = 0;
651 lintsrc.mpc_destapic = MP_APIC_ALL;
652 for (i = 0; i < 2; i++) {
653 lintsrc.mpc_irqtype = linttypes[i];
654 lintsrc.mpc_destapiclint = i;
655 MP_lintsrc_info(&lintsrc);
656 }
657}
658
659static struct intel_mp_floating *mpf_found;
660
661/*
662 * Scan the memory blocks for an SMP configuration block.
663 */
888032cd 664static void __init __get_smp_config(unsigned early)
1da177e4
LT
665{
666 struct intel_mp_floating *mpf = mpf_found;
667
888032cd
AS
668 if (acpi_lapic && early)
669 return;
1da177e4 670 /*
4ef81297 671 * ACPI supports both logical (e.g. Hyper-Threading) and physical
1da177e4
LT
672 * processors, where MPS only supports physical.
673 */
674 if (acpi_lapic && acpi_ioapic) {
4421b1c8
AS
675 printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
676 "information\n");
1da177e4 677 return;
4ef81297 678 } else if (acpi_lapic)
4421b1c8
AS
679 printk(KERN_INFO "Using ACPI for processor (LAPIC) "
680 "configuration information\n");
1da177e4 681
4ef81297
AS
682 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
683 mpf->mpf_specification);
b3e24164 684#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
4ef81297 685 if (mpf->mpf_feature2 & (1 << 7)) {
1da177e4
LT
686 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
687 pic_mode = 1;
688 } else {
689 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
690 pic_mode = 0;
691 }
4421b1c8 692#endif
1da177e4
LT
693 /*
694 * Now see if we need to read further.
695 */
696 if (mpf->mpf_feature1 != 0) {
888032cd
AS
697 if (early) {
698 /*
699 * local APIC has default address
700 */
701 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
702 return;
703 }
1da177e4 704
4ef81297
AS
705 printk(KERN_INFO "Default MP configuration #%d\n",
706 mpf->mpf_feature1);
1da177e4
LT
707 construct_default_ISA_mptable(mpf->mpf_feature1);
708
709 } else if (mpf->mpf_physptr) {
710
711 /*
712 * Read the physical hardware table. Anything here will
713 * override the defaults.
714 */
888032cd 715 if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr), early)) {
bab4b27c 716#ifdef CONFIG_X86_LOCAL_APIC
1da177e4 717 smp_found_config = 0;
bab4b27c 718#endif
4ef81297
AS
719 printk(KERN_ERR
720 "BIOS bug, MP table errors detected!...\n");
4421b1c8
AS
721 printk(KERN_ERR "... disabling SMP support. "
722 "(tell your hw vendor)\n");
1da177e4
LT
723 return;
724 }
61048c63 725
888032cd
AS
726 if (early)
727 return;
61048c63 728#ifdef CONFIG_X86_IO_APIC
1da177e4
LT
729 /*
730 * If there are no explicit MP IRQ entries, then we are
731 * broken. We set up most of the low 16 IO-APIC pins to
732 * ISA defaults and hope it will work.
733 */
734 if (!mp_irq_entries) {
735 struct mpc_config_bus bus;
736
4421b1c8
AS
737 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
738 "using default mptable. "
739 "(tell your hw vendor)\n");
1da177e4
LT
740
741 bus.mpc_type = MP_BUS;
742 bus.mpc_busid = 0;
743 memcpy(bus.mpc_bustype, "ISA ", 6);
744 MP_bus_info(&bus);
745
746 construct_default_ioirq_mptable(0);
747 }
61048c63 748#endif
1da177e4
LT
749 } else
750 BUG();
751
888032cd
AS
752 if (!early)
753 printk(KERN_INFO "Processors: %d\n", num_processors);
1da177e4
LT
754 /*
755 * Only use the first configuration found.
756 */
757}
758
888032cd
AS
759void __init early_get_smp_config(void)
760{
761 __get_smp_config(1);
762}
763
764void __init get_smp_config(void)
765{
766 __get_smp_config(0);
767}
768
769static int __init smp_scan_config(unsigned long base, unsigned long length,
770 unsigned reserve)
1da177e4 771{
92fd4b7a 772 unsigned int *bp = phys_to_virt(base);
1da177e4
LT
773 struct intel_mp_floating *mpf;
774
11a62a05 775 printk(KERN_DEBUG "Scan SMP from %p for %ld bytes.\n", bp, length);
5d47a271 776 BUILD_BUG_ON(sizeof(*mpf) != 16);
1da177e4
LT
777
778 while (length > 0) {
779 mpf = (struct intel_mp_floating *)bp;
780 if ((*bp == SMP_MAGIC_IDENT) &&
4ef81297
AS
781 (mpf->mpf_length == 1) &&
782 !mpf_checksum((unsigned char *)bp, 16) &&
783 ((mpf->mpf_specification == 1)
784 || (mpf->mpf_specification == 4))) {
bab4b27c 785#ifdef CONFIG_X86_LOCAL_APIC
1da177e4 786 smp_found_config = 1;
bab4b27c 787#endif
92fd4b7a
AS
788 mpf_found = mpf;
789#ifdef CONFIG_X86_32
e91a3b43 790 printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
4ef81297 791 mpf, virt_to_phys(mpf));
72a7fe39
BW
792 reserve_bootmem(virt_to_phys(mpf), PAGE_SIZE,
793 BOOTMEM_DEFAULT);
1da177e4
LT
794 if (mpf->mpf_physptr) {
795 /*
796 * We cannot access to MPC table to compute
797 * table size yet, as only few megabytes from
798 * the bottom is mapped now.
799 * PC-9800's MPC table places on the very last
800 * of physical memory; so that simply reserving
801 * PAGE_SIZE from mpg->mpf_physptr yields BUG()
802 * in reserve_bootmem.
803 */
804 unsigned long size = PAGE_SIZE;
805 unsigned long end = max_low_pfn * PAGE_SIZE;
806 if (mpf->mpf_physptr + size > end)
807 size = end - mpf->mpf_physptr;
72a7fe39
BW
808 reserve_bootmem(mpf->mpf_physptr, size,
809 BOOTMEM_DEFAULT);
1da177e4
LT
810 }
811
92fd4b7a
AS
812#else
813 if (!reserve)
814 return 1;
815
816 reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE);
817 if (mpf->mpf_physptr)
818 reserve_bootmem_generic(mpf->mpf_physptr,
819 PAGE_SIZE);
820#endif
821 return 1;
1da177e4
LT
822 }
823 bp += 4;
824 length -= 16;
825 }
826 return 0;
827}
828
888032cd 829static void __init __find_smp_config(unsigned reserve)
1da177e4
LT
830{
831 unsigned int address;
832
833 /*
834 * FIXME: Linux assumes you have 640K of base ram..
835 * this continues the error...
836 *
837 * 1) Scan the bottom 1K for a signature
838 * 2) Scan the top 1K of base RAM
839 * 3) Scan the 64K of bios
840 */
888032cd
AS
841 if (smp_scan_config(0x0, 0x400, reserve) ||
842 smp_scan_config(639 * 0x400, 0x400, reserve) ||
843 smp_scan_config(0xF0000, 0x10000, reserve))
1da177e4
LT
844 return;
845 /*
846 * If it is an SMP machine we should know now, unless the
847 * configuration is in an EISA/MCA bus machine with an
848 * extended bios data area.
849 *
850 * there is a real-mode segmented pointer pointing to the
851 * 4K EBDA area at 0x40E, calculate and scan it here.
852 *
853 * NOTE! There are Linux loaders that will corrupt the EBDA
854 * area, and as such this kind of SMP config may be less
855 * trustworthy, simply because the SMP table may have been
856 * stomped on during early boot. These loaders are buggy and
857 * should be fixed.
858 *
859 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
860 */
861
862 address = get_bios_ebda();
863 if (address)
888032cd
AS
864 smp_scan_config(address, 0x400, reserve);
865}
866
867void __init early_find_smp_config(void)
868{
869 __find_smp_config(0);
870}
871
872void __init find_smp_config(void)
873{
874 __find_smp_config(1);
1da177e4 875}
2944e16b
YL
876
877#ifdef CONFIG_X86_IO_APIC
878static u8 __initdata irq_used[MAX_IRQ_SOURCES];
879
880static int __init get_MP_intsrc_index(struct mpc_config_intsrc *m)
881{
882 int i;
883
884 if (m->mpc_irqtype != mp_INT)
885 return 0;
886
887 if (m->mpc_irqflag != 0x0f)
888 return 0;
889
890 /* not legacy */
891
892 for (i = 0; i < mp_irq_entries; i++) {
893 if (mp_irqs[i].mp_irqtype != mp_INT)
894 continue;
895
896 if (mp_irqs[i].mp_irqflag != 0x0f)
897 continue;
898
899 if (mp_irqs[i].mp_srcbus != m->mpc_srcbus)
900 continue;
901 if (mp_irqs[i].mp_srcbusirq != m->mpc_srcbusirq)
902 continue;
903 if (irq_used[i]) {
904 /* already claimed */
905 return -2;
906 }
907 irq_used[i] = 1;
908 return i;
909 }
910
911 /* not found */
912 return -1;
913}
914
915#define SPARE_SLOT_NUM 20
916
917static struct mpc_config_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
918#endif
919
920static int __init replace_intsrc_all(struct mp_config_table *mpc,
921 unsigned long mpc_new_phys,
922 unsigned long mpc_new_length)
923{
924#ifdef CONFIG_X86_IO_APIC
925 int i;
926 int nr_m_spare = 0;
927#endif
928
929 int count = sizeof(*mpc);
930 unsigned char *mpt = ((unsigned char *)mpc) + count;
931
932 printk(KERN_INFO "mpc_length %x\n", mpc->mpc_length);
933 while (count < mpc->mpc_length) {
934 switch (*mpt) {
935 case MP_PROCESSOR:
936 {
937 struct mpc_config_processor *m =
938 (struct mpc_config_processor *)mpt;
939 mpt += sizeof(*m);
940 count += sizeof(*m);
941 break;
942 }
943 case MP_BUS:
944 {
945 struct mpc_config_bus *m =
946 (struct mpc_config_bus *)mpt;
947 mpt += sizeof(*m);
948 count += sizeof(*m);
949 break;
950 }
951 case MP_IOAPIC:
952 {
953 mpt += sizeof(struct mpc_config_ioapic);
954 count += sizeof(struct mpc_config_ioapic);
955 break;
956 }
957 case MP_INTSRC:
958 {
959#ifdef CONFIG_X86_IO_APIC
960 struct mpc_config_intsrc *m =
961 (struct mpc_config_intsrc *)mpt;
962
963 printk(KERN_INFO "OLD ");
964 print_MP_intsrc_info(m);
965 i = get_MP_intsrc_index(m);
966 if (i > 0) {
967 assign_to_mpc_intsrc(&mp_irqs[i], m);
968 printk(KERN_INFO "NEW ");
969 print_mp_irq_info(&mp_irqs[i]);
970 } else if (!i) {
971 /* legacy, do nothing */
972 } else if (nr_m_spare < SPARE_SLOT_NUM) {
973 /*
974 * not found (-1), or duplicated (-2)
975 * are invalid entries,
976 * we need to use the slot later
977 */
978 m_spare[nr_m_spare] = m;
979 nr_m_spare++;
980 }
981#endif
982 mpt += sizeof(struct mpc_config_intsrc);
983 count += sizeof(struct mpc_config_intsrc);
984 break;
985 }
986 case MP_LINTSRC:
987 {
988 struct mpc_config_lintsrc *m =
989 (struct mpc_config_lintsrc *)mpt;
990 mpt += sizeof(*m);
991 count += sizeof(*m);
992 break;
993 }
994 default:
995 /* wrong mptable */
996 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
997 printk(KERN_ERR "type %x\n", *mpt);
998 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
999 1, mpc, mpc->mpc_length, 1);
1000 goto out;
1001 }
1002 }
1003
1004#ifdef CONFIG_X86_IO_APIC
1005 for (i = 0; i < mp_irq_entries; i++) {
1006 if (irq_used[i])
1007 continue;
1008
1009 if (mp_irqs[i].mp_irqtype != mp_INT)
1010 continue;
1011
1012 if (mp_irqs[i].mp_irqflag != 0x0f)
1013 continue;
1014
1015 if (nr_m_spare > 0) {
1016 printk(KERN_INFO "*NEW* found ");
1017 nr_m_spare--;
1018 assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
1019 m_spare[nr_m_spare] = NULL;
1020 } else {
1021 struct mpc_config_intsrc *m =
1022 (struct mpc_config_intsrc *)mpt;
1023 count += sizeof(struct mpc_config_intsrc);
1024 if (!mpc_new_phys) {
1025 printk(KERN_INFO "No spare slots, try to append...take your risk, new mpc_length %x\n", count);
1026 } else {
1027 if (count <= mpc_new_length)
1028 printk(KERN_INFO "No spare slots, try to append..., new mpc_length %x\n", count);
1029 else {
1030 printk(KERN_ERR "mpc_new_length %lx is too small\n", mpc_new_length);
1031 goto out;
1032 }
1033 }
1034 assign_to_mpc_intsrc(&mp_irqs[i], m);
1035 mpc->mpc_length = count;
1036 mpt += sizeof(struct mpc_config_intsrc);
1037 }
1038 print_mp_irq_info(&mp_irqs[i]);
1039 }
1040#endif
1041out:
1042 /* update checksum */
1043 mpc->mpc_checksum = 0;
1044 mpc->mpc_checksum -= mpf_checksum((unsigned char *)mpc,
1045 mpc->mpc_length);
1046
1047 return 0;
1048}
1049
1050int __initdata enable_update_mptable;
1051
1052static int __init update_mptable_setup(char *str)
1053{
1054 enable_update_mptable = 1;
1055 return 0;
1056}
1057early_param("update_mptable", update_mptable_setup);
1058
1059static unsigned long __initdata mpc_new_phys;
1060static unsigned long mpc_new_length __initdata = 4096;
1061
1062/* alloc_mptable or alloc_mptable=4k */
1063static int __initdata alloc_mptable;
1064static int __init parse_alloc_mptable_opt(char *p)
1065{
1066 enable_update_mptable = 1;
1067 alloc_mptable = 1;
1068 if (!p)
1069 return 0;
1070 mpc_new_length = memparse(p, &p);
1071 return 0;
1072}
1073early_param("alloc_mptable", parse_alloc_mptable_opt);
1074
1075void __init early_reserve_e820_mpc_new(void)
1076{
1077 if (enable_update_mptable && alloc_mptable) {
1078 u64 startt = 0;
1079#ifdef CONFIG_X86_TRAMPOLINE
1080 startt = TRAMPOLINE_BASE;
1081#endif
1082 mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
1083 }
1084}
1085
1086static int __init update_mp_table(void)
1087{
1088 char str[16];
1089 char oem[10];
1090 struct intel_mp_floating *mpf;
1091 struct mp_config_table *mpc;
1092 struct mp_config_table *mpc_new;
1093
1094 if (!enable_update_mptable)
1095 return 0;
1096
1097 mpf = mpf_found;
1098 if (!mpf)
1099 return 0;
1100
1101 /*
1102 * Now see if we need to go further.
1103 */
1104 if (mpf->mpf_feature1 != 0)
1105 return 0;
1106
1107 if (!mpf->mpf_physptr)
1108 return 0;
1109
1110 mpc = phys_to_virt(mpf->mpf_physptr);
1111
1112 if (!smp_check_mpc(mpc, oem, str))
1113 return 0;
1114
1115 printk(KERN_INFO "mpf: %lx\n", virt_to_phys(mpf));
1116 printk(KERN_INFO "mpf_physptr: %x\n", mpf->mpf_physptr);
1117
1118 if (mpc_new_phys && mpc->mpc_length > mpc_new_length) {
1119 mpc_new_phys = 0;
1120 printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
1121 mpc_new_length);
1122 }
1123
1124 if (!mpc_new_phys) {
1125 unsigned char old, new;
1126 /* check if we can change the postion */
1127 mpc->mpc_checksum = 0;
1128 old = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
1129 mpc->mpc_checksum = 0xff;
1130 new = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
1131 if (old == new) {
1132 printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
1133 return 0;
1134 }
1135 printk(KERN_INFO "use in-positon replacing\n");
1136 } else {
1137 mpf->mpf_physptr = mpc_new_phys;
1138 mpc_new = phys_to_virt(mpc_new_phys);
1139 memcpy(mpc_new, mpc, mpc->mpc_length);
1140 mpc = mpc_new;
1141 /* check if we can modify that */
1142 if (mpc_new_phys - mpf->mpf_physptr) {
1143 struct intel_mp_floating *mpf_new;
1144 /* steal 16 bytes from [0, 1k) */
1145 printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
1146 mpf_new = phys_to_virt(0x400 - 16);
1147 memcpy(mpf_new, mpf, 16);
1148 mpf = mpf_new;
1149 mpf->mpf_physptr = mpc_new_phys;
1150 }
1151 mpf->mpf_checksum = 0;
1152 mpf->mpf_checksum -= mpf_checksum((unsigned char *)mpf, 16);
1153 printk(KERN_INFO "mpf_physptr new: %x\n", mpf->mpf_physptr);
1154 }
1155
1156 /*
1157 * only replace the one with mp_INT and
1158 * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
1159 * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
1160 * may need pci=routeirq for all coverage
1161 */
1162 replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
1163
1164 return 0;
1165}
1166
1167late_initcall(update_mp_table);
This page took 0.866714 seconds and 5 git commands to generate.