blob: a42f23f1dc7e0c4985f32aaacdd763226879c376 [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
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300118static int bad_ioapic(unsigned long address)
119{
120 if (nr_ioapics >= MAX_IO_APICS) {
121 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
122 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
123 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
124 }
125 if (!address) {
126 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
127 " found in table, skipping!\n");
128 return 1;
129 }
130 return 0;
131}
132
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530133static void __init MP_ioapic_info(struct mpc_ioapic *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134{
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530135 if (!(m->flags & MPC_APIC_USABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 return;
137
Thomas Gleixner64883ab2008-01-30 13:30:35 +0100138 printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530139 m->apicid, m->apicver, m->apicaddr);
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300140
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530141 if (bad_ioapic(m->apicaddr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 return;
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300143
Jaswinder Singh Rajputb5ba7e62009-01-12 17:46:17 +0530144 mp_ioapics[nr_ioapics].apicaddr = m->apicaddr;
145 mp_ioapics[nr_ioapics].apicid = m->apicid;
146 mp_ioapics[nr_ioapics].type = m->type;
147 mp_ioapics[nr_ioapics].apicver = m->apicver;
148 mp_ioapics[nr_ioapics].flags = m->flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 nr_ioapics++;
150}
151
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530152static void print_MP_intsrc_info(struct mpc_intsrc *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200154 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530156 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbus,
157 m->srcbusirq, m->dstapic, m->dstirq);
Yinghai Lu2944e162008-06-01 13:17:38 -0700158}
159
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530160static void __init print_mp_irq_info(struct mpc_intsrc *mp_irq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700161{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200162 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
Yinghai Lu2944e162008-06-01 13:17:38 -0700163 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530164 mp_irq->irqtype, mp_irq->irqflag & 3,
165 (mp_irq->irqflag >> 2) & 3, mp_irq->srcbus,
166 mp_irq->srcbusirq, mp_irq->dstapic, mp_irq->dstirq);
Yinghai Lu2944e162008-06-01 13:17:38 -0700167}
168
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530169static void __init assign_to_mp_irq(struct mpc_intsrc *m,
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530170 struct mpc_intsrc *mp_irq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700171{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530172 mp_irq->dstapic = m->dstapic;
173 mp_irq->type = m->type;
174 mp_irq->irqtype = m->irqtype;
175 mp_irq->irqflag = m->irqflag;
176 mp_irq->srcbus = m->srcbus;
177 mp_irq->srcbusirq = m->srcbusirq;
178 mp_irq->dstirq = m->dstirq;
Yinghai Lu2944e162008-06-01 13:17:38 -0700179}
180
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530181static void __init assign_to_mpc_intsrc(struct mpc_intsrc *mp_irq,
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530182 struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700183{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530184 m->dstapic = mp_irq->dstapic;
185 m->type = mp_irq->type;
186 m->irqtype = mp_irq->irqtype;
187 m->irqflag = mp_irq->irqflag;
188 m->srcbus = mp_irq->srcbus;
189 m->srcbusirq = mp_irq->srcbusirq;
190 m->dstirq = mp_irq->dstirq;
Yinghai Lu2944e162008-06-01 13:17:38 -0700191}
192
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530193static int __init mp_irq_mpc_intsrc_cmp(struct mpc_intsrc *mp_irq,
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530194 struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700195{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530196 if (mp_irq->dstapic != m->dstapic)
Yinghai Lu2944e162008-06-01 13:17:38 -0700197 return 1;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530198 if (mp_irq->type != m->type)
Yinghai Lu2944e162008-06-01 13:17:38 -0700199 return 2;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530200 if (mp_irq->irqtype != m->irqtype)
Yinghai Lu2944e162008-06-01 13:17:38 -0700201 return 3;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530202 if (mp_irq->irqflag != m->irqflag)
Yinghai Lu2944e162008-06-01 13:17:38 -0700203 return 4;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530204 if (mp_irq->srcbus != m->srcbus)
Yinghai Lu2944e162008-06-01 13:17:38 -0700205 return 5;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530206 if (mp_irq->srcbusirq != m->srcbusirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700207 return 6;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530208 if (mp_irq->dstirq != m->dstirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700209 return 7;
210
211 return 0;
212}
213
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530214static void __init MP_intsrc_info(struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700215{
216 int i;
217
218 print_MP_intsrc_info(m);
219
Yinghai Lufcfa1462008-06-18 17:29:31 -0700220 for (i = 0; i < mp_irq_entries; i++) {
221 if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m))
222 return;
223 }
Yinghai Lu2944e162008-06-01 13:17:38 -0700224
225 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 if (++mp_irq_entries == MAX_IRQ_SOURCES)
227 panic("Max # of irq sources exceeded!!\n");
228}
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530229#else /* CONFIG_X86_IO_APIC */
230static inline void __init MP_bus_info(struct mpc_bus *m) {}
231static inline void __init MP_ioapic_info(struct mpc_ioapic *m) {}
232static inline void __init MP_intsrc_info(struct mpc_intsrc *m) {}
233#endif /* CONFIG_X86_IO_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400235
Jaswinder Singh Rajput8fb29522009-01-03 15:51:54 +0530236static void __init MP_lintsrc_info(struct mpc_lintsrc *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200238 apic_printk(APIC_VERBOSE, "Lint: type %d, pol %d, trig %d, bus %02x,"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
Jaswinder Singh Rajputb5ced7c2009-01-04 21:55:53 +0530240 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbusid,
241 m->srcbusirq, m->destapic, m->destapiclint);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242}
243
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244/*
245 * Read/parse the MPC
246 */
247
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530248static int __init smp_check_mpc(struct mpc_table *mpc, char *oem, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530251 if (memcmp(mpc->signature, MPC_SIGNATURE, 4)) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400252 printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530253 mpc->signature[0], mpc->signature[1],
254 mpc->signature[2], mpc->signature[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 return 0;
256 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530257 if (mpf_checksum((unsigned char *)mpc, mpc->length)) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400258 printk(KERN_ERR "MPTABLE: checksum error!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 return 0;
260 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530261 if (mpc->spec != 0x01 && mpc->spec != 0x04) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400262 printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530263 mpc->spec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 return 0;
265 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530266 if (!mpc->lapic) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400267 printk(KERN_ERR "MPTABLE: null local APIC address!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 return 0;
269 }
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530270 memcpy(oem, mpc->oem, 8);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400271 oem[8] = 0;
Yinghai Lu11a62a02008-05-12 15:43:38 +0200272 printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530274 memcpy(str, mpc->productid, 12);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400275 str[12] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Yinghai Lu11a62a02008-05-12 15:43:38 +0200277 printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530279 printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->lapic);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
Yinghai Lu2944e162008-06-01 13:17:38 -0700281 return 1;
282}
283
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530284static void skip_entry(unsigned char **ptr, int *count, int size)
285{
286 *ptr += size;
287 *count += size;
288}
289
Jaswinder Singh Rajput5a5737e2009-03-21 13:28:39 +0530290static void __init smp_dump_mptable(struct mpc_table *mpc, unsigned char *mpt)
291{
292 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n"
293 "type %x\n", *mpt);
294 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
295 1, mpc, mpc->length, 1);
296}
297
Thomas Gleixner72302142009-08-20 12:18:32 +0200298void __init default_smp_read_mpc_oem(struct mpc_table *mpc) { }
299
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530300static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early)
Yinghai Lu2944e162008-06-01 13:17:38 -0700301{
302 char str[16];
303 char oem[10];
304
305 int count = sizeof(*mpc);
306 unsigned char *mpt = ((unsigned char *)mpc) + count;
307
308 if (!smp_check_mpc(mpc, oem, str))
309 return 0;
310
311#ifdef CONFIG_X86_32
Ingo Molnar9c764242009-01-28 13:44:32 +0100312 generic_mps_oem_check(mpc, oem, str);
Yinghai Lu2944e162008-06-01 13:17:38 -0700313#endif
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400314 /* save the local APIC address, it might be non-default */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 if (!acpi_lapic)
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530316 mp_lapic_addr = mpc->lapic;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400318 if (early)
319 return 1;
320
Thomas Gleixner72302142009-08-20 12:18:32 +0200321 if (mpc->oemptr)
322 x86_init.mpparse.smp_read_mpc_oem(mpc);
Yinghai Lu64898a82008-07-19 18:01:16 -0700323
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 /*
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400325 * Now process the configuration blocks.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 */
Thomas Gleixnerf4848472009-08-20 12:05:01 +0200327 x86_init.mpparse.mpc_record(0);
Yinghai Lu64898a82008-07-19 18:01:16 -0700328
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530329 while (count < mpc->length) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400330 switch (*mpt) {
331 case MP_PROCESSOR:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530332 /* ACPI may have already provided this data */
333 if (!acpi_lapic)
Ingo Molnarc58603e2009-03-19 08:50:35 +0100334 MP_processor_info((struct mpc_cpu *)mpt);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530335 skip_entry(&mpt, &count, sizeof(struct mpc_cpu));
336 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400337 case MP_BUS:
Ingo Molnarc58603e2009-03-19 08:50:35 +0100338 MP_bus_info((struct mpc_bus *)mpt);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530339 skip_entry(&mpt, &count, sizeof(struct mpc_bus));
340 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400341 case MP_IOAPIC:
Ingo Molnarc58603e2009-03-19 08:50:35 +0100342 MP_ioapic_info((struct mpc_ioapic *)mpt);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530343 skip_entry(&mpt, &count, sizeof(struct mpc_ioapic));
344 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400345 case MP_INTSRC:
Ingo Molnarc58603e2009-03-19 08:50:35 +0100346 MP_intsrc_info((struct mpc_intsrc *)mpt);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530347 skip_entry(&mpt, &count, sizeof(struct mpc_intsrc));
348 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400349 case MP_LINTSRC:
Ingo Molnarc58603e2009-03-19 08:50:35 +0100350 MP_lintsrc_info((struct mpc_lintsrc *)mpt);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530351 skip_entry(&mpt, &count, sizeof(struct mpc_lintsrc));
352 break;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400353 default:
Yinghai Lu711554d2008-04-07 11:36:39 -0700354 /* wrong mptable */
Jaswinder Singh Rajput5a5737e2009-03-21 13:28:39 +0530355 smp_dump_mptable(mpc, mpt);
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530356 count = mpc->length;
Yinghai Lu711554d2008-04-07 11:36:39 -0700357 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 }
Thomas Gleixnerf4848472009-08-20 12:05:01 +0200359 x86_init.mpparse.mpc_record(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 }
Yinghai Lue0da3362008-06-08 18:29:22 -0700361
Yinghai Lu26f7ef12009-01-29 14:19:22 -0800362#ifdef CONFIG_X86_BIGSMP
363 generic_bigsmp_probe();
Yinghai Lue0da3362008-06-08 18:29:22 -0700364#endif
365
Ingo Molnar72ce0162009-01-28 06:50:47 +0100366 if (apic->setup_apic_routing)
367 apic->setup_apic_routing();
368
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 if (!num_processors)
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400370 printk(KERN_ERR "MPTABLE: no processors registered!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 return num_processors;
372}
373
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400374#ifdef CONFIG_X86_IO_APIC
375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376static int __init ELCR_trigger(unsigned int irq)
377{
378 unsigned int port;
379
380 port = 0x4d0 + (irq >> 3);
381 return (inb(port) >> (irq & 7)) & 1;
382}
383
384static void __init construct_default_ioirq_mptable(int mpc_default_type)
385{
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530386 struct mpc_intsrc intsrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 int i;
388 int ELCR_fallback = 0;
389
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530390 intsrc.type = MP_INTSRC;
391 intsrc.irqflag = 0; /* conforming */
392 intsrc.srcbus = 0;
Jaswinder Singh Rajputb5ba7e62009-01-12 17:46:17 +0530393 intsrc.dstapic = mp_ioapics[0].apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530395 intsrc.irqtype = mp_INT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
397 /*
398 * If true, we have an ISA/PCI system with no IRQ entries
399 * in the MP table. To prevent the PCI interrupts from being set up
400 * incorrectly, we try to use the ELCR. The sanity check to see if
401 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
402 * never be level sensitive, so we simply see if the ELCR agrees.
403 * If it does, we assume it's valid.
404 */
405 if (mpc_default_type == 5) {
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400406 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
407 "falling back to ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400409 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
410 ELCR_trigger(13))
411 printk(KERN_ERR "ELCR contains invalid data... "
412 "not using ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 else {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400414 printk(KERN_INFO
415 "Using ELCR to identify PCI interrupts\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 ELCR_fallback = 1;
417 }
418 }
419
420 for (i = 0; i < 16; i++) {
421 switch (mpc_default_type) {
422 case 2:
423 if (i == 0 || i == 13)
424 continue; /* IRQ0 & IRQ13 not connected */
425 /* fall through */
426 default:
427 if (i == 2)
428 continue; /* IRQ2 is never connected */
429 }
430
431 if (ELCR_fallback) {
432 /*
433 * If the ELCR indicates a level-sensitive interrupt, we
434 * copy that information over to the MP table in the
435 * irqflag field (level sensitive, active high polarity).
436 */
437 if (ELCR_trigger(i))
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530438 intsrc.irqflag = 13;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 else
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530440 intsrc.irqflag = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 }
442
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530443 intsrc.srcbusirq = i;
444 intsrc.dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 MP_intsrc_info(&intsrc);
446 }
447
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530448 intsrc.irqtype = mp_ExtINT;
449 intsrc.srcbusirq = 0;
450 intsrc.dstirq = 0; /* 8259A to INTIN0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 MP_intsrc_info(&intsrc);
452}
453
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400454
Marcin Slusarz39e00fe2008-08-11 00:09:38 +0200455static void __init construct_ioapic_table(int mpc_default_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456{
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530457 struct mpc_ioapic ioapic;
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +0530458 struct mpc_bus bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530460 bus.type = MP_BUS;
461 bus.busid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 switch (mpc_default_type) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400463 default:
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400464 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400465 mpc_default_type);
466 /* fall through */
467 case 1:
468 case 5:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530469 memcpy(bus.bustype, "ISA ", 6);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400470 break;
471 case 2:
472 case 6:
473 case 3:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530474 memcpy(bus.bustype, "EISA ", 6);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400475 break;
476 case 4:
477 case 7:
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530478 memcpy(bus.bustype, "MCA ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 }
480 MP_bus_info(&bus);
481 if (mpc_default_type > 4) {
Jaswinder Singh Rajputd4c715f2009-01-04 21:59:26 +0530482 bus.busid = 1;
483 memcpy(bus.bustype, "PCI ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 MP_bus_info(&bus);
485 }
486
Jaswinder Singh Rajput5df82c72009-01-04 21:54:39 +0530487 ioapic.type = MP_IOAPIC;
488 ioapic.apicid = 2;
489 ioapic.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
490 ioapic.flags = MPC_APIC_USABLE;
491 ioapic.apicaddr = 0xFEC00000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 MP_ioapic_info(&ioapic);
493
494 /*
495 * We set up most of the low 16 IO-APIC pins according to MPS rules.
496 */
497 construct_default_ioirq_mptable(mpc_default_type);
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200498}
499#else
Marcin Slusarz39e00fe2008-08-11 00:09:38 +0200500static inline void __init construct_ioapic_table(int mpc_default_type) { }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400501#endif
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200502
503static inline void __init construct_default_ISA_mptable(int mpc_default_type)
504{
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +0530505 struct mpc_cpu processor;
Jaswinder Singh Rajput8fb29522009-01-03 15:51:54 +0530506 struct mpc_lintsrc lintsrc;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200507 int linttypes[2] = { mp_ExtINT, mp_NMI };
508 int i;
509
510 /*
511 * local APIC has default address
512 */
513 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
514
515 /*
516 * 2 CPUs, numbered 0 & 1.
517 */
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530518 processor.type = MP_PROCESSOR;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200519 /* Either an integrated APIC or a discrete 82489DX. */
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530520 processor.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
521 processor.cpuflag = CPU_ENABLED;
522 processor.cpufeature = (boot_cpu_data.x86 << 8) |
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200523 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530524 processor.featureflag = boot_cpu_data.x86_capability[0];
525 processor.reserved[0] = 0;
526 processor.reserved[1] = 0;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200527 for (i = 0; i < 2; i++) {
Jaswinder Singh Rajputc4563822009-01-04 21:58:25 +0530528 processor.apicid = i;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200529 MP_processor_info(&processor);
530 }
531
532 construct_ioapic_table(mpc_default_type);
533
Jaswinder Singh Rajputb5ced7c2009-01-04 21:55:53 +0530534 lintsrc.type = MP_LINTSRC;
535 lintsrc.irqflag = 0; /* conforming */
536 lintsrc.srcbusid = 0;
537 lintsrc.srcbusirq = 0;
538 lintsrc.destapic = MP_APIC_ALL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 for (i = 0; i < 2; i++) {
Jaswinder Singh Rajputb5ced7c2009-01-04 21:55:53 +0530540 lintsrc.irqtype = linttypes[i];
541 lintsrc.destapiclint = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 MP_lintsrc_info(&lintsrc);
543 }
544}
545
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530546static struct mpf_intel *mpf_found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
Yinghai Lu8d4dd912009-03-04 01:25:21 -0800548static unsigned long __init get_mpc_size(unsigned long physptr)
549{
550 struct mpc_table *mpc;
551 unsigned long size;
552
553 mpc = early_ioremap(physptr, PAGE_SIZE);
554 size = mpc->length;
555 early_iounmap(mpc, PAGE_SIZE);
556 apic_printk(APIC_VERBOSE, " mpc: %lx-%lx\n", physptr, physptr + size);
557
558 return size;
559}
560
Jaswinder Singh Rajput0b3ba0c2009-03-21 13:43:20 +0530561static int __init check_physptr(struct mpf_intel *mpf, unsigned int early)
562{
563 struct mpc_table *mpc;
564 unsigned long size;
565
566 size = get_mpc_size(mpf->physptr);
567 mpc = early_ioremap(mpf->physptr, size);
568 /*
569 * Read the physical hardware table. Anything here will
570 * override the defaults.
571 */
572 if (!smp_read_mpc(mpc, early)) {
573#ifdef CONFIG_X86_LOCAL_APIC
574 smp_found_config = 0;
575#endif
576 printk(KERN_ERR "BIOS bug, MP table errors detected!...\n"
577 "... disabling SMP support. (tell your hw vendor)\n");
578 early_iounmap(mpc, size);
579 return -1;
580 }
581 early_iounmap(mpc, size);
582
583 if (early)
584 return -1;
585
586#ifdef CONFIG_X86_IO_APIC
587 /*
588 * If there are no explicit MP IRQ entries, then we are
589 * broken. We set up most of the low 16 IO-APIC pins to
590 * ISA defaults and hope it will work.
591 */
592 if (!mp_irq_entries) {
593 struct mpc_bus bus;
594
595 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
596 "using default mptable. (tell your hw vendor)\n");
597
598 bus.type = MP_BUS;
599 bus.busid = 0;
600 memcpy(bus.bustype, "ISA ", 6);
601 MP_bus_info(&bus);
602
603 construct_default_ioirq_mptable(0);
604 }
605#endif
606
607 return 0;
608}
609
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610/*
611 * Scan the memory blocks for an SMP configuration block.
612 */
Ingo Molnar3b335532008-07-10 17:30:40 +0200613static void __init __get_smp_config(unsigned int early)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614{
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530615 struct mpf_intel *mpf = mpf_found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
Yinghai Lu69b88af2008-12-05 22:45:50 -0800617 if (!mpf)
618 return;
619
620 if (acpi_lapic && early)
621 return;
622
623 /*
624 * MPS doesn't support hyperthreading, aka only have
625 * thread 0 apic id in MPS table
626 */
627 if (acpi_lapic && acpi_ioapic)
628 return;
629
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700630 if (x86_quirks->mach_get_smp_config) {
631 if (x86_quirks->mach_get_smp_config(early))
Ingo Molnar3b335532008-07-10 17:30:40 +0200632 return;
633 }
Andi Kleen9adc1382008-12-04 13:33:35 +0100634
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400635 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530636 mpf->specification);
Alexey Starikovskiyb3e24162008-05-23 01:54:44 +0400637#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530638 if (mpf->feature2 & (1 << 7)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
640 pic_mode = 1;
641 } else {
642 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
643 pic_mode = 0;
644 }
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400645#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 /*
647 * Now see if we need to read further.
648 */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530649 if (mpf->feature1 != 0) {
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400650 if (early) {
651 /*
652 * local APIC has default address
653 */
654 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
655 return;
656 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400658 printk(KERN_INFO "Default MP configuration #%d\n",
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530659 mpf->feature1);
660 construct_default_ISA_mptable(mpf->feature1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530662 } else if (mpf->physptr) {
Jaswinder Singh Rajput0b3ba0c2009-03-21 13:43:20 +0530663 if (check_physptr(mpf, early))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 } else
666 BUG();
667
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400668 if (!early)
669 printk(KERN_INFO "Processors: %d\n", num_processors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 /*
671 * Only use the first configuration found.
672 */
673}
674
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400675void __init early_get_smp_config(void)
676{
677 __get_smp_config(1);
678}
679
680void __init get_smp_config(void)
681{
682 __get_smp_config(0);
683}
684
Rakib Mullick57592222009-04-11 09:04:59 +0600685static void __init smp_reserve_bootmem(struct mpf_intel *mpf)
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530686{
687 unsigned long size = get_mpc_size(mpf->physptr);
688#ifdef CONFIG_X86_32
689 /*
690 * We cannot access to MPC table to compute table size yet,
691 * as only few megabytes from the bottom is mapped now.
692 * PC-9800's MPC table places on the very last of physical
693 * memory; so that simply reserving PAGE_SIZE from mpf->physptr
694 * yields BUG() in reserve_bootmem.
695 * also need to make sure physptr is below than max_low_pfn
696 * we don't need reserve the area above max_low_pfn
697 */
698 unsigned long end = max_low_pfn * PAGE_SIZE;
699
700 if (mpf->physptr < end) {
701 if (mpf->physptr + size > end)
702 size = end - mpf->physptr;
703 reserve_bootmem_generic(mpf->physptr, size, BOOTMEM_DEFAULT);
704 }
705#else
706 reserve_bootmem_generic(mpf->physptr, size, BOOTMEM_DEFAULT);
707#endif
708}
709
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400710static int __init smp_scan_config(unsigned long base, unsigned long length,
711 unsigned reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712{
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400713 unsigned int *bp = phys_to_virt(base);
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530714 struct mpf_intel *mpf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200716 apic_printk(APIC_VERBOSE, "Scan SMP from %p for %ld bytes.\n",
717 bp, length);
Akinobu Mita5d47a272008-04-19 23:55:11 +0900718 BUILD_BUG_ON(sizeof(*mpf) != 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
720 while (length > 0) {
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +0530721 mpf = (struct mpf_intel *)bp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 if ((*bp == SMP_MAGIC_IDENT) &&
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530723 (mpf->length == 1) &&
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400724 !mpf_checksum((unsigned char *)bp, 16) &&
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +0530725 ((mpf->specification == 1)
726 || (mpf->specification == 4))) {
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400727#ifdef CONFIG_X86_LOCAL_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 smp_found_config = 1;
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400729#endif
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400730 mpf_found = mpf;
Yinghai Lub1f006b2008-06-09 18:11:36 -0700731
Jaswinder Singh Rajputba1511b2009-02-11 23:38:25 +0530732 printk(KERN_INFO "found SMP MP-table at [%p] %llx\n",
733 mpf, (u64)virt_to_phys(mpf));
Yinghai Lub1f006b2008-06-09 18:11:36 -0700734
735 if (!reserve)
736 return 1;
Yinghai Luf6243232009-03-04 01:25:54 -0800737 reserve_bootmem_generic(virt_to_phys(mpf), sizeof(*mpf),
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800738 BOOTMEM_DEFAULT);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530739 if (mpf->physptr)
740 smp_reserve_bootmem(mpf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
Yinghai Lud2dbf342008-06-13 02:00:56 -0700742 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 }
744 bp += 4;
745 length -= 16;
746 }
747 return 0;
748}
749
Ingo Molnar3b335532008-07-10 17:30:40 +0200750static void __init __find_smp_config(unsigned int reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751{
752 unsigned int address;
753
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700754 if (x86_quirks->mach_find_smp_config) {
755 if (x86_quirks->mach_find_smp_config(reserve))
Ingo Molnar3b335532008-07-10 17:30:40 +0200756 return;
757 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 /*
759 * FIXME: Linux assumes you have 640K of base ram..
760 * this continues the error...
761 *
762 * 1) Scan the bottom 1K for a signature
763 * 2) Scan the top 1K of base RAM
764 * 3) Scan the 64K of bios
765 */
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400766 if (smp_scan_config(0x0, 0x400, reserve) ||
767 smp_scan_config(639 * 0x400, 0x400, reserve) ||
768 smp_scan_config(0xF0000, 0x10000, reserve))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 return;
770 /*
771 * If it is an SMP machine we should know now, unless the
772 * configuration is in an EISA/MCA bus machine with an
773 * extended bios data area.
774 *
775 * there is a real-mode segmented pointer pointing to the
776 * 4K EBDA area at 0x40E, calculate and scan it here.
777 *
778 * NOTE! There are Linux loaders that will corrupt the EBDA
779 * area, and as such this kind of SMP config may be less
780 * trustworthy, simply because the SMP table may have been
781 * stomped on during early boot. These loaders are buggy and
782 * should be fixed.
783 *
784 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
785 */
786
787 address = get_bios_ebda();
788 if (address)
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400789 smp_scan_config(address, 0x400, reserve);
790}
791
792void __init early_find_smp_config(void)
793{
794 __find_smp_config(0);
795}
796
797void __init find_smp_config(void)
798{
799 __find_smp_config(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800}
Yinghai Lu2944e162008-06-01 13:17:38 -0700801
802#ifdef CONFIG_X86_IO_APIC
803static u8 __initdata irq_used[MAX_IRQ_SOURCES];
804
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530805static int __init get_MP_intsrc_index(struct mpc_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700806{
807 int i;
808
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530809 if (m->irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700810 return 0;
811
Jaswinder Singh Rajpute253b392009-01-04 21:56:44 +0530812 if (m->irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700813 return 0;
814
815 /* not legacy */
816
817 for (i = 0; i < mp_irq_entries; i++) {
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530818 if (mp_irqs[i].irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700819 continue;
820
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530821 if (mp_irqs[i].irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700822 continue;
823
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530824 if (mp_irqs[i].srcbus != m->srcbus)
Yinghai Lu2944e162008-06-01 13:17:38 -0700825 continue;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530826 if (mp_irqs[i].srcbusirq != m->srcbusirq)
Yinghai Lu2944e162008-06-01 13:17:38 -0700827 continue;
828 if (irq_used[i]) {
829 /* already claimed */
830 return -2;
831 }
832 irq_used[i] = 1;
833 return i;
834 }
835
836 /* not found */
837 return -1;
838}
839
840#define SPARE_SLOT_NUM 20
841
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530842static struct mpc_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530843
Rakib Mullick57592222009-04-11 09:04:59 +0600844static void __init check_irq_src(struct mpc_intsrc *m, int *nr_m_spare)
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530845{
846 int i;
847
848 apic_printk(APIC_VERBOSE, "OLD ");
849 print_MP_intsrc_info(m);
850
851 i = get_MP_intsrc_index(m);
852 if (i > 0) {
853 assign_to_mpc_intsrc(&mp_irqs[i], m);
854 apic_printk(APIC_VERBOSE, "NEW ");
855 print_mp_irq_info(&mp_irqs[i]);
856 return;
857 }
858 if (!i) {
859 /* legacy, do nothing */
860 return;
861 }
862 if (*nr_m_spare < SPARE_SLOT_NUM) {
863 /*
864 * not found (-1), or duplicated (-2) are invalid entries,
865 * we need to use the slot later
866 */
867 m_spare[*nr_m_spare] = m;
868 *nr_m_spare += 1;
869 }
870}
871#else /* CONFIG_X86_IO_APIC */
Rakib Mullick57592222009-04-11 09:04:59 +0600872static
873inline void __init check_irq_src(struct mpc_intsrc *m, int *nr_m_spare) {}
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530874#endif /* CONFIG_X86_IO_APIC */
875
Yinghai Luee214552009-05-06 10:07:07 -0700876static int
877check_slot(unsigned long mpc_new_phys, unsigned long mpc_new_length, int count)
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530878{
Yinghai Luee214552009-05-06 10:07:07 -0700879 int ret = 0;
880
881 if (!mpc_new_phys || count <= mpc_new_length) {
882 WARN(1, "update_mptable: No spare slots (length: %x)\n", count);
883 return -1;
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530884 }
885
Yinghai Luee214552009-05-06 10:07:07 -0700886 return ret;
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530887}
Yinghai Lu2944e162008-06-01 13:17:38 -0700888
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530889static int __init replace_intsrc_all(struct mpc_table *mpc,
Yinghai Lu2944e162008-06-01 13:17:38 -0700890 unsigned long mpc_new_phys,
891 unsigned long mpc_new_length)
892{
893#ifdef CONFIG_X86_IO_APIC
894 int i;
Yinghai Lu2944e162008-06-01 13:17:38 -0700895#endif
Yinghai Lu2944e162008-06-01 13:17:38 -0700896 int count = sizeof(*mpc);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530897 int nr_m_spare = 0;
Yinghai Lu2944e162008-06-01 13:17:38 -0700898 unsigned char *mpt = ((unsigned char *)mpc) + count;
899
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530900 printk(KERN_INFO "mpc_length %x\n", mpc->length);
901 while (count < mpc->length) {
Yinghai Lu2944e162008-06-01 13:17:38 -0700902 switch (*mpt) {
903 case MP_PROCESSOR:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530904 skip_entry(&mpt, &count, sizeof(struct mpc_cpu));
905 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700906 case MP_BUS:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530907 skip_entry(&mpt, &count, sizeof(struct mpc_bus));
908 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700909 case MP_IOAPIC:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530910 skip_entry(&mpt, &count, sizeof(struct mpc_ioapic));
911 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700912 case MP_INTSRC:
Ingo Molnarc58603e2009-03-19 08:50:35 +0100913 check_irq_src((struct mpc_intsrc *)mpt, &nr_m_spare);
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530914 skip_entry(&mpt, &count, sizeof(struct mpc_intsrc));
915 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700916 case MP_LINTSRC:
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530917 skip_entry(&mpt, &count, sizeof(struct mpc_lintsrc));
918 break;
Yinghai Lu2944e162008-06-01 13:17:38 -0700919 default:
920 /* wrong mptable */
Jaswinder Singh Rajput5a5737e2009-03-21 13:28:39 +0530921 smp_dump_mptable(mpc, mpt);
Yinghai Lu2944e162008-06-01 13:17:38 -0700922 goto out;
923 }
924 }
925
926#ifdef CONFIG_X86_IO_APIC
927 for (i = 0; i < mp_irq_entries; i++) {
928 if (irq_used[i])
929 continue;
930
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530931 if (mp_irqs[i].irqtype != mp_INT)
Yinghai Lu2944e162008-06-01 13:17:38 -0700932 continue;
933
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530934 if (mp_irqs[i].irqflag != 0x0f)
Yinghai Lu2944e162008-06-01 13:17:38 -0700935 continue;
936
937 if (nr_m_spare > 0) {
Jan Beulich82034d62009-03-12 12:57:10 +0000938 apic_printk(APIC_VERBOSE, "*NEW* found\n");
Yinghai Lu2944e162008-06-01 13:17:38 -0700939 nr_m_spare--;
940 assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
941 m_spare[nr_m_spare] = NULL;
942 } else {
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530943 struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
944 count += sizeof(struct mpc_intsrc);
Yinghai Luee214552009-05-06 10:07:07 -0700945 if (check_slot(mpc_new_phys, mpc_new_length, count) < 0)
Jaswinder Singh Rajputa6830272009-03-18 20:42:28 +0530946 goto out;
Yinghai Lu2944e162008-06-01 13:17:38 -0700947 assign_to_mpc_intsrc(&mp_irqs[i], m);
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530948 mpc->length = count;
Jaswinder Singh Rajput540d4e72009-01-03 15:50:52 +0530949 mpt += sizeof(struct mpc_intsrc);
Yinghai Lu2944e162008-06-01 13:17:38 -0700950 }
951 print_mp_irq_info(&mp_irqs[i]);
952 }
953#endif
954out:
955 /* update checksum */
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +0530956 mpc->checksum = 0;
957 mpc->checksum -= mpf_checksum((unsigned char *)mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -0700958
959 return 0;
960}
961
Yinghai Luf1bdb522009-05-15 13:05:16 -0700962int enable_update_mptable;
Yinghai Lufcfa1462008-06-18 17:29:31 -0700963
Yinghai Lu2944e162008-06-01 13:17:38 -0700964static int __init update_mptable_setup(char *str)
965{
966 enable_update_mptable = 1;
Yinghai Lu629e15d2009-05-15 13:05:16 -0700967#ifdef CONFIG_PCI
968 pci_routeirq = 1;
969#endif
Yinghai Lu2944e162008-06-01 13:17:38 -0700970 return 0;
971}
972early_param("update_mptable", update_mptable_setup);
973
974static unsigned long __initdata mpc_new_phys;
975static unsigned long mpc_new_length __initdata = 4096;
976
977/* alloc_mptable or alloc_mptable=4k */
978static int __initdata alloc_mptable;
979static int __init parse_alloc_mptable_opt(char *p)
980{
981 enable_update_mptable = 1;
Yinghai Lu629e15d2009-05-15 13:05:16 -0700982#ifdef CONFIG_PCI
983 pci_routeirq = 1;
984#endif
Yinghai Lu2944e162008-06-01 13:17:38 -0700985 alloc_mptable = 1;
986 if (!p)
987 return 0;
988 mpc_new_length = memparse(p, &p);
989 return 0;
990}
991early_param("alloc_mptable", parse_alloc_mptable_opt);
992
993void __init early_reserve_e820_mpc_new(void)
994{
995 if (enable_update_mptable && alloc_mptable) {
996 u64 startt = 0;
997#ifdef CONFIG_X86_TRAMPOLINE
998 startt = TRAMPOLINE_BASE;
999#endif
1000 mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
1001 }
1002}
1003
1004static int __init update_mp_table(void)
1005{
1006 char str[16];
1007 char oem[10];
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +05301008 struct mpf_intel *mpf;
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +05301009 struct mpc_table *mpc, *mpc_new;
Yinghai Lu2944e162008-06-01 13:17:38 -07001010
1011 if (!enable_update_mptable)
1012 return 0;
1013
1014 mpf = mpf_found;
1015 if (!mpf)
1016 return 0;
1017
1018 /*
1019 * Now see if we need to go further.
1020 */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301021 if (mpf->feature1 != 0)
Yinghai Lu2944e162008-06-01 13:17:38 -07001022 return 0;
1023
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301024 if (!mpf->physptr)
Yinghai Lu2944e162008-06-01 13:17:38 -07001025 return 0;
1026
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301027 mpc = phys_to_virt(mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -07001028
1029 if (!smp_check_mpc(mpc, oem, str))
1030 return 0;
1031
Jaswinder Singh Rajputba1511b2009-02-11 23:38:25 +05301032 printk(KERN_INFO "mpf: %llx\n", (u64)virt_to_phys(mpf));
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301033 printk(KERN_INFO "physptr: %x\n", mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -07001034
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +05301035 if (mpc_new_phys && mpc->length > mpc_new_length) {
Yinghai Lu2944e162008-06-01 13:17:38 -07001036 mpc_new_phys = 0;
1037 printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
1038 mpc_new_length);
1039 }
1040
1041 if (!mpc_new_phys) {
1042 unsigned char old, new;
1043 /* check if we can change the postion */
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +05301044 mpc->checksum = 0;
1045 old = mpf_checksum((unsigned char *)mpc, mpc->length);
1046 mpc->checksum = 0xff;
1047 new = mpf_checksum((unsigned char *)mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -07001048 if (old == new) {
1049 printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
1050 return 0;
1051 }
1052 printk(KERN_INFO "use in-positon replacing\n");
1053 } else {
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301054 mpf->physptr = mpc_new_phys;
Yinghai Lu2944e162008-06-01 13:17:38 -07001055 mpc_new = phys_to_virt(mpc_new_phys);
Jaswinder Singh Rajput6c65da52009-01-04 22:22:56 +05301056 memcpy(mpc_new, mpc, mpc->length);
Yinghai Lu2944e162008-06-01 13:17:38 -07001057 mpc = mpc_new;
1058 /* check if we can modify that */
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301059 if (mpc_new_phys - mpf->physptr) {
Jaswinder Singh Rajput41401db2009-01-08 15:42:46 +05301060 struct mpf_intel *mpf_new;
Yinghai Lu2944e162008-06-01 13:17:38 -07001061 /* steal 16 bytes from [0, 1k) */
1062 printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
1063 mpf_new = phys_to_virt(0x400 - 16);
1064 memcpy(mpf_new, mpf, 16);
1065 mpf = mpf_new;
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301066 mpf->physptr = mpc_new_phys;
Yinghai Lu2944e162008-06-01 13:17:38 -07001067 }
Jaswinder Singh Rajput1eb1b3b2009-01-08 15:43:26 +05301068 mpf->checksum = 0;
1069 mpf->checksum -= mpf_checksum((unsigned char *)mpf, 16);
1070 printk(KERN_INFO "physptr new: %x\n", mpf->physptr);
Yinghai Lu2944e162008-06-01 13:17:38 -07001071 }
1072
1073 /*
1074 * only replace the one with mp_INT and
1075 * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
1076 * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
1077 * may need pci=routeirq for all coverage
1078 */
1079 replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
1080
1081 return 0;
1082}
1083
1084late_initcall(update_mp_table);