blob: 7ec4b0da98515f4227e53119a878053b275ade82 [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 *
5 * (c) 1995 Alan Cox, Building #3 <alan@redhat.com>
6 * (c) 1998, 1999, 2000 Ingo Molnar <mingo@redhat.com>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +04007 * (c) 2008 Alexey Starikovskiy <astarikovskiy@suse.de>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
9
10#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/bootmem.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/kernel_stat.h>
15#include <linux/mc146818rtc.h>
16#include <linux/bitops.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040017#include <linux/acpi.h>
18#include <linux/module.h>
Jaswinder Singh Rajput103ceff2009-01-02 23:43:25 +053019#include <linux/smp.h>
20#include <linux/acpi.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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32#include <mach_apic.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040033#ifdef CONFIG_X86_32
Andi Kleen874c4fe2006-09-26 10:52:26 +020034#include <mach_apicdef.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <mach_mpparse.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040036#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Linus Torvalds1da177e2005-04-16 15:20:36 -070038/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 * Checksum an MP configuration block.
40 */
41
42static int __init mpf_checksum(unsigned char *mp, int len)
43{
44 int sum = 0;
45
46 while (len--)
47 sum += *mp++;
48
49 return sum & 0xFF;
50}
51
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +053052static void __init MP_processor_info(struct mpc_cpu *m)
Alexey Starikovskiyc853c672008-03-27 23:54:13 +030053{
54 int apicid;
Alexey Starikovskiy746f2242008-04-04 23:42:15 +040055 char *bootup_cpu = "";
Alexey Starikovskiyc853c672008-03-27 23:54:13 +030056
Glauber Costa7b1292e2008-03-03 14:12:41 -030057 if (!(m->mpc_cpuflag & CPU_ENABLED)) {
58 disabled_cpus++;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 return;
Glauber Costa7b1292e2008-03-03 14:12:41 -030060 }
Yinghai Lu64898a82008-07-19 18:01:16 -070061
62 if (x86_quirks->mpc_apic_id)
63 apicid = x86_quirks->mpc_apic_id(m);
Yinghai Luab530e12008-06-03 10:25:54 -070064 else
65 apicid = m->mpc_apicid;
Yinghai Lu64898a82008-07-19 18:01:16 -070066
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
Alexey Starikovskiy746f2242008-04-04 23:42:15 +040068 bootup_cpu = " (Bootup-CPU)";
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 boot_cpu_physical_apicid = m->mpc_apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 }
71
Alexey Starikovskiy746f2242008-04-04 23:42:15 +040072 printk(KERN_INFO "Processor #%d%s\n", m->mpc_apicid, bootup_cpu);
Alexey Starikovskiyc853c672008-03-27 23:54:13 +030073 generic_processor_info(apicid, m->mpc_apicver);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074}
75
Thomas Gleixner85cc35f2008-05-25 21:21:36 +020076#ifdef CONFIG_X86_IO_APIC
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +053077static void __init MP_bus_info(struct mpc_bus *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078{
79 char str[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 memcpy(str, m->mpc_bustype, 6);
81 str[6] = 0;
82
Yinghai Lu64898a82008-07-19 18:01:16 -070083 if (x86_quirks->mpc_oem_bus_info)
84 x86_quirks->mpc_oem_bus_info(m, str);
85 else
Rene Hermaneeb0d7d2008-08-11 17:44:57 +020086 apic_printk(APIC_VERBOSE, "Bus #%d is %s\n", m->mpc_busid, str);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Andi Kleen5e4edbb2006-09-26 10:52:35 +020088#if MAX_MP_BUSSES < 256
Randy Dunlapc0ec31a2006-04-10 22:53:13 -070089 if (m->mpc_busid >= MAX_MP_BUSSES) {
90 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",
92 m->mpc_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 Rajput103ceff2009-01-02 23:43:25 +053098 set_bit(m->mpc_busid, mp_bus_not_pci);
99#if defined(CONFIG_EISA) || defined(CONFIG_MCA)
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +0400100 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA;
101#endif
102 } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
Yinghai Lu64898a82008-07-19 18:01:16 -0700103 if (x86_quirks->mpc_oem_pci_bus)
104 x86_quirks->mpc_oem_pci_bus(m);
105
Alexey Starikovskiya6333c32008-03-20 14:54:09 +0300106 clear_bit(m->mpc_busid, mp_bus_not_pci);
Jaswinder Singh Rajput103ceff2009-01-02 23:43:25 +0530107#if defined(CONFIG_EISA) || defined(CONFIG_MCA)
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +0300108 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400109 } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
Alexey Starikovskiy9e0a2de2008-03-20 14:54:56 +0300110 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400111 } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 mp_bus_id_to_type[m->mpc_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}
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200117#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400119#ifdef CONFIG_X86_IO_APIC
120
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300121static int bad_ioapic(unsigned long address)
122{
123 if (nr_ioapics >= MAX_IO_APICS) {
124 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
125 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
126 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
127 }
128 if (!address) {
129 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
130 " found in table, skipping!\n");
131 return 1;
132 }
133 return 0;
134}
135
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530136static void __init MP_ioapic_info(struct mpc_ioapic *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137{
138 if (!(m->mpc_flags & MPC_APIC_USABLE))
139 return;
140
Thomas Gleixner64883ab2008-01-30 13:30:35 +0100141 printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400142 m->mpc_apicid, m->mpc_apicver, m->mpc_apicaddr);
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300143
144 if (bad_ioapic(m->mpc_apicaddr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 return;
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300146
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400147 mp_ioapics[nr_ioapics].mp_apicaddr = m->mpc_apicaddr;
148 mp_ioapics[nr_ioapics].mp_apicid = m->mpc_apicid;
149 mp_ioapics[nr_ioapics].mp_type = m->mpc_type;
150 mp_ioapics[nr_ioapics].mp_apicver = m->mpc_apicver;
151 mp_ioapics[nr_ioapics].mp_flags = m->mpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 nr_ioapics++;
153}
154
Yinghai Lu2944e162008-06-01 13:17:38 -0700155static void print_MP_intsrc_info(struct mpc_config_intsrc *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200157 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400159 m->mpc_irqtype, m->mpc_irqflag & 3,
160 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
161 m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
Yinghai Lu2944e162008-06-01 13:17:38 -0700162}
163
164static void __init print_mp_irq_info(struct mp_config_intsrc *mp_irq)
165{
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200166 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
Yinghai Lu2944e162008-06-01 13:17:38 -0700167 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
168 mp_irq->mp_irqtype, mp_irq->mp_irqflag & 3,
169 (mp_irq->mp_irqflag >> 2) & 3, mp_irq->mp_srcbus,
170 mp_irq->mp_srcbusirq, mp_irq->mp_dstapic, mp_irq->mp_dstirq);
171}
172
Yinghai Lufcfa1462008-06-18 17:29:31 -0700173static void __init assign_to_mp_irq(struct mpc_config_intsrc *m,
Yinghai Lu2944e162008-06-01 13:17:38 -0700174 struct mp_config_intsrc *mp_irq)
175{
176 mp_irq->mp_dstapic = m->mpc_dstapic;
177 mp_irq->mp_type = m->mpc_type;
178 mp_irq->mp_irqtype = m->mpc_irqtype;
179 mp_irq->mp_irqflag = m->mpc_irqflag;
180 mp_irq->mp_srcbus = m->mpc_srcbus;
181 mp_irq->mp_srcbusirq = m->mpc_srcbusirq;
182 mp_irq->mp_dstirq = m->mpc_dstirq;
183}
184
185static void __init assign_to_mpc_intsrc(struct mp_config_intsrc *mp_irq,
186 struct mpc_config_intsrc *m)
187{
188 m->mpc_dstapic = mp_irq->mp_dstapic;
189 m->mpc_type = mp_irq->mp_type;
190 m->mpc_irqtype = mp_irq->mp_irqtype;
191 m->mpc_irqflag = mp_irq->mp_irqflag;
192 m->mpc_srcbus = mp_irq->mp_srcbus;
193 m->mpc_srcbusirq = mp_irq->mp_srcbusirq;
194 m->mpc_dstirq = mp_irq->mp_dstirq;
195}
196
Yinghai Lufcfa1462008-06-18 17:29:31 -0700197static int __init mp_irq_mpc_intsrc_cmp(struct mp_config_intsrc *mp_irq,
Yinghai Lu2944e162008-06-01 13:17:38 -0700198 struct mpc_config_intsrc *m)
199{
200 if (mp_irq->mp_dstapic != m->mpc_dstapic)
201 return 1;
202 if (mp_irq->mp_type != m->mpc_type)
203 return 2;
204 if (mp_irq->mp_irqtype != m->mpc_irqtype)
205 return 3;
206 if (mp_irq->mp_irqflag != m->mpc_irqflag)
207 return 4;
208 if (mp_irq->mp_srcbus != m->mpc_srcbus)
209 return 5;
210 if (mp_irq->mp_srcbusirq != m->mpc_srcbusirq)
211 return 6;
212 if (mp_irq->mp_dstirq != m->mpc_dstirq)
213 return 7;
214
215 return 0;
216}
217
Yinghai Lufcfa1462008-06-18 17:29:31 -0700218static void __init MP_intsrc_info(struct mpc_config_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700219{
220 int i;
221
222 print_MP_intsrc_info(m);
223
Yinghai Lufcfa1462008-06-18 17:29:31 -0700224 for (i = 0; i < mp_irq_entries; i++) {
225 if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m))
226 return;
227 }
Yinghai Lu2944e162008-06-01 13:17:38 -0700228
229 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 if (++mp_irq_entries == MAX_IRQ_SOURCES)
231 panic("Max # of irq sources exceeded!!\n");
232}
233
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400234#endif
235
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400236static void __init MP_lintsrc_info(struct mpc_config_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",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400240 m->mpc_irqtype, m->mpc_irqflag & 3,
241 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbusid,
242 m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243}
244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245/*
246 * Read/parse the MPC
247 */
248
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530249static int __init smp_check_mpc(struct mpc_table *mpc, char *oem, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400252 if (memcmp(mpc->mpc_signature, MPC_SIGNATURE, 4)) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400253 printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
254 mpc->mpc_signature[0], mpc->mpc_signature[1],
255 mpc->mpc_signature[2], mpc->mpc_signature[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 return 0;
257 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400258 if (mpf_checksum((unsigned char *)mpc, mpc->mpc_length)) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400259 printk(KERN_ERR "MPTABLE: checksum error!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 return 0;
261 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400262 if (mpc->mpc_spec != 0x01 && mpc->mpc_spec != 0x04) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400263 printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400264 mpc->mpc_spec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 return 0;
266 }
267 if (!mpc->mpc_lapic) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400268 printk(KERN_ERR "MPTABLE: null local APIC address!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 return 0;
270 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400271 memcpy(oem, mpc->mpc_oem, 8);
272 oem[8] = 0;
Yinghai Lu11a62a02008-05-12 15:43:38 +0200273 printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400275 memcpy(str, mpc->mpc_productid, 12);
276 str[12] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
Yinghai Lu11a62a02008-05-12 15:43:38 +0200278 printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400280 printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->mpc_lapic);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
Yinghai Lu2944e162008-06-01 13:17:38 -0700282 return 1;
283}
284
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530285static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early)
Yinghai Lu2944e162008-06-01 13:17:38 -0700286{
287 char str[16];
288 char oem[10];
289
290 int count = sizeof(*mpc);
291 unsigned char *mpt = ((unsigned char *)mpc) + count;
292
293 if (!smp_check_mpc(mpc, oem, str))
294 return 0;
295
296#ifdef CONFIG_X86_32
Yinghai Lud49c4282008-06-08 18:31:54 -0700297 /*
298 * need to make sure summit and es7000's mps_oem_check is safe to be
299 * called early via genericarch 's mps_oem_check
300 */
301 if (early) {
302#ifdef CONFIG_X86_NUMAQ
303 numaq_mps_oem_check(mpc, oem, str);
304#endif
305 } else
306 mps_oem_check(mpc, oem, str);
Yinghai Lu2944e162008-06-01 13:17:38 -0700307#endif
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400308 /* save the local APIC address, it might be non-default */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 if (!acpi_lapic)
310 mp_lapic_addr = mpc->mpc_lapic;
311
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400312 if (early)
313 return 1;
314
Yinghai Lu64898a82008-07-19 18:01:16 -0700315 if (mpc->mpc_oemptr && x86_quirks->smp_read_mpc_oem) {
316 struct mp_config_oemtable *oem_table = (struct mp_config_oemtable *)(unsigned long)mpc->mpc_oemptr;
317 x86_quirks->smp_read_mpc_oem(oem_table, mpc->mpc_oemsize);
318 }
319
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 /*
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400321 * Now process the configuration blocks.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 */
Yinghai Lu64898a82008-07-19 18:01:16 -0700323 if (x86_quirks->mpc_record)
324 *x86_quirks->mpc_record = 0;
325
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 while (count < mpc->mpc_length) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400327 switch (*mpt) {
328 case MP_PROCESSOR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 {
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +0530330 struct mpc_cpu *m = (struct mpc_cpu *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 /* ACPI may have already provided this data */
332 if (!acpi_lapic)
333 MP_processor_info(m);
334 mpt += sizeof(*m);
335 count += sizeof(*m);
336 break;
337 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400338 case MP_BUS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 {
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +0530340 struct mpc_bus *m = (struct mpc_bus *)mpt;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200341#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 MP_bus_info(m);
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200343#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 mpt += sizeof(*m);
345 count += sizeof(*m);
346 break;
347 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400348 case MP_IOAPIC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 {
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400350#ifdef CONFIG_X86_IO_APIC
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530351 struct mpc_ioapic *m = (struct mpc_ioapic *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 MP_ioapic_info(m);
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400353#endif
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530354 mpt += sizeof(struct mpc_ioapic);
355 count += sizeof(struct mpc_ioapic);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 break;
357 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400358 case MP_INTSRC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 {
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400360#ifdef CONFIG_X86_IO_APIC
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400361 struct mpc_config_intsrc *m =
362 (struct mpc_config_intsrc *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
364 MP_intsrc_info(m);
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400365#endif
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400366 mpt += sizeof(struct mpc_config_intsrc);
367 count += sizeof(struct mpc_config_intsrc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 break;
369 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400370 case MP_LINTSRC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400372 struct mpc_config_lintsrc *m =
373 (struct mpc_config_lintsrc *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 MP_lintsrc_info(m);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400375 mpt += sizeof(*m);
376 count += sizeof(*m);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 break;
378 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400379 default:
Yinghai Lu711554d2008-04-07 11:36:39 -0700380 /* wrong mptable */
381 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
382 printk(KERN_ERR "type %x\n", *mpt);
383 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
384 1, mpc, mpc->mpc_length, 1);
385 count = mpc->mpc_length;
386 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 }
Yinghai Lu64898a82008-07-19 18:01:16 -0700388 if (x86_quirks->mpc_record)
389 (*x86_quirks->mpc_record)++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 }
Yinghai Lue0da3362008-06-08 18:29:22 -0700391
392#ifdef CONFIG_X86_GENERICARCH
393 generic_bigsmp_probe();
394#endif
395
Suresh Siddha6e1cb382008-07-10 11:16:58 -0700396#ifdef CONFIG_X86_32
Ingo Molnar3c43f032007-05-02 19:27:04 +0200397 setup_apic_routing();
Suresh Siddha6e1cb382008-07-10 11:16:58 -0700398#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 if (!num_processors)
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400400 printk(KERN_ERR "MPTABLE: no processors registered!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 return num_processors;
402}
403
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400404#ifdef CONFIG_X86_IO_APIC
405
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406static int __init ELCR_trigger(unsigned int irq)
407{
408 unsigned int port;
409
410 port = 0x4d0 + (irq >> 3);
411 return (inb(port) >> (irq & 7)) & 1;
412}
413
414static void __init construct_default_ioirq_mptable(int mpc_default_type)
415{
416 struct mpc_config_intsrc intsrc;
417 int i;
418 int ELCR_fallback = 0;
419
420 intsrc.mpc_type = MP_INTSRC;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400421 intsrc.mpc_irqflag = 0; /* conforming */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 intsrc.mpc_srcbus = 0;
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400423 intsrc.mpc_dstapic = mp_ioapics[0].mp_apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
425 intsrc.mpc_irqtype = mp_INT;
426
427 /*
428 * If true, we have an ISA/PCI system with no IRQ entries
429 * in the MP table. To prevent the PCI interrupts from being set up
430 * incorrectly, we try to use the ELCR. The sanity check to see if
431 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
432 * never be level sensitive, so we simply see if the ELCR agrees.
433 * If it does, we assume it's valid.
434 */
435 if (mpc_default_type == 5) {
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400436 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
437 "falling back to ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400439 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
440 ELCR_trigger(13))
441 printk(KERN_ERR "ELCR contains invalid data... "
442 "not using ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 else {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400444 printk(KERN_INFO
445 "Using ELCR to identify PCI interrupts\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 ELCR_fallback = 1;
447 }
448 }
449
450 for (i = 0; i < 16; i++) {
451 switch (mpc_default_type) {
452 case 2:
453 if (i == 0 || i == 13)
454 continue; /* IRQ0 & IRQ13 not connected */
455 /* fall through */
456 default:
457 if (i == 2)
458 continue; /* IRQ2 is never connected */
459 }
460
461 if (ELCR_fallback) {
462 /*
463 * If the ELCR indicates a level-sensitive interrupt, we
464 * copy that information over to the MP table in the
465 * irqflag field (level sensitive, active high polarity).
466 */
467 if (ELCR_trigger(i))
468 intsrc.mpc_irqflag = 13;
469 else
470 intsrc.mpc_irqflag = 0;
471 }
472
473 intsrc.mpc_srcbusirq = i;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400474 intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 MP_intsrc_info(&intsrc);
476 }
477
478 intsrc.mpc_irqtype = mp_ExtINT;
479 intsrc.mpc_srcbusirq = 0;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400480 intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 MP_intsrc_info(&intsrc);
482}
483
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400484
Marcin Slusarz39e00fe2008-08-11 00:09:38 +0200485static void __init construct_ioapic_table(int mpc_default_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486{
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530487 struct mpc_ioapic ioapic;
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +0530488 struct mpc_bus bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
490 bus.mpc_type = MP_BUS;
491 bus.mpc_busid = 0;
492 switch (mpc_default_type) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400493 default:
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400494 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400495 mpc_default_type);
496 /* fall through */
497 case 1:
498 case 5:
499 memcpy(bus.mpc_bustype, "ISA ", 6);
500 break;
501 case 2:
502 case 6:
503 case 3:
504 memcpy(bus.mpc_bustype, "EISA ", 6);
505 break;
506 case 4:
507 case 7:
508 memcpy(bus.mpc_bustype, "MCA ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 }
510 MP_bus_info(&bus);
511 if (mpc_default_type > 4) {
512 bus.mpc_busid = 1;
513 memcpy(bus.mpc_bustype, "PCI ", 6);
514 MP_bus_info(&bus);
515 }
516
517 ioapic.mpc_type = MP_IOAPIC;
518 ioapic.mpc_apicid = 2;
519 ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
520 ioapic.mpc_flags = MPC_APIC_USABLE;
521 ioapic.mpc_apicaddr = 0xFEC00000;
522 MP_ioapic_info(&ioapic);
523
524 /*
525 * We set up most of the low 16 IO-APIC pins according to MPS rules.
526 */
527 construct_default_ioirq_mptable(mpc_default_type);
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200528}
529#else
Marcin Slusarz39e00fe2008-08-11 00:09:38 +0200530static inline void __init construct_ioapic_table(int mpc_default_type) { }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400531#endif
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200532
533static inline void __init construct_default_ISA_mptable(int mpc_default_type)
534{
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +0530535 struct mpc_cpu processor;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200536 struct mpc_config_lintsrc lintsrc;
537 int linttypes[2] = { mp_ExtINT, mp_NMI };
538 int i;
539
540 /*
541 * local APIC has default address
542 */
543 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
544
545 /*
546 * 2 CPUs, numbered 0 & 1.
547 */
548 processor.mpc_type = MP_PROCESSOR;
549 /* Either an integrated APIC or a discrete 82489DX. */
550 processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
551 processor.mpc_cpuflag = CPU_ENABLED;
552 processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
553 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
554 processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
555 processor.mpc_reserved[0] = 0;
556 processor.mpc_reserved[1] = 0;
557 for (i = 0; i < 2; i++) {
558 processor.mpc_apicid = i;
559 MP_processor_info(&processor);
560 }
561
562 construct_ioapic_table(mpc_default_type);
563
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 lintsrc.mpc_type = MP_LINTSRC;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400565 lintsrc.mpc_irqflag = 0; /* conforming */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 lintsrc.mpc_srcbusid = 0;
567 lintsrc.mpc_srcbusirq = 0;
568 lintsrc.mpc_destapic = MP_APIC_ALL;
569 for (i = 0; i < 2; i++) {
570 lintsrc.mpc_irqtype = linttypes[i];
571 lintsrc.mpc_destapiclint = i;
572 MP_lintsrc_info(&lintsrc);
573 }
574}
575
576static struct intel_mp_floating *mpf_found;
577
578/*
579 * Scan the memory blocks for an SMP configuration block.
580 */
Ingo Molnar3b335532008-07-10 17:30:40 +0200581static void __init __get_smp_config(unsigned int early)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582{
583 struct intel_mp_floating *mpf = mpf_found;
584
Yinghai Lu69b88af2008-12-05 22:45:50 -0800585 if (!mpf)
586 return;
587
588 if (acpi_lapic && early)
589 return;
590
591 /*
592 * MPS doesn't support hyperthreading, aka only have
593 * thread 0 apic id in MPS table
594 */
595 if (acpi_lapic && acpi_ioapic)
596 return;
597
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700598 if (x86_quirks->mach_get_smp_config) {
599 if (x86_quirks->mach_get_smp_config(early))
Ingo Molnar3b335532008-07-10 17:30:40 +0200600 return;
601 }
Andi Kleen9adc1382008-12-04 13:33:35 +0100602
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400603 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
604 mpf->mpf_specification);
Alexey Starikovskiyb3e24162008-05-23 01:54:44 +0400605#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400606 if (mpf->mpf_feature2 & (1 << 7)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
608 pic_mode = 1;
609 } else {
610 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
611 pic_mode = 0;
612 }
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400613#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 /*
615 * Now see if we need to read further.
616 */
617 if (mpf->mpf_feature1 != 0) {
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400618 if (early) {
619 /*
620 * local APIC has default address
621 */
622 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
623 return;
624 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400626 printk(KERN_INFO "Default MP configuration #%d\n",
627 mpf->mpf_feature1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 construct_default_ISA_mptable(mpf->mpf_feature1);
629
630 } else if (mpf->mpf_physptr) {
631
632 /*
633 * Read the physical hardware table. Anything here will
634 * override the defaults.
635 */
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400636 if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr), early)) {
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400637#ifdef CONFIG_X86_LOCAL_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 smp_found_config = 0;
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400639#endif
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400640 printk(KERN_ERR
641 "BIOS bug, MP table errors detected!...\n");
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400642 printk(KERN_ERR "... disabling SMP support. "
643 "(tell your hw vendor)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 return;
645 }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400646
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400647 if (early)
648 return;
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400649#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 /*
651 * If there are no explicit MP IRQ entries, then we are
652 * broken. We set up most of the low 16 IO-APIC pins to
653 * ISA defaults and hope it will work.
654 */
655 if (!mp_irq_entries) {
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +0530656 struct mpc_bus bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400658 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
659 "using default mptable. "
660 "(tell your hw vendor)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
662 bus.mpc_type = MP_BUS;
663 bus.mpc_busid = 0;
664 memcpy(bus.mpc_bustype, "ISA ", 6);
665 MP_bus_info(&bus);
666
667 construct_default_ioirq_mptable(0);
668 }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400669#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 } else
671 BUG();
672
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400673 if (!early)
674 printk(KERN_INFO "Processors: %d\n", num_processors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 /*
676 * Only use the first configuration found.
677 */
678}
679
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400680void __init early_get_smp_config(void)
681{
682 __get_smp_config(1);
683}
684
685void __init get_smp_config(void)
686{
687 __get_smp_config(0);
688}
689
690static int __init smp_scan_config(unsigned long base, unsigned long length,
691 unsigned reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692{
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400693 unsigned int *bp = phys_to_virt(base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 struct intel_mp_floating *mpf;
695
Rene Hermaneeb0d7d2008-08-11 17:44:57 +0200696 apic_printk(APIC_VERBOSE, "Scan SMP from %p for %ld bytes.\n",
697 bp, length);
Akinobu Mita5d47a272008-04-19 23:55:11 +0900698 BUILD_BUG_ON(sizeof(*mpf) != 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
700 while (length > 0) {
701 mpf = (struct intel_mp_floating *)bp;
702 if ((*bp == SMP_MAGIC_IDENT) &&
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400703 (mpf->mpf_length == 1) &&
704 !mpf_checksum((unsigned char *)bp, 16) &&
705 ((mpf->mpf_specification == 1)
706 || (mpf->mpf_specification == 4))) {
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400707#ifdef CONFIG_X86_LOCAL_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 smp_found_config = 1;
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400709#endif
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400710 mpf_found = mpf;
Yinghai Lub1f006b2008-06-09 18:11:36 -0700711
Ingo Molnare91a3b42008-01-30 13:33:08 +0100712 printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400713 mpf, virt_to_phys(mpf));
Yinghai Lub1f006b2008-06-09 18:11:36 -0700714
715 if (!reserve)
716 return 1;
Yinghai Lud2dbf342008-06-13 02:00:56 -0700717 reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE,
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800718 BOOTMEM_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 if (mpf->mpf_physptr) {
Yinghai Lud2dbf342008-06-13 02:00:56 -0700720 unsigned long size = PAGE_SIZE;
721#ifdef CONFIG_X86_32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 /*
723 * We cannot access to MPC table to compute
724 * table size yet, as only few megabytes from
725 * the bottom is mapped now.
726 * PC-9800's MPC table places on the very last
727 * of physical memory; so that simply reserving
728 * PAGE_SIZE from mpg->mpf_physptr yields BUG()
729 * in reserve_bootmem.
730 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 unsigned long end = max_low_pfn * PAGE_SIZE;
732 if (mpf->mpf_physptr + size > end)
733 size = end - mpf->mpf_physptr;
Yinghai Lud2dbf342008-06-13 02:00:56 -0700734#endif
735 reserve_bootmem_generic(mpf->mpf_physptr, size,
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800736 BOOTMEM_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 }
738
Yinghai Lud2dbf342008-06-13 02:00:56 -0700739 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 }
741 bp += 4;
742 length -= 16;
743 }
744 return 0;
745}
746
Ingo Molnar3b335532008-07-10 17:30:40 +0200747static void __init __find_smp_config(unsigned int reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748{
749 unsigned int address;
750
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700751 if (x86_quirks->mach_find_smp_config) {
752 if (x86_quirks->mach_find_smp_config(reserve))
Ingo Molnar3b335532008-07-10 17:30:40 +0200753 return;
754 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 /*
756 * FIXME: Linux assumes you have 640K of base ram..
757 * this continues the error...
758 *
759 * 1) Scan the bottom 1K for a signature
760 * 2) Scan the top 1K of base RAM
761 * 3) Scan the 64K of bios
762 */
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400763 if (smp_scan_config(0x0, 0x400, reserve) ||
764 smp_scan_config(639 * 0x400, 0x400, reserve) ||
765 smp_scan_config(0xF0000, 0x10000, reserve))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 return;
767 /*
768 * If it is an SMP machine we should know now, unless the
769 * configuration is in an EISA/MCA bus machine with an
770 * extended bios data area.
771 *
772 * there is a real-mode segmented pointer pointing to the
773 * 4K EBDA area at 0x40E, calculate and scan it here.
774 *
775 * NOTE! There are Linux loaders that will corrupt the EBDA
776 * area, and as such this kind of SMP config may be less
777 * trustworthy, simply because the SMP table may have been
778 * stomped on during early boot. These loaders are buggy and
779 * should be fixed.
780 *
781 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
782 */
783
784 address = get_bios_ebda();
785 if (address)
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400786 smp_scan_config(address, 0x400, reserve);
787}
788
789void __init early_find_smp_config(void)
790{
791 __find_smp_config(0);
792}
793
794void __init find_smp_config(void)
795{
796 __find_smp_config(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797}
Yinghai Lu2944e162008-06-01 13:17:38 -0700798
799#ifdef CONFIG_X86_IO_APIC
800static u8 __initdata irq_used[MAX_IRQ_SOURCES];
801
802static int __init get_MP_intsrc_index(struct mpc_config_intsrc *m)
803{
804 int i;
805
806 if (m->mpc_irqtype != mp_INT)
807 return 0;
808
809 if (m->mpc_irqflag != 0x0f)
810 return 0;
811
812 /* not legacy */
813
814 for (i = 0; i < mp_irq_entries; i++) {
815 if (mp_irqs[i].mp_irqtype != mp_INT)
816 continue;
817
818 if (mp_irqs[i].mp_irqflag != 0x0f)
819 continue;
820
821 if (mp_irqs[i].mp_srcbus != m->mpc_srcbus)
822 continue;
823 if (mp_irqs[i].mp_srcbusirq != m->mpc_srcbusirq)
824 continue;
825 if (irq_used[i]) {
826 /* already claimed */
827 return -2;
828 }
829 irq_used[i] = 1;
830 return i;
831 }
832
833 /* not found */
834 return -1;
835}
836
837#define SPARE_SLOT_NUM 20
838
839static struct mpc_config_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
840#endif
841
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +0530842static int __init replace_intsrc_all(struct mpc_table *mpc,
Yinghai Lu2944e162008-06-01 13:17:38 -0700843 unsigned long mpc_new_phys,
844 unsigned long mpc_new_length)
845{
846#ifdef CONFIG_X86_IO_APIC
847 int i;
848 int nr_m_spare = 0;
849#endif
850
851 int count = sizeof(*mpc);
852 unsigned char *mpt = ((unsigned char *)mpc) + count;
853
854 printk(KERN_INFO "mpc_length %x\n", mpc->mpc_length);
855 while (count < mpc->mpc_length) {
856 switch (*mpt) {
857 case MP_PROCESSOR:
858 {
Jaswinder Singh Rajputf4f21b72009-01-03 15:48:52 +0530859 struct mpc_cpu *m = (struct mpc_cpu *)mpt;
Yinghai Lu2944e162008-06-01 13:17:38 -0700860 mpt += sizeof(*m);
861 count += sizeof(*m);
862 break;
863 }
864 case MP_BUS:
865 {
Jaswinder Singh Rajput00fb8602009-01-03 15:47:32 +0530866 struct mpc_bus *m = (struct mpc_bus *)mpt;
Yinghai Lu2944e162008-06-01 13:17:38 -0700867 mpt += sizeof(*m);
868 count += sizeof(*m);
869 break;
870 }
871 case MP_IOAPIC:
872 {
Jaswinder Singh Rajput2b85b5f2009-01-03 15:49:57 +0530873 mpt += sizeof(struct mpc_ioapic);
874 count += sizeof(struct mpc_ioapic);
Yinghai Lu2944e162008-06-01 13:17:38 -0700875 break;
876 }
877 case MP_INTSRC:
878 {
879#ifdef CONFIG_X86_IO_APIC
880 struct mpc_config_intsrc *m =
881 (struct mpc_config_intsrc *)mpt;
882
883 printk(KERN_INFO "OLD ");
884 print_MP_intsrc_info(m);
885 i = get_MP_intsrc_index(m);
886 if (i > 0) {
887 assign_to_mpc_intsrc(&mp_irqs[i], m);
888 printk(KERN_INFO "NEW ");
889 print_mp_irq_info(&mp_irqs[i]);
890 } else if (!i) {
891 /* legacy, do nothing */
892 } else if (nr_m_spare < SPARE_SLOT_NUM) {
893 /*
894 * not found (-1), or duplicated (-2)
895 * are invalid entries,
896 * we need to use the slot later
897 */
898 m_spare[nr_m_spare] = m;
899 nr_m_spare++;
900 }
901#endif
902 mpt += sizeof(struct mpc_config_intsrc);
903 count += sizeof(struct mpc_config_intsrc);
904 break;
905 }
906 case MP_LINTSRC:
907 {
908 struct mpc_config_lintsrc *m =
909 (struct mpc_config_lintsrc *)mpt;
910 mpt += sizeof(*m);
911 count += sizeof(*m);
912 break;
913 }
914 default:
915 /* wrong mptable */
916 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
917 printk(KERN_ERR "type %x\n", *mpt);
918 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
919 1, mpc, mpc->mpc_length, 1);
920 goto out;
921 }
922 }
923
924#ifdef CONFIG_X86_IO_APIC
925 for (i = 0; i < mp_irq_entries; i++) {
926 if (irq_used[i])
927 continue;
928
929 if (mp_irqs[i].mp_irqtype != mp_INT)
930 continue;
931
932 if (mp_irqs[i].mp_irqflag != 0x0f)
933 continue;
934
935 if (nr_m_spare > 0) {
936 printk(KERN_INFO "*NEW* found ");
937 nr_m_spare--;
938 assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
939 m_spare[nr_m_spare] = NULL;
940 } else {
941 struct mpc_config_intsrc *m =
942 (struct mpc_config_intsrc *)mpt;
943 count += sizeof(struct mpc_config_intsrc);
944 if (!mpc_new_phys) {
945 printk(KERN_INFO "No spare slots, try to append...take your risk, new mpc_length %x\n", count);
946 } else {
947 if (count <= mpc_new_length)
948 printk(KERN_INFO "No spare slots, try to append..., new mpc_length %x\n", count);
949 else {
950 printk(KERN_ERR "mpc_new_length %lx is too small\n", mpc_new_length);
951 goto out;
952 }
953 }
954 assign_to_mpc_intsrc(&mp_irqs[i], m);
955 mpc->mpc_length = count;
956 mpt += sizeof(struct mpc_config_intsrc);
957 }
958 print_mp_irq_info(&mp_irqs[i]);
959 }
960#endif
961out:
962 /* update checksum */
963 mpc->mpc_checksum = 0;
964 mpc->mpc_checksum -= mpf_checksum((unsigned char *)mpc,
965 mpc->mpc_length);
966
967 return 0;
968}
969
Yinghai Lufcfa1462008-06-18 17:29:31 -0700970static int __initdata enable_update_mptable;
971
Yinghai Lu2944e162008-06-01 13:17:38 -0700972static int __init update_mptable_setup(char *str)
973{
974 enable_update_mptable = 1;
975 return 0;
976}
977early_param("update_mptable", update_mptable_setup);
978
979static unsigned long __initdata mpc_new_phys;
980static unsigned long mpc_new_length __initdata = 4096;
981
982/* alloc_mptable or alloc_mptable=4k */
983static int __initdata alloc_mptable;
984static int __init parse_alloc_mptable_opt(char *p)
985{
986 enable_update_mptable = 1;
987 alloc_mptable = 1;
988 if (!p)
989 return 0;
990 mpc_new_length = memparse(p, &p);
991 return 0;
992}
993early_param("alloc_mptable", parse_alloc_mptable_opt);
994
995void __init early_reserve_e820_mpc_new(void)
996{
997 if (enable_update_mptable && alloc_mptable) {
998 u64 startt = 0;
999#ifdef CONFIG_X86_TRAMPOLINE
1000 startt = TRAMPOLINE_BASE;
1001#endif
1002 mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
1003 }
1004}
1005
1006static int __init update_mp_table(void)
1007{
1008 char str[16];
1009 char oem[10];
1010 struct intel_mp_floating *mpf;
Jaswinder Singh Rajputf29521e2009-01-03 15:46:57 +05301011 struct mpc_table *mpc, *mpc_new;
Yinghai Lu2944e162008-06-01 13:17:38 -07001012
1013 if (!enable_update_mptable)
1014 return 0;
1015
1016 mpf = mpf_found;
1017 if (!mpf)
1018 return 0;
1019
1020 /*
1021 * Now see if we need to go further.
1022 */
1023 if (mpf->mpf_feature1 != 0)
1024 return 0;
1025
1026 if (!mpf->mpf_physptr)
1027 return 0;
1028
1029 mpc = phys_to_virt(mpf->mpf_physptr);
1030
1031 if (!smp_check_mpc(mpc, oem, str))
1032 return 0;
1033
1034 printk(KERN_INFO "mpf: %lx\n", virt_to_phys(mpf));
1035 printk(KERN_INFO "mpf_physptr: %x\n", mpf->mpf_physptr);
1036
1037 if (mpc_new_phys && mpc->mpc_length > mpc_new_length) {
1038 mpc_new_phys = 0;
1039 printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
1040 mpc_new_length);
1041 }
1042
1043 if (!mpc_new_phys) {
1044 unsigned char old, new;
1045 /* check if we can change the postion */
1046 mpc->mpc_checksum = 0;
1047 old = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
1048 mpc->mpc_checksum = 0xff;
1049 new = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
1050 if (old == new) {
1051 printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
1052 return 0;
1053 }
1054 printk(KERN_INFO "use in-positon replacing\n");
1055 } else {
1056 mpf->mpf_physptr = mpc_new_phys;
1057 mpc_new = phys_to_virt(mpc_new_phys);
1058 memcpy(mpc_new, mpc, mpc->mpc_length);
1059 mpc = mpc_new;
1060 /* check if we can modify that */
1061 if (mpc_new_phys - mpf->mpf_physptr) {
1062 struct intel_mp_floating *mpf_new;
1063 /* steal 16 bytes from [0, 1k) */
1064 printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
1065 mpf_new = phys_to_virt(0x400 - 16);
1066 memcpy(mpf_new, mpf, 16);
1067 mpf = mpf_new;
1068 mpf->mpf_physptr = mpc_new_phys;
1069 }
1070 mpf->mpf_checksum = 0;
1071 mpf->mpf_checksum -= mpf_checksum((unsigned char *)mpf, 16);
1072 printk(KERN_INFO "mpf_physptr new: %x\n", mpf->mpf_physptr);
1073 }
1074
1075 /*
1076 * only replace the one with mp_INT and
1077 * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
1078 * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
1079 * may need pci=routeirq for all coverage
1080 */
1081 replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
1082
1083 return 0;
1084}
1085
1086late_initcall(update_mp_table);