blob: cd2a41a7c45c3a056ba69bbbd721bd598335352e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04002 * Intel Multiprocessor Specification 1.1 and 1.4
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * compliant MP-table parsing routines.
4 *
Alan Cox87c6fe22009-01-05 14:08:04 +00005 * (c) 1995 Alan Cox, Building #3 <alan@lxorguk.ukuu.org.uk>
Ingo Molnar8f47e162009-01-31 02:03:42 +01006 * (c) 1998, 1999, 2000, 2009 Ingo Molnar <mingo@redhat.com>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +04007 * (c) 2008 Alexey Starikovskiy <astarikovskiy@suse.de>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
9
10#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/bootmem.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/kernel_stat.h>
15#include <linux/mc146818rtc.h>
16#include <linux/bitops.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040017#include <linux/acpi.h>
18#include <linux/module.h>
Jaswinder Singh Rajput103ceff2009-01-02 23:43:25 +053019#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/mtrr.h>
22#include <asm/mpspec.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040023#include <asm/pgalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/io_apic.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040025#include <asm/proto.h>
Alexey Starikovskiyce3fe6b2008-03-17 22:08:17 +030026#include <asm/bios_ebda.h>
Yinghai Lu2944e162008-06-01 13:17:38 -070027#include <asm/e820.h>
28#include <asm/trampoline.h>
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -070029#include <asm/setup.h>
Jaswinder Singh Rajput4884d8e2009-01-11 18:38:55 +053030#include <asm/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Ingo Molnar7b6aa332009-02-17 13:58:15 +010032#include <asm/apic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 * Checksum an MP configuration block.
35 */
36
37static int __init mpf_checksum(unsigned char *mp, int len)
38{
39 int sum = 0;
40
41 while (len--)
42 sum += *mp++;
43
44 return sum & 0xFF;
45}
46
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +053047static void __init MP_processor_info(struct mpc_cpu *m)
Alexey Starikovskiyc853c672008-03-27 23:54:13 +030048{
49 int apicid;
Alexey Starikovskiy746f2242008-04-04 23:42:15 +040050 char *bootup_cpu = "";
Alexey Starikovskiyc853c672008-03-27 23:54:13 +030051
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053052 if (!(m->cpuflag & CPU_ENABLED)) {
Glauber Costa7b1292e2008-03-03 14:12:41 -030053 disabled_cpus++;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 return;
Glauber Costa7b1292e2008-03-03 14:12:41 -030055 }
Yinghai Lu64898a82008-07-19 18:01:16 -070056
57 if (x86_quirks->mpc_apic_id)
58 apicid = x86_quirks->mpc_apic_id(m);
Yinghai Luab530e12008-06-03 10:25:54 -070059 else
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053060 apicid = m->apicid;
Yinghai Lu64898a82008-07-19 18:01:16 -070061
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053062 if (m->cpuflag & CPU_BOOTPROCESSOR) {
Alexey Starikovskiy746f2242008-04-04 23:42:15 +040063 bootup_cpu = " (Bootup-CPU)";
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053064 boot_cpu_physical_apicid = m->apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 }
66
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053067 printk(KERN_INFO "Processor #%d%s\n", m->apicid, bootup_cpu);
68 generic_processor_info(apicid, m->apicver);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069}
70
Thomas Gleixner85cc35f2008-05-25 21:21:36 +020071#ifdef CONFIG_X86_IO_APIC
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +053072static void __init MP_bus_info(struct mpc_bus *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073{
74 char str[7];
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053075 memcpy(str, m->bustype, 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 str[6] = 0;
77
Yinghai Lu64898a82008-07-19 18:01:16 -070078 if (x86_quirks->mpc_oem_bus_info)
79 x86_quirks->mpc_oem_bus_info(m, str);
80 else
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053081 apic_printk(APIC_VERBOSE, "Bus #%d is %s\n", m->busid, str);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Andi Kleen5e4edbb2006-09-26 10:52:35 +020083#if MAX_MP_BUSSES < 256
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053084 if (m->busid >= MAX_MP_BUSSES) {
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070085 printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +040086 " is too large, max. supported is %d\n",
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053087 m->busid, str, MAX_MP_BUSSES - 1);
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070088 return;
89 }
Andi Kleen5e4edbb2006-09-26 10:52:35 +020090#endif
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070091
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +040092 if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053093 set_bit(m->busid, mp_bus_not_pci);
Jaswinder Singh Rajput103ceff2009-01-02 23:43:25 +053094#if defined(CONFIG_EISA) || defined(CONFIG_MCA)
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053095 mp_bus_id_to_type[m->busid] = MP_BUS_ISA;
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +040096#endif
97 } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
Yinghai Lu64898a82008-07-19 18:01:16 -070098 if (x86_quirks->mpc_oem_pci_bus)
99 x86_quirks->mpc_oem_pci_bus(m);
100
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530101 clear_bit(m->busid, mp_bus_not_pci);
Jaswinder Singh Rajput103ceff2009-01-02 23:43:25 +0530102#if defined(CONFIG_EISA) || defined(CONFIG_MCA)
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530103 mp_bus_id_to_type[m->busid] = MP_BUS_PCI;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400104 } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530105 mp_bus_id_to_type[m->busid] = MP_BUS_EISA;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400106 } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530107 mp_bus_id_to_type[m->busid] = MP_BUS_MCA;
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +0300108#endif
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +0400109 } else
110 printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111}
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400112
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300113static int bad_ioapic(unsigned long address)
114{
115 if (nr_ioapics >= MAX_IO_APICS) {
116 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
117 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
118 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
119 }
120 if (!address) {
121 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
122 " found in table, skipping!\n");
123 return 1;
124 }
125 return 0;
126}
127
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530128static void __init MP_ioapic_info(struct mpc_ioapic *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530130 if (!(m->flags & MPC_APIC_USABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 return;
132
Thomas Gleixner64883ab2008-01-30 13:30:35 +0100133 printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530134 m->apicid, m->apicver, m->apicaddr);
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300135
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530136 if (bad_ioapic(m->apicaddr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 return;
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300138
Jaswinder Singh Rajputb5ba7e6d2009-01-12 17:46:17 +0530139 mp_ioapics[nr_ioapics].apicaddr = m->apicaddr;
140 mp_ioapics[nr_ioapics].apicid = m->apicid;
141 mp_ioapics[nr_ioapics].type = m->type;
142 mp_ioapics[nr_ioapics].apicver = m->apicver;
143 mp_ioapics[nr_ioapics].flags = m->flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 nr_ioapics++;
145}
146
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530147static void print_MP_intsrc_info(struct mpc_intsrc *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200149 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530151 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbus,
152 m->srcbusirq, m->dstapic, m->dstirq);
Yinghai Lu2944e162008-06-01 13:17:38 -0700153}
154
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530155static void __init print_mp_irq_info(struct mpc_intsrc *mp_irq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700156{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200157 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
Yinghai Lu2944e162008-06-01 13:17:38 -0700158 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530159 mp_irq->irqtype, mp_irq->irqflag & 3,
160 (mp_irq->irqflag >> 2) & 3, mp_irq->srcbus,
161 mp_irq->srcbusirq, mp_irq->dstapic, mp_irq->dstirq);
Yinghai Lu2944e162008-06-01 13:17:38 -0700162}
163
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530164static void __init assign_to_mp_irq(struct mpc_intsrc *m,
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530165 struct mpc_intsrc *mp_irq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700166{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530167 mp_irq->dstapic = m->dstapic;
168 mp_irq->type = m->type;
169 mp_irq->irqtype = m->irqtype;
170 mp_irq->irqflag = m->irqflag;
171 mp_irq->srcbus = m->srcbus;
172 mp_irq->srcbusirq = m->srcbusirq;
173 mp_irq->dstirq = m->dstirq;
Yinghai Lu2944e162008-06-01 13:17:38 -0700174}
175
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530176static void __init assign_to_mpc_intsrc(struct mpc_intsrc *mp_irq,
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530177 struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700178{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530179 m->dstapic = mp_irq->dstapic;
180 m->type = mp_irq->type;
181 m->irqtype = mp_irq->irqtype;
182 m->irqflag = mp_irq->irqflag;
183 m->srcbus = mp_irq->srcbus;
184 m->srcbusirq = mp_irq->srcbusirq;
185 m->dstirq = mp_irq->dstirq;
Yinghai Lu2944e162008-06-01 13:17:38 -0700186}
187
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530188static int __init mp_irq_mpc_intsrc_cmp(struct mpc_intsrc *mp_irq,
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530189 struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700190{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530191 if (mp_irq->dstapic != m->dstapic)
Yinghai Lu2944e162008-06-01 13:17:38 -0700192 return 1;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530193 if (mp_irq->type != m->type)
Yinghai Lu2944e162008-06-01 13:17:38 -0700194 return 2;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530195 if (mp_irq->irqtype != m->irqtype)
Yinghai Lu2944e162008-06-01 13:17:38 -0700196 return 3;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530197 if (mp_irq->irqflag != m->irqflag)
Yinghai Lu2944e162008-06-01 13:17:38 -0700198 return 4;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530199 if (mp_irq->srcbus != m->srcbus)
Yinghai Lu2944e162008-06-01 13:17:38 -0700200 return 5;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530201 if (mp_irq->srcbusirq != m->srcbusirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700202 return 6;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530203 if (mp_irq->dstirq != m->dstirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700204 return 7;
205
206 return 0;
207}
208
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530209static void __init MP_intsrc_info(struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700210{
211 int i;
212
213 print_MP_intsrc_info(m);
214
Yinghai Lufcfa1462008-06-18 17:29:31 -0700215 for (i = 0; i < mp_irq_entries; i++) {
216 if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m))
217 return;
218 }
Yinghai Lu2944e162008-06-01 13:17:38 -0700219
220 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 if (++mp_irq_entries == MAX_IRQ_SOURCES)
222 panic("Max # of irq sources exceeded!!\n");
223}
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530224#else /* CONFIG_X86_IO_APIC */
225static inline void __init MP_bus_info(struct mpc_bus *m) {}
226static inline void __init MP_ioapic_info(struct mpc_ioapic *m) {}
227static inline void __init MP_intsrc_info(struct mpc_intsrc *m) {}
228#endif /* CONFIG_X86_IO_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400230
Jaswinder Singh Rajput8fb29522009-01-03 15:51:54 +0530231static void __init MP_lintsrc_info(struct mpc_lintsrc *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200233 apic_printk(APIC_VERBOSE, "Lint: type %d, pol %d, trig %d, bus %02x,"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
Jaswinder Singh Rajputb5ced7cd2009-01-04 21:55:53 +0530235 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbusid,
236 m->srcbusirq, m->destapic, m->destapiclint);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237}
238
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239/*
240 * Read/parse the MPC
241 */
242
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530243static int __init smp_check_mpc(struct mpc_table *mpc, char *oem, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530246 if (memcmp(mpc->signature, MPC_SIGNATURE, 4)) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400247 printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530248 mpc->signature[0], mpc->signature[1],
249 mpc->signature[2], mpc->signature[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 return 0;
251 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530252 if (mpf_checksum((unsigned char *)mpc, mpc->length)) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400253 printk(KERN_ERR "MPTABLE: checksum error!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 return 0;
255 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530256 if (mpc->spec != 0x01 && mpc->spec != 0x04) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400257 printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530258 mpc->spec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 return 0;
260 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530261 if (!mpc->lapic) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400262 printk(KERN_ERR "MPTABLE: null local APIC address!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 return 0;
264 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530265 memcpy(oem, mpc->oem, 8);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400266 oem[8] = 0;
Yinghai Lu11a62a02008-05-12 15:43:38 +0200267 printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530269 memcpy(str, mpc->productid, 12);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400270 str[12] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Yinghai Lu11a62a02008-05-12 15:43:38 +0200272 printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530274 printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->lapic);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
Yinghai Lu2944e162008-06-01 13:17:38 -0700276 return 1;
277}
278
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530279static void skip_entry(unsigned char **ptr, int *count, int size)
280{
281 *ptr += size;
282 *count += size;
283}
284
Jaswinder Singh Rajput5a5737e2009-03-21 13:28:39 +0530285static void __init smp_dump_mptable(struct mpc_table *mpc, unsigned char *mpt)
286{
287 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n"
288 "type %x\n", *mpt);
289 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
290 1, mpc, mpc->length, 1);
291}
292
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530293static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early)
Yinghai Lu2944e162008-06-01 13:17:38 -0700294{
295 char str[16];
296 char oem[10];
297
298 int count = sizeof(*mpc);
299 unsigned char *mpt = ((unsigned char *)mpc) + count;
300
301 if (!smp_check_mpc(mpc, oem, str))
302 return 0;
303
304#ifdef CONFIG_X86_32
Ingo Molnar9c764242009-01-28 13:44:32 +0100305 generic_mps_oem_check(mpc, oem, str);
Yinghai Lu2944e162008-06-01 13:17:38 -0700306#endif
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400307 /* save the local APIC address, it might be non-default */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 if (!acpi_lapic)
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530309 mp_lapic_addr = mpc->lapic;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400311 if (early)
312 return 1;
313
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530314 if (mpc->oemptr && x86_quirks->smp_read_mpc_oem) {
315 struct mpc_oemtable *oem_table = (void *)(long)mpc->oemptr;
316 x86_quirks->smp_read_mpc_oem(oem_table, mpc->oemsize);
Yinghai Lu64898a82008-07-19 18:01:16 -0700317 }
318
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 /*
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400320 * Now process the configuration blocks.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 */
Yinghai Lu64898a82008-07-19 18:01:16 -0700322 if (x86_quirks->mpc_record)
323 *x86_quirks->mpc_record = 0;
324
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 }
Yinghai Lu64898a82008-07-19 18:01:16 -0700355 if (x86_quirks->mpc_record)
356 (*x86_quirks->mpc_record)++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 }
Yinghai Lue0da3362008-06-08 18:29:22 -0700358
Yinghai Lu26f7ef12009-01-29 14:19:22 -0800359#ifdef CONFIG_X86_BIGSMP
360 generic_bigsmp_probe();
Yinghai Lue0da3362008-06-08 18:29:22 -0700361#endif
362
Ingo Molnar72ce0162009-01-28 06:50:47 +0100363 if (apic->setup_apic_routing)
364 apic->setup_apic_routing();
365
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 if (!num_processors)
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400367 printk(KERN_ERR "MPTABLE: no processors registered!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 return num_processors;
369}
370
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400371#ifdef CONFIG_X86_IO_APIC
372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373static int __init ELCR_trigger(unsigned int irq)
374{
375 unsigned int port;
376
377 port = 0x4d0 + (irq >> 3);
378 return (inb(port) >> (irq & 7)) & 1;
379}
380
381static void __init construct_default_ioirq_mptable(int mpc_default_type)
382{
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530383 struct mpc_intsrc intsrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 int i;
385 int ELCR_fallback = 0;
386
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530387 intsrc.type = MP_INTSRC;
388 intsrc.irqflag = 0; /* conforming */
389 intsrc.srcbus = 0;
Jaswinder Singh Rajputb5ba7e6d2009-01-12 17:46:17 +0530390 intsrc.dstapic = mp_ioapics[0].apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530392 intsrc.irqtype = mp_INT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
394 /*
395 * If true, we have an ISA/PCI system with no IRQ entries
396 * in the MP table. To prevent the PCI interrupts from being set up
397 * incorrectly, we try to use the ELCR. The sanity check to see if
398 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
399 * never be level sensitive, so we simply see if the ELCR agrees.
400 * If it does, we assume it's valid.
401 */
402 if (mpc_default_type == 5) {
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400403 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
404 "falling back to ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400406 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
407 ELCR_trigger(13))
408 printk(KERN_ERR "ELCR contains invalid data... "
409 "not using ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 else {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400411 printk(KERN_INFO
412 "Using ELCR to identify PCI interrupts\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 ELCR_fallback = 1;
414 }
415 }
416
417 for (i = 0; i < 16; i++) {
418 switch (mpc_default_type) {
419 case 2:
420 if (i == 0 || i == 13)
421 continue; /* IRQ0 & IRQ13 not connected */
422 /* fall through */
423 default:
424 if (i == 2)
425 continue; /* IRQ2 is never connected */
426 }
427
428 if (ELCR_fallback) {
429 /*
430 * If the ELCR indicates a level-sensitive interrupt, we
431 * copy that information over to the MP table in the
432 * irqflag field (level sensitive, active high polarity).
433 */
434 if (ELCR_trigger(i))
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530435 intsrc.irqflag = 13;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 else
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530437 intsrc.irqflag = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 }
439
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530440 intsrc.srcbusirq = i;
441 intsrc.dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 MP_intsrc_info(&intsrc);
443 }
444
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530445 intsrc.irqtype = mp_ExtINT;
446 intsrc.srcbusirq = 0;
447 intsrc.dstirq = 0; /* 8259A to INTIN0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 MP_intsrc_info(&intsrc);
449}
450
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400451
Marcin Slusarz39e00fe2008-08-11 00:09:38 +0200452static void __init construct_ioapic_table(int mpc_default_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453{
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530454 struct mpc_ioapic ioapic;
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +0530455 struct mpc_bus bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530457 bus.type = MP_BUS;
458 bus.busid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 switch (mpc_default_type) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400460 default:
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400461 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400462 mpc_default_type);
463 /* fall through */
464 case 1:
465 case 5:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530466 memcpy(bus.bustype, "ISA ", 6);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400467 break;
468 case 2:
469 case 6:
470 case 3:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530471 memcpy(bus.bustype, "EISA ", 6);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400472 break;
473 case 4:
474 case 7:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530475 memcpy(bus.bustype, "MCA ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 }
477 MP_bus_info(&bus);
478 if (mpc_default_type > 4) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530479 bus.busid = 1;
480 memcpy(bus.bustype, "PCI ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 MP_bus_info(&bus);
482 }
483
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530484 ioapic.type = MP_IOAPIC;
485 ioapic.apicid = 2;
486 ioapic.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
487 ioapic.flags = MPC_APIC_USABLE;
488 ioapic.apicaddr = 0xFEC00000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 MP_ioapic_info(&ioapic);
490
491 /*
492 * We set up most of the low 16 IO-APIC pins according to MPS rules.
493 */
494 construct_default_ioirq_mptable(mpc_default_type);
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200495}
496#else
Marcin Slusarz39e00fe2008-08-11 00:09:38 +0200497static inline void __init construct_ioapic_table(int mpc_default_type) { }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400498#endif
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200499
500static inline void __init construct_default_ISA_mptable(int mpc_default_type)
501{
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +0530502 struct mpc_cpu processor;
Jaswinder Singh Rajput8fb29522009-01-03 15:51:54 +0530503 struct mpc_lintsrc lintsrc;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200504 int linttypes[2] = { mp_ExtINT, mp_NMI };
505 int i;
506
507 /*
508 * local APIC has default address
509 */
510 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
511
512 /*
513 * 2 CPUs, numbered 0 & 1.
514 */
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530515 processor.type = MP_PROCESSOR;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200516 /* Either an integrated APIC or a discrete 82489DX. */
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530517 processor.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
518 processor.cpuflag = CPU_ENABLED;
519 processor.cpufeature = (boot_cpu_data.x86 << 8) |
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200520 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530521 processor.featureflag = boot_cpu_data.x86_capability[0];
522 processor.reserved[0] = 0;
523 processor.reserved[1] = 0;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200524 for (i = 0; i < 2; i++) {
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530525 processor.apicid = i;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200526 MP_processor_info(&processor);
527 }
528
529 construct_ioapic_table(mpc_default_type);
530
Jaswinder Singh Rajputb5ced7cd2009-01-04 21:55:53 +0530531 lintsrc.type = MP_LINTSRC;
532 lintsrc.irqflag = 0; /* conforming */
533 lintsrc.srcbusid = 0;
534 lintsrc.srcbusirq = 0;
535 lintsrc.destapic = MP_APIC_ALL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 for (i = 0; i < 2; i++) {
Jaswinder Singh Rajputb5ced7cd2009-01-04 21:55:53 +0530537 lintsrc.irqtype = linttypes[i];
538 lintsrc.destapiclint = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 MP_lintsrc_info(&lintsrc);
540 }
541}
542
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530543static struct mpf_intel *mpf_found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Yinghai Lu8d4dd912009-03-04 01:25:21 -0800545static unsigned long __init get_mpc_size(unsigned long physptr)
546{
547 struct mpc_table *mpc;
548 unsigned long size;
549
550 mpc = early_ioremap(physptr, PAGE_SIZE);
551 size = mpc->length;
552 early_iounmap(mpc, PAGE_SIZE);
553 apic_printk(APIC_VERBOSE, " mpc: %lx-%lx\n", physptr, physptr + size);
554
555 return size;
556}
557
Jaswinder Singh Rajput0b3ba0c2009-03-21 13:43:20 +0530558static int __init check_physptr(struct mpf_intel *mpf, unsigned int early)
559{
560 struct mpc_table *mpc;
561 unsigned long size;
562
563 size = get_mpc_size(mpf->physptr);
564 mpc = early_ioremap(mpf->physptr, size);
565 /*
566 * Read the physical hardware table. Anything here will
567 * override the defaults.
568 */
569 if (!smp_read_mpc(mpc, early)) {
570#ifdef CONFIG_X86_LOCAL_APIC
571 smp_found_config = 0;
572#endif
573 printk(KERN_ERR "BIOS bug, MP table errors detected!...\n"
574 "... disabling SMP support. (tell your hw vendor)\n");
575 early_iounmap(mpc, size);
576 return -1;
577 }
578 early_iounmap(mpc, size);
579
580 if (early)
581 return -1;
582
583#ifdef CONFIG_X86_IO_APIC
584 /*
585 * If there are no explicit MP IRQ entries, then we are
586 * broken. We set up most of the low 16 IO-APIC pins to
587 * ISA defaults and hope it will work.
588 */
589 if (!mp_irq_entries) {
590 struct mpc_bus bus;
591
592 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
593 "using default mptable. (tell your hw vendor)\n");
594
595 bus.type = MP_BUS;
596 bus.busid = 0;
597 memcpy(bus.bustype, "ISA ", 6);
598 MP_bus_info(&bus);
599
600 construct_default_ioirq_mptable(0);
601 }
602#endif
603
604 return 0;
605}
606
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607/*
608 * Scan the memory blocks for an SMP configuration block.
609 */
Ingo Molnar3b335532008-07-10 17:30:40 +0200610static void __init __get_smp_config(unsigned int early)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611{
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530612 struct mpf_intel *mpf = mpf_found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
Yinghai Lu69b88af2008-12-05 22:45:50 -0800614 if (!mpf)
615 return;
616
617 if (acpi_lapic && early)
618 return;
619
620 /*
621 * MPS doesn't support hyperthreading, aka only have
622 * thread 0 apic id in MPS table
623 */
624 if (acpi_lapic && acpi_ioapic)
625 return;
626
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700627 if (x86_quirks->mach_get_smp_config) {
628 if (x86_quirks->mach_get_smp_config(early))
Ingo Molnar3b335532008-07-10 17:30:40 +0200629 return;
630 }
Andi Kleen9adc1382008-12-04 13:33:35 +0100631
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400632 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530633 mpf->specification);
Alexey Starikovskiyb3e24162008-05-23 01:54:44 +0400634#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530635 if (mpf->feature2 & (1 << 7)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
637 pic_mode = 1;
638 } else {
639 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
640 pic_mode = 0;
641 }
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400642#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 /*
644 * Now see if we need to read further.
645 */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530646 if (mpf->feature1 != 0) {
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400647 if (early) {
648 /*
649 * local APIC has default address
650 */
651 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
652 return;
653 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400655 printk(KERN_INFO "Default MP configuration #%d\n",
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530656 mpf->feature1);
657 construct_default_ISA_mptable(mpf->feature1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530659 } else if (mpf->physptr) {
Jaswinder Singh Rajput0b3ba0c2009-03-21 13:43:20 +0530660 if (check_physptr(mpf, early))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 } else
663 BUG();
664
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400665 if (!early)
666 printk(KERN_INFO "Processors: %d\n", num_processors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 /*
668 * Only use the first configuration found.
669 */
670}
671
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400672void __init early_get_smp_config(void)
673{
674 __get_smp_config(1);
675}
676
677void __init get_smp_config(void)
678{
679 __get_smp_config(0);
680}
681
Rakib Mullick57592222009-04-11 09:04:59 +0600682static void __init smp_reserve_bootmem(struct mpf_intel *mpf)
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530683{
684 unsigned long size = get_mpc_size(mpf->physptr);
685#ifdef CONFIG_X86_32
686 /*
687 * We cannot access to MPC table to compute table size yet,
688 * as only few megabytes from the bottom is mapped now.
689 * PC-9800's MPC table places on the very last of physical
690 * memory; so that simply reserving PAGE_SIZE from mpf->physptr
691 * yields BUG() in reserve_bootmem.
692 * also need to make sure physptr is below than max_low_pfn
693 * we don't need reserve the area above max_low_pfn
694 */
695 unsigned long end = max_low_pfn * PAGE_SIZE;
696
697 if (mpf->physptr < end) {
698 if (mpf->physptr + size > end)
699 size = end - mpf->physptr;
700 reserve_bootmem_generic(mpf->physptr, size, BOOTMEM_DEFAULT);
701 }
702#else
703 reserve_bootmem_generic(mpf->physptr, size, BOOTMEM_DEFAULT);
704#endif
705}
706
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400707static int __init smp_scan_config(unsigned long base, unsigned long length,
708 unsigned reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709{
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400710 unsigned int *bp = phys_to_virt(base);
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530711 struct mpf_intel *mpf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200713 apic_printk(APIC_VERBOSE, "Scan SMP from %p for %ld bytes.\n",
714 bp, length);
Akinobu Mita5d47a272008-04-19 23:55:11 +0900715 BUILD_BUG_ON(sizeof(*mpf) != 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
717 while (length > 0) {
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530718 mpf = (struct mpf_intel *)bp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 if ((*bp == SMP_MAGIC_IDENT) &&
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530720 (mpf->length == 1) &&
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400721 !mpf_checksum((unsigned char *)bp, 16) &&
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530722 ((mpf->specification == 1)
723 || (mpf->specification == 4))) {
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400724#ifdef CONFIG_X86_LOCAL_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 smp_found_config = 1;
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400726#endif
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400727 mpf_found = mpf;
Yinghai Lub1f006b2008-06-09 18:11:36 -0700728
Jaswinder Singh Rajputba1511b2009-02-11 23:38:25 +0530729 printk(KERN_INFO "found SMP MP-table at [%p] %llx\n",
730 mpf, (u64)virt_to_phys(mpf));
Yinghai Lub1f006b2008-06-09 18:11:36 -0700731
732 if (!reserve)
733 return 1;
Yinghai Luf6243232009-03-04 01:25:54 -0800734 reserve_bootmem_generic(virt_to_phys(mpf), sizeof(*mpf),
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800735 BOOTMEM_DEFAULT);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530736 if (mpf->physptr)
737 smp_reserve_bootmem(mpf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
Yinghai Lud2dbf342008-06-13 02:00:56 -0700739 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 }
741 bp += 4;
742 length -= 16;
743 }
744 return 0;
745}
746
Ingo Molnar3b335532008-07-10 17:30:40 +0200747static void __init __find_smp_config(unsigned int reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748{
749 unsigned int address;
750
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700751 if (x86_quirks->mach_find_smp_config) {
752 if (x86_quirks->mach_find_smp_config(reserve))
Ingo Molnar3b335532008-07-10 17:30:40 +0200753 return;
754 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 /*
756 * FIXME: Linux assumes you have 640K of base ram..
757 * this continues the error...
758 *
759 * 1) Scan the bottom 1K for a signature
760 * 2) Scan the top 1K of base RAM
761 * 3) Scan the 64K of bios
762 */
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400763 if (smp_scan_config(0x0, 0x400, reserve) ||
764 smp_scan_config(639 * 0x400, 0x400, reserve) ||
765 smp_scan_config(0xF0000, 0x10000, reserve))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 return;
767 /*
768 * If it is an SMP machine we should know now, unless the
769 * configuration is in an EISA/MCA bus machine with an
770 * extended bios data area.
771 *
772 * there is a real-mode segmented pointer pointing to the
773 * 4K EBDA area at 0x40E, calculate and scan it here.
774 *
775 * NOTE! There are Linux loaders that will corrupt the EBDA
776 * area, and as such this kind of SMP config may be less
777 * trustworthy, simply because the SMP table may have been
778 * stomped on during early boot. These loaders are buggy and
779 * should be fixed.
780 *
781 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
782 */
783
784 address = get_bios_ebda();
785 if (address)
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400786 smp_scan_config(address, 0x400, reserve);
787}
788
789void __init early_find_smp_config(void)
790{
791 __find_smp_config(0);
792}
793
794void __init find_smp_config(void)
795{
796 __find_smp_config(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797}
Yinghai Lu2944e162008-06-01 13:17:38 -0700798
799#ifdef CONFIG_X86_IO_APIC
800static u8 __initdata irq_used[MAX_IRQ_SOURCES];
801
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530802static int __init get_MP_intsrc_index(struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700803{
804 int i;
805
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530806 if (m->irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700807 return 0;
808
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530809 if (m->irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700810 return 0;
811
812 /* not legacy */
813
814 for (i = 0; i < mp_irq_entries; i++) {
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530815 if (mp_irqs[i].irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700816 continue;
817
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530818 if (mp_irqs[i].irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700819 continue;
820
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530821 if (mp_irqs[i].srcbus != m->srcbus)
Yinghai Lu2944e162008-06-01 13:17:38 -0700822 continue;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530823 if (mp_irqs[i].srcbusirq != m->srcbusirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700824 continue;
825 if (irq_used[i]) {
826 /* already claimed */
827 return -2;
828 }
829 irq_used[i] = 1;
830 return i;
831 }
832
833 /* not found */
834 return -1;
835}
836
837#define SPARE_SLOT_NUM 20
838
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530839static struct mpc_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530840
Rakib Mullick57592222009-04-11 09:04:59 +0600841static void __init check_irq_src(struct mpc_intsrc *m, int *nr_m_spare)
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530842{
843 int i;
844
845 apic_printk(APIC_VERBOSE, "OLD ");
846 print_MP_intsrc_info(m);
847
848 i = get_MP_intsrc_index(m);
849 if (i > 0) {
850 assign_to_mpc_intsrc(&mp_irqs[i], m);
851 apic_printk(APIC_VERBOSE, "NEW ");
852 print_mp_irq_info(&mp_irqs[i]);
853 return;
854 }
855 if (!i) {
856 /* legacy, do nothing */
857 return;
858 }
859 if (*nr_m_spare < SPARE_SLOT_NUM) {
860 /*
861 * not found (-1), or duplicated (-2) are invalid entries,
862 * we need to use the slot later
863 */
864 m_spare[*nr_m_spare] = m;
865 *nr_m_spare += 1;
866 }
867}
868#else /* CONFIG_X86_IO_APIC */
Rakib Mullick57592222009-04-11 09:04:59 +0600869static
870inline void __init check_irq_src(struct mpc_intsrc *m, int *nr_m_spare) {}
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530871#endif /* CONFIG_X86_IO_APIC */
872
Yinghai Luee214552009-05-06 10:07:07 -0700873static int
874check_slot(unsigned long mpc_new_phys, unsigned long mpc_new_length, int count)
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530875{
Yinghai Luee214552009-05-06 10:07:07 -0700876 int ret = 0;
877
878 if (!mpc_new_phys || count <= mpc_new_length) {
879 WARN(1, "update_mptable: No spare slots (length: %x)\n", count);
880 return -1;
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530881 }
882
Yinghai Luee214552009-05-06 10:07:07 -0700883 return ret;
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530884}
Yinghai Lu2944e162008-06-01 13:17:38 -0700885
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530886static int __init replace_intsrc_all(struct mpc_table *mpc,
Yinghai Lu2944e162008-06-01 13:17:38 -0700887 unsigned long mpc_new_phys,
888 unsigned long mpc_new_length)
889{
890#ifdef CONFIG_X86_IO_APIC
891 int i;
Yinghai Lu2944e162008-06-01 13:17:38 -0700892#endif
Yinghai Lu2944e162008-06-01 13:17:38 -0700893 int count = sizeof(*mpc);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530894 int nr_m_spare = 0;
Yinghai Lu2944e162008-06-01 13:17:38 -0700895 unsigned char *mpt = ((unsigned char *)mpc) + count;
896
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530897 printk(KERN_INFO "mpc_length %x\n", mpc->length);
898 while (count < mpc->length) {
Yinghai Lu2944e162008-06-01 13:17:38 -0700899 switch (*mpt) {
900 case MP_PROCESSOR:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530901 skip_entry(&mpt, &count, sizeof(struct mpc_cpu));
902 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700903 case MP_BUS:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530904 skip_entry(&mpt, &count, sizeof(struct mpc_bus));
905 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700906 case MP_IOAPIC:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530907 skip_entry(&mpt, &count, sizeof(struct mpc_ioapic));
908 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700909 case MP_INTSRC:
Ingo Molnarc58603e2009-03-19 08:50:35 +0100910 check_irq_src((struct mpc_intsrc *)mpt, &nr_m_spare);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530911 skip_entry(&mpt, &count, sizeof(struct mpc_intsrc));
912 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700913 case MP_LINTSRC:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530914 skip_entry(&mpt, &count, sizeof(struct mpc_lintsrc));
915 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700916 default:
917 /* wrong mptable */
Jaswinder Singh Rajput5a5737e2009-03-21 13:28:39 +0530918 smp_dump_mptable(mpc, mpt);
Yinghai Lu2944e162008-06-01 13:17:38 -0700919 goto out;
920 }
921 }
922
923#ifdef CONFIG_X86_IO_APIC
924 for (i = 0; i < mp_irq_entries; i++) {
925 if (irq_used[i])
926 continue;
927
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530928 if (mp_irqs[i].irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700929 continue;
930
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530931 if (mp_irqs[i].irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700932 continue;
933
934 if (nr_m_spare > 0) {
Jan Beulich82034d62009-03-12 12:57:10 +0000935 apic_printk(APIC_VERBOSE, "*NEW* found\n");
Yinghai Lu2944e162008-06-01 13:17:38 -0700936 nr_m_spare--;
937 assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
938 m_spare[nr_m_spare] = NULL;
939 } else {
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530940 struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
941 count += sizeof(struct mpc_intsrc);
Yinghai Luee214552009-05-06 10:07:07 -0700942 if (check_slot(mpc_new_phys, mpc_new_length, count) < 0)
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530943 goto out;
Yinghai Lu2944e162008-06-01 13:17:38 -0700944 assign_to_mpc_intsrc(&mp_irqs[i], m);
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530945 mpc->length = count;
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530946 mpt += sizeof(struct mpc_intsrc);
Yinghai Lu2944e162008-06-01 13:17:38 -0700947 }
948 print_mp_irq_info(&mp_irqs[i]);
949 }
950#endif
951out:
952 /* update checksum */
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530953 mpc->checksum = 0;
954 mpc->checksum -= mpf_checksum((unsigned char *)mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -0700955
956 return 0;
957}
958
Yinghai Lufcfa1462008-06-18 17:29:31 -0700959static int __initdata enable_update_mptable;
960
Yinghai Lu2944e162008-06-01 13:17:38 -0700961static int __init update_mptable_setup(char *str)
962{
963 enable_update_mptable = 1;
964 return 0;
965}
966early_param("update_mptable", update_mptable_setup);
967
968static unsigned long __initdata mpc_new_phys;
969static unsigned long mpc_new_length __initdata = 4096;
970
971/* alloc_mptable or alloc_mptable=4k */
972static int __initdata alloc_mptable;
973static int __init parse_alloc_mptable_opt(char *p)
974{
975 enable_update_mptable = 1;
976 alloc_mptable = 1;
977 if (!p)
978 return 0;
979 mpc_new_length = memparse(p, &p);
980 return 0;
981}
982early_param("alloc_mptable", parse_alloc_mptable_opt);
983
984void __init early_reserve_e820_mpc_new(void)
985{
986 if (enable_update_mptable && alloc_mptable) {
987 u64 startt = 0;
988#ifdef CONFIG_X86_TRAMPOLINE
989 startt = TRAMPOLINE_BASE;
990#endif
991 mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
992 }
993}
994
995static int __init update_mp_table(void)
996{
997 char str[16];
998 char oem[10];
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530999 struct mpf_intel *mpf;
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +05301000 struct mpc_table *mpc, *mpc_new;
Yinghai Lu2944e162008-06-01 13:17:38 -07001001
1002 if (!enable_update_mptable)
1003 return 0;
1004
1005 mpf = mpf_found;
1006 if (!mpf)
1007 return 0;
1008
1009 /*
1010 * Now see if we need to go further.
1011 */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301012 if (mpf->feature1 != 0)
Yinghai Lu2944e162008-06-01 13:17:38 -07001013 return 0;
1014
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301015 if (!mpf->physptr)
Yinghai Lu2944e162008-06-01 13:17:38 -07001016 return 0;
1017
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301018 mpc = phys_to_virt(mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -07001019
1020 if (!smp_check_mpc(mpc, oem, str))
1021 return 0;
1022
Jaswinder Singh Rajputba1511b2009-02-11 23:38:25 +05301023 printk(KERN_INFO "mpf: %llx\n", (u64)virt_to_phys(mpf));
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301024 printk(KERN_INFO "physptr: %x\n", mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -07001025
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +05301026 if (mpc_new_phys && mpc->length > mpc_new_length) {
Yinghai Lu2944e162008-06-01 13:17:38 -07001027 mpc_new_phys = 0;
1028 printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
1029 mpc_new_length);
1030 }
1031
1032 if (!mpc_new_phys) {
1033 unsigned char old, new;
1034 /* check if we can change the postion */
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +05301035 mpc->checksum = 0;
1036 old = mpf_checksum((unsigned char *)mpc, mpc->length);
1037 mpc->checksum = 0xff;
1038 new = mpf_checksum((unsigned char *)mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -07001039 if (old == new) {
1040 printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
1041 return 0;
1042 }
1043 printk(KERN_INFO "use in-positon replacing\n");
1044 } else {
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301045 mpf->physptr = mpc_new_phys;
Yinghai Lu2944e162008-06-01 13:17:38 -07001046 mpc_new = phys_to_virt(mpc_new_phys);
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +05301047 memcpy(mpc_new, mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -07001048 mpc = mpc_new;
1049 /* check if we can modify that */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301050 if (mpc_new_phys - mpf->physptr) {
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +05301051 struct mpf_intel *mpf_new;
Yinghai Lu2944e162008-06-01 13:17:38 -07001052 /* steal 16 bytes from [0, 1k) */
1053 printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
1054 mpf_new = phys_to_virt(0x400 - 16);
1055 memcpy(mpf_new, mpf, 16);
1056 mpf = mpf_new;
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301057 mpf->physptr = mpc_new_phys;
Yinghai Lu2944e162008-06-01 13:17:38 -07001058 }
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301059 mpf->checksum = 0;
1060 mpf->checksum -= mpf_checksum((unsigned char *)mpf, 16);
1061 printk(KERN_INFO "physptr new: %x\n", mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -07001062 }
1063
1064 /*
1065 * only replace the one with mp_INT and
1066 * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
1067 * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
1068 * may need pci=routeirq for all coverage
1069 */
1070 replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
1071
1072 return 0;
1073}
1074
1075late_initcall(update_mp_table);