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