blob: 7591325e616d3b90a23a6894b596e69f058b1b9f [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 }
Yinghai Lue0da3362008-06-08 18:29:22 -0700476
477#ifdef CONFIG_X86_GENERICARCH
478 generic_bigsmp_probe();
479#endif
480
Ingo Molnar3c43f032007-05-02 19:27:04 +0200481 setup_apic_routing();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 if (!num_processors)
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400483 printk(KERN_ERR "MPTABLE: no processors registered!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 return num_processors;
485}
486
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400487#ifdef CONFIG_X86_IO_APIC
488
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489static int __init ELCR_trigger(unsigned int irq)
490{
491 unsigned int port;
492
493 port = 0x4d0 + (irq >> 3);
494 return (inb(port) >> (irq & 7)) & 1;
495}
496
497static void __init construct_default_ioirq_mptable(int mpc_default_type)
498{
499 struct mpc_config_intsrc intsrc;
500 int i;
501 int ELCR_fallback = 0;
502
503 intsrc.mpc_type = MP_INTSRC;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400504 intsrc.mpc_irqflag = 0; /* conforming */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 intsrc.mpc_srcbus = 0;
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400506 intsrc.mpc_dstapic = mp_ioapics[0].mp_apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
508 intsrc.mpc_irqtype = mp_INT;
509
510 /*
511 * If true, we have an ISA/PCI system with no IRQ entries
512 * in the MP table. To prevent the PCI interrupts from being set up
513 * incorrectly, we try to use the ELCR. The sanity check to see if
514 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
515 * never be level sensitive, so we simply see if the ELCR agrees.
516 * If it does, we assume it's valid.
517 */
518 if (mpc_default_type == 5) {
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400519 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
520 "falling back to ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400522 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
523 ELCR_trigger(13))
524 printk(KERN_ERR "ELCR contains invalid data... "
525 "not using ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 else {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400527 printk(KERN_INFO
528 "Using ELCR to identify PCI interrupts\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 ELCR_fallback = 1;
530 }
531 }
532
533 for (i = 0; i < 16; i++) {
534 switch (mpc_default_type) {
535 case 2:
536 if (i == 0 || i == 13)
537 continue; /* IRQ0 & IRQ13 not connected */
538 /* fall through */
539 default:
540 if (i == 2)
541 continue; /* IRQ2 is never connected */
542 }
543
544 if (ELCR_fallback) {
545 /*
546 * If the ELCR indicates a level-sensitive interrupt, we
547 * copy that information over to the MP table in the
548 * irqflag field (level sensitive, active high polarity).
549 */
550 if (ELCR_trigger(i))
551 intsrc.mpc_irqflag = 13;
552 else
553 intsrc.mpc_irqflag = 0;
554 }
555
556 intsrc.mpc_srcbusirq = i;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400557 intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 MP_intsrc_info(&intsrc);
559 }
560
561 intsrc.mpc_irqtype = mp_ExtINT;
562 intsrc.mpc_srcbusirq = 0;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400563 intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 MP_intsrc_info(&intsrc);
565}
566
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400567
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200568static void construct_ioapic_table(int mpc_default_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 struct mpc_config_ioapic ioapic;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200571 struct mpc_config_bus bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
573 bus.mpc_type = MP_BUS;
574 bus.mpc_busid = 0;
575 switch (mpc_default_type) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400576 default:
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400577 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400578 mpc_default_type);
579 /* fall through */
580 case 1:
581 case 5:
582 memcpy(bus.mpc_bustype, "ISA ", 6);
583 break;
584 case 2:
585 case 6:
586 case 3:
587 memcpy(bus.mpc_bustype, "EISA ", 6);
588 break;
589 case 4:
590 case 7:
591 memcpy(bus.mpc_bustype, "MCA ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 }
593 MP_bus_info(&bus);
594 if (mpc_default_type > 4) {
595 bus.mpc_busid = 1;
596 memcpy(bus.mpc_bustype, "PCI ", 6);
597 MP_bus_info(&bus);
598 }
599
600 ioapic.mpc_type = MP_IOAPIC;
601 ioapic.mpc_apicid = 2;
602 ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
603 ioapic.mpc_flags = MPC_APIC_USABLE;
604 ioapic.mpc_apicaddr = 0xFEC00000;
605 MP_ioapic_info(&ioapic);
606
607 /*
608 * We set up most of the low 16 IO-APIC pins according to MPS rules.
609 */
610 construct_default_ioirq_mptable(mpc_default_type);
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200611}
612#else
613static inline void construct_ioapic_table(int mpc_default_type) { }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400614#endif
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200615
616static inline void __init construct_default_ISA_mptable(int mpc_default_type)
617{
618 struct mpc_config_processor processor;
619 struct mpc_config_lintsrc lintsrc;
620 int linttypes[2] = { mp_ExtINT, mp_NMI };
621 int i;
622
623 /*
624 * local APIC has default address
625 */
626 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
627
628 /*
629 * 2 CPUs, numbered 0 & 1.
630 */
631 processor.mpc_type = MP_PROCESSOR;
632 /* Either an integrated APIC or a discrete 82489DX. */
633 processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
634 processor.mpc_cpuflag = CPU_ENABLED;
635 processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
636 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
637 processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
638 processor.mpc_reserved[0] = 0;
639 processor.mpc_reserved[1] = 0;
640 for (i = 0; i < 2; i++) {
641 processor.mpc_apicid = i;
642 MP_processor_info(&processor);
643 }
644
645 construct_ioapic_table(mpc_default_type);
646
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 lintsrc.mpc_type = MP_LINTSRC;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400648 lintsrc.mpc_irqflag = 0; /* conforming */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 lintsrc.mpc_srcbusid = 0;
650 lintsrc.mpc_srcbusirq = 0;
651 lintsrc.mpc_destapic = MP_APIC_ALL;
652 for (i = 0; i < 2; i++) {
653 lintsrc.mpc_irqtype = linttypes[i];
654 lintsrc.mpc_destapiclint = i;
655 MP_lintsrc_info(&lintsrc);
656 }
657}
658
659static struct intel_mp_floating *mpf_found;
660
661/*
662 * Scan the memory blocks for an SMP configuration block.
663 */
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400664static void __init __get_smp_config(unsigned early)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665{
666 struct intel_mp_floating *mpf = mpf_found;
667
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400668 if (acpi_lapic && early)
669 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 /*
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400671 * ACPI supports both logical (e.g. Hyper-Threading) and physical
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 * processors, where MPS only supports physical.
673 */
674 if (acpi_lapic && acpi_ioapic) {
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400675 printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
676 "information\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 return;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400678 } else if (acpi_lapic)
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400679 printk(KERN_INFO "Using ACPI for processor (LAPIC) "
680 "configuration information\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400682 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
683 mpf->mpf_specification);
Alexey Starikovskiyb3e24162008-05-23 01:54:44 +0400684#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400685 if (mpf->mpf_feature2 & (1 << 7)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
687 pic_mode = 1;
688 } else {
689 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
690 pic_mode = 0;
691 }
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400692#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 /*
694 * Now see if we need to read further.
695 */
696 if (mpf->mpf_feature1 != 0) {
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400697 if (early) {
698 /*
699 * local APIC has default address
700 */
701 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
702 return;
703 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400705 printk(KERN_INFO "Default MP configuration #%d\n",
706 mpf->mpf_feature1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 construct_default_ISA_mptable(mpf->mpf_feature1);
708
709 } else if (mpf->mpf_physptr) {
710
711 /*
712 * Read the physical hardware table. Anything here will
713 * override the defaults.
714 */
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400715 if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr), early)) {
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400716#ifdef CONFIG_X86_LOCAL_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 smp_found_config = 0;
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400718#endif
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400719 printk(KERN_ERR
720 "BIOS bug, MP table errors detected!...\n");
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400721 printk(KERN_ERR "... disabling SMP support. "
722 "(tell your hw vendor)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 return;
724 }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400725
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400726 if (early)
727 return;
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400728#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 /*
730 * If there are no explicit MP IRQ entries, then we are
731 * broken. We set up most of the low 16 IO-APIC pins to
732 * ISA defaults and hope it will work.
733 */
734 if (!mp_irq_entries) {
735 struct mpc_config_bus bus;
736
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400737 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
738 "using default mptable. "
739 "(tell your hw vendor)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
741 bus.mpc_type = MP_BUS;
742 bus.mpc_busid = 0;
743 memcpy(bus.mpc_bustype, "ISA ", 6);
744 MP_bus_info(&bus);
745
746 construct_default_ioirq_mptable(0);
747 }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400748#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 } else
750 BUG();
751
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400752 if (!early)
753 printk(KERN_INFO "Processors: %d\n", num_processors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 /*
755 * Only use the first configuration found.
756 */
757}
758
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400759void __init early_get_smp_config(void)
760{
761 __get_smp_config(1);
762}
763
764void __init get_smp_config(void)
765{
766 __get_smp_config(0);
767}
768
769static int __init smp_scan_config(unsigned long base, unsigned long length,
770 unsigned reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771{
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400772 unsigned int *bp = phys_to_virt(base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 struct intel_mp_floating *mpf;
774
Yinghai Lu11a62a02008-05-12 15:43:38 +0200775 printk(KERN_DEBUG "Scan SMP from %p for %ld bytes.\n", bp, length);
Akinobu Mita5d47a272008-04-19 23:55:11 +0900776 BUILD_BUG_ON(sizeof(*mpf) != 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
778 while (length > 0) {
779 mpf = (struct intel_mp_floating *)bp;
780 if ((*bp == SMP_MAGIC_IDENT) &&
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400781 (mpf->mpf_length == 1) &&
782 !mpf_checksum((unsigned char *)bp, 16) &&
783 ((mpf->mpf_specification == 1)
784 || (mpf->mpf_specification == 4))) {
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400785#ifdef CONFIG_X86_LOCAL_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 smp_found_config = 1;
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400787#endif
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400788 mpf_found = mpf;
789#ifdef CONFIG_X86_32
Ingo Molnare91a3b42008-01-30 13:33:08 +0100790 printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400791 mpf, virt_to_phys(mpf));
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800792 reserve_bootmem(virt_to_phys(mpf), PAGE_SIZE,
793 BOOTMEM_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 if (mpf->mpf_physptr) {
795 /*
796 * We cannot access to MPC table to compute
797 * table size yet, as only few megabytes from
798 * the bottom is mapped now.
799 * PC-9800's MPC table places on the very last
800 * of physical memory; so that simply reserving
801 * PAGE_SIZE from mpg->mpf_physptr yields BUG()
802 * in reserve_bootmem.
803 */
804 unsigned long size = PAGE_SIZE;
805 unsigned long end = max_low_pfn * PAGE_SIZE;
806 if (mpf->mpf_physptr + size > end)
807 size = end - mpf->mpf_physptr;
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800808 reserve_bootmem(mpf->mpf_physptr, size,
809 BOOTMEM_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 }
811
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400812#else
813 if (!reserve)
814 return 1;
815
816 reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE);
817 if (mpf->mpf_physptr)
818 reserve_bootmem_generic(mpf->mpf_physptr,
819 PAGE_SIZE);
820#endif
821 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 }
823 bp += 4;
824 length -= 16;
825 }
826 return 0;
827}
828
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400829static void __init __find_smp_config(unsigned reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830{
831 unsigned int address;
832
833 /*
834 * FIXME: Linux assumes you have 640K of base ram..
835 * this continues the error...
836 *
837 * 1) Scan the bottom 1K for a signature
838 * 2) Scan the top 1K of base RAM
839 * 3) Scan the 64K of bios
840 */
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400841 if (smp_scan_config(0x0, 0x400, reserve) ||
842 smp_scan_config(639 * 0x400, 0x400, reserve) ||
843 smp_scan_config(0xF0000, 0x10000, reserve))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 return;
845 /*
846 * If it is an SMP machine we should know now, unless the
847 * configuration is in an EISA/MCA bus machine with an
848 * extended bios data area.
849 *
850 * there is a real-mode segmented pointer pointing to the
851 * 4K EBDA area at 0x40E, calculate and scan it here.
852 *
853 * NOTE! There are Linux loaders that will corrupt the EBDA
854 * area, and as such this kind of SMP config may be less
855 * trustworthy, simply because the SMP table may have been
856 * stomped on during early boot. These loaders are buggy and
857 * should be fixed.
858 *
859 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
860 */
861
862 address = get_bios_ebda();
863 if (address)
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400864 smp_scan_config(address, 0x400, reserve);
865}
866
867void __init early_find_smp_config(void)
868{
869 __find_smp_config(0);
870}
871
872void __init find_smp_config(void)
873{
874 __find_smp_config(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875}
Yinghai Lu2944e162008-06-01 13:17:38 -0700876
877#ifdef CONFIG_X86_IO_APIC
878static u8 __initdata irq_used[MAX_IRQ_SOURCES];
879
880static int __init get_MP_intsrc_index(struct mpc_config_intsrc *m)
881{
882 int i;
883
884 if (m->mpc_irqtype != mp_INT)
885 return 0;
886
887 if (m->mpc_irqflag != 0x0f)
888 return 0;
889
890 /* not legacy */
891
892 for (i = 0; i < mp_irq_entries; i++) {
893 if (mp_irqs[i].mp_irqtype != mp_INT)
894 continue;
895
896 if (mp_irqs[i].mp_irqflag != 0x0f)
897 continue;
898
899 if (mp_irqs[i].mp_srcbus != m->mpc_srcbus)
900 continue;
901 if (mp_irqs[i].mp_srcbusirq != m->mpc_srcbusirq)
902 continue;
903 if (irq_used[i]) {
904 /* already claimed */
905 return -2;
906 }
907 irq_used[i] = 1;
908 return i;
909 }
910
911 /* not found */
912 return -1;
913}
914
915#define SPARE_SLOT_NUM 20
916
917static struct mpc_config_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
918#endif
919
920static int __init replace_intsrc_all(struct mp_config_table *mpc,
921 unsigned long mpc_new_phys,
922 unsigned long mpc_new_length)
923{
924#ifdef CONFIG_X86_IO_APIC
925 int i;
926 int nr_m_spare = 0;
927#endif
928
929 int count = sizeof(*mpc);
930 unsigned char *mpt = ((unsigned char *)mpc) + count;
931
932 printk(KERN_INFO "mpc_length %x\n", mpc->mpc_length);
933 while (count < mpc->mpc_length) {
934 switch (*mpt) {
935 case MP_PROCESSOR:
936 {
937 struct mpc_config_processor *m =
938 (struct mpc_config_processor *)mpt;
939 mpt += sizeof(*m);
940 count += sizeof(*m);
941 break;
942 }
943 case MP_BUS:
944 {
945 struct mpc_config_bus *m =
946 (struct mpc_config_bus *)mpt;
947 mpt += sizeof(*m);
948 count += sizeof(*m);
949 break;
950 }
951 case MP_IOAPIC:
952 {
953 mpt += sizeof(struct mpc_config_ioapic);
954 count += sizeof(struct mpc_config_ioapic);
955 break;
956 }
957 case MP_INTSRC:
958 {
959#ifdef CONFIG_X86_IO_APIC
960 struct mpc_config_intsrc *m =
961 (struct mpc_config_intsrc *)mpt;
962
963 printk(KERN_INFO "OLD ");
964 print_MP_intsrc_info(m);
965 i = get_MP_intsrc_index(m);
966 if (i > 0) {
967 assign_to_mpc_intsrc(&mp_irqs[i], m);
968 printk(KERN_INFO "NEW ");
969 print_mp_irq_info(&mp_irqs[i]);
970 } else if (!i) {
971 /* legacy, do nothing */
972 } else if (nr_m_spare < SPARE_SLOT_NUM) {
973 /*
974 * not found (-1), or duplicated (-2)
975 * are invalid entries,
976 * we need to use the slot later
977 */
978 m_spare[nr_m_spare] = m;
979 nr_m_spare++;
980 }
981#endif
982 mpt += sizeof(struct mpc_config_intsrc);
983 count += sizeof(struct mpc_config_intsrc);
984 break;
985 }
986 case MP_LINTSRC:
987 {
988 struct mpc_config_lintsrc *m =
989 (struct mpc_config_lintsrc *)mpt;
990 mpt += sizeof(*m);
991 count += sizeof(*m);
992 break;
993 }
994 default:
995 /* wrong mptable */
996 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
997 printk(KERN_ERR "type %x\n", *mpt);
998 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
999 1, mpc, mpc->mpc_length, 1);
1000 goto out;
1001 }
1002 }
1003
1004#ifdef CONFIG_X86_IO_APIC
1005 for (i = 0; i < mp_irq_entries; i++) {
1006 if (irq_used[i])
1007 continue;
1008
1009 if (mp_irqs[i].mp_irqtype != mp_INT)
1010 continue;
1011
1012 if (mp_irqs[i].mp_irqflag != 0x0f)
1013 continue;
1014
1015 if (nr_m_spare > 0) {
1016 printk(KERN_INFO "*NEW* found ");
1017 nr_m_spare--;
1018 assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
1019 m_spare[nr_m_spare] = NULL;
1020 } else {
1021 struct mpc_config_intsrc *m =
1022 (struct mpc_config_intsrc *)mpt;
1023 count += sizeof(struct mpc_config_intsrc);
1024 if (!mpc_new_phys) {
1025 printk(KERN_INFO "No spare slots, try to append...take your risk, new mpc_length %x\n", count);
1026 } else {
1027 if (count <= mpc_new_length)
1028 printk(KERN_INFO "No spare slots, try to append..., new mpc_length %x\n", count);
1029 else {
1030 printk(KERN_ERR "mpc_new_length %lx is too small\n", mpc_new_length);
1031 goto out;
1032 }
1033 }
1034 assign_to_mpc_intsrc(&mp_irqs[i], m);
1035 mpc->mpc_length = count;
1036 mpt += sizeof(struct mpc_config_intsrc);
1037 }
1038 print_mp_irq_info(&mp_irqs[i]);
1039 }
1040#endif
1041out:
1042 /* update checksum */
1043 mpc->mpc_checksum = 0;
1044 mpc->mpc_checksum -= mpf_checksum((unsigned char *)mpc,
1045 mpc->mpc_length);
1046
1047 return 0;
1048}
1049
1050int __initdata enable_update_mptable;
1051
1052static int __init update_mptable_setup(char *str)
1053{
1054 enable_update_mptable = 1;
1055 return 0;
1056}
1057early_param("update_mptable", update_mptable_setup);
1058
1059static unsigned long __initdata mpc_new_phys;
1060static unsigned long mpc_new_length __initdata = 4096;
1061
1062/* alloc_mptable or alloc_mptable=4k */
1063static int __initdata alloc_mptable;
1064static int __init parse_alloc_mptable_opt(char *p)
1065{
1066 enable_update_mptable = 1;
1067 alloc_mptable = 1;
1068 if (!p)
1069 return 0;
1070 mpc_new_length = memparse(p, &p);
1071 return 0;
1072}
1073early_param("alloc_mptable", parse_alloc_mptable_opt);
1074
1075void __init early_reserve_e820_mpc_new(void)
1076{
1077 if (enable_update_mptable && alloc_mptable) {
1078 u64 startt = 0;
1079#ifdef CONFIG_X86_TRAMPOLINE
1080 startt = TRAMPOLINE_BASE;
1081#endif
1082 mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
1083 }
1084}
1085
1086static int __init update_mp_table(void)
1087{
1088 char str[16];
1089 char oem[10];
1090 struct intel_mp_floating *mpf;
1091 struct mp_config_table *mpc;
1092 struct mp_config_table *mpc_new;
1093
1094 if (!enable_update_mptable)
1095 return 0;
1096
1097 mpf = mpf_found;
1098 if (!mpf)
1099 return 0;
1100
1101 /*
1102 * Now see if we need to go further.
1103 */
1104 if (mpf->mpf_feature1 != 0)
1105 return 0;
1106
1107 if (!mpf->mpf_physptr)
1108 return 0;
1109
1110 mpc = phys_to_virt(mpf->mpf_physptr);
1111
1112 if (!smp_check_mpc(mpc, oem, str))
1113 return 0;
1114
1115 printk(KERN_INFO "mpf: %lx\n", virt_to_phys(mpf));
1116 printk(KERN_INFO "mpf_physptr: %x\n", mpf->mpf_physptr);
1117
1118 if (mpc_new_phys && mpc->mpc_length > mpc_new_length) {
1119 mpc_new_phys = 0;
1120 printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
1121 mpc_new_length);
1122 }
1123
1124 if (!mpc_new_phys) {
1125 unsigned char old, new;
1126 /* check if we can change the postion */
1127 mpc->mpc_checksum = 0;
1128 old = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
1129 mpc->mpc_checksum = 0xff;
1130 new = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
1131 if (old == new) {
1132 printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
1133 return 0;
1134 }
1135 printk(KERN_INFO "use in-positon replacing\n");
1136 } else {
1137 mpf->mpf_physptr = mpc_new_phys;
1138 mpc_new = phys_to_virt(mpc_new_phys);
1139 memcpy(mpc_new, mpc, mpc->mpc_length);
1140 mpc = mpc_new;
1141 /* check if we can modify that */
1142 if (mpc_new_phys - mpf->mpf_physptr) {
1143 struct intel_mp_floating *mpf_new;
1144 /* steal 16 bytes from [0, 1k) */
1145 printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
1146 mpf_new = phys_to_virt(0x400 - 16);
1147 memcpy(mpf_new, mpf, 16);
1148 mpf = mpf_new;
1149 mpf->mpf_physptr = mpc_new_phys;
1150 }
1151 mpf->mpf_checksum = 0;
1152 mpf->mpf_checksum -= mpf_checksum((unsigned char *)mpf, 16);
1153 printk(KERN_INFO "mpf_physptr new: %x\n", mpf->mpf_physptr);
1154 }
1155
1156 /*
1157 * only replace the one with mp_INT and
1158 * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
1159 * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
1160 * may need pci=routeirq for all coverage
1161 */
1162 replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
1163
1164 return 0;
1165}
1166
1167late_initcall(update_mp_table);