blob: a86a65537433d139b7245ec39b8398c97250e7a7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04002 * Intel Multiprocessor Specification 1.1 and 1.4
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * compliant MP-table parsing routines.
4 *
Alan Cox87c6fe22009-01-05 14:08:04 +00005 * (c) 1995 Alan Cox, Building #3 <alan@lxorguk.ukuu.org.uk>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * (c) 1998, 1999, 2000 Ingo Molnar <mingo@redhat.com>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +04007 * (c) 2008 Alexey Starikovskiy <astarikovskiy@suse.de>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
9
10#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/bootmem.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/kernel_stat.h>
15#include <linux/mc146818rtc.h>
16#include <linux/bitops.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040017#include <linux/acpi.h>
18#include <linux/module.h>
Jaswinder Singh Rajput103ceff2009-01-02 23:43:25 +053019#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/mtrr.h>
22#include <asm/mpspec.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040023#include <asm/pgalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/io_apic.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040025#include <asm/proto.h>
Alexey Starikovskiyce3fe6b2008-03-17 22:08:17 +030026#include <asm/bios_ebda.h>
Yinghai Lu2944e162008-06-01 13:17:38 -070027#include <asm/e820.h>
28#include <asm/trampoline.h>
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -070029#include <asm/setup.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31#include <mach_apic.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040032#ifdef CONFIG_X86_32
Andi Kleen874c4fe2006-09-26 10:52:26 +020033#include <mach_apicdef.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <mach_mpparse.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040035#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Linus Torvalds1da177e2005-04-16 15:20:36 -070037/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 * Checksum an MP configuration block.
39 */
40
41static int __init mpf_checksum(unsigned char *mp, int len)
42{
43 int sum = 0;
44
45 while (len--)
46 sum += *mp++;
47
48 return sum & 0xFF;
49}
50
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +053051static void __init MP_processor_info(struct mpc_cpu *m)
Alexey Starikovskiyc853c672008-03-27 23:54:13 +030052{
53 int apicid;
Alexey Starikovskiy746f2242008-04-04 23:42:15 +040054 char *bootup_cpu = "";
Alexey Starikovskiyc853c672008-03-27 23:54:13 +030055
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053056 if (!(m->cpuflag & CPU_ENABLED)) {
Glauber Costa7b1292e2008-03-03 14:12:41 -030057 disabled_cpus++;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 return;
Glauber Costa7b1292e2008-03-03 14:12:41 -030059 }
Yinghai Lu64898a82008-07-19 18:01:16 -070060
61 if (x86_quirks->mpc_apic_id)
62 apicid = x86_quirks->mpc_apic_id(m);
Yinghai Luab530e12008-06-03 10:25:54 -070063 else
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053064 apicid = m->apicid;
Yinghai Lu64898a82008-07-19 18:01:16 -070065
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053066 if (m->cpuflag & CPU_BOOTPROCESSOR) {
Alexey Starikovskiy746f2242008-04-04 23:42:15 +040067 bootup_cpu = " (Bootup-CPU)";
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053068 boot_cpu_physical_apicid = m->apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 }
70
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053071 printk(KERN_INFO "Processor #%d%s\n", m->apicid, bootup_cpu);
72 generic_processor_info(apicid, m->apicver);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073}
74
Thomas Gleixner85cc35f2008-05-25 21:21:36 +020075#ifdef CONFIG_X86_IO_APIC
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +053076static void __init MP_bus_info(struct mpc_bus *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077{
78 char str[7];
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053079 memcpy(str, m->bustype, 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 str[6] = 0;
81
Yinghai Lu64898a82008-07-19 18:01:16 -070082 if (x86_quirks->mpc_oem_bus_info)
83 x86_quirks->mpc_oem_bus_info(m, str);
84 else
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053085 apic_printk(APIC_VERBOSE, "Bus #%d is %s\n", m->busid, str);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Andi Kleen5e4edbb2006-09-26 10:52:35 +020087#if MAX_MP_BUSSES < 256
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053088 if (m->busid >= MAX_MP_BUSSES) {
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070089 printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +040090 " is too large, max. supported is %d\n",
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053091 m->busid, str, MAX_MP_BUSSES - 1);
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070092 return;
93 }
Andi Kleen5e4edbb2006-09-26 10:52:35 +020094#endif
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070095
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +040096 if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053097 set_bit(m->busid, mp_bus_not_pci);
Jaswinder Singh Rajput103ceff2009-01-02 23:43:25 +053098#if defined(CONFIG_EISA) || defined(CONFIG_MCA)
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053099 mp_bus_id_to_type[m->busid] = MP_BUS_ISA;
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +0400100#endif
101 } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
Yinghai Lu64898a82008-07-19 18:01:16 -0700102 if (x86_quirks->mpc_oem_pci_bus)
103 x86_quirks->mpc_oem_pci_bus(m);
104
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530105 clear_bit(m->busid, mp_bus_not_pci);
Jaswinder Singh Rajput103ceff2009-01-02 23:43:25 +0530106#if defined(CONFIG_EISA) || defined(CONFIG_MCA)
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530107 mp_bus_id_to_type[m->busid] = MP_BUS_PCI;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400108 } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530109 mp_bus_id_to_type[m->busid] = MP_BUS_EISA;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400110 } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530111 mp_bus_id_to_type[m->busid] = MP_BUS_MCA;
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +0300112#endif
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +0400113 } else
114 printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115}
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200116#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400118#ifdef CONFIG_X86_IO_APIC
119
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300120static int bad_ioapic(unsigned long address)
121{
122 if (nr_ioapics >= MAX_IO_APICS) {
123 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
124 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
125 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
126 }
127 if (!address) {
128 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
129 " found in table, skipping!\n");
130 return 1;
131 }
132 return 0;
133}
134
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530135static void __init MP_ioapic_info(struct mpc_ioapic *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136{
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530137 if (!(m->flags & MPC_APIC_USABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 return;
139
Thomas Gleixner64883ab2008-01-30 13:30:35 +0100140 printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530141 m->apicid, m->apicver, m->apicaddr);
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300142
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530143 if (bad_ioapic(m->apicaddr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 return;
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300145
Jaswinder Singh Rajputb5ba7e62009-01-12 17:46:17 +0530146 mp_ioapics[nr_ioapics].apicaddr = m->apicaddr;
147 mp_ioapics[nr_ioapics].apicid = m->apicid;
148 mp_ioapics[nr_ioapics].type = m->type;
149 mp_ioapics[nr_ioapics].apicver = m->apicver;
150 mp_ioapics[nr_ioapics].flags = m->flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 nr_ioapics++;
152}
153
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530154static void print_MP_intsrc_info(struct mpc_intsrc *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200156 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530158 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbus,
159 m->srcbusirq, m->dstapic, m->dstirq);
Yinghai Lu2944e162008-06-01 13:17:38 -0700160}
161
162static void __init print_mp_irq_info(struct mp_config_intsrc *mp_irq)
163{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200164 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
Yinghai Lu2944e162008-06-01 13:17:38 -0700165 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
166 mp_irq->mp_irqtype, mp_irq->mp_irqflag & 3,
167 (mp_irq->mp_irqflag >> 2) & 3, mp_irq->mp_srcbus,
168 mp_irq->mp_srcbusirq, mp_irq->mp_dstapic, mp_irq->mp_dstirq);
169}
170
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530171static void __init assign_to_mp_irq(struct mpc_intsrc *m,
Yinghai Lu2944e162008-06-01 13:17:38 -0700172 struct mp_config_intsrc *mp_irq)
173{
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530174 mp_irq->mp_dstapic = m->dstapic;
175 mp_irq->mp_type = m->type;
176 mp_irq->mp_irqtype = m->irqtype;
177 mp_irq->mp_irqflag = m->irqflag;
178 mp_irq->mp_srcbus = m->srcbus;
179 mp_irq->mp_srcbusirq = m->srcbusirq;
180 mp_irq->mp_dstirq = m->dstirq;
Yinghai Lu2944e162008-06-01 13:17:38 -0700181}
182
183static void __init assign_to_mpc_intsrc(struct mp_config_intsrc *mp_irq,
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530184 struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700185{
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530186 m->dstapic = mp_irq->mp_dstapic;
187 m->type = mp_irq->mp_type;
188 m->irqtype = mp_irq->mp_irqtype;
189 m->irqflag = mp_irq->mp_irqflag;
190 m->srcbus = mp_irq->mp_srcbus;
191 m->srcbusirq = mp_irq->mp_srcbusirq;
192 m->dstirq = mp_irq->mp_dstirq;
Yinghai Lu2944e162008-06-01 13:17:38 -0700193}
194
Yinghai Lufcfa1462008-06-18 17:29:31 -0700195static int __init mp_irq_mpc_intsrc_cmp(struct mp_config_intsrc *mp_irq,
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530196 struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700197{
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530198 if (mp_irq->mp_dstapic != m->dstapic)
Yinghai Lu2944e162008-06-01 13:17:38 -0700199 return 1;
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530200 if (mp_irq->mp_type != m->type)
Yinghai Lu2944e162008-06-01 13:17:38 -0700201 return 2;
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530202 if (mp_irq->mp_irqtype != m->irqtype)
Yinghai Lu2944e162008-06-01 13:17:38 -0700203 return 3;
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530204 if (mp_irq->mp_irqflag != m->irqflag)
Yinghai Lu2944e162008-06-01 13:17:38 -0700205 return 4;
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530206 if (mp_irq->mp_srcbus != m->srcbus)
Yinghai Lu2944e162008-06-01 13:17:38 -0700207 return 5;
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530208 if (mp_irq->mp_srcbusirq != m->srcbusirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700209 return 6;
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530210 if (mp_irq->mp_dstirq != m->dstirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700211 return 7;
212
213 return 0;
214}
215
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530216static void __init MP_intsrc_info(struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700217{
218 int i;
219
220 print_MP_intsrc_info(m);
221
Yinghai Lufcfa1462008-06-18 17:29:31 -0700222 for (i = 0; i < mp_irq_entries; i++) {
223 if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m))
224 return;
225 }
Yinghai Lu2944e162008-06-01 13:17:38 -0700226
227 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 if (++mp_irq_entries == MAX_IRQ_SOURCES)
229 panic("Max # of irq sources exceeded!!\n");
230}
231
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400232#endif
233
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 Rajputb5ced7c2009-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 Rajputf29521e2009-01-03 15:46:57 +0530282static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early)
Yinghai Lu2944e162008-06-01 13:17:38 -0700283{
284 char str[16];
285 char oem[10];
286
287 int count = sizeof(*mpc);
288 unsigned char *mpt = ((unsigned char *)mpc) + count;
289
290 if (!smp_check_mpc(mpc, oem, str))
291 return 0;
292
293#ifdef CONFIG_X86_32
Yinghai Lud49c4282008-06-08 18:31:54 -0700294 /*
295 * need to make sure summit and es7000's mps_oem_check is safe to be
296 * called early via genericarch 's mps_oem_check
297 */
298 if (early) {
299#ifdef CONFIG_X86_NUMAQ
300 numaq_mps_oem_check(mpc, oem, str);
301#endif
302 } else
303 mps_oem_check(mpc, oem, str);
Yinghai Lu2944e162008-06-01 13:17:38 -0700304#endif
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400305 /* save the local APIC address, it might be non-default */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 if (!acpi_lapic)
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530307 mp_lapic_addr = mpc->lapic;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400309 if (early)
310 return 1;
311
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530312 if (mpc->oemptr && x86_quirks->smp_read_mpc_oem) {
313 struct mpc_oemtable *oem_table = (void *)(long)mpc->oemptr;
314 x86_quirks->smp_read_mpc_oem(oem_table, mpc->oemsize);
Yinghai Lu64898a82008-07-19 18:01:16 -0700315 }
316
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 /*
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400318 * Now process the configuration blocks.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 */
Yinghai Lu64898a82008-07-19 18:01:16 -0700320 if (x86_quirks->mpc_record)
321 *x86_quirks->mpc_record = 0;
322
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530323 while (count < mpc->length) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400324 switch (*mpt) {
325 case MP_PROCESSOR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 {
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +0530327 struct mpc_cpu *m = (struct mpc_cpu *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 /* ACPI may have already provided this data */
329 if (!acpi_lapic)
330 MP_processor_info(m);
331 mpt += sizeof(*m);
332 count += sizeof(*m);
333 break;
334 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400335 case MP_BUS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 {
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +0530337 struct mpc_bus *m = (struct mpc_bus *)mpt;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200338#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 MP_bus_info(m);
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200340#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 mpt += sizeof(*m);
342 count += sizeof(*m);
343 break;
344 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400345 case MP_IOAPIC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 {
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400347#ifdef CONFIG_X86_IO_APIC
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530348 struct mpc_ioapic *m = (struct mpc_ioapic *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 MP_ioapic_info(m);
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400350#endif
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530351 mpt += sizeof(struct mpc_ioapic);
352 count += sizeof(struct mpc_ioapic);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 break;
354 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400355 case MP_INTSRC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 {
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400357#ifdef CONFIG_X86_IO_APIC
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530358 struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
360 MP_intsrc_info(m);
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400361#endif
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530362 mpt += sizeof(struct mpc_intsrc);
363 count += sizeof(struct mpc_intsrc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 break;
365 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400366 case MP_LINTSRC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 {
Jaswinder Singh Rajput8fb29522009-01-03 15:51:54 +0530368 struct mpc_lintsrc *m =
369 (struct mpc_lintsrc *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 MP_lintsrc_info(m);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400371 mpt += sizeof(*m);
372 count += sizeof(*m);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 break;
374 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400375 default:
Yinghai Lu711554d2008-04-07 11:36:39 -0700376 /* wrong mptable */
377 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
378 printk(KERN_ERR "type %x\n", *mpt);
379 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530380 1, mpc, mpc->length, 1);
381 count = mpc->length;
Yinghai Lu711554d2008-04-07 11:36:39 -0700382 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 }
Yinghai Lu64898a82008-07-19 18:01:16 -0700384 if (x86_quirks->mpc_record)
385 (*x86_quirks->mpc_record)++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 }
Yinghai Lue0da3362008-06-08 18:29:22 -0700387
388#ifdef CONFIG_X86_GENERICARCH
389 generic_bigsmp_probe();
390#endif
391
Suresh Siddha6e1cb382008-07-10 11:16:58 -0700392#ifdef CONFIG_X86_32
Ingo Molnar3c43f032007-05-02 19:27:04 +0200393 setup_apic_routing();
Suresh Siddha6e1cb382008-07-10 11:16:58 -0700394#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 if (!num_processors)
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400396 printk(KERN_ERR "MPTABLE: no processors registered!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 return num_processors;
398}
399
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400400#ifdef CONFIG_X86_IO_APIC
401
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402static int __init ELCR_trigger(unsigned int irq)
403{
404 unsigned int port;
405
406 port = 0x4d0 + (irq >> 3);
407 return (inb(port) >> (irq & 7)) & 1;
408}
409
410static void __init construct_default_ioirq_mptable(int mpc_default_type)
411{
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530412 struct mpc_intsrc intsrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 int i;
414 int ELCR_fallback = 0;
415
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530416 intsrc.type = MP_INTSRC;
417 intsrc.irqflag = 0; /* conforming */
418 intsrc.srcbus = 0;
Jaswinder Singh Rajputb5ba7e62009-01-12 17:46:17 +0530419 intsrc.dstapic = mp_ioapics[0].apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530421 intsrc.irqtype = mp_INT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
423 /*
424 * If true, we have an ISA/PCI system with no IRQ entries
425 * in the MP table. To prevent the PCI interrupts from being set up
426 * incorrectly, we try to use the ELCR. The sanity check to see if
427 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
428 * never be level sensitive, so we simply see if the ELCR agrees.
429 * If it does, we assume it's valid.
430 */
431 if (mpc_default_type == 5) {
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400432 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
433 "falling back to ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400435 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
436 ELCR_trigger(13))
437 printk(KERN_ERR "ELCR contains invalid data... "
438 "not using ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 else {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400440 printk(KERN_INFO
441 "Using ELCR to identify PCI interrupts\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 ELCR_fallback = 1;
443 }
444 }
445
446 for (i = 0; i < 16; i++) {
447 switch (mpc_default_type) {
448 case 2:
449 if (i == 0 || i == 13)
450 continue; /* IRQ0 & IRQ13 not connected */
451 /* fall through */
452 default:
453 if (i == 2)
454 continue; /* IRQ2 is never connected */
455 }
456
457 if (ELCR_fallback) {
458 /*
459 * If the ELCR indicates a level-sensitive interrupt, we
460 * copy that information over to the MP table in the
461 * irqflag field (level sensitive, active high polarity).
462 */
463 if (ELCR_trigger(i))
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530464 intsrc.irqflag = 13;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 else
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530466 intsrc.irqflag = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 }
468
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530469 intsrc.srcbusirq = i;
470 intsrc.dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 MP_intsrc_info(&intsrc);
472 }
473
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530474 intsrc.irqtype = mp_ExtINT;
475 intsrc.srcbusirq = 0;
476 intsrc.dstirq = 0; /* 8259A to INTIN0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 MP_intsrc_info(&intsrc);
478}
479
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400480
Marcin Slusarz39e00fe2008-08-11 00:09:38 +0200481static void __init construct_ioapic_table(int mpc_default_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482{
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530483 struct mpc_ioapic ioapic;
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +0530484 struct mpc_bus bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530486 bus.type = MP_BUS;
487 bus.busid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 switch (mpc_default_type) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400489 default:
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400490 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400491 mpc_default_type);
492 /* fall through */
493 case 1:
494 case 5:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530495 memcpy(bus.bustype, "ISA ", 6);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400496 break;
497 case 2:
498 case 6:
499 case 3:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530500 memcpy(bus.bustype, "EISA ", 6);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400501 break;
502 case 4:
503 case 7:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530504 memcpy(bus.bustype, "MCA ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 }
506 MP_bus_info(&bus);
507 if (mpc_default_type > 4) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530508 bus.busid = 1;
509 memcpy(bus.bustype, "PCI ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 MP_bus_info(&bus);
511 }
512
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530513 ioapic.type = MP_IOAPIC;
514 ioapic.apicid = 2;
515 ioapic.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
516 ioapic.flags = MPC_APIC_USABLE;
517 ioapic.apicaddr = 0xFEC00000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 MP_ioapic_info(&ioapic);
519
520 /*
521 * We set up most of the low 16 IO-APIC pins according to MPS rules.
522 */
523 construct_default_ioirq_mptable(mpc_default_type);
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200524}
525#else
Marcin Slusarz39e00fe2008-08-11 00:09:38 +0200526static inline void __init construct_ioapic_table(int mpc_default_type) { }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400527#endif
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200528
529static inline void __init construct_default_ISA_mptable(int mpc_default_type)
530{
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +0530531 struct mpc_cpu processor;
Jaswinder Singh Rajput8fb29522009-01-03 15:51:54 +0530532 struct mpc_lintsrc lintsrc;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200533 int linttypes[2] = { mp_ExtINT, mp_NMI };
534 int i;
535
536 /*
537 * local APIC has default address
538 */
539 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
540
541 /*
542 * 2 CPUs, numbered 0 & 1.
543 */
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530544 processor.type = MP_PROCESSOR;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200545 /* Either an integrated APIC or a discrete 82489DX. */
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530546 processor.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
547 processor.cpuflag = CPU_ENABLED;
548 processor.cpufeature = (boot_cpu_data.x86 << 8) |
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200549 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530550 processor.featureflag = boot_cpu_data.x86_capability[0];
551 processor.reserved[0] = 0;
552 processor.reserved[1] = 0;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200553 for (i = 0; i < 2; i++) {
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530554 processor.apicid = i;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200555 MP_processor_info(&processor);
556 }
557
558 construct_ioapic_table(mpc_default_type);
559
Jaswinder Singh Rajputb5ced7c2009-01-04 21:55:53 +0530560 lintsrc.type = MP_LINTSRC;
561 lintsrc.irqflag = 0; /* conforming */
562 lintsrc.srcbusid = 0;
563 lintsrc.srcbusirq = 0;
564 lintsrc.destapic = MP_APIC_ALL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 for (i = 0; i < 2; i++) {
Jaswinder Singh Rajputb5ced7c2009-01-04 21:55:53 +0530566 lintsrc.irqtype = linttypes[i];
567 lintsrc.destapiclint = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 MP_lintsrc_info(&lintsrc);
569 }
570}
571
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530572static struct mpf_intel *mpf_found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
574/*
575 * Scan the memory blocks for an SMP configuration block.
576 */
Ingo Molnar3b335532008-07-10 17:30:40 +0200577static void __init __get_smp_config(unsigned int early)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578{
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530579 struct mpf_intel *mpf = mpf_found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
Yinghai Lu69b88af2008-12-05 22:45:50 -0800581 if (!mpf)
582 return;
583
584 if (acpi_lapic && early)
585 return;
586
587 /*
588 * MPS doesn't support hyperthreading, aka only have
589 * thread 0 apic id in MPS table
590 */
591 if (acpi_lapic && acpi_ioapic)
592 return;
593
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700594 if (x86_quirks->mach_get_smp_config) {
595 if (x86_quirks->mach_get_smp_config(early))
Ingo Molnar3b335532008-07-10 17:30:40 +0200596 return;
597 }
Andi Kleen9adc1382008-12-04 13:33:35 +0100598
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400599 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530600 mpf->specification);
Alexey Starikovskiyb3e24162008-05-23 01:54:44 +0400601#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530602 if (mpf->feature2 & (1 << 7)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
604 pic_mode = 1;
605 } else {
606 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
607 pic_mode = 0;
608 }
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400609#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 /*
611 * Now see if we need to read further.
612 */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530613 if (mpf->feature1 != 0) {
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400614 if (early) {
615 /*
616 * local APIC has default address
617 */
618 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
619 return;
620 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400622 printk(KERN_INFO "Default MP configuration #%d\n",
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530623 mpf->feature1);
624 construct_default_ISA_mptable(mpf->feature1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530626 } else if (mpf->physptr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
628 /*
629 * Read the physical hardware table. Anything here will
630 * override the defaults.
631 */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530632 if (!smp_read_mpc(phys_to_virt(mpf->physptr), early)) {
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400633#ifdef CONFIG_X86_LOCAL_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 smp_found_config = 0;
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400635#endif
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400636 printk(KERN_ERR
637 "BIOS bug, MP table errors detected!...\n");
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400638 printk(KERN_ERR "... disabling SMP support. "
639 "(tell your hw vendor)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 return;
641 }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400642
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400643 if (early)
644 return;
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400645#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 /*
647 * If there are no explicit MP IRQ entries, then we are
648 * broken. We set up most of the low 16 IO-APIC pins to
649 * ISA defaults and hope it will work.
650 */
651 if (!mp_irq_entries) {
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +0530652 struct mpc_bus bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400654 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
655 "using default mptable. "
656 "(tell your hw vendor)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530658 bus.type = MP_BUS;
659 bus.busid = 0;
660 memcpy(bus.bustype, "ISA ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 MP_bus_info(&bus);
662
663 construct_default_ioirq_mptable(0);
664 }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400665#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 } else
667 BUG();
668
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400669 if (!early)
670 printk(KERN_INFO "Processors: %d\n", num_processors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 /*
672 * Only use the first configuration found.
673 */
674}
675
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400676void __init early_get_smp_config(void)
677{
678 __get_smp_config(1);
679}
680
681void __init get_smp_config(void)
682{
683 __get_smp_config(0);
684}
685
686static int __init smp_scan_config(unsigned long base, unsigned long length,
687 unsigned reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688{
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400689 unsigned int *bp = phys_to_virt(base);
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530690 struct mpf_intel *mpf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200692 apic_printk(APIC_VERBOSE, "Scan SMP from %p for %ld bytes.\n",
693 bp, length);
Akinobu Mita5d47a272008-04-19 23:55:11 +0900694 BUILD_BUG_ON(sizeof(*mpf) != 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
696 while (length > 0) {
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530697 mpf = (struct mpf_intel *)bp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 if ((*bp == SMP_MAGIC_IDENT) &&
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530699 (mpf->length == 1) &&
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400700 !mpf_checksum((unsigned char *)bp, 16) &&
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530701 ((mpf->specification == 1)
702 || (mpf->specification == 4))) {
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400703#ifdef CONFIG_X86_LOCAL_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 smp_found_config = 1;
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400705#endif
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400706 mpf_found = mpf;
Yinghai Lub1f006b2008-06-09 18:11:36 -0700707
Ingo Molnare91a3b432008-01-30 13:33:08 +0100708 printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400709 mpf, virt_to_phys(mpf));
Yinghai Lub1f006b2008-06-09 18:11:36 -0700710
711 if (!reserve)
712 return 1;
Yinghai Lud2dbf342008-06-13 02:00:56 -0700713 reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE,
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800714 BOOTMEM_DEFAULT);
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530715 if (mpf->physptr) {
Yinghai Lud2dbf342008-06-13 02:00:56 -0700716 unsigned long size = PAGE_SIZE;
717#ifdef CONFIG_X86_32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 /*
719 * We cannot access to MPC table to compute
720 * table size yet, as only few megabytes from
721 * the bottom is mapped now.
722 * PC-9800's MPC table places on the very last
723 * of physical memory; so that simply reserving
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530724 * PAGE_SIZE from mpf->physptr yields BUG()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 * in reserve_bootmem.
726 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 unsigned long end = max_low_pfn * PAGE_SIZE;
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530728 if (mpf->physptr + size > end)
729 size = end - mpf->physptr;
Yinghai Lud2dbf342008-06-13 02:00:56 -0700730#endif
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530731 reserve_bootmem_generic(mpf->physptr, size,
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800732 BOOTMEM_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 }
734
Yinghai Lud2dbf342008-06-13 02:00:56 -0700735 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 }
737 bp += 4;
738 length -= 16;
739 }
740 return 0;
741}
742
Ingo Molnar3b335532008-07-10 17:30:40 +0200743static void __init __find_smp_config(unsigned int reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744{
745 unsigned int address;
746
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700747 if (x86_quirks->mach_find_smp_config) {
748 if (x86_quirks->mach_find_smp_config(reserve))
Ingo Molnar3b335532008-07-10 17:30:40 +0200749 return;
750 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 /*
752 * FIXME: Linux assumes you have 640K of base ram..
753 * this continues the error...
754 *
755 * 1) Scan the bottom 1K for a signature
756 * 2) Scan the top 1K of base RAM
757 * 3) Scan the 64K of bios
758 */
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400759 if (smp_scan_config(0x0, 0x400, reserve) ||
760 smp_scan_config(639 * 0x400, 0x400, reserve) ||
761 smp_scan_config(0xF0000, 0x10000, reserve))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 return;
763 /*
764 * If it is an SMP machine we should know now, unless the
765 * configuration is in an EISA/MCA bus machine with an
766 * extended bios data area.
767 *
768 * there is a real-mode segmented pointer pointing to the
769 * 4K EBDA area at 0x40E, calculate and scan it here.
770 *
771 * NOTE! There are Linux loaders that will corrupt the EBDA
772 * area, and as such this kind of SMP config may be less
773 * trustworthy, simply because the SMP table may have been
774 * stomped on during early boot. These loaders are buggy and
775 * should be fixed.
776 *
777 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
778 */
779
780 address = get_bios_ebda();
781 if (address)
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400782 smp_scan_config(address, 0x400, reserve);
783}
784
785void __init early_find_smp_config(void)
786{
787 __find_smp_config(0);
788}
789
790void __init find_smp_config(void)
791{
792 __find_smp_config(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793}
Yinghai Lu2944e162008-06-01 13:17:38 -0700794
795#ifdef CONFIG_X86_IO_APIC
796static u8 __initdata irq_used[MAX_IRQ_SOURCES];
797
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530798static int __init get_MP_intsrc_index(struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700799{
800 int i;
801
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530802 if (m->irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700803 return 0;
804
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530805 if (m->irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700806 return 0;
807
808 /* not legacy */
809
810 for (i = 0; i < mp_irq_entries; i++) {
811 if (mp_irqs[i].mp_irqtype != mp_INT)
812 continue;
813
814 if (mp_irqs[i].mp_irqflag != 0x0f)
815 continue;
816
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530817 if (mp_irqs[i].mp_srcbus != m->srcbus)
Yinghai Lu2944e162008-06-01 13:17:38 -0700818 continue;
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530819 if (mp_irqs[i].mp_srcbusirq != m->srcbusirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700820 continue;
821 if (irq_used[i]) {
822 /* already claimed */
823 return -2;
824 }
825 irq_used[i] = 1;
826 return i;
827 }
828
829 /* not found */
830 return -1;
831}
832
833#define SPARE_SLOT_NUM 20
834
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530835static struct mpc_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
Yinghai Lu2944e162008-06-01 13:17:38 -0700836#endif
837
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530838static int __init replace_intsrc_all(struct mpc_table *mpc,
Yinghai Lu2944e162008-06-01 13:17:38 -0700839 unsigned long mpc_new_phys,
840 unsigned long mpc_new_length)
841{
842#ifdef CONFIG_X86_IO_APIC
843 int i;
844 int nr_m_spare = 0;
845#endif
846
847 int count = sizeof(*mpc);
848 unsigned char *mpt = ((unsigned char *)mpc) + count;
849
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530850 printk(KERN_INFO "mpc_length %x\n", mpc->length);
851 while (count < mpc->length) {
Yinghai Lu2944e162008-06-01 13:17:38 -0700852 switch (*mpt) {
853 case MP_PROCESSOR:
854 {
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +0530855 struct mpc_cpu *m = (struct mpc_cpu *)mpt;
Yinghai Lu2944e162008-06-01 13:17:38 -0700856 mpt += sizeof(*m);
857 count += sizeof(*m);
858 break;
859 }
860 case MP_BUS:
861 {
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +0530862 struct mpc_bus *m = (struct mpc_bus *)mpt;
Yinghai Lu2944e162008-06-01 13:17:38 -0700863 mpt += sizeof(*m);
864 count += sizeof(*m);
865 break;
866 }
867 case MP_IOAPIC:
868 {
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530869 mpt += sizeof(struct mpc_ioapic);
870 count += sizeof(struct mpc_ioapic);
Yinghai Lu2944e162008-06-01 13:17:38 -0700871 break;
872 }
873 case MP_INTSRC:
874 {
875#ifdef CONFIG_X86_IO_APIC
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530876 struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
Yinghai Lu2944e162008-06-01 13:17:38 -0700877
878 printk(KERN_INFO "OLD ");
879 print_MP_intsrc_info(m);
880 i = get_MP_intsrc_index(m);
881 if (i > 0) {
882 assign_to_mpc_intsrc(&mp_irqs[i], m);
883 printk(KERN_INFO "NEW ");
884 print_mp_irq_info(&mp_irqs[i]);
885 } else if (!i) {
886 /* legacy, do nothing */
887 } else if (nr_m_spare < SPARE_SLOT_NUM) {
888 /*
889 * not found (-1), or duplicated (-2)
890 * are invalid entries,
891 * we need to use the slot later
892 */
893 m_spare[nr_m_spare] = m;
894 nr_m_spare++;
895 }
896#endif
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530897 mpt += sizeof(struct mpc_intsrc);
898 count += sizeof(struct mpc_intsrc);
Yinghai Lu2944e162008-06-01 13:17:38 -0700899 break;
900 }
901 case MP_LINTSRC:
902 {
Jaswinder Singh Rajput8fb29522009-01-03 15:51:54 +0530903 struct mpc_lintsrc *m =
904 (struct mpc_lintsrc *)mpt;
Yinghai Lu2944e162008-06-01 13:17:38 -0700905 mpt += sizeof(*m);
906 count += sizeof(*m);
907 break;
908 }
909 default:
910 /* wrong mptable */
911 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
912 printk(KERN_ERR "type %x\n", *mpt);
913 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530914 1, mpc, mpc->length, 1);
Yinghai Lu2944e162008-06-01 13:17:38 -0700915 goto out;
916 }
917 }
918
919#ifdef CONFIG_X86_IO_APIC
920 for (i = 0; i < mp_irq_entries; i++) {
921 if (irq_used[i])
922 continue;
923
924 if (mp_irqs[i].mp_irqtype != mp_INT)
925 continue;
926
927 if (mp_irqs[i].mp_irqflag != 0x0f)
928 continue;
929
930 if (nr_m_spare > 0) {
931 printk(KERN_INFO "*NEW* found ");
932 nr_m_spare--;
933 assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
934 m_spare[nr_m_spare] = NULL;
935 } else {
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530936 struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
937 count += sizeof(struct mpc_intsrc);
Yinghai Lu2944e162008-06-01 13:17:38 -0700938 if (!mpc_new_phys) {
939 printk(KERN_INFO "No spare slots, try to append...take your risk, new mpc_length %x\n", count);
940 } else {
941 if (count <= mpc_new_length)
942 printk(KERN_INFO "No spare slots, try to append..., new mpc_length %x\n", count);
943 else {
944 printk(KERN_ERR "mpc_new_length %lx is too small\n", mpc_new_length);
945 goto out;
946 }
947 }
948 assign_to_mpc_intsrc(&mp_irqs[i], m);
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530949 mpc->length = count;
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530950 mpt += sizeof(struct mpc_intsrc);
Yinghai Lu2944e162008-06-01 13:17:38 -0700951 }
952 print_mp_irq_info(&mp_irqs[i]);
953 }
954#endif
955out:
956 /* update checksum */
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530957 mpc->checksum = 0;
958 mpc->checksum -= mpf_checksum((unsigned char *)mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -0700959
960 return 0;
961}
962
Yinghai Lufcfa1462008-06-18 17:29:31 -0700963static int __initdata enable_update_mptable;
964
Yinghai Lu2944e162008-06-01 13:17:38 -0700965static int __init update_mptable_setup(char *str)
966{
967 enable_update_mptable = 1;
968 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;
980 alloc_mptable = 1;
981 if (!p)
982 return 0;
983 mpc_new_length = memparse(p, &p);
984 return 0;
985}
986early_param("alloc_mptable", parse_alloc_mptable_opt);
987
988void __init early_reserve_e820_mpc_new(void)
989{
990 if (enable_update_mptable && alloc_mptable) {
991 u64 startt = 0;
992#ifdef CONFIG_X86_TRAMPOLINE
993 startt = TRAMPOLINE_BASE;
994#endif
995 mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
996 }
997}
998
999static int __init update_mp_table(void)
1000{
1001 char str[16];
1002 char oem[10];
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +05301003 struct mpf_intel *mpf;
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +05301004 struct mpc_table *mpc, *mpc_new;
Yinghai Lu2944e162008-06-01 13:17:38 -07001005
1006 if (!enable_update_mptable)
1007 return 0;
1008
1009 mpf = mpf_found;
1010 if (!mpf)
1011 return 0;
1012
1013 /*
1014 * Now see if we need to go further.
1015 */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301016 if (mpf->feature1 != 0)
Yinghai Lu2944e162008-06-01 13:17:38 -07001017 return 0;
1018
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301019 if (!mpf->physptr)
Yinghai Lu2944e162008-06-01 13:17:38 -07001020 return 0;
1021
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301022 mpc = phys_to_virt(mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -07001023
1024 if (!smp_check_mpc(mpc, oem, str))
1025 return 0;
1026
1027 printk(KERN_INFO "mpf: %lx\n", virt_to_phys(mpf));
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301028 printk(KERN_INFO "physptr: %x\n", mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -07001029
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +05301030 if (mpc_new_phys && mpc->length > mpc_new_length) {
Yinghai Lu2944e162008-06-01 13:17:38 -07001031 mpc_new_phys = 0;
1032 printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
1033 mpc_new_length);
1034 }
1035
1036 if (!mpc_new_phys) {
1037 unsigned char old, new;
1038 /* check if we can change the postion */
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +05301039 mpc->checksum = 0;
1040 old = mpf_checksum((unsigned char *)mpc, mpc->length);
1041 mpc->checksum = 0xff;
1042 new = mpf_checksum((unsigned char *)mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -07001043 if (old == new) {
1044 printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
1045 return 0;
1046 }
1047 printk(KERN_INFO "use in-positon replacing\n");
1048 } else {
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301049 mpf->physptr = mpc_new_phys;
Yinghai Lu2944e162008-06-01 13:17:38 -07001050 mpc_new = phys_to_virt(mpc_new_phys);
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +05301051 memcpy(mpc_new, mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -07001052 mpc = mpc_new;
1053 /* check if we can modify that */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301054 if (mpc_new_phys - mpf->physptr) {
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +05301055 struct mpf_intel *mpf_new;
Yinghai Lu2944e162008-06-01 13:17:38 -07001056 /* steal 16 bytes from [0, 1k) */
1057 printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
1058 mpf_new = phys_to_virt(0x400 - 16);
1059 memcpy(mpf_new, mpf, 16);
1060 mpf = mpf_new;
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301061 mpf->physptr = mpc_new_phys;
Yinghai Lu2944e162008-06-01 13:17:38 -07001062 }
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301063 mpf->checksum = 0;
1064 mpf->checksum -= mpf_checksum((unsigned char *)mpf, 16);
1065 printk(KERN_INFO "physptr new: %x\n", mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -07001066 }
1067
1068 /*
1069 * only replace the one with mp_INT and
1070 * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
1071 * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
1072 * may need pci=routeirq for all coverage
1073 */
1074 replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
1075
1076 return 0;
1077}
1078
1079late_initcall(update_mp_table);