blob: b4a950da2f97c416b73e0e7d4807fd47e0113ac8 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20#include <asm/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/mtrr.h>
22#include <asm/mpspec.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040023#include <asm/pgalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/io_apic.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040025#include <asm/proto.h>
26#include <asm/acpi.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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31#include <mach_apic.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040032#ifdef CONFIG_X86_32
Andi Kleen874c4fe2006-09-26 10:52:26 +020033#include <mach_apicdef.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <mach_mpparse.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040035#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Linus Torvalds1da177e2005-04-16 15:20:36 -070037/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 * Checksum an MP configuration block.
39 */
40
41static int __init mpf_checksum(unsigned char *mp, int len)
42{
43 int sum = 0;
44
45 while (len--)
46 sum += *mp++;
47
48 return sum & 0xFF;
49}
50
Alexey Starikovskiy86420502008-03-17 22:08:55 +030051#ifdef CONFIG_X86_NUMAQ
Linus Torvalds1da177e2005-04-16 15:20:36 -070052/*
53 * Have to match translation table entries to main table entries by counter
54 * hence the mpc_record variable .... can't see a less disgusting way of
55 * doing this ....
56 */
57
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +040058static int mpc_record;
59static struct mpc_config_translation *translation_table[MAX_MPC_ENTRY]
60 __cpuinitdata;
Alexey Starikovskiy86420502008-03-17 22:08:55 +030061#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Alexey Starikovskiyc853c672008-03-27 23:54:13 +030063static void __cpuinit MP_processor_info(struct mpc_config_processor *m)
64{
65 int apicid;
Alexey Starikovskiy746f2242008-04-04 23:42:15 +040066 char *bootup_cpu = "";
Alexey Starikovskiyc853c672008-03-27 23:54:13 +030067
Glauber Costa7b1292e2008-03-03 14:12:41 -030068 if (!(m->mpc_cpuflag & CPU_ENABLED)) {
69 disabled_cpus++;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 return;
Glauber Costa7b1292e2008-03-03 14:12:41 -030071 }
Alexey Starikovskiy4655c7d2008-03-17 22:08:36 +030072#ifdef CONFIG_X86_NUMAQ
Yinghai Luab530e12008-06-03 10:25:54 -070073 if (found_numaq)
74 apicid = mpc_apic_id(m, translation_table[mpc_record]);
75 else
76 apicid = m->mpc_apicid;
Alexey Starikovskiy4655c7d2008-03-17 22:08:36 +030077#else
Alexey Starikovskiy4655c7d2008-03-17 22:08:36 +030078 apicid = m->mpc_apicid;
79#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
Alexey Starikovskiy746f2242008-04-04 23:42:15 +040081 bootup_cpu = " (Bootup-CPU)";
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 boot_cpu_physical_apicid = m->mpc_apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 }
84
Alexey Starikovskiy746f2242008-04-04 23:42:15 +040085 printk(KERN_INFO "Processor #%d%s\n", m->mpc_apicid, bootup_cpu);
Alexey Starikovskiyc853c672008-03-27 23:54:13 +030086 generic_processor_info(apicid, m->mpc_apicver);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087}
88
Thomas Gleixner85cc35f2008-05-25 21:21:36 +020089#ifdef CONFIG_X86_IO_APIC
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +040090static void __init MP_bus_info(struct mpc_config_bus *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
92 char str[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 memcpy(str, m->mpc_bustype, 6);
94 str[6] = 0;
95
Alexey Starikovskiy0ec153a2008-03-17 22:08:48 +030096#ifdef CONFIG_X86_NUMAQ
Yinghai Luab530e12008-06-03 10:25:54 -070097 if (found_numaq)
98 mpc_oem_bus_info(m, str, translation_table[mpc_record]);
Alexey Starikovskiy0ec153a2008-03-17 22:08:48 +030099#else
Yinghai Lu11a62a02008-05-12 15:43:38 +0200100 printk(KERN_INFO "Bus #%d is %s\n", m->mpc_busid, str);
Alexey Starikovskiy0ec153a2008-03-17 22:08:48 +0300101#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Andi Kleen5e4edbb2006-09-26 10:52:35 +0200103#if MAX_MP_BUSSES < 256
Randy Dunlapc0ec31a2006-04-10 22:53:13 -0700104 if (m->mpc_busid >= MAX_MP_BUSSES) {
105 printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400106 " is too large, max. supported is %d\n",
107 m->mpc_busid, str, MAX_MP_BUSSES - 1);
Randy Dunlapc0ec31a2006-04-10 22:53:13 -0700108 return;
109 }
Andi Kleen5e4edbb2006-09-26 10:52:35 +0200110#endif
Randy Dunlapc0ec31a2006-04-10 22:53:13 -0700111
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +0400112 if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
113 set_bit(m->mpc_busid, mp_bus_not_pci);
114#if defined(CONFIG_EISA) || defined (CONFIG_MCA)
115 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA;
116#endif
117 } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
Alexey Starikovskiyd285e332008-03-17 22:08:42 +0300118#ifdef CONFIG_X86_NUMAQ
Yinghai Luab530e12008-06-03 10:25:54 -0700119 if (found_numaq)
120 mpc_oem_pci_bus(m, translation_table[mpc_record]);
Alexey Starikovskiyd285e332008-03-17 22:08:42 +0300121#endif
Alexey Starikovskiya6333c32008-03-20 14:54:09 +0300122 clear_bit(m->mpc_busid, mp_bus_not_pci);
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +0300123#if defined(CONFIG_EISA) || defined (CONFIG_MCA)
124 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400125 } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
Alexey Starikovskiy9e0a2de2008-03-20 14:54:56 +0300126 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400127 } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_MCA;
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +0300129#endif
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +0400130 } else
131 printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132}
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200133#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400135#ifdef CONFIG_X86_IO_APIC
136
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300137static int bad_ioapic(unsigned long address)
138{
139 if (nr_ioapics >= MAX_IO_APICS) {
140 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
141 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
142 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
143 }
144 if (!address) {
145 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
146 " found in table, skipping!\n");
147 return 1;
148 }
149 return 0;
150}
151
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400152static void __init MP_ioapic_info(struct mpc_config_ioapic *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153{
154 if (!(m->mpc_flags & MPC_APIC_USABLE))
155 return;
156
Thomas Gleixner64883ab2008-01-30 13:30:35 +0100157 printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400158 m->mpc_apicid, m->mpc_apicver, m->mpc_apicaddr);
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300159
160 if (bad_ioapic(m->mpc_apicaddr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 return;
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300162
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400163 mp_ioapics[nr_ioapics].mp_apicaddr = m->mpc_apicaddr;
164 mp_ioapics[nr_ioapics].mp_apicid = m->mpc_apicid;
165 mp_ioapics[nr_ioapics].mp_type = m->mpc_type;
166 mp_ioapics[nr_ioapics].mp_apicver = m->mpc_apicver;
167 mp_ioapics[nr_ioapics].mp_flags = m->mpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 nr_ioapics++;
169}
170
Yinghai Lu2944e162008-06-01 13:17:38 -0700171static void print_MP_intsrc_info(struct mpc_config_intsrc *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172{
Yinghai Lu2944e162008-06-01 13:17:38 -0700173 printk(KERN_CONT "Int: type %d, pol %d, trig %d, bus %02x,"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400175 m->mpc_irqtype, m->mpc_irqflag & 3,
176 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
177 m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
Yinghai Lu2944e162008-06-01 13:17:38 -0700178}
179
180static void __init print_mp_irq_info(struct mp_config_intsrc *mp_irq)
181{
182 printk(KERN_CONT "Int: type %d, pol %d, trig %d, bus %02x,"
183 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
184 mp_irq->mp_irqtype, mp_irq->mp_irqflag & 3,
185 (mp_irq->mp_irqflag >> 2) & 3, mp_irq->mp_srcbus,
186 mp_irq->mp_srcbusirq, mp_irq->mp_dstapic, mp_irq->mp_dstirq);
187}
188
189static void assign_to_mp_irq(struct mpc_config_intsrc *m,
190 struct mp_config_intsrc *mp_irq)
191{
192 mp_irq->mp_dstapic = m->mpc_dstapic;
193 mp_irq->mp_type = m->mpc_type;
194 mp_irq->mp_irqtype = m->mpc_irqtype;
195 mp_irq->mp_irqflag = m->mpc_irqflag;
196 mp_irq->mp_srcbus = m->mpc_srcbus;
197 mp_irq->mp_srcbusirq = m->mpc_srcbusirq;
198 mp_irq->mp_dstirq = m->mpc_dstirq;
199}
200
201static void __init assign_to_mpc_intsrc(struct mp_config_intsrc *mp_irq,
202 struct mpc_config_intsrc *m)
203{
204 m->mpc_dstapic = mp_irq->mp_dstapic;
205 m->mpc_type = mp_irq->mp_type;
206 m->mpc_irqtype = mp_irq->mp_irqtype;
207 m->mpc_irqflag = mp_irq->mp_irqflag;
208 m->mpc_srcbus = mp_irq->mp_srcbus;
209 m->mpc_srcbusirq = mp_irq->mp_srcbusirq;
210 m->mpc_dstirq = mp_irq->mp_dstirq;
211}
212
213static int mp_irq_mpc_intsrc_cmp(struct mp_config_intsrc *mp_irq,
214 struct mpc_config_intsrc *m)
215{
216 if (mp_irq->mp_dstapic != m->mpc_dstapic)
217 return 1;
218 if (mp_irq->mp_type != m->mpc_type)
219 return 2;
220 if (mp_irq->mp_irqtype != m->mpc_irqtype)
221 return 3;
222 if (mp_irq->mp_irqflag != m->mpc_irqflag)
223 return 4;
224 if (mp_irq->mp_srcbus != m->mpc_srcbus)
225 return 5;
226 if (mp_irq->mp_srcbusirq != m->mpc_srcbusirq)
227 return 6;
228 if (mp_irq->mp_dstirq != m->mpc_dstirq)
229 return 7;
230
231 return 0;
232}
233
234void MP_intsrc_info(struct mpc_config_intsrc *m)
235{
236 int i;
237
238 print_MP_intsrc_info(m);
239
240 for (i = 0; i < mp_irq_entries; i++) {
241 if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m))
242 return;
243 }
244
245 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 if (++mp_irq_entries == MAX_IRQ_SOURCES)
247 panic("Max # of irq sources exceeded!!\n");
248}
249
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400250#endif
251
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400252static void __init MP_lintsrc_info(struct mpc_config_lintsrc *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253{
Yinghai Lu11a62a02008-05-12 15:43:38 +0200254 printk(KERN_INFO "Lint: type %d, pol %d, trig %d, bus %02x,"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400256 m->mpc_irqtype, m->mpc_irqflag & 3,
257 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbusid,
258 m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259}
260
261#ifdef CONFIG_X86_NUMAQ
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400262static void __init MP_translation_info(struct mpc_config_translation *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263{
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400264 printk(KERN_INFO
265 "Translation: record %d, type %d, quad %d, global %d, local %d\n",
266 mpc_record, m->trans_type, m->trans_quad, m->trans_global,
267 m->trans_local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400269 if (mpc_record >= MAX_MPC_ENTRY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 printk(KERN_ERR "MAX_MPC_ENTRY exceeded!\n");
271 else
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400272 translation_table[mpc_record] = m; /* stash this for later */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 if (m->trans_quad < MAX_NUMNODES && !node_online(m->trans_quad))
274 node_set_online(m->trans_quad);
275}
276
277/*
278 * Read/parse the MPC oem tables
279 */
280
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400281static void __init smp_read_mpc_oem(struct mp_config_oemtable *oemtable,
282 unsigned short oemsize)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400284 int count = sizeof(*oemtable); /* the header size */
285 unsigned char *oemptr = ((unsigned char *)oemtable) + count;
286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 mpc_record = 0;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400288 printk(KERN_INFO "Found an OEM MPC table at %8p - parsing it ... \n",
289 oemtable);
290 if (memcmp(oemtable->oem_signature, MPC_OEM_SIGNATURE, 4)) {
291 printk(KERN_WARNING
292 "SMP mpc oemtable: bad signature [%c%c%c%c]!\n",
293 oemtable->oem_signature[0], oemtable->oem_signature[1],
294 oemtable->oem_signature[2], oemtable->oem_signature[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 return;
296 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400297 if (mpf_checksum((unsigned char *)oemtable, oemtable->oem_length)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 printk(KERN_WARNING "SMP oem mptable: checksum error!\n");
299 return;
300 }
301 while (count < oemtable->oem_length) {
302 switch (*oemptr) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400303 case MP_TRANSLATION:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400305 struct mpc_config_translation *m =
306 (struct mpc_config_translation *)oemptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 MP_translation_info(m);
308 oemptr += sizeof(*m);
309 count += sizeof(*m);
310 ++mpc_record;
311 break;
312 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400313 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400315 printk(KERN_WARNING
316 "Unrecognised OEM table entry type! - %d\n",
317 (int)*oemptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 return;
319 }
320 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400321 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322}
323
324static inline void mps_oem_check(struct mp_config_table *mpc, char *oem,
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400325 char *productid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326{
327 if (strncmp(oem, "IBM NUMA", 8))
328 printk("Warning! May not be a NUMA-Q system!\n");
Yinghai Luab530e12008-06-03 10:25:54 -0700329 else
330 found_numaq = 1;
331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 if (mpc->mpc_oemptr)
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400333 smp_read_mpc_oem((struct mp_config_oemtable *)mpc->mpc_oemptr,
334 mpc->mpc_oemsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335}
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400336#endif /* CONFIG_X86_NUMAQ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
338/*
339 * Read/parse the MPC
340 */
341
Yinghai Lu2944e162008-06-01 13:17:38 -0700342static int __init smp_check_mpc(struct mp_config_table *mpc, char *oem,
343 char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400346 if (memcmp(mpc->mpc_signature, MPC_SIGNATURE, 4)) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400347 printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
348 mpc->mpc_signature[0], mpc->mpc_signature[1],
349 mpc->mpc_signature[2], mpc->mpc_signature[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 return 0;
351 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400352 if (mpf_checksum((unsigned char *)mpc, mpc->mpc_length)) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400353 printk(KERN_ERR "MPTABLE: checksum error!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 return 0;
355 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400356 if (mpc->mpc_spec != 0x01 && mpc->mpc_spec != 0x04) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400357 printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400358 mpc->mpc_spec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 return 0;
360 }
361 if (!mpc->mpc_lapic) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400362 printk(KERN_ERR "MPTABLE: null local APIC address!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 return 0;
364 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400365 memcpy(oem, mpc->mpc_oem, 8);
366 oem[8] = 0;
Yinghai Lu11a62a02008-05-12 15:43:38 +0200367 printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400369 memcpy(str, mpc->mpc_productid, 12);
370 str[12] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Yinghai Lu11a62a02008-05-12 15:43:38 +0200372 printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400374 printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->mpc_lapic);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Yinghai Lu2944e162008-06-01 13:17:38 -0700376 return 1;
377}
378
379static int __init smp_read_mpc(struct mp_config_table *mpc, unsigned early)
380{
381 char str[16];
382 char oem[10];
383
384 int count = sizeof(*mpc);
385 unsigned char *mpt = ((unsigned char *)mpc) + count;
386
387 if (!smp_check_mpc(mpc, oem, str))
388 return 0;
389
390#ifdef CONFIG_X86_32
391 mps_oem_check(mpc, oem, str);
392#endif
393
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400394 /* save the local APIC address, it might be non-default */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 if (!acpi_lapic)
396 mp_lapic_addr = mpc->mpc_lapic;
397
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400398 if (early)
399 return 1;
400
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 /*
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400402 * Now process the configuration blocks.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 */
Alexey Starikovskiy86420502008-03-17 22:08:55 +0300404#ifdef CONFIG_X86_NUMAQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 mpc_record = 0;
Alexey Starikovskiy86420502008-03-17 22:08:55 +0300406#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 while (count < mpc->mpc_length) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400408 switch (*mpt) {
409 case MP_PROCESSOR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400411 struct mpc_config_processor *m =
412 (struct mpc_config_processor *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 /* ACPI may have already provided this data */
414 if (!acpi_lapic)
415 MP_processor_info(m);
416 mpt += sizeof(*m);
417 count += sizeof(*m);
418 break;
419 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400420 case MP_BUS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400422 struct mpc_config_bus *m =
423 (struct mpc_config_bus *)mpt;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200424#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 MP_bus_info(m);
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200426#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 mpt += sizeof(*m);
428 count += sizeof(*m);
429 break;
430 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400431 case MP_IOAPIC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 {
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400433#ifdef CONFIG_X86_IO_APIC
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400434 struct mpc_config_ioapic *m =
435 (struct mpc_config_ioapic *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 MP_ioapic_info(m);
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400437#endif
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400438 mpt += sizeof(struct mpc_config_ioapic);
439 count += sizeof(struct mpc_config_ioapic);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 break;
441 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400442 case MP_INTSRC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 {
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400444#ifdef CONFIG_X86_IO_APIC
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400445 struct mpc_config_intsrc *m =
446 (struct mpc_config_intsrc *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
448 MP_intsrc_info(m);
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400449#endif
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400450 mpt += sizeof(struct mpc_config_intsrc);
451 count += sizeof(struct mpc_config_intsrc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 break;
453 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400454 case MP_LINTSRC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400456 struct mpc_config_lintsrc *m =
457 (struct mpc_config_lintsrc *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 MP_lintsrc_info(m);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400459 mpt += sizeof(*m);
460 count += sizeof(*m);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 break;
462 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400463 default:
Yinghai Lu711554d2008-04-07 11:36:39 -0700464 /* wrong mptable */
465 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
466 printk(KERN_ERR "type %x\n", *mpt);
467 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
468 1, mpc, mpc->mpc_length, 1);
469 count = mpc->mpc_length;
470 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 }
Alexey Starikovskiy86420502008-03-17 22:08:55 +0300472#ifdef CONFIG_X86_NUMAQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 ++mpc_record;
Alexey Starikovskiy86420502008-03-17 22:08:55 +0300474#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 }
Ingo Molnar3c43f032007-05-02 19:27:04 +0200476 setup_apic_routing();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 if (!num_processors)
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400478 printk(KERN_ERR "MPTABLE: no processors registered!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 return num_processors;
480}
481
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400482#ifdef CONFIG_X86_IO_APIC
483
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484static int __init ELCR_trigger(unsigned int irq)
485{
486 unsigned int port;
487
488 port = 0x4d0 + (irq >> 3);
489 return (inb(port) >> (irq & 7)) & 1;
490}
491
492static void __init construct_default_ioirq_mptable(int mpc_default_type)
493{
494 struct mpc_config_intsrc intsrc;
495 int i;
496 int ELCR_fallback = 0;
497
498 intsrc.mpc_type = MP_INTSRC;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400499 intsrc.mpc_irqflag = 0; /* conforming */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 intsrc.mpc_srcbus = 0;
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400501 intsrc.mpc_dstapic = mp_ioapics[0].mp_apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
503 intsrc.mpc_irqtype = mp_INT;
504
505 /*
506 * If true, we have an ISA/PCI system with no IRQ entries
507 * in the MP table. To prevent the PCI interrupts from being set up
508 * incorrectly, we try to use the ELCR. The sanity check to see if
509 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
510 * never be level sensitive, so we simply see if the ELCR agrees.
511 * If it does, we assume it's valid.
512 */
513 if (mpc_default_type == 5) {
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400514 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
515 "falling back to ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400517 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
518 ELCR_trigger(13))
519 printk(KERN_ERR "ELCR contains invalid data... "
520 "not using ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 else {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400522 printk(KERN_INFO
523 "Using ELCR to identify PCI interrupts\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 ELCR_fallback = 1;
525 }
526 }
527
528 for (i = 0; i < 16; i++) {
529 switch (mpc_default_type) {
530 case 2:
531 if (i == 0 || i == 13)
532 continue; /* IRQ0 & IRQ13 not connected */
533 /* fall through */
534 default:
535 if (i == 2)
536 continue; /* IRQ2 is never connected */
537 }
538
539 if (ELCR_fallback) {
540 /*
541 * If the ELCR indicates a level-sensitive interrupt, we
542 * copy that information over to the MP table in the
543 * irqflag field (level sensitive, active high polarity).
544 */
545 if (ELCR_trigger(i))
546 intsrc.mpc_irqflag = 13;
547 else
548 intsrc.mpc_irqflag = 0;
549 }
550
551 intsrc.mpc_srcbusirq = i;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400552 intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 MP_intsrc_info(&intsrc);
554 }
555
556 intsrc.mpc_irqtype = mp_ExtINT;
557 intsrc.mpc_srcbusirq = 0;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400558 intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 MP_intsrc_info(&intsrc);
560}
561
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400562
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200563static void construct_ioapic_table(int mpc_default_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 struct mpc_config_ioapic ioapic;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200566 struct mpc_config_bus bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
568 bus.mpc_type = MP_BUS;
569 bus.mpc_busid = 0;
570 switch (mpc_default_type) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400571 default:
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400572 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400573 mpc_default_type);
574 /* fall through */
575 case 1:
576 case 5:
577 memcpy(bus.mpc_bustype, "ISA ", 6);
578 break;
579 case 2:
580 case 6:
581 case 3:
582 memcpy(bus.mpc_bustype, "EISA ", 6);
583 break;
584 case 4:
585 case 7:
586 memcpy(bus.mpc_bustype, "MCA ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 }
588 MP_bus_info(&bus);
589 if (mpc_default_type > 4) {
590 bus.mpc_busid = 1;
591 memcpy(bus.mpc_bustype, "PCI ", 6);
592 MP_bus_info(&bus);
593 }
594
595 ioapic.mpc_type = MP_IOAPIC;
596 ioapic.mpc_apicid = 2;
597 ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
598 ioapic.mpc_flags = MPC_APIC_USABLE;
599 ioapic.mpc_apicaddr = 0xFEC00000;
600 MP_ioapic_info(&ioapic);
601
602 /*
603 * We set up most of the low 16 IO-APIC pins according to MPS rules.
604 */
605 construct_default_ioirq_mptable(mpc_default_type);
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200606}
607#else
608static inline void construct_ioapic_table(int mpc_default_type) { }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400609#endif
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200610
611static inline void __init construct_default_ISA_mptable(int mpc_default_type)
612{
613 struct mpc_config_processor processor;
614 struct mpc_config_lintsrc lintsrc;
615 int linttypes[2] = { mp_ExtINT, mp_NMI };
616 int i;
617
618 /*
619 * local APIC has default address
620 */
621 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
622
623 /*
624 * 2 CPUs, numbered 0 & 1.
625 */
626 processor.mpc_type = MP_PROCESSOR;
627 /* Either an integrated APIC or a discrete 82489DX. */
628 processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
629 processor.mpc_cpuflag = CPU_ENABLED;
630 processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
631 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
632 processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
633 processor.mpc_reserved[0] = 0;
634 processor.mpc_reserved[1] = 0;
635 for (i = 0; i < 2; i++) {
636 processor.mpc_apicid = i;
637 MP_processor_info(&processor);
638 }
639
640 construct_ioapic_table(mpc_default_type);
641
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 lintsrc.mpc_type = MP_LINTSRC;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400643 lintsrc.mpc_irqflag = 0; /* conforming */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 lintsrc.mpc_srcbusid = 0;
645 lintsrc.mpc_srcbusirq = 0;
646 lintsrc.mpc_destapic = MP_APIC_ALL;
647 for (i = 0; i < 2; i++) {
648 lintsrc.mpc_irqtype = linttypes[i];
649 lintsrc.mpc_destapiclint = i;
650 MP_lintsrc_info(&lintsrc);
651 }
652}
653
654static struct intel_mp_floating *mpf_found;
655
656/*
657 * Scan the memory blocks for an SMP configuration block.
658 */
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400659static void __init __get_smp_config(unsigned early)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660{
661 struct intel_mp_floating *mpf = mpf_found;
662
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400663 if (acpi_lapic && early)
664 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 /*
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400666 * ACPI supports both logical (e.g. Hyper-Threading) and physical
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 * processors, where MPS only supports physical.
668 */
669 if (acpi_lapic && acpi_ioapic) {
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400670 printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
671 "information\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 return;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400673 } else if (acpi_lapic)
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400674 printk(KERN_INFO "Using ACPI for processor (LAPIC) "
675 "configuration information\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400677 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
678 mpf->mpf_specification);
Alexey Starikovskiyb3e24162008-05-23 01:54:44 +0400679#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400680 if (mpf->mpf_feature2 & (1 << 7)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
682 pic_mode = 1;
683 } else {
684 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
685 pic_mode = 0;
686 }
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400687#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 /*
689 * Now see if we need to read further.
690 */
691 if (mpf->mpf_feature1 != 0) {
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400692 if (early) {
693 /*
694 * local APIC has default address
695 */
696 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
697 return;
698 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400700 printk(KERN_INFO "Default MP configuration #%d\n",
701 mpf->mpf_feature1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 construct_default_ISA_mptable(mpf->mpf_feature1);
703
704 } else if (mpf->mpf_physptr) {
705
706 /*
707 * Read the physical hardware table. Anything here will
708 * override the defaults.
709 */
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400710 if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr), early)) {
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400711#ifdef CONFIG_X86_LOCAL_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 smp_found_config = 0;
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400713#endif
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400714 printk(KERN_ERR
715 "BIOS bug, MP table errors detected!...\n");
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400716 printk(KERN_ERR "... disabling SMP support. "
717 "(tell your hw vendor)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 return;
719 }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400720
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400721 if (early)
722 return;
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400723#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 /*
725 * If there are no explicit MP IRQ entries, then we are
726 * broken. We set up most of the low 16 IO-APIC pins to
727 * ISA defaults and hope it will work.
728 */
729 if (!mp_irq_entries) {
730 struct mpc_config_bus bus;
731
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400732 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
733 "using default mptable. "
734 "(tell your hw vendor)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
736 bus.mpc_type = MP_BUS;
737 bus.mpc_busid = 0;
738 memcpy(bus.mpc_bustype, "ISA ", 6);
739 MP_bus_info(&bus);
740
741 construct_default_ioirq_mptable(0);
742 }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400743#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 } else
745 BUG();
746
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400747 if (!early)
748 printk(KERN_INFO "Processors: %d\n", num_processors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 /*
750 * Only use the first configuration found.
751 */
752}
753
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400754void __init early_get_smp_config(void)
755{
756 __get_smp_config(1);
757}
758
759void __init get_smp_config(void)
760{
761 __get_smp_config(0);
762}
763
764static int __init smp_scan_config(unsigned long base, unsigned long length,
765 unsigned reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766{
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400767 unsigned int *bp = phys_to_virt(base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 struct intel_mp_floating *mpf;
769
Yinghai Lu11a62a02008-05-12 15:43:38 +0200770 printk(KERN_DEBUG "Scan SMP from %p for %ld bytes.\n", bp, length);
Akinobu Mita5d47a272008-04-19 23:55:11 +0900771 BUILD_BUG_ON(sizeof(*mpf) != 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
773 while (length > 0) {
774 mpf = (struct intel_mp_floating *)bp;
775 if ((*bp == SMP_MAGIC_IDENT) &&
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400776 (mpf->mpf_length == 1) &&
777 !mpf_checksum((unsigned char *)bp, 16) &&
778 ((mpf->mpf_specification == 1)
779 || (mpf->mpf_specification == 4))) {
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400780#ifdef CONFIG_X86_LOCAL_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 smp_found_config = 1;
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400782#endif
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400783 mpf_found = mpf;
784#ifdef CONFIG_X86_32
Ingo Molnare91a3b42008-01-30 13:33:08 +0100785 printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400786 mpf, virt_to_phys(mpf));
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800787 reserve_bootmem(virt_to_phys(mpf), PAGE_SIZE,
788 BOOTMEM_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 if (mpf->mpf_physptr) {
790 /*
791 * We cannot access to MPC table to compute
792 * table size yet, as only few megabytes from
793 * the bottom is mapped now.
794 * PC-9800's MPC table places on the very last
795 * of physical memory; so that simply reserving
796 * PAGE_SIZE from mpg->mpf_physptr yields BUG()
797 * in reserve_bootmem.
798 */
799 unsigned long size = PAGE_SIZE;
800 unsigned long end = max_low_pfn * PAGE_SIZE;
801 if (mpf->mpf_physptr + size > end)
802 size = end - mpf->mpf_physptr;
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800803 reserve_bootmem(mpf->mpf_physptr, size,
804 BOOTMEM_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 }
806
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400807#else
808 if (!reserve)
809 return 1;
810
811 reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE);
812 if (mpf->mpf_physptr)
813 reserve_bootmem_generic(mpf->mpf_physptr,
814 PAGE_SIZE);
815#endif
816 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 }
818 bp += 4;
819 length -= 16;
820 }
821 return 0;
822}
823
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400824static void __init __find_smp_config(unsigned reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825{
826 unsigned int address;
827
828 /*
829 * FIXME: Linux assumes you have 640K of base ram..
830 * this continues the error...
831 *
832 * 1) Scan the bottom 1K for a signature
833 * 2) Scan the top 1K of base RAM
834 * 3) Scan the 64K of bios
835 */
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400836 if (smp_scan_config(0x0, 0x400, reserve) ||
837 smp_scan_config(639 * 0x400, 0x400, reserve) ||
838 smp_scan_config(0xF0000, 0x10000, reserve))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 return;
840 /*
841 * If it is an SMP machine we should know now, unless the
842 * configuration is in an EISA/MCA bus machine with an
843 * extended bios data area.
844 *
845 * there is a real-mode segmented pointer pointing to the
846 * 4K EBDA area at 0x40E, calculate and scan it here.
847 *
848 * NOTE! There are Linux loaders that will corrupt the EBDA
849 * area, and as such this kind of SMP config may be less
850 * trustworthy, simply because the SMP table may have been
851 * stomped on during early boot. These loaders are buggy and
852 * should be fixed.
853 *
854 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
855 */
856
857 address = get_bios_ebda();
858 if (address)
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400859 smp_scan_config(address, 0x400, reserve);
860}
861
862void __init early_find_smp_config(void)
863{
864 __find_smp_config(0);
865}
866
867void __init find_smp_config(void)
868{
869 __find_smp_config(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870}
Yinghai Lu2944e162008-06-01 13:17:38 -0700871
872#ifdef CONFIG_X86_IO_APIC
873static u8 __initdata irq_used[MAX_IRQ_SOURCES];
874
875static int __init get_MP_intsrc_index(struct mpc_config_intsrc *m)
876{
877 int i;
878
879 if (m->mpc_irqtype != mp_INT)
880 return 0;
881
882 if (m->mpc_irqflag != 0x0f)
883 return 0;
884
885 /* not legacy */
886
887 for (i = 0; i < mp_irq_entries; i++) {
888 if (mp_irqs[i].mp_irqtype != mp_INT)
889 continue;
890
891 if (mp_irqs[i].mp_irqflag != 0x0f)
892 continue;
893
894 if (mp_irqs[i].mp_srcbus != m->mpc_srcbus)
895 continue;
896 if (mp_irqs[i].mp_srcbusirq != m->mpc_srcbusirq)
897 continue;
898 if (irq_used[i]) {
899 /* already claimed */
900 return -2;
901 }
902 irq_used[i] = 1;
903 return i;
904 }
905
906 /* not found */
907 return -1;
908}
909
910#define SPARE_SLOT_NUM 20
911
912static struct mpc_config_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
913#endif
914
915static int __init replace_intsrc_all(struct mp_config_table *mpc,
916 unsigned long mpc_new_phys,
917 unsigned long mpc_new_length)
918{
919#ifdef CONFIG_X86_IO_APIC
920 int i;
921 int nr_m_spare = 0;
922#endif
923
924 int count = sizeof(*mpc);
925 unsigned char *mpt = ((unsigned char *)mpc) + count;
926
927 printk(KERN_INFO "mpc_length %x\n", mpc->mpc_length);
928 while (count < mpc->mpc_length) {
929 switch (*mpt) {
930 case MP_PROCESSOR:
931 {
932 struct mpc_config_processor *m =
933 (struct mpc_config_processor *)mpt;
934 mpt += sizeof(*m);
935 count += sizeof(*m);
936 break;
937 }
938 case MP_BUS:
939 {
940 struct mpc_config_bus *m =
941 (struct mpc_config_bus *)mpt;
942 mpt += sizeof(*m);
943 count += sizeof(*m);
944 break;
945 }
946 case MP_IOAPIC:
947 {
948 mpt += sizeof(struct mpc_config_ioapic);
949 count += sizeof(struct mpc_config_ioapic);
950 break;
951 }
952 case MP_INTSRC:
953 {
954#ifdef CONFIG_X86_IO_APIC
955 struct mpc_config_intsrc *m =
956 (struct mpc_config_intsrc *)mpt;
957
958 printk(KERN_INFO "OLD ");
959 print_MP_intsrc_info(m);
960 i = get_MP_intsrc_index(m);
961 if (i > 0) {
962 assign_to_mpc_intsrc(&mp_irqs[i], m);
963 printk(KERN_INFO "NEW ");
964 print_mp_irq_info(&mp_irqs[i]);
965 } else if (!i) {
966 /* legacy, do nothing */
967 } else if (nr_m_spare < SPARE_SLOT_NUM) {
968 /*
969 * not found (-1), or duplicated (-2)
970 * are invalid entries,
971 * we need to use the slot later
972 */
973 m_spare[nr_m_spare] = m;
974 nr_m_spare++;
975 }
976#endif
977 mpt += sizeof(struct mpc_config_intsrc);
978 count += sizeof(struct mpc_config_intsrc);
979 break;
980 }
981 case MP_LINTSRC:
982 {
983 struct mpc_config_lintsrc *m =
984 (struct mpc_config_lintsrc *)mpt;
985 mpt += sizeof(*m);
986 count += sizeof(*m);
987 break;
988 }
989 default:
990 /* wrong mptable */
991 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
992 printk(KERN_ERR "type %x\n", *mpt);
993 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
994 1, mpc, mpc->mpc_length, 1);
995 goto out;
996 }
997 }
998
999#ifdef CONFIG_X86_IO_APIC
1000 for (i = 0; i < mp_irq_entries; i++) {
1001 if (irq_used[i])
1002 continue;
1003
1004 if (mp_irqs[i].mp_irqtype != mp_INT)
1005 continue;
1006
1007 if (mp_irqs[i].mp_irqflag != 0x0f)
1008 continue;
1009
1010 if (nr_m_spare > 0) {
1011 printk(KERN_INFO "*NEW* found ");
1012 nr_m_spare--;
1013 assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
1014 m_spare[nr_m_spare] = NULL;
1015 } else {
1016 struct mpc_config_intsrc *m =
1017 (struct mpc_config_intsrc *)mpt;
1018 count += sizeof(struct mpc_config_intsrc);
1019 if (!mpc_new_phys) {
1020 printk(KERN_INFO "No spare slots, try to append...take your risk, new mpc_length %x\n", count);
1021 } else {
1022 if (count <= mpc_new_length)
1023 printk(KERN_INFO "No spare slots, try to append..., new mpc_length %x\n", count);
1024 else {
1025 printk(KERN_ERR "mpc_new_length %lx is too small\n", mpc_new_length);
1026 goto out;
1027 }
1028 }
1029 assign_to_mpc_intsrc(&mp_irqs[i], m);
1030 mpc->mpc_length = count;
1031 mpt += sizeof(struct mpc_config_intsrc);
1032 }
1033 print_mp_irq_info(&mp_irqs[i]);
1034 }
1035#endif
1036out:
1037 /* update checksum */
1038 mpc->mpc_checksum = 0;
1039 mpc->mpc_checksum -= mpf_checksum((unsigned char *)mpc,
1040 mpc->mpc_length);
1041
1042 return 0;
1043}
1044
1045int __initdata enable_update_mptable;
1046
1047static int __init update_mptable_setup(char *str)
1048{
1049 enable_update_mptable = 1;
1050 return 0;
1051}
1052early_param("update_mptable", update_mptable_setup);
1053
1054static unsigned long __initdata mpc_new_phys;
1055static unsigned long mpc_new_length __initdata = 4096;
1056
1057/* alloc_mptable or alloc_mptable=4k */
1058static int __initdata alloc_mptable;
1059static int __init parse_alloc_mptable_opt(char *p)
1060{
1061 enable_update_mptable = 1;
1062 alloc_mptable = 1;
1063 if (!p)
1064 return 0;
1065 mpc_new_length = memparse(p, &p);
1066 return 0;
1067}
1068early_param("alloc_mptable", parse_alloc_mptable_opt);
1069
1070void __init early_reserve_e820_mpc_new(void)
1071{
1072 if (enable_update_mptable && alloc_mptable) {
1073 u64 startt = 0;
1074#ifdef CONFIG_X86_TRAMPOLINE
1075 startt = TRAMPOLINE_BASE;
1076#endif
1077 mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
1078 }
1079}
1080
1081static int __init update_mp_table(void)
1082{
1083 char str[16];
1084 char oem[10];
1085 struct intel_mp_floating *mpf;
1086 struct mp_config_table *mpc;
1087 struct mp_config_table *mpc_new;
1088
1089 if (!enable_update_mptable)
1090 return 0;
1091
1092 mpf = mpf_found;
1093 if (!mpf)
1094 return 0;
1095
1096 /*
1097 * Now see if we need to go further.
1098 */
1099 if (mpf->mpf_feature1 != 0)
1100 return 0;
1101
1102 if (!mpf->mpf_physptr)
1103 return 0;
1104
1105 mpc = phys_to_virt(mpf->mpf_physptr);
1106
1107 if (!smp_check_mpc(mpc, oem, str))
1108 return 0;
1109
1110 printk(KERN_INFO "mpf: %lx\n", virt_to_phys(mpf));
1111 printk(KERN_INFO "mpf_physptr: %x\n", mpf->mpf_physptr);
1112
1113 if (mpc_new_phys && mpc->mpc_length > mpc_new_length) {
1114 mpc_new_phys = 0;
1115 printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
1116 mpc_new_length);
1117 }
1118
1119 if (!mpc_new_phys) {
1120 unsigned char old, new;
1121 /* check if we can change the postion */
1122 mpc->mpc_checksum = 0;
1123 old = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
1124 mpc->mpc_checksum = 0xff;
1125 new = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
1126 if (old == new) {
1127 printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
1128 return 0;
1129 }
1130 printk(KERN_INFO "use in-positon replacing\n");
1131 } else {
1132 mpf->mpf_physptr = mpc_new_phys;
1133 mpc_new = phys_to_virt(mpc_new_phys);
1134 memcpy(mpc_new, mpc, mpc->mpc_length);
1135 mpc = mpc_new;
1136 /* check if we can modify that */
1137 if (mpc_new_phys - mpf->mpf_physptr) {
1138 struct intel_mp_floating *mpf_new;
1139 /* steal 16 bytes from [0, 1k) */
1140 printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
1141 mpf_new = phys_to_virt(0x400 - 16);
1142 memcpy(mpf_new, mpf, 16);
1143 mpf = mpf_new;
1144 mpf->mpf_physptr = mpc_new_phys;
1145 }
1146 mpf->mpf_checksum = 0;
1147 mpf->mpf_checksum -= mpf_checksum((unsigned char *)mpf, 16);
1148 printk(KERN_INFO "mpf_physptr new: %x\n", mpf->mpf_physptr);
1149 }
1150
1151 /*
1152 * only replace the one with mp_INT and
1153 * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
1154 * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
1155 * may need pci=routeirq for all coverage
1156 */
1157 replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
1158
1159 return 0;
1160}
1161
1162late_initcall(update_mp_table);