blob: b2179fdf0ff78de304eac44f99ed22810a5dbe1f [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>
Yinghai Lu629e15d2009-05-15 13:05:16 -070020#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <asm/mtrr.h>
23#include <asm/mpspec.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040024#include <asm/pgalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/io_apic.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040026#include <asm/proto.h>
Alexey Starikovskiyce3fe6b2008-03-17 22:08:17 +030027#include <asm/bios_ebda.h>
Yinghai Lu2944e162008-06-01 13:17:38 -070028#include <asm/e820.h>
29#include <asm/trampoline.h>
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -070030#include <asm/setup.h>
Jaswinder Singh Rajput4884d8e2009-01-11 18:38:55 +053031#include <asm/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Ingo Molnar7b6aa332009-02-17 13:58:15 +010033#include <asm/apic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 * Checksum an MP configuration block.
36 */
37
38static int __init mpf_checksum(unsigned char *mp, int len)
39{
40 int sum = 0;
41
42 while (len--)
43 sum += *mp++;
44
45 return sum & 0xFF;
46}
47
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +053048static void __init MP_processor_info(struct mpc_cpu *m)
Alexey Starikovskiyc853c672008-03-27 23:54:13 +030049{
50 int apicid;
Alexey Starikovskiy746f2242008-04-04 23:42:15 +040051 char *bootup_cpu = "";
Alexey Starikovskiyc853c672008-03-27 23:54:13 +030052
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053053 if (!(m->cpuflag & CPU_ENABLED)) {
Glauber Costa7b1292e2008-03-03 14:12:41 -030054 disabled_cpus++;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 return;
Glauber Costa7b1292e2008-03-03 14:12:41 -030056 }
Yinghai Lu64898a82008-07-19 18:01:16 -070057
58 if (x86_quirks->mpc_apic_id)
59 apicid = x86_quirks->mpc_apic_id(m);
Yinghai Luab530e12008-06-03 10:25:54 -070060 else
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053061 apicid = m->apicid;
Yinghai Lu64898a82008-07-19 18:01:16 -070062
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053063 if (m->cpuflag & CPU_BOOTPROCESSOR) {
Alexey Starikovskiy746f2242008-04-04 23:42:15 +040064 bootup_cpu = " (Bootup-CPU)";
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053065 boot_cpu_physical_apicid = m->apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 }
67
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053068 printk(KERN_INFO "Processor #%d%s\n", m->apicid, bootup_cpu);
69 generic_processor_info(apicid, m->apicver);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070}
71
Thomas Gleixner85cc35f2008-05-25 21:21:36 +020072#ifdef CONFIG_X86_IO_APIC
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +053073static void __init MP_bus_info(struct mpc_bus *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
75 char str[7];
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053076 memcpy(str, m->bustype, 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 str[6] = 0;
78
Yinghai Lu64898a82008-07-19 18:01:16 -070079 if (x86_quirks->mpc_oem_bus_info)
80 x86_quirks->mpc_oem_bus_info(m, str);
81 else
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053082 apic_printk(APIC_VERBOSE, "Bus #%d is %s\n", m->busid, str);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Andi Kleen5e4edbb2006-09-26 10:52:35 +020084#if MAX_MP_BUSSES < 256
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053085 if (m->busid >= MAX_MP_BUSSES) {
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070086 printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +040087 " is too large, max. supported is %d\n",
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053088 m->busid, str, MAX_MP_BUSSES - 1);
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070089 return;
90 }
Andi Kleen5e4edbb2006-09-26 10:52:35 +020091#endif
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070092
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +040093 if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053094 set_bit(m->busid, mp_bus_not_pci);
Jaswinder Singh Rajput103ceff2009-01-02 23:43:25 +053095#if defined(CONFIG_EISA) || defined(CONFIG_MCA)
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053096 mp_bus_id_to_type[m->busid] = MP_BUS_ISA;
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +040097#endif
98 } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
Yinghai Lu64898a82008-07-19 18:01:16 -070099 if (x86_quirks->mpc_oem_pci_bus)
100 x86_quirks->mpc_oem_pci_bus(m);
101
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530102 clear_bit(m->busid, mp_bus_not_pci);
Jaswinder Singh Rajput103ceff2009-01-02 23:43:25 +0530103#if defined(CONFIG_EISA) || defined(CONFIG_MCA)
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530104 mp_bus_id_to_type[m->busid] = MP_BUS_PCI;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400105 } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530106 mp_bus_id_to_type[m->busid] = MP_BUS_EISA;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400107 } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530108 mp_bus_id_to_type[m->busid] = MP_BUS_MCA;
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +0300109#endif
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +0400110 } else
111 printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112}
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400113
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300114static int bad_ioapic(unsigned long address)
115{
116 if (nr_ioapics >= MAX_IO_APICS) {
117 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
118 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
119 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
120 }
121 if (!address) {
122 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
123 " found in table, skipping!\n");
124 return 1;
125 }
126 return 0;
127}
128
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530129static void __init MP_ioapic_info(struct mpc_ioapic *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130{
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530131 if (!(m->flags & MPC_APIC_USABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 return;
133
Thomas Gleixner64883ab2008-01-30 13:30:35 +0100134 printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530135 m->apicid, m->apicver, m->apicaddr);
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300136
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530137 if (bad_ioapic(m->apicaddr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 return;
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300139
Jaswinder Singh Rajputb5ba7e62009-01-12 17:46:17 +0530140 mp_ioapics[nr_ioapics].apicaddr = m->apicaddr;
141 mp_ioapics[nr_ioapics].apicid = m->apicid;
142 mp_ioapics[nr_ioapics].type = m->type;
143 mp_ioapics[nr_ioapics].apicver = m->apicver;
144 mp_ioapics[nr_ioapics].flags = m->flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 nr_ioapics++;
146}
147
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530148static void print_MP_intsrc_info(struct mpc_intsrc *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200150 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530152 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbus,
153 m->srcbusirq, m->dstapic, m->dstirq);
Yinghai Lu2944e162008-06-01 13:17:38 -0700154}
155
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530156static void __init print_mp_irq_info(struct mpc_intsrc *mp_irq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700157{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200158 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
Yinghai Lu2944e162008-06-01 13:17:38 -0700159 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530160 mp_irq->irqtype, mp_irq->irqflag & 3,
161 (mp_irq->irqflag >> 2) & 3, mp_irq->srcbus,
162 mp_irq->srcbusirq, mp_irq->dstapic, mp_irq->dstirq);
Yinghai Lu2944e162008-06-01 13:17:38 -0700163}
164
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530165static void __init assign_to_mp_irq(struct mpc_intsrc *m,
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530166 struct mpc_intsrc *mp_irq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700167{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530168 mp_irq->dstapic = m->dstapic;
169 mp_irq->type = m->type;
170 mp_irq->irqtype = m->irqtype;
171 mp_irq->irqflag = m->irqflag;
172 mp_irq->srcbus = m->srcbus;
173 mp_irq->srcbusirq = m->srcbusirq;
174 mp_irq->dstirq = m->dstirq;
Yinghai Lu2944e162008-06-01 13:17:38 -0700175}
176
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530177static void __init assign_to_mpc_intsrc(struct mpc_intsrc *mp_irq,
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530178 struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700179{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530180 m->dstapic = mp_irq->dstapic;
181 m->type = mp_irq->type;
182 m->irqtype = mp_irq->irqtype;
183 m->irqflag = mp_irq->irqflag;
184 m->srcbus = mp_irq->srcbus;
185 m->srcbusirq = mp_irq->srcbusirq;
186 m->dstirq = mp_irq->dstirq;
Yinghai Lu2944e162008-06-01 13:17:38 -0700187}
188
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530189static int __init mp_irq_mpc_intsrc_cmp(struct mpc_intsrc *mp_irq,
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530190 struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700191{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530192 if (mp_irq->dstapic != m->dstapic)
Yinghai Lu2944e162008-06-01 13:17:38 -0700193 return 1;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530194 if (mp_irq->type != m->type)
Yinghai Lu2944e162008-06-01 13:17:38 -0700195 return 2;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530196 if (mp_irq->irqtype != m->irqtype)
Yinghai Lu2944e162008-06-01 13:17:38 -0700197 return 3;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530198 if (mp_irq->irqflag != m->irqflag)
Yinghai Lu2944e162008-06-01 13:17:38 -0700199 return 4;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530200 if (mp_irq->srcbus != m->srcbus)
Yinghai Lu2944e162008-06-01 13:17:38 -0700201 return 5;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530202 if (mp_irq->srcbusirq != m->srcbusirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700203 return 6;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530204 if (mp_irq->dstirq != m->dstirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700205 return 7;
206
207 return 0;
208}
209
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530210static void __init MP_intsrc_info(struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700211{
212 int i;
213
214 print_MP_intsrc_info(m);
215
Yinghai Lufcfa1462008-06-18 17:29:31 -0700216 for (i = 0; i < mp_irq_entries; i++) {
217 if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m))
218 return;
219 }
Yinghai Lu2944e162008-06-01 13:17:38 -0700220
221 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 if (++mp_irq_entries == MAX_IRQ_SOURCES)
223 panic("Max # of irq sources exceeded!!\n");
224}
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530225#else /* CONFIG_X86_IO_APIC */
226static inline void __init MP_bus_info(struct mpc_bus *m) {}
227static inline void __init MP_ioapic_info(struct mpc_ioapic *m) {}
228static inline void __init MP_intsrc_info(struct mpc_intsrc *m) {}
229#endif /* CONFIG_X86_IO_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400231
Jaswinder Singh Rajput8fb29522009-01-03 15:51:54 +0530232static void __init MP_lintsrc_info(struct mpc_lintsrc *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200234 apic_printk(APIC_VERBOSE, "Lint: type %d, pol %d, trig %d, bus %02x,"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
Jaswinder Singh Rajputb5ced7c2009-01-04 21:55:53 +0530236 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbusid,
237 m->srcbusirq, m->destapic, m->destapiclint);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238}
239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240/*
241 * Read/parse the MPC
242 */
243
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530244static int __init smp_check_mpc(struct mpc_table *mpc, char *oem, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530247 if (memcmp(mpc->signature, MPC_SIGNATURE, 4)) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400248 printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530249 mpc->signature[0], mpc->signature[1],
250 mpc->signature[2], mpc->signature[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 return 0;
252 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530253 if (mpf_checksum((unsigned char *)mpc, mpc->length)) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400254 printk(KERN_ERR "MPTABLE: checksum error!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 return 0;
256 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530257 if (mpc->spec != 0x01 && mpc->spec != 0x04) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400258 printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530259 mpc->spec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 return 0;
261 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530262 if (!mpc->lapic) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400263 printk(KERN_ERR "MPTABLE: null local APIC address!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 return 0;
265 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530266 memcpy(oem, mpc->oem, 8);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400267 oem[8] = 0;
Yinghai Lu11a62a02008-05-12 15:43:38 +0200268 printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530270 memcpy(str, mpc->productid, 12);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400271 str[12] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
Yinghai Lu11a62a02008-05-12 15:43:38 +0200273 printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530275 printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->lapic);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Yinghai Lu2944e162008-06-01 13:17:38 -0700277 return 1;
278}
279
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530280static void skip_entry(unsigned char **ptr, int *count, int size)
281{
282 *ptr += size;
283 *count += size;
284}
285
Jaswinder Singh Rajput5a5737e2009-03-21 13:28:39 +0530286static void __init smp_dump_mptable(struct mpc_table *mpc, unsigned char *mpt)
287{
288 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n"
289 "type %x\n", *mpt);
290 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
291 1, mpc, mpc->length, 1);
292}
293
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530294static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early)
Yinghai Lu2944e162008-06-01 13:17:38 -0700295{
296 char str[16];
297 char oem[10];
298
299 int count = sizeof(*mpc);
300 unsigned char *mpt = ((unsigned char *)mpc) + count;
301
302 if (!smp_check_mpc(mpc, oem, str))
303 return 0;
304
305#ifdef CONFIG_X86_32
Ingo Molnar9c764242009-01-28 13:44:32 +0100306 generic_mps_oem_check(mpc, oem, str);
Yinghai Lu2944e162008-06-01 13:17:38 -0700307#endif
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400308 /* save the local APIC address, it might be non-default */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 if (!acpi_lapic)
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530310 mp_lapic_addr = mpc->lapic;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400312 if (early)
313 return 1;
314
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530315 if (mpc->oemptr && x86_quirks->smp_read_mpc_oem) {
316 struct mpc_oemtable *oem_table = (void *)(long)mpc->oemptr;
317 x86_quirks->smp_read_mpc_oem(oem_table, mpc->oemsize);
Yinghai Lu64898a82008-07-19 18:01:16 -0700318 }
319
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 /*
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400321 * Now process the configuration blocks.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 */
Thomas Gleixnerf4848472009-08-20 12:05:01 +0200323 x86_init.mpparse.mpc_record(0);
Yinghai Lu64898a82008-07-19 18:01:16 -0700324
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530325 while (count < mpc->length) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400326 switch (*mpt) {
327 case MP_PROCESSOR:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530328 /* ACPI may have already provided this data */
329 if (!acpi_lapic)
Ingo Molnarc58603e2009-03-19 08:50:35 +0100330 MP_processor_info((struct mpc_cpu *)mpt);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530331 skip_entry(&mpt, &count, sizeof(struct mpc_cpu));
332 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400333 case MP_BUS:
Ingo Molnarc58603e2009-03-19 08:50:35 +0100334 MP_bus_info((struct mpc_bus *)mpt);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530335 skip_entry(&mpt, &count, sizeof(struct mpc_bus));
336 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400337 case MP_IOAPIC:
Ingo Molnarc58603e2009-03-19 08:50:35 +0100338 MP_ioapic_info((struct mpc_ioapic *)mpt);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530339 skip_entry(&mpt, &count, sizeof(struct mpc_ioapic));
340 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400341 case MP_INTSRC:
Ingo Molnarc58603e2009-03-19 08:50:35 +0100342 MP_intsrc_info((struct mpc_intsrc *)mpt);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530343 skip_entry(&mpt, &count, sizeof(struct mpc_intsrc));
344 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400345 case MP_LINTSRC:
Ingo Molnarc58603e2009-03-19 08:50:35 +0100346 MP_lintsrc_info((struct mpc_lintsrc *)mpt);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530347 skip_entry(&mpt, &count, sizeof(struct mpc_lintsrc));
348 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400349 default:
Yinghai Lu711554d2008-04-07 11:36:39 -0700350 /* wrong mptable */
Jaswinder Singh Rajput5a5737e2009-03-21 13:28:39 +0530351 smp_dump_mptable(mpc, mpt);
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530352 count = mpc->length;
Yinghai Lu711554d2008-04-07 11:36:39 -0700353 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 }
Thomas Gleixnerf4848472009-08-20 12:05:01 +0200355 x86_init.mpparse.mpc_record(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 }
Yinghai Lue0da3362008-06-08 18:29:22 -0700357
Yinghai Lu26f7ef12009-01-29 14:19:22 -0800358#ifdef CONFIG_X86_BIGSMP
359 generic_bigsmp_probe();
Yinghai Lue0da3362008-06-08 18:29:22 -0700360#endif
361
Ingo Molnar72ce0162009-01-28 06:50:47 +0100362 if (apic->setup_apic_routing)
363 apic->setup_apic_routing();
364
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 if (!num_processors)
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400366 printk(KERN_ERR "MPTABLE: no processors registered!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 return num_processors;
368}
369
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400370#ifdef CONFIG_X86_IO_APIC
371
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372static int __init ELCR_trigger(unsigned int irq)
373{
374 unsigned int port;
375
376 port = 0x4d0 + (irq >> 3);
377 return (inb(port) >> (irq & 7)) & 1;
378}
379
380static void __init construct_default_ioirq_mptable(int mpc_default_type)
381{
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530382 struct mpc_intsrc intsrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 int i;
384 int ELCR_fallback = 0;
385
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530386 intsrc.type = MP_INTSRC;
387 intsrc.irqflag = 0; /* conforming */
388 intsrc.srcbus = 0;
Jaswinder Singh Rajputb5ba7e62009-01-12 17:46:17 +0530389 intsrc.dstapic = mp_ioapics[0].apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530391 intsrc.irqtype = mp_INT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
393 /*
394 * If true, we have an ISA/PCI system with no IRQ entries
395 * in the MP table. To prevent the PCI interrupts from being set up
396 * incorrectly, we try to use the ELCR. The sanity check to see if
397 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
398 * never be level sensitive, so we simply see if the ELCR agrees.
399 * If it does, we assume it's valid.
400 */
401 if (mpc_default_type == 5) {
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400402 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
403 "falling back to ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400405 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
406 ELCR_trigger(13))
407 printk(KERN_ERR "ELCR contains invalid data... "
408 "not using ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 else {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400410 printk(KERN_INFO
411 "Using ELCR to identify PCI interrupts\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 ELCR_fallback = 1;
413 }
414 }
415
416 for (i = 0; i < 16; i++) {
417 switch (mpc_default_type) {
418 case 2:
419 if (i == 0 || i == 13)
420 continue; /* IRQ0 & IRQ13 not connected */
421 /* fall through */
422 default:
423 if (i == 2)
424 continue; /* IRQ2 is never connected */
425 }
426
427 if (ELCR_fallback) {
428 /*
429 * If the ELCR indicates a level-sensitive interrupt, we
430 * copy that information over to the MP table in the
431 * irqflag field (level sensitive, active high polarity).
432 */
433 if (ELCR_trigger(i))
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530434 intsrc.irqflag = 13;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 else
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530436 intsrc.irqflag = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 }
438
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530439 intsrc.srcbusirq = i;
440 intsrc.dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 MP_intsrc_info(&intsrc);
442 }
443
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530444 intsrc.irqtype = mp_ExtINT;
445 intsrc.srcbusirq = 0;
446 intsrc.dstirq = 0; /* 8259A to INTIN0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 MP_intsrc_info(&intsrc);
448}
449
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400450
Marcin Slusarz39e00fe2008-08-11 00:09:38 +0200451static void __init construct_ioapic_table(int mpc_default_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452{
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530453 struct mpc_ioapic ioapic;
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +0530454 struct mpc_bus bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530456 bus.type = MP_BUS;
457 bus.busid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 switch (mpc_default_type) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400459 default:
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400460 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400461 mpc_default_type);
462 /* fall through */
463 case 1:
464 case 5:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530465 memcpy(bus.bustype, "ISA ", 6);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400466 break;
467 case 2:
468 case 6:
469 case 3:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530470 memcpy(bus.bustype, "EISA ", 6);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400471 break;
472 case 4:
473 case 7:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530474 memcpy(bus.bustype, "MCA ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 }
476 MP_bus_info(&bus);
477 if (mpc_default_type > 4) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530478 bus.busid = 1;
479 memcpy(bus.bustype, "PCI ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 MP_bus_info(&bus);
481 }
482
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530483 ioapic.type = MP_IOAPIC;
484 ioapic.apicid = 2;
485 ioapic.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
486 ioapic.flags = MPC_APIC_USABLE;
487 ioapic.apicaddr = 0xFEC00000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 MP_ioapic_info(&ioapic);
489
490 /*
491 * We set up most of the low 16 IO-APIC pins according to MPS rules.
492 */
493 construct_default_ioirq_mptable(mpc_default_type);
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200494}
495#else
Marcin Slusarz39e00fe2008-08-11 00:09:38 +0200496static inline void __init construct_ioapic_table(int mpc_default_type) { }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400497#endif
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200498
499static inline void __init construct_default_ISA_mptable(int mpc_default_type)
500{
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +0530501 struct mpc_cpu processor;
Jaswinder Singh Rajput8fb29522009-01-03 15:51:54 +0530502 struct mpc_lintsrc lintsrc;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200503 int linttypes[2] = { mp_ExtINT, mp_NMI };
504 int i;
505
506 /*
507 * local APIC has default address
508 */
509 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
510
511 /*
512 * 2 CPUs, numbered 0 & 1.
513 */
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530514 processor.type = MP_PROCESSOR;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200515 /* Either an integrated APIC or a discrete 82489DX. */
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530516 processor.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
517 processor.cpuflag = CPU_ENABLED;
518 processor.cpufeature = (boot_cpu_data.x86 << 8) |
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200519 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530520 processor.featureflag = boot_cpu_data.x86_capability[0];
521 processor.reserved[0] = 0;
522 processor.reserved[1] = 0;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200523 for (i = 0; i < 2; i++) {
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530524 processor.apicid = i;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200525 MP_processor_info(&processor);
526 }
527
528 construct_ioapic_table(mpc_default_type);
529
Jaswinder Singh Rajputb5ced7c2009-01-04 21:55:53 +0530530 lintsrc.type = MP_LINTSRC;
531 lintsrc.irqflag = 0; /* conforming */
532 lintsrc.srcbusid = 0;
533 lintsrc.srcbusirq = 0;
534 lintsrc.destapic = MP_APIC_ALL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 for (i = 0; i < 2; i++) {
Jaswinder Singh Rajputb5ced7c2009-01-04 21:55:53 +0530536 lintsrc.irqtype = linttypes[i];
537 lintsrc.destapiclint = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 MP_lintsrc_info(&lintsrc);
539 }
540}
541
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530542static struct mpf_intel *mpf_found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
Yinghai Lu8d4dd912009-03-04 01:25:21 -0800544static unsigned long __init get_mpc_size(unsigned long physptr)
545{
546 struct mpc_table *mpc;
547 unsigned long size;
548
549 mpc = early_ioremap(physptr, PAGE_SIZE);
550 size = mpc->length;
551 early_iounmap(mpc, PAGE_SIZE);
552 apic_printk(APIC_VERBOSE, " mpc: %lx-%lx\n", physptr, physptr + size);
553
554 return size;
555}
556
Jaswinder Singh Rajput0b3ba0c2009-03-21 13:43:20 +0530557static int __init check_physptr(struct mpf_intel *mpf, unsigned int early)
558{
559 struct mpc_table *mpc;
560 unsigned long size;
561
562 size = get_mpc_size(mpf->physptr);
563 mpc = early_ioremap(mpf->physptr, size);
564 /*
565 * Read the physical hardware table. Anything here will
566 * override the defaults.
567 */
568 if (!smp_read_mpc(mpc, early)) {
569#ifdef CONFIG_X86_LOCAL_APIC
570 smp_found_config = 0;
571#endif
572 printk(KERN_ERR "BIOS bug, MP table errors detected!...\n"
573 "... disabling SMP support. (tell your hw vendor)\n");
574 early_iounmap(mpc, size);
575 return -1;
576 }
577 early_iounmap(mpc, size);
578
579 if (early)
580 return -1;
581
582#ifdef CONFIG_X86_IO_APIC
583 /*
584 * If there are no explicit MP IRQ entries, then we are
585 * broken. We set up most of the low 16 IO-APIC pins to
586 * ISA defaults and hope it will work.
587 */
588 if (!mp_irq_entries) {
589 struct mpc_bus bus;
590
591 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
592 "using default mptable. (tell your hw vendor)\n");
593
594 bus.type = MP_BUS;
595 bus.busid = 0;
596 memcpy(bus.bustype, "ISA ", 6);
597 MP_bus_info(&bus);
598
599 construct_default_ioirq_mptable(0);
600 }
601#endif
602
603 return 0;
604}
605
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606/*
607 * Scan the memory blocks for an SMP configuration block.
608 */
Ingo Molnar3b335532008-07-10 17:30:40 +0200609static void __init __get_smp_config(unsigned int early)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610{
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530611 struct mpf_intel *mpf = mpf_found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
Yinghai Lu69b88af2008-12-05 22:45:50 -0800613 if (!mpf)
614 return;
615
616 if (acpi_lapic && early)
617 return;
618
619 /*
620 * MPS doesn't support hyperthreading, aka only have
621 * thread 0 apic id in MPS table
622 */
623 if (acpi_lapic && acpi_ioapic)
624 return;
625
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700626 if (x86_quirks->mach_get_smp_config) {
627 if (x86_quirks->mach_get_smp_config(early))
Ingo Molnar3b335532008-07-10 17:30:40 +0200628 return;
629 }
Andi Kleen9adc1382008-12-04 13:33:35 +0100630
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400631 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530632 mpf->specification);
Alexey Starikovskiyb3e24162008-05-23 01:54:44 +0400633#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530634 if (mpf->feature2 & (1 << 7)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
636 pic_mode = 1;
637 } else {
638 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
639 pic_mode = 0;
640 }
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400641#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 /*
643 * Now see if we need to read further.
644 */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530645 if (mpf->feature1 != 0) {
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400646 if (early) {
647 /*
648 * local APIC has default address
649 */
650 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
651 return;
652 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400654 printk(KERN_INFO "Default MP configuration #%d\n",
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530655 mpf->feature1);
656 construct_default_ISA_mptable(mpf->feature1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530658 } else if (mpf->physptr) {
Jaswinder Singh Rajput0b3ba0c2009-03-21 13:43:20 +0530659 if (check_physptr(mpf, early))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 } else
662 BUG();
663
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400664 if (!early)
665 printk(KERN_INFO "Processors: %d\n", num_processors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 /*
667 * Only use the first configuration found.
668 */
669}
670
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400671void __init early_get_smp_config(void)
672{
673 __get_smp_config(1);
674}
675
676void __init get_smp_config(void)
677{
678 __get_smp_config(0);
679}
680
Rakib Mullick57592222009-04-11 09:04:59 +0600681static void __init smp_reserve_bootmem(struct mpf_intel *mpf)
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530682{
683 unsigned long size = get_mpc_size(mpf->physptr);
684#ifdef CONFIG_X86_32
685 /*
686 * We cannot access to MPC table to compute table size yet,
687 * as only few megabytes from the bottom is mapped now.
688 * PC-9800's MPC table places on the very last of physical
689 * memory; so that simply reserving PAGE_SIZE from mpf->physptr
690 * yields BUG() in reserve_bootmem.
691 * also need to make sure physptr is below than max_low_pfn
692 * we don't need reserve the area above max_low_pfn
693 */
694 unsigned long end = max_low_pfn * PAGE_SIZE;
695
696 if (mpf->physptr < end) {
697 if (mpf->physptr + size > end)
698 size = end - mpf->physptr;
699 reserve_bootmem_generic(mpf->physptr, size, BOOTMEM_DEFAULT);
700 }
701#else
702 reserve_bootmem_generic(mpf->physptr, size, BOOTMEM_DEFAULT);
703#endif
704}
705
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400706static int __init smp_scan_config(unsigned long base, unsigned long length,
707 unsigned reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708{
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400709 unsigned int *bp = phys_to_virt(base);
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530710 struct mpf_intel *mpf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200712 apic_printk(APIC_VERBOSE, "Scan SMP from %p for %ld bytes.\n",
713 bp, length);
Akinobu Mita5d47a272008-04-19 23:55:11 +0900714 BUILD_BUG_ON(sizeof(*mpf) != 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
716 while (length > 0) {
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530717 mpf = (struct mpf_intel *)bp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 if ((*bp == SMP_MAGIC_IDENT) &&
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530719 (mpf->length == 1) &&
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400720 !mpf_checksum((unsigned char *)bp, 16) &&
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530721 ((mpf->specification == 1)
722 || (mpf->specification == 4))) {
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400723#ifdef CONFIG_X86_LOCAL_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 smp_found_config = 1;
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400725#endif
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400726 mpf_found = mpf;
Yinghai Lub1f006b2008-06-09 18:11:36 -0700727
Jaswinder Singh Rajputba1511b2009-02-11 23:38:25 +0530728 printk(KERN_INFO "found SMP MP-table at [%p] %llx\n",
729 mpf, (u64)virt_to_phys(mpf));
Yinghai Lub1f006b2008-06-09 18:11:36 -0700730
731 if (!reserve)
732 return 1;
Yinghai Luf6243232009-03-04 01:25:54 -0800733 reserve_bootmem_generic(virt_to_phys(mpf), sizeof(*mpf),
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800734 BOOTMEM_DEFAULT);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530735 if (mpf->physptr)
736 smp_reserve_bootmem(mpf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
Yinghai Lud2dbf342008-06-13 02:00:56 -0700738 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 }
740 bp += 4;
741 length -= 16;
742 }
743 return 0;
744}
745
Ingo Molnar3b335532008-07-10 17:30:40 +0200746static void __init __find_smp_config(unsigned int reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747{
748 unsigned int address;
749
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700750 if (x86_quirks->mach_find_smp_config) {
751 if (x86_quirks->mach_find_smp_config(reserve))
Ingo Molnar3b335532008-07-10 17:30:40 +0200752 return;
753 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 /*
755 * FIXME: Linux assumes you have 640K of base ram..
756 * this continues the error...
757 *
758 * 1) Scan the bottom 1K for a signature
759 * 2) Scan the top 1K of base RAM
760 * 3) Scan the 64K of bios
761 */
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400762 if (smp_scan_config(0x0, 0x400, reserve) ||
763 smp_scan_config(639 * 0x400, 0x400, reserve) ||
764 smp_scan_config(0xF0000, 0x10000, reserve))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 return;
766 /*
767 * If it is an SMP machine we should know now, unless the
768 * configuration is in an EISA/MCA bus machine with an
769 * extended bios data area.
770 *
771 * there is a real-mode segmented pointer pointing to the
772 * 4K EBDA area at 0x40E, calculate and scan it here.
773 *
774 * NOTE! There are Linux loaders that will corrupt the EBDA
775 * area, and as such this kind of SMP config may be less
776 * trustworthy, simply because the SMP table may have been
777 * stomped on during early boot. These loaders are buggy and
778 * should be fixed.
779 *
780 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
781 */
782
783 address = get_bios_ebda();
784 if (address)
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400785 smp_scan_config(address, 0x400, reserve);
786}
787
788void __init early_find_smp_config(void)
789{
790 __find_smp_config(0);
791}
792
793void __init find_smp_config(void)
794{
795 __find_smp_config(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796}
Yinghai Lu2944e162008-06-01 13:17:38 -0700797
798#ifdef CONFIG_X86_IO_APIC
799static u8 __initdata irq_used[MAX_IRQ_SOURCES];
800
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530801static int __init get_MP_intsrc_index(struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700802{
803 int i;
804
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530805 if (m->irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700806 return 0;
807
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530808 if (m->irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700809 return 0;
810
811 /* not legacy */
812
813 for (i = 0; i < mp_irq_entries; i++) {
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530814 if (mp_irqs[i].irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700815 continue;
816
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530817 if (mp_irqs[i].irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700818 continue;
819
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530820 if (mp_irqs[i].srcbus != m->srcbus)
Yinghai Lu2944e162008-06-01 13:17:38 -0700821 continue;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530822 if (mp_irqs[i].srcbusirq != m->srcbusirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700823 continue;
824 if (irq_used[i]) {
825 /* already claimed */
826 return -2;
827 }
828 irq_used[i] = 1;
829 return i;
830 }
831
832 /* not found */
833 return -1;
834}
835
836#define SPARE_SLOT_NUM 20
837
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530838static struct mpc_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530839
Rakib Mullick57592222009-04-11 09:04:59 +0600840static void __init check_irq_src(struct mpc_intsrc *m, int *nr_m_spare)
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530841{
842 int i;
843
844 apic_printk(APIC_VERBOSE, "OLD ");
845 print_MP_intsrc_info(m);
846
847 i = get_MP_intsrc_index(m);
848 if (i > 0) {
849 assign_to_mpc_intsrc(&mp_irqs[i], m);
850 apic_printk(APIC_VERBOSE, "NEW ");
851 print_mp_irq_info(&mp_irqs[i]);
852 return;
853 }
854 if (!i) {
855 /* legacy, do nothing */
856 return;
857 }
858 if (*nr_m_spare < SPARE_SLOT_NUM) {
859 /*
860 * not found (-1), or duplicated (-2) are invalid entries,
861 * we need to use the slot later
862 */
863 m_spare[*nr_m_spare] = m;
864 *nr_m_spare += 1;
865 }
866}
867#else /* CONFIG_X86_IO_APIC */
Rakib Mullick57592222009-04-11 09:04:59 +0600868static
869inline void __init check_irq_src(struct mpc_intsrc *m, int *nr_m_spare) {}
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530870#endif /* CONFIG_X86_IO_APIC */
871
Yinghai Luee214552009-05-06 10:07:07 -0700872static int
873check_slot(unsigned long mpc_new_phys, unsigned long mpc_new_length, int count)
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530874{
Yinghai Luee214552009-05-06 10:07:07 -0700875 int ret = 0;
876
877 if (!mpc_new_phys || count <= mpc_new_length) {
878 WARN(1, "update_mptable: No spare slots (length: %x)\n", count);
879 return -1;
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530880 }
881
Yinghai Luee214552009-05-06 10:07:07 -0700882 return ret;
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530883}
Yinghai Lu2944e162008-06-01 13:17:38 -0700884
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530885static int __init replace_intsrc_all(struct mpc_table *mpc,
Yinghai Lu2944e162008-06-01 13:17:38 -0700886 unsigned long mpc_new_phys,
887 unsigned long mpc_new_length)
888{
889#ifdef CONFIG_X86_IO_APIC
890 int i;
Yinghai Lu2944e162008-06-01 13:17:38 -0700891#endif
Yinghai Lu2944e162008-06-01 13:17:38 -0700892 int count = sizeof(*mpc);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530893 int nr_m_spare = 0;
Yinghai Lu2944e162008-06-01 13:17:38 -0700894 unsigned char *mpt = ((unsigned char *)mpc) + count;
895
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530896 printk(KERN_INFO "mpc_length %x\n", mpc->length);
897 while (count < mpc->length) {
Yinghai Lu2944e162008-06-01 13:17:38 -0700898 switch (*mpt) {
899 case MP_PROCESSOR:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530900 skip_entry(&mpt, &count, sizeof(struct mpc_cpu));
901 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700902 case MP_BUS:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530903 skip_entry(&mpt, &count, sizeof(struct mpc_bus));
904 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700905 case MP_IOAPIC:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530906 skip_entry(&mpt, &count, sizeof(struct mpc_ioapic));
907 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700908 case MP_INTSRC:
Ingo Molnarc58603e2009-03-19 08:50:35 +0100909 check_irq_src((struct mpc_intsrc *)mpt, &nr_m_spare);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530910 skip_entry(&mpt, &count, sizeof(struct mpc_intsrc));
911 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700912 case MP_LINTSRC:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530913 skip_entry(&mpt, &count, sizeof(struct mpc_lintsrc));
914 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700915 default:
916 /* wrong mptable */
Jaswinder Singh Rajput5a5737e2009-03-21 13:28:39 +0530917 smp_dump_mptable(mpc, mpt);
Yinghai Lu2944e162008-06-01 13:17:38 -0700918 goto out;
919 }
920 }
921
922#ifdef CONFIG_X86_IO_APIC
923 for (i = 0; i < mp_irq_entries; i++) {
924 if (irq_used[i])
925 continue;
926
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530927 if (mp_irqs[i].irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700928 continue;
929
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530930 if (mp_irqs[i].irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700931 continue;
932
933 if (nr_m_spare > 0) {
Jan Beulich82034d62009-03-12 12:57:10 +0000934 apic_printk(APIC_VERBOSE, "*NEW* found\n");
Yinghai Lu2944e162008-06-01 13:17:38 -0700935 nr_m_spare--;
936 assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
937 m_spare[nr_m_spare] = NULL;
938 } else {
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530939 struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
940 count += sizeof(struct mpc_intsrc);
Yinghai Luee214552009-05-06 10:07:07 -0700941 if (check_slot(mpc_new_phys, mpc_new_length, count) < 0)
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530942 goto out;
Yinghai Lu2944e162008-06-01 13:17:38 -0700943 assign_to_mpc_intsrc(&mp_irqs[i], m);
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530944 mpc->length = count;
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530945 mpt += sizeof(struct mpc_intsrc);
Yinghai Lu2944e162008-06-01 13:17:38 -0700946 }
947 print_mp_irq_info(&mp_irqs[i]);
948 }
949#endif
950out:
951 /* update checksum */
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530952 mpc->checksum = 0;
953 mpc->checksum -= mpf_checksum((unsigned char *)mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -0700954
955 return 0;
956}
957
Yinghai Luf1bdb522009-05-15 13:05:16 -0700958int enable_update_mptable;
Yinghai Lufcfa1462008-06-18 17:29:31 -0700959
Yinghai Lu2944e162008-06-01 13:17:38 -0700960static int __init update_mptable_setup(char *str)
961{
962 enable_update_mptable = 1;
Yinghai Lu629e15d2009-05-15 13:05:16 -0700963#ifdef CONFIG_PCI
964 pci_routeirq = 1;
965#endif
Yinghai Lu2944e162008-06-01 13:17:38 -0700966 return 0;
967}
968early_param("update_mptable", update_mptable_setup);
969
970static unsigned long __initdata mpc_new_phys;
971static unsigned long mpc_new_length __initdata = 4096;
972
973/* alloc_mptable or alloc_mptable=4k */
974static int __initdata alloc_mptable;
975static int __init parse_alloc_mptable_opt(char *p)
976{
977 enable_update_mptable = 1;
Yinghai Lu629e15d2009-05-15 13:05:16 -0700978#ifdef CONFIG_PCI
979 pci_routeirq = 1;
980#endif
Yinghai Lu2944e162008-06-01 13:17:38 -0700981 alloc_mptable = 1;
982 if (!p)
983 return 0;
984 mpc_new_length = memparse(p, &p);
985 return 0;
986}
987early_param("alloc_mptable", parse_alloc_mptable_opt);
988
989void __init early_reserve_e820_mpc_new(void)
990{
991 if (enable_update_mptable && alloc_mptable) {
992 u64 startt = 0;
993#ifdef CONFIG_X86_TRAMPOLINE
994 startt = TRAMPOLINE_BASE;
995#endif
996 mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
997 }
998}
999
1000static int __init update_mp_table(void)
1001{
1002 char str[16];
1003 char oem[10];
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +05301004 struct mpf_intel *mpf;
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +05301005 struct mpc_table *mpc, *mpc_new;
Yinghai Lu2944e162008-06-01 13:17:38 -07001006
1007 if (!enable_update_mptable)
1008 return 0;
1009
1010 mpf = mpf_found;
1011 if (!mpf)
1012 return 0;
1013
1014 /*
1015 * Now see if we need to go further.
1016 */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301017 if (mpf->feature1 != 0)
Yinghai Lu2944e162008-06-01 13:17:38 -07001018 return 0;
1019
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301020 if (!mpf->physptr)
Yinghai Lu2944e162008-06-01 13:17:38 -07001021 return 0;
1022
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301023 mpc = phys_to_virt(mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -07001024
1025 if (!smp_check_mpc(mpc, oem, str))
1026 return 0;
1027
Jaswinder Singh Rajputba1511b2009-02-11 23:38:25 +05301028 printk(KERN_INFO "mpf: %llx\n", (u64)virt_to_phys(mpf));
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301029 printk(KERN_INFO "physptr: %x\n", mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -07001030
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +05301031 if (mpc_new_phys && mpc->length > mpc_new_length) {
Yinghai Lu2944e162008-06-01 13:17:38 -07001032 mpc_new_phys = 0;
1033 printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
1034 mpc_new_length);
1035 }
1036
1037 if (!mpc_new_phys) {
1038 unsigned char old, new;
1039 /* check if we can change the postion */
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +05301040 mpc->checksum = 0;
1041 old = mpf_checksum((unsigned char *)mpc, mpc->length);
1042 mpc->checksum = 0xff;
1043 new = mpf_checksum((unsigned char *)mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -07001044 if (old == new) {
1045 printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
1046 return 0;
1047 }
1048 printk(KERN_INFO "use in-positon replacing\n");
1049 } else {
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301050 mpf->physptr = mpc_new_phys;
Yinghai Lu2944e162008-06-01 13:17:38 -07001051 mpc_new = phys_to_virt(mpc_new_phys);
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +05301052 memcpy(mpc_new, mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -07001053 mpc = mpc_new;
1054 /* check if we can modify that */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301055 if (mpc_new_phys - mpf->physptr) {
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +05301056 struct mpf_intel *mpf_new;
Yinghai Lu2944e162008-06-01 13:17:38 -07001057 /* steal 16 bytes from [0, 1k) */
1058 printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
1059 mpf_new = phys_to_virt(0x400 - 16);
1060 memcpy(mpf_new, mpf, 16);
1061 mpf = mpf_new;
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301062 mpf->physptr = mpc_new_phys;
Yinghai Lu2944e162008-06-01 13:17:38 -07001063 }
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301064 mpf->checksum = 0;
1065 mpf->checksum -= mpf_checksum((unsigned char *)mpf, 16);
1066 printk(KERN_INFO "physptr new: %x\n", mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -07001067 }
1068
1069 /*
1070 * only replace the one with mp_INT and
1071 * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
1072 * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
1073 * may need pci=routeirq for all coverage
1074 */
1075 replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
1076
1077 return 0;
1078}
1079
1080late_initcall(update_mp_table);