blob: 58ddf6259afb10a467ff47f45fc9a43f42d5c32f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04002 * Intel Multiprocessor Specification 1.1 and 1.4
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * compliant MP-table parsing routines.
4 *
Alan Cox87c6fe22009-01-05 14:08:04 +00005 * (c) 1995 Alan Cox, Building #3 <alan@lxorguk.ukuu.org.uk>
Ingo Molnar8f47e162009-01-31 02:03:42 +01006 * (c) 1998, 1999, 2000, 2009 Ingo Molnar <mingo@redhat.com>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +04007 * (c) 2008 Alexey Starikovskiy <astarikovskiy@suse.de>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
9
10#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/bootmem.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/kernel_stat.h>
15#include <linux/mc146818rtc.h>
16#include <linux/bitops.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040017#include <linux/acpi.h>
18#include <linux/module.h>
Jaswinder Singh Rajput103ceff2009-01-02 23:43:25 +053019#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/mtrr.h>
22#include <asm/mpspec.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040023#include <asm/pgalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/io_apic.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040025#include <asm/proto.h>
Alexey Starikovskiyce3fe6b2008-03-17 22:08:17 +030026#include <asm/bios_ebda.h>
Yinghai Lu2944e162008-06-01 13:17:38 -070027#include <asm/e820.h>
28#include <asm/trampoline.h>
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -070029#include <asm/setup.h>
Jaswinder Singh Rajput4884d8e2009-01-11 18:38:55 +053030#include <asm/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Ingo Molnar7b6aa332009-02-17 13:58:15 +010032#include <asm/apic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 * Checksum an MP configuration block.
35 */
36
37static int __init mpf_checksum(unsigned char *mp, int len)
38{
39 int sum = 0;
40
41 while (len--)
42 sum += *mp++;
43
44 return sum & 0xFF;
45}
46
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +053047static void __init MP_processor_info(struct mpc_cpu *m)
Alexey Starikovskiyc853c672008-03-27 23:54:13 +030048{
49 int apicid;
Alexey Starikovskiy746f2242008-04-04 23:42:15 +040050 char *bootup_cpu = "";
Alexey Starikovskiyc853c672008-03-27 23:54:13 +030051
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053052 if (!(m->cpuflag & CPU_ENABLED)) {
Glauber Costa7b1292e2008-03-03 14:12:41 -030053 disabled_cpus++;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 return;
Glauber Costa7b1292e2008-03-03 14:12:41 -030055 }
Yinghai Lu64898a82008-07-19 18:01:16 -070056
57 if (x86_quirks->mpc_apic_id)
58 apicid = x86_quirks->mpc_apic_id(m);
Yinghai Luab530e12008-06-03 10:25:54 -070059 else
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053060 apicid = m->apicid;
Yinghai Lu64898a82008-07-19 18:01:16 -070061
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053062 if (m->cpuflag & CPU_BOOTPROCESSOR) {
Alexey Starikovskiy746f2242008-04-04 23:42:15 +040063 bootup_cpu = " (Bootup-CPU)";
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053064 boot_cpu_physical_apicid = m->apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 }
66
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053067 printk(KERN_INFO "Processor #%d%s\n", m->apicid, bootup_cpu);
68 generic_processor_info(apicid, m->apicver);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069}
70
Thomas Gleixner85cc35f2008-05-25 21:21:36 +020071#ifdef CONFIG_X86_IO_APIC
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +053072static void __init MP_bus_info(struct mpc_bus *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073{
74 char str[7];
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053075 memcpy(str, m->bustype, 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 str[6] = 0;
77
Yinghai Lu64898a82008-07-19 18:01:16 -070078 if (x86_quirks->mpc_oem_bus_info)
79 x86_quirks->mpc_oem_bus_info(m, str);
80 else
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053081 apic_printk(APIC_VERBOSE, "Bus #%d is %s\n", m->busid, str);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Andi Kleen5e4edbb2006-09-26 10:52:35 +020083#if MAX_MP_BUSSES < 256
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053084 if (m->busid >= MAX_MP_BUSSES) {
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070085 printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +040086 " is too large, max. supported is %d\n",
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053087 m->busid, str, MAX_MP_BUSSES - 1);
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070088 return;
89 }
Andi Kleen5e4edbb2006-09-26 10:52:35 +020090#endif
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070091
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +040092 if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053093 set_bit(m->busid, mp_bus_not_pci);
Jaswinder Singh Rajput103ceff2009-01-02 23:43:25 +053094#if defined(CONFIG_EISA) || defined(CONFIG_MCA)
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053095 mp_bus_id_to_type[m->busid] = MP_BUS_ISA;
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +040096#endif
97 } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
Yinghai Lu64898a82008-07-19 18:01:16 -070098 if (x86_quirks->mpc_oem_pci_bus)
99 x86_quirks->mpc_oem_pci_bus(m);
100
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530101 clear_bit(m->busid, mp_bus_not_pci);
Jaswinder Singh Rajput103ceff2009-01-02 23:43:25 +0530102#if defined(CONFIG_EISA) || defined(CONFIG_MCA)
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530103 mp_bus_id_to_type[m->busid] = MP_BUS_PCI;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400104 } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530105 mp_bus_id_to_type[m->busid] = MP_BUS_EISA;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400106 } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530107 mp_bus_id_to_type[m->busid] = MP_BUS_MCA;
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +0300108#endif
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +0400109 } else
110 printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111}
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400112
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300113static int bad_ioapic(unsigned long address)
114{
115 if (nr_ioapics >= MAX_IO_APICS) {
116 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
117 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
118 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
119 }
120 if (!address) {
121 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
122 " found in table, skipping!\n");
123 return 1;
124 }
125 return 0;
126}
127
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530128static void __init MP_ioapic_info(struct mpc_ioapic *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530130 if (!(m->flags & MPC_APIC_USABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 return;
132
Thomas Gleixner64883ab2008-01-30 13:30:35 +0100133 printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530134 m->apicid, m->apicver, m->apicaddr);
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300135
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530136 if (bad_ioapic(m->apicaddr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 return;
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300138
Jaswinder Singh Rajputb5ba7e62009-01-12 17:46:17 +0530139 mp_ioapics[nr_ioapics].apicaddr = m->apicaddr;
140 mp_ioapics[nr_ioapics].apicid = m->apicid;
141 mp_ioapics[nr_ioapics].type = m->type;
142 mp_ioapics[nr_ioapics].apicver = m->apicver;
143 mp_ioapics[nr_ioapics].flags = m->flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 nr_ioapics++;
145}
146
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530147static void print_MP_intsrc_info(struct mpc_intsrc *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200149 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530151 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbus,
152 m->srcbusirq, m->dstapic, m->dstirq);
Yinghai Lu2944e162008-06-01 13:17:38 -0700153}
154
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530155static void __init print_mp_irq_info(struct mpc_intsrc *mp_irq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700156{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200157 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
Yinghai Lu2944e162008-06-01 13:17:38 -0700158 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530159 mp_irq->irqtype, mp_irq->irqflag & 3,
160 (mp_irq->irqflag >> 2) & 3, mp_irq->srcbus,
161 mp_irq->srcbusirq, mp_irq->dstapic, mp_irq->dstirq);
Yinghai Lu2944e162008-06-01 13:17:38 -0700162}
163
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530164static void __init assign_to_mp_irq(struct mpc_intsrc *m,
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530165 struct mpc_intsrc *mp_irq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700166{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530167 mp_irq->dstapic = m->dstapic;
168 mp_irq->type = m->type;
169 mp_irq->irqtype = m->irqtype;
170 mp_irq->irqflag = m->irqflag;
171 mp_irq->srcbus = m->srcbus;
172 mp_irq->srcbusirq = m->srcbusirq;
173 mp_irq->dstirq = m->dstirq;
Yinghai Lu2944e162008-06-01 13:17:38 -0700174}
175
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530176static void __init assign_to_mpc_intsrc(struct mpc_intsrc *mp_irq,
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530177 struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700178{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530179 m->dstapic = mp_irq->dstapic;
180 m->type = mp_irq->type;
181 m->irqtype = mp_irq->irqtype;
182 m->irqflag = mp_irq->irqflag;
183 m->srcbus = mp_irq->srcbus;
184 m->srcbusirq = mp_irq->srcbusirq;
185 m->dstirq = mp_irq->dstirq;
Yinghai Lu2944e162008-06-01 13:17:38 -0700186}
187
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530188static int __init mp_irq_mpc_intsrc_cmp(struct mpc_intsrc *mp_irq,
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530189 struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700190{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530191 if (mp_irq->dstapic != m->dstapic)
Yinghai Lu2944e162008-06-01 13:17:38 -0700192 return 1;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530193 if (mp_irq->type != m->type)
Yinghai Lu2944e162008-06-01 13:17:38 -0700194 return 2;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530195 if (mp_irq->irqtype != m->irqtype)
Yinghai Lu2944e162008-06-01 13:17:38 -0700196 return 3;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530197 if (mp_irq->irqflag != m->irqflag)
Yinghai Lu2944e162008-06-01 13:17:38 -0700198 return 4;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530199 if (mp_irq->srcbus != m->srcbus)
Yinghai Lu2944e162008-06-01 13:17:38 -0700200 return 5;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530201 if (mp_irq->srcbusirq != m->srcbusirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700202 return 6;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530203 if (mp_irq->dstirq != m->dstirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700204 return 7;
205
206 return 0;
207}
208
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530209static void __init MP_intsrc_info(struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700210{
211 int i;
212
213 print_MP_intsrc_info(m);
214
Yinghai Lufcfa1462008-06-18 17:29:31 -0700215 for (i = 0; i < mp_irq_entries; i++) {
216 if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m))
217 return;
218 }
Yinghai Lu2944e162008-06-01 13:17:38 -0700219
220 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 if (++mp_irq_entries == MAX_IRQ_SOURCES)
222 panic("Max # of irq sources exceeded!!\n");
223}
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530224#else /* CONFIG_X86_IO_APIC */
225static inline void __init MP_bus_info(struct mpc_bus *m) {}
226static inline void __init MP_ioapic_info(struct mpc_ioapic *m) {}
227static inline void __init MP_intsrc_info(struct mpc_intsrc *m) {}
228#endif /* CONFIG_X86_IO_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400230
Jaswinder Singh Rajput8fb29522009-01-03 15:51:54 +0530231static void __init MP_lintsrc_info(struct mpc_lintsrc *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200233 apic_printk(APIC_VERBOSE, "Lint: type %d, pol %d, trig %d, bus %02x,"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
Jaswinder Singh Rajputb5ced7c2009-01-04 21:55:53 +0530235 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbusid,
236 m->srcbusirq, m->destapic, m->destapiclint);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237}
238
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239/*
240 * Read/parse the MPC
241 */
242
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530243static int __init smp_check_mpc(struct mpc_table *mpc, char *oem, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530246 if (memcmp(mpc->signature, MPC_SIGNATURE, 4)) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400247 printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530248 mpc->signature[0], mpc->signature[1],
249 mpc->signature[2], mpc->signature[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 return 0;
251 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530252 if (mpf_checksum((unsigned char *)mpc, mpc->length)) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400253 printk(KERN_ERR "MPTABLE: checksum error!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 return 0;
255 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530256 if (mpc->spec != 0x01 && mpc->spec != 0x04) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400257 printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530258 mpc->spec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 return 0;
260 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530261 if (!mpc->lapic) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400262 printk(KERN_ERR "MPTABLE: null local APIC address!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 return 0;
264 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530265 memcpy(oem, mpc->oem, 8);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400266 oem[8] = 0;
Yinghai Lu11a62a02008-05-12 15:43:38 +0200267 printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530269 memcpy(str, mpc->productid, 12);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400270 str[12] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Yinghai Lu11a62a02008-05-12 15:43:38 +0200272 printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530274 printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->lapic);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
Yinghai Lu2944e162008-06-01 13:17:38 -0700276 return 1;
277}
278
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530279static void skip_entry(unsigned char **ptr, int *count, int size)
280{
281 *ptr += size;
282 *count += size;
283}
284
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530285static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early)
Yinghai Lu2944e162008-06-01 13:17:38 -0700286{
287 char str[16];
288 char oem[10];
289
290 int count = sizeof(*mpc);
291 unsigned char *mpt = ((unsigned char *)mpc) + count;
292
293 if (!smp_check_mpc(mpc, oem, str))
294 return 0;
295
296#ifdef CONFIG_X86_32
Ingo Molnar9c764242009-01-28 13:44:32 +0100297 generic_mps_oem_check(mpc, oem, str);
Yinghai Lu2944e162008-06-01 13:17:38 -0700298#endif
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400299 /* save the local APIC address, it might be non-default */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 if (!acpi_lapic)
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530301 mp_lapic_addr = mpc->lapic;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400303 if (early)
304 return 1;
305
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530306 if (mpc->oemptr && x86_quirks->smp_read_mpc_oem) {
307 struct mpc_oemtable *oem_table = (void *)(long)mpc->oemptr;
308 x86_quirks->smp_read_mpc_oem(oem_table, mpc->oemsize);
Yinghai Lu64898a82008-07-19 18:01:16 -0700309 }
310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 /*
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400312 * Now process the configuration blocks.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 */
Yinghai Lu64898a82008-07-19 18:01:16 -0700314 if (x86_quirks->mpc_record)
315 *x86_quirks->mpc_record = 0;
316
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530317 while (count < mpc->length) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400318 switch (*mpt) {
319 case MP_PROCESSOR:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530320 /* ACPI may have already provided this data */
321 if (!acpi_lapic)
322 MP_processor_info((struct mpc_cpu *)&mpt);
323 skip_entry(&mpt, &count, sizeof(struct mpc_cpu));
324 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400325 case MP_BUS:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530326 MP_bus_info((struct mpc_bus *)&mpt);
327 skip_entry(&mpt, &count, sizeof(struct mpc_bus));
328 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400329 case MP_IOAPIC:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530330 MP_ioapic_info((struct mpc_ioapic *)&mpt);
331 skip_entry(&mpt, &count, sizeof(struct mpc_ioapic));
332 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400333 case MP_INTSRC:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530334 MP_intsrc_info((struct mpc_intsrc *)&mpt);
335 skip_entry(&mpt, &count, sizeof(struct mpc_intsrc));
336 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400337 case MP_LINTSRC:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530338 MP_lintsrc_info((struct mpc_lintsrc *)&mpt);
339 skip_entry(&mpt, &count, sizeof(struct mpc_lintsrc));
340 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400341 default:
Yinghai Lu711554d2008-04-07 11:36:39 -0700342 /* wrong mptable */
343 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
344 printk(KERN_ERR "type %x\n", *mpt);
345 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530346 1, mpc, mpc->length, 1);
347 count = mpc->length;
Yinghai Lu711554d2008-04-07 11:36:39 -0700348 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 }
Yinghai Lu64898a82008-07-19 18:01:16 -0700350 if (x86_quirks->mpc_record)
351 (*x86_quirks->mpc_record)++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 }
Yinghai Lue0da3362008-06-08 18:29:22 -0700353
Yinghai Lu26f7ef12009-01-29 14:19:22 -0800354#ifdef CONFIG_X86_BIGSMP
355 generic_bigsmp_probe();
Yinghai Lue0da3362008-06-08 18:29:22 -0700356#endif
357
Ingo Molnar72ce0162009-01-28 06:50:47 +0100358 if (apic->setup_apic_routing)
359 apic->setup_apic_routing();
360
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 if (!num_processors)
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400362 printk(KERN_ERR "MPTABLE: no processors registered!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 return num_processors;
364}
365
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400366#ifdef CONFIG_X86_IO_APIC
367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368static int __init ELCR_trigger(unsigned int irq)
369{
370 unsigned int port;
371
372 port = 0x4d0 + (irq >> 3);
373 return (inb(port) >> (irq & 7)) & 1;
374}
375
376static void __init construct_default_ioirq_mptable(int mpc_default_type)
377{
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530378 struct mpc_intsrc intsrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 int i;
380 int ELCR_fallback = 0;
381
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530382 intsrc.type = MP_INTSRC;
383 intsrc.irqflag = 0; /* conforming */
384 intsrc.srcbus = 0;
Jaswinder Singh Rajputb5ba7e62009-01-12 17:46:17 +0530385 intsrc.dstapic = mp_ioapics[0].apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530387 intsrc.irqtype = mp_INT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
389 /*
390 * If true, we have an ISA/PCI system with no IRQ entries
391 * in the MP table. To prevent the PCI interrupts from being set up
392 * incorrectly, we try to use the ELCR. The sanity check to see if
393 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
394 * never be level sensitive, so we simply see if the ELCR agrees.
395 * If it does, we assume it's valid.
396 */
397 if (mpc_default_type == 5) {
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400398 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
399 "falling back to ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400401 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
402 ELCR_trigger(13))
403 printk(KERN_ERR "ELCR contains invalid data... "
404 "not using ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 else {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400406 printk(KERN_INFO
407 "Using ELCR to identify PCI interrupts\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 ELCR_fallback = 1;
409 }
410 }
411
412 for (i = 0; i < 16; i++) {
413 switch (mpc_default_type) {
414 case 2:
415 if (i == 0 || i == 13)
416 continue; /* IRQ0 & IRQ13 not connected */
417 /* fall through */
418 default:
419 if (i == 2)
420 continue; /* IRQ2 is never connected */
421 }
422
423 if (ELCR_fallback) {
424 /*
425 * If the ELCR indicates a level-sensitive interrupt, we
426 * copy that information over to the MP table in the
427 * irqflag field (level sensitive, active high polarity).
428 */
429 if (ELCR_trigger(i))
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530430 intsrc.irqflag = 13;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 else
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530432 intsrc.irqflag = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 }
434
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530435 intsrc.srcbusirq = i;
436 intsrc.dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 MP_intsrc_info(&intsrc);
438 }
439
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530440 intsrc.irqtype = mp_ExtINT;
441 intsrc.srcbusirq = 0;
442 intsrc.dstirq = 0; /* 8259A to INTIN0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 MP_intsrc_info(&intsrc);
444}
445
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400446
Marcin Slusarz39e00fe2008-08-11 00:09:38 +0200447static void __init construct_ioapic_table(int mpc_default_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448{
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530449 struct mpc_ioapic ioapic;
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +0530450 struct mpc_bus bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530452 bus.type = MP_BUS;
453 bus.busid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 switch (mpc_default_type) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400455 default:
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400456 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400457 mpc_default_type);
458 /* fall through */
459 case 1:
460 case 5:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530461 memcpy(bus.bustype, "ISA ", 6);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400462 break;
463 case 2:
464 case 6:
465 case 3:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530466 memcpy(bus.bustype, "EISA ", 6);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400467 break;
468 case 4:
469 case 7:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530470 memcpy(bus.bustype, "MCA ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 }
472 MP_bus_info(&bus);
473 if (mpc_default_type > 4) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530474 bus.busid = 1;
475 memcpy(bus.bustype, "PCI ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 MP_bus_info(&bus);
477 }
478
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530479 ioapic.type = MP_IOAPIC;
480 ioapic.apicid = 2;
481 ioapic.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
482 ioapic.flags = MPC_APIC_USABLE;
483 ioapic.apicaddr = 0xFEC00000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 MP_ioapic_info(&ioapic);
485
486 /*
487 * We set up most of the low 16 IO-APIC pins according to MPS rules.
488 */
489 construct_default_ioirq_mptable(mpc_default_type);
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200490}
491#else
Marcin Slusarz39e00fe2008-08-11 00:09:38 +0200492static inline void __init construct_ioapic_table(int mpc_default_type) { }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400493#endif
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200494
495static inline void __init construct_default_ISA_mptable(int mpc_default_type)
496{
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +0530497 struct mpc_cpu processor;
Jaswinder Singh Rajput8fb29522009-01-03 15:51:54 +0530498 struct mpc_lintsrc lintsrc;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200499 int linttypes[2] = { mp_ExtINT, mp_NMI };
500 int i;
501
502 /*
503 * local APIC has default address
504 */
505 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
506
507 /*
508 * 2 CPUs, numbered 0 & 1.
509 */
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530510 processor.type = MP_PROCESSOR;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200511 /* Either an integrated APIC or a discrete 82489DX. */
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530512 processor.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
513 processor.cpuflag = CPU_ENABLED;
514 processor.cpufeature = (boot_cpu_data.x86 << 8) |
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200515 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530516 processor.featureflag = boot_cpu_data.x86_capability[0];
517 processor.reserved[0] = 0;
518 processor.reserved[1] = 0;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200519 for (i = 0; i < 2; i++) {
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530520 processor.apicid = i;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200521 MP_processor_info(&processor);
522 }
523
524 construct_ioapic_table(mpc_default_type);
525
Jaswinder Singh Rajputb5ced7c2009-01-04 21:55:53 +0530526 lintsrc.type = MP_LINTSRC;
527 lintsrc.irqflag = 0; /* conforming */
528 lintsrc.srcbusid = 0;
529 lintsrc.srcbusirq = 0;
530 lintsrc.destapic = MP_APIC_ALL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 for (i = 0; i < 2; i++) {
Jaswinder Singh Rajputb5ced7c2009-01-04 21:55:53 +0530532 lintsrc.irqtype = linttypes[i];
533 lintsrc.destapiclint = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 MP_lintsrc_info(&lintsrc);
535 }
536}
537
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530538static struct mpf_intel *mpf_found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
Yinghai Lu8d4dd9192009-03-04 01:25:21 -0800540static unsigned long __init get_mpc_size(unsigned long physptr)
541{
542 struct mpc_table *mpc;
543 unsigned long size;
544
545 mpc = early_ioremap(physptr, PAGE_SIZE);
546 size = mpc->length;
547 early_iounmap(mpc, PAGE_SIZE);
548 apic_printk(APIC_VERBOSE, " mpc: %lx-%lx\n", physptr, physptr + size);
549
550 return size;
551}
552
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553/*
554 * Scan the memory blocks for an SMP configuration block.
555 */
Ingo Molnar3b335532008-07-10 17:30:40 +0200556static void __init __get_smp_config(unsigned int early)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557{
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530558 struct mpf_intel *mpf = mpf_found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
Yinghai Lu69b88af2008-12-05 22:45:50 -0800560 if (!mpf)
561 return;
562
563 if (acpi_lapic && early)
564 return;
565
566 /*
567 * MPS doesn't support hyperthreading, aka only have
568 * thread 0 apic id in MPS table
569 */
570 if (acpi_lapic && acpi_ioapic)
571 return;
572
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700573 if (x86_quirks->mach_get_smp_config) {
574 if (x86_quirks->mach_get_smp_config(early))
Ingo Molnar3b335532008-07-10 17:30:40 +0200575 return;
576 }
Andi Kleen9adc1382008-12-04 13:33:35 +0100577
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400578 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530579 mpf->specification);
Alexey Starikovskiyb3e24162008-05-23 01:54:44 +0400580#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530581 if (mpf->feature2 & (1 << 7)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
583 pic_mode = 1;
584 } else {
585 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
586 pic_mode = 0;
587 }
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400588#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 /*
590 * Now see if we need to read further.
591 */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530592 if (mpf->feature1 != 0) {
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400593 if (early) {
594 /*
595 * local APIC has default address
596 */
597 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
598 return;
599 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400601 printk(KERN_INFO "Default MP configuration #%d\n",
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530602 mpf->feature1);
603 construct_default_ISA_mptable(mpf->feature1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530605 } else if (mpf->physptr) {
Yinghai Lu8d4dd9192009-03-04 01:25:21 -0800606 struct mpc_table *mpc;
607 unsigned long size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
Yinghai Lu8d4dd9192009-03-04 01:25:21 -0800609 size = get_mpc_size(mpf->physptr);
610 mpc = early_ioremap(mpf->physptr, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 /*
612 * Read the physical hardware table. Anything here will
613 * override the defaults.
614 */
Yinghai Lu8d4dd9192009-03-04 01:25:21 -0800615 if (!smp_read_mpc(mpc, early)) {
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400616#ifdef CONFIG_X86_LOCAL_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 smp_found_config = 0;
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400618#endif
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400619 printk(KERN_ERR
620 "BIOS bug, MP table errors detected!...\n");
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400621 printk(KERN_ERR "... disabling SMP support. "
622 "(tell your hw vendor)\n");
Yinghai Lu8d4dd9192009-03-04 01:25:21 -0800623 early_iounmap(mpc, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 return;
625 }
Yinghai Lu8d4dd9192009-03-04 01:25:21 -0800626 early_iounmap(mpc, size);
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400627
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400628 if (early)
629 return;
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400630#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 /*
632 * If there are no explicit MP IRQ entries, then we are
633 * broken. We set up most of the low 16 IO-APIC pins to
634 * ISA defaults and hope it will work.
635 */
636 if (!mp_irq_entries) {
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +0530637 struct mpc_bus bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400639 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
640 "using default mptable. "
641 "(tell your hw vendor)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530643 bus.type = MP_BUS;
644 bus.busid = 0;
645 memcpy(bus.bustype, "ISA ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 MP_bus_info(&bus);
647
648 construct_default_ioirq_mptable(0);
649 }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400650#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 } else
652 BUG();
653
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400654 if (!early)
655 printk(KERN_INFO "Processors: %d\n", num_processors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 /*
657 * Only use the first configuration found.
658 */
659}
660
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400661void __init early_get_smp_config(void)
662{
663 __get_smp_config(1);
664}
665
666void __init get_smp_config(void)
667{
668 __get_smp_config(0);
669}
670
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530671static void smp_reserve_bootmem(struct mpf_intel *mpf)
672{
673 unsigned long size = get_mpc_size(mpf->physptr);
674#ifdef CONFIG_X86_32
675 /*
676 * We cannot access to MPC table to compute table size yet,
677 * as only few megabytes from the bottom is mapped now.
678 * PC-9800's MPC table places on the very last of physical
679 * memory; so that simply reserving PAGE_SIZE from mpf->physptr
680 * yields BUG() in reserve_bootmem.
681 * also need to make sure physptr is below than max_low_pfn
682 * we don't need reserve the area above max_low_pfn
683 */
684 unsigned long end = max_low_pfn * PAGE_SIZE;
685
686 if (mpf->physptr < end) {
687 if (mpf->physptr + size > end)
688 size = end - mpf->physptr;
689 reserve_bootmem_generic(mpf->physptr, size, BOOTMEM_DEFAULT);
690 }
691#else
692 reserve_bootmem_generic(mpf->physptr, size, BOOTMEM_DEFAULT);
693#endif
694}
695
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400696static int __init smp_scan_config(unsigned long base, unsigned long length,
697 unsigned reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698{
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400699 unsigned int *bp = phys_to_virt(base);
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530700 struct mpf_intel *mpf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200702 apic_printk(APIC_VERBOSE, "Scan SMP from %p for %ld bytes.\n",
703 bp, length);
Akinobu Mita5d47a272008-04-19 23:55:11 +0900704 BUILD_BUG_ON(sizeof(*mpf) != 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
706 while (length > 0) {
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530707 mpf = (struct mpf_intel *)bp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 if ((*bp == SMP_MAGIC_IDENT) &&
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530709 (mpf->length == 1) &&
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400710 !mpf_checksum((unsigned char *)bp, 16) &&
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530711 ((mpf->specification == 1)
712 || (mpf->specification == 4))) {
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400713#ifdef CONFIG_X86_LOCAL_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 smp_found_config = 1;
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400715#endif
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400716 mpf_found = mpf;
Yinghai Lub1f006b2008-06-09 18:11:36 -0700717
Jaswinder Singh Rajputba1511b2009-02-11 23:38:25 +0530718 printk(KERN_INFO "found SMP MP-table at [%p] %llx\n",
719 mpf, (u64)virt_to_phys(mpf));
Yinghai Lub1f006b2008-06-09 18:11:36 -0700720
721 if (!reserve)
722 return 1;
Yinghai Luf6243232009-03-04 01:25:54 -0800723 reserve_bootmem_generic(virt_to_phys(mpf), sizeof(*mpf),
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800724 BOOTMEM_DEFAULT);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530725 if (mpf->physptr)
726 smp_reserve_bootmem(mpf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
Yinghai Lud2dbf342008-06-13 02:00:56 -0700728 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 }
730 bp += 4;
731 length -= 16;
732 }
733 return 0;
734}
735
Ingo Molnar3b335532008-07-10 17:30:40 +0200736static void __init __find_smp_config(unsigned int reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737{
738 unsigned int address;
739
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700740 if (x86_quirks->mach_find_smp_config) {
741 if (x86_quirks->mach_find_smp_config(reserve))
Ingo Molnar3b335532008-07-10 17:30:40 +0200742 return;
743 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 /*
745 * FIXME: Linux assumes you have 640K of base ram..
746 * this continues the error...
747 *
748 * 1) Scan the bottom 1K for a signature
749 * 2) Scan the top 1K of base RAM
750 * 3) Scan the 64K of bios
751 */
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400752 if (smp_scan_config(0x0, 0x400, reserve) ||
753 smp_scan_config(639 * 0x400, 0x400, reserve) ||
754 smp_scan_config(0xF0000, 0x10000, reserve))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 return;
756 /*
757 * If it is an SMP machine we should know now, unless the
758 * configuration is in an EISA/MCA bus machine with an
759 * extended bios data area.
760 *
761 * there is a real-mode segmented pointer pointing to the
762 * 4K EBDA area at 0x40E, calculate and scan it here.
763 *
764 * NOTE! There are Linux loaders that will corrupt the EBDA
765 * area, and as such this kind of SMP config may be less
766 * trustworthy, simply because the SMP table may have been
767 * stomped on during early boot. These loaders are buggy and
768 * should be fixed.
769 *
770 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
771 */
772
773 address = get_bios_ebda();
774 if (address)
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400775 smp_scan_config(address, 0x400, reserve);
776}
777
778void __init early_find_smp_config(void)
779{
780 __find_smp_config(0);
781}
782
783void __init find_smp_config(void)
784{
785 __find_smp_config(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786}
Yinghai Lu2944e162008-06-01 13:17:38 -0700787
788#ifdef CONFIG_X86_IO_APIC
789static u8 __initdata irq_used[MAX_IRQ_SOURCES];
790
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530791static int __init get_MP_intsrc_index(struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700792{
793 int i;
794
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530795 if (m->irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700796 return 0;
797
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530798 if (m->irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700799 return 0;
800
801 /* not legacy */
802
803 for (i = 0; i < mp_irq_entries; i++) {
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530804 if (mp_irqs[i].irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700805 continue;
806
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530807 if (mp_irqs[i].irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700808 continue;
809
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530810 if (mp_irqs[i].srcbus != m->srcbus)
Yinghai Lu2944e162008-06-01 13:17:38 -0700811 continue;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530812 if (mp_irqs[i].srcbusirq != m->srcbusirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700813 continue;
814 if (irq_used[i]) {
815 /* already claimed */
816 return -2;
817 }
818 irq_used[i] = 1;
819 return i;
820 }
821
822 /* not found */
823 return -1;
824}
825
826#define SPARE_SLOT_NUM 20
827
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530828static struct mpc_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530829
830static void check_irq_src(struct mpc_intsrc *m, int *nr_m_spare)
831{
832 int i;
833
834 apic_printk(APIC_VERBOSE, "OLD ");
835 print_MP_intsrc_info(m);
836
837 i = get_MP_intsrc_index(m);
838 if (i > 0) {
839 assign_to_mpc_intsrc(&mp_irqs[i], m);
840 apic_printk(APIC_VERBOSE, "NEW ");
841 print_mp_irq_info(&mp_irqs[i]);
842 return;
843 }
844 if (!i) {
845 /* legacy, do nothing */
846 return;
847 }
848 if (*nr_m_spare < SPARE_SLOT_NUM) {
849 /*
850 * not found (-1), or duplicated (-2) are invalid entries,
851 * we need to use the slot later
852 */
853 m_spare[*nr_m_spare] = m;
854 *nr_m_spare += 1;
855 }
856}
857#else /* CONFIG_X86_IO_APIC */
858static inline void check_irq_src(struct mpc_intsrc *m, int *nr_m_spare) {}
859#endif /* CONFIG_X86_IO_APIC */
860
861static int check_slot(unsigned long mpc_new_phys, unsigned long mpc_new_length,
862 int count)
863{
864 if (!mpc_new_phys) {
865 pr_info("No spare slots, try to append...take your risk, "
866 "new mpc_length %x\n", count);
867 } else {
868 if (count <= mpc_new_length)
869 pr_info("No spare slots, try to append..., "
870 "new mpc_length %x\n", count);
871 else {
872 pr_err("mpc_new_length %lx is too small\n",
873 mpc_new_length);
874 return -1;
875 }
876 }
877
878 return 0;
879}
Yinghai Lu2944e162008-06-01 13:17:38 -0700880
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530881static int __init replace_intsrc_all(struct mpc_table *mpc,
Yinghai Lu2944e162008-06-01 13:17:38 -0700882 unsigned long mpc_new_phys,
883 unsigned long mpc_new_length)
884{
885#ifdef CONFIG_X86_IO_APIC
886 int i;
Yinghai Lu2944e162008-06-01 13:17:38 -0700887#endif
Yinghai Lu2944e162008-06-01 13:17:38 -0700888 int count = sizeof(*mpc);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530889 int nr_m_spare = 0;
Yinghai Lu2944e162008-06-01 13:17:38 -0700890 unsigned char *mpt = ((unsigned char *)mpc) + count;
891
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530892 printk(KERN_INFO "mpc_length %x\n", mpc->length);
893 while (count < mpc->length) {
Yinghai Lu2944e162008-06-01 13:17:38 -0700894 switch (*mpt) {
895 case MP_PROCESSOR:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530896 skip_entry(&mpt, &count, sizeof(struct mpc_cpu));
897 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700898 case MP_BUS:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530899 skip_entry(&mpt, &count, sizeof(struct mpc_bus));
900 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700901 case MP_IOAPIC:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530902 skip_entry(&mpt, &count, sizeof(struct mpc_ioapic));
903 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700904 case MP_INTSRC:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530905 check_irq_src((struct mpc_intsrc *)&mpt, &nr_m_spare);
906 skip_entry(&mpt, &count, sizeof(struct mpc_intsrc));
907 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700908 case MP_LINTSRC:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530909 skip_entry(&mpt, &count, sizeof(struct mpc_lintsrc));
910 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700911 default:
912 /* wrong mptable */
913 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
914 printk(KERN_ERR "type %x\n", *mpt);
915 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530916 1, mpc, mpc->length, 1);
Yinghai Lu2944e162008-06-01 13:17:38 -0700917 goto out;
918 }
919 }
920
921#ifdef CONFIG_X86_IO_APIC
922 for (i = 0; i < mp_irq_entries; i++) {
923 if (irq_used[i])
924 continue;
925
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530926 if (mp_irqs[i].irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700927 continue;
928
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530929 if (mp_irqs[i].irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700930 continue;
931
932 if (nr_m_spare > 0) {
Jan Beulich82034d62009-03-12 12:57:10 +0000933 apic_printk(APIC_VERBOSE, "*NEW* found\n");
Yinghai Lu2944e162008-06-01 13:17:38 -0700934 nr_m_spare--;
935 assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
936 m_spare[nr_m_spare] = NULL;
937 } else {
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530938 struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
939 count += sizeof(struct mpc_intsrc);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530940 if (!check_slot(mpc_new_phys, mpc_new_length, count))
941 goto out;
Yinghai Lu2944e162008-06-01 13:17:38 -0700942 assign_to_mpc_intsrc(&mp_irqs[i], m);
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530943 mpc->length = count;
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530944 mpt += sizeof(struct mpc_intsrc);
Yinghai Lu2944e162008-06-01 13:17:38 -0700945 }
946 print_mp_irq_info(&mp_irqs[i]);
947 }
948#endif
949out:
950 /* update checksum */
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530951 mpc->checksum = 0;
952 mpc->checksum -= mpf_checksum((unsigned char *)mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -0700953
954 return 0;
955}
956
Yinghai Lufcfa1462008-06-18 17:29:31 -0700957static int __initdata enable_update_mptable;
958
Yinghai Lu2944e162008-06-01 13:17:38 -0700959static int __init update_mptable_setup(char *str)
960{
961 enable_update_mptable = 1;
962 return 0;
963}
964early_param("update_mptable", update_mptable_setup);
965
966static unsigned long __initdata mpc_new_phys;
967static unsigned long mpc_new_length __initdata = 4096;
968
969/* alloc_mptable or alloc_mptable=4k */
970static int __initdata alloc_mptable;
971static int __init parse_alloc_mptable_opt(char *p)
972{
973 enable_update_mptable = 1;
974 alloc_mptable = 1;
975 if (!p)
976 return 0;
977 mpc_new_length = memparse(p, &p);
978 return 0;
979}
980early_param("alloc_mptable", parse_alloc_mptable_opt);
981
982void __init early_reserve_e820_mpc_new(void)
983{
984 if (enable_update_mptable && alloc_mptable) {
985 u64 startt = 0;
986#ifdef CONFIG_X86_TRAMPOLINE
987 startt = TRAMPOLINE_BASE;
988#endif
989 mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
990 }
991}
992
993static int __init update_mp_table(void)
994{
995 char str[16];
996 char oem[10];
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530997 struct mpf_intel *mpf;
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530998 struct mpc_table *mpc, *mpc_new;
Yinghai Lu2944e162008-06-01 13:17:38 -0700999
1000 if (!enable_update_mptable)
1001 return 0;
1002
1003 mpf = mpf_found;
1004 if (!mpf)
1005 return 0;
1006
1007 /*
1008 * Now see if we need to go further.
1009 */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301010 if (mpf->feature1 != 0)
Yinghai Lu2944e162008-06-01 13:17:38 -07001011 return 0;
1012
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301013 if (!mpf->physptr)
Yinghai Lu2944e162008-06-01 13:17:38 -07001014 return 0;
1015
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301016 mpc = phys_to_virt(mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -07001017
1018 if (!smp_check_mpc(mpc, oem, str))
1019 return 0;
1020
Jaswinder Singh Rajputba1511b2009-02-11 23:38:25 +05301021 printk(KERN_INFO "mpf: %llx\n", (u64)virt_to_phys(mpf));
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301022 printk(KERN_INFO "physptr: %x\n", mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -07001023
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +05301024 if (mpc_new_phys && mpc->length > mpc_new_length) {
Yinghai Lu2944e162008-06-01 13:17:38 -07001025 mpc_new_phys = 0;
1026 printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
1027 mpc_new_length);
1028 }
1029
1030 if (!mpc_new_phys) {
1031 unsigned char old, new;
1032 /* check if we can change the postion */
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +05301033 mpc->checksum = 0;
1034 old = mpf_checksum((unsigned char *)mpc, mpc->length);
1035 mpc->checksum = 0xff;
1036 new = mpf_checksum((unsigned char *)mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -07001037 if (old == new) {
1038 printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
1039 return 0;
1040 }
1041 printk(KERN_INFO "use in-positon replacing\n");
1042 } else {
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301043 mpf->physptr = mpc_new_phys;
Yinghai Lu2944e162008-06-01 13:17:38 -07001044 mpc_new = phys_to_virt(mpc_new_phys);
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +05301045 memcpy(mpc_new, mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -07001046 mpc = mpc_new;
1047 /* check if we can modify that */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301048 if (mpc_new_phys - mpf->physptr) {
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +05301049 struct mpf_intel *mpf_new;
Yinghai Lu2944e162008-06-01 13:17:38 -07001050 /* steal 16 bytes from [0, 1k) */
1051 printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
1052 mpf_new = phys_to_virt(0x400 - 16);
1053 memcpy(mpf_new, mpf, 16);
1054 mpf = mpf_new;
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301055 mpf->physptr = mpc_new_phys;
Yinghai Lu2944e162008-06-01 13:17:38 -07001056 }
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301057 mpf->checksum = 0;
1058 mpf->checksum -= mpf_checksum((unsigned char *)mpf, 16);
1059 printk(KERN_INFO "physptr new: %x\n", mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -07001060 }
1061
1062 /*
1063 * only replace the one with mp_INT and
1064 * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
1065 * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
1066 * may need pci=routeirq for all coverage
1067 */
1068 replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
1069
1070 return 0;
1071}
1072
1073late_initcall(update_mp_table);