blob: 04560860a72a246a7b0ad51fb7b73125d42072c0 [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
Thomas Gleixnerfd6c6662009-08-20 10:41:58 +020048int __init default_mpc_apic_id(struct mpc_cpu *m)
49{
50 return m->apicid;
51}
52
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +053053static void __init MP_processor_info(struct mpc_cpu *m)
Alexey Starikovskiyc853c672008-03-27 23:54:13 +030054{
55 int apicid;
Alexey Starikovskiy746f2242008-04-04 23:42:15 +040056 char *bootup_cpu = "";
Alexey Starikovskiyc853c672008-03-27 23:54:13 +030057
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053058 if (!(m->cpuflag & CPU_ENABLED)) {
Glauber Costa7b1292e2008-03-03 14:12:41 -030059 disabled_cpus++;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 return;
Glauber Costa7b1292e2008-03-03 14:12:41 -030061 }
Yinghai Lu64898a82008-07-19 18:01:16 -070062
Thomas Gleixnerfd6c6662009-08-20 10:41:58 +020063 apicid = x86_init.mpparse.mpc_apic_id(m);
Yinghai Lu64898a82008-07-19 18:01:16 -070064
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053065 if (m->cpuflag & CPU_BOOTPROCESSOR) {
Alexey Starikovskiy746f2242008-04-04 23:42:15 +040066 bootup_cpu = " (Bootup-CPU)";
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053067 boot_cpu_physical_apicid = m->apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 }
69
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053070 printk(KERN_INFO "Processor #%d%s\n", m->apicid, bootup_cpu);
71 generic_processor_info(apicid, m->apicver);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072}
73
Thomas Gleixner85cc35f2008-05-25 21:21:36 +020074#ifdef CONFIG_X86_IO_APIC
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +053075static void __init MP_bus_info(struct mpc_bus *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
77 char str[7];
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053078 memcpy(str, m->bustype, 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 str[6] = 0;
80
Yinghai Lu64898a82008-07-19 18:01:16 -070081 if (x86_quirks->mpc_oem_bus_info)
82 x86_quirks->mpc_oem_bus_info(m, str);
83 else
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053084 apic_printk(APIC_VERBOSE, "Bus #%d is %s\n", m->busid, str);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Andi Kleen5e4edbb2006-09-26 10:52:35 +020086#if MAX_MP_BUSSES < 256
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053087 if (m->busid >= MAX_MP_BUSSES) {
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070088 printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +040089 " is too large, max. supported is %d\n",
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053090 m->busid, str, MAX_MP_BUSSES - 1);
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070091 return;
92 }
Andi Kleen5e4edbb2006-09-26 10:52:35 +020093#endif
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070094
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +040095 if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053096 set_bit(m->busid, mp_bus_not_pci);
Jaswinder Singh Rajput103ceff2009-01-02 23:43:25 +053097#if defined(CONFIG_EISA) || defined(CONFIG_MCA)
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053098 mp_bus_id_to_type[m->busid] = MP_BUS_ISA;
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +040099#endif
100 } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
Yinghai Lu64898a82008-07-19 18:01:16 -0700101 if (x86_quirks->mpc_oem_pci_bus)
102 x86_quirks->mpc_oem_pci_bus(m);
103
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530104 clear_bit(m->busid, mp_bus_not_pci);
Jaswinder Singh Rajput103ceff2009-01-02 23:43:25 +0530105#if defined(CONFIG_EISA) || defined(CONFIG_MCA)
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530106 mp_bus_id_to_type[m->busid] = MP_BUS_PCI;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400107 } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530108 mp_bus_id_to_type[m->busid] = MP_BUS_EISA;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400109 } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530110 mp_bus_id_to_type[m->busid] = MP_BUS_MCA;
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +0300111#endif
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +0400112 } else
113 printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114}
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400115
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300116static int bad_ioapic(unsigned long address)
117{
118 if (nr_ioapics >= MAX_IO_APICS) {
119 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
120 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
121 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
122 }
123 if (!address) {
124 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
125 " found in table, skipping!\n");
126 return 1;
127 }
128 return 0;
129}
130
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530131static void __init MP_ioapic_info(struct mpc_ioapic *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132{
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530133 if (!(m->flags & MPC_APIC_USABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 return;
135
Thomas Gleixner64883ab2008-01-30 13:30:35 +0100136 printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530137 m->apicid, m->apicver, m->apicaddr);
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300138
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530139 if (bad_ioapic(m->apicaddr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 return;
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300141
Jaswinder Singh Rajputb5ba7e6d2009-01-12 17:46:17 +0530142 mp_ioapics[nr_ioapics].apicaddr = m->apicaddr;
143 mp_ioapics[nr_ioapics].apicid = m->apicid;
144 mp_ioapics[nr_ioapics].type = m->type;
145 mp_ioapics[nr_ioapics].apicver = m->apicver;
146 mp_ioapics[nr_ioapics].flags = m->flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 nr_ioapics++;
148}
149
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530150static void print_MP_intsrc_info(struct mpc_intsrc *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200152 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530154 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbus,
155 m->srcbusirq, m->dstapic, m->dstirq);
Yinghai Lu2944e162008-06-01 13:17:38 -0700156}
157
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530158static void __init print_mp_irq_info(struct mpc_intsrc *mp_irq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700159{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200160 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
Yinghai Lu2944e162008-06-01 13:17:38 -0700161 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530162 mp_irq->irqtype, mp_irq->irqflag & 3,
163 (mp_irq->irqflag >> 2) & 3, mp_irq->srcbus,
164 mp_irq->srcbusirq, mp_irq->dstapic, mp_irq->dstirq);
Yinghai Lu2944e162008-06-01 13:17:38 -0700165}
166
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530167static void __init assign_to_mp_irq(struct mpc_intsrc *m,
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530168 struct mpc_intsrc *mp_irq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700169{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530170 mp_irq->dstapic = m->dstapic;
171 mp_irq->type = m->type;
172 mp_irq->irqtype = m->irqtype;
173 mp_irq->irqflag = m->irqflag;
174 mp_irq->srcbus = m->srcbus;
175 mp_irq->srcbusirq = m->srcbusirq;
176 mp_irq->dstirq = m->dstirq;
Yinghai Lu2944e162008-06-01 13:17:38 -0700177}
178
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530179static void __init assign_to_mpc_intsrc(struct mpc_intsrc *mp_irq,
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530180 struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700181{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530182 m->dstapic = mp_irq->dstapic;
183 m->type = mp_irq->type;
184 m->irqtype = mp_irq->irqtype;
185 m->irqflag = mp_irq->irqflag;
186 m->srcbus = mp_irq->srcbus;
187 m->srcbusirq = mp_irq->srcbusirq;
188 m->dstirq = mp_irq->dstirq;
Yinghai Lu2944e162008-06-01 13:17:38 -0700189}
190
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530191static int __init mp_irq_mpc_intsrc_cmp(struct mpc_intsrc *mp_irq,
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530192 struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700193{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530194 if (mp_irq->dstapic != m->dstapic)
Yinghai Lu2944e162008-06-01 13:17:38 -0700195 return 1;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530196 if (mp_irq->type != m->type)
Yinghai Lu2944e162008-06-01 13:17:38 -0700197 return 2;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530198 if (mp_irq->irqtype != m->irqtype)
Yinghai Lu2944e162008-06-01 13:17:38 -0700199 return 3;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530200 if (mp_irq->irqflag != m->irqflag)
Yinghai Lu2944e162008-06-01 13:17:38 -0700201 return 4;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530202 if (mp_irq->srcbus != m->srcbus)
Yinghai Lu2944e162008-06-01 13:17:38 -0700203 return 5;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530204 if (mp_irq->srcbusirq != m->srcbusirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700205 return 6;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530206 if (mp_irq->dstirq != m->dstirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700207 return 7;
208
209 return 0;
210}
211
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530212static void __init MP_intsrc_info(struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700213{
214 int i;
215
216 print_MP_intsrc_info(m);
217
Yinghai Lufcfa1462008-06-18 17:29:31 -0700218 for (i = 0; i < mp_irq_entries; i++) {
219 if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m))
220 return;
221 }
Yinghai Lu2944e162008-06-01 13:17:38 -0700222
223 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 if (++mp_irq_entries == MAX_IRQ_SOURCES)
225 panic("Max # of irq sources exceeded!!\n");
226}
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530227#else /* CONFIG_X86_IO_APIC */
228static inline void __init MP_bus_info(struct mpc_bus *m) {}
229static inline void __init MP_ioapic_info(struct mpc_ioapic *m) {}
230static inline void __init MP_intsrc_info(struct mpc_intsrc *m) {}
231#endif /* CONFIG_X86_IO_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400233
Jaswinder Singh Rajput8fb29522009-01-03 15:51:54 +0530234static void __init MP_lintsrc_info(struct mpc_lintsrc *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200236 apic_printk(APIC_VERBOSE, "Lint: type %d, pol %d, trig %d, bus %02x,"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
Jaswinder Singh Rajputb5ced7cd2009-01-04 21:55:53 +0530238 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbusid,
239 m->srcbusirq, m->destapic, m->destapiclint);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240}
241
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242/*
243 * Read/parse the MPC
244 */
245
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530246static int __init smp_check_mpc(struct mpc_table *mpc, char *oem, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530249 if (memcmp(mpc->signature, MPC_SIGNATURE, 4)) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400250 printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530251 mpc->signature[0], mpc->signature[1],
252 mpc->signature[2], mpc->signature[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 return 0;
254 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530255 if (mpf_checksum((unsigned char *)mpc, mpc->length)) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400256 printk(KERN_ERR "MPTABLE: checksum error!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 return 0;
258 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530259 if (mpc->spec != 0x01 && mpc->spec != 0x04) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400260 printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530261 mpc->spec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 return 0;
263 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530264 if (!mpc->lapic) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400265 printk(KERN_ERR "MPTABLE: null local APIC address!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 return 0;
267 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530268 memcpy(oem, mpc->oem, 8);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400269 oem[8] = 0;
Yinghai Lu11a62a02008-05-12 15:43:38 +0200270 printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530272 memcpy(str, mpc->productid, 12);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400273 str[12] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
Yinghai Lu11a62a02008-05-12 15:43:38 +0200275 printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530277 printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->lapic);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Yinghai Lu2944e162008-06-01 13:17:38 -0700279 return 1;
280}
281
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530282static void skip_entry(unsigned char **ptr, int *count, int size)
283{
284 *ptr += size;
285 *count += size;
286}
287
Jaswinder Singh Rajput5a5737e2009-03-21 13:28:39 +0530288static void __init smp_dump_mptable(struct mpc_table *mpc, unsigned char *mpt)
289{
290 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n"
291 "type %x\n", *mpt);
292 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
293 1, mpc, mpc->length, 1);
294}
295
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530296static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early)
Yinghai Lu2944e162008-06-01 13:17:38 -0700297{
298 char str[16];
299 char oem[10];
300
301 int count = sizeof(*mpc);
302 unsigned char *mpt = ((unsigned char *)mpc) + count;
303
304 if (!smp_check_mpc(mpc, oem, str))
305 return 0;
306
307#ifdef CONFIG_X86_32
Ingo Molnar9c764242009-01-28 13:44:32 +0100308 generic_mps_oem_check(mpc, oem, str);
Yinghai Lu2944e162008-06-01 13:17:38 -0700309#endif
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400310 /* save the local APIC address, it might be non-default */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 if (!acpi_lapic)
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530312 mp_lapic_addr = mpc->lapic;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400314 if (early)
315 return 1;
316
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530317 if (mpc->oemptr && x86_quirks->smp_read_mpc_oem) {
318 struct mpc_oemtable *oem_table = (void *)(long)mpc->oemptr;
319 x86_quirks->smp_read_mpc_oem(oem_table, mpc->oemsize);
Yinghai Lu64898a82008-07-19 18:01:16 -0700320 }
321
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 /*
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400323 * Now process the configuration blocks.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 */
Thomas Gleixnerf4848472009-08-20 12:05:01 +0200325 x86_init.mpparse.mpc_record(0);
Yinghai Lu64898a82008-07-19 18:01:16 -0700326
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530327 while (count < mpc->length) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400328 switch (*mpt) {
329 case MP_PROCESSOR:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530330 /* ACPI may have already provided this data */
331 if (!acpi_lapic)
Ingo Molnarc58603e2009-03-19 08:50:35 +0100332 MP_processor_info((struct mpc_cpu *)mpt);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530333 skip_entry(&mpt, &count, sizeof(struct mpc_cpu));
334 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400335 case MP_BUS:
Ingo Molnarc58603e2009-03-19 08:50:35 +0100336 MP_bus_info((struct mpc_bus *)mpt);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530337 skip_entry(&mpt, &count, sizeof(struct mpc_bus));
338 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400339 case MP_IOAPIC:
Ingo Molnarc58603e2009-03-19 08:50:35 +0100340 MP_ioapic_info((struct mpc_ioapic *)mpt);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530341 skip_entry(&mpt, &count, sizeof(struct mpc_ioapic));
342 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400343 case MP_INTSRC:
Ingo Molnarc58603e2009-03-19 08:50:35 +0100344 MP_intsrc_info((struct mpc_intsrc *)mpt);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530345 skip_entry(&mpt, &count, sizeof(struct mpc_intsrc));
346 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400347 case MP_LINTSRC:
Ingo Molnarc58603e2009-03-19 08:50:35 +0100348 MP_lintsrc_info((struct mpc_lintsrc *)mpt);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530349 skip_entry(&mpt, &count, sizeof(struct mpc_lintsrc));
350 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400351 default:
Yinghai Lu711554d2008-04-07 11:36:39 -0700352 /* wrong mptable */
Jaswinder Singh Rajput5a5737e2009-03-21 13:28:39 +0530353 smp_dump_mptable(mpc, mpt);
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530354 count = mpc->length;
Yinghai Lu711554d2008-04-07 11:36:39 -0700355 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 }
Thomas Gleixnerf4848472009-08-20 12:05:01 +0200357 x86_init.mpparse.mpc_record(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 }
Yinghai Lue0da3362008-06-08 18:29:22 -0700359
Yinghai Lu26f7ef12009-01-29 14:19:22 -0800360#ifdef CONFIG_X86_BIGSMP
361 generic_bigsmp_probe();
Yinghai Lue0da3362008-06-08 18:29:22 -0700362#endif
363
Ingo Molnar72ce0162009-01-28 06:50:47 +0100364 if (apic->setup_apic_routing)
365 apic->setup_apic_routing();
366
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 if (!num_processors)
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400368 printk(KERN_ERR "MPTABLE: no processors registered!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 return num_processors;
370}
371
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400372#ifdef CONFIG_X86_IO_APIC
373
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374static int __init ELCR_trigger(unsigned int irq)
375{
376 unsigned int port;
377
378 port = 0x4d0 + (irq >> 3);
379 return (inb(port) >> (irq & 7)) & 1;
380}
381
382static void __init construct_default_ioirq_mptable(int mpc_default_type)
383{
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530384 struct mpc_intsrc intsrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 int i;
386 int ELCR_fallback = 0;
387
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530388 intsrc.type = MP_INTSRC;
389 intsrc.irqflag = 0; /* conforming */
390 intsrc.srcbus = 0;
Jaswinder Singh Rajputb5ba7e6d2009-01-12 17:46:17 +0530391 intsrc.dstapic = mp_ioapics[0].apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530393 intsrc.irqtype = mp_INT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
395 /*
396 * If true, we have an ISA/PCI system with no IRQ entries
397 * in the MP table. To prevent the PCI interrupts from being set up
398 * incorrectly, we try to use the ELCR. The sanity check to see if
399 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
400 * never be level sensitive, so we simply see if the ELCR agrees.
401 * If it does, we assume it's valid.
402 */
403 if (mpc_default_type == 5) {
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400404 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
405 "falling back to ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400407 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
408 ELCR_trigger(13))
409 printk(KERN_ERR "ELCR contains invalid data... "
410 "not using ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 else {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400412 printk(KERN_INFO
413 "Using ELCR to identify PCI interrupts\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 ELCR_fallback = 1;
415 }
416 }
417
418 for (i = 0; i < 16; i++) {
419 switch (mpc_default_type) {
420 case 2:
421 if (i == 0 || i == 13)
422 continue; /* IRQ0 & IRQ13 not connected */
423 /* fall through */
424 default:
425 if (i == 2)
426 continue; /* IRQ2 is never connected */
427 }
428
429 if (ELCR_fallback) {
430 /*
431 * If the ELCR indicates a level-sensitive interrupt, we
432 * copy that information over to the MP table in the
433 * irqflag field (level sensitive, active high polarity).
434 */
435 if (ELCR_trigger(i))
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530436 intsrc.irqflag = 13;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 else
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530438 intsrc.irqflag = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 }
440
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530441 intsrc.srcbusirq = i;
442 intsrc.dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 MP_intsrc_info(&intsrc);
444 }
445
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530446 intsrc.irqtype = mp_ExtINT;
447 intsrc.srcbusirq = 0;
448 intsrc.dstirq = 0; /* 8259A to INTIN0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 MP_intsrc_info(&intsrc);
450}
451
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400452
Marcin Slusarz39e00fe2008-08-11 00:09:38 +0200453static void __init construct_ioapic_table(int mpc_default_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454{
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530455 struct mpc_ioapic ioapic;
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +0530456 struct mpc_bus bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530458 bus.type = MP_BUS;
459 bus.busid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 switch (mpc_default_type) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400461 default:
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400462 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400463 mpc_default_type);
464 /* fall through */
465 case 1:
466 case 5:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530467 memcpy(bus.bustype, "ISA ", 6);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400468 break;
469 case 2:
470 case 6:
471 case 3:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530472 memcpy(bus.bustype, "EISA ", 6);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400473 break;
474 case 4:
475 case 7:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530476 memcpy(bus.bustype, "MCA ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 }
478 MP_bus_info(&bus);
479 if (mpc_default_type > 4) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530480 bus.busid = 1;
481 memcpy(bus.bustype, "PCI ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 MP_bus_info(&bus);
483 }
484
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530485 ioapic.type = MP_IOAPIC;
486 ioapic.apicid = 2;
487 ioapic.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
488 ioapic.flags = MPC_APIC_USABLE;
489 ioapic.apicaddr = 0xFEC00000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 MP_ioapic_info(&ioapic);
491
492 /*
493 * We set up most of the low 16 IO-APIC pins according to MPS rules.
494 */
495 construct_default_ioirq_mptable(mpc_default_type);
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200496}
497#else
Marcin Slusarz39e00fe2008-08-11 00:09:38 +0200498static inline void __init construct_ioapic_table(int mpc_default_type) { }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400499#endif
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200500
501static inline void __init construct_default_ISA_mptable(int mpc_default_type)
502{
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +0530503 struct mpc_cpu processor;
Jaswinder Singh Rajput8fb29522009-01-03 15:51:54 +0530504 struct mpc_lintsrc lintsrc;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200505 int linttypes[2] = { mp_ExtINT, mp_NMI };
506 int i;
507
508 /*
509 * local APIC has default address
510 */
511 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
512
513 /*
514 * 2 CPUs, numbered 0 & 1.
515 */
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530516 processor.type = MP_PROCESSOR;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200517 /* Either an integrated APIC or a discrete 82489DX. */
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530518 processor.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
519 processor.cpuflag = CPU_ENABLED;
520 processor.cpufeature = (boot_cpu_data.x86 << 8) |
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200521 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530522 processor.featureflag = boot_cpu_data.x86_capability[0];
523 processor.reserved[0] = 0;
524 processor.reserved[1] = 0;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200525 for (i = 0; i < 2; i++) {
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530526 processor.apicid = i;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200527 MP_processor_info(&processor);
528 }
529
530 construct_ioapic_table(mpc_default_type);
531
Jaswinder Singh Rajputb5ced7cd2009-01-04 21:55:53 +0530532 lintsrc.type = MP_LINTSRC;
533 lintsrc.irqflag = 0; /* conforming */
534 lintsrc.srcbusid = 0;
535 lintsrc.srcbusirq = 0;
536 lintsrc.destapic = MP_APIC_ALL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 for (i = 0; i < 2; i++) {
Jaswinder Singh Rajputb5ced7cd2009-01-04 21:55:53 +0530538 lintsrc.irqtype = linttypes[i];
539 lintsrc.destapiclint = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 MP_lintsrc_info(&lintsrc);
541 }
542}
543
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530544static struct mpf_intel *mpf_found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Yinghai Lu8d4dd912009-03-04 01:25:21 -0800546static unsigned long __init get_mpc_size(unsigned long physptr)
547{
548 struct mpc_table *mpc;
549 unsigned long size;
550
551 mpc = early_ioremap(physptr, PAGE_SIZE);
552 size = mpc->length;
553 early_iounmap(mpc, PAGE_SIZE);
554 apic_printk(APIC_VERBOSE, " mpc: %lx-%lx\n", physptr, physptr + size);
555
556 return size;
557}
558
Jaswinder Singh Rajput0b3ba0c2009-03-21 13:43:20 +0530559static int __init check_physptr(struct mpf_intel *mpf, unsigned int early)
560{
561 struct mpc_table *mpc;
562 unsigned long size;
563
564 size = get_mpc_size(mpf->physptr);
565 mpc = early_ioremap(mpf->physptr, size);
566 /*
567 * Read the physical hardware table. Anything here will
568 * override the defaults.
569 */
570 if (!smp_read_mpc(mpc, early)) {
571#ifdef CONFIG_X86_LOCAL_APIC
572 smp_found_config = 0;
573#endif
574 printk(KERN_ERR "BIOS bug, MP table errors detected!...\n"
575 "... disabling SMP support. (tell your hw vendor)\n");
576 early_iounmap(mpc, size);
577 return -1;
578 }
579 early_iounmap(mpc, size);
580
581 if (early)
582 return -1;
583
584#ifdef CONFIG_X86_IO_APIC
585 /*
586 * If there are no explicit MP IRQ entries, then we are
587 * broken. We set up most of the low 16 IO-APIC pins to
588 * ISA defaults and hope it will work.
589 */
590 if (!mp_irq_entries) {
591 struct mpc_bus bus;
592
593 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
594 "using default mptable. (tell your hw vendor)\n");
595
596 bus.type = MP_BUS;
597 bus.busid = 0;
598 memcpy(bus.bustype, "ISA ", 6);
599 MP_bus_info(&bus);
600
601 construct_default_ioirq_mptable(0);
602 }
603#endif
604
605 return 0;
606}
607
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608/*
609 * Scan the memory blocks for an SMP configuration block.
610 */
Ingo Molnar3b335532008-07-10 17:30:40 +0200611static void __init __get_smp_config(unsigned int early)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612{
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530613 struct mpf_intel *mpf = mpf_found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
Yinghai Lu69b88af2008-12-05 22:45:50 -0800615 if (!mpf)
616 return;
617
618 if (acpi_lapic && early)
619 return;
620
621 /*
622 * MPS doesn't support hyperthreading, aka only have
623 * thread 0 apic id in MPS table
624 */
625 if (acpi_lapic && acpi_ioapic)
626 return;
627
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700628 if (x86_quirks->mach_get_smp_config) {
629 if (x86_quirks->mach_get_smp_config(early))
Ingo Molnar3b335532008-07-10 17:30:40 +0200630 return;
631 }
Andi Kleen9adc1382008-12-04 13:33:35 +0100632
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400633 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530634 mpf->specification);
Alexey Starikovskiyb3e24162008-05-23 01:54:44 +0400635#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530636 if (mpf->feature2 & (1 << 7)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
638 pic_mode = 1;
639 } else {
640 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
641 pic_mode = 0;
642 }
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400643#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 /*
645 * Now see if we need to read further.
646 */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530647 if (mpf->feature1 != 0) {
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400648 if (early) {
649 /*
650 * local APIC has default address
651 */
652 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
653 return;
654 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400656 printk(KERN_INFO "Default MP configuration #%d\n",
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530657 mpf->feature1);
658 construct_default_ISA_mptable(mpf->feature1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530660 } else if (mpf->physptr) {
Jaswinder Singh Rajput0b3ba0c2009-03-21 13:43:20 +0530661 if (check_physptr(mpf, early))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 } else
664 BUG();
665
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400666 if (!early)
667 printk(KERN_INFO "Processors: %d\n", num_processors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 /*
669 * Only use the first configuration found.
670 */
671}
672
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400673void __init early_get_smp_config(void)
674{
675 __get_smp_config(1);
676}
677
678void __init get_smp_config(void)
679{
680 __get_smp_config(0);
681}
682
Rakib Mullick57592222009-04-11 09:04:59 +0600683static void __init smp_reserve_bootmem(struct mpf_intel *mpf)
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530684{
685 unsigned long size = get_mpc_size(mpf->physptr);
686#ifdef CONFIG_X86_32
687 /*
688 * We cannot access to MPC table to compute table size yet,
689 * as only few megabytes from the bottom is mapped now.
690 * PC-9800's MPC table places on the very last of physical
691 * memory; so that simply reserving PAGE_SIZE from mpf->physptr
692 * yields BUG() in reserve_bootmem.
693 * also need to make sure physptr is below than max_low_pfn
694 * we don't need reserve the area above max_low_pfn
695 */
696 unsigned long end = max_low_pfn * PAGE_SIZE;
697
698 if (mpf->physptr < end) {
699 if (mpf->physptr + size > end)
700 size = end - mpf->physptr;
701 reserve_bootmem_generic(mpf->physptr, size, BOOTMEM_DEFAULT);
702 }
703#else
704 reserve_bootmem_generic(mpf->physptr, size, BOOTMEM_DEFAULT);
705#endif
706}
707
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400708static int __init smp_scan_config(unsigned long base, unsigned long length,
709 unsigned reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710{
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400711 unsigned int *bp = phys_to_virt(base);
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530712 struct mpf_intel *mpf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200714 apic_printk(APIC_VERBOSE, "Scan SMP from %p for %ld bytes.\n",
715 bp, length);
Akinobu Mita5d47a272008-04-19 23:55:11 +0900716 BUILD_BUG_ON(sizeof(*mpf) != 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717
718 while (length > 0) {
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530719 mpf = (struct mpf_intel *)bp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 if ((*bp == SMP_MAGIC_IDENT) &&
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530721 (mpf->length == 1) &&
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400722 !mpf_checksum((unsigned char *)bp, 16) &&
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530723 ((mpf->specification == 1)
724 || (mpf->specification == 4))) {
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400725#ifdef CONFIG_X86_LOCAL_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 smp_found_config = 1;
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400727#endif
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400728 mpf_found = mpf;
Yinghai Lub1f006b2008-06-09 18:11:36 -0700729
Jaswinder Singh Rajputba1511b2009-02-11 23:38:25 +0530730 printk(KERN_INFO "found SMP MP-table at [%p] %llx\n",
731 mpf, (u64)virt_to_phys(mpf));
Yinghai Lub1f006b2008-06-09 18:11:36 -0700732
733 if (!reserve)
734 return 1;
Yinghai Luf6243232009-03-04 01:25:54 -0800735 reserve_bootmem_generic(virt_to_phys(mpf), sizeof(*mpf),
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800736 BOOTMEM_DEFAULT);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530737 if (mpf->physptr)
738 smp_reserve_bootmem(mpf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
Yinghai Lud2dbf342008-06-13 02:00:56 -0700740 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 }
742 bp += 4;
743 length -= 16;
744 }
745 return 0;
746}
747
Ingo Molnar3b335532008-07-10 17:30:40 +0200748static void __init __find_smp_config(unsigned int reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749{
750 unsigned int address;
751
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700752 if (x86_quirks->mach_find_smp_config) {
753 if (x86_quirks->mach_find_smp_config(reserve))
Ingo Molnar3b335532008-07-10 17:30:40 +0200754 return;
755 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 /*
757 * FIXME: Linux assumes you have 640K of base ram..
758 * this continues the error...
759 *
760 * 1) Scan the bottom 1K for a signature
761 * 2) Scan the top 1K of base RAM
762 * 3) Scan the 64K of bios
763 */
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400764 if (smp_scan_config(0x0, 0x400, reserve) ||
765 smp_scan_config(639 * 0x400, 0x400, reserve) ||
766 smp_scan_config(0xF0000, 0x10000, reserve))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 return;
768 /*
769 * If it is an SMP machine we should know now, unless the
770 * configuration is in an EISA/MCA bus machine with an
771 * extended bios data area.
772 *
773 * there is a real-mode segmented pointer pointing to the
774 * 4K EBDA area at 0x40E, calculate and scan it here.
775 *
776 * NOTE! There are Linux loaders that will corrupt the EBDA
777 * area, and as such this kind of SMP config may be less
778 * trustworthy, simply because the SMP table may have been
779 * stomped on during early boot. These loaders are buggy and
780 * should be fixed.
781 *
782 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
783 */
784
785 address = get_bios_ebda();
786 if (address)
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400787 smp_scan_config(address, 0x400, reserve);
788}
789
790void __init early_find_smp_config(void)
791{
792 __find_smp_config(0);
793}
794
795void __init find_smp_config(void)
796{
797 __find_smp_config(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798}
Yinghai Lu2944e162008-06-01 13:17:38 -0700799
800#ifdef CONFIG_X86_IO_APIC
801static u8 __initdata irq_used[MAX_IRQ_SOURCES];
802
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530803static int __init get_MP_intsrc_index(struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700804{
805 int i;
806
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530807 if (m->irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700808 return 0;
809
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530810 if (m->irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700811 return 0;
812
813 /* not legacy */
814
815 for (i = 0; i < mp_irq_entries; i++) {
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530816 if (mp_irqs[i].irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700817 continue;
818
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530819 if (mp_irqs[i].irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700820 continue;
821
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530822 if (mp_irqs[i].srcbus != m->srcbus)
Yinghai Lu2944e162008-06-01 13:17:38 -0700823 continue;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530824 if (mp_irqs[i].srcbusirq != m->srcbusirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700825 continue;
826 if (irq_used[i]) {
827 /* already claimed */
828 return -2;
829 }
830 irq_used[i] = 1;
831 return i;
832 }
833
834 /* not found */
835 return -1;
836}
837
838#define SPARE_SLOT_NUM 20
839
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530840static struct mpc_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530841
Rakib Mullick57592222009-04-11 09:04:59 +0600842static void __init check_irq_src(struct mpc_intsrc *m, int *nr_m_spare)
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530843{
844 int i;
845
846 apic_printk(APIC_VERBOSE, "OLD ");
847 print_MP_intsrc_info(m);
848
849 i = get_MP_intsrc_index(m);
850 if (i > 0) {
851 assign_to_mpc_intsrc(&mp_irqs[i], m);
852 apic_printk(APIC_VERBOSE, "NEW ");
853 print_mp_irq_info(&mp_irqs[i]);
854 return;
855 }
856 if (!i) {
857 /* legacy, do nothing */
858 return;
859 }
860 if (*nr_m_spare < SPARE_SLOT_NUM) {
861 /*
862 * not found (-1), or duplicated (-2) are invalid entries,
863 * we need to use the slot later
864 */
865 m_spare[*nr_m_spare] = m;
866 *nr_m_spare += 1;
867 }
868}
869#else /* CONFIG_X86_IO_APIC */
Rakib Mullick57592222009-04-11 09:04:59 +0600870static
871inline void __init check_irq_src(struct mpc_intsrc *m, int *nr_m_spare) {}
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530872#endif /* CONFIG_X86_IO_APIC */
873
Yinghai Luee214552009-05-06 10:07:07 -0700874static int
875check_slot(unsigned long mpc_new_phys, unsigned long mpc_new_length, int count)
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530876{
Yinghai Luee214552009-05-06 10:07:07 -0700877 int ret = 0;
878
879 if (!mpc_new_phys || count <= mpc_new_length) {
880 WARN(1, "update_mptable: No spare slots (length: %x)\n", count);
881 return -1;
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530882 }
883
Yinghai Luee214552009-05-06 10:07:07 -0700884 return ret;
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530885}
Yinghai Lu2944e162008-06-01 13:17:38 -0700886
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530887static int __init replace_intsrc_all(struct mpc_table *mpc,
Yinghai Lu2944e162008-06-01 13:17:38 -0700888 unsigned long mpc_new_phys,
889 unsigned long mpc_new_length)
890{
891#ifdef CONFIG_X86_IO_APIC
892 int i;
Yinghai Lu2944e162008-06-01 13:17:38 -0700893#endif
Yinghai Lu2944e162008-06-01 13:17:38 -0700894 int count = sizeof(*mpc);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530895 int nr_m_spare = 0;
Yinghai Lu2944e162008-06-01 13:17:38 -0700896 unsigned char *mpt = ((unsigned char *)mpc) + count;
897
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530898 printk(KERN_INFO "mpc_length %x\n", mpc->length);
899 while (count < mpc->length) {
Yinghai Lu2944e162008-06-01 13:17:38 -0700900 switch (*mpt) {
901 case MP_PROCESSOR:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530902 skip_entry(&mpt, &count, sizeof(struct mpc_cpu));
903 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700904 case MP_BUS:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530905 skip_entry(&mpt, &count, sizeof(struct mpc_bus));
906 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700907 case MP_IOAPIC:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530908 skip_entry(&mpt, &count, sizeof(struct mpc_ioapic));
909 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700910 case MP_INTSRC:
Ingo Molnarc58603e2009-03-19 08:50:35 +0100911 check_irq_src((struct mpc_intsrc *)mpt, &nr_m_spare);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530912 skip_entry(&mpt, &count, sizeof(struct mpc_intsrc));
913 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700914 case MP_LINTSRC:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530915 skip_entry(&mpt, &count, sizeof(struct mpc_lintsrc));
916 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700917 default:
918 /* wrong mptable */
Jaswinder Singh Rajput5a5737e2009-03-21 13:28:39 +0530919 smp_dump_mptable(mpc, mpt);
Yinghai Lu2944e162008-06-01 13:17:38 -0700920 goto out;
921 }
922 }
923
924#ifdef CONFIG_X86_IO_APIC
925 for (i = 0; i < mp_irq_entries; i++) {
926 if (irq_used[i])
927 continue;
928
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530929 if (mp_irqs[i].irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700930 continue;
931
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530932 if (mp_irqs[i].irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700933 continue;
934
935 if (nr_m_spare > 0) {
Jan Beulich82034d62009-03-12 12:57:10 +0000936 apic_printk(APIC_VERBOSE, "*NEW* found\n");
Yinghai Lu2944e162008-06-01 13:17:38 -0700937 nr_m_spare--;
938 assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
939 m_spare[nr_m_spare] = NULL;
940 } else {
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530941 struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
942 count += sizeof(struct mpc_intsrc);
Yinghai Luee214552009-05-06 10:07:07 -0700943 if (check_slot(mpc_new_phys, mpc_new_length, count) < 0)
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530944 goto out;
Yinghai Lu2944e162008-06-01 13:17:38 -0700945 assign_to_mpc_intsrc(&mp_irqs[i], m);
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530946 mpc->length = count;
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530947 mpt += sizeof(struct mpc_intsrc);
Yinghai Lu2944e162008-06-01 13:17:38 -0700948 }
949 print_mp_irq_info(&mp_irqs[i]);
950 }
951#endif
952out:
953 /* update checksum */
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530954 mpc->checksum = 0;
955 mpc->checksum -= mpf_checksum((unsigned char *)mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -0700956
957 return 0;
958}
959
Yinghai Luf1bdb522009-05-15 13:05:16 -0700960int enable_update_mptable;
Yinghai Lufcfa1462008-06-18 17:29:31 -0700961
Yinghai Lu2944e162008-06-01 13:17:38 -0700962static int __init update_mptable_setup(char *str)
963{
964 enable_update_mptable = 1;
Yinghai Lu629e15d2009-05-15 13:05:16 -0700965#ifdef CONFIG_PCI
966 pci_routeirq = 1;
967#endif
Yinghai Lu2944e162008-06-01 13:17:38 -0700968 return 0;
969}
970early_param("update_mptable", update_mptable_setup);
971
972static unsigned long __initdata mpc_new_phys;
973static unsigned long mpc_new_length __initdata = 4096;
974
975/* alloc_mptable or alloc_mptable=4k */
976static int __initdata alloc_mptable;
977static int __init parse_alloc_mptable_opt(char *p)
978{
979 enable_update_mptable = 1;
Yinghai Lu629e15d2009-05-15 13:05:16 -0700980#ifdef CONFIG_PCI
981 pci_routeirq = 1;
982#endif
Yinghai Lu2944e162008-06-01 13:17:38 -0700983 alloc_mptable = 1;
984 if (!p)
985 return 0;
986 mpc_new_length = memparse(p, &p);
987 return 0;
988}
989early_param("alloc_mptable", parse_alloc_mptable_opt);
990
991void __init early_reserve_e820_mpc_new(void)
992{
993 if (enable_update_mptable && alloc_mptable) {
994 u64 startt = 0;
995#ifdef CONFIG_X86_TRAMPOLINE
996 startt = TRAMPOLINE_BASE;
997#endif
998 mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
999 }
1000}
1001
1002static int __init update_mp_table(void)
1003{
1004 char str[16];
1005 char oem[10];
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +05301006 struct mpf_intel *mpf;
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +05301007 struct mpc_table *mpc, *mpc_new;
Yinghai Lu2944e162008-06-01 13:17:38 -07001008
1009 if (!enable_update_mptable)
1010 return 0;
1011
1012 mpf = mpf_found;
1013 if (!mpf)
1014 return 0;
1015
1016 /*
1017 * Now see if we need to go further.
1018 */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301019 if (mpf->feature1 != 0)
Yinghai Lu2944e162008-06-01 13:17:38 -07001020 return 0;
1021
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301022 if (!mpf->physptr)
Yinghai Lu2944e162008-06-01 13:17:38 -07001023 return 0;
1024
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301025 mpc = phys_to_virt(mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -07001026
1027 if (!smp_check_mpc(mpc, oem, str))
1028 return 0;
1029
Jaswinder Singh Rajputba1511b2009-02-11 23:38:25 +05301030 printk(KERN_INFO "mpf: %llx\n", (u64)virt_to_phys(mpf));
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301031 printk(KERN_INFO "physptr: %x\n", mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -07001032
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +05301033 if (mpc_new_phys && mpc->length > mpc_new_length) {
Yinghai Lu2944e162008-06-01 13:17:38 -07001034 mpc_new_phys = 0;
1035 printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
1036 mpc_new_length);
1037 }
1038
1039 if (!mpc_new_phys) {
1040 unsigned char old, new;
1041 /* check if we can change the postion */
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +05301042 mpc->checksum = 0;
1043 old = mpf_checksum((unsigned char *)mpc, mpc->length);
1044 mpc->checksum = 0xff;
1045 new = mpf_checksum((unsigned char *)mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -07001046 if (old == new) {
1047 printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
1048 return 0;
1049 }
1050 printk(KERN_INFO "use in-positon replacing\n");
1051 } else {
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301052 mpf->physptr = mpc_new_phys;
Yinghai Lu2944e162008-06-01 13:17:38 -07001053 mpc_new = phys_to_virt(mpc_new_phys);
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +05301054 memcpy(mpc_new, mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -07001055 mpc = mpc_new;
1056 /* check if we can modify that */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301057 if (mpc_new_phys - mpf->physptr) {
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +05301058 struct mpf_intel *mpf_new;
Yinghai Lu2944e162008-06-01 13:17:38 -07001059 /* steal 16 bytes from [0, 1k) */
1060 printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
1061 mpf_new = phys_to_virt(0x400 - 16);
1062 memcpy(mpf_new, mpf, 16);
1063 mpf = mpf_new;
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301064 mpf->physptr = mpc_new_phys;
Yinghai Lu2944e162008-06-01 13:17:38 -07001065 }
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301066 mpf->checksum = 0;
1067 mpf->checksum -= mpf_checksum((unsigned char *)mpf, 16);
1068 printk(KERN_INFO "physptr new: %x\n", mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -07001069 }
1070
1071 /*
1072 * only replace the one with mp_INT and
1073 * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
1074 * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
1075 * may need pci=routeirq for all coverage
1076 */
1077 replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
1078
1079 return 0;
1080}
1081
1082late_initcall(update_mp_table);