blob: b12fa5ce6f58c046084a4a6742d893d5c3d05128 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * (c) 1998, 1999, 2000 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
32#include <mach_apic.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040033#ifdef CONFIG_X86_32
Andi Kleen874c4fe2006-09-26 10:52:26 +020034#include <mach_apicdef.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <mach_mpparse.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040036#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Linus Torvalds1da177e2005-04-16 15:20:36 -070038/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 * Checksum an MP configuration block.
40 */
41
42static int __init mpf_checksum(unsigned char *mp, int len)
43{
44 int sum = 0;
45
46 while (len--)
47 sum += *mp++;
48
49 return sum & 0xFF;
50}
51
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +053052static void __init MP_processor_info(struct mpc_cpu *m)
Alexey Starikovskiyc853c672008-03-27 23:54:13 +030053{
54 int apicid;
Alexey Starikovskiy746f2242008-04-04 23:42:15 +040055 char *bootup_cpu = "";
Alexey Starikovskiyc853c672008-03-27 23:54:13 +030056
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053057 if (!(m->cpuflag & CPU_ENABLED)) {
Glauber Costa7b1292e2008-03-03 14:12:41 -030058 disabled_cpus++;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 return;
Glauber Costa7b1292e2008-03-03 14:12:41 -030060 }
Yinghai Lu64898a82008-07-19 18:01:16 -070061
62 if (x86_quirks->mpc_apic_id)
63 apicid = x86_quirks->mpc_apic_id(m);
Yinghai Luab530e12008-06-03 10:25:54 -070064 else
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053065 apicid = m->apicid;
Yinghai Lu64898a82008-07-19 18:01:16 -070066
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053067 if (m->cpuflag & CPU_BOOTPROCESSOR) {
Alexey Starikovskiy746f2242008-04-04 23:42:15 +040068 bootup_cpu = " (Bootup-CPU)";
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053069 boot_cpu_physical_apicid = m->apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 }
71
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053072 printk(KERN_INFO "Processor #%d%s\n", m->apicid, bootup_cpu);
73 generic_processor_info(apicid, m->apicver);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074}
75
Thomas Gleixner85cc35f2008-05-25 21:21:36 +020076#ifdef CONFIG_X86_IO_APIC
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +053077static void __init MP_bus_info(struct mpc_bus *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078{
79 char str[7];
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053080 memcpy(str, m->bustype, 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 str[6] = 0;
82
Yinghai Lu64898a82008-07-19 18:01:16 -070083 if (x86_quirks->mpc_oem_bus_info)
84 x86_quirks->mpc_oem_bus_info(m, str);
85 else
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053086 apic_printk(APIC_VERBOSE, "Bus #%d is %s\n", m->busid, str);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Andi Kleen5e4edbb2006-09-26 10:52:35 +020088#if MAX_MP_BUSSES < 256
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053089 if (m->busid >= MAX_MP_BUSSES) {
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070090 printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +040091 " is too large, max. supported is %d\n",
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053092 m->busid, str, MAX_MP_BUSSES - 1);
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070093 return;
94 }
Andi Kleen5e4edbb2006-09-26 10:52:35 +020095#endif
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070096
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +040097 if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053098 set_bit(m->busid, mp_bus_not_pci);
Jaswinder Singh Rajput103ceff2009-01-02 23:43:25 +053099#if defined(CONFIG_EISA) || defined(CONFIG_MCA)
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530100 mp_bus_id_to_type[m->busid] = MP_BUS_ISA;
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +0400101#endif
102 } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
Yinghai Lu64898a82008-07-19 18:01:16 -0700103 if (x86_quirks->mpc_oem_pci_bus)
104 x86_quirks->mpc_oem_pci_bus(m);
105
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530106 clear_bit(m->busid, mp_bus_not_pci);
Jaswinder Singh Rajput103ceff2009-01-02 23:43:25 +0530107#if defined(CONFIG_EISA) || defined(CONFIG_MCA)
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530108 mp_bus_id_to_type[m->busid] = MP_BUS_PCI;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400109 } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530110 mp_bus_id_to_type[m->busid] = MP_BUS_EISA;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400111 } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530112 mp_bus_id_to_type[m->busid] = MP_BUS_MCA;
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +0300113#endif
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +0400114 } else
115 printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116}
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200117#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400119#ifdef CONFIG_X86_IO_APIC
120
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300121static int bad_ioapic(unsigned long address)
122{
123 if (nr_ioapics >= MAX_IO_APICS) {
124 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
125 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
126 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
127 }
128 if (!address) {
129 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
130 " found in table, skipping!\n");
131 return 1;
132 }
133 return 0;
134}
135
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530136static void __init MP_ioapic_info(struct mpc_ioapic *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137{
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530138 if (!(m->flags & MPC_APIC_USABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 return;
140
Thomas Gleixner64883ab2008-01-30 13:30:35 +0100141 printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530142 m->apicid, m->apicver, m->apicaddr);
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300143
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530144 if (bad_ioapic(m->apicaddr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 return;
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300146
Jaswinder Singh Rajputb5ba7e62009-01-12 17:46:17 +0530147 mp_ioapics[nr_ioapics].apicaddr = m->apicaddr;
148 mp_ioapics[nr_ioapics].apicid = m->apicid;
149 mp_ioapics[nr_ioapics].type = m->type;
150 mp_ioapics[nr_ioapics].apicver = m->apicver;
151 mp_ioapics[nr_ioapics].flags = m->flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 nr_ioapics++;
153}
154
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530155static void print_MP_intsrc_info(struct mpc_intsrc *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200157 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530159 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbus,
160 m->srcbusirq, m->dstapic, m->dstirq);
Yinghai Lu2944e162008-06-01 13:17:38 -0700161}
162
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530163static void __init print_mp_irq_info(struct mpc_intsrc *mp_irq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700164{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200165 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
Yinghai Lu2944e162008-06-01 13:17:38 -0700166 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530167 mp_irq->irqtype, mp_irq->irqflag & 3,
168 (mp_irq->irqflag >> 2) & 3, mp_irq->srcbus,
169 mp_irq->srcbusirq, mp_irq->dstapic, mp_irq->dstirq);
Yinghai Lu2944e162008-06-01 13:17:38 -0700170}
171
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530172static void __init assign_to_mp_irq(struct mpc_intsrc *m,
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530173 struct mpc_intsrc *mp_irq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700174{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530175 mp_irq->dstapic = m->dstapic;
176 mp_irq->type = m->type;
177 mp_irq->irqtype = m->irqtype;
178 mp_irq->irqflag = m->irqflag;
179 mp_irq->srcbus = m->srcbus;
180 mp_irq->srcbusirq = m->srcbusirq;
181 mp_irq->dstirq = m->dstirq;
Yinghai Lu2944e162008-06-01 13:17:38 -0700182}
183
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530184static void __init assign_to_mpc_intsrc(struct mpc_intsrc *mp_irq,
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530185 struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700186{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530187 m->dstapic = mp_irq->dstapic;
188 m->type = mp_irq->type;
189 m->irqtype = mp_irq->irqtype;
190 m->irqflag = mp_irq->irqflag;
191 m->srcbus = mp_irq->srcbus;
192 m->srcbusirq = mp_irq->srcbusirq;
193 m->dstirq = mp_irq->dstirq;
Yinghai Lu2944e162008-06-01 13:17:38 -0700194}
195
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530196static int __init mp_irq_mpc_intsrc_cmp(struct mpc_intsrc *mp_irq,
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530197 struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700198{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530199 if (mp_irq->dstapic != m->dstapic)
Yinghai Lu2944e162008-06-01 13:17:38 -0700200 return 1;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530201 if (mp_irq->type != m->type)
Yinghai Lu2944e162008-06-01 13:17:38 -0700202 return 2;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530203 if (mp_irq->irqtype != m->irqtype)
Yinghai Lu2944e162008-06-01 13:17:38 -0700204 return 3;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530205 if (mp_irq->irqflag != m->irqflag)
Yinghai Lu2944e162008-06-01 13:17:38 -0700206 return 4;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530207 if (mp_irq->srcbus != m->srcbus)
Yinghai Lu2944e162008-06-01 13:17:38 -0700208 return 5;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530209 if (mp_irq->srcbusirq != m->srcbusirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700210 return 6;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530211 if (mp_irq->dstirq != m->dstirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700212 return 7;
213
214 return 0;
215}
216
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530217static void __init MP_intsrc_info(struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700218{
219 int i;
220
221 print_MP_intsrc_info(m);
222
Yinghai Lufcfa1462008-06-18 17:29:31 -0700223 for (i = 0; i < mp_irq_entries; i++) {
224 if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m))
225 return;
226 }
Yinghai Lu2944e162008-06-01 13:17:38 -0700227
228 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 if (++mp_irq_entries == MAX_IRQ_SOURCES)
230 panic("Max # of irq sources exceeded!!\n");
231}
232
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400233#endif
234
Jaswinder Singh Rajput8fb29522009-01-03 15:51:54 +0530235static void __init MP_lintsrc_info(struct mpc_lintsrc *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200237 apic_printk(APIC_VERBOSE, "Lint: type %d, pol %d, trig %d, bus %02x,"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
Jaswinder Singh Rajputb5ced7c2009-01-04 21:55:53 +0530239 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbusid,
240 m->srcbusirq, m->destapic, m->destapiclint);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241}
242
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243/*
244 * Read/parse the MPC
245 */
246
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530247static int __init smp_check_mpc(struct mpc_table *mpc, char *oem, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530250 if (memcmp(mpc->signature, MPC_SIGNATURE, 4)) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400251 printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530252 mpc->signature[0], mpc->signature[1],
253 mpc->signature[2], mpc->signature[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 return 0;
255 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530256 if (mpf_checksum((unsigned char *)mpc, mpc->length)) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400257 printk(KERN_ERR "MPTABLE: checksum error!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 return 0;
259 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530260 if (mpc->spec != 0x01 && mpc->spec != 0x04) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400261 printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530262 mpc->spec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 return 0;
264 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530265 if (!mpc->lapic) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400266 printk(KERN_ERR "MPTABLE: null local APIC address!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 return 0;
268 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530269 memcpy(oem, mpc->oem, 8);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400270 oem[8] = 0;
Yinghai Lu11a62a02008-05-12 15:43:38 +0200271 printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530273 memcpy(str, mpc->productid, 12);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400274 str[12] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
Yinghai Lu11a62a02008-05-12 15:43:38 +0200276 printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530278 printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->lapic);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Yinghai Lu2944e162008-06-01 13:17:38 -0700280 return 1;
281}
282
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530283static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early)
Yinghai Lu2944e162008-06-01 13:17:38 -0700284{
285 char str[16];
286 char oem[10];
287
288 int count = sizeof(*mpc);
289 unsigned char *mpt = ((unsigned char *)mpc) + count;
290
291 if (!smp_check_mpc(mpc, oem, str))
292 return 0;
293
294#ifdef CONFIG_X86_32
Ingo Molnar9c764242009-01-28 13:44:32 +0100295 generic_mps_oem_check(mpc, oem, str);
Yinghai Lu2944e162008-06-01 13:17:38 -0700296#endif
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400297 /* save the local APIC address, it might be non-default */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 if (!acpi_lapic)
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530299 mp_lapic_addr = mpc->lapic;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400301 if (early)
302 return 1;
303
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530304 if (mpc->oemptr && x86_quirks->smp_read_mpc_oem) {
305 struct mpc_oemtable *oem_table = (void *)(long)mpc->oemptr;
306 x86_quirks->smp_read_mpc_oem(oem_table, mpc->oemsize);
Yinghai Lu64898a82008-07-19 18:01:16 -0700307 }
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 /*
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400310 * Now process the configuration blocks.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 */
Yinghai Lu64898a82008-07-19 18:01:16 -0700312 if (x86_quirks->mpc_record)
313 *x86_quirks->mpc_record = 0;
314
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530315 while (count < mpc->length) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400316 switch (*mpt) {
317 case MP_PROCESSOR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 {
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +0530319 struct mpc_cpu *m = (struct mpc_cpu *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 /* ACPI may have already provided this data */
321 if (!acpi_lapic)
322 MP_processor_info(m);
323 mpt += sizeof(*m);
324 count += sizeof(*m);
325 break;
326 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400327 case MP_BUS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 {
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +0530329 struct mpc_bus *m = (struct mpc_bus *)mpt;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200330#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 MP_bus_info(m);
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200332#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 mpt += sizeof(*m);
334 count += sizeof(*m);
335 break;
336 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400337 case MP_IOAPIC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 {
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400339#ifdef CONFIG_X86_IO_APIC
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530340 struct mpc_ioapic *m = (struct mpc_ioapic *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 MP_ioapic_info(m);
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400342#endif
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530343 mpt += sizeof(struct mpc_ioapic);
344 count += sizeof(struct mpc_ioapic);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 break;
346 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400347 case MP_INTSRC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 {
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400349#ifdef CONFIG_X86_IO_APIC
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530350 struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
352 MP_intsrc_info(m);
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400353#endif
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530354 mpt += sizeof(struct mpc_intsrc);
355 count += sizeof(struct mpc_intsrc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 break;
357 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400358 case MP_LINTSRC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 {
Jaswinder Singh Rajput8fb29522009-01-03 15:51:54 +0530360 struct mpc_lintsrc *m =
361 (struct mpc_lintsrc *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 MP_lintsrc_info(m);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400363 mpt += sizeof(*m);
364 count += sizeof(*m);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 break;
366 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400367 default:
Yinghai Lu711554d2008-04-07 11:36:39 -0700368 /* wrong mptable */
369 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
370 printk(KERN_ERR "type %x\n", *mpt);
371 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530372 1, mpc, mpc->length, 1);
373 count = mpc->length;
Yinghai Lu711554d2008-04-07 11:36:39 -0700374 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 }
Yinghai Lu64898a82008-07-19 18:01:16 -0700376 if (x86_quirks->mpc_record)
377 (*x86_quirks->mpc_record)++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 }
Yinghai Lue0da3362008-06-08 18:29:22 -0700379
380#ifdef CONFIG_X86_GENERICARCH
381 generic_bigsmp_probe();
382#endif
383
Ingo Molnar72ce0162009-01-28 06:50:47 +0100384 if (apic->setup_apic_routing)
385 apic->setup_apic_routing();
386
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 if (!num_processors)
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400388 printk(KERN_ERR "MPTABLE: no processors registered!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 return num_processors;
390}
391
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400392#ifdef CONFIG_X86_IO_APIC
393
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394static int __init ELCR_trigger(unsigned int irq)
395{
396 unsigned int port;
397
398 port = 0x4d0 + (irq >> 3);
399 return (inb(port) >> (irq & 7)) & 1;
400}
401
402static void __init construct_default_ioirq_mptable(int mpc_default_type)
403{
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530404 struct mpc_intsrc intsrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 int i;
406 int ELCR_fallback = 0;
407
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530408 intsrc.type = MP_INTSRC;
409 intsrc.irqflag = 0; /* conforming */
410 intsrc.srcbus = 0;
Jaswinder Singh Rajputb5ba7e62009-01-12 17:46:17 +0530411 intsrc.dstapic = mp_ioapics[0].apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530413 intsrc.irqtype = mp_INT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
415 /*
416 * If true, we have an ISA/PCI system with no IRQ entries
417 * in the MP table. To prevent the PCI interrupts from being set up
418 * incorrectly, we try to use the ELCR. The sanity check to see if
419 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
420 * never be level sensitive, so we simply see if the ELCR agrees.
421 * If it does, we assume it's valid.
422 */
423 if (mpc_default_type == 5) {
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400424 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
425 "falling back to ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400427 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
428 ELCR_trigger(13))
429 printk(KERN_ERR "ELCR contains invalid data... "
430 "not using ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 else {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400432 printk(KERN_INFO
433 "Using ELCR to identify PCI interrupts\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 ELCR_fallback = 1;
435 }
436 }
437
438 for (i = 0; i < 16; i++) {
439 switch (mpc_default_type) {
440 case 2:
441 if (i == 0 || i == 13)
442 continue; /* IRQ0 & IRQ13 not connected */
443 /* fall through */
444 default:
445 if (i == 2)
446 continue; /* IRQ2 is never connected */
447 }
448
449 if (ELCR_fallback) {
450 /*
451 * If the ELCR indicates a level-sensitive interrupt, we
452 * copy that information over to the MP table in the
453 * irqflag field (level sensitive, active high polarity).
454 */
455 if (ELCR_trigger(i))
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530456 intsrc.irqflag = 13;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 else
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530458 intsrc.irqflag = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 }
460
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530461 intsrc.srcbusirq = i;
462 intsrc.dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 MP_intsrc_info(&intsrc);
464 }
465
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530466 intsrc.irqtype = mp_ExtINT;
467 intsrc.srcbusirq = 0;
468 intsrc.dstirq = 0; /* 8259A to INTIN0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 MP_intsrc_info(&intsrc);
470}
471
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400472
Marcin Slusarz39e00fe2008-08-11 00:09:38 +0200473static void __init construct_ioapic_table(int mpc_default_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474{
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530475 struct mpc_ioapic ioapic;
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +0530476 struct mpc_bus bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530478 bus.type = MP_BUS;
479 bus.busid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 switch (mpc_default_type) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400481 default:
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400482 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400483 mpc_default_type);
484 /* fall through */
485 case 1:
486 case 5:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530487 memcpy(bus.bustype, "ISA ", 6);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400488 break;
489 case 2:
490 case 6:
491 case 3:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530492 memcpy(bus.bustype, "EISA ", 6);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400493 break;
494 case 4:
495 case 7:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530496 memcpy(bus.bustype, "MCA ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 }
498 MP_bus_info(&bus);
499 if (mpc_default_type > 4) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530500 bus.busid = 1;
501 memcpy(bus.bustype, "PCI ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 MP_bus_info(&bus);
503 }
504
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530505 ioapic.type = MP_IOAPIC;
506 ioapic.apicid = 2;
507 ioapic.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
508 ioapic.flags = MPC_APIC_USABLE;
509 ioapic.apicaddr = 0xFEC00000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 MP_ioapic_info(&ioapic);
511
512 /*
513 * We set up most of the low 16 IO-APIC pins according to MPS rules.
514 */
515 construct_default_ioirq_mptable(mpc_default_type);
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200516}
517#else
Marcin Slusarz39e00fe2008-08-11 00:09:38 +0200518static inline void __init construct_ioapic_table(int mpc_default_type) { }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400519#endif
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200520
521static inline void __init construct_default_ISA_mptable(int mpc_default_type)
522{
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +0530523 struct mpc_cpu processor;
Jaswinder Singh Rajput8fb29522009-01-03 15:51:54 +0530524 struct mpc_lintsrc lintsrc;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200525 int linttypes[2] = { mp_ExtINT, mp_NMI };
526 int i;
527
528 /*
529 * local APIC has default address
530 */
531 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
532
533 /*
534 * 2 CPUs, numbered 0 & 1.
535 */
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530536 processor.type = MP_PROCESSOR;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200537 /* Either an integrated APIC or a discrete 82489DX. */
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530538 processor.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
539 processor.cpuflag = CPU_ENABLED;
540 processor.cpufeature = (boot_cpu_data.x86 << 8) |
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200541 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530542 processor.featureflag = boot_cpu_data.x86_capability[0];
543 processor.reserved[0] = 0;
544 processor.reserved[1] = 0;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200545 for (i = 0; i < 2; i++) {
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530546 processor.apicid = i;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200547 MP_processor_info(&processor);
548 }
549
550 construct_ioapic_table(mpc_default_type);
551
Jaswinder Singh Rajputb5ced7c2009-01-04 21:55:53 +0530552 lintsrc.type = MP_LINTSRC;
553 lintsrc.irqflag = 0; /* conforming */
554 lintsrc.srcbusid = 0;
555 lintsrc.srcbusirq = 0;
556 lintsrc.destapic = MP_APIC_ALL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 for (i = 0; i < 2; i++) {
Jaswinder Singh Rajputb5ced7c2009-01-04 21:55:53 +0530558 lintsrc.irqtype = linttypes[i];
559 lintsrc.destapiclint = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 MP_lintsrc_info(&lintsrc);
561 }
562}
563
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530564static struct mpf_intel *mpf_found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
566/*
567 * Scan the memory blocks for an SMP configuration block.
568 */
Ingo Molnar3b335532008-07-10 17:30:40 +0200569static void __init __get_smp_config(unsigned int early)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570{
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530571 struct mpf_intel *mpf = mpf_found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
Yinghai Lu69b88af2008-12-05 22:45:50 -0800573 if (!mpf)
574 return;
575
576 if (acpi_lapic && early)
577 return;
578
579 /*
580 * MPS doesn't support hyperthreading, aka only have
581 * thread 0 apic id in MPS table
582 */
583 if (acpi_lapic && acpi_ioapic)
584 return;
585
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700586 if (x86_quirks->mach_get_smp_config) {
587 if (x86_quirks->mach_get_smp_config(early))
Ingo Molnar3b335532008-07-10 17:30:40 +0200588 return;
589 }
Andi Kleen9adc1382008-12-04 13:33:35 +0100590
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400591 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530592 mpf->specification);
Alexey Starikovskiyb3e24162008-05-23 01:54:44 +0400593#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530594 if (mpf->feature2 & (1 << 7)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
596 pic_mode = 1;
597 } else {
598 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
599 pic_mode = 0;
600 }
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400601#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 /*
603 * Now see if we need to read further.
604 */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530605 if (mpf->feature1 != 0) {
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400606 if (early) {
607 /*
608 * local APIC has default address
609 */
610 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
611 return;
612 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400614 printk(KERN_INFO "Default MP configuration #%d\n",
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530615 mpf->feature1);
616 construct_default_ISA_mptable(mpf->feature1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530618 } else if (mpf->physptr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
620 /*
621 * Read the physical hardware table. Anything here will
622 * override the defaults.
623 */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530624 if (!smp_read_mpc(phys_to_virt(mpf->physptr), early)) {
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400625#ifdef CONFIG_X86_LOCAL_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 smp_found_config = 0;
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400627#endif
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400628 printk(KERN_ERR
629 "BIOS bug, MP table errors detected!...\n");
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400630 printk(KERN_ERR "... disabling SMP support. "
631 "(tell your hw vendor)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 return;
633 }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400634
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400635 if (early)
636 return;
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400637#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 /*
639 * If there are no explicit MP IRQ entries, then we are
640 * broken. We set up most of the low 16 IO-APIC pins to
641 * ISA defaults and hope it will work.
642 */
643 if (!mp_irq_entries) {
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +0530644 struct mpc_bus bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400646 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
647 "using default mptable. "
648 "(tell your hw vendor)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530650 bus.type = MP_BUS;
651 bus.busid = 0;
652 memcpy(bus.bustype, "ISA ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 MP_bus_info(&bus);
654
655 construct_default_ioirq_mptable(0);
656 }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400657#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 } else
659 BUG();
660
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400661 if (!early)
662 printk(KERN_INFO "Processors: %d\n", num_processors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 /*
664 * Only use the first configuration found.
665 */
666}
667
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400668void __init early_get_smp_config(void)
669{
670 __get_smp_config(1);
671}
672
673void __init get_smp_config(void)
674{
675 __get_smp_config(0);
676}
677
678static int __init smp_scan_config(unsigned long base, unsigned long length,
679 unsigned reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680{
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400681 unsigned int *bp = phys_to_virt(base);
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530682 struct mpf_intel *mpf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200684 apic_printk(APIC_VERBOSE, "Scan SMP from %p for %ld bytes.\n",
685 bp, length);
Akinobu Mita5d47a272008-04-19 23:55:11 +0900686 BUILD_BUG_ON(sizeof(*mpf) != 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
688 while (length > 0) {
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530689 mpf = (struct mpf_intel *)bp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 if ((*bp == SMP_MAGIC_IDENT) &&
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530691 (mpf->length == 1) &&
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400692 !mpf_checksum((unsigned char *)bp, 16) &&
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530693 ((mpf->specification == 1)
694 || (mpf->specification == 4))) {
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400695#ifdef CONFIG_X86_LOCAL_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 smp_found_config = 1;
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400697#endif
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400698 mpf_found = mpf;
Yinghai Lub1f006b2008-06-09 18:11:36 -0700699
Ingo Molnare91a3b42008-01-30 13:33:08 +0100700 printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400701 mpf, virt_to_phys(mpf));
Yinghai Lub1f006b2008-06-09 18:11:36 -0700702
703 if (!reserve)
704 return 1;
Yinghai Lud2dbf342008-06-13 02:00:56 -0700705 reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE,
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800706 BOOTMEM_DEFAULT);
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530707 if (mpf->physptr) {
Yinghai Lud2dbf342008-06-13 02:00:56 -0700708 unsigned long size = PAGE_SIZE;
709#ifdef CONFIG_X86_32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 /*
711 * We cannot access to MPC table to compute
712 * table size yet, as only few megabytes from
713 * the bottom is mapped now.
714 * PC-9800's MPC table places on the very last
715 * of physical memory; so that simply reserving
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530716 * PAGE_SIZE from mpf->physptr yields BUG()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 * in reserve_bootmem.
718 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 unsigned long end = max_low_pfn * PAGE_SIZE;
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530720 if (mpf->physptr + size > end)
721 size = end - mpf->physptr;
Yinghai Lud2dbf342008-06-13 02:00:56 -0700722#endif
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530723 reserve_bootmem_generic(mpf->physptr, size,
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800724 BOOTMEM_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 }
726
Yinghai Lud2dbf342008-06-13 02:00:56 -0700727 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 }
729 bp += 4;
730 length -= 16;
731 }
732 return 0;
733}
734
Ingo Molnar3b335532008-07-10 17:30:40 +0200735static void __init __find_smp_config(unsigned int reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736{
737 unsigned int address;
738
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700739 if (x86_quirks->mach_find_smp_config) {
740 if (x86_quirks->mach_find_smp_config(reserve))
Ingo Molnar3b335532008-07-10 17:30:40 +0200741 return;
742 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 /*
744 * FIXME: Linux assumes you have 640K of base ram..
745 * this continues the error...
746 *
747 * 1) Scan the bottom 1K for a signature
748 * 2) Scan the top 1K of base RAM
749 * 3) Scan the 64K of bios
750 */
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400751 if (smp_scan_config(0x0, 0x400, reserve) ||
752 smp_scan_config(639 * 0x400, 0x400, reserve) ||
753 smp_scan_config(0xF0000, 0x10000, reserve))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 return;
755 /*
756 * If it is an SMP machine we should know now, unless the
757 * configuration is in an EISA/MCA bus machine with an
758 * extended bios data area.
759 *
760 * there is a real-mode segmented pointer pointing to the
761 * 4K EBDA area at 0x40E, calculate and scan it here.
762 *
763 * NOTE! There are Linux loaders that will corrupt the EBDA
764 * area, and as such this kind of SMP config may be less
765 * trustworthy, simply because the SMP table may have been
766 * stomped on during early boot. These loaders are buggy and
767 * should be fixed.
768 *
769 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
770 */
771
772 address = get_bios_ebda();
773 if (address)
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400774 smp_scan_config(address, 0x400, reserve);
775}
776
777void __init early_find_smp_config(void)
778{
779 __find_smp_config(0);
780}
781
782void __init find_smp_config(void)
783{
784 __find_smp_config(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785}
Yinghai Lu2944e162008-06-01 13:17:38 -0700786
787#ifdef CONFIG_X86_IO_APIC
788static u8 __initdata irq_used[MAX_IRQ_SOURCES];
789
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530790static int __init get_MP_intsrc_index(struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700791{
792 int i;
793
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530794 if (m->irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700795 return 0;
796
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530797 if (m->irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700798 return 0;
799
800 /* not legacy */
801
802 for (i = 0; i < mp_irq_entries; i++) {
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530803 if (mp_irqs[i].irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700804 continue;
805
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530806 if (mp_irqs[i].irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700807 continue;
808
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530809 if (mp_irqs[i].srcbus != m->srcbus)
Yinghai Lu2944e162008-06-01 13:17:38 -0700810 continue;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530811 if (mp_irqs[i].srcbusirq != m->srcbusirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700812 continue;
813 if (irq_used[i]) {
814 /* already claimed */
815 return -2;
816 }
817 irq_used[i] = 1;
818 return i;
819 }
820
821 /* not found */
822 return -1;
823}
824
825#define SPARE_SLOT_NUM 20
826
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530827static struct mpc_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
Yinghai Lu2944e162008-06-01 13:17:38 -0700828#endif
829
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530830static int __init replace_intsrc_all(struct mpc_table *mpc,
Yinghai Lu2944e162008-06-01 13:17:38 -0700831 unsigned long mpc_new_phys,
832 unsigned long mpc_new_length)
833{
834#ifdef CONFIG_X86_IO_APIC
835 int i;
836 int nr_m_spare = 0;
837#endif
838
839 int count = sizeof(*mpc);
840 unsigned char *mpt = ((unsigned char *)mpc) + count;
841
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530842 printk(KERN_INFO "mpc_length %x\n", mpc->length);
843 while (count < mpc->length) {
Yinghai Lu2944e162008-06-01 13:17:38 -0700844 switch (*mpt) {
845 case MP_PROCESSOR:
846 {
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +0530847 struct mpc_cpu *m = (struct mpc_cpu *)mpt;
Yinghai Lu2944e162008-06-01 13:17:38 -0700848 mpt += sizeof(*m);
849 count += sizeof(*m);
850 break;
851 }
852 case MP_BUS:
853 {
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +0530854 struct mpc_bus *m = (struct mpc_bus *)mpt;
Yinghai Lu2944e162008-06-01 13:17:38 -0700855 mpt += sizeof(*m);
856 count += sizeof(*m);
857 break;
858 }
859 case MP_IOAPIC:
860 {
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530861 mpt += sizeof(struct mpc_ioapic);
862 count += sizeof(struct mpc_ioapic);
Yinghai Lu2944e162008-06-01 13:17:38 -0700863 break;
864 }
865 case MP_INTSRC:
866 {
867#ifdef CONFIG_X86_IO_APIC
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530868 struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
Yinghai Lu2944e162008-06-01 13:17:38 -0700869
870 printk(KERN_INFO "OLD ");
871 print_MP_intsrc_info(m);
872 i = get_MP_intsrc_index(m);
873 if (i > 0) {
874 assign_to_mpc_intsrc(&mp_irqs[i], m);
875 printk(KERN_INFO "NEW ");
876 print_mp_irq_info(&mp_irqs[i]);
877 } else if (!i) {
878 /* legacy, do nothing */
879 } else if (nr_m_spare < SPARE_SLOT_NUM) {
880 /*
881 * not found (-1), or duplicated (-2)
882 * are invalid entries,
883 * we need to use the slot later
884 */
885 m_spare[nr_m_spare] = m;
886 nr_m_spare++;
887 }
888#endif
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530889 mpt += sizeof(struct mpc_intsrc);
890 count += sizeof(struct mpc_intsrc);
Yinghai Lu2944e162008-06-01 13:17:38 -0700891 break;
892 }
893 case MP_LINTSRC:
894 {
Jaswinder Singh Rajput8fb29522009-01-03 15:51:54 +0530895 struct mpc_lintsrc *m =
896 (struct mpc_lintsrc *)mpt;
Yinghai Lu2944e162008-06-01 13:17:38 -0700897 mpt += sizeof(*m);
898 count += sizeof(*m);
899 break;
900 }
901 default:
902 /* wrong mptable */
903 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
904 printk(KERN_ERR "type %x\n", *mpt);
905 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530906 1, mpc, mpc->length, 1);
Yinghai Lu2944e162008-06-01 13:17:38 -0700907 goto out;
908 }
909 }
910
911#ifdef CONFIG_X86_IO_APIC
912 for (i = 0; i < mp_irq_entries; i++) {
913 if (irq_used[i])
914 continue;
915
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530916 if (mp_irqs[i].irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700917 continue;
918
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530919 if (mp_irqs[i].irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700920 continue;
921
922 if (nr_m_spare > 0) {
923 printk(KERN_INFO "*NEW* found ");
924 nr_m_spare--;
925 assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
926 m_spare[nr_m_spare] = NULL;
927 } else {
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530928 struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
929 count += sizeof(struct mpc_intsrc);
Yinghai Lu2944e162008-06-01 13:17:38 -0700930 if (!mpc_new_phys) {
931 printk(KERN_INFO "No spare slots, try to append...take your risk, new mpc_length %x\n", count);
932 } else {
933 if (count <= mpc_new_length)
934 printk(KERN_INFO "No spare slots, try to append..., new mpc_length %x\n", count);
935 else {
936 printk(KERN_ERR "mpc_new_length %lx is too small\n", mpc_new_length);
937 goto out;
938 }
939 }
940 assign_to_mpc_intsrc(&mp_irqs[i], m);
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530941 mpc->length = count;
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530942 mpt += sizeof(struct mpc_intsrc);
Yinghai Lu2944e162008-06-01 13:17:38 -0700943 }
944 print_mp_irq_info(&mp_irqs[i]);
945 }
946#endif
947out:
948 /* update checksum */
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530949 mpc->checksum = 0;
950 mpc->checksum -= mpf_checksum((unsigned char *)mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -0700951
952 return 0;
953}
954
Yinghai Lufcfa1462008-06-18 17:29:31 -0700955static int __initdata enable_update_mptable;
956
Yinghai Lu2944e162008-06-01 13:17:38 -0700957static int __init update_mptable_setup(char *str)
958{
959 enable_update_mptable = 1;
960 return 0;
961}
962early_param("update_mptable", update_mptable_setup);
963
964static unsigned long __initdata mpc_new_phys;
965static unsigned long mpc_new_length __initdata = 4096;
966
967/* alloc_mptable or alloc_mptable=4k */
968static int __initdata alloc_mptable;
969static int __init parse_alloc_mptable_opt(char *p)
970{
971 enable_update_mptable = 1;
972 alloc_mptable = 1;
973 if (!p)
974 return 0;
975 mpc_new_length = memparse(p, &p);
976 return 0;
977}
978early_param("alloc_mptable", parse_alloc_mptable_opt);
979
980void __init early_reserve_e820_mpc_new(void)
981{
982 if (enable_update_mptable && alloc_mptable) {
983 u64 startt = 0;
984#ifdef CONFIG_X86_TRAMPOLINE
985 startt = TRAMPOLINE_BASE;
986#endif
987 mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
988 }
989}
990
991static int __init update_mp_table(void)
992{
993 char str[16];
994 char oem[10];
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530995 struct mpf_intel *mpf;
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530996 struct mpc_table *mpc, *mpc_new;
Yinghai Lu2944e162008-06-01 13:17:38 -0700997
998 if (!enable_update_mptable)
999 return 0;
1000
1001 mpf = mpf_found;
1002 if (!mpf)
1003 return 0;
1004
1005 /*
1006 * Now see if we need to go further.
1007 */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301008 if (mpf->feature1 != 0)
Yinghai Lu2944e162008-06-01 13:17:38 -07001009 return 0;
1010
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301011 if (!mpf->physptr)
Yinghai Lu2944e162008-06-01 13:17:38 -07001012 return 0;
1013
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301014 mpc = phys_to_virt(mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -07001015
1016 if (!smp_check_mpc(mpc, oem, str))
1017 return 0;
1018
1019 printk(KERN_INFO "mpf: %lx\n", virt_to_phys(mpf));
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301020 printk(KERN_INFO "physptr: %x\n", mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -07001021
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +05301022 if (mpc_new_phys && mpc->length > mpc_new_length) {
Yinghai Lu2944e162008-06-01 13:17:38 -07001023 mpc_new_phys = 0;
1024 printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
1025 mpc_new_length);
1026 }
1027
1028 if (!mpc_new_phys) {
1029 unsigned char old, new;
1030 /* check if we can change the postion */
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +05301031 mpc->checksum = 0;
1032 old = mpf_checksum((unsigned char *)mpc, mpc->length);
1033 mpc->checksum = 0xff;
1034 new = mpf_checksum((unsigned char *)mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -07001035 if (old == new) {
1036 printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
1037 return 0;
1038 }
1039 printk(KERN_INFO "use in-positon replacing\n");
1040 } else {
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301041 mpf->physptr = mpc_new_phys;
Yinghai Lu2944e162008-06-01 13:17:38 -07001042 mpc_new = phys_to_virt(mpc_new_phys);
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +05301043 memcpy(mpc_new, mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -07001044 mpc = mpc_new;
1045 /* check if we can modify that */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301046 if (mpc_new_phys - mpf->physptr) {
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +05301047 struct mpf_intel *mpf_new;
Yinghai Lu2944e162008-06-01 13:17:38 -07001048 /* steal 16 bytes from [0, 1k) */
1049 printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
1050 mpf_new = phys_to_virt(0x400 - 16);
1051 memcpy(mpf_new, mpf, 16);
1052 mpf = mpf_new;
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301053 mpf->physptr = mpc_new_phys;
Yinghai Lu2944e162008-06-01 13:17:38 -07001054 }
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301055 mpf->checksum = 0;
1056 mpf->checksum -= mpf_checksum((unsigned char *)mpf, 16);
1057 printk(KERN_INFO "physptr new: %x\n", mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -07001058 }
1059
1060 /*
1061 * only replace the one with mp_INT and
1062 * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
1063 * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
1064 * may need pci=routeirq for all coverage
1065 */
1066 replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
1067
1068 return 0;
1069}
1070
1071late_initcall(update_mp_table);