blob: b62ac6ba1410e439e7e49d0abfb8eff9f57458bb [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
Yinghai Lud49c4282008-06-08 18:31:54 -070052int found_numaq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053/*
54 * Have to match translation table entries to main table entries by counter
55 * hence the mpc_record variable .... can't see a less disgusting way of
56 * doing this ....
57 */
Yinghai Lud49c4282008-06-08 18:31:54 -070058struct mpc_config_translation {
59 unsigned char mpc_type;
60 unsigned char trans_len;
61 unsigned char trans_type;
62 unsigned char trans_quad;
63 unsigned char trans_global;
64 unsigned char trans_local;
65 unsigned short trans_reserved;
66};
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +040069static int mpc_record;
70static struct mpc_config_translation *translation_table[MAX_MPC_ENTRY]
71 __cpuinitdata;
Yinghai Lud49c4282008-06-08 18:31:54 -070072
73static inline int generate_logical_apicid(int quad, int phys_apicid)
74{
75 return (quad << 4) + (phys_apicid ? phys_apicid << 1 : 1);
76}
77
78
79static inline int mpc_apic_id(struct mpc_config_processor *m,
80 struct mpc_config_translation *translation_record)
81{
82 int quad = translation_record->trans_quad;
83 int logical_apicid = generate_logical_apicid(quad, m->mpc_apicid);
84
85 printk(KERN_DEBUG "Processor #%d %u:%u APIC version %d (quad %d, apic %d)\n",
86 m->mpc_apicid,
87 (m->mpc_cpufeature & CPU_FAMILY_MASK) >> 8,
88 (m->mpc_cpufeature & CPU_MODEL_MASK) >> 4,
89 m->mpc_apicver, quad, logical_apicid);
90 return logical_apicid;
91}
92
93int mp_bus_id_to_node[MAX_MP_BUSSES];
94
95int mp_bus_id_to_local[MAX_MP_BUSSES];
96
97static void mpc_oem_bus_info(struct mpc_config_bus *m, char *name,
98 struct mpc_config_translation *translation)
99{
100 int quad = translation->trans_quad;
101 int local = translation->trans_local;
102
103 mp_bus_id_to_node[m->mpc_busid] = quad;
104 mp_bus_id_to_local[m->mpc_busid] = local;
105 printk(KERN_INFO "Bus #%d is %s (node %d)\n",
106 m->mpc_busid, name, quad);
107}
108
109int quad_local_to_mp_bus_id [NR_CPUS/4][4];
110static void mpc_oem_pci_bus(struct mpc_config_bus *m,
111 struct mpc_config_translation *translation)
112{
113 int quad = translation->trans_quad;
114 int local = translation->trans_local;
115
116 quad_local_to_mp_bus_id[quad][local] = m->mpc_busid;
117}
118
Alexey Starikovskiy86420502008-03-17 22:08:55 +0300119#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Alexey Starikovskiyc853c672008-03-27 23:54:13 +0300121static void __cpuinit MP_processor_info(struct mpc_config_processor *m)
122{
123 int apicid;
Alexey Starikovskiy746f2242008-04-04 23:42:15 +0400124 char *bootup_cpu = "";
Alexey Starikovskiyc853c672008-03-27 23:54:13 +0300125
Glauber Costa7b1292e2008-03-03 14:12:41 -0300126 if (!(m->mpc_cpuflag & CPU_ENABLED)) {
127 disabled_cpus++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 return;
Glauber Costa7b1292e2008-03-03 14:12:41 -0300129 }
Alexey Starikovskiy4655c7d2008-03-17 22:08:36 +0300130#ifdef CONFIG_X86_NUMAQ
Yinghai Luab530e12008-06-03 10:25:54 -0700131 if (found_numaq)
132 apicid = mpc_apic_id(m, translation_table[mpc_record]);
133 else
134 apicid = m->mpc_apicid;
Alexey Starikovskiy4655c7d2008-03-17 22:08:36 +0300135#else
Alexey Starikovskiy4655c7d2008-03-17 22:08:36 +0300136 apicid = m->mpc_apicid;
137#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
Alexey Starikovskiy746f2242008-04-04 23:42:15 +0400139 bootup_cpu = " (Bootup-CPU)";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 boot_cpu_physical_apicid = m->mpc_apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 }
142
Alexey Starikovskiy746f2242008-04-04 23:42:15 +0400143 printk(KERN_INFO "Processor #%d%s\n", m->mpc_apicid, bootup_cpu);
Alexey Starikovskiyc853c672008-03-27 23:54:13 +0300144 generic_processor_info(apicid, m->mpc_apicver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145}
146
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200147#ifdef CONFIG_X86_IO_APIC
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400148static void __init MP_bus_info(struct mpc_config_bus *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
150 char str[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 memcpy(str, m->mpc_bustype, 6);
152 str[6] = 0;
153
Alexey Starikovskiy0ec153a2008-03-17 22:08:48 +0300154#ifdef CONFIG_X86_NUMAQ
Yinghai Luab530e12008-06-03 10:25:54 -0700155 if (found_numaq)
156 mpc_oem_bus_info(m, str, translation_table[mpc_record]);
Alexey Starikovskiy0ec153a2008-03-17 22:08:48 +0300157#else
Yinghai Lu11a62a02008-05-12 15:43:38 +0200158 printk(KERN_INFO "Bus #%d is %s\n", m->mpc_busid, str);
Alexey Starikovskiy0ec153a2008-03-17 22:08:48 +0300159#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Andi Kleen5e4edbb2006-09-26 10:52:35 +0200161#if MAX_MP_BUSSES < 256
Randy Dunlapc0ec31a2006-04-10 22:53:13 -0700162 if (m->mpc_busid >= MAX_MP_BUSSES) {
163 printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400164 " is too large, max. supported is %d\n",
165 m->mpc_busid, str, MAX_MP_BUSSES - 1);
Randy Dunlapc0ec31a2006-04-10 22:53:13 -0700166 return;
167 }
Andi Kleen5e4edbb2006-09-26 10:52:35 +0200168#endif
Randy Dunlapc0ec31a2006-04-10 22:53:13 -0700169
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +0400170 if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
171 set_bit(m->mpc_busid, mp_bus_not_pci);
172#if defined(CONFIG_EISA) || defined (CONFIG_MCA)
173 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA;
174#endif
175 } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
Alexey Starikovskiyd285e332008-03-17 22:08:42 +0300176#ifdef CONFIG_X86_NUMAQ
Yinghai Luab530e12008-06-03 10:25:54 -0700177 if (found_numaq)
178 mpc_oem_pci_bus(m, translation_table[mpc_record]);
Alexey Starikovskiyd285e332008-03-17 22:08:42 +0300179#endif
Alexey Starikovskiya6333c32008-03-20 14:54:09 +0300180 clear_bit(m->mpc_busid, mp_bus_not_pci);
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +0300181#if defined(CONFIG_EISA) || defined (CONFIG_MCA)
182 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400183 } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
Alexey Starikovskiy9e0a2de2008-03-20 14:54:56 +0300184 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400185 } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_MCA;
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +0300187#endif
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +0400188 } else
189 printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190}
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200191#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400193#ifdef CONFIG_X86_IO_APIC
194
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300195static int bad_ioapic(unsigned long address)
196{
197 if (nr_ioapics >= MAX_IO_APICS) {
198 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
199 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
200 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
201 }
202 if (!address) {
203 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
204 " found in table, skipping!\n");
205 return 1;
206 }
207 return 0;
208}
209
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400210static void __init MP_ioapic_info(struct mpc_config_ioapic *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211{
212 if (!(m->mpc_flags & MPC_APIC_USABLE))
213 return;
214
Thomas Gleixner64883ab2008-01-30 13:30:35 +0100215 printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400216 m->mpc_apicid, m->mpc_apicver, m->mpc_apicaddr);
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300217
218 if (bad_ioapic(m->mpc_apicaddr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 return;
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300220
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400221 mp_ioapics[nr_ioapics].mp_apicaddr = m->mpc_apicaddr;
222 mp_ioapics[nr_ioapics].mp_apicid = m->mpc_apicid;
223 mp_ioapics[nr_ioapics].mp_type = m->mpc_type;
224 mp_ioapics[nr_ioapics].mp_apicver = m->mpc_apicver;
225 mp_ioapics[nr_ioapics].mp_flags = m->mpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 nr_ioapics++;
227}
228
Yinghai Lu2944e162008-06-01 13:17:38 -0700229static void print_MP_intsrc_info(struct mpc_config_intsrc *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230{
Yinghai Lu2944e162008-06-01 13:17:38 -0700231 printk(KERN_CONT "Int: type %d, pol %d, trig %d, bus %02x,"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400233 m->mpc_irqtype, m->mpc_irqflag & 3,
234 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
235 m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
Yinghai Lu2944e162008-06-01 13:17:38 -0700236}
237
238static void __init print_mp_irq_info(struct mp_config_intsrc *mp_irq)
239{
240 printk(KERN_CONT "Int: type %d, pol %d, trig %d, bus %02x,"
241 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
242 mp_irq->mp_irqtype, mp_irq->mp_irqflag & 3,
243 (mp_irq->mp_irqflag >> 2) & 3, mp_irq->mp_srcbus,
244 mp_irq->mp_srcbusirq, mp_irq->mp_dstapic, mp_irq->mp_dstirq);
245}
246
247static void assign_to_mp_irq(struct mpc_config_intsrc *m,
248 struct mp_config_intsrc *mp_irq)
249{
250 mp_irq->mp_dstapic = m->mpc_dstapic;
251 mp_irq->mp_type = m->mpc_type;
252 mp_irq->mp_irqtype = m->mpc_irqtype;
253 mp_irq->mp_irqflag = m->mpc_irqflag;
254 mp_irq->mp_srcbus = m->mpc_srcbus;
255 mp_irq->mp_srcbusirq = m->mpc_srcbusirq;
256 mp_irq->mp_dstirq = m->mpc_dstirq;
257}
258
259static void __init assign_to_mpc_intsrc(struct mp_config_intsrc *mp_irq,
260 struct mpc_config_intsrc *m)
261{
262 m->mpc_dstapic = mp_irq->mp_dstapic;
263 m->mpc_type = mp_irq->mp_type;
264 m->mpc_irqtype = mp_irq->mp_irqtype;
265 m->mpc_irqflag = mp_irq->mp_irqflag;
266 m->mpc_srcbus = mp_irq->mp_srcbus;
267 m->mpc_srcbusirq = mp_irq->mp_srcbusirq;
268 m->mpc_dstirq = mp_irq->mp_dstirq;
269}
270
271static int mp_irq_mpc_intsrc_cmp(struct mp_config_intsrc *mp_irq,
272 struct mpc_config_intsrc *m)
273{
274 if (mp_irq->mp_dstapic != m->mpc_dstapic)
275 return 1;
276 if (mp_irq->mp_type != m->mpc_type)
277 return 2;
278 if (mp_irq->mp_irqtype != m->mpc_irqtype)
279 return 3;
280 if (mp_irq->mp_irqflag != m->mpc_irqflag)
281 return 4;
282 if (mp_irq->mp_srcbus != m->mpc_srcbus)
283 return 5;
284 if (mp_irq->mp_srcbusirq != m->mpc_srcbusirq)
285 return 6;
286 if (mp_irq->mp_dstirq != m->mpc_dstirq)
287 return 7;
288
289 return 0;
290}
291
292void MP_intsrc_info(struct mpc_config_intsrc *m)
293{
294 int i;
295
296 print_MP_intsrc_info(m);
297
298 for (i = 0; i < mp_irq_entries; i++) {
299 if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m))
300 return;
301 }
302
303 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 if (++mp_irq_entries == MAX_IRQ_SOURCES)
305 panic("Max # of irq sources exceeded!!\n");
306}
307
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400308#endif
309
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400310static void __init MP_lintsrc_info(struct mpc_config_lintsrc *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311{
Yinghai Lu11a62a02008-05-12 15:43:38 +0200312 printk(KERN_INFO "Lint: type %d, pol %d, trig %d, bus %02x,"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400314 m->mpc_irqtype, m->mpc_irqflag & 3,
315 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbusid,
316 m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317}
318
319#ifdef CONFIG_X86_NUMAQ
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400320static void __init MP_translation_info(struct mpc_config_translation *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321{
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400322 printk(KERN_INFO
323 "Translation: record %d, type %d, quad %d, global %d, local %d\n",
324 mpc_record, m->trans_type, m->trans_quad, m->trans_global,
325 m->trans_local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400327 if (mpc_record >= MAX_MPC_ENTRY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 printk(KERN_ERR "MAX_MPC_ENTRY exceeded!\n");
329 else
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400330 translation_table[mpc_record] = m; /* stash this for later */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 if (m->trans_quad < MAX_NUMNODES && !node_online(m->trans_quad))
332 node_set_online(m->trans_quad);
333}
334
335/*
336 * Read/parse the MPC oem tables
337 */
338
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400339static void __init smp_read_mpc_oem(struct mp_config_oemtable *oemtable,
340 unsigned short oemsize)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341{
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400342 int count = sizeof(*oemtable); /* the header size */
343 unsigned char *oemptr = ((unsigned char *)oemtable) + count;
344
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 mpc_record = 0;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400346 printk(KERN_INFO "Found an OEM MPC table at %8p - parsing it ... \n",
347 oemtable);
348 if (memcmp(oemtable->oem_signature, MPC_OEM_SIGNATURE, 4)) {
349 printk(KERN_WARNING
350 "SMP mpc oemtable: bad signature [%c%c%c%c]!\n",
351 oemtable->oem_signature[0], oemtable->oem_signature[1],
352 oemtable->oem_signature[2], oemtable->oem_signature[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 return;
354 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400355 if (mpf_checksum((unsigned char *)oemtable, oemtable->oem_length)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 printk(KERN_WARNING "SMP oem mptable: checksum error!\n");
357 return;
358 }
359 while (count < oemtable->oem_length) {
360 switch (*oemptr) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400361 case MP_TRANSLATION:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400363 struct mpc_config_translation *m =
364 (struct mpc_config_translation *)oemptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 MP_translation_info(m);
366 oemptr += sizeof(*m);
367 count += sizeof(*m);
368 ++mpc_record;
369 break;
370 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400371 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400373 printk(KERN_WARNING
374 "Unrecognised OEM table entry type! - %d\n",
375 (int)*oemptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 return;
377 }
378 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400379 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380}
381
Yinghai Lud49c4282008-06-08 18:31:54 -0700382void numaq_mps_oem_check(struct mp_config_table *mpc, char *oem,
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400383 char *productid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384{
385 if (strncmp(oem, "IBM NUMA", 8))
Yinghai Lud49c4282008-06-08 18:31:54 -0700386 printk("Warning! Not a NUMA-Q system!\n");
Yinghai Luab530e12008-06-03 10:25:54 -0700387 else
388 found_numaq = 1;
389
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 if (mpc->mpc_oemptr)
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400391 smp_read_mpc_oem((struct mp_config_oemtable *)mpc->mpc_oemptr,
392 mpc->mpc_oemsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393}
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400394#endif /* CONFIG_X86_NUMAQ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
396/*
397 * Read/parse the MPC
398 */
399
Yinghai Lu2944e162008-06-01 13:17:38 -0700400static int __init smp_check_mpc(struct mp_config_table *mpc, char *oem,
401 char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400404 if (memcmp(mpc->mpc_signature, MPC_SIGNATURE, 4)) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400405 printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
406 mpc->mpc_signature[0], mpc->mpc_signature[1],
407 mpc->mpc_signature[2], mpc->mpc_signature[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 return 0;
409 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400410 if (mpf_checksum((unsigned char *)mpc, mpc->mpc_length)) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400411 printk(KERN_ERR "MPTABLE: checksum error!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 return 0;
413 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400414 if (mpc->mpc_spec != 0x01 && mpc->mpc_spec != 0x04) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400415 printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400416 mpc->mpc_spec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 return 0;
418 }
419 if (!mpc->mpc_lapic) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400420 printk(KERN_ERR "MPTABLE: null local APIC address!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 return 0;
422 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400423 memcpy(oem, mpc->mpc_oem, 8);
424 oem[8] = 0;
Yinghai Lu11a62a02008-05-12 15:43:38 +0200425 printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400427 memcpy(str, mpc->mpc_productid, 12);
428 str[12] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Yinghai Lu11a62a02008-05-12 15:43:38 +0200430 printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400432 printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->mpc_lapic);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
Yinghai Lu2944e162008-06-01 13:17:38 -0700434 return 1;
435}
436
437static int __init smp_read_mpc(struct mp_config_table *mpc, unsigned early)
438{
439 char str[16];
440 char oem[10];
441
442 int count = sizeof(*mpc);
443 unsigned char *mpt = ((unsigned char *)mpc) + count;
444
445 if (!smp_check_mpc(mpc, oem, str))
446 return 0;
447
448#ifdef CONFIG_X86_32
Yinghai Lud49c4282008-06-08 18:31:54 -0700449 /*
450 * need to make sure summit and es7000's mps_oem_check is safe to be
451 * called early via genericarch 's mps_oem_check
452 */
453 if (early) {
454#ifdef CONFIG_X86_NUMAQ
455 numaq_mps_oem_check(mpc, oem, str);
456#endif
457 } else
458 mps_oem_check(mpc, oem, str);
Yinghai Lu2944e162008-06-01 13:17:38 -0700459#endif
460
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400461 /* save the local APIC address, it might be non-default */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 if (!acpi_lapic)
463 mp_lapic_addr = mpc->mpc_lapic;
464
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400465 if (early)
466 return 1;
467
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 /*
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400469 * Now process the configuration blocks.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 */
Alexey Starikovskiy86420502008-03-17 22:08:55 +0300471#ifdef CONFIG_X86_NUMAQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 mpc_record = 0;
Alexey Starikovskiy86420502008-03-17 22:08:55 +0300473#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 while (count < mpc->mpc_length) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400475 switch (*mpt) {
476 case MP_PROCESSOR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400478 struct mpc_config_processor *m =
479 (struct mpc_config_processor *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 /* ACPI may have already provided this data */
481 if (!acpi_lapic)
482 MP_processor_info(m);
483 mpt += sizeof(*m);
484 count += sizeof(*m);
485 break;
486 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400487 case MP_BUS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400489 struct mpc_config_bus *m =
490 (struct mpc_config_bus *)mpt;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200491#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 MP_bus_info(m);
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200493#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 mpt += sizeof(*m);
495 count += sizeof(*m);
496 break;
497 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400498 case MP_IOAPIC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 {
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400500#ifdef CONFIG_X86_IO_APIC
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400501 struct mpc_config_ioapic *m =
502 (struct mpc_config_ioapic *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 MP_ioapic_info(m);
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400504#endif
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400505 mpt += sizeof(struct mpc_config_ioapic);
506 count += sizeof(struct mpc_config_ioapic);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 break;
508 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400509 case MP_INTSRC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 {
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400511#ifdef CONFIG_X86_IO_APIC
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400512 struct mpc_config_intsrc *m =
513 (struct mpc_config_intsrc *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
515 MP_intsrc_info(m);
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400516#endif
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400517 mpt += sizeof(struct mpc_config_intsrc);
518 count += sizeof(struct mpc_config_intsrc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 break;
520 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400521 case MP_LINTSRC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400523 struct mpc_config_lintsrc *m =
524 (struct mpc_config_lintsrc *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 MP_lintsrc_info(m);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400526 mpt += sizeof(*m);
527 count += sizeof(*m);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 break;
529 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400530 default:
Yinghai Lu711554d2008-04-07 11:36:39 -0700531 /* wrong mptable */
532 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
533 printk(KERN_ERR "type %x\n", *mpt);
534 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
535 1, mpc, mpc->mpc_length, 1);
536 count = mpc->mpc_length;
537 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 }
Alexey Starikovskiy86420502008-03-17 22:08:55 +0300539#ifdef CONFIG_X86_NUMAQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 ++mpc_record;
Alexey Starikovskiy86420502008-03-17 22:08:55 +0300541#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 }
Yinghai Lue0da3362008-06-08 18:29:22 -0700543
544#ifdef CONFIG_X86_GENERICARCH
545 generic_bigsmp_probe();
546#endif
547
Ingo Molnar3c43f032007-05-02 19:27:04 +0200548 setup_apic_routing();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 if (!num_processors)
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400550 printk(KERN_ERR "MPTABLE: no processors registered!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 return num_processors;
552}
553
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400554#ifdef CONFIG_X86_IO_APIC
555
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556static int __init ELCR_trigger(unsigned int irq)
557{
558 unsigned int port;
559
560 port = 0x4d0 + (irq >> 3);
561 return (inb(port) >> (irq & 7)) & 1;
562}
563
564static void __init construct_default_ioirq_mptable(int mpc_default_type)
565{
566 struct mpc_config_intsrc intsrc;
567 int i;
568 int ELCR_fallback = 0;
569
570 intsrc.mpc_type = MP_INTSRC;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400571 intsrc.mpc_irqflag = 0; /* conforming */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 intsrc.mpc_srcbus = 0;
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400573 intsrc.mpc_dstapic = mp_ioapics[0].mp_apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
575 intsrc.mpc_irqtype = mp_INT;
576
577 /*
578 * If true, we have an ISA/PCI system with no IRQ entries
579 * in the MP table. To prevent the PCI interrupts from being set up
580 * incorrectly, we try to use the ELCR. The sanity check to see if
581 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
582 * never be level sensitive, so we simply see if the ELCR agrees.
583 * If it does, we assume it's valid.
584 */
585 if (mpc_default_type == 5) {
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400586 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
587 "falling back to ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400589 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
590 ELCR_trigger(13))
591 printk(KERN_ERR "ELCR contains invalid data... "
592 "not using ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 else {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400594 printk(KERN_INFO
595 "Using ELCR to identify PCI interrupts\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 ELCR_fallback = 1;
597 }
598 }
599
600 for (i = 0; i < 16; i++) {
601 switch (mpc_default_type) {
602 case 2:
603 if (i == 0 || i == 13)
604 continue; /* IRQ0 & IRQ13 not connected */
605 /* fall through */
606 default:
607 if (i == 2)
608 continue; /* IRQ2 is never connected */
609 }
610
611 if (ELCR_fallback) {
612 /*
613 * If the ELCR indicates a level-sensitive interrupt, we
614 * copy that information over to the MP table in the
615 * irqflag field (level sensitive, active high polarity).
616 */
617 if (ELCR_trigger(i))
618 intsrc.mpc_irqflag = 13;
619 else
620 intsrc.mpc_irqflag = 0;
621 }
622
623 intsrc.mpc_srcbusirq = i;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400624 intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 MP_intsrc_info(&intsrc);
626 }
627
628 intsrc.mpc_irqtype = mp_ExtINT;
629 intsrc.mpc_srcbusirq = 0;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400630 intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 MP_intsrc_info(&intsrc);
632}
633
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400634
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200635static void construct_ioapic_table(int mpc_default_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 struct mpc_config_ioapic ioapic;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200638 struct mpc_config_bus bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
640 bus.mpc_type = MP_BUS;
641 bus.mpc_busid = 0;
642 switch (mpc_default_type) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400643 default:
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400644 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400645 mpc_default_type);
646 /* fall through */
647 case 1:
648 case 5:
649 memcpy(bus.mpc_bustype, "ISA ", 6);
650 break;
651 case 2:
652 case 6:
653 case 3:
654 memcpy(bus.mpc_bustype, "EISA ", 6);
655 break;
656 case 4:
657 case 7:
658 memcpy(bus.mpc_bustype, "MCA ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 }
660 MP_bus_info(&bus);
661 if (mpc_default_type > 4) {
662 bus.mpc_busid = 1;
663 memcpy(bus.mpc_bustype, "PCI ", 6);
664 MP_bus_info(&bus);
665 }
666
667 ioapic.mpc_type = MP_IOAPIC;
668 ioapic.mpc_apicid = 2;
669 ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
670 ioapic.mpc_flags = MPC_APIC_USABLE;
671 ioapic.mpc_apicaddr = 0xFEC00000;
672 MP_ioapic_info(&ioapic);
673
674 /*
675 * We set up most of the low 16 IO-APIC pins according to MPS rules.
676 */
677 construct_default_ioirq_mptable(mpc_default_type);
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200678}
679#else
680static inline void construct_ioapic_table(int mpc_default_type) { }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400681#endif
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200682
683static inline void __init construct_default_ISA_mptable(int mpc_default_type)
684{
685 struct mpc_config_processor processor;
686 struct mpc_config_lintsrc lintsrc;
687 int linttypes[2] = { mp_ExtINT, mp_NMI };
688 int i;
689
690 /*
691 * local APIC has default address
692 */
693 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
694
695 /*
696 * 2 CPUs, numbered 0 & 1.
697 */
698 processor.mpc_type = MP_PROCESSOR;
699 /* Either an integrated APIC or a discrete 82489DX. */
700 processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
701 processor.mpc_cpuflag = CPU_ENABLED;
702 processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
703 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
704 processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
705 processor.mpc_reserved[0] = 0;
706 processor.mpc_reserved[1] = 0;
707 for (i = 0; i < 2; i++) {
708 processor.mpc_apicid = i;
709 MP_processor_info(&processor);
710 }
711
712 construct_ioapic_table(mpc_default_type);
713
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 lintsrc.mpc_type = MP_LINTSRC;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400715 lintsrc.mpc_irqflag = 0; /* conforming */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 lintsrc.mpc_srcbusid = 0;
717 lintsrc.mpc_srcbusirq = 0;
718 lintsrc.mpc_destapic = MP_APIC_ALL;
719 for (i = 0; i < 2; i++) {
720 lintsrc.mpc_irqtype = linttypes[i];
721 lintsrc.mpc_destapiclint = i;
722 MP_lintsrc_info(&lintsrc);
723 }
724}
725
726static struct intel_mp_floating *mpf_found;
727
728/*
729 * Scan the memory blocks for an SMP configuration block.
730 */
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400731static void __init __get_smp_config(unsigned early)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732{
733 struct intel_mp_floating *mpf = mpf_found;
734
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400735 if (acpi_lapic && early)
736 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 /*
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400738 * ACPI supports both logical (e.g. Hyper-Threading) and physical
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 * processors, where MPS only supports physical.
740 */
741 if (acpi_lapic && acpi_ioapic) {
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400742 printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
743 "information\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 return;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400745 } else if (acpi_lapic)
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400746 printk(KERN_INFO "Using ACPI for processor (LAPIC) "
747 "configuration information\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400749 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
750 mpf->mpf_specification);
Alexey Starikovskiyb3e24162008-05-23 01:54:44 +0400751#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400752 if (mpf->mpf_feature2 & (1 << 7)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
754 pic_mode = 1;
755 } else {
756 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
757 pic_mode = 0;
758 }
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400759#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 /*
761 * Now see if we need to read further.
762 */
763 if (mpf->mpf_feature1 != 0) {
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400764 if (early) {
765 /*
766 * local APIC has default address
767 */
768 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
769 return;
770 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400772 printk(KERN_INFO "Default MP configuration #%d\n",
773 mpf->mpf_feature1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 construct_default_ISA_mptable(mpf->mpf_feature1);
775
776 } else if (mpf->mpf_physptr) {
777
778 /*
779 * Read the physical hardware table. Anything here will
780 * override the defaults.
781 */
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400782 if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr), early)) {
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400783#ifdef CONFIG_X86_LOCAL_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 smp_found_config = 0;
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400785#endif
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400786 printk(KERN_ERR
787 "BIOS bug, MP table errors detected!...\n");
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400788 printk(KERN_ERR "... disabling SMP support. "
789 "(tell your hw vendor)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 return;
791 }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400792
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400793 if (early)
794 return;
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400795#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 /*
797 * If there are no explicit MP IRQ entries, then we are
798 * broken. We set up most of the low 16 IO-APIC pins to
799 * ISA defaults and hope it will work.
800 */
801 if (!mp_irq_entries) {
802 struct mpc_config_bus bus;
803
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400804 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
805 "using default mptable. "
806 "(tell your hw vendor)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
808 bus.mpc_type = MP_BUS;
809 bus.mpc_busid = 0;
810 memcpy(bus.mpc_bustype, "ISA ", 6);
811 MP_bus_info(&bus);
812
813 construct_default_ioirq_mptable(0);
814 }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400815#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 } else
817 BUG();
818
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400819 if (!early)
820 printk(KERN_INFO "Processors: %d\n", num_processors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 /*
822 * Only use the first configuration found.
823 */
824}
825
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400826void __init early_get_smp_config(void)
827{
828 __get_smp_config(1);
829}
830
831void __init get_smp_config(void)
832{
833 __get_smp_config(0);
834}
835
836static int __init smp_scan_config(unsigned long base, unsigned long length,
837 unsigned reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838{
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400839 unsigned int *bp = phys_to_virt(base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 struct intel_mp_floating *mpf;
841
Yinghai Lu11a62a02008-05-12 15:43:38 +0200842 printk(KERN_DEBUG "Scan SMP from %p for %ld bytes.\n", bp, length);
Akinobu Mita5d47a272008-04-19 23:55:11 +0900843 BUILD_BUG_ON(sizeof(*mpf) != 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844
845 while (length > 0) {
846 mpf = (struct intel_mp_floating *)bp;
847 if ((*bp == SMP_MAGIC_IDENT) &&
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400848 (mpf->mpf_length == 1) &&
849 !mpf_checksum((unsigned char *)bp, 16) &&
850 ((mpf->mpf_specification == 1)
851 || (mpf->mpf_specification == 4))) {
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400852#ifdef CONFIG_X86_LOCAL_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 smp_found_config = 1;
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400854#endif
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400855 mpf_found = mpf;
Yinghai Lub1f006b2008-06-09 18:11:36 -0700856
Ingo Molnare91a3b432008-01-30 13:33:08 +0100857 printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400858 mpf, virt_to_phys(mpf));
Yinghai Lub1f006b2008-06-09 18:11:36 -0700859
860 if (!reserve)
861 return 1;
Yinghai Lud2dbf342008-06-13 02:00:56 -0700862 reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE,
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800863 BOOTMEM_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 if (mpf->mpf_physptr) {
Yinghai Lud2dbf342008-06-13 02:00:56 -0700865 unsigned long size = PAGE_SIZE;
866#ifdef CONFIG_X86_32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 /*
868 * We cannot access to MPC table to compute
869 * table size yet, as only few megabytes from
870 * the bottom is mapped now.
871 * PC-9800's MPC table places on the very last
872 * of physical memory; so that simply reserving
873 * PAGE_SIZE from mpg->mpf_physptr yields BUG()
874 * in reserve_bootmem.
875 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 unsigned long end = max_low_pfn * PAGE_SIZE;
877 if (mpf->mpf_physptr + size > end)
878 size = end - mpf->mpf_physptr;
Yinghai Lud2dbf342008-06-13 02:00:56 -0700879#endif
880 reserve_bootmem_generic(mpf->mpf_physptr, size,
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800881 BOOTMEM_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 }
883
Yinghai Lud2dbf342008-06-13 02:00:56 -0700884 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 }
886 bp += 4;
887 length -= 16;
888 }
889 return 0;
890}
891
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400892static void __init __find_smp_config(unsigned reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893{
894 unsigned int address;
895
896 /*
897 * FIXME: Linux assumes you have 640K of base ram..
898 * this continues the error...
899 *
900 * 1) Scan the bottom 1K for a signature
901 * 2) Scan the top 1K of base RAM
902 * 3) Scan the 64K of bios
903 */
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400904 if (smp_scan_config(0x0, 0x400, reserve) ||
905 smp_scan_config(639 * 0x400, 0x400, reserve) ||
906 smp_scan_config(0xF0000, 0x10000, reserve))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 return;
908 /*
909 * If it is an SMP machine we should know now, unless the
910 * configuration is in an EISA/MCA bus machine with an
911 * extended bios data area.
912 *
913 * there is a real-mode segmented pointer pointing to the
914 * 4K EBDA area at 0x40E, calculate and scan it here.
915 *
916 * NOTE! There are Linux loaders that will corrupt the EBDA
917 * area, and as such this kind of SMP config may be less
918 * trustworthy, simply because the SMP table may have been
919 * stomped on during early boot. These loaders are buggy and
920 * should be fixed.
921 *
922 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
923 */
924
925 address = get_bios_ebda();
926 if (address)
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400927 smp_scan_config(address, 0x400, reserve);
928}
929
930void __init early_find_smp_config(void)
931{
932 __find_smp_config(0);
933}
934
935void __init find_smp_config(void)
936{
937 __find_smp_config(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938}
Yinghai Lu2944e162008-06-01 13:17:38 -0700939
940#ifdef CONFIG_X86_IO_APIC
941static u8 __initdata irq_used[MAX_IRQ_SOURCES];
942
943static int __init get_MP_intsrc_index(struct mpc_config_intsrc *m)
944{
945 int i;
946
947 if (m->mpc_irqtype != mp_INT)
948 return 0;
949
950 if (m->mpc_irqflag != 0x0f)
951 return 0;
952
953 /* not legacy */
954
955 for (i = 0; i < mp_irq_entries; i++) {
956 if (mp_irqs[i].mp_irqtype != mp_INT)
957 continue;
958
959 if (mp_irqs[i].mp_irqflag != 0x0f)
960 continue;
961
962 if (mp_irqs[i].mp_srcbus != m->mpc_srcbus)
963 continue;
964 if (mp_irqs[i].mp_srcbusirq != m->mpc_srcbusirq)
965 continue;
966 if (irq_used[i]) {
967 /* already claimed */
968 return -2;
969 }
970 irq_used[i] = 1;
971 return i;
972 }
973
974 /* not found */
975 return -1;
976}
977
978#define SPARE_SLOT_NUM 20
979
980static struct mpc_config_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
981#endif
982
983static int __init replace_intsrc_all(struct mp_config_table *mpc,
984 unsigned long mpc_new_phys,
985 unsigned long mpc_new_length)
986{
987#ifdef CONFIG_X86_IO_APIC
988 int i;
989 int nr_m_spare = 0;
990#endif
991
992 int count = sizeof(*mpc);
993 unsigned char *mpt = ((unsigned char *)mpc) + count;
994
995 printk(KERN_INFO "mpc_length %x\n", mpc->mpc_length);
996 while (count < mpc->mpc_length) {
997 switch (*mpt) {
998 case MP_PROCESSOR:
999 {
1000 struct mpc_config_processor *m =
1001 (struct mpc_config_processor *)mpt;
1002 mpt += sizeof(*m);
1003 count += sizeof(*m);
1004 break;
1005 }
1006 case MP_BUS:
1007 {
1008 struct mpc_config_bus *m =
1009 (struct mpc_config_bus *)mpt;
1010 mpt += sizeof(*m);
1011 count += sizeof(*m);
1012 break;
1013 }
1014 case MP_IOAPIC:
1015 {
1016 mpt += sizeof(struct mpc_config_ioapic);
1017 count += sizeof(struct mpc_config_ioapic);
1018 break;
1019 }
1020 case MP_INTSRC:
1021 {
1022#ifdef CONFIG_X86_IO_APIC
1023 struct mpc_config_intsrc *m =
1024 (struct mpc_config_intsrc *)mpt;
1025
1026 printk(KERN_INFO "OLD ");
1027 print_MP_intsrc_info(m);
1028 i = get_MP_intsrc_index(m);
1029 if (i > 0) {
1030 assign_to_mpc_intsrc(&mp_irqs[i], m);
1031 printk(KERN_INFO "NEW ");
1032 print_mp_irq_info(&mp_irqs[i]);
1033 } else if (!i) {
1034 /* legacy, do nothing */
1035 } else if (nr_m_spare < SPARE_SLOT_NUM) {
1036 /*
1037 * not found (-1), or duplicated (-2)
1038 * are invalid entries,
1039 * we need to use the slot later
1040 */
1041 m_spare[nr_m_spare] = m;
1042 nr_m_spare++;
1043 }
1044#endif
1045 mpt += sizeof(struct mpc_config_intsrc);
1046 count += sizeof(struct mpc_config_intsrc);
1047 break;
1048 }
1049 case MP_LINTSRC:
1050 {
1051 struct mpc_config_lintsrc *m =
1052 (struct mpc_config_lintsrc *)mpt;
1053 mpt += sizeof(*m);
1054 count += sizeof(*m);
1055 break;
1056 }
1057 default:
1058 /* wrong mptable */
1059 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
1060 printk(KERN_ERR "type %x\n", *mpt);
1061 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
1062 1, mpc, mpc->mpc_length, 1);
1063 goto out;
1064 }
1065 }
1066
1067#ifdef CONFIG_X86_IO_APIC
1068 for (i = 0; i < mp_irq_entries; i++) {
1069 if (irq_used[i])
1070 continue;
1071
1072 if (mp_irqs[i].mp_irqtype != mp_INT)
1073 continue;
1074
1075 if (mp_irqs[i].mp_irqflag != 0x0f)
1076 continue;
1077
1078 if (nr_m_spare > 0) {
1079 printk(KERN_INFO "*NEW* found ");
1080 nr_m_spare--;
1081 assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
1082 m_spare[nr_m_spare] = NULL;
1083 } else {
1084 struct mpc_config_intsrc *m =
1085 (struct mpc_config_intsrc *)mpt;
1086 count += sizeof(struct mpc_config_intsrc);
1087 if (!mpc_new_phys) {
1088 printk(KERN_INFO "No spare slots, try to append...take your risk, new mpc_length %x\n", count);
1089 } else {
1090 if (count <= mpc_new_length)
1091 printk(KERN_INFO "No spare slots, try to append..., new mpc_length %x\n", count);
1092 else {
1093 printk(KERN_ERR "mpc_new_length %lx is too small\n", mpc_new_length);
1094 goto out;
1095 }
1096 }
1097 assign_to_mpc_intsrc(&mp_irqs[i], m);
1098 mpc->mpc_length = count;
1099 mpt += sizeof(struct mpc_config_intsrc);
1100 }
1101 print_mp_irq_info(&mp_irqs[i]);
1102 }
1103#endif
1104out:
1105 /* update checksum */
1106 mpc->mpc_checksum = 0;
1107 mpc->mpc_checksum -= mpf_checksum((unsigned char *)mpc,
1108 mpc->mpc_length);
1109
1110 return 0;
1111}
1112
1113int __initdata enable_update_mptable;
1114
1115static int __init update_mptable_setup(char *str)
1116{
1117 enable_update_mptable = 1;
1118 return 0;
1119}
1120early_param("update_mptable", update_mptable_setup);
1121
1122static unsigned long __initdata mpc_new_phys;
1123static unsigned long mpc_new_length __initdata = 4096;
1124
1125/* alloc_mptable or alloc_mptable=4k */
1126static int __initdata alloc_mptable;
1127static int __init parse_alloc_mptable_opt(char *p)
1128{
1129 enable_update_mptable = 1;
1130 alloc_mptable = 1;
1131 if (!p)
1132 return 0;
1133 mpc_new_length = memparse(p, &p);
1134 return 0;
1135}
1136early_param("alloc_mptable", parse_alloc_mptable_opt);
1137
1138void __init early_reserve_e820_mpc_new(void)
1139{
1140 if (enable_update_mptable && alloc_mptable) {
1141 u64 startt = 0;
1142#ifdef CONFIG_X86_TRAMPOLINE
1143 startt = TRAMPOLINE_BASE;
1144#endif
1145 mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
1146 }
1147}
1148
1149static int __init update_mp_table(void)
1150{
1151 char str[16];
1152 char oem[10];
1153 struct intel_mp_floating *mpf;
1154 struct mp_config_table *mpc;
1155 struct mp_config_table *mpc_new;
1156
1157 if (!enable_update_mptable)
1158 return 0;
1159
1160 mpf = mpf_found;
1161 if (!mpf)
1162 return 0;
1163
1164 /*
1165 * Now see if we need to go further.
1166 */
1167 if (mpf->mpf_feature1 != 0)
1168 return 0;
1169
1170 if (!mpf->mpf_physptr)
1171 return 0;
1172
1173 mpc = phys_to_virt(mpf->mpf_physptr);
1174
1175 if (!smp_check_mpc(mpc, oem, str))
1176 return 0;
1177
1178 printk(KERN_INFO "mpf: %lx\n", virt_to_phys(mpf));
1179 printk(KERN_INFO "mpf_physptr: %x\n", mpf->mpf_physptr);
1180
1181 if (mpc_new_phys && mpc->mpc_length > mpc_new_length) {
1182 mpc_new_phys = 0;
1183 printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
1184 mpc_new_length);
1185 }
1186
1187 if (!mpc_new_phys) {
1188 unsigned char old, new;
1189 /* check if we can change the postion */
1190 mpc->mpc_checksum = 0;
1191 old = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
1192 mpc->mpc_checksum = 0xff;
1193 new = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
1194 if (old == new) {
1195 printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
1196 return 0;
1197 }
1198 printk(KERN_INFO "use in-positon replacing\n");
1199 } else {
1200 mpf->mpf_physptr = mpc_new_phys;
1201 mpc_new = phys_to_virt(mpc_new_phys);
1202 memcpy(mpc_new, mpc, mpc->mpc_length);
1203 mpc = mpc_new;
1204 /* check if we can modify that */
1205 if (mpc_new_phys - mpf->mpf_physptr) {
1206 struct intel_mp_floating *mpf_new;
1207 /* steal 16 bytes from [0, 1k) */
1208 printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
1209 mpf_new = phys_to_virt(0x400 - 16);
1210 memcpy(mpf_new, mpf, 16);
1211 mpf = mpf_new;
1212 mpf->mpf_physptr = mpc_new_phys;
1213 }
1214 mpf->mpf_checksum = 0;
1215 mpf->mpf_checksum -= mpf_checksum((unsigned char *)mpf, 16);
1216 printk(KERN_INFO "mpf_physptr new: %x\n", mpf->mpf_physptr);
1217 }
1218
1219 /*
1220 * only replace the one with mp_INT and
1221 * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
1222 * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
1223 * may need pci=routeirq for all coverage
1224 */
1225 replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
1226
1227 return 0;
1228}
1229
1230late_initcall(update_mp_table);