blob: 3cbd2df3abe4916bdcfed5865ffc13c7c7ac3c12 [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>
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -070030#include <asm/setup.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32#include <mach_apic.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040033#ifdef CONFIG_X86_32
Andi Kleen874c4fe2006-09-26 10:52:26 +020034#include <mach_apicdef.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <mach_mpparse.h>
Alexey Starikovskiy85bddde2008-04-04 23:43:18 +040036#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Linus Torvalds1da177e2005-04-16 15:20:36 -070038/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 * Checksum an MP configuration block.
40 */
41
42static int __init mpf_checksum(unsigned char *mp, int len)
43{
44 int sum = 0;
45
46 while (len--)
47 sum += *mp++;
48
49 return sum & 0xFF;
50}
51
Alexey Starikovskiy86420502008-03-17 22:08:55 +030052#ifdef CONFIG_X86_NUMAQ
Yinghai Lud49c4282008-06-08 18:31:54 -070053int found_numaq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054/*
55 * Have to match translation table entries to main table entries by counter
56 * hence the mpc_record variable .... can't see a less disgusting way of
57 * doing this ....
58 */
Yinghai Lud49c4282008-06-08 18:31:54 -070059struct mpc_config_translation {
60 unsigned char mpc_type;
61 unsigned char trans_len;
62 unsigned char trans_type;
63 unsigned char trans_quad;
64 unsigned char trans_global;
65 unsigned char trans_local;
66 unsigned short trans_reserved;
67};
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +040070static int mpc_record;
71static struct mpc_config_translation *translation_table[MAX_MPC_ENTRY]
72 __cpuinitdata;
Yinghai Lud49c4282008-06-08 18:31:54 -070073
74static inline int generate_logical_apicid(int quad, int phys_apicid)
75{
76 return (quad << 4) + (phys_apicid ? phys_apicid << 1 : 1);
77}
78
79
80static inline int mpc_apic_id(struct mpc_config_processor *m,
81 struct mpc_config_translation *translation_record)
82{
83 int quad = translation_record->trans_quad;
84 int logical_apicid = generate_logical_apicid(quad, m->mpc_apicid);
85
86 printk(KERN_DEBUG "Processor #%d %u:%u APIC version %d (quad %d, apic %d)\n",
87 m->mpc_apicid,
88 (m->mpc_cpufeature & CPU_FAMILY_MASK) >> 8,
89 (m->mpc_cpufeature & CPU_MODEL_MASK) >> 4,
90 m->mpc_apicver, quad, logical_apicid);
91 return logical_apicid;
92}
93
94int mp_bus_id_to_node[MAX_MP_BUSSES];
95
96int mp_bus_id_to_local[MAX_MP_BUSSES];
97
98static void mpc_oem_bus_info(struct mpc_config_bus *m, char *name,
99 struct mpc_config_translation *translation)
100{
101 int quad = translation->trans_quad;
102 int local = translation->trans_local;
103
104 mp_bus_id_to_node[m->mpc_busid] = quad;
105 mp_bus_id_to_local[m->mpc_busid] = local;
106 printk(KERN_INFO "Bus #%d is %s (node %d)\n",
107 m->mpc_busid, name, quad);
108}
109
110int quad_local_to_mp_bus_id [NR_CPUS/4][4];
111static void mpc_oem_pci_bus(struct mpc_config_bus *m,
112 struct mpc_config_translation *translation)
113{
114 int quad = translation->trans_quad;
115 int local = translation->trans_local;
116
117 quad_local_to_mp_bus_id[quad][local] = m->mpc_busid;
118}
119
Alexey Starikovskiy86420502008-03-17 22:08:55 +0300120#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Alexey Starikovskiyc853c672008-03-27 23:54:13 +0300122static void __cpuinit MP_processor_info(struct mpc_config_processor *m)
123{
124 int apicid;
Alexey Starikovskiy746f2242008-04-04 23:42:15 +0400125 char *bootup_cpu = "";
Alexey Starikovskiyc853c672008-03-27 23:54:13 +0300126
Glauber Costa7b1292e2008-03-03 14:12:41 -0300127 if (!(m->mpc_cpuflag & CPU_ENABLED)) {
128 disabled_cpus++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 return;
Glauber Costa7b1292e2008-03-03 14:12:41 -0300130 }
Alexey Starikovskiy4655c7d2008-03-17 22:08:36 +0300131#ifdef CONFIG_X86_NUMAQ
Yinghai Luab530e12008-06-03 10:25:54 -0700132 if (found_numaq)
133 apicid = mpc_apic_id(m, translation_table[mpc_record]);
134 else
135 apicid = m->mpc_apicid;
Alexey Starikovskiy4655c7d2008-03-17 22:08:36 +0300136#else
Alexey Starikovskiy4655c7d2008-03-17 22:08:36 +0300137 apicid = m->mpc_apicid;
138#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
Alexey Starikovskiy746f2242008-04-04 23:42:15 +0400140 bootup_cpu = " (Bootup-CPU)";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 boot_cpu_physical_apicid = m->mpc_apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 }
143
Alexey Starikovskiy746f2242008-04-04 23:42:15 +0400144 printk(KERN_INFO "Processor #%d%s\n", m->mpc_apicid, bootup_cpu);
Alexey Starikovskiyc853c672008-03-27 23:54:13 +0300145 generic_processor_info(apicid, m->mpc_apicver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146}
147
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200148#ifdef CONFIG_X86_IO_APIC
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400149static void __init MP_bus_info(struct mpc_config_bus *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150{
151 char str[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 memcpy(str, m->mpc_bustype, 6);
153 str[6] = 0;
154
Alexey Starikovskiy0ec153a2008-03-17 22:08:48 +0300155#ifdef CONFIG_X86_NUMAQ
Yinghai Luab530e12008-06-03 10:25:54 -0700156 if (found_numaq)
157 mpc_oem_bus_info(m, str, translation_table[mpc_record]);
Alexey Starikovskiy0ec153a2008-03-17 22:08:48 +0300158#else
Yinghai Lu11a62a02008-05-12 15:43:38 +0200159 printk(KERN_INFO "Bus #%d is %s\n", m->mpc_busid, str);
Alexey Starikovskiy0ec153a2008-03-17 22:08:48 +0300160#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Andi Kleen5e4edbb2006-09-26 10:52:35 +0200162#if MAX_MP_BUSSES < 256
Randy Dunlapc0ec31a2006-04-10 22:53:13 -0700163 if (m->mpc_busid >= MAX_MP_BUSSES) {
164 printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400165 " is too large, max. supported is %d\n",
166 m->mpc_busid, str, MAX_MP_BUSSES - 1);
Randy Dunlapc0ec31a2006-04-10 22:53:13 -0700167 return;
168 }
Andi Kleen5e4edbb2006-09-26 10:52:35 +0200169#endif
Randy Dunlapc0ec31a2006-04-10 22:53:13 -0700170
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +0400171 if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
172 set_bit(m->mpc_busid, mp_bus_not_pci);
173#if defined(CONFIG_EISA) || defined (CONFIG_MCA)
174 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA;
175#endif
176 } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
Alexey Starikovskiyd285e332008-03-17 22:08:42 +0300177#ifdef CONFIG_X86_NUMAQ
Yinghai Luab530e12008-06-03 10:25:54 -0700178 if (found_numaq)
179 mpc_oem_pci_bus(m, translation_table[mpc_record]);
Alexey Starikovskiyd285e332008-03-17 22:08:42 +0300180#endif
Alexey Starikovskiya6333c32008-03-20 14:54:09 +0300181 clear_bit(m->mpc_busid, mp_bus_not_pci);
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +0300182#if defined(CONFIG_EISA) || defined (CONFIG_MCA)
183 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400184 } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
Alexey Starikovskiy9e0a2de2008-03-20 14:54:56 +0300185 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400186 } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_MCA;
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +0300188#endif
Alexey Starikovskiyf8924e72008-04-04 23:42:21 +0400189 } else
190 printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191}
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200192#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400194#ifdef CONFIG_X86_IO_APIC
195
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300196static int bad_ioapic(unsigned long address)
197{
198 if (nr_ioapics >= MAX_IO_APICS) {
199 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
200 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
201 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
202 }
203 if (!address) {
204 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
205 " found in table, skipping!\n");
206 return 1;
207 }
208 return 0;
209}
210
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400211static void __init MP_ioapic_info(struct mpc_config_ioapic *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212{
213 if (!(m->mpc_flags & MPC_APIC_USABLE))
214 return;
215
Thomas Gleixner64883ab2008-01-30 13:30:35 +0100216 printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400217 m->mpc_apicid, m->mpc_apicver, m->mpc_apicaddr);
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300218
219 if (bad_ioapic(m->mpc_apicaddr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 return;
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300221
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400222 mp_ioapics[nr_ioapics].mp_apicaddr = m->mpc_apicaddr;
223 mp_ioapics[nr_ioapics].mp_apicid = m->mpc_apicid;
224 mp_ioapics[nr_ioapics].mp_type = m->mpc_type;
225 mp_ioapics[nr_ioapics].mp_apicver = m->mpc_apicver;
226 mp_ioapics[nr_ioapics].mp_flags = m->mpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 nr_ioapics++;
228}
229
Yinghai Lu2944e162008-06-01 13:17:38 -0700230static void print_MP_intsrc_info(struct mpc_config_intsrc *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
Yinghai Lu2944e162008-06-01 13:17:38 -0700232 printk(KERN_CONT "Int: type %d, pol %d, trig %d, bus %02x,"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400234 m->mpc_irqtype, m->mpc_irqflag & 3,
235 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
236 m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
Yinghai Lu2944e162008-06-01 13:17:38 -0700237}
238
239static void __init print_mp_irq_info(struct mp_config_intsrc *mp_irq)
240{
241 printk(KERN_CONT "Int: type %d, pol %d, trig %d, bus %02x,"
242 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
243 mp_irq->mp_irqtype, mp_irq->mp_irqflag & 3,
244 (mp_irq->mp_irqflag >> 2) & 3, mp_irq->mp_srcbus,
245 mp_irq->mp_srcbusirq, mp_irq->mp_dstapic, mp_irq->mp_dstirq);
246}
247
Yinghai Lufcfa1462008-06-18 17:29:31 -0700248static void __init assign_to_mp_irq(struct mpc_config_intsrc *m,
Yinghai Lu2944e162008-06-01 13:17:38 -0700249 struct mp_config_intsrc *mp_irq)
250{
251 mp_irq->mp_dstapic = m->mpc_dstapic;
252 mp_irq->mp_type = m->mpc_type;
253 mp_irq->mp_irqtype = m->mpc_irqtype;
254 mp_irq->mp_irqflag = m->mpc_irqflag;
255 mp_irq->mp_srcbus = m->mpc_srcbus;
256 mp_irq->mp_srcbusirq = m->mpc_srcbusirq;
257 mp_irq->mp_dstirq = m->mpc_dstirq;
258}
259
260static void __init assign_to_mpc_intsrc(struct mp_config_intsrc *mp_irq,
261 struct mpc_config_intsrc *m)
262{
263 m->mpc_dstapic = mp_irq->mp_dstapic;
264 m->mpc_type = mp_irq->mp_type;
265 m->mpc_irqtype = mp_irq->mp_irqtype;
266 m->mpc_irqflag = mp_irq->mp_irqflag;
267 m->mpc_srcbus = mp_irq->mp_srcbus;
268 m->mpc_srcbusirq = mp_irq->mp_srcbusirq;
269 m->mpc_dstirq = mp_irq->mp_dstirq;
270}
271
Yinghai Lufcfa1462008-06-18 17:29:31 -0700272static int __init mp_irq_mpc_intsrc_cmp(struct mp_config_intsrc *mp_irq,
Yinghai Lu2944e162008-06-01 13:17:38 -0700273 struct mpc_config_intsrc *m)
274{
275 if (mp_irq->mp_dstapic != m->mpc_dstapic)
276 return 1;
277 if (mp_irq->mp_type != m->mpc_type)
278 return 2;
279 if (mp_irq->mp_irqtype != m->mpc_irqtype)
280 return 3;
281 if (mp_irq->mp_irqflag != m->mpc_irqflag)
282 return 4;
283 if (mp_irq->mp_srcbus != m->mpc_srcbus)
284 return 5;
285 if (mp_irq->mp_srcbusirq != m->mpc_srcbusirq)
286 return 6;
287 if (mp_irq->mp_dstirq != m->mpc_dstirq)
288 return 7;
289
290 return 0;
291}
292
Yinghai Lufcfa1462008-06-18 17:29:31 -0700293static void __init MP_intsrc_info(struct mpc_config_intsrc *m)
Yinghai Lu2944e162008-06-01 13:17:38 -0700294{
295 int i;
296
297 print_MP_intsrc_info(m);
298
Yinghai Lufcfa1462008-06-18 17:29:31 -0700299 for (i = 0; i < mp_irq_entries; i++) {
300 if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m))
301 return;
302 }
Yinghai Lu2944e162008-06-01 13:17:38 -0700303
304 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 if (++mp_irq_entries == MAX_IRQ_SOURCES)
306 panic("Max # of irq sources exceeded!!\n");
307}
308
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400309#endif
310
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400311static void __init MP_lintsrc_info(struct mpc_config_lintsrc *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312{
Yinghai Lu11a62a02008-05-12 15:43:38 +0200313 printk(KERN_INFO "Lint: type %d, pol %d, trig %d, bus %02x,"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400315 m->mpc_irqtype, m->mpc_irqflag & 3,
316 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbusid,
317 m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318}
319
320#ifdef CONFIG_X86_NUMAQ
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400321static void __init MP_translation_info(struct mpc_config_translation *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322{
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400323 printk(KERN_INFO
324 "Translation: record %d, type %d, quad %d, global %d, local %d\n",
325 mpc_record, m->trans_type, m->trans_quad, m->trans_global,
326 m->trans_local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400328 if (mpc_record >= MAX_MPC_ENTRY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 printk(KERN_ERR "MAX_MPC_ENTRY exceeded!\n");
330 else
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400331 translation_table[mpc_record] = m; /* stash this for later */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 if (m->trans_quad < MAX_NUMNODES && !node_online(m->trans_quad))
333 node_set_online(m->trans_quad);
334}
335
336/*
337 * Read/parse the MPC oem tables
338 */
339
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400340static void __init smp_read_mpc_oem(struct mp_config_oemtable *oemtable,
341 unsigned short oemsize)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342{
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400343 int count = sizeof(*oemtable); /* the header size */
344 unsigned char *oemptr = ((unsigned char *)oemtable) + count;
345
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 mpc_record = 0;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400347 printk(KERN_INFO "Found an OEM MPC table at %8p - parsing it ... \n",
348 oemtable);
349 if (memcmp(oemtable->oem_signature, MPC_OEM_SIGNATURE, 4)) {
350 printk(KERN_WARNING
351 "SMP mpc oemtable: bad signature [%c%c%c%c]!\n",
352 oemtable->oem_signature[0], oemtable->oem_signature[1],
353 oemtable->oem_signature[2], oemtable->oem_signature[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 return;
355 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400356 if (mpf_checksum((unsigned char *)oemtable, oemtable->oem_length)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 printk(KERN_WARNING "SMP oem mptable: checksum error!\n");
358 return;
359 }
360 while (count < oemtable->oem_length) {
361 switch (*oemptr) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400362 case MP_TRANSLATION:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400364 struct mpc_config_translation *m =
365 (struct mpc_config_translation *)oemptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 MP_translation_info(m);
367 oemptr += sizeof(*m);
368 count += sizeof(*m);
369 ++mpc_record;
370 break;
371 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400372 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400374 printk(KERN_WARNING
375 "Unrecognised OEM table entry type! - %d\n",
376 (int)*oemptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 return;
378 }
379 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400380 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381}
382
Yinghai Lud49c4282008-06-08 18:31:54 -0700383void numaq_mps_oem_check(struct mp_config_table *mpc, char *oem,
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400384 char *productid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385{
386 if (strncmp(oem, "IBM NUMA", 8))
Yinghai Lud49c4282008-06-08 18:31:54 -0700387 printk("Warning! Not a NUMA-Q system!\n");
Yinghai Luab530e12008-06-03 10:25:54 -0700388 else
389 found_numaq = 1;
390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 if (mpc->mpc_oemptr)
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400392 smp_read_mpc_oem((struct mp_config_oemtable *)mpc->mpc_oemptr,
393 mpc->mpc_oemsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394}
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400395#endif /* CONFIG_X86_NUMAQ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
397/*
398 * Read/parse the MPC
399 */
400
Yinghai Lu2944e162008-06-01 13:17:38 -0700401static int __init smp_check_mpc(struct mp_config_table *mpc, char *oem,
402 char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400405 if (memcmp(mpc->mpc_signature, MPC_SIGNATURE, 4)) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400406 printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
407 mpc->mpc_signature[0], mpc->mpc_signature[1],
408 mpc->mpc_signature[2], mpc->mpc_signature[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 return 0;
410 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400411 if (mpf_checksum((unsigned char *)mpc, mpc->mpc_length)) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400412 printk(KERN_ERR "MPTABLE: checksum error!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 return 0;
414 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400415 if (mpc->mpc_spec != 0x01 && mpc->mpc_spec != 0x04) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400416 printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400417 mpc->mpc_spec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 return 0;
419 }
420 if (!mpc->mpc_lapic) {
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400421 printk(KERN_ERR "MPTABLE: null local APIC address!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 return 0;
423 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400424 memcpy(oem, mpc->mpc_oem, 8);
425 oem[8] = 0;
Yinghai Lu11a62a02008-05-12 15:43:38 +0200426 printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400428 memcpy(str, mpc->mpc_productid, 12);
429 str[12] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
Yinghai Lu11a62a02008-05-12 15:43:38 +0200431 printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400433 printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->mpc_lapic);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
Yinghai Lu2944e162008-06-01 13:17:38 -0700435 return 1;
436}
437
438static int __init smp_read_mpc(struct mp_config_table *mpc, unsigned early)
439{
440 char str[16];
441 char oem[10];
442
443 int count = sizeof(*mpc);
444 unsigned char *mpt = ((unsigned char *)mpc) + count;
445
446 if (!smp_check_mpc(mpc, oem, str))
447 return 0;
448
449#ifdef CONFIG_X86_32
Yinghai Lud49c4282008-06-08 18:31:54 -0700450 /*
451 * need to make sure summit and es7000's mps_oem_check is safe to be
452 * called early via genericarch 's mps_oem_check
453 */
454 if (early) {
455#ifdef CONFIG_X86_NUMAQ
456 numaq_mps_oem_check(mpc, oem, str);
457#endif
458 } else
459 mps_oem_check(mpc, oem, str);
Yinghai Lu2944e162008-06-01 13:17:38 -0700460#endif
461
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400462 /* save the local APIC address, it might be non-default */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 if (!acpi_lapic)
464 mp_lapic_addr = mpc->mpc_lapic;
465
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400466 if (early)
467 return 1;
468
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 /*
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400470 * Now process the configuration blocks.
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 = 0;
Alexey Starikovskiy86420502008-03-17 22:08:55 +0300474#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 while (count < mpc->mpc_length) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400476 switch (*mpt) {
477 case MP_PROCESSOR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400479 struct mpc_config_processor *m =
480 (struct mpc_config_processor *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 /* ACPI may have already provided this data */
482 if (!acpi_lapic)
483 MP_processor_info(m);
484 mpt += sizeof(*m);
485 count += sizeof(*m);
486 break;
487 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400488 case MP_BUS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400490 struct mpc_config_bus *m =
491 (struct mpc_config_bus *)mpt;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200492#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 MP_bus_info(m);
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200494#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 mpt += sizeof(*m);
496 count += sizeof(*m);
497 break;
498 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400499 case MP_IOAPIC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 {
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400501#ifdef CONFIG_X86_IO_APIC
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400502 struct mpc_config_ioapic *m =
503 (struct mpc_config_ioapic *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 MP_ioapic_info(m);
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400505#endif
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400506 mpt += sizeof(struct mpc_config_ioapic);
507 count += sizeof(struct mpc_config_ioapic);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 break;
509 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400510 case MP_INTSRC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 {
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400512#ifdef CONFIG_X86_IO_APIC
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400513 struct mpc_config_intsrc *m =
514 (struct mpc_config_intsrc *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
516 MP_intsrc_info(m);
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400517#endif
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400518 mpt += sizeof(struct mpc_config_intsrc);
519 count += sizeof(struct mpc_config_intsrc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 break;
521 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400522 case MP_LINTSRC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400524 struct mpc_config_lintsrc *m =
525 (struct mpc_config_lintsrc *)mpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 MP_lintsrc_info(m);
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400527 mpt += sizeof(*m);
528 count += sizeof(*m);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 break;
530 }
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400531 default:
Yinghai Lu711554d2008-04-07 11:36:39 -0700532 /* wrong mptable */
533 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
534 printk(KERN_ERR "type %x\n", *mpt);
535 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
536 1, mpc, mpc->mpc_length, 1);
537 count = mpc->mpc_length;
538 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 }
Alexey Starikovskiy86420502008-03-17 22:08:55 +0300540#ifdef CONFIG_X86_NUMAQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 ++mpc_record;
Alexey Starikovskiy86420502008-03-17 22:08:55 +0300542#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 }
Yinghai Lue0da3362008-06-08 18:29:22 -0700544
545#ifdef CONFIG_X86_GENERICARCH
546 generic_bigsmp_probe();
547#endif
548
Ingo Molnar3c43f032007-05-02 19:27:04 +0200549 setup_apic_routing();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 if (!num_processors)
Alexey Starikovskiye950bea2008-04-04 23:42:27 +0400551 printk(KERN_ERR "MPTABLE: no processors registered!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 return num_processors;
553}
554
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400555#ifdef CONFIG_X86_IO_APIC
556
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557static int __init ELCR_trigger(unsigned int irq)
558{
559 unsigned int port;
560
561 port = 0x4d0 + (irq >> 3);
562 return (inb(port) >> (irq & 7)) & 1;
563}
564
565static void __init construct_default_ioirq_mptable(int mpc_default_type)
566{
567 struct mpc_config_intsrc intsrc;
568 int i;
569 int ELCR_fallback = 0;
570
571 intsrc.mpc_type = MP_INTSRC;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400572 intsrc.mpc_irqflag = 0; /* conforming */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 intsrc.mpc_srcbus = 0;
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400574 intsrc.mpc_dstapic = mp_ioapics[0].mp_apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
576 intsrc.mpc_irqtype = mp_INT;
577
578 /*
579 * If true, we have an ISA/PCI system with no IRQ entries
580 * in the MP table. To prevent the PCI interrupts from being set up
581 * incorrectly, we try to use the ELCR. The sanity check to see if
582 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
583 * never be level sensitive, so we simply see if the ELCR agrees.
584 * If it does, we assume it's valid.
585 */
586 if (mpc_default_type == 5) {
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400587 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
588 "falling back to ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400590 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
591 ELCR_trigger(13))
592 printk(KERN_ERR "ELCR contains invalid data... "
593 "not using ELCR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 else {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400595 printk(KERN_INFO
596 "Using ELCR to identify PCI interrupts\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 ELCR_fallback = 1;
598 }
599 }
600
601 for (i = 0; i < 16; i++) {
602 switch (mpc_default_type) {
603 case 2:
604 if (i == 0 || i == 13)
605 continue; /* IRQ0 & IRQ13 not connected */
606 /* fall through */
607 default:
608 if (i == 2)
609 continue; /* IRQ2 is never connected */
610 }
611
612 if (ELCR_fallback) {
613 /*
614 * If the ELCR indicates a level-sensitive interrupt, we
615 * copy that information over to the MP table in the
616 * irqflag field (level sensitive, active high polarity).
617 */
618 if (ELCR_trigger(i))
619 intsrc.mpc_irqflag = 13;
620 else
621 intsrc.mpc_irqflag = 0;
622 }
623
624 intsrc.mpc_srcbusirq = i;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400625 intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 MP_intsrc_info(&intsrc);
627 }
628
629 intsrc.mpc_irqtype = mp_ExtINT;
630 intsrc.mpc_srcbusirq = 0;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400631 intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 MP_intsrc_info(&intsrc);
633}
634
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400635
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200636static void construct_ioapic_table(int mpc_default_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 struct mpc_config_ioapic ioapic;
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200639 struct mpc_config_bus bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
641 bus.mpc_type = MP_BUS;
642 bus.mpc_busid = 0;
643 switch (mpc_default_type) {
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400644 default:
Alexey Starikovskiy62441bf2008-04-04 23:42:34 +0400645 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400646 mpc_default_type);
647 /* fall through */
648 case 1:
649 case 5:
650 memcpy(bus.mpc_bustype, "ISA ", 6);
651 break;
652 case 2:
653 case 6:
654 case 3:
655 memcpy(bus.mpc_bustype, "EISA ", 6);
656 break;
657 case 4:
658 case 7:
659 memcpy(bus.mpc_bustype, "MCA ", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 }
661 MP_bus_info(&bus);
662 if (mpc_default_type > 4) {
663 bus.mpc_busid = 1;
664 memcpy(bus.mpc_bustype, "PCI ", 6);
665 MP_bus_info(&bus);
666 }
667
668 ioapic.mpc_type = MP_IOAPIC;
669 ioapic.mpc_apicid = 2;
670 ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
671 ioapic.mpc_flags = MPC_APIC_USABLE;
672 ioapic.mpc_apicaddr = 0xFEC00000;
673 MP_ioapic_info(&ioapic);
674
675 /*
676 * We set up most of the low 16 IO-APIC pins according to MPS rules.
677 */
678 construct_default_ioirq_mptable(mpc_default_type);
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200679}
680#else
681static inline void construct_ioapic_table(int mpc_default_type) { }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400682#endif
Thomas Gleixner85cc35f2008-05-25 21:21:36 +0200683
684static inline void __init construct_default_ISA_mptable(int mpc_default_type)
685{
686 struct mpc_config_processor processor;
687 struct mpc_config_lintsrc lintsrc;
688 int linttypes[2] = { mp_ExtINT, mp_NMI };
689 int i;
690
691 /*
692 * local APIC has default address
693 */
694 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
695
696 /*
697 * 2 CPUs, numbered 0 & 1.
698 */
699 processor.mpc_type = MP_PROCESSOR;
700 /* Either an integrated APIC or a discrete 82489DX. */
701 processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
702 processor.mpc_cpuflag = CPU_ENABLED;
703 processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
704 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
705 processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
706 processor.mpc_reserved[0] = 0;
707 processor.mpc_reserved[1] = 0;
708 for (i = 0; i < 2; i++) {
709 processor.mpc_apicid = i;
710 MP_processor_info(&processor);
711 }
712
713 construct_ioapic_table(mpc_default_type);
714
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 lintsrc.mpc_type = MP_LINTSRC;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400716 lintsrc.mpc_irqflag = 0; /* conforming */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 lintsrc.mpc_srcbusid = 0;
718 lintsrc.mpc_srcbusirq = 0;
719 lintsrc.mpc_destapic = MP_APIC_ALL;
720 for (i = 0; i < 2; i++) {
721 lintsrc.mpc_irqtype = linttypes[i];
722 lintsrc.mpc_destapiclint = i;
723 MP_lintsrc_info(&lintsrc);
724 }
725}
726
727static struct intel_mp_floating *mpf_found;
728
729/*
730 * Scan the memory blocks for an SMP configuration block.
731 */
Ingo Molnar3b335532008-07-10 17:30:40 +0200732static void __init __get_smp_config(unsigned int early)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733{
734 struct intel_mp_floating *mpf = mpf_found;
735
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700736 if (x86_quirks->mach_get_smp_config) {
737 if (x86_quirks->mach_get_smp_config(early))
Ingo Molnar3b335532008-07-10 17:30:40 +0200738 return;
739 }
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400740 if (acpi_lapic && early)
741 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 /*
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400743 * ACPI supports both logical (e.g. Hyper-Threading) and physical
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 * processors, where MPS only supports physical.
745 */
746 if (acpi_lapic && acpi_ioapic) {
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400747 printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
748 "information\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 return;
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400750 } else if (acpi_lapic)
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400751 printk(KERN_INFO "Using ACPI for processor (LAPIC) "
752 "configuration information\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400754 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
755 mpf->mpf_specification);
Alexey Starikovskiyb3e24162008-05-23 01:54:44 +0400756#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400757 if (mpf->mpf_feature2 & (1 << 7)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
759 pic_mode = 1;
760 } else {
761 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
762 pic_mode = 0;
763 }
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400764#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 /*
766 * Now see if we need to read further.
767 */
768 if (mpf->mpf_feature1 != 0) {
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400769 if (early) {
770 /*
771 * local APIC has default address
772 */
773 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
774 return;
775 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400777 printk(KERN_INFO "Default MP configuration #%d\n",
778 mpf->mpf_feature1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 construct_default_ISA_mptable(mpf->mpf_feature1);
780
781 } else if (mpf->mpf_physptr) {
782
783 /*
784 * Read the physical hardware table. Anything here will
785 * override the defaults.
786 */
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400787 if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr), early)) {
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400788#ifdef CONFIG_X86_LOCAL_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 smp_found_config = 0;
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400790#endif
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400791 printk(KERN_ERR
792 "BIOS bug, MP table errors detected!...\n");
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400793 printk(KERN_ERR "... disabling SMP support. "
794 "(tell your hw vendor)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 return;
796 }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400797
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400798 if (early)
799 return;
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400800#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 /*
802 * If there are no explicit MP IRQ entries, then we are
803 * broken. We set up most of the low 16 IO-APIC pins to
804 * ISA defaults and hope it will work.
805 */
806 if (!mp_irq_entries) {
807 struct mpc_config_bus bus;
808
Alexey Starikovskiy4421b1c2008-04-04 23:42:40 +0400809 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
810 "using default mptable. "
811 "(tell your hw vendor)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
813 bus.mpc_type = MP_BUS;
814 bus.mpc_busid = 0;
815 memcpy(bus.mpc_bustype, "ISA ", 6);
816 MP_bus_info(&bus);
817
818 construct_default_ioirq_mptable(0);
819 }
Alexey Starikovskiy61048c62008-04-04 23:41:07 +0400820#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 } else
822 BUG();
823
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400824 if (!early)
825 printk(KERN_INFO "Processors: %d\n", num_processors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 /*
827 * Only use the first configuration found.
828 */
829}
830
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400831void __init early_get_smp_config(void)
832{
833 __get_smp_config(1);
834}
835
836void __init get_smp_config(void)
837{
838 __get_smp_config(0);
839}
840
841static int __init smp_scan_config(unsigned long base, unsigned long length,
842 unsigned reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843{
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400844 unsigned int *bp = phys_to_virt(base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 struct intel_mp_floating *mpf;
846
Yinghai Lu11a62a02008-05-12 15:43:38 +0200847 printk(KERN_DEBUG "Scan SMP from %p for %ld bytes.\n", bp, length);
Akinobu Mita5d47a272008-04-19 23:55:11 +0900848 BUILD_BUG_ON(sizeof(*mpf) != 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
850 while (length > 0) {
851 mpf = (struct intel_mp_floating *)bp;
852 if ((*bp == SMP_MAGIC_IDENT) &&
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400853 (mpf->mpf_length == 1) &&
854 !mpf_checksum((unsigned char *)bp, 16) &&
855 ((mpf->mpf_specification == 1)
856 || (mpf->mpf_specification == 4))) {
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400857#ifdef CONFIG_X86_LOCAL_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 smp_found_config = 1;
Alexey Starikovskiybab4b272008-05-19 19:47:03 +0400859#endif
Alexey Starikovskiy92fd4b72008-04-04 23:42:46 +0400860 mpf_found = mpf;
Yinghai Lub1f006b2008-06-09 18:11:36 -0700861
Ingo Molnare91a3b42008-01-30 13:33:08 +0100862 printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
Alexey Starikovskiy4ef81292008-04-04 23:42:03 +0400863 mpf, virt_to_phys(mpf));
Yinghai Lub1f006b2008-06-09 18:11:36 -0700864
865 if (!reserve)
866 return 1;
Yinghai Lud2dbf342008-06-13 02:00:56 -0700867 reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE,
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800868 BOOTMEM_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 if (mpf->mpf_physptr) {
Yinghai Lud2dbf342008-06-13 02:00:56 -0700870 unsigned long size = PAGE_SIZE;
871#ifdef CONFIG_X86_32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 /*
873 * We cannot access to MPC table to compute
874 * table size yet, as only few megabytes from
875 * the bottom is mapped now.
876 * PC-9800's MPC table places on the very last
877 * of physical memory; so that simply reserving
878 * PAGE_SIZE from mpg->mpf_physptr yields BUG()
879 * in reserve_bootmem.
880 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 unsigned long end = max_low_pfn * PAGE_SIZE;
882 if (mpf->mpf_physptr + size > end)
883 size = end - mpf->mpf_physptr;
Yinghai Lud2dbf342008-06-13 02:00:56 -0700884#endif
885 reserve_bootmem_generic(mpf->mpf_physptr, size,
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800886 BOOTMEM_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 }
888
Yinghai Lud2dbf342008-06-13 02:00:56 -0700889 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 }
891 bp += 4;
892 length -= 16;
893 }
894 return 0;
895}
896
Ingo Molnar3b335532008-07-10 17:30:40 +0200897static void __init __find_smp_config(unsigned int reserve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898{
899 unsigned int address;
900
Yinghai Lu3c9cb6d2008-07-19 02:07:25 -0700901 if (x86_quirks->mach_find_smp_config) {
902 if (x86_quirks->mach_find_smp_config(reserve))
Ingo Molnar3b335532008-07-10 17:30:40 +0200903 return;
904 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 /*
906 * FIXME: Linux assumes you have 640K of base ram..
907 * this continues the error...
908 *
909 * 1) Scan the bottom 1K for a signature
910 * 2) Scan the top 1K of base RAM
911 * 3) Scan the 64K of bios
912 */
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400913 if (smp_scan_config(0x0, 0x400, reserve) ||
914 smp_scan_config(639 * 0x400, 0x400, reserve) ||
915 smp_scan_config(0xF0000, 0x10000, reserve))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 return;
917 /*
918 * If it is an SMP machine we should know now, unless the
919 * configuration is in an EISA/MCA bus machine with an
920 * extended bios data area.
921 *
922 * there is a real-mode segmented pointer pointing to the
923 * 4K EBDA area at 0x40E, calculate and scan it here.
924 *
925 * NOTE! There are Linux loaders that will corrupt the EBDA
926 * area, and as such this kind of SMP config may be less
927 * trustworthy, simply because the SMP table may have been
928 * stomped on during early boot. These loaders are buggy and
929 * should be fixed.
930 *
931 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
932 */
933
934 address = get_bios_ebda();
935 if (address)
Alexey Starikovskiy888032c2008-04-04 23:42:09 +0400936 smp_scan_config(address, 0x400, reserve);
937}
938
939void __init early_find_smp_config(void)
940{
941 __find_smp_config(0);
942}
943
944void __init find_smp_config(void)
945{
946 __find_smp_config(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947}
Yinghai Lu2944e162008-06-01 13:17:38 -0700948
949#ifdef CONFIG_X86_IO_APIC
950static u8 __initdata irq_used[MAX_IRQ_SOURCES];
951
952static int __init get_MP_intsrc_index(struct mpc_config_intsrc *m)
953{
954 int i;
955
956 if (m->mpc_irqtype != mp_INT)
957 return 0;
958
959 if (m->mpc_irqflag != 0x0f)
960 return 0;
961
962 /* not legacy */
963
964 for (i = 0; i < mp_irq_entries; i++) {
965 if (mp_irqs[i].mp_irqtype != mp_INT)
966 continue;
967
968 if (mp_irqs[i].mp_irqflag != 0x0f)
969 continue;
970
971 if (mp_irqs[i].mp_srcbus != m->mpc_srcbus)
972 continue;
973 if (mp_irqs[i].mp_srcbusirq != m->mpc_srcbusirq)
974 continue;
975 if (irq_used[i]) {
976 /* already claimed */
977 return -2;
978 }
979 irq_used[i] = 1;
980 return i;
981 }
982
983 /* not found */
984 return -1;
985}
986
987#define SPARE_SLOT_NUM 20
988
989static struct mpc_config_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
990#endif
991
992static int __init replace_intsrc_all(struct mp_config_table *mpc,
993 unsigned long mpc_new_phys,
994 unsigned long mpc_new_length)
995{
996#ifdef CONFIG_X86_IO_APIC
997 int i;
998 int nr_m_spare = 0;
999#endif
1000
1001 int count = sizeof(*mpc);
1002 unsigned char *mpt = ((unsigned char *)mpc) + count;
1003
1004 printk(KERN_INFO "mpc_length %x\n", mpc->mpc_length);
1005 while (count < mpc->mpc_length) {
1006 switch (*mpt) {
1007 case MP_PROCESSOR:
1008 {
1009 struct mpc_config_processor *m =
1010 (struct mpc_config_processor *)mpt;
1011 mpt += sizeof(*m);
1012 count += sizeof(*m);
1013 break;
1014 }
1015 case MP_BUS:
1016 {
1017 struct mpc_config_bus *m =
1018 (struct mpc_config_bus *)mpt;
1019 mpt += sizeof(*m);
1020 count += sizeof(*m);
1021 break;
1022 }
1023 case MP_IOAPIC:
1024 {
1025 mpt += sizeof(struct mpc_config_ioapic);
1026 count += sizeof(struct mpc_config_ioapic);
1027 break;
1028 }
1029 case MP_INTSRC:
1030 {
1031#ifdef CONFIG_X86_IO_APIC
1032 struct mpc_config_intsrc *m =
1033 (struct mpc_config_intsrc *)mpt;
1034
1035 printk(KERN_INFO "OLD ");
1036 print_MP_intsrc_info(m);
1037 i = get_MP_intsrc_index(m);
1038 if (i > 0) {
1039 assign_to_mpc_intsrc(&mp_irqs[i], m);
1040 printk(KERN_INFO "NEW ");
1041 print_mp_irq_info(&mp_irqs[i]);
1042 } else if (!i) {
1043 /* legacy, do nothing */
1044 } else if (nr_m_spare < SPARE_SLOT_NUM) {
1045 /*
1046 * not found (-1), or duplicated (-2)
1047 * are invalid entries,
1048 * we need to use the slot later
1049 */
1050 m_spare[nr_m_spare] = m;
1051 nr_m_spare++;
1052 }
1053#endif
1054 mpt += sizeof(struct mpc_config_intsrc);
1055 count += sizeof(struct mpc_config_intsrc);
1056 break;
1057 }
1058 case MP_LINTSRC:
1059 {
1060 struct mpc_config_lintsrc *m =
1061 (struct mpc_config_lintsrc *)mpt;
1062 mpt += sizeof(*m);
1063 count += sizeof(*m);
1064 break;
1065 }
1066 default:
1067 /* wrong mptable */
1068 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
1069 printk(KERN_ERR "type %x\n", *mpt);
1070 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
1071 1, mpc, mpc->mpc_length, 1);
1072 goto out;
1073 }
1074 }
1075
1076#ifdef CONFIG_X86_IO_APIC
1077 for (i = 0; i < mp_irq_entries; i++) {
1078 if (irq_used[i])
1079 continue;
1080
1081 if (mp_irqs[i].mp_irqtype != mp_INT)
1082 continue;
1083
1084 if (mp_irqs[i].mp_irqflag != 0x0f)
1085 continue;
1086
1087 if (nr_m_spare > 0) {
1088 printk(KERN_INFO "*NEW* found ");
1089 nr_m_spare--;
1090 assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
1091 m_spare[nr_m_spare] = NULL;
1092 } else {
1093 struct mpc_config_intsrc *m =
1094 (struct mpc_config_intsrc *)mpt;
1095 count += sizeof(struct mpc_config_intsrc);
1096 if (!mpc_new_phys) {
1097 printk(KERN_INFO "No spare slots, try to append...take your risk, new mpc_length %x\n", count);
1098 } else {
1099 if (count <= mpc_new_length)
1100 printk(KERN_INFO "No spare slots, try to append..., new mpc_length %x\n", count);
1101 else {
1102 printk(KERN_ERR "mpc_new_length %lx is too small\n", mpc_new_length);
1103 goto out;
1104 }
1105 }
1106 assign_to_mpc_intsrc(&mp_irqs[i], m);
1107 mpc->mpc_length = count;
1108 mpt += sizeof(struct mpc_config_intsrc);
1109 }
1110 print_mp_irq_info(&mp_irqs[i]);
1111 }
1112#endif
1113out:
1114 /* update checksum */
1115 mpc->mpc_checksum = 0;
1116 mpc->mpc_checksum -= mpf_checksum((unsigned char *)mpc,
1117 mpc->mpc_length);
1118
1119 return 0;
1120}
1121
Yinghai Lufcfa1462008-06-18 17:29:31 -07001122static int __initdata enable_update_mptable;
1123
Yinghai Lu2944e162008-06-01 13:17:38 -07001124static int __init update_mptable_setup(char *str)
1125{
1126 enable_update_mptable = 1;
1127 return 0;
1128}
1129early_param("update_mptable", update_mptable_setup);
1130
1131static unsigned long __initdata mpc_new_phys;
1132static unsigned long mpc_new_length __initdata = 4096;
1133
1134/* alloc_mptable or alloc_mptable=4k */
1135static int __initdata alloc_mptable;
1136static int __init parse_alloc_mptable_opt(char *p)
1137{
1138 enable_update_mptable = 1;
1139 alloc_mptable = 1;
1140 if (!p)
1141 return 0;
1142 mpc_new_length = memparse(p, &p);
1143 return 0;
1144}
1145early_param("alloc_mptable", parse_alloc_mptable_opt);
1146
1147void __init early_reserve_e820_mpc_new(void)
1148{
1149 if (enable_update_mptable && alloc_mptable) {
1150 u64 startt = 0;
1151#ifdef CONFIG_X86_TRAMPOLINE
1152 startt = TRAMPOLINE_BASE;
1153#endif
1154 mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
1155 }
1156}
1157
1158static int __init update_mp_table(void)
1159{
1160 char str[16];
1161 char oem[10];
1162 struct intel_mp_floating *mpf;
1163 struct mp_config_table *mpc;
1164 struct mp_config_table *mpc_new;
1165
1166 if (!enable_update_mptable)
1167 return 0;
1168
1169 mpf = mpf_found;
1170 if (!mpf)
1171 return 0;
1172
1173 /*
1174 * Now see if we need to go further.
1175 */
1176 if (mpf->mpf_feature1 != 0)
1177 return 0;
1178
1179 if (!mpf->mpf_physptr)
1180 return 0;
1181
1182 mpc = phys_to_virt(mpf->mpf_physptr);
1183
1184 if (!smp_check_mpc(mpc, oem, str))
1185 return 0;
1186
1187 printk(KERN_INFO "mpf: %lx\n", virt_to_phys(mpf));
1188 printk(KERN_INFO "mpf_physptr: %x\n", mpf->mpf_physptr);
1189
1190 if (mpc_new_phys && mpc->mpc_length > mpc_new_length) {
1191 mpc_new_phys = 0;
1192 printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
1193 mpc_new_length);
1194 }
1195
1196 if (!mpc_new_phys) {
1197 unsigned char old, new;
1198 /* check if we can change the postion */
1199 mpc->mpc_checksum = 0;
1200 old = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
1201 mpc->mpc_checksum = 0xff;
1202 new = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
1203 if (old == new) {
1204 printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
1205 return 0;
1206 }
1207 printk(KERN_INFO "use in-positon replacing\n");
1208 } else {
1209 mpf->mpf_physptr = mpc_new_phys;
1210 mpc_new = phys_to_virt(mpc_new_phys);
1211 memcpy(mpc_new, mpc, mpc->mpc_length);
1212 mpc = mpc_new;
1213 /* check if we can modify that */
1214 if (mpc_new_phys - mpf->mpf_physptr) {
1215 struct intel_mp_floating *mpf_new;
1216 /* steal 16 bytes from [0, 1k) */
1217 printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
1218 mpf_new = phys_to_virt(0x400 - 16);
1219 memcpy(mpf_new, mpf, 16);
1220 mpf = mpf_new;
1221 mpf->mpf_physptr = mpc_new_phys;
1222 }
1223 mpf->mpf_checksum = 0;
1224 mpf->mpf_checksum -= mpf_checksum((unsigned char *)mpf, 16);
1225 printk(KERN_INFO "mpf_physptr new: %x\n", mpf->mpf_physptr);
1226 }
1227
1228 /*
1229 * only replace the one with mp_INT and
1230 * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
1231 * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
1232 * may need pci=routeirq for all coverage
1233 */
1234 replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
1235
1236 return 0;
1237}
1238
1239late_initcall(update_mp_table);