blob: 7f4d2586972e472a896bf8c7870c42429e343f4a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04002 * Intel Multiprocessor Specification 1.1 and 1.4
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * compliant MP-table parsing routines.
4 *
Alan Cox87c6fe22009-01-05 14:08:04 +00005 * (c) 1995 Alan Cox, Building #3 <alan@lxorguk.ukuu.org.uk>
Ingo Molnar8f47e162009-01-31 02:03:42 +01006 * (c) 1998, 1999, 2000, 2009 Ingo Molnar <mingo@redhat.com>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +04007 * (c) 2008 Alexey Starikovskiy <astarikovskiy@suse.de>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
9
10#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/bootmem.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/kernel_stat.h>
15#include <linux/mc146818rtc.h>
16#include <linux/bitops.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040017#include <linux/acpi.h>
18#include <linux/module.h>
Jaswinder Singh Rajput103ceff2009-01-02 23:43:25 +053019#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/mtrr.h>
22#include <asm/mpspec.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040023#include <asm/pgalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/io_apic.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040025#include <asm/proto.h>
Alexey Starikovskiyce3fe6b2008-03-17 22:08:17 +030026#include <asm/bios_ebda.h>
Yinghai Lu2944e162008-06-01 13:17:38 -070027#include <asm/e820.h>
28#include <asm/trampoline.h>
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -070029#include <asm/setup.h>
Jaswinder Singh Rajput4884d8e2009-01-11 18:38:55 +053030#include <asm/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Ingo Molnar7b6aa332009-02-17 13:58:15 +010032#include <asm/apic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 * Checksum an MP configuration block.
35 */
36
37static int __init mpf_checksum(unsigned char *mp, int len)
38{
39 int sum = 0;
40
41 while (len--)
42 sum += *mp++;
43
44 return sum & 0xFF;
45}
46
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +053047static void __init MP_processor_info(struct mpc_cpu *m)
Alexey Starikovskiyc853c672008-03-27 23:54:13 +030048{
49 int apicid;
Alexey Starikovskiy746f2242008-04-04 23:42:15 +040050 char *bootup_cpu = "";
Alexey Starikovskiyc853c672008-03-27 23:54:13 +030051
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053052 if (!(m->cpuflag & CPU_ENABLED)) {
Glauber Costa7b1292e2008-03-03 14:12:41 -030053 disabled_cpus++;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 return;
Glauber Costa7b1292e2008-03-03 14:12:41 -030055 }
Yinghai Lu64898a82008-07-19 18:01:16 -070056
57 if (x86_quirks->mpc_apic_id)
58 apicid = x86_quirks->mpc_apic_id(m);
Yinghai Luab530e12008-06-03 10:25:54 -070059 else
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053060 apicid = m->apicid;
Yinghai Lu64898a82008-07-19 18:01:16 -070061
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053062 if (m->cpuflag & CPU_BOOTPROCESSOR) {
Alexey Starikovskiy746f2242008-04-04 23:42:15 +040063 bootup_cpu = " (Bootup-CPU)";
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053064 boot_cpu_physical_apicid = m->apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 }
66
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053067 printk(KERN_INFO "Processor #%d%s\n", m->apicid, bootup_cpu);
68 generic_processor_info(apicid, m->apicver);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069}
70
Thomas Gleixner85cc35f2008-05-25 21:21:36 +020071#ifdef CONFIG_X86_IO_APIC
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +053072static void __init MP_bus_info(struct mpc_bus *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073{
74 char str[7];
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053075 memcpy(str, m->bustype, 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 str[6] = 0;
77
Yinghai Lu64898a82008-07-19 18:01:16 -070078 if (x86_quirks->mpc_oem_bus_info)
79 x86_quirks->mpc_oem_bus_info(m, str);
80 else
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053081 apic_printk(APIC_VERBOSE, "Bus #%d is %s\n", m->busid, str);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Andi Kleen5e4edbb2006-09-26 10:52:35 +020083#if MAX_MP_BUSSES < 256
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053084 if (m->busid >= MAX_MP_BUSSES) {
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070085 printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +040086 " is too large, max. supported is %d\n",
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053087 m->busid, str, MAX_MP_BUSSES - 1);
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070088 return;
89 }
Andi Kleen5e4edbb2006-09-26 10:52:35 +020090#endif
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070091
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +040092 if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053093 set_bit(m->busid, mp_bus_not_pci);
Jaswinder Singh Rajput103ceff2009-01-02 23:43:25 +053094#if defined(CONFIG_EISA) || defined(CONFIG_MCA)
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053095 mp_bus_id_to_type[m->busid] = MP_BUS_ISA;
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +040096#endif
97 } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
Yinghai Lu64898a82008-07-19 18:01:16 -070098 if (x86_quirks->mpc_oem_pci_bus)
99 x86_quirks->mpc_oem_pci_bus(m);
100
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530101 clear_bit(m->busid, mp_bus_not_pci);
Jaswinder Singh Rajput103ceff2009-01-02 23:43:25 +0530102#if defined(CONFIG_EISA) || defined(CONFIG_MCA)
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530103 mp_bus_id_to_type[m->busid] = MP_BUS_PCI;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400104 } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530105 mp_bus_id_to_type[m->busid] = MP_BUS_EISA;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400106 } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530107 mp_bus_id_to_type[m->busid] = MP_BUS_MCA;
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +0300108#endif
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +0400109 } else
110 printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111}
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200112#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400114#ifdef CONFIG_X86_IO_APIC
115
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300116static int bad_ioapic(unsigned long address)
117{
118 if (nr_ioapics >= MAX_IO_APICS) {
119 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
120 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
121 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
122 }
123 if (!address) {
124 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
125 " found in table, skipping!\n");
126 return 1;
127 }
128 return 0;
129}
130
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530131static void __init MP_ioapic_info(struct mpc_ioapic *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132{
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530133 if (!(m->flags & MPC_APIC_USABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 return;
135
Thomas Gleixner64883ab2008-01-30 13:30:35 +0100136 printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530137 m->apicid, m->apicver, m->apicaddr);
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300138
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530139 if (bad_ioapic(m->apicaddr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 return;
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300141
Jaswinder Singh Rajputb5ba7e6d2009-01-12 17:46:17 +0530142 mp_ioapics[nr_ioapics].apicaddr = m->apicaddr;
143 mp_ioapics[nr_ioapics].apicid = m->apicid;
144 mp_ioapics[nr_ioapics].type = m->type;
145 mp_ioapics[nr_ioapics].apicver = m->apicver;
146 mp_ioapics[nr_ioapics].flags = m->flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 nr_ioapics++;
148}
149
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530150static void print_MP_intsrc_info(struct mpc_intsrc *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200152 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530154 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbus,
155 m->srcbusirq, m->dstapic, m->dstirq);
Yinghai Lu2944e162008-06-01 13:17:38 -0700156}
157
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530158static void __init print_mp_irq_info(struct mpc_intsrc *mp_irq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700159{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200160 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
Yinghai Lu2944e162008-06-01 13:17:38 -0700161 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530162 mp_irq->irqtype, mp_irq->irqflag & 3,
163 (mp_irq->irqflag >> 2) & 3, mp_irq->srcbus,
164 mp_irq->srcbusirq, mp_irq->dstapic, mp_irq->dstirq);
Yinghai Lu2944e162008-06-01 13:17:38 -0700165}
166
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530167static void __init assign_to_mp_irq(struct mpc_intsrc *m,
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530168 struct mpc_intsrc *mp_irq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700169{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530170 mp_irq->dstapic = m->dstapic;
171 mp_irq->type = m->type;
172 mp_irq->irqtype = m->irqtype;
173 mp_irq->irqflag = m->irqflag;
174 mp_irq->srcbus = m->srcbus;
175 mp_irq->srcbusirq = m->srcbusirq;
176 mp_irq->dstirq = m->dstirq;
Yinghai Lu2944e162008-06-01 13:17:38 -0700177}
178
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530179static void __init assign_to_mpc_intsrc(struct mpc_intsrc *mp_irq,
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530180 struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700181{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530182 m->dstapic = mp_irq->dstapic;
183 m->type = mp_irq->type;
184 m->irqtype = mp_irq->irqtype;
185 m->irqflag = mp_irq->irqflag;
186 m->srcbus = mp_irq->srcbus;
187 m->srcbusirq = mp_irq->srcbusirq;
188 m->dstirq = mp_irq->dstirq;
Yinghai Lu2944e162008-06-01 13:17:38 -0700189}
190
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530191static int __init mp_irq_mpc_intsrc_cmp(struct mpc_intsrc *mp_irq,
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530192 struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700193{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530194 if (mp_irq->dstapic != m->dstapic)
Yinghai Lu2944e162008-06-01 13:17:38 -0700195 return 1;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530196 if (mp_irq->type != m->type)
Yinghai Lu2944e162008-06-01 13:17:38 -0700197 return 2;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530198 if (mp_irq->irqtype != m->irqtype)
Yinghai Lu2944e162008-06-01 13:17:38 -0700199 return 3;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530200 if (mp_irq->irqflag != m->irqflag)
Yinghai Lu2944e162008-06-01 13:17:38 -0700201 return 4;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530202 if (mp_irq->srcbus != m->srcbus)
Yinghai Lu2944e162008-06-01 13:17:38 -0700203 return 5;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530204 if (mp_irq->srcbusirq != m->srcbusirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700205 return 6;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530206 if (mp_irq->dstirq != m->dstirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700207 return 7;
208
209 return 0;
210}
211
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530212static void __init MP_intsrc_info(struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700213{
214 int i;
215
216 print_MP_intsrc_info(m);
217
Yinghai Lufcfa1462008-06-18 17:29:31 -0700218 for (i = 0; i < mp_irq_entries; i++) {
219 if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m))
220 return;
221 }
Yinghai Lu2944e162008-06-01 13:17:38 -0700222
223 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 if (++mp_irq_entries == MAX_IRQ_SOURCES)
225 panic("Max # of irq sources exceeded!!\n");
226}
227
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400228#endif
229
Jaswinder Singh Rajput8fb29522009-01-03 15:51:54 +0530230static void __init MP_lintsrc_info(struct mpc_lintsrc *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200232 apic_printk(APIC_VERBOSE, "Lint: type %d, pol %d, trig %d, bus %02x,"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
Jaswinder Singh Rajputb5ced7cd2009-01-04 21:55:53 +0530234 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbusid,
235 m->srcbusirq, m->destapic, m->destapiclint);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236}
237
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238/*
239 * Read/parse the MPC
240 */
241
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530242static int __init smp_check_mpc(struct mpc_table *mpc, char *oem, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530245 if (memcmp(mpc->signature, MPC_SIGNATURE, 4)) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400246 printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530247 mpc->signature[0], mpc->signature[1],
248 mpc->signature[2], mpc->signature[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 return 0;
250 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530251 if (mpf_checksum((unsigned char *)mpc, mpc->length)) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400252 printk(KERN_ERR "MPTABLE: checksum error!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 return 0;
254 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530255 if (mpc->spec != 0x01 && mpc->spec != 0x04) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400256 printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530257 mpc->spec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 return 0;
259 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530260 if (!mpc->lapic) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400261 printk(KERN_ERR "MPTABLE: null local APIC address!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 return 0;
263 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530264 memcpy(oem, mpc->oem, 8);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400265 oem[8] = 0;
Yinghai Lu11a62a02008-05-12 15:43:38 +0200266 printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530268 memcpy(str, mpc->productid, 12);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400269 str[12] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
Yinghai Lu11a62a02008-05-12 15:43:38 +0200271 printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530273 printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->lapic);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
Yinghai Lu2944e162008-06-01 13:17:38 -0700275 return 1;
276}
277
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530278static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early)
Yinghai Lu2944e162008-06-01 13:17:38 -0700279{
280 char str[16];
281 char oem[10];
282
283 int count = sizeof(*mpc);
284 unsigned char *mpt = ((unsigned char *)mpc) + count;
285
286 if (!smp_check_mpc(mpc, oem, str))
287 return 0;
288
289#ifdef CONFIG_X86_32
Ingo Molnar9c764242009-01-28 13:44:32 +0100290 generic_mps_oem_check(mpc, oem, str);
Yinghai Lu2944e162008-06-01 13:17:38 -0700291#endif
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400292 /* save the local APIC address, it might be non-default */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 if (!acpi_lapic)
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530294 mp_lapic_addr = mpc->lapic;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400296 if (early)
297 return 1;
298
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530299 if (mpc->oemptr && x86_quirks->smp_read_mpc_oem) {
300 struct mpc_oemtable *oem_table = (void *)(long)mpc->oemptr;
301 x86_quirks->smp_read_mpc_oem(oem_table, mpc->oemsize);
Yinghai Lu64898a82008-07-19 18:01:16 -0700302 }
303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 /*
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400305 * Now process the configuration blocks.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 */
Yinghai Lu64898a82008-07-19 18:01:16 -0700307 if (x86_quirks->mpc_record)
308 *x86_quirks->mpc_record = 0;
309
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530310 while (count < mpc->length) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400311 switch (*mpt) {
312 case MP_PROCESSOR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 {
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +0530314 struct mpc_cpu *m = (struct mpc_cpu *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 /* ACPI may have already provided this data */
316 if (!acpi_lapic)
317 MP_processor_info(m);
318 mpt += sizeof(*m);
319 count += sizeof(*m);
320 break;
321 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400322 case MP_BUS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 {
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +0530324 struct mpc_bus *m = (struct mpc_bus *)mpt;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200325#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 MP_bus_info(m);
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200327#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 mpt += sizeof(*m);
329 count += sizeof(*m);
330 break;
331 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400332 case MP_IOAPIC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 {
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400334#ifdef CONFIG_X86_IO_APIC
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530335 struct mpc_ioapic *m = (struct mpc_ioapic *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 MP_ioapic_info(m);
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400337#endif
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530338 mpt += sizeof(struct mpc_ioapic);
339 count += sizeof(struct mpc_ioapic);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 break;
341 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400342 case MP_INTSRC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 {
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400344#ifdef CONFIG_X86_IO_APIC
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530345 struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
347 MP_intsrc_info(m);
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400348#endif
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530349 mpt += sizeof(struct mpc_intsrc);
350 count += sizeof(struct mpc_intsrc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 break;
352 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400353 case MP_LINTSRC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 {
Jaswinder Singh Rajput8fb29522009-01-03 15:51:54 +0530355 struct mpc_lintsrc *m =
356 (struct mpc_lintsrc *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 MP_lintsrc_info(m);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400358 mpt += sizeof(*m);
359 count += sizeof(*m);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 break;
361 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400362 default:
Yinghai Lu711554d2008-04-07 11:36:39 -0700363 /* wrong mptable */
364 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
365 printk(KERN_ERR "type %x\n", *mpt);
366 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530367 1, mpc, mpc->length, 1);
368 count = mpc->length;
Yinghai Lu711554d2008-04-07 11:36:39 -0700369 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 }
Yinghai Lu64898a82008-07-19 18:01:16 -0700371 if (x86_quirks->mpc_record)
372 (*x86_quirks->mpc_record)++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 }
Yinghai Lue0da3362008-06-08 18:29:22 -0700374
Yinghai Lu26f7ef12009-01-29 14:19:22 -0800375#ifdef CONFIG_X86_BIGSMP
376 generic_bigsmp_probe();
Yinghai Lue0da3362008-06-08 18:29:22 -0700377#endif
378
Ingo Molnar72ce0162009-01-28 06:50:47 +0100379 if (apic->setup_apic_routing)
380 apic->setup_apic_routing();
381
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 if (!num_processors)
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400383 printk(KERN_ERR "MPTABLE: no processors registered!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 return num_processors;
385}
386
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400387#ifdef CONFIG_X86_IO_APIC
388
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389static int __init ELCR_trigger(unsigned int irq)
390{
391 unsigned int port;
392
393 port = 0x4d0 + (irq >> 3);
394 return (inb(port) >> (irq & 7)) & 1;
395}
396
397static void __init construct_default_ioirq_mptable(int mpc_default_type)
398{
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530399 struct mpc_intsrc intsrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 int i;
401 int ELCR_fallback = 0;
402
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530403 intsrc.type = MP_INTSRC;
404 intsrc.irqflag = 0; /* conforming */
405 intsrc.srcbus = 0;
Jaswinder Singh Rajputb5ba7e6d2009-01-12 17:46:17 +0530406 intsrc.dstapic = mp_ioapics[0].apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530408 intsrc.irqtype = mp_INT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
410 /*
411 * If true, we have an ISA/PCI system with no IRQ entries
412 * in the MP table. To prevent the PCI interrupts from being set up
413 * incorrectly, we try to use the ELCR. The sanity check to see if
414 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
415 * never be level sensitive, so we simply see if the ELCR agrees.
416 * If it does, we assume it's valid.
417 */
418 if (mpc_default_type == 5) {
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400419 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
420 "falling back to ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400422 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
423 ELCR_trigger(13))
424 printk(KERN_ERR "ELCR contains invalid data... "
425 "not using ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 else {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400427 printk(KERN_INFO
428 "Using ELCR to identify PCI interrupts\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 ELCR_fallback = 1;
430 }
431 }
432
433 for (i = 0; i < 16; i++) {
434 switch (mpc_default_type) {
435 case 2:
436 if (i == 0 || i == 13)
437 continue; /* IRQ0 & IRQ13 not connected */
438 /* fall through */
439 default:
440 if (i == 2)
441 continue; /* IRQ2 is never connected */
442 }
443
444 if (ELCR_fallback) {
445 /*
446 * If the ELCR indicates a level-sensitive interrupt, we
447 * copy that information over to the MP table in the
448 * irqflag field (level sensitive, active high polarity).
449 */
450 if (ELCR_trigger(i))
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530451 intsrc.irqflag = 13;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 else
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530453 intsrc.irqflag = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 }
455
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530456 intsrc.srcbusirq = i;
457 intsrc.dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 MP_intsrc_info(&intsrc);
459 }
460
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530461 intsrc.irqtype = mp_ExtINT;
462 intsrc.srcbusirq = 0;
463 intsrc.dstirq = 0; /* 8259A to INTIN0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 MP_intsrc_info(&intsrc);
465}
466
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400467
Marcin Slusarz39e00fe2008-08-11 00:09:38 +0200468static void __init construct_ioapic_table(int mpc_default_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469{
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530470 struct mpc_ioapic ioapic;
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +0530471 struct mpc_bus bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530473 bus.type = MP_BUS;
474 bus.busid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 switch (mpc_default_type) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400476 default:
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400477 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400478 mpc_default_type);
479 /* fall through */
480 case 1:
481 case 5:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530482 memcpy(bus.bustype, "ISA ", 6);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400483 break;
484 case 2:
485 case 6:
486 case 3:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530487 memcpy(bus.bustype, "EISA ", 6);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400488 break;
489 case 4:
490 case 7:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530491 memcpy(bus.bustype, "MCA ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 }
493 MP_bus_info(&bus);
494 if (mpc_default_type > 4) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530495 bus.busid = 1;
496 memcpy(bus.bustype, "PCI ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 MP_bus_info(&bus);
498 }
499
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530500 ioapic.type = MP_IOAPIC;
501 ioapic.apicid = 2;
502 ioapic.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
503 ioapic.flags = MPC_APIC_USABLE;
504 ioapic.apicaddr = 0xFEC00000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 MP_ioapic_info(&ioapic);
506
507 /*
508 * We set up most of the low 16 IO-APIC pins according to MPS rules.
509 */
510 construct_default_ioirq_mptable(mpc_default_type);
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200511}
512#else
Marcin Slusarz39e00fe2008-08-11 00:09:38 +0200513static inline void __init construct_ioapic_table(int mpc_default_type) { }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400514#endif
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200515
516static inline void __init construct_default_ISA_mptable(int mpc_default_type)
517{
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +0530518 struct mpc_cpu processor;
Jaswinder Singh Rajput8fb29522009-01-03 15:51:54 +0530519 struct mpc_lintsrc lintsrc;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200520 int linttypes[2] = { mp_ExtINT, mp_NMI };
521 int i;
522
523 /*
524 * local APIC has default address
525 */
526 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
527
528 /*
529 * 2 CPUs, numbered 0 & 1.
530 */
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530531 processor.type = MP_PROCESSOR;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200532 /* Either an integrated APIC or a discrete 82489DX. */
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530533 processor.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
534 processor.cpuflag = CPU_ENABLED;
535 processor.cpufeature = (boot_cpu_data.x86 << 8) |
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200536 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530537 processor.featureflag = boot_cpu_data.x86_capability[0];
538 processor.reserved[0] = 0;
539 processor.reserved[1] = 0;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200540 for (i = 0; i < 2; i++) {
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530541 processor.apicid = i;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200542 MP_processor_info(&processor);
543 }
544
545 construct_ioapic_table(mpc_default_type);
546
Jaswinder Singh Rajputb5ced7cd2009-01-04 21:55:53 +0530547 lintsrc.type = MP_LINTSRC;
548 lintsrc.irqflag = 0; /* conforming */
549 lintsrc.srcbusid = 0;
550 lintsrc.srcbusirq = 0;
551 lintsrc.destapic = MP_APIC_ALL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 for (i = 0; i < 2; i++) {
Jaswinder Singh Rajputb5ced7cd2009-01-04 21:55:53 +0530553 lintsrc.irqtype = linttypes[i];
554 lintsrc.destapiclint = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 MP_lintsrc_info(&lintsrc);
556 }
557}
558
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530559static struct mpf_intel *mpf_found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
561/*
562 * Scan the memory blocks for an SMP configuration block.
563 */
Ingo Molnar3b335532008-07-10 17:30:40 +0200564static void __init __get_smp_config(unsigned int early)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565{
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530566 struct mpf_intel *mpf = mpf_found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
Yinghai Lu69b88af2008-12-05 22:45:50 -0800568 if (!mpf)
569 return;
570
571 if (acpi_lapic && early)
572 return;
573
574 /*
575 * MPS doesn't support hyperthreading, aka only have
576 * thread 0 apic id in MPS table
577 */
578 if (acpi_lapic && acpi_ioapic)
579 return;
580
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700581 if (x86_quirks->mach_get_smp_config) {
582 if (x86_quirks->mach_get_smp_config(early))
Ingo Molnar3b335532008-07-10 17:30:40 +0200583 return;
584 }
Andi Kleen9adc1382008-12-04 13:33:35 +0100585
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400586 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530587 mpf->specification);
Alexey Starikovskiyb3e24162008-05-23 01:54:44 +0400588#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530589 if (mpf->feature2 & (1 << 7)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
591 pic_mode = 1;
592 } else {
593 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
594 pic_mode = 0;
595 }
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400596#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 /*
598 * Now see if we need to read further.
599 */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530600 if (mpf->feature1 != 0) {
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400601 if (early) {
602 /*
603 * local APIC has default address
604 */
605 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
606 return;
607 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400609 printk(KERN_INFO "Default MP configuration #%d\n",
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530610 mpf->feature1);
611 construct_default_ISA_mptable(mpf->feature1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530613 } else if (mpf->physptr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
615 /*
616 * Read the physical hardware table. Anything here will
617 * override the defaults.
618 */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530619 if (!smp_read_mpc(phys_to_virt(mpf->physptr), early)) {
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400620#ifdef CONFIG_X86_LOCAL_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 smp_found_config = 0;
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400622#endif
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400623 printk(KERN_ERR
624 "BIOS bug, MP table errors detected!...\n");
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400625 printk(KERN_ERR "... disabling SMP support. "
626 "(tell your hw vendor)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 return;
628 }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400629
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400630 if (early)
631 return;
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400632#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 /*
634 * If there are no explicit MP IRQ entries, then we are
635 * broken. We set up most of the low 16 IO-APIC pins to
636 * ISA defaults and hope it will work.
637 */
638 if (!mp_irq_entries) {
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +0530639 struct mpc_bus bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400641 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
642 "using default mptable. "
643 "(tell your hw vendor)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530645 bus.type = MP_BUS;
646 bus.busid = 0;
647 memcpy(bus.bustype, "ISA ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 MP_bus_info(&bus);
649
650 construct_default_ioirq_mptable(0);
651 }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400652#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 } else
654 BUG();
655
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400656 if (!early)
657 printk(KERN_INFO "Processors: %d\n", num_processors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 /*
659 * Only use the first configuration found.
660 */
661}
662
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400663void __init early_get_smp_config(void)
664{
665 __get_smp_config(1);
666}
667
668void __init get_smp_config(void)
669{
670 __get_smp_config(0);
671}
672
673static int __init smp_scan_config(unsigned long base, unsigned long length,
674 unsigned reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675{
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400676 unsigned int *bp = phys_to_virt(base);
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530677 struct mpf_intel *mpf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200679 apic_printk(APIC_VERBOSE, "Scan SMP from %p for %ld bytes.\n",
680 bp, length);
Akinobu Mita5d47a272008-04-19 23:55:11 +0900681 BUILD_BUG_ON(sizeof(*mpf) != 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682
683 while (length > 0) {
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530684 mpf = (struct mpf_intel *)bp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 if ((*bp == SMP_MAGIC_IDENT) &&
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530686 (mpf->length == 1) &&
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400687 !mpf_checksum((unsigned char *)bp, 16) &&
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530688 ((mpf->specification == 1)
689 || (mpf->specification == 4))) {
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400690#ifdef CONFIG_X86_LOCAL_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 smp_found_config = 1;
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400692#endif
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400693 mpf_found = mpf;
Yinghai Lub1f006b2008-06-09 18:11:36 -0700694
Jaswinder Singh Rajputba1511b2009-02-11 23:38:25 +0530695 printk(KERN_INFO "found SMP MP-table at [%p] %llx\n",
696 mpf, (u64)virt_to_phys(mpf));
Yinghai Lub1f006b2008-06-09 18:11:36 -0700697
698 if (!reserve)
699 return 1;
Yinghai Lud2dbf342008-06-13 02:00:56 -0700700 reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE,
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800701 BOOTMEM_DEFAULT);
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530702 if (mpf->physptr) {
Yinghai Lud2dbf342008-06-13 02:00:56 -0700703 unsigned long size = PAGE_SIZE;
704#ifdef CONFIG_X86_32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 /*
706 * We cannot access to MPC table to compute
707 * table size yet, as only few megabytes from
708 * the bottom is mapped now.
709 * PC-9800's MPC table places on the very last
710 * of physical memory; so that simply reserving
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530711 * PAGE_SIZE from mpf->physptr yields BUG()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 * in reserve_bootmem.
713 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 unsigned long end = max_low_pfn * PAGE_SIZE;
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530715 if (mpf->physptr + size > end)
716 size = end - mpf->physptr;
Yinghai Lud2dbf342008-06-13 02:00:56 -0700717#endif
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530718 reserve_bootmem_generic(mpf->physptr, size,
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800719 BOOTMEM_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 }
721
Yinghai Lud2dbf342008-06-13 02:00:56 -0700722 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 }
724 bp += 4;
725 length -= 16;
726 }
727 return 0;
728}
729
Ingo Molnar3b335532008-07-10 17:30:40 +0200730static void __init __find_smp_config(unsigned int reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731{
732 unsigned int address;
733
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700734 if (x86_quirks->mach_find_smp_config) {
735 if (x86_quirks->mach_find_smp_config(reserve))
Ingo Molnar3b335532008-07-10 17:30:40 +0200736 return;
737 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 /*
739 * FIXME: Linux assumes you have 640K of base ram..
740 * this continues the error...
741 *
742 * 1) Scan the bottom 1K for a signature
743 * 2) Scan the top 1K of base RAM
744 * 3) Scan the 64K of bios
745 */
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400746 if (smp_scan_config(0x0, 0x400, reserve) ||
747 smp_scan_config(639 * 0x400, 0x400, reserve) ||
748 smp_scan_config(0xF0000, 0x10000, reserve))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 return;
750 /*
751 * If it is an SMP machine we should know now, unless the
752 * configuration is in an EISA/MCA bus machine with an
753 * extended bios data area.
754 *
755 * there is a real-mode segmented pointer pointing to the
756 * 4K EBDA area at 0x40E, calculate and scan it here.
757 *
758 * NOTE! There are Linux loaders that will corrupt the EBDA
759 * area, and as such this kind of SMP config may be less
760 * trustworthy, simply because the SMP table may have been
761 * stomped on during early boot. These loaders are buggy and
762 * should be fixed.
763 *
764 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
765 */
766
767 address = get_bios_ebda();
768 if (address)
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400769 smp_scan_config(address, 0x400, reserve);
770}
771
772void __init early_find_smp_config(void)
773{
774 __find_smp_config(0);
775}
776
777void __init find_smp_config(void)
778{
779 __find_smp_config(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780}
Yinghai Lu2944e162008-06-01 13:17:38 -0700781
782#ifdef CONFIG_X86_IO_APIC
783static u8 __initdata irq_used[MAX_IRQ_SOURCES];
784
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530785static int __init get_MP_intsrc_index(struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700786{
787 int i;
788
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530789 if (m->irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700790 return 0;
791
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530792 if (m->irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700793 return 0;
794
795 /* not legacy */
796
797 for (i = 0; i < mp_irq_entries; i++) {
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530798 if (mp_irqs[i].irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700799 continue;
800
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530801 if (mp_irqs[i].irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700802 continue;
803
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530804 if (mp_irqs[i].srcbus != m->srcbus)
Yinghai Lu2944e162008-06-01 13:17:38 -0700805 continue;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530806 if (mp_irqs[i].srcbusirq != m->srcbusirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700807 continue;
808 if (irq_used[i]) {
809 /* already claimed */
810 return -2;
811 }
812 irq_used[i] = 1;
813 return i;
814 }
815
816 /* not found */
817 return -1;
818}
819
820#define SPARE_SLOT_NUM 20
821
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530822static struct mpc_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
Yinghai Lu2944e162008-06-01 13:17:38 -0700823#endif
824
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530825static int __init replace_intsrc_all(struct mpc_table *mpc,
Yinghai Lu2944e162008-06-01 13:17:38 -0700826 unsigned long mpc_new_phys,
827 unsigned long mpc_new_length)
828{
829#ifdef CONFIG_X86_IO_APIC
830 int i;
831 int nr_m_spare = 0;
832#endif
833
834 int count = sizeof(*mpc);
835 unsigned char *mpt = ((unsigned char *)mpc) + count;
836
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530837 printk(KERN_INFO "mpc_length %x\n", mpc->length);
838 while (count < mpc->length) {
Yinghai Lu2944e162008-06-01 13:17:38 -0700839 switch (*mpt) {
840 case MP_PROCESSOR:
841 {
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +0530842 struct mpc_cpu *m = (struct mpc_cpu *)mpt;
Yinghai Lu2944e162008-06-01 13:17:38 -0700843 mpt += sizeof(*m);
844 count += sizeof(*m);
845 break;
846 }
847 case MP_BUS:
848 {
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +0530849 struct mpc_bus *m = (struct mpc_bus *)mpt;
Yinghai Lu2944e162008-06-01 13:17:38 -0700850 mpt += sizeof(*m);
851 count += sizeof(*m);
852 break;
853 }
854 case MP_IOAPIC:
855 {
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530856 mpt += sizeof(struct mpc_ioapic);
857 count += sizeof(struct mpc_ioapic);
Yinghai Lu2944e162008-06-01 13:17:38 -0700858 break;
859 }
860 case MP_INTSRC:
861 {
862#ifdef CONFIG_X86_IO_APIC
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530863 struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
Yinghai Lu2944e162008-06-01 13:17:38 -0700864
865 printk(KERN_INFO "OLD ");
866 print_MP_intsrc_info(m);
867 i = get_MP_intsrc_index(m);
868 if (i > 0) {
869 assign_to_mpc_intsrc(&mp_irqs[i], m);
870 printk(KERN_INFO "NEW ");
871 print_mp_irq_info(&mp_irqs[i]);
872 } else if (!i) {
873 /* legacy, do nothing */
874 } else if (nr_m_spare < SPARE_SLOT_NUM) {
875 /*
876 * not found (-1), or duplicated (-2)
877 * are invalid entries,
878 * we need to use the slot later
879 */
880 m_spare[nr_m_spare] = m;
881 nr_m_spare++;
882 }
883#endif
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530884 mpt += sizeof(struct mpc_intsrc);
885 count += sizeof(struct mpc_intsrc);
Yinghai Lu2944e162008-06-01 13:17:38 -0700886 break;
887 }
888 case MP_LINTSRC:
889 {
Jaswinder Singh Rajput8fb29522009-01-03 15:51:54 +0530890 struct mpc_lintsrc *m =
891 (struct mpc_lintsrc *)mpt;
Yinghai Lu2944e162008-06-01 13:17:38 -0700892 mpt += sizeof(*m);
893 count += sizeof(*m);
894 break;
895 }
896 default:
897 /* wrong mptable */
898 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
899 printk(KERN_ERR "type %x\n", *mpt);
900 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530901 1, mpc, mpc->length, 1);
Yinghai Lu2944e162008-06-01 13:17:38 -0700902 goto out;
903 }
904 }
905
906#ifdef CONFIG_X86_IO_APIC
907 for (i = 0; i < mp_irq_entries; i++) {
908 if (irq_used[i])
909 continue;
910
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530911 if (mp_irqs[i].irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700912 continue;
913
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530914 if (mp_irqs[i].irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700915 continue;
916
917 if (nr_m_spare > 0) {
918 printk(KERN_INFO "*NEW* found ");
919 nr_m_spare--;
920 assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
921 m_spare[nr_m_spare] = NULL;
922 } else {
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530923 struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
924 count += sizeof(struct mpc_intsrc);
Yinghai Lu2944e162008-06-01 13:17:38 -0700925 if (!mpc_new_phys) {
926 printk(KERN_INFO "No spare slots, try to append...take your risk, new mpc_length %x\n", count);
927 } else {
928 if (count <= mpc_new_length)
929 printk(KERN_INFO "No spare slots, try to append..., new mpc_length %x\n", count);
930 else {
931 printk(KERN_ERR "mpc_new_length %lx is too small\n", mpc_new_length);
932 goto out;
933 }
934 }
935 assign_to_mpc_intsrc(&mp_irqs[i], m);
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530936 mpc->length = count;
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530937 mpt += sizeof(struct mpc_intsrc);
Yinghai Lu2944e162008-06-01 13:17:38 -0700938 }
939 print_mp_irq_info(&mp_irqs[i]);
940 }
941#endif
942out:
943 /* update checksum */
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530944 mpc->checksum = 0;
945 mpc->checksum -= mpf_checksum((unsigned char *)mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -0700946
947 return 0;
948}
949
Yinghai Lufcfa1462008-06-18 17:29:31 -0700950static int __initdata enable_update_mptable;
951
Yinghai Lu2944e162008-06-01 13:17:38 -0700952static int __init update_mptable_setup(char *str)
953{
954 enable_update_mptable = 1;
955 return 0;
956}
957early_param("update_mptable", update_mptable_setup);
958
959static unsigned long __initdata mpc_new_phys;
960static unsigned long mpc_new_length __initdata = 4096;
961
962/* alloc_mptable or alloc_mptable=4k */
963static int __initdata alloc_mptable;
964static int __init parse_alloc_mptable_opt(char *p)
965{
966 enable_update_mptable = 1;
967 alloc_mptable = 1;
968 if (!p)
969 return 0;
970 mpc_new_length = memparse(p, &p);
971 return 0;
972}
973early_param("alloc_mptable", parse_alloc_mptable_opt);
974
975void __init early_reserve_e820_mpc_new(void)
976{
977 if (enable_update_mptable && alloc_mptable) {
978 u64 startt = 0;
979#ifdef CONFIG_X86_TRAMPOLINE
980 startt = TRAMPOLINE_BASE;
981#endif
982 mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
983 }
984}
985
986static int __init update_mp_table(void)
987{
988 char str[16];
989 char oem[10];
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530990 struct mpf_intel *mpf;
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530991 struct mpc_table *mpc, *mpc_new;
Yinghai Lu2944e162008-06-01 13:17:38 -0700992
993 if (!enable_update_mptable)
994 return 0;
995
996 mpf = mpf_found;
997 if (!mpf)
998 return 0;
999
1000 /*
1001 * Now see if we need to go further.
1002 */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301003 if (mpf->feature1 != 0)
Yinghai Lu2944e162008-06-01 13:17:38 -07001004 return 0;
1005
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301006 if (!mpf->physptr)
Yinghai Lu2944e162008-06-01 13:17:38 -07001007 return 0;
1008
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301009 mpc = phys_to_virt(mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -07001010
1011 if (!smp_check_mpc(mpc, oem, str))
1012 return 0;
1013
Jaswinder Singh Rajputba1511b2009-02-11 23:38:25 +05301014 printk(KERN_INFO "mpf: %llx\n", (u64)virt_to_phys(mpf));
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301015 printk(KERN_INFO "physptr: %x\n", mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -07001016
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +05301017 if (mpc_new_phys && mpc->length > mpc_new_length) {
Yinghai Lu2944e162008-06-01 13:17:38 -07001018 mpc_new_phys = 0;
1019 printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
1020 mpc_new_length);
1021 }
1022
1023 if (!mpc_new_phys) {
1024 unsigned char old, new;
1025 /* check if we can change the postion */
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +05301026 mpc->checksum = 0;
1027 old = mpf_checksum((unsigned char *)mpc, mpc->length);
1028 mpc->checksum = 0xff;
1029 new = mpf_checksum((unsigned char *)mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -07001030 if (old == new) {
1031 printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
1032 return 0;
1033 }
1034 printk(KERN_INFO "use in-positon replacing\n");
1035 } else {
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301036 mpf->physptr = mpc_new_phys;
Yinghai Lu2944e162008-06-01 13:17:38 -07001037 mpc_new = phys_to_virt(mpc_new_phys);
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +05301038 memcpy(mpc_new, mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -07001039 mpc = mpc_new;
1040 /* check if we can modify that */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301041 if (mpc_new_phys - mpf->physptr) {
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +05301042 struct mpf_intel *mpf_new;
Yinghai Lu2944e162008-06-01 13:17:38 -07001043 /* steal 16 bytes from [0, 1k) */
1044 printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
1045 mpf_new = phys_to_virt(0x400 - 16);
1046 memcpy(mpf_new, mpf, 16);
1047 mpf = mpf_new;
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301048 mpf->physptr = mpc_new_phys;
Yinghai Lu2944e162008-06-01 13:17:38 -07001049 }
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301050 mpf->checksum = 0;
1051 mpf->checksum -= mpf_checksum((unsigned char *)mpf, 16);
1052 printk(KERN_INFO "physptr new: %x\n", mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -07001053 }
1054
1055 /*
1056 * only replace the one with mp_INT and
1057 * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
1058 * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
1059 * may need pci=routeirq for all coverage
1060 */
1061 replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
1062
1063 return 0;
1064}
1065
1066late_initcall(update_mp_table);