blob: d7b6f7fb4fecfd44205d63ab6cfebfb400e8b21a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04002 * Intel Multiprocessor Specification 1.1 and 1.4
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * compliant MP-table parsing routines.
4 *
Alan Cox87c6fe22009-01-05 14:08:04 +00005 * (c) 1995 Alan Cox, Building #3 <alan@lxorguk.ukuu.org.uk>
Ingo Molnar8f47e162009-01-31 02:03:42 +01006 * (c) 1998, 1999, 2000, 2009 Ingo Molnar <mingo@redhat.com>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +04007 * (c) 2008 Alexey Starikovskiy <astarikovskiy@suse.de>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
9
10#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/bootmem.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/kernel_stat.h>
15#include <linux/mc146818rtc.h>
16#include <linux/bitops.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040017#include <linux/acpi.h>
18#include <linux/module.h>
Jaswinder Singh Rajput103ceff2009-01-02 23:43:25 +053019#include <linux/smp.h>
Yinghai Lu629e15d2009-05-15 13:05:16 -070020#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <asm/mtrr.h>
23#include <asm/mpspec.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040024#include <asm/pgalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/io_apic.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040026#include <asm/proto.h>
Alexey Starikovskiyce3fe6b2008-03-17 22:08:17 +030027#include <asm/bios_ebda.h>
Yinghai Lu2944e162008-06-01 13:17:38 -070028#include <asm/e820.h>
29#include <asm/trampoline.h>
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -070030#include <asm/setup.h>
Jaswinder Singh Rajput4884d8e2009-01-11 18:38:55 +053031#include <asm/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Ingo Molnar7b6aa332009-02-17 13:58:15 +010033#include <asm/apic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 * Checksum an MP configuration block.
36 */
37
38static int __init mpf_checksum(unsigned char *mp, int len)
39{
40 int sum = 0;
41
42 while (len--)
43 sum += *mp++;
44
45 return sum & 0xFF;
46}
47
Thomas Gleixnerfd6c6662009-08-20 10:41:58 +020048int __init default_mpc_apic_id(struct mpc_cpu *m)
49{
50 return m->apicid;
51}
52
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +053053static void __init MP_processor_info(struct mpc_cpu *m)
Alexey Starikovskiyc853c672008-03-27 23:54:13 +030054{
55 int apicid;
Alexey Starikovskiy746f2242008-04-04 23:42:15 +040056 char *bootup_cpu = "";
Alexey Starikovskiyc853c672008-03-27 23:54:13 +030057
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053058 if (!(m->cpuflag & CPU_ENABLED)) {
Glauber Costa7b1292e2008-03-03 14:12:41 -030059 disabled_cpus++;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 return;
Glauber Costa7b1292e2008-03-03 14:12:41 -030061 }
Yinghai Lu64898a82008-07-19 18:01:16 -070062
Thomas Gleixnerfd6c6662009-08-20 10:41:58 +020063 apicid = x86_init.mpparse.mpc_apic_id(m);
Yinghai Lu64898a82008-07-19 18:01:16 -070064
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053065 if (m->cpuflag & CPU_BOOTPROCESSOR) {
Alexey Starikovskiy746f2242008-04-04 23:42:15 +040066 bootup_cpu = " (Bootup-CPU)";
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053067 boot_cpu_physical_apicid = m->apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 }
69
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053070 printk(KERN_INFO "Processor #%d%s\n", m->apicid, bootup_cpu);
71 generic_processor_info(apicid, m->apicver);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072}
73
Thomas Gleixner85cc35f2008-05-25 21:21:36 +020074#ifdef CONFIG_X86_IO_APIC
Thomas Gleixner90e1c692009-08-20 12:34:47 +020075void __init default_mpc_oem_bus_info(struct mpc_bus *m, char *str)
76{
77 memcpy(str, m->bustype, 6);
78 str[6] = 0;
79 apic_printk(APIC_VERBOSE, "Bus #%d is %s\n", m->busid, str);
80}
81
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +053082static void __init MP_bus_info(struct mpc_bus *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
84 char str[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Thomas Gleixner90e1c692009-08-20 12:34:47 +020086 x86_init.mpparse.mpc_oem_bus_info(m, str);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Andi Kleen5e4edbb2006-09-26 10:52:35 +020088#if MAX_MP_BUSSES < 256
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053089 if (m->busid >= MAX_MP_BUSSES) {
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070090 printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +040091 " is too large, max. supported is %d\n",
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053092 m->busid, str, MAX_MP_BUSSES - 1);
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070093 return;
94 }
Andi Kleen5e4edbb2006-09-26 10:52:35 +020095#endif
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070096
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +040097 if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053098 set_bit(m->busid, mp_bus_not_pci);
Jaswinder Singh Rajput103ceff2009-01-02 23:43:25 +053099#if defined(CONFIG_EISA) || defined(CONFIG_MCA)
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530100 mp_bus_id_to_type[m->busid] = MP_BUS_ISA;
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +0400101#endif
102 } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
Thomas Gleixner52fdb562009-08-20 12:45:33 +0200103 if (x86_init.mpparse.mpc_oem_pci_bus)
104 x86_init.mpparse.mpc_oem_pci_bus(m);
Yinghai Lu64898a82008-07-19 18:01:16 -0700105
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530106 clear_bit(m->busid, mp_bus_not_pci);
Jaswinder Singh Rajput103ceff2009-01-02 23:43:25 +0530107#if defined(CONFIG_EISA) || defined(CONFIG_MCA)
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530108 mp_bus_id_to_type[m->busid] = MP_BUS_PCI;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400109 } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530110 mp_bus_id_to_type[m->busid] = MP_BUS_EISA;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400111 } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530112 mp_bus_id_to_type[m->busid] = MP_BUS_MCA;
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +0300113#endif
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +0400114 } else
115 printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116}
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400117
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530118static void __init MP_ioapic_info(struct mpc_ioapic *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119{
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530120 if (!(m->flags & MPC_APIC_USABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 return;
122
Thomas Gleixner64883ab2008-01-30 13:30:35 +0100123 printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530124 m->apicid, m->apicver, m->apicaddr);
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300125
Eric W. Biedermana4384df2010-06-08 11:44:32 -0700126 mp_register_ioapic(m->apicid, m->apicaddr, gsi_top);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127}
128
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530129static void print_MP_intsrc_info(struct mpc_intsrc *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200131 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530133 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbus,
134 m->srcbusirq, m->dstapic, m->dstirq);
Yinghai Lu2944e162008-06-01 13:17:38 -0700135}
136
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530137static void __init print_mp_irq_info(struct mpc_intsrc *mp_irq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700138{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200139 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
Yinghai Lu2944e162008-06-01 13:17:38 -0700140 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530141 mp_irq->irqtype, mp_irq->irqflag & 3,
142 (mp_irq->irqflag >> 2) & 3, mp_irq->srcbus,
143 mp_irq->srcbusirq, mp_irq->dstapic, mp_irq->dstirq);
Yinghai Lu2944e162008-06-01 13:17:38 -0700144}
145
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530146static void __init assign_to_mp_irq(struct mpc_intsrc *m,
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530147 struct mpc_intsrc *mp_irq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700148{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530149 mp_irq->dstapic = m->dstapic;
150 mp_irq->type = m->type;
151 mp_irq->irqtype = m->irqtype;
152 mp_irq->irqflag = m->irqflag;
153 mp_irq->srcbus = m->srcbus;
154 mp_irq->srcbusirq = m->srcbusirq;
155 mp_irq->dstirq = m->dstirq;
Yinghai Lu2944e162008-06-01 13:17:38 -0700156}
157
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530158static void __init assign_to_mpc_intsrc(struct mpc_intsrc *mp_irq,
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530159 struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700160{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530161 m->dstapic = mp_irq->dstapic;
162 m->type = mp_irq->type;
163 m->irqtype = mp_irq->irqtype;
164 m->irqflag = mp_irq->irqflag;
165 m->srcbus = mp_irq->srcbus;
166 m->srcbusirq = mp_irq->srcbusirq;
167 m->dstirq = mp_irq->dstirq;
Yinghai Lu2944e162008-06-01 13:17:38 -0700168}
169
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530170static int __init mp_irq_mpc_intsrc_cmp(struct mpc_intsrc *mp_irq,
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530171 struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700172{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530173 if (mp_irq->dstapic != m->dstapic)
Yinghai Lu2944e162008-06-01 13:17:38 -0700174 return 1;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530175 if (mp_irq->type != m->type)
Yinghai Lu2944e162008-06-01 13:17:38 -0700176 return 2;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530177 if (mp_irq->irqtype != m->irqtype)
Yinghai Lu2944e162008-06-01 13:17:38 -0700178 return 3;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530179 if (mp_irq->irqflag != m->irqflag)
Yinghai Lu2944e162008-06-01 13:17:38 -0700180 return 4;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530181 if (mp_irq->srcbus != m->srcbus)
Yinghai Lu2944e162008-06-01 13:17:38 -0700182 return 5;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530183 if (mp_irq->srcbusirq != m->srcbusirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700184 return 6;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530185 if (mp_irq->dstirq != m->dstirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700186 return 7;
187
188 return 0;
189}
190
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530191static void __init MP_intsrc_info(struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700192{
193 int i;
194
195 print_MP_intsrc_info(m);
196
Yinghai Lufcfa1462008-06-18 17:29:31 -0700197 for (i = 0; i < mp_irq_entries; i++) {
198 if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m))
199 return;
200 }
Yinghai Lu2944e162008-06-01 13:17:38 -0700201
202 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 if (++mp_irq_entries == MAX_IRQ_SOURCES)
204 panic("Max # of irq sources exceeded!!\n");
205}
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530206#else /* CONFIG_X86_IO_APIC */
207static inline void __init MP_bus_info(struct mpc_bus *m) {}
208static inline void __init MP_ioapic_info(struct mpc_ioapic *m) {}
209static inline void __init MP_intsrc_info(struct mpc_intsrc *m) {}
210#endif /* CONFIG_X86_IO_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400212
Jaswinder Singh Rajput8fb29522009-01-03 15:51:54 +0530213static void __init MP_lintsrc_info(struct mpc_lintsrc *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200215 apic_printk(APIC_VERBOSE, "Lint: type %d, pol %d, trig %d, bus %02x,"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
Jaswinder Singh Rajputb5ced7c2009-01-04 21:55:53 +0530217 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbusid,
218 m->srcbusirq, m->destapic, m->destapiclint);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219}
220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221/*
222 * Read/parse the MPC
223 */
224
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530225static int __init smp_check_mpc(struct mpc_table *mpc, char *oem, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530228 if (memcmp(mpc->signature, MPC_SIGNATURE, 4)) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400229 printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530230 mpc->signature[0], mpc->signature[1],
231 mpc->signature[2], mpc->signature[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 return 0;
233 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530234 if (mpf_checksum((unsigned char *)mpc, mpc->length)) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400235 printk(KERN_ERR "MPTABLE: checksum error!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 return 0;
237 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530238 if (mpc->spec != 0x01 && mpc->spec != 0x04) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400239 printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530240 mpc->spec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 return 0;
242 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530243 if (!mpc->lapic) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400244 printk(KERN_ERR "MPTABLE: null local APIC address!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 return 0;
246 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530247 memcpy(oem, mpc->oem, 8);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400248 oem[8] = 0;
Yinghai Lu11a62a02008-05-12 15:43:38 +0200249 printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530251 memcpy(str, mpc->productid, 12);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400252 str[12] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
Yinghai Lu11a62a02008-05-12 15:43:38 +0200254 printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530256 printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->lapic);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
Yinghai Lu2944e162008-06-01 13:17:38 -0700258 return 1;
259}
260
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530261static void skip_entry(unsigned char **ptr, int *count, int size)
262{
263 *ptr += size;
264 *count += size;
265}
266
Jaswinder Singh Rajput5a5737e2009-03-21 13:28:39 +0530267static void __init smp_dump_mptable(struct mpc_table *mpc, unsigned char *mpt)
268{
269 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n"
270 "type %x\n", *mpt);
271 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
272 1, mpc, mpc->length, 1);
273}
274
Thomas Gleixner72302142009-08-20 12:18:32 +0200275void __init default_smp_read_mpc_oem(struct mpc_table *mpc) { }
276
Eric W. Biederman5989cd62010-08-04 13:30:27 -0700277static void __init smp_register_lapic_address(unsigned long address)
278{
279 mp_lapic_addr = address;
280
281 set_fixmap_nocache(FIX_APIC_BASE, address);
282 if (boot_cpu_physical_apicid == -1U) {
283 boot_cpu_physical_apicid = read_apic_id();
284 apic_version[boot_cpu_physical_apicid] =
285 GET_APIC_VERSION(apic_read(APIC_LVR));
286 }
287}
288
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530289static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early)
Yinghai Lu2944e162008-06-01 13:17:38 -0700290{
291 char str[16];
292 char oem[10];
293
294 int count = sizeof(*mpc);
295 unsigned char *mpt = ((unsigned char *)mpc) + count;
296
297 if (!smp_check_mpc(mpc, oem, str))
298 return 0;
299
300#ifdef CONFIG_X86_32
Ingo Molnar9c764242009-01-28 13:44:32 +0100301 generic_mps_oem_check(mpc, oem, str);
Yinghai Lu2944e162008-06-01 13:17:38 -0700302#endif
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400303 /* save the local APIC address, it might be non-default */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 if (!acpi_lapic)
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530305 mp_lapic_addr = mpc->lapic;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400307 if (early)
308 return 1;
309
Eric W. Biederman5989cd62010-08-04 13:30:27 -0700310 /* Initialize the lapic mapping */
311 if (!acpi_lapic)
312 smp_register_lapic_address(mpc->lapic);
313
Thomas Gleixner72302142009-08-20 12:18:32 +0200314 if (mpc->oemptr)
315 x86_init.mpparse.smp_read_mpc_oem(mpc);
Yinghai Lu64898a82008-07-19 18:01:16 -0700316
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 */
Thomas Gleixnerf4848472009-08-20 12:05:01 +0200320 x86_init.mpparse.mpc_record(0);
Yinghai Lu64898a82008-07-19 18:01:16 -0700321
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530322 while (count < mpc->length) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400323 switch (*mpt) {
324 case MP_PROCESSOR:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530325 /* ACPI may have already provided this data */
326 if (!acpi_lapic)
Ingo Molnarc58603e2009-03-19 08:50:35 +0100327 MP_processor_info((struct mpc_cpu *)mpt);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530328 skip_entry(&mpt, &count, sizeof(struct mpc_cpu));
329 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400330 case MP_BUS:
Ingo Molnarc58603e2009-03-19 08:50:35 +0100331 MP_bus_info((struct mpc_bus *)mpt);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530332 skip_entry(&mpt, &count, sizeof(struct mpc_bus));
333 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400334 case MP_IOAPIC:
Ingo Molnarc58603e2009-03-19 08:50:35 +0100335 MP_ioapic_info((struct mpc_ioapic *)mpt);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530336 skip_entry(&mpt, &count, sizeof(struct mpc_ioapic));
337 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400338 case MP_INTSRC:
Ingo Molnarc58603e2009-03-19 08:50:35 +0100339 MP_intsrc_info((struct mpc_intsrc *)mpt);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530340 skip_entry(&mpt, &count, sizeof(struct mpc_intsrc));
341 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400342 case MP_LINTSRC:
Ingo Molnarc58603e2009-03-19 08:50:35 +0100343 MP_lintsrc_info((struct mpc_lintsrc *)mpt);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530344 skip_entry(&mpt, &count, sizeof(struct mpc_lintsrc));
345 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400346 default:
Yinghai Lu711554d2008-04-07 11:36:39 -0700347 /* wrong mptable */
Jaswinder Singh Rajput5a5737e2009-03-21 13:28:39 +0530348 smp_dump_mptable(mpc, mpt);
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530349 count = mpc->length;
Yinghai Lu711554d2008-04-07 11:36:39 -0700350 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 }
Thomas Gleixnerf4848472009-08-20 12:05:01 +0200352 x86_init.mpparse.mpc_record(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 }
Yinghai Lue0da3362008-06-08 18:29:22 -0700354
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 if (!num_processors)
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400356 printk(KERN_ERR "MPTABLE: no processors registered!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 return num_processors;
358}
359
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400360#ifdef CONFIG_X86_IO_APIC
361
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362static int __init ELCR_trigger(unsigned int irq)
363{
364 unsigned int port;
365
366 port = 0x4d0 + (irq >> 3);
367 return (inb(port) >> (irq & 7)) & 1;
368}
369
370static void __init construct_default_ioirq_mptable(int mpc_default_type)
371{
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530372 struct mpc_intsrc intsrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 int i;
374 int ELCR_fallback = 0;
375
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530376 intsrc.type = MP_INTSRC;
377 intsrc.irqflag = 0; /* conforming */
378 intsrc.srcbus = 0;
Jaswinder Singh Rajputb5ba7e62009-01-12 17:46:17 +0530379 intsrc.dstapic = mp_ioapics[0].apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530381 intsrc.irqtype = mp_INT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
383 /*
384 * If true, we have an ISA/PCI system with no IRQ entries
385 * in the MP table. To prevent the PCI interrupts from being set up
386 * incorrectly, we try to use the ELCR. The sanity check to see if
387 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
388 * never be level sensitive, so we simply see if the ELCR agrees.
389 * If it does, we assume it's valid.
390 */
391 if (mpc_default_type == 5) {
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400392 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
393 "falling back to ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400395 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
396 ELCR_trigger(13))
397 printk(KERN_ERR "ELCR contains invalid data... "
398 "not using ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 else {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400400 printk(KERN_INFO
401 "Using ELCR to identify PCI interrupts\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 ELCR_fallback = 1;
403 }
404 }
405
406 for (i = 0; i < 16; i++) {
407 switch (mpc_default_type) {
408 case 2:
409 if (i == 0 || i == 13)
410 continue; /* IRQ0 & IRQ13 not connected */
411 /* fall through */
412 default:
413 if (i == 2)
414 continue; /* IRQ2 is never connected */
415 }
416
417 if (ELCR_fallback) {
418 /*
419 * If the ELCR indicates a level-sensitive interrupt, we
420 * copy that information over to the MP table in the
421 * irqflag field (level sensitive, active high polarity).
422 */
423 if (ELCR_trigger(i))
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530424 intsrc.irqflag = 13;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 else
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530426 intsrc.irqflag = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 }
428
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530429 intsrc.srcbusirq = i;
430 intsrc.dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 MP_intsrc_info(&intsrc);
432 }
433
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530434 intsrc.irqtype = mp_ExtINT;
435 intsrc.srcbusirq = 0;
436 intsrc.dstirq = 0; /* 8259A to INTIN0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 MP_intsrc_info(&intsrc);
438}
439
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400440
Marcin Slusarz39e00fe2008-08-11 00:09:38 +0200441static void __init construct_ioapic_table(int mpc_default_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442{
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530443 struct mpc_ioapic ioapic;
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +0530444 struct mpc_bus bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530446 bus.type = MP_BUS;
447 bus.busid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 switch (mpc_default_type) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400449 default:
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400450 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400451 mpc_default_type);
452 /* fall through */
453 case 1:
454 case 5:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530455 memcpy(bus.bustype, "ISA ", 6);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400456 break;
457 case 2:
458 case 6:
459 case 3:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530460 memcpy(bus.bustype, "EISA ", 6);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400461 break;
462 case 4:
463 case 7:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530464 memcpy(bus.bustype, "MCA ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 }
466 MP_bus_info(&bus);
467 if (mpc_default_type > 4) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530468 bus.busid = 1;
469 memcpy(bus.bustype, "PCI ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 MP_bus_info(&bus);
471 }
472
Cyrill Gorcunov8f3e1df2009-08-24 21:53:36 +0400473 ioapic.type = MP_IOAPIC;
474 ioapic.apicid = 2;
475 ioapic.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
476 ioapic.flags = MPC_APIC_USABLE;
477 ioapic.apicaddr = IO_APIC_DEFAULT_PHYS_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 MP_ioapic_info(&ioapic);
479
480 /*
481 * We set up most of the low 16 IO-APIC pins according to MPS rules.
482 */
483 construct_default_ioirq_mptable(mpc_default_type);
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200484}
485#else
Marcin Slusarz39e00fe2008-08-11 00:09:38 +0200486static inline void __init construct_ioapic_table(int mpc_default_type) { }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400487#endif
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200488
489static inline void __init construct_default_ISA_mptable(int mpc_default_type)
490{
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +0530491 struct mpc_cpu processor;
Jaswinder Singh Rajput8fb29522009-01-03 15:51:54 +0530492 struct mpc_lintsrc lintsrc;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200493 int linttypes[2] = { mp_ExtINT, mp_NMI };
494 int i;
495
496 /*
497 * local APIC has default address
498 */
499 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
500
501 /*
502 * 2 CPUs, numbered 0 & 1.
503 */
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530504 processor.type = MP_PROCESSOR;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200505 /* Either an integrated APIC or a discrete 82489DX. */
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530506 processor.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
507 processor.cpuflag = CPU_ENABLED;
508 processor.cpufeature = (boot_cpu_data.x86 << 8) |
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200509 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530510 processor.featureflag = boot_cpu_data.x86_capability[0];
511 processor.reserved[0] = 0;
512 processor.reserved[1] = 0;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200513 for (i = 0; i < 2; i++) {
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530514 processor.apicid = i;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200515 MP_processor_info(&processor);
516 }
517
518 construct_ioapic_table(mpc_default_type);
519
Jaswinder Singh Rajputb5ced7c2009-01-04 21:55:53 +0530520 lintsrc.type = MP_LINTSRC;
521 lintsrc.irqflag = 0; /* conforming */
522 lintsrc.srcbusid = 0;
523 lintsrc.srcbusirq = 0;
524 lintsrc.destapic = MP_APIC_ALL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 for (i = 0; i < 2; i++) {
Jaswinder Singh Rajputb5ced7c2009-01-04 21:55:53 +0530526 lintsrc.irqtype = linttypes[i];
527 lintsrc.destapiclint = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 MP_lintsrc_info(&lintsrc);
529 }
530}
531
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530532static struct mpf_intel *mpf_found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
Yinghai Lu8d4dd9192009-03-04 01:25:21 -0800534static unsigned long __init get_mpc_size(unsigned long physptr)
535{
536 struct mpc_table *mpc;
537 unsigned long size;
538
539 mpc = early_ioremap(physptr, PAGE_SIZE);
540 size = mpc->length;
541 early_iounmap(mpc, PAGE_SIZE);
542 apic_printk(APIC_VERBOSE, " mpc: %lx-%lx\n", physptr, physptr + size);
543
544 return size;
545}
546
Jaswinder Singh Rajput0b3ba0c2009-03-21 13:43:20 +0530547static int __init check_physptr(struct mpf_intel *mpf, unsigned int early)
548{
549 struct mpc_table *mpc;
550 unsigned long size;
551
552 size = get_mpc_size(mpf->physptr);
553 mpc = early_ioremap(mpf->physptr, size);
554 /*
555 * Read the physical hardware table. Anything here will
556 * override the defaults.
557 */
558 if (!smp_read_mpc(mpc, early)) {
559#ifdef CONFIG_X86_LOCAL_APIC
560 smp_found_config = 0;
561#endif
562 printk(KERN_ERR "BIOS bug, MP table errors detected!...\n"
563 "... disabling SMP support. (tell your hw vendor)\n");
564 early_iounmap(mpc, size);
565 return -1;
566 }
567 early_iounmap(mpc, size);
568
569 if (early)
570 return -1;
571
572#ifdef CONFIG_X86_IO_APIC
573 /*
574 * If there are no explicit MP IRQ entries, then we are
575 * broken. We set up most of the low 16 IO-APIC pins to
576 * ISA defaults and hope it will work.
577 */
578 if (!mp_irq_entries) {
579 struct mpc_bus bus;
580
581 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
582 "using default mptable. (tell your hw vendor)\n");
583
584 bus.type = MP_BUS;
585 bus.busid = 0;
586 memcpy(bus.bustype, "ISA ", 6);
587 MP_bus_info(&bus);
588
589 construct_default_ioirq_mptable(0);
590 }
591#endif
592
593 return 0;
594}
595
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596/*
597 * Scan the memory blocks for an SMP configuration block.
598 */
Thomas Gleixnerb3f1b612009-08-20 11:11:52 +0200599void __init default_get_smp_config(unsigned int early)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600{
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530601 struct mpf_intel *mpf = mpf_found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Yinghai Lu69b88af2008-12-05 22:45:50 -0800603 if (!mpf)
604 return;
605
606 if (acpi_lapic && early)
607 return;
608
609 /*
610 * MPS doesn't support hyperthreading, aka only have
611 * thread 0 apic id in MPS table
612 */
613 if (acpi_lapic && acpi_ioapic)
614 return;
615
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400616 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530617 mpf->specification);
Alexey Starikovskiyb3e24162008-05-23 01:54:44 +0400618#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530619 if (mpf->feature2 & (1 << 7)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
621 pic_mode = 1;
622 } else {
623 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
624 pic_mode = 0;
625 }
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400626#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 /*
628 * Now see if we need to read further.
629 */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530630 if (mpf->feature1 != 0) {
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400631 if (early) {
632 /*
633 * local APIC has default address
634 */
635 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
636 return;
637 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400639 printk(KERN_INFO "Default MP configuration #%d\n",
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530640 mpf->feature1);
641 construct_default_ISA_mptable(mpf->feature1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530643 } else if (mpf->physptr) {
Jaswinder Singh Rajput0b3ba0c2009-03-21 13:43:20 +0530644 if (check_physptr(mpf, early))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 } else
647 BUG();
648
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400649 if (!early)
650 printk(KERN_INFO "Processors: %d\n", num_processors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 /*
652 * Only use the first configuration found.
653 */
654}
655
Yinghai Lub24c2a92009-11-24 02:48:18 -0800656static void __init smp_reserve_memory(struct mpf_intel *mpf)
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530657{
658 unsigned long size = get_mpc_size(mpf->physptr);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530659
Andi Kleen909fc872010-03-29 09:41:11 +0200660 reserve_early_overlap_ok(mpf->physptr, mpf->physptr+size, "MP-table mpc");
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530661}
662
Yinghai Lub24c2a92009-11-24 02:48:18 -0800663static int __init smp_scan_config(unsigned long base, unsigned long length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664{
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400665 unsigned int *bp = phys_to_virt(base);
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530666 struct mpf_intel *mpf;
Yinghai Lub24c2a92009-11-24 02:48:18 -0800667 unsigned long mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200669 apic_printk(APIC_VERBOSE, "Scan SMP from %p for %ld bytes.\n",
670 bp, length);
Akinobu Mita5d47a272008-04-19 23:55:11 +0900671 BUILD_BUG_ON(sizeof(*mpf) != 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
673 while (length > 0) {
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530674 mpf = (struct mpf_intel *)bp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 if ((*bp == SMP_MAGIC_IDENT) &&
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530676 (mpf->length == 1) &&
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400677 !mpf_checksum((unsigned char *)bp, 16) &&
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530678 ((mpf->specification == 1)
679 || (mpf->specification == 4))) {
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400680#ifdef CONFIG_X86_LOCAL_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 smp_found_config = 1;
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400682#endif
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400683 mpf_found = mpf;
Yinghai Lub1f006b2008-06-09 18:11:36 -0700684
Jaswinder Singh Rajputba1511b2009-02-11 23:38:25 +0530685 printk(KERN_INFO "found SMP MP-table at [%p] %llx\n",
686 mpf, (u64)virt_to_phys(mpf));
Yinghai Lub1f006b2008-06-09 18:11:36 -0700687
Yinghai Lub24c2a92009-11-24 02:48:18 -0800688 mem = virt_to_phys(mpf);
Andi Kleen909fc872010-03-29 09:41:11 +0200689 reserve_early_overlap_ok(mem, mem + sizeof(*mpf), "MP-table mpf");
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530690 if (mpf->physptr)
Yinghai Lub24c2a92009-11-24 02:48:18 -0800691 smp_reserve_memory(mpf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
Yinghai Lud2dbf342008-06-13 02:00:56 -0700693 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 }
695 bp += 4;
696 length -= 16;
697 }
698 return 0;
699}
700
Yinghai Lub24c2a92009-11-24 02:48:18 -0800701void __init default_find_smp_config(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702{
703 unsigned int address;
704
705 /*
706 * FIXME: Linux assumes you have 640K of base ram..
707 * this continues the error...
708 *
709 * 1) Scan the bottom 1K for a signature
710 * 2) Scan the top 1K of base RAM
711 * 3) Scan the 64K of bios
712 */
Yinghai Lub24c2a92009-11-24 02:48:18 -0800713 if (smp_scan_config(0x0, 0x400) ||
714 smp_scan_config(639 * 0x400, 0x400) ||
715 smp_scan_config(0xF0000, 0x10000))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 return;
717 /*
718 * If it is an SMP machine we should know now, unless the
719 * configuration is in an EISA/MCA bus machine with an
720 * extended bios data area.
721 *
722 * there is a real-mode segmented pointer pointing to the
723 * 4K EBDA area at 0x40E, calculate and scan it here.
724 *
725 * NOTE! There are Linux loaders that will corrupt the EBDA
726 * area, and as such this kind of SMP config may be less
727 * trustworthy, simply because the SMP table may have been
728 * stomped on during early boot. These loaders are buggy and
729 * should be fixed.
730 *
731 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
732 */
733
734 address = get_bios_ebda();
735 if (address)
Yinghai Lub24c2a92009-11-24 02:48:18 -0800736 smp_scan_config(address, 0x400);
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400737}
738
Yinghai Lu2944e162008-06-01 13:17:38 -0700739#ifdef CONFIG_X86_IO_APIC
740static u8 __initdata irq_used[MAX_IRQ_SOURCES];
741
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530742static int __init get_MP_intsrc_index(struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700743{
744 int i;
745
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530746 if (m->irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700747 return 0;
748
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530749 if (m->irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700750 return 0;
751
752 /* not legacy */
753
754 for (i = 0; i < mp_irq_entries; i++) {
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530755 if (mp_irqs[i].irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700756 continue;
757
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530758 if (mp_irqs[i].irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700759 continue;
760
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530761 if (mp_irqs[i].srcbus != m->srcbus)
Yinghai Lu2944e162008-06-01 13:17:38 -0700762 continue;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530763 if (mp_irqs[i].srcbusirq != m->srcbusirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700764 continue;
765 if (irq_used[i]) {
766 /* already claimed */
767 return -2;
768 }
769 irq_used[i] = 1;
770 return i;
771 }
772
773 /* not found */
774 return -1;
775}
776
777#define SPARE_SLOT_NUM 20
778
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530779static struct mpc_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530780
Rakib Mullick57592222009-04-11 09:04:59 +0600781static void __init check_irq_src(struct mpc_intsrc *m, int *nr_m_spare)
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530782{
783 int i;
784
785 apic_printk(APIC_VERBOSE, "OLD ");
786 print_MP_intsrc_info(m);
787
788 i = get_MP_intsrc_index(m);
789 if (i > 0) {
790 assign_to_mpc_intsrc(&mp_irqs[i], m);
791 apic_printk(APIC_VERBOSE, "NEW ");
792 print_mp_irq_info(&mp_irqs[i]);
793 return;
794 }
795 if (!i) {
796 /* legacy, do nothing */
797 return;
798 }
799 if (*nr_m_spare < SPARE_SLOT_NUM) {
800 /*
801 * not found (-1), or duplicated (-2) are invalid entries,
802 * we need to use the slot later
803 */
804 m_spare[*nr_m_spare] = m;
805 *nr_m_spare += 1;
806 }
807}
808#else /* CONFIG_X86_IO_APIC */
Rakib Mullick57592222009-04-11 09:04:59 +0600809static
810inline void __init check_irq_src(struct mpc_intsrc *m, int *nr_m_spare) {}
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530811#endif /* CONFIG_X86_IO_APIC */
812
Yinghai Luee214552009-05-06 10:07:07 -0700813static int
814check_slot(unsigned long mpc_new_phys, unsigned long mpc_new_length, int count)
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530815{
Yinghai Luee214552009-05-06 10:07:07 -0700816 int ret = 0;
817
818 if (!mpc_new_phys || count <= mpc_new_length) {
819 WARN(1, "update_mptable: No spare slots (length: %x)\n", count);
820 return -1;
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530821 }
822
Yinghai Luee214552009-05-06 10:07:07 -0700823 return ret;
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530824}
Yinghai Lu2944e162008-06-01 13:17:38 -0700825
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530826static int __init replace_intsrc_all(struct mpc_table *mpc,
Yinghai Lu2944e162008-06-01 13:17:38 -0700827 unsigned long mpc_new_phys,
828 unsigned long mpc_new_length)
829{
830#ifdef CONFIG_X86_IO_APIC
831 int i;
Yinghai Lu2944e162008-06-01 13:17:38 -0700832#endif
Yinghai Lu2944e162008-06-01 13:17:38 -0700833 int count = sizeof(*mpc);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530834 int nr_m_spare = 0;
Yinghai Lu2944e162008-06-01 13:17:38 -0700835 unsigned char *mpt = ((unsigned char *)mpc) + count;
836
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530837 printk(KERN_INFO "mpc_length %x\n", mpc->length);
838 while (count < mpc->length) {
Yinghai Lu2944e162008-06-01 13:17:38 -0700839 switch (*mpt) {
840 case MP_PROCESSOR:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530841 skip_entry(&mpt, &count, sizeof(struct mpc_cpu));
842 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700843 case MP_BUS:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530844 skip_entry(&mpt, &count, sizeof(struct mpc_bus));
845 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700846 case MP_IOAPIC:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530847 skip_entry(&mpt, &count, sizeof(struct mpc_ioapic));
848 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700849 case MP_INTSRC:
Ingo Molnarc58603e2009-03-19 08:50:35 +0100850 check_irq_src((struct mpc_intsrc *)mpt, &nr_m_spare);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530851 skip_entry(&mpt, &count, sizeof(struct mpc_intsrc));
852 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700853 case MP_LINTSRC:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530854 skip_entry(&mpt, &count, sizeof(struct mpc_lintsrc));
855 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700856 default:
857 /* wrong mptable */
Jaswinder Singh Rajput5a5737e2009-03-21 13:28:39 +0530858 smp_dump_mptable(mpc, mpt);
Yinghai Lu2944e162008-06-01 13:17:38 -0700859 goto out;
860 }
861 }
862
863#ifdef CONFIG_X86_IO_APIC
864 for (i = 0; i < mp_irq_entries; i++) {
865 if (irq_used[i])
866 continue;
867
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530868 if (mp_irqs[i].irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700869 continue;
870
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530871 if (mp_irqs[i].irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700872 continue;
873
874 if (nr_m_spare > 0) {
Jan Beulich82034d62009-03-12 12:57:10 +0000875 apic_printk(APIC_VERBOSE, "*NEW* found\n");
Yinghai Lu2944e162008-06-01 13:17:38 -0700876 nr_m_spare--;
877 assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
878 m_spare[nr_m_spare] = NULL;
879 } else {
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530880 struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
881 count += sizeof(struct mpc_intsrc);
Yinghai Luee214552009-05-06 10:07:07 -0700882 if (check_slot(mpc_new_phys, mpc_new_length, count) < 0)
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530883 goto out;
Yinghai Lu2944e162008-06-01 13:17:38 -0700884 assign_to_mpc_intsrc(&mp_irqs[i], m);
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530885 mpc->length = count;
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530886 mpt += sizeof(struct mpc_intsrc);
Yinghai Lu2944e162008-06-01 13:17:38 -0700887 }
888 print_mp_irq_info(&mp_irqs[i]);
889 }
890#endif
891out:
892 /* update checksum */
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530893 mpc->checksum = 0;
894 mpc->checksum -= mpf_checksum((unsigned char *)mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -0700895
896 return 0;
897}
898
Yinghai Luf1bdb522009-05-15 13:05:16 -0700899int enable_update_mptable;
Yinghai Lufcfa1462008-06-18 17:29:31 -0700900
Yinghai Lu2944e162008-06-01 13:17:38 -0700901static int __init update_mptable_setup(char *str)
902{
903 enable_update_mptable = 1;
Yinghai Lu629e15d2009-05-15 13:05:16 -0700904#ifdef CONFIG_PCI
905 pci_routeirq = 1;
906#endif
Yinghai Lu2944e162008-06-01 13:17:38 -0700907 return 0;
908}
909early_param("update_mptable", update_mptable_setup);
910
911static unsigned long __initdata mpc_new_phys;
912static unsigned long mpc_new_length __initdata = 4096;
913
914/* alloc_mptable or alloc_mptable=4k */
915static int __initdata alloc_mptable;
916static int __init parse_alloc_mptable_opt(char *p)
917{
918 enable_update_mptable = 1;
Yinghai Lu629e15d2009-05-15 13:05:16 -0700919#ifdef CONFIG_PCI
920 pci_routeirq = 1;
921#endif
Yinghai Lu2944e162008-06-01 13:17:38 -0700922 alloc_mptable = 1;
923 if (!p)
924 return 0;
925 mpc_new_length = memparse(p, &p);
926 return 0;
927}
928early_param("alloc_mptable", parse_alloc_mptable_opt);
929
930void __init early_reserve_e820_mpc_new(void)
931{
932 if (enable_update_mptable && alloc_mptable) {
933 u64 startt = 0;
Yinghai Lu2944e162008-06-01 13:17:38 -0700934 mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
935 }
936}
937
938static int __init update_mp_table(void)
939{
940 char str[16];
941 char oem[10];
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530942 struct mpf_intel *mpf;
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530943 struct mpc_table *mpc, *mpc_new;
Yinghai Lu2944e162008-06-01 13:17:38 -0700944
945 if (!enable_update_mptable)
946 return 0;
947
948 mpf = mpf_found;
949 if (!mpf)
950 return 0;
951
952 /*
953 * Now see if we need to go further.
954 */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530955 if (mpf->feature1 != 0)
Yinghai Lu2944e162008-06-01 13:17:38 -0700956 return 0;
957
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530958 if (!mpf->physptr)
Yinghai Lu2944e162008-06-01 13:17:38 -0700959 return 0;
960
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530961 mpc = phys_to_virt(mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -0700962
963 if (!smp_check_mpc(mpc, oem, str))
964 return 0;
965
Jaswinder Singh Rajputba1511b2009-02-11 23:38:25 +0530966 printk(KERN_INFO "mpf: %llx\n", (u64)virt_to_phys(mpf));
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530967 printk(KERN_INFO "physptr: %x\n", mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -0700968
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530969 if (mpc_new_phys && mpc->length > mpc_new_length) {
Yinghai Lu2944e162008-06-01 13:17:38 -0700970 mpc_new_phys = 0;
971 printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
972 mpc_new_length);
973 }
974
975 if (!mpc_new_phys) {
976 unsigned char old, new;
977 /* check if we can change the postion */
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530978 mpc->checksum = 0;
979 old = mpf_checksum((unsigned char *)mpc, mpc->length);
980 mpc->checksum = 0xff;
981 new = mpf_checksum((unsigned char *)mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -0700982 if (old == new) {
983 printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
984 return 0;
985 }
986 printk(KERN_INFO "use in-positon replacing\n");
987 } else {
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530988 mpf->physptr = mpc_new_phys;
Yinghai Lu2944e162008-06-01 13:17:38 -0700989 mpc_new = phys_to_virt(mpc_new_phys);
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530990 memcpy(mpc_new, mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -0700991 mpc = mpc_new;
992 /* check if we can modify that */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530993 if (mpc_new_phys - mpf->physptr) {
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530994 struct mpf_intel *mpf_new;
Yinghai Lu2944e162008-06-01 13:17:38 -0700995 /* steal 16 bytes from [0, 1k) */
996 printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
997 mpf_new = phys_to_virt(0x400 - 16);
998 memcpy(mpf_new, mpf, 16);
999 mpf = mpf_new;
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301000 mpf->physptr = mpc_new_phys;
Yinghai Lu2944e162008-06-01 13:17:38 -07001001 }
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301002 mpf->checksum = 0;
1003 mpf->checksum -= mpf_checksum((unsigned char *)mpf, 16);
1004 printk(KERN_INFO "physptr new: %x\n", mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -07001005 }
1006
1007 /*
1008 * only replace the one with mp_INT and
1009 * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
1010 * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
1011 * may need pci=routeirq for all coverage
1012 */
1013 replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
1014
1015 return 0;
1016}
1017
1018late_initcall(update_mp_table);