blob: db0b70317949ef8f0a4f16d04ec897c8ed5adf04 [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>
Yinghai Lu72d7c3b2010-08-25 13:39:17 -070014#include <linux/memblock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/kernel_stat.h>
16#include <linux/mc146818rtc.h>
17#include <linux/bitops.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040018#include <linux/acpi.h>
19#include <linux/module.h>
Jaswinder Singh Rajput103ceff2009-01-02 23:43:25 +053020#include <linux/smp.h>
Yinghai Lu629e15d2009-05-15 13:05:16 -070021#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/mtrr.h>
24#include <asm/mpspec.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040025#include <asm/pgalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <asm/io_apic.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040027#include <asm/proto.h>
Alexey Starikovskiyce3fe6b2008-03-17 22:08:17 +030028#include <asm/bios_ebda.h>
Yinghai Lu2944e162008-06-01 13:17:38 -070029#include <asm/e820.h>
30#include <asm/trampoline.h>
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -070031#include <asm/setup.h>
Jaswinder Singh Rajput4884d8e2009-01-11 18:38:55 +053032#include <asm/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Ingo Molnar7b6aa332009-02-17 13:58:15 +010034#include <asm/apic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 * Checksum an MP configuration block.
37 */
38
39static int __init mpf_checksum(unsigned char *mp, int len)
40{
41 int sum = 0;
42
43 while (len--)
44 sum += *mp++;
45
46 return sum & 0xFF;
47}
48
Thomas Gleixnerfd6c6662009-08-20 10:41:58 +020049int __init default_mpc_apic_id(struct mpc_cpu *m)
50{
51 return m->apicid;
52}
53
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +053054static void __init MP_processor_info(struct mpc_cpu *m)
Alexey Starikovskiyc853c672008-03-27 23:54:13 +030055{
56 int apicid;
Alexey Starikovskiy746f2242008-04-04 23:42:15 +040057 char *bootup_cpu = "";
Alexey Starikovskiyc853c672008-03-27 23:54:13 +030058
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053059 if (!(m->cpuflag & CPU_ENABLED)) {
Glauber Costa7b1292e2008-03-03 14:12:41 -030060 disabled_cpus++;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 return;
Glauber Costa7b1292e2008-03-03 14:12:41 -030062 }
Yinghai Lu64898a82008-07-19 18:01:16 -070063
Thomas Gleixnerfd6c6662009-08-20 10:41:58 +020064 apicid = x86_init.mpparse.mpc_apic_id(m);
Yinghai Lu64898a82008-07-19 18:01:16 -070065
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053066 if (m->cpuflag & CPU_BOOTPROCESSOR) {
Alexey Starikovskiy746f2242008-04-04 23:42:15 +040067 bootup_cpu = " (Bootup-CPU)";
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053068 boot_cpu_physical_apicid = m->apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 }
70
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +053071 printk(KERN_INFO "Processor #%d%s\n", m->apicid, bootup_cpu);
72 generic_processor_info(apicid, m->apicver);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073}
74
Thomas Gleixner85cc35f2008-05-25 21:21:36 +020075#ifdef CONFIG_X86_IO_APIC
Thomas Gleixner90e1c692009-08-20 12:34:47 +020076void __init default_mpc_oem_bus_info(struct mpc_bus *m, char *str)
77{
78 memcpy(str, m->bustype, 6);
79 str[6] = 0;
80 apic_printk(APIC_VERBOSE, "Bus #%d is %s\n", m->busid, str);
81}
82
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +053083static void __init MP_bus_info(struct mpc_bus *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
85 char str[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Thomas Gleixner90e1c692009-08-20 12:34:47 +020087 x86_init.mpparse.mpc_oem_bus_info(m, str);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Andi Kleen5e4edbb2006-09-26 10:52:35 +020089#if MAX_MP_BUSSES < 256
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053090 if (m->busid >= MAX_MP_BUSSES) {
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070091 printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +040092 " is too large, max. supported is %d\n",
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053093 m->busid, str, MAX_MP_BUSSES - 1);
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070094 return;
95 }
Andi Kleen5e4edbb2006-09-26 10:52:35 +020096#endif
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070097
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +040098 if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +053099 set_bit(m->busid, mp_bus_not_pci);
Jaswinder Singh Rajput103ceff2009-01-02 23:43:25 +0530100#if defined(CONFIG_EISA) || defined(CONFIG_MCA)
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530101 mp_bus_id_to_type[m->busid] = MP_BUS_ISA;
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +0400102#endif
103 } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
Thomas Gleixner52fdb562009-08-20 12:45:33 +0200104 if (x86_init.mpparse.mpc_oem_pci_bus)
105 x86_init.mpparse.mpc_oem_pci_bus(m);
Yinghai Lu64898a82008-07-19 18:01:16 -0700106
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530107 clear_bit(m->busid, mp_bus_not_pci);
Jaswinder Singh Rajput103ceff2009-01-02 23:43:25 +0530108#if defined(CONFIG_EISA) || defined(CONFIG_MCA)
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530109 mp_bus_id_to_type[m->busid] = MP_BUS_PCI;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400110 } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530111 mp_bus_id_to_type[m->busid] = MP_BUS_EISA;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400112 } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530113 mp_bus_id_to_type[m->busid] = MP_BUS_MCA;
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +0300114#endif
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +0400115 } else
116 printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117}
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400118
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530119static void __init MP_ioapic_info(struct mpc_ioapic *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120{
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530121 if (!(m->flags & MPC_APIC_USABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 return;
123
Thomas Gleixner64883ab2008-01-30 13:30:35 +0100124 printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530125 m->apicid, m->apicver, m->apicaddr);
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300126
Eric W. Biedermana4384df2010-06-08 11:44:32 -0700127 mp_register_ioapic(m->apicid, m->apicaddr, gsi_top);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128}
129
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530130static void print_MP_intsrc_info(struct mpc_intsrc *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200132 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530134 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbus,
135 m->srcbusirq, m->dstapic, m->dstirq);
Yinghai Lu2944e162008-06-01 13:17:38 -0700136}
137
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530138static void __init print_mp_irq_info(struct mpc_intsrc *mp_irq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700139{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200140 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
Yinghai Lu2944e162008-06-01 13:17:38 -0700141 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530142 mp_irq->irqtype, mp_irq->irqflag & 3,
143 (mp_irq->irqflag >> 2) & 3, mp_irq->srcbus,
144 mp_irq->srcbusirq, mp_irq->dstapic, mp_irq->dstirq);
Yinghai Lu2944e162008-06-01 13:17:38 -0700145}
146
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530147static void __init assign_to_mp_irq(struct mpc_intsrc *m,
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530148 struct mpc_intsrc *mp_irq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700149{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530150 mp_irq->dstapic = m->dstapic;
151 mp_irq->type = m->type;
152 mp_irq->irqtype = m->irqtype;
153 mp_irq->irqflag = m->irqflag;
154 mp_irq->srcbus = m->srcbus;
155 mp_irq->srcbusirq = m->srcbusirq;
156 mp_irq->dstirq = m->dstirq;
Yinghai Lu2944e162008-06-01 13:17:38 -0700157}
158
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530159static void __init assign_to_mpc_intsrc(struct mpc_intsrc *mp_irq,
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530160 struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700161{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530162 m->dstapic = mp_irq->dstapic;
163 m->type = mp_irq->type;
164 m->irqtype = mp_irq->irqtype;
165 m->irqflag = mp_irq->irqflag;
166 m->srcbus = mp_irq->srcbus;
167 m->srcbusirq = mp_irq->srcbusirq;
168 m->dstirq = mp_irq->dstirq;
Yinghai Lu2944e162008-06-01 13:17:38 -0700169}
170
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530171static int __init mp_irq_mpc_intsrc_cmp(struct mpc_intsrc *mp_irq,
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530172 struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700173{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530174 if (mp_irq->dstapic != m->dstapic)
Yinghai Lu2944e162008-06-01 13:17:38 -0700175 return 1;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530176 if (mp_irq->type != m->type)
Yinghai Lu2944e162008-06-01 13:17:38 -0700177 return 2;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530178 if (mp_irq->irqtype != m->irqtype)
Yinghai Lu2944e162008-06-01 13:17:38 -0700179 return 3;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530180 if (mp_irq->irqflag != m->irqflag)
Yinghai Lu2944e162008-06-01 13:17:38 -0700181 return 4;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530182 if (mp_irq->srcbus != m->srcbus)
Yinghai Lu2944e162008-06-01 13:17:38 -0700183 return 5;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530184 if (mp_irq->srcbusirq != m->srcbusirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700185 return 6;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530186 if (mp_irq->dstirq != m->dstirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700187 return 7;
188
189 return 0;
190}
191
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530192static void __init MP_intsrc_info(struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700193{
194 int i;
195
196 print_MP_intsrc_info(m);
197
Yinghai Lufcfa1462008-06-18 17:29:31 -0700198 for (i = 0; i < mp_irq_entries; i++) {
199 if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m))
200 return;
201 }
Yinghai Lu2944e162008-06-01 13:17:38 -0700202
203 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 if (++mp_irq_entries == MAX_IRQ_SOURCES)
205 panic("Max # of irq sources exceeded!!\n");
206}
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530207#else /* CONFIG_X86_IO_APIC */
208static inline void __init MP_bus_info(struct mpc_bus *m) {}
209static inline void __init MP_ioapic_info(struct mpc_ioapic *m) {}
210static inline void __init MP_intsrc_info(struct mpc_intsrc *m) {}
211#endif /* CONFIG_X86_IO_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400213
Jaswinder Singh Rajput8fb29522009-01-03 15:51:54 +0530214static void __init MP_lintsrc_info(struct mpc_lintsrc *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200216 apic_printk(APIC_VERBOSE, "Lint: type %d, pol %d, trig %d, bus %02x,"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
Jaswinder Singh Rajputb5ced7c2009-01-04 21:55:53 +0530218 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbusid,
219 m->srcbusirq, m->destapic, m->destapiclint);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220}
221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222/*
223 * Read/parse the MPC
224 */
225
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530226static int __init smp_check_mpc(struct mpc_table *mpc, char *oem, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530229 if (memcmp(mpc->signature, MPC_SIGNATURE, 4)) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400230 printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530231 mpc->signature[0], mpc->signature[1],
232 mpc->signature[2], mpc->signature[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 return 0;
234 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530235 if (mpf_checksum((unsigned char *)mpc, mpc->length)) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400236 printk(KERN_ERR "MPTABLE: checksum error!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 return 0;
238 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530239 if (mpc->spec != 0x01 && mpc->spec != 0x04) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400240 printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530241 mpc->spec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 return 0;
243 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530244 if (!mpc->lapic) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400245 printk(KERN_ERR "MPTABLE: null local APIC address!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 return 0;
247 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530248 memcpy(oem, mpc->oem, 8);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400249 oem[8] = 0;
Yinghai Lu11a62a02008-05-12 15:43:38 +0200250 printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530252 memcpy(str, mpc->productid, 12);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400253 str[12] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
Yinghai Lu11a62a02008-05-12 15:43:38 +0200255 printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530257 printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->lapic);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Yinghai Lu2944e162008-06-01 13:17:38 -0700259 return 1;
260}
261
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530262static void skip_entry(unsigned char **ptr, int *count, int size)
263{
264 *ptr += size;
265 *count += size;
266}
267
Jaswinder Singh Rajput5a5737e2009-03-21 13:28:39 +0530268static void __init smp_dump_mptable(struct mpc_table *mpc, unsigned char *mpt)
269{
270 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n"
271 "type %x\n", *mpt);
272 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
273 1, mpc, mpc->length, 1);
274}
275
Thomas Gleixner72302142009-08-20 12:18:32 +0200276void __init default_smp_read_mpc_oem(struct mpc_table *mpc) { }
277
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530278static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early)
Yinghai Lu2944e162008-06-01 13:17:38 -0700279{
280 char str[16];
281 char oem[10];
282
283 int count = sizeof(*mpc);
284 unsigned char *mpt = ((unsigned char *)mpc) + count;
285
286 if (!smp_check_mpc(mpc, oem, str))
287 return 0;
288
289#ifdef CONFIG_X86_32
Ingo Molnar9c764242009-01-28 13:44:32 +0100290 generic_mps_oem_check(mpc, oem, str);
Yinghai Lu2944e162008-06-01 13:17:38 -0700291#endif
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400292 /* save the local APIC address, it might be non-default */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 if (!acpi_lapic)
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530294 mp_lapic_addr = mpc->lapic;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400296 if (early)
297 return 1;
298
Eric W. Biederman5989cd62010-08-04 13:30:27 -0700299 /* Initialize the lapic mapping */
300 if (!acpi_lapic)
Yinghai Luc0104d32010-12-07 00:55:17 -0800301 register_lapic_address(mpc->lapic);
Eric W. Biederman5989cd62010-08-04 13:30:27 -0700302
Thomas Gleixner72302142009-08-20 12:18:32 +0200303 if (mpc->oemptr)
304 x86_init.mpparse.smp_read_mpc_oem(mpc);
Yinghai Lu64898a82008-07-19 18:01:16 -0700305
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 /*
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400307 * Now process the configuration blocks.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 */
Thomas Gleixnerf4848472009-08-20 12:05:01 +0200309 x86_init.mpparse.mpc_record(0);
Yinghai Lu64898a82008-07-19 18:01:16 -0700310
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530311 while (count < mpc->length) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400312 switch (*mpt) {
313 case MP_PROCESSOR:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530314 /* ACPI may have already provided this data */
315 if (!acpi_lapic)
Ingo Molnarc58603e2009-03-19 08:50:35 +0100316 MP_processor_info((struct mpc_cpu *)mpt);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530317 skip_entry(&mpt, &count, sizeof(struct mpc_cpu));
318 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400319 case MP_BUS:
Ingo Molnarc58603e2009-03-19 08:50:35 +0100320 MP_bus_info((struct mpc_bus *)mpt);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530321 skip_entry(&mpt, &count, sizeof(struct mpc_bus));
322 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400323 case MP_IOAPIC:
Ingo Molnarc58603e2009-03-19 08:50:35 +0100324 MP_ioapic_info((struct mpc_ioapic *)mpt);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530325 skip_entry(&mpt, &count, sizeof(struct mpc_ioapic));
326 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400327 case MP_INTSRC:
Ingo Molnarc58603e2009-03-19 08:50:35 +0100328 MP_intsrc_info((struct mpc_intsrc *)mpt);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530329 skip_entry(&mpt, &count, sizeof(struct mpc_intsrc));
330 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400331 case MP_LINTSRC:
Ingo Molnarc58603e2009-03-19 08:50:35 +0100332 MP_lintsrc_info((struct mpc_lintsrc *)mpt);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530333 skip_entry(&mpt, &count, sizeof(struct mpc_lintsrc));
334 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400335 default:
Yinghai Lu711554d2008-04-07 11:36:39 -0700336 /* wrong mptable */
Jaswinder Singh Rajput5a5737e2009-03-21 13:28:39 +0530337 smp_dump_mptable(mpc, mpt);
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530338 count = mpc->length;
Yinghai Lu711554d2008-04-07 11:36:39 -0700339 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 }
Thomas Gleixnerf4848472009-08-20 12:05:01 +0200341 x86_init.mpparse.mpc_record(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 }
Yinghai Lue0da3362008-06-08 18:29:22 -0700343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 if (!num_processors)
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400345 printk(KERN_ERR "MPTABLE: no processors registered!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 return num_processors;
347}
348
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400349#ifdef CONFIG_X86_IO_APIC
350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351static int __init ELCR_trigger(unsigned int irq)
352{
353 unsigned int port;
354
355 port = 0x4d0 + (irq >> 3);
356 return (inb(port) >> (irq & 7)) & 1;
357}
358
359static void __init construct_default_ioirq_mptable(int mpc_default_type)
360{
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530361 struct mpc_intsrc intsrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 int i;
363 int ELCR_fallback = 0;
364
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530365 intsrc.type = MP_INTSRC;
366 intsrc.irqflag = 0; /* conforming */
367 intsrc.srcbus = 0;
Jaswinder Singh Rajputb5ba7e62009-01-12 17:46:17 +0530368 intsrc.dstapic = mp_ioapics[0].apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530370 intsrc.irqtype = mp_INT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
372 /*
373 * If true, we have an ISA/PCI system with no IRQ entries
374 * in the MP table. To prevent the PCI interrupts from being set up
375 * incorrectly, we try to use the ELCR. The sanity check to see if
376 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
377 * never be level sensitive, so we simply see if the ELCR agrees.
378 * If it does, we assume it's valid.
379 */
380 if (mpc_default_type == 5) {
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400381 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
382 "falling back to ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400384 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
385 ELCR_trigger(13))
386 printk(KERN_ERR "ELCR contains invalid data... "
387 "not using ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 else {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400389 printk(KERN_INFO
390 "Using ELCR to identify PCI interrupts\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 ELCR_fallback = 1;
392 }
393 }
394
395 for (i = 0; i < 16; i++) {
396 switch (mpc_default_type) {
397 case 2:
398 if (i == 0 || i == 13)
399 continue; /* IRQ0 & IRQ13 not connected */
400 /* fall through */
401 default:
402 if (i == 2)
403 continue; /* IRQ2 is never connected */
404 }
405
406 if (ELCR_fallback) {
407 /*
408 * If the ELCR indicates a level-sensitive interrupt, we
409 * copy that information over to the MP table in the
410 * irqflag field (level sensitive, active high polarity).
411 */
412 if (ELCR_trigger(i))
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530413 intsrc.irqflag = 13;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 else
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530415 intsrc.irqflag = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 }
417
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530418 intsrc.srcbusirq = i;
419 intsrc.dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 MP_intsrc_info(&intsrc);
421 }
422
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530423 intsrc.irqtype = mp_ExtINT;
424 intsrc.srcbusirq = 0;
425 intsrc.dstirq = 0; /* 8259A to INTIN0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 MP_intsrc_info(&intsrc);
427}
428
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400429
Marcin Slusarz39e00fe2008-08-11 00:09:38 +0200430static void __init construct_ioapic_table(int mpc_default_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431{
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530432 struct mpc_ioapic ioapic;
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +0530433 struct mpc_bus bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530435 bus.type = MP_BUS;
436 bus.busid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 switch (mpc_default_type) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400438 default:
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400439 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400440 mpc_default_type);
441 /* fall through */
442 case 1:
443 case 5:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530444 memcpy(bus.bustype, "ISA ", 6);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400445 break;
446 case 2:
447 case 6:
448 case 3:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530449 memcpy(bus.bustype, "EISA ", 6);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400450 break;
451 case 4:
452 case 7:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530453 memcpy(bus.bustype, "MCA ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 }
455 MP_bus_info(&bus);
456 if (mpc_default_type > 4) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530457 bus.busid = 1;
458 memcpy(bus.bustype, "PCI ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 MP_bus_info(&bus);
460 }
461
Cyrill Gorcunov8f3e1df2009-08-24 21:53:36 +0400462 ioapic.type = MP_IOAPIC;
463 ioapic.apicid = 2;
464 ioapic.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
465 ioapic.flags = MPC_APIC_USABLE;
466 ioapic.apicaddr = IO_APIC_DEFAULT_PHYS_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 MP_ioapic_info(&ioapic);
468
469 /*
470 * We set up most of the low 16 IO-APIC pins according to MPS rules.
471 */
472 construct_default_ioirq_mptable(mpc_default_type);
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200473}
474#else
Marcin Slusarz39e00fe2008-08-11 00:09:38 +0200475static inline void __init construct_ioapic_table(int mpc_default_type) { }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400476#endif
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200477
478static inline void __init construct_default_ISA_mptable(int mpc_default_type)
479{
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +0530480 struct mpc_cpu processor;
Jaswinder Singh Rajput8fb29522009-01-03 15:51:54 +0530481 struct mpc_lintsrc lintsrc;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200482 int linttypes[2] = { mp_ExtINT, mp_NMI };
483 int i;
484
485 /*
486 * local APIC has default address
487 */
488 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
489
490 /*
491 * 2 CPUs, numbered 0 & 1.
492 */
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530493 processor.type = MP_PROCESSOR;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200494 /* Either an integrated APIC or a discrete 82489DX. */
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530495 processor.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
496 processor.cpuflag = CPU_ENABLED;
497 processor.cpufeature = (boot_cpu_data.x86 << 8) |
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200498 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530499 processor.featureflag = boot_cpu_data.x86_capability[0];
500 processor.reserved[0] = 0;
501 processor.reserved[1] = 0;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200502 for (i = 0; i < 2; i++) {
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530503 processor.apicid = i;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200504 MP_processor_info(&processor);
505 }
506
507 construct_ioapic_table(mpc_default_type);
508
Jaswinder Singh Rajputb5ced7c2009-01-04 21:55:53 +0530509 lintsrc.type = MP_LINTSRC;
510 lintsrc.irqflag = 0; /* conforming */
511 lintsrc.srcbusid = 0;
512 lintsrc.srcbusirq = 0;
513 lintsrc.destapic = MP_APIC_ALL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 for (i = 0; i < 2; i++) {
Jaswinder Singh Rajputb5ced7c2009-01-04 21:55:53 +0530515 lintsrc.irqtype = linttypes[i];
516 lintsrc.destapiclint = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 MP_lintsrc_info(&lintsrc);
518 }
519}
520
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530521static struct mpf_intel *mpf_found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
Yinghai Lu8d4dd9192009-03-04 01:25:21 -0800523static unsigned long __init get_mpc_size(unsigned long physptr)
524{
525 struct mpc_table *mpc;
526 unsigned long size;
527
528 mpc = early_ioremap(physptr, PAGE_SIZE);
529 size = mpc->length;
530 early_iounmap(mpc, PAGE_SIZE);
531 apic_printk(APIC_VERBOSE, " mpc: %lx-%lx\n", physptr, physptr + size);
532
533 return size;
534}
535
Jaswinder Singh Rajput0b3ba0c2009-03-21 13:43:20 +0530536static int __init check_physptr(struct mpf_intel *mpf, unsigned int early)
537{
538 struct mpc_table *mpc;
539 unsigned long size;
540
541 size = get_mpc_size(mpf->physptr);
542 mpc = early_ioremap(mpf->physptr, size);
543 /*
544 * Read the physical hardware table. Anything here will
545 * override the defaults.
546 */
547 if (!smp_read_mpc(mpc, early)) {
548#ifdef CONFIG_X86_LOCAL_APIC
549 smp_found_config = 0;
550#endif
551 printk(KERN_ERR "BIOS bug, MP table errors detected!...\n"
552 "... disabling SMP support. (tell your hw vendor)\n");
553 early_iounmap(mpc, size);
554 return -1;
555 }
556 early_iounmap(mpc, size);
557
558 if (early)
559 return -1;
560
561#ifdef CONFIG_X86_IO_APIC
562 /*
563 * If there are no explicit MP IRQ entries, then we are
564 * broken. We set up most of the low 16 IO-APIC pins to
565 * ISA defaults and hope it will work.
566 */
567 if (!mp_irq_entries) {
568 struct mpc_bus bus;
569
570 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
571 "using default mptable. (tell your hw vendor)\n");
572
573 bus.type = MP_BUS;
574 bus.busid = 0;
575 memcpy(bus.bustype, "ISA ", 6);
576 MP_bus_info(&bus);
577
578 construct_default_ioirq_mptable(0);
579 }
580#endif
581
582 return 0;
583}
584
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585/*
586 * Scan the memory blocks for an SMP configuration block.
587 */
Thomas Gleixnerb3f1b612009-08-20 11:11:52 +0200588void __init default_get_smp_config(unsigned int early)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589{
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530590 struct mpf_intel *mpf = mpf_found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
Yinghai Lu69b88af2008-12-05 22:45:50 -0800592 if (!mpf)
593 return;
594
595 if (acpi_lapic && early)
596 return;
597
598 /*
599 * MPS doesn't support hyperthreading, aka only have
600 * thread 0 apic id in MPS table
601 */
602 if (acpi_lapic && acpi_ioapic)
603 return;
604
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400605 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530606 mpf->specification);
Alexey Starikovskiyb3e24162008-05-23 01:54:44 +0400607#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530608 if (mpf->feature2 & (1 << 7)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
610 pic_mode = 1;
611 } else {
612 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
613 pic_mode = 0;
614 }
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400615#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 /*
617 * Now see if we need to read further.
618 */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530619 if (mpf->feature1 != 0) {
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400620 if (early) {
621 /*
622 * local APIC has default address
623 */
624 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
625 return;
626 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400628 printk(KERN_INFO "Default MP configuration #%d\n",
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530629 mpf->feature1);
630 construct_default_ISA_mptable(mpf->feature1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530632 } else if (mpf->physptr) {
Jaswinder Singh Rajput0b3ba0c2009-03-21 13:43:20 +0530633 if (check_physptr(mpf, early))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 } else
636 BUG();
637
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400638 if (!early)
639 printk(KERN_INFO "Processors: %d\n", num_processors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 /*
641 * Only use the first configuration found.
642 */
643}
644
Yinghai Lub24c2a92009-11-24 02:48:18 -0800645static void __init smp_reserve_memory(struct mpf_intel *mpf)
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530646{
647 unsigned long size = get_mpc_size(mpf->physptr);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530648
Yinghai Lu72d7c3b2010-08-25 13:39:17 -0700649 memblock_x86_reserve_range(mpf->physptr, mpf->physptr+size, "* MP-table mpc");
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530650}
651
Yinghai Lub24c2a92009-11-24 02:48:18 -0800652static int __init smp_scan_config(unsigned long base, unsigned long length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653{
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400654 unsigned int *bp = phys_to_virt(base);
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530655 struct mpf_intel *mpf;
Yinghai Lub24c2a92009-11-24 02:48:18 -0800656 unsigned long mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200658 apic_printk(APIC_VERBOSE, "Scan SMP from %p for %ld bytes.\n",
659 bp, length);
Akinobu Mita5d47a272008-04-19 23:55:11 +0900660 BUILD_BUG_ON(sizeof(*mpf) != 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
662 while (length > 0) {
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530663 mpf = (struct mpf_intel *)bp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 if ((*bp == SMP_MAGIC_IDENT) &&
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530665 (mpf->length == 1) &&
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400666 !mpf_checksum((unsigned char *)bp, 16) &&
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530667 ((mpf->specification == 1)
668 || (mpf->specification == 4))) {
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400669#ifdef CONFIG_X86_LOCAL_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 smp_found_config = 1;
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400671#endif
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400672 mpf_found = mpf;
Yinghai Lub1f006b2008-06-09 18:11:36 -0700673
Jaswinder Singh Rajputba1511b2009-02-11 23:38:25 +0530674 printk(KERN_INFO "found SMP MP-table at [%p] %llx\n",
675 mpf, (u64)virt_to_phys(mpf));
Yinghai Lub1f006b2008-06-09 18:11:36 -0700676
Yinghai Lub24c2a92009-11-24 02:48:18 -0800677 mem = virt_to_phys(mpf);
Yinghai Lu72d7c3b2010-08-25 13:39:17 -0700678 memblock_x86_reserve_range(mem, mem + sizeof(*mpf), "* MP-table mpf");
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530679 if (mpf->physptr)
Yinghai Lub24c2a92009-11-24 02:48:18 -0800680 smp_reserve_memory(mpf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
Yinghai Lud2dbf342008-06-13 02:00:56 -0700682 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 }
684 bp += 4;
685 length -= 16;
686 }
687 return 0;
688}
689
Yinghai Lub24c2a92009-11-24 02:48:18 -0800690void __init default_find_smp_config(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691{
692 unsigned int address;
693
694 /*
695 * FIXME: Linux assumes you have 640K of base ram..
696 * this continues the error...
697 *
698 * 1) Scan the bottom 1K for a signature
699 * 2) Scan the top 1K of base RAM
700 * 3) Scan the 64K of bios
701 */
Yinghai Lub24c2a92009-11-24 02:48:18 -0800702 if (smp_scan_config(0x0, 0x400) ||
703 smp_scan_config(639 * 0x400, 0x400) ||
704 smp_scan_config(0xF0000, 0x10000))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 return;
706 /*
707 * If it is an SMP machine we should know now, unless the
708 * configuration is in an EISA/MCA bus machine with an
709 * extended bios data area.
710 *
711 * there is a real-mode segmented pointer pointing to the
712 * 4K EBDA area at 0x40E, calculate and scan it here.
713 *
714 * NOTE! There are Linux loaders that will corrupt the EBDA
715 * area, and as such this kind of SMP config may be less
716 * trustworthy, simply because the SMP table may have been
717 * stomped on during early boot. These loaders are buggy and
718 * should be fixed.
719 *
720 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
721 */
722
723 address = get_bios_ebda();
724 if (address)
Yinghai Lub24c2a92009-11-24 02:48:18 -0800725 smp_scan_config(address, 0x400);
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400726}
727
Yinghai Lu2944e162008-06-01 13:17:38 -0700728#ifdef CONFIG_X86_IO_APIC
729static u8 __initdata irq_used[MAX_IRQ_SOURCES];
730
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530731static int __init get_MP_intsrc_index(struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700732{
733 int i;
734
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530735 if (m->irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700736 return 0;
737
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530738 if (m->irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700739 return 0;
740
741 /* not legacy */
742
743 for (i = 0; i < mp_irq_entries; i++) {
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530744 if (mp_irqs[i].irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700745 continue;
746
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530747 if (mp_irqs[i].irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700748 continue;
749
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530750 if (mp_irqs[i].srcbus != m->srcbus)
Yinghai Lu2944e162008-06-01 13:17:38 -0700751 continue;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530752 if (mp_irqs[i].srcbusirq != m->srcbusirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700753 continue;
754 if (irq_used[i]) {
755 /* already claimed */
756 return -2;
757 }
758 irq_used[i] = 1;
759 return i;
760 }
761
762 /* not found */
763 return -1;
764}
765
766#define SPARE_SLOT_NUM 20
767
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530768static struct mpc_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530769
Rakib Mullick57592222009-04-11 09:04:59 +0600770static void __init check_irq_src(struct mpc_intsrc *m, int *nr_m_spare)
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530771{
772 int i;
773
774 apic_printk(APIC_VERBOSE, "OLD ");
775 print_MP_intsrc_info(m);
776
777 i = get_MP_intsrc_index(m);
778 if (i > 0) {
779 assign_to_mpc_intsrc(&mp_irqs[i], m);
780 apic_printk(APIC_VERBOSE, "NEW ");
781 print_mp_irq_info(&mp_irqs[i]);
782 return;
783 }
784 if (!i) {
785 /* legacy, do nothing */
786 return;
787 }
788 if (*nr_m_spare < SPARE_SLOT_NUM) {
789 /*
790 * not found (-1), or duplicated (-2) are invalid entries,
791 * we need to use the slot later
792 */
793 m_spare[*nr_m_spare] = m;
794 *nr_m_spare += 1;
795 }
796}
797#else /* CONFIG_X86_IO_APIC */
Rakib Mullick57592222009-04-11 09:04:59 +0600798static
799inline void __init check_irq_src(struct mpc_intsrc *m, int *nr_m_spare) {}
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530800#endif /* CONFIG_X86_IO_APIC */
801
Yinghai Luee214552009-05-06 10:07:07 -0700802static int
803check_slot(unsigned long mpc_new_phys, unsigned long mpc_new_length, int count)
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530804{
Yinghai Luee214552009-05-06 10:07:07 -0700805 int ret = 0;
806
807 if (!mpc_new_phys || count <= mpc_new_length) {
808 WARN(1, "update_mptable: No spare slots (length: %x)\n", count);
809 return -1;
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530810 }
811
Yinghai Luee214552009-05-06 10:07:07 -0700812 return ret;
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530813}
Yinghai Lu2944e162008-06-01 13:17:38 -0700814
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530815static int __init replace_intsrc_all(struct mpc_table *mpc,
Yinghai Lu2944e162008-06-01 13:17:38 -0700816 unsigned long mpc_new_phys,
817 unsigned long mpc_new_length)
818{
819#ifdef CONFIG_X86_IO_APIC
820 int i;
Yinghai Lu2944e162008-06-01 13:17:38 -0700821#endif
Yinghai Lu2944e162008-06-01 13:17:38 -0700822 int count = sizeof(*mpc);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530823 int nr_m_spare = 0;
Yinghai Lu2944e162008-06-01 13:17:38 -0700824 unsigned char *mpt = ((unsigned char *)mpc) + count;
825
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530826 printk(KERN_INFO "mpc_length %x\n", mpc->length);
827 while (count < mpc->length) {
Yinghai Lu2944e162008-06-01 13:17:38 -0700828 switch (*mpt) {
829 case MP_PROCESSOR:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530830 skip_entry(&mpt, &count, sizeof(struct mpc_cpu));
831 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700832 case MP_BUS:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530833 skip_entry(&mpt, &count, sizeof(struct mpc_bus));
834 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700835 case MP_IOAPIC:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530836 skip_entry(&mpt, &count, sizeof(struct mpc_ioapic));
837 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700838 case MP_INTSRC:
Ingo Molnarc58603e2009-03-19 08:50:35 +0100839 check_irq_src((struct mpc_intsrc *)mpt, &nr_m_spare);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530840 skip_entry(&mpt, &count, sizeof(struct mpc_intsrc));
841 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700842 case MP_LINTSRC:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530843 skip_entry(&mpt, &count, sizeof(struct mpc_lintsrc));
844 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700845 default:
846 /* wrong mptable */
Jaswinder Singh Rajput5a5737e2009-03-21 13:28:39 +0530847 smp_dump_mptable(mpc, mpt);
Yinghai Lu2944e162008-06-01 13:17:38 -0700848 goto out;
849 }
850 }
851
852#ifdef CONFIG_X86_IO_APIC
853 for (i = 0; i < mp_irq_entries; i++) {
854 if (irq_used[i])
855 continue;
856
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530857 if (mp_irqs[i].irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700858 continue;
859
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530860 if (mp_irqs[i].irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700861 continue;
862
863 if (nr_m_spare > 0) {
Jan Beulich82034d62009-03-12 12:57:10 +0000864 apic_printk(APIC_VERBOSE, "*NEW* found\n");
Yinghai Lu2944e162008-06-01 13:17:38 -0700865 nr_m_spare--;
866 assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
867 m_spare[nr_m_spare] = NULL;
868 } else {
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530869 struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
870 count += sizeof(struct mpc_intsrc);
Yinghai Luee214552009-05-06 10:07:07 -0700871 if (check_slot(mpc_new_phys, mpc_new_length, count) < 0)
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530872 goto out;
Yinghai Lu2944e162008-06-01 13:17:38 -0700873 assign_to_mpc_intsrc(&mp_irqs[i], m);
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530874 mpc->length = count;
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530875 mpt += sizeof(struct mpc_intsrc);
Yinghai Lu2944e162008-06-01 13:17:38 -0700876 }
877 print_mp_irq_info(&mp_irqs[i]);
878 }
879#endif
880out:
881 /* update checksum */
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530882 mpc->checksum = 0;
883 mpc->checksum -= mpf_checksum((unsigned char *)mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -0700884
885 return 0;
886}
887
Yinghai Luf1bdb522009-05-15 13:05:16 -0700888int enable_update_mptable;
Yinghai Lufcfa1462008-06-18 17:29:31 -0700889
Yinghai Lu2944e162008-06-01 13:17:38 -0700890static int __init update_mptable_setup(char *str)
891{
892 enable_update_mptable = 1;
Yinghai Lu629e15d2009-05-15 13:05:16 -0700893#ifdef CONFIG_PCI
894 pci_routeirq = 1;
895#endif
Yinghai Lu2944e162008-06-01 13:17:38 -0700896 return 0;
897}
898early_param("update_mptable", update_mptable_setup);
899
900static unsigned long __initdata mpc_new_phys;
901static unsigned long mpc_new_length __initdata = 4096;
902
903/* alloc_mptable or alloc_mptable=4k */
904static int __initdata alloc_mptable;
905static int __init parse_alloc_mptable_opt(char *p)
906{
907 enable_update_mptable = 1;
Yinghai Lu629e15d2009-05-15 13:05:16 -0700908#ifdef CONFIG_PCI
909 pci_routeirq = 1;
910#endif
Yinghai Lu2944e162008-06-01 13:17:38 -0700911 alloc_mptable = 1;
912 if (!p)
913 return 0;
914 mpc_new_length = memparse(p, &p);
915 return 0;
916}
917early_param("alloc_mptable", parse_alloc_mptable_opt);
918
919void __init early_reserve_e820_mpc_new(void)
920{
921 if (enable_update_mptable && alloc_mptable) {
922 u64 startt = 0;
Yinghai Lu2944e162008-06-01 13:17:38 -0700923 mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
924 }
925}
926
927static int __init update_mp_table(void)
928{
929 char str[16];
930 char oem[10];
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530931 struct mpf_intel *mpf;
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530932 struct mpc_table *mpc, *mpc_new;
Yinghai Lu2944e162008-06-01 13:17:38 -0700933
934 if (!enable_update_mptable)
935 return 0;
936
937 mpf = mpf_found;
938 if (!mpf)
939 return 0;
940
941 /*
942 * Now see if we need to go further.
943 */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530944 if (mpf->feature1 != 0)
Yinghai Lu2944e162008-06-01 13:17:38 -0700945 return 0;
946
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530947 if (!mpf->physptr)
Yinghai Lu2944e162008-06-01 13:17:38 -0700948 return 0;
949
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530950 mpc = phys_to_virt(mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -0700951
952 if (!smp_check_mpc(mpc, oem, str))
953 return 0;
954
Jaswinder Singh Rajputba1511b2009-02-11 23:38:25 +0530955 printk(KERN_INFO "mpf: %llx\n", (u64)virt_to_phys(mpf));
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530956 printk(KERN_INFO "physptr: %x\n", mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -0700957
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530958 if (mpc_new_phys && mpc->length > mpc_new_length) {
Yinghai Lu2944e162008-06-01 13:17:38 -0700959 mpc_new_phys = 0;
960 printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
961 mpc_new_length);
962 }
963
964 if (!mpc_new_phys) {
965 unsigned char old, new;
966 /* check if we can change the postion */
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530967 mpc->checksum = 0;
968 old = mpf_checksum((unsigned char *)mpc, mpc->length);
969 mpc->checksum = 0xff;
970 new = mpf_checksum((unsigned char *)mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -0700971 if (old == new) {
972 printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
973 return 0;
974 }
975 printk(KERN_INFO "use in-positon replacing\n");
976 } else {
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530977 mpf->physptr = mpc_new_phys;
Yinghai Lu2944e162008-06-01 13:17:38 -0700978 mpc_new = phys_to_virt(mpc_new_phys);
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530979 memcpy(mpc_new, mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -0700980 mpc = mpc_new;
981 /* check if we can modify that */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530982 if (mpc_new_phys - mpf->physptr) {
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530983 struct mpf_intel *mpf_new;
Yinghai Lu2944e162008-06-01 13:17:38 -0700984 /* steal 16 bytes from [0, 1k) */
985 printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
986 mpf_new = phys_to_virt(0x400 - 16);
987 memcpy(mpf_new, mpf, 16);
988 mpf = mpf_new;
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530989 mpf->physptr = mpc_new_phys;
Yinghai Lu2944e162008-06-01 13:17:38 -0700990 }
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530991 mpf->checksum = 0;
992 mpf->checksum -= mpf_checksum((unsigned char *)mpf, 16);
993 printk(KERN_INFO "physptr new: %x\n", mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -0700994 }
995
996 /*
997 * only replace the one with mp_INT and
998 * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
999 * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
1000 * may need pci=routeirq for all coverage
1001 */
1002 replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
1003
1004 return 0;
1005}
1006
1007late_initcall(update_mp_table);