blob: 15265ee11f89c9808efab0718e5c8096517c091c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Intel Multiprocessor Specification 1.1 and 1.4
3 * 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>
7 *
8 * Fixes
9 * Erich Boleyn : MP v1.4 and additional changes.
10 * Alan Cox : Added EBDA scanning
11 * Ingo Molnar : various cleanups and rewrites
12 * Maciej W. Rozycki: Bits for default MP configurations
13 * Paul Diefenbaugh: Added full ACPI support
14 */
15
16#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/init.h>
18#include <linux/acpi.h>
19#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/bootmem.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/kernel_stat.h>
22#include <linux/mc146818rtc.h>
23#include <linux/bitops.h>
24
25#include <asm/smp.h>
26#include <asm/acpi.h>
27#include <asm/mtrr.h>
28#include <asm/mpspec.h>
29#include <asm/io_apic.h>
Alexey Starikovskiyce3fe6b2008-03-17 22:08:17 +030030#include <asm/bios_ebda.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32#include <mach_apic.h>
Andi Kleen874c4fe2006-09-26 10:52:26 +020033#include <mach_apicdef.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <mach_mpparse.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36/* Have we found an MP table */
37int smp_found_config;
Vivek Goyal4a5d1072007-01-11 01:52:44 +010038unsigned int __cpuinitdata maxcpus = NR_CPUS;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40/*
41 * Various Linux-internal data structures created from the
42 * MP-table.
43 */
44int apic_version [MAX_APICS];
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +030045#if defined (CONFIG_MCA) || defined (CONFIG_EISA)
Linus Torvalds1da177e2005-04-16 15:20:36 -070046int mp_bus_id_to_type [MAX_MP_BUSSES];
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +030047#endif
Alexey Starikovskiya6333c32008-03-20 14:54:09 +030048DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049int mp_bus_id_to_pci_bus [MAX_MP_BUSSES] = { [0 ... MAX_MP_BUSSES-1] = -1 };
50static int mp_current_pci_id;
51
52/* I/O APIC entries */
53struct mpc_config_ioapic mp_ioapics[MAX_IO_APICS];
54
55/* # of MP IRQ source entries */
56struct mpc_config_intsrc mp_irqs[MAX_IRQ_SOURCES];
57
58/* MP IRQ source entries */
59int mp_irq_entries;
60
61int nr_ioapics;
62
63int pic_mode;
64unsigned long mp_lapic_addr;
65
Venkatesh Pallipadi911a62d2005-09-03 15:56:31 -070066unsigned int def_to_bigsmp = 0;
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068/* Processor that is doing the boot up */
69unsigned int boot_cpu_physical_apicid = -1U;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070/* Internal processor count */
Sam Ravnborg87d7e982008-01-30 13:33:37 +010071unsigned int num_processors;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Glauber Costa7b1292e2008-03-03 14:12:41 -030073unsigned disabled_cpus __cpuinitdata;
74
Linus Torvalds1da177e2005-04-16 15:20:36 -070075/* Bitmask of physically existing CPUs */
76physid_mask_t phys_cpu_present_map;
77
Ingo Molnar11617052008-03-19 20:26:15 +010078#ifndef CONFIG_SMP
79DEFINE_PER_CPU(u16, x86_bios_cpu_apicid) = BAD_APICID;
80#endif
81
Linus Torvalds1da177e2005-04-16 15:20:36 -070082/*
83 * Intel MP BIOS table parsing routines:
84 */
85
86
87/*
88 * Checksum an MP configuration block.
89 */
90
91static int __init mpf_checksum(unsigned char *mp, int len)
92{
93 int sum = 0;
94
95 while (len--)
96 sum += *mp++;
97
98 return sum & 0xFF;
99}
100
Alexey Starikovskiy86420502008-03-17 22:08:55 +0300101#ifdef CONFIG_X86_NUMAQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102/*
103 * Have to match translation table entries to main table entries by counter
104 * hence the mpc_record variable .... can't see a less disgusting way of
105 * doing this ....
106 */
107
108static int mpc_record;
Vivek Goyal4a5d1072007-01-11 01:52:44 +0100109static struct mpc_config_translation *translation_table[MAX_MPC_ENTRY] __cpuinitdata;
Alexey Starikovskiy86420502008-03-17 22:08:55 +0300110#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Vivek Goyal4a5d1072007-01-11 01:52:44 +0100112static void __cpuinit MP_processor_info (struct mpc_config_processor *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113{
Glauber de Oliveira Costaa6c422c2008-03-19 14:25:25 -0300114 int ver, apicid, cpu;
115 cpumask_t tmp_map;
Andrew Morton12992322005-09-09 13:01:21 -0700116 physid_mask_t phys_cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Glauber Costa7b1292e2008-03-03 14:12:41 -0300118 if (!(m->mpc_cpuflag & CPU_ENABLED)) {
119 disabled_cpus++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 return;
Glauber Costa7b1292e2008-03-03 14:12:41 -0300121 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Alexey Starikovskiy4655c7d2008-03-17 22:08:36 +0300123#ifdef CONFIG_X86_NUMAQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 apicid = mpc_apic_id(m, translation_table[mpc_record]);
Alexey Starikovskiy4655c7d2008-03-17 22:08:36 +0300125#else
126 Dprintk("Processor #%d %u:%u APIC version %d\n",
127 m->mpc_apicid,
128 (m->mpc_cpufeature & CPU_FAMILY_MASK) >> 8,
129 (m->mpc_cpufeature & CPU_MODEL_MASK) >> 4,
130 m->mpc_apicver);
131 apicid = m->mpc_apicid;
132#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134 if (m->mpc_featureflag&(1<<0))
135 Dprintk(" Floating point unit present.\n");
136 if (m->mpc_featureflag&(1<<7))
137 Dprintk(" Machine Exception supported.\n");
138 if (m->mpc_featureflag&(1<<8))
139 Dprintk(" 64 bit compare & exchange supported.\n");
140 if (m->mpc_featureflag&(1<<9))
141 Dprintk(" Internal APIC present.\n");
142 if (m->mpc_featureflag&(1<<11))
143 Dprintk(" SEP present.\n");
144 if (m->mpc_featureflag&(1<<12))
145 Dprintk(" MTRR present.\n");
146 if (m->mpc_featureflag&(1<<13))
147 Dprintk(" PGE present.\n");
148 if (m->mpc_featureflag&(1<<14))
149 Dprintk(" MCA present.\n");
150 if (m->mpc_featureflag&(1<<15))
151 Dprintk(" CMOV present.\n");
152 if (m->mpc_featureflag&(1<<16))
153 Dprintk(" PAT present.\n");
154 if (m->mpc_featureflag&(1<<17))
155 Dprintk(" PSE present.\n");
156 if (m->mpc_featureflag&(1<<18))
157 Dprintk(" PSN present.\n");
158 if (m->mpc_featureflag&(1<<19))
159 Dprintk(" Cache Line Flush Instruction present.\n");
160 /* 20 Reserved */
161 if (m->mpc_featureflag&(1<<21))
162 Dprintk(" Debug Trace and EMON Store present.\n");
163 if (m->mpc_featureflag&(1<<22))
164 Dprintk(" ACPI Thermal Throttle Registers present.\n");
165 if (m->mpc_featureflag&(1<<23))
166 Dprintk(" MMX present.\n");
167 if (m->mpc_featureflag&(1<<24))
168 Dprintk(" FXSR present.\n");
169 if (m->mpc_featureflag&(1<<25))
170 Dprintk(" XMM present.\n");
171 if (m->mpc_featureflag&(1<<26))
172 Dprintk(" Willamette New Instructions present.\n");
173 if (m->mpc_featureflag&(1<<27))
174 Dprintk(" Self Snoop present.\n");
175 if (m->mpc_featureflag&(1<<28))
176 Dprintk(" HT present.\n");
177 if (m->mpc_featureflag&(1<<29))
178 Dprintk(" Thermal Monitor present.\n");
179 /* 30, 31 Reserved */
180
181
182 if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
183 Dprintk(" Bootup CPU\n");
184 boot_cpu_physical_apicid = m->mpc_apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 }
186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 ver = m->mpc_apicver;
188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 /*
190 * Validate version
191 */
192 if (ver == 0x0) {
Andrew Morton12992322005-09-09 13:01:21 -0700193 printk(KERN_WARNING "BIOS bug, APIC version is 0 for CPU#%d! "
194 "fixing up to 0x10. (tell your hw vendor)\n",
195 m->mpc_apicid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 ver = 0x10;
197 }
198 apic_version[m->mpc_apicid] = ver;
Eric W. Biederman6c180d92005-10-30 14:59:47 -0800199
200 phys_cpu = apicid_to_cpu_present(apicid);
201 physids_or(phys_cpu_present_map, phys_cpu_present_map, phys_cpu);
202
203 if (num_processors >= NR_CPUS) {
204 printk(KERN_WARNING "WARNING: NR_CPUS limit of %i reached."
205 " Processor ignored.\n", NR_CPUS);
206 return;
207 }
208
209 if (num_processors >= maxcpus) {
210 printk(KERN_WARNING "WARNING: maxcpus limit of %i reached."
211 " Processor ignored.\n", maxcpus);
212 return;
213 }
214
215 cpu_set(num_processors, cpu_possible_map);
216 num_processors++;
Glauber de Oliveira Costaa6c422c2008-03-19 14:25:25 -0300217 cpus_complement(tmp_map, cpu_present_map);
218 cpu = first_cpu(tmp_map);
219
220 if (m->mpc_cpuflag & CPU_BOOTPROCESSOR)
221 /*
222 * x86_bios_cpu_apicid is required to have processors listed
223 * in same order as logical cpu numbers. Hence the first
224 * entry is BSP, and so on.
225 */
226 cpu = 0;
Eric W. Biederman6c180d92005-10-30 14:59:47 -0800227
Ashok Raj6cf272a2006-04-10 22:53:07 -0700228 /*
229 * Would be preferable to switch to bigsmp when CONFIG_HOTPLUG_CPU=y
230 * but we need to work other dependencies like SMP_SUSPEND etc
231 * before this can be done without some confusion.
232 * if (CPU_HOTPLUG_ENABLED || num_processors > 8)
233 * - Ashok Raj <ashok.raj@intel.com>
234 */
235 if (num_processors > 8) {
Ashok Raje72c8582006-01-06 00:12:09 -0800236 switch (boot_cpu_data.x86_vendor) {
237 case X86_VENDOR_INTEL:
238 if (!APIC_XAPIC(ver)) {
239 def_to_bigsmp = 0;
240 break;
241 }
242 /* If P4 and above fall through */
243 case X86_VENDOR_AMD:
244 def_to_bigsmp = 1;
245 }
246 }
Ingo Molnar11617052008-03-19 20:26:15 +0100247#ifdef CONFIG_SMP
Glauber de Oliveira Costa73bf1022008-03-19 14:25:24 -0300248 /* are we being called early in kernel startup? */
249 if (x86_cpu_to_apicid_early_ptr) {
Glauber de Oliveira Costaa6c422c2008-03-19 14:25:25 -0300250 u16 *cpu_to_apicid = x86_cpu_to_apicid_early_ptr;
Glauber de Oliveira Costa73bf1022008-03-19 14:25:24 -0300251 u16 *bios_cpu_apicid = x86_bios_cpu_apicid_early_ptr;
Glauber de Oliveira Costaa6c422c2008-03-19 14:25:25 -0300252
253 cpu_to_apicid[cpu] = m->mpc_apicid;
Glauber de Oliveira Costa73bf1022008-03-19 14:25:24 -0300254 bios_cpu_apicid[num_processors - 1] = m->mpc_apicid;
255 } else {
Glauber de Oliveira Costaa6c422c2008-03-19 14:25:25 -0300256 per_cpu(x86_cpu_to_apicid, cpu) = m->mpc_apicid;
Glauber de Oliveira Costa73bf1022008-03-19 14:25:24 -0300257 per_cpu(x86_bios_cpu_apicid, cpu) = m->mpc_apicid;
258 }
Ingo Molnar11617052008-03-19 20:26:15 +0100259#endif
Glauber de Oliveira Costaa6c422c2008-03-19 14:25:25 -0300260 cpu_set(cpu, cpu_present_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261}
262
263static void __init MP_bus_info (struct mpc_config_bus *m)
264{
265 char str[7];
266
267 memcpy(str, m->mpc_bustype, 6);
268 str[6] = 0;
269
Alexey Starikovskiy0ec153a2008-03-17 22:08:48 +0300270#ifdef CONFIG_X86_NUMAQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 mpc_oem_bus_info(m, str, translation_table[mpc_record]);
Alexey Starikovskiy0ec153a2008-03-17 22:08:48 +0300272#else
273 Dprintk("Bus #%d is %s\n", m->mpc_busid, str);
274#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
Andi Kleen5e4edbb2006-09-26 10:52:35 +0200276#if MAX_MP_BUSSES < 256
Randy Dunlapc0ec31a2006-04-10 22:53:13 -0700277 if (m->mpc_busid >= MAX_MP_BUSSES) {
278 printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
279 " is too large, max. supported is %d\n",
280 m->mpc_busid, str, MAX_MP_BUSSES - 1);
281 return;
282 }
Andi Kleen5e4edbb2006-09-26 10:52:35 +0200283#endif
Randy Dunlapc0ec31a2006-04-10 22:53:13 -0700284
Alexey Starikovskiya6333c32008-03-20 14:54:09 +0300285 set_bit(m->mpc_busid, mp_bus_not_pci);
Alexey Starikovskiy9e0a2de2008-03-20 14:54:56 +0300286 if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI)-1) == 0) {
Alexey Starikovskiyd285e332008-03-17 22:08:42 +0300287#ifdef CONFIG_X86_NUMAQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 mpc_oem_pci_bus(m, translation_table[mpc_record]);
Alexey Starikovskiyd285e332008-03-17 22:08:42 +0300289#endif
Alexey Starikovskiya6333c32008-03-20 14:54:09 +0300290 clear_bit(m->mpc_busid, mp_bus_not_pci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 mp_bus_id_to_pci_bus[m->mpc_busid] = mp_current_pci_id;
292 mp_current_pci_id++;
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +0300293#if defined(CONFIG_EISA) || defined (CONFIG_MCA)
294 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI;
Alexey Starikovskiy9e0a2de2008-03-20 14:54:56 +0300295 } else if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA)-1) == 0) {
296 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA;
297 } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA)-1) == 0) {
298 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA)-1) == 0) {
300 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_MCA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 } else {
302 printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +0300303#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 }
305}
306
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300307static int bad_ioapic(unsigned long address)
308{
309 if (nr_ioapics >= MAX_IO_APICS) {
310 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
311 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
312 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
313 }
314 if (!address) {
315 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
316 " found in table, skipping!\n");
317 return 1;
318 }
319 return 0;
320}
321
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322static void __init MP_ioapic_info (struct mpc_config_ioapic *m)
323{
324 if (!(m->mpc_flags & MPC_APIC_USABLE))
325 return;
326
Thomas Gleixner64883ab2008-01-30 13:30:35 +0100327 printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 m->mpc_apicid, m->mpc_apicver, m->mpc_apicaddr);
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300329
330 if (bad_ioapic(m->mpc_apicaddr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 return;
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300332
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 mp_ioapics[nr_ioapics] = *m;
334 nr_ioapics++;
335}
336
337static void __init MP_intsrc_info (struct mpc_config_intsrc *m)
338{
339 mp_irqs [mp_irq_entries] = *m;
340 Dprintk("Int: type %d, pol %d, trig %d, bus %d,"
341 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
342 m->mpc_irqtype, m->mpc_irqflag & 3,
343 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
344 m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
345 if (++mp_irq_entries == MAX_IRQ_SOURCES)
346 panic("Max # of irq sources exceeded!!\n");
347}
348
349static void __init MP_lintsrc_info (struct mpc_config_lintsrc *m)
350{
351 Dprintk("Lint: type %d, pol %d, trig %d, bus %d,"
352 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
353 m->mpc_irqtype, m->mpc_irqflag & 3,
354 (m->mpc_irqflag >> 2) &3, m->mpc_srcbusid,
355 m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356}
357
358#ifdef CONFIG_X86_NUMAQ
359static void __init MP_translation_info (struct mpc_config_translation *m)
360{
361 printk(KERN_INFO "Translation: record %d, type %d, quad %d, global %d, local %d\n", mpc_record, m->trans_type, m->trans_quad, m->trans_global, m->trans_local);
362
363 if (mpc_record >= MAX_MPC_ENTRY)
364 printk(KERN_ERR "MAX_MPC_ENTRY exceeded!\n");
365 else
366 translation_table[mpc_record] = m; /* stash this for later */
367 if (m->trans_quad < MAX_NUMNODES && !node_online(m->trans_quad))
368 node_set_online(m->trans_quad);
369}
370
371/*
372 * Read/parse the MPC oem tables
373 */
374
375static void __init smp_read_mpc_oem(struct mp_config_oemtable *oemtable, \
376 unsigned short oemsize)
377{
378 int count = sizeof (*oemtable); /* the header size */
379 unsigned char *oemptr = ((unsigned char *)oemtable)+count;
380
381 mpc_record = 0;
382 printk(KERN_INFO "Found an OEM MPC table at %8p - parsing it ... \n", oemtable);
383 if (memcmp(oemtable->oem_signature,MPC_OEM_SIGNATURE,4))
384 {
385 printk(KERN_WARNING "SMP mpc oemtable: bad signature [%c%c%c%c]!\n",
386 oemtable->oem_signature[0],
387 oemtable->oem_signature[1],
388 oemtable->oem_signature[2],
389 oemtable->oem_signature[3]);
390 return;
391 }
392 if (mpf_checksum((unsigned char *)oemtable,oemtable->oem_length))
393 {
394 printk(KERN_WARNING "SMP oem mptable: checksum error!\n");
395 return;
396 }
397 while (count < oemtable->oem_length) {
398 switch (*oemptr) {
399 case MP_TRANSLATION:
400 {
401 struct mpc_config_translation *m=
402 (struct mpc_config_translation *)oemptr;
403 MP_translation_info(m);
404 oemptr += sizeof(*m);
405 count += sizeof(*m);
406 ++mpc_record;
407 break;
408 }
409 default:
410 {
411 printk(KERN_WARNING "Unrecognised OEM table entry type! - %d\n", (int) *oemptr);
412 return;
413 }
414 }
415 }
416}
417
418static inline void mps_oem_check(struct mp_config_table *mpc, char *oem,
419 char *productid)
420{
421 if (strncmp(oem, "IBM NUMA", 8))
422 printk("Warning! May not be a NUMA-Q system!\n");
423 if (mpc->mpc_oemptr)
424 smp_read_mpc_oem((struct mp_config_oemtable *) mpc->mpc_oemptr,
425 mpc->mpc_oemsize);
426}
427#endif /* CONFIG_X86_NUMAQ */
428
429/*
430 * Read/parse the MPC
431 */
432
433static int __init smp_read_mpc(struct mp_config_table *mpc)
434{
435 char str[16];
436 char oem[10];
437 int count=sizeof(*mpc);
438 unsigned char *mpt=((unsigned char *)mpc)+count;
439
440 if (memcmp(mpc->mpc_signature,MPC_SIGNATURE,4)) {
441 printk(KERN_ERR "SMP mptable: bad signature [0x%x]!\n",
442 *(u32 *)mpc->mpc_signature);
443 return 0;
444 }
445 if (mpf_checksum((unsigned char *)mpc,mpc->mpc_length)) {
446 printk(KERN_ERR "SMP mptable: checksum error!\n");
447 return 0;
448 }
449 if (mpc->mpc_spec!=0x01 && mpc->mpc_spec!=0x04) {
450 printk(KERN_ERR "SMP mptable: bad table version (%d)!!\n",
451 mpc->mpc_spec);
452 return 0;
453 }
454 if (!mpc->mpc_lapic) {
455 printk(KERN_ERR "SMP mptable: null local APIC address!\n");
456 return 0;
457 }
458 memcpy(oem,mpc->mpc_oem,8);
459 oem[8]=0;
460 printk(KERN_INFO "OEM ID: %s ",oem);
461
462 memcpy(str,mpc->mpc_productid,12);
463 str[12]=0;
464 printk("Product ID: %s ",str);
465
466 mps_oem_check(mpc, oem, str);
467
Thomas Gleixner64883ab2008-01-30 13:30:35 +0100468 printk("APIC at: 0x%X\n", mpc->mpc_lapic);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
Thomas Gleixner64883ab2008-01-30 13:30:35 +0100470 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 * Save the local APIC address (it might be non-default) -- but only
472 * if we're not using ACPI.
473 */
474 if (!acpi_lapic)
475 mp_lapic_addr = mpc->mpc_lapic;
476
477 /*
478 * Now process the configuration blocks.
479 */
Alexey Starikovskiy86420502008-03-17 22:08:55 +0300480#ifdef CONFIG_X86_NUMAQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 mpc_record = 0;
Alexey Starikovskiy86420502008-03-17 22:08:55 +0300482#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 while (count < mpc->mpc_length) {
484 switch(*mpt) {
485 case MP_PROCESSOR:
486 {
487 struct mpc_config_processor *m=
488 (struct mpc_config_processor *)mpt;
489 /* ACPI may have already provided this data */
490 if (!acpi_lapic)
491 MP_processor_info(m);
492 mpt += sizeof(*m);
493 count += sizeof(*m);
494 break;
495 }
496 case MP_BUS:
497 {
498 struct mpc_config_bus *m=
499 (struct mpc_config_bus *)mpt;
500 MP_bus_info(m);
501 mpt += sizeof(*m);
502 count += sizeof(*m);
503 break;
504 }
505 case MP_IOAPIC:
506 {
507 struct mpc_config_ioapic *m=
508 (struct mpc_config_ioapic *)mpt;
509 MP_ioapic_info(m);
510 mpt+=sizeof(*m);
511 count+=sizeof(*m);
512 break;
513 }
514 case MP_INTSRC:
515 {
516 struct mpc_config_intsrc *m=
517 (struct mpc_config_intsrc *)mpt;
518
519 MP_intsrc_info(m);
520 mpt+=sizeof(*m);
521 count+=sizeof(*m);
522 break;
523 }
524 case MP_LINTSRC:
525 {
526 struct mpc_config_lintsrc *m=
527 (struct mpc_config_lintsrc *)mpt;
528 MP_lintsrc_info(m);
529 mpt+=sizeof(*m);
530 count+=sizeof(*m);
531 break;
532 }
533 default:
534 {
535 count = mpc->mpc_length;
536 break;
537 }
538 }
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 }
Ingo Molnar3c43f032007-05-02 19:27:04 +0200543 setup_apic_routing();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 if (!num_processors)
545 printk(KERN_ERR "SMP mptable: no processors registered!\n");
546 return num_processors;
547}
548
549static int __init ELCR_trigger(unsigned int irq)
550{
551 unsigned int port;
552
553 port = 0x4d0 + (irq >> 3);
554 return (inb(port) >> (irq & 7)) & 1;
555}
556
557static void __init construct_default_ioirq_mptable(int mpc_default_type)
558{
559 struct mpc_config_intsrc intsrc;
560 int i;
561 int ELCR_fallback = 0;
562
563 intsrc.mpc_type = MP_INTSRC;
564 intsrc.mpc_irqflag = 0; /* conforming */
565 intsrc.mpc_srcbus = 0;
566 intsrc.mpc_dstapic = mp_ioapics[0].mpc_apicid;
567
568 intsrc.mpc_irqtype = mp_INT;
569
570 /*
571 * If true, we have an ISA/PCI system with no IRQ entries
572 * in the MP table. To prevent the PCI interrupts from being set up
573 * incorrectly, we try to use the ELCR. The sanity check to see if
574 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
575 * never be level sensitive, so we simply see if the ELCR agrees.
576 * If it does, we assume it's valid.
577 */
578 if (mpc_default_type == 5) {
579 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... falling back to ELCR\n");
580
581 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) || ELCR_trigger(13))
582 printk(KERN_WARNING "ELCR contains invalid data... not using ELCR\n");
583 else {
584 printk(KERN_INFO "Using ELCR to identify PCI interrupts\n");
585 ELCR_fallback = 1;
586 }
587 }
588
589 for (i = 0; i < 16; i++) {
590 switch (mpc_default_type) {
591 case 2:
592 if (i == 0 || i == 13)
593 continue; /* IRQ0 & IRQ13 not connected */
594 /* fall through */
595 default:
596 if (i == 2)
597 continue; /* IRQ2 is never connected */
598 }
599
600 if (ELCR_fallback) {
601 /*
602 * If the ELCR indicates a level-sensitive interrupt, we
603 * copy that information over to the MP table in the
604 * irqflag field (level sensitive, active high polarity).
605 */
606 if (ELCR_trigger(i))
607 intsrc.mpc_irqflag = 13;
608 else
609 intsrc.mpc_irqflag = 0;
610 }
611
612 intsrc.mpc_srcbusirq = i;
613 intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
614 MP_intsrc_info(&intsrc);
615 }
616
617 intsrc.mpc_irqtype = mp_ExtINT;
618 intsrc.mpc_srcbusirq = 0;
619 intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */
620 MP_intsrc_info(&intsrc);
621}
622
623static inline void __init construct_default_ISA_mptable(int mpc_default_type)
624{
625 struct mpc_config_processor processor;
626 struct mpc_config_bus bus;
627 struct mpc_config_ioapic ioapic;
628 struct mpc_config_lintsrc lintsrc;
629 int linttypes[2] = { mp_ExtINT, mp_NMI };
630 int i;
631
632 /*
633 * local APIC has default address
634 */
635 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
636
637 /*
638 * 2 CPUs, numbered 0 & 1.
639 */
640 processor.mpc_type = MP_PROCESSOR;
641 /* Either an integrated APIC or a discrete 82489DX. */
642 processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
643 processor.mpc_cpuflag = CPU_ENABLED;
644 processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
645 (boot_cpu_data.x86_model << 4) |
646 boot_cpu_data.x86_mask;
647 processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
648 processor.mpc_reserved[0] = 0;
649 processor.mpc_reserved[1] = 0;
650 for (i = 0; i < 2; i++) {
651 processor.mpc_apicid = i;
652 MP_processor_info(&processor);
653 }
654
655 bus.mpc_type = MP_BUS;
656 bus.mpc_busid = 0;
657 switch (mpc_default_type) {
658 default:
659 printk("???\n");
660 printk(KERN_ERR "Unknown standard configuration %d\n",
661 mpc_default_type);
662 /* fall through */
663 case 1:
664 case 5:
665 memcpy(bus.mpc_bustype, "ISA ", 6);
666 break;
667 case 2:
668 case 6:
669 case 3:
670 memcpy(bus.mpc_bustype, "EISA ", 6);
671 break;
672 case 4:
673 case 7:
674 memcpy(bus.mpc_bustype, "MCA ", 6);
675 }
676 MP_bus_info(&bus);
677 if (mpc_default_type > 4) {
678 bus.mpc_busid = 1;
679 memcpy(bus.mpc_bustype, "PCI ", 6);
680 MP_bus_info(&bus);
681 }
682
683 ioapic.mpc_type = MP_IOAPIC;
684 ioapic.mpc_apicid = 2;
685 ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
686 ioapic.mpc_flags = MPC_APIC_USABLE;
687 ioapic.mpc_apicaddr = 0xFEC00000;
688 MP_ioapic_info(&ioapic);
689
690 /*
691 * We set up most of the low 16 IO-APIC pins according to MPS rules.
692 */
693 construct_default_ioirq_mptable(mpc_default_type);
694
695 lintsrc.mpc_type = MP_LINTSRC;
696 lintsrc.mpc_irqflag = 0; /* conforming */
697 lintsrc.mpc_srcbusid = 0;
698 lintsrc.mpc_srcbusirq = 0;
699 lintsrc.mpc_destapic = MP_APIC_ALL;
700 for (i = 0; i < 2; i++) {
701 lintsrc.mpc_irqtype = linttypes[i];
702 lintsrc.mpc_destapiclint = i;
703 MP_lintsrc_info(&lintsrc);
704 }
705}
706
707static struct intel_mp_floating *mpf_found;
708
709/*
710 * Scan the memory blocks for an SMP configuration block.
711 */
712void __init get_smp_config (void)
713{
714 struct intel_mp_floating *mpf = mpf_found;
715
716 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 * ACPI supports both logical (e.g. Hyper-Threading) and physical
718 * processors, where MPS only supports physical.
719 */
720 if (acpi_lapic && acpi_ioapic) {
721 printk(KERN_INFO "Using ACPI (MADT) for SMP configuration information\n");
722 return;
723 }
724 else if (acpi_lapic)
725 printk(KERN_INFO "Using ACPI for processor (LAPIC) configuration information\n");
726
727 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n", mpf->mpf_specification);
728 if (mpf->mpf_feature2 & (1<<7)) {
729 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
730 pic_mode = 1;
731 } else {
732 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
733 pic_mode = 0;
734 }
735
736 /*
737 * Now see if we need to read further.
738 */
739 if (mpf->mpf_feature1 != 0) {
740
741 printk(KERN_INFO "Default MP configuration #%d\n", mpf->mpf_feature1);
742 construct_default_ISA_mptable(mpf->mpf_feature1);
743
744 } else if (mpf->mpf_physptr) {
745
746 /*
747 * Read the physical hardware table. Anything here will
748 * override the defaults.
749 */
Daniel Yeisley7d4c8e52006-02-20 18:27:54 -0800750 if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 smp_found_config = 0;
752 printk(KERN_ERR "BIOS bug, MP table errors detected!...\n");
753 printk(KERN_ERR "... disabling SMP support. (tell your hw vendor)\n");
754 return;
755 }
756 /*
757 * If there are no explicit MP IRQ entries, then we are
758 * broken. We set up most of the low 16 IO-APIC pins to
759 * ISA defaults and hope it will work.
760 */
761 if (!mp_irq_entries) {
762 struct mpc_config_bus bus;
763
764 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, using default mptable. (tell your hw vendor)\n");
765
766 bus.mpc_type = MP_BUS;
767 bus.mpc_busid = 0;
768 memcpy(bus.mpc_bustype, "ISA ", 6);
769 MP_bus_info(&bus);
770
771 construct_default_ioirq_mptable(0);
772 }
773
774 } else
775 BUG();
776
777 printk(KERN_INFO "Processors: %d\n", num_processors);
778 /*
779 * Only use the first configuration found.
780 */
781}
782
783static int __init smp_scan_config (unsigned long base, unsigned long length)
784{
785 unsigned long *bp = phys_to_virt(base);
786 struct intel_mp_floating *mpf;
787
Ingo Molnare91a3b42008-01-30 13:33:08 +0100788 printk(KERN_INFO "Scan SMP from %p for %ld bytes.\n", bp,length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 if (sizeof(*mpf) != 16)
790 printk("Error: MPF size\n");
791
792 while (length > 0) {
793 mpf = (struct intel_mp_floating *)bp;
794 if ((*bp == SMP_MAGIC_IDENT) &&
795 (mpf->mpf_length == 1) &&
796 !mpf_checksum((unsigned char *)bp, 16) &&
797 ((mpf->mpf_specification == 1)
798 || (mpf->mpf_specification == 4)) ) {
799
800 smp_found_config = 1;
Ingo Molnare91a3b42008-01-30 13:33:08 +0100801 printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
802 mpf, virt_to_phys(mpf));
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800803 reserve_bootmem(virt_to_phys(mpf), PAGE_SIZE,
804 BOOTMEM_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 if (mpf->mpf_physptr) {
806 /*
807 * We cannot access to MPC table to compute
808 * table size yet, as only few megabytes from
809 * the bottom is mapped now.
810 * PC-9800's MPC table places on the very last
811 * of physical memory; so that simply reserving
812 * PAGE_SIZE from mpg->mpf_physptr yields BUG()
813 * in reserve_bootmem.
814 */
815 unsigned long size = PAGE_SIZE;
816 unsigned long end = max_low_pfn * PAGE_SIZE;
817 if (mpf->mpf_physptr + size > end)
818 size = end - mpf->mpf_physptr;
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800819 reserve_bootmem(mpf->mpf_physptr, size,
820 BOOTMEM_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 }
822
823 mpf_found = mpf;
824 return 1;
825 }
826 bp += 4;
827 length -= 16;
828 }
829 return 0;
830}
831
832void __init find_smp_config (void)
833{
834 unsigned int address;
835
836 /*
837 * FIXME: Linux assumes you have 640K of base ram..
838 * this continues the error...
839 *
840 * 1) Scan the bottom 1K for a signature
841 * 2) Scan the top 1K of base RAM
842 * 3) Scan the 64K of bios
843 */
844 if (smp_scan_config(0x0,0x400) ||
845 smp_scan_config(639*0x400,0x400) ||
846 smp_scan_config(0xF0000,0x10000))
847 return;
848 /*
849 * If it is an SMP machine we should know now, unless the
850 * configuration is in an EISA/MCA bus machine with an
851 * extended bios data area.
852 *
853 * there is a real-mode segmented pointer pointing to the
854 * 4K EBDA area at 0x40E, calculate and scan it here.
855 *
856 * NOTE! There are Linux loaders that will corrupt the EBDA
857 * area, and as such this kind of SMP config may be less
858 * trustworthy, simply because the SMP table may have been
859 * stomped on during early boot. These loaders are buggy and
860 * should be fixed.
861 *
862 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
863 */
864
865 address = get_bios_ebda();
866 if (address)
867 smp_scan_config(address, 0x400);
868}
869
Natalie.Protasevich@unisys.come5428ed2006-03-23 02:59:36 -0800870int es7000_plat;
871
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872/* --------------------------------------------------------------------------
873 ACPI-based MP Configuration
874 -------------------------------------------------------------------------- */
875
Len Brown888ba6c2005-08-24 12:07:20 -0400876#ifdef CONFIG_ACPI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
Andi Kleen19f03ff2006-09-26 10:52:30 +0200878void __init mp_register_lapic_address(u64 address)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879{
880 mp_lapic_addr = (unsigned long) address;
881
882 set_fixmap_nocache(FIX_APIC_BASE, mp_lapic_addr);
883
884 if (boot_cpu_physical_apicid == -1U)
885 boot_cpu_physical_apicid = GET_APIC_ID(apic_read(APIC_ID));
886
887 Dprintk("Boot CPU = %d\n", boot_cpu_physical_apicid);
888}
889
Vivek Goyal4a5d1072007-01-11 01:52:44 +0100890void __cpuinit mp_register_lapic (u8 id, u8 enabled)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891{
892 struct mpc_config_processor processor;
Andi Kleen19f03ff2006-09-26 10:52:30 +0200893 int boot_cpu = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
895 if (MAX_APICS - id <= 0) {
896 printk(KERN_WARNING "Processor #%d invalid (max %d)\n",
897 id, MAX_APICS);
898 return;
899 }
900
901 if (id == boot_cpu_physical_apicid)
902 boot_cpu = 1;
903
904 processor.mpc_type = MP_PROCESSOR;
905 processor.mpc_apicid = id;
906 processor.mpc_apicver = GET_APIC_VERSION(apic_read(APIC_LVR));
907 processor.mpc_cpuflag = (enabled ? CPU_ENABLED : 0);
908 processor.mpc_cpuflag |= (boot_cpu ? CPU_BOOTPROCESSOR : 0);
909 processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
910 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
911 processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
912 processor.mpc_reserved[0] = 0;
913 processor.mpc_reserved[1] = 0;
914
915 MP_processor_info(&processor);
916}
917
Len Brown84663612005-08-24 12:09:07 -0400918#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919
920#define MP_ISA_BUS 0
921#define MP_MAX_IOAPIC_PIN 127
922
923static struct mp_ioapic_routing {
924 int apic_id;
925 int gsi_base;
926 int gsi_end;
927 u32 pin_programmed[4];
928} mp_ioapic_routing[MAX_IO_APICS];
929
Andi Kleen19f03ff2006-09-26 10:52:30 +0200930static int mp_find_ioapic (int gsi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931{
Andi Kleen19f03ff2006-09-26 10:52:30 +0200932 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
934 /* Find the IOAPIC that manages this GSI. */
935 for (i = 0; i < nr_ioapics; i++) {
936 if ((gsi >= mp_ioapic_routing[i].gsi_base)
937 && (gsi <= mp_ioapic_routing[i].gsi_end))
938 return i;
939 }
940
941 printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %d\n", gsi);
942
943 return -1;
944}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
Alexey Starikovskiye3e3ffa2008-03-17 22:08:11 +0300946static u8 uniq_ioapic_id(u8 id)
947{
948 if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) &&
949 !APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
950 return io_apic_get_unique_id(nr_ioapics, id);
951 else
952 return id;
953}
954
Andi Kleen19f03ff2006-09-26 10:52:30 +0200955void __init mp_register_ioapic(u8 id, u32 address, u32 gsi_base)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956{
Andi Kleen19f03ff2006-09-26 10:52:30 +0200957 int idx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300959 if (bad_ioapic(address))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
Alexey Starikovskiye3e3ffa2008-03-17 22:08:11 +0300962 idx = nr_ioapics;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
964 mp_ioapics[idx].mpc_type = MP_IOAPIC;
965 mp_ioapics[idx].mpc_flags = MPC_APIC_USABLE;
966 mp_ioapics[idx].mpc_apicaddr = address;
967
968 set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
Alexey Starikovskiye3e3ffa2008-03-17 22:08:11 +0300969 mp_ioapics[idx].mpc_apicid = uniq_ioapic_id(id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 mp_ioapics[idx].mpc_apicver = io_apic_get_version(idx);
971
972 /*
973 * Build basic GSI lookup table to facilitate gsi->io_apic lookups
974 * and to prevent reprogramming of IOAPIC pins (PCI GSIs).
975 */
976 mp_ioapic_routing[idx].apic_id = mp_ioapics[idx].mpc_apicid;
977 mp_ioapic_routing[idx].gsi_base = gsi_base;
Thomas Gleixner64883ab2008-01-30 13:30:35 +0100978 mp_ioapic_routing[idx].gsi_end = gsi_base +
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 io_apic_get_redir_entries(idx);
980
Thomas Gleixner64883ab2008-01-30 13:30:35 +0100981 printk("IOAPIC[%d]: apic_id %d, version %d, address 0x%x, "
982 "GSI %d-%d\n", idx, mp_ioapics[idx].mpc_apicid,
Alexey Starikovskiye3e3ffa2008-03-17 22:08:11 +0300983 mp_ioapics[idx].mpc_apicver,
984 mp_ioapics[idx].mpc_apicaddr,
Thomas Gleixner64883ab2008-01-30 13:30:35 +0100985 mp_ioapic_routing[idx].gsi_base,
986 mp_ioapic_routing[idx].gsi_end);
Alexey Starikovskiye3e3ffa2008-03-17 22:08:11 +0300987
988 nr_ioapics++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989}
990
Andi Kleen19f03ff2006-09-26 10:52:30 +0200991void __init
992mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993{
994 struct mpc_config_intsrc intsrc;
995 int ioapic = -1;
996 int pin = -1;
997
998 /*
999 * Convert 'gsi' to 'ioapic.pin'.
1000 */
1001 ioapic = mp_find_ioapic(gsi);
1002 if (ioapic < 0)
1003 return;
1004 pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
1005
1006 /*
1007 * TBD: This check is for faulty timer entries, where the override
1008 * erroneously sets the trigger to level, resulting in a HUGE
1009 * increase of timer interrupts!
1010 */
1011 if ((bus_irq == 0) && (trigger == 3))
1012 trigger = 1;
1013
1014 intsrc.mpc_type = MP_INTSRC;
1015 intsrc.mpc_irqtype = mp_INT;
1016 intsrc.mpc_irqflag = (trigger << 2) | polarity;
1017 intsrc.mpc_srcbus = MP_ISA_BUS;
1018 intsrc.mpc_srcbusirq = bus_irq; /* IRQ */
1019 intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid; /* APIC ID */
1020 intsrc.mpc_dstirq = pin; /* INTIN# */
1021
1022 Dprintk("Int: type %d, pol %d, trig %d, bus %d, irq %d, %d-%d\n",
1023 intsrc.mpc_irqtype, intsrc.mpc_irqflag & 3,
1024 (intsrc.mpc_irqflag >> 2) & 3, intsrc.mpc_srcbus,
1025 intsrc.mpc_srcbusirq, intsrc.mpc_dstapic, intsrc.mpc_dstirq);
1026
1027 mp_irqs[mp_irq_entries] = intsrc;
1028 if (++mp_irq_entries == MAX_IRQ_SOURCES)
1029 panic("Max # of irq sources exceeded!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030}
1031
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032void __init mp_config_acpi_legacy_irqs (void)
1033{
1034 struct mpc_config_intsrc intsrc;
Andi Kleen19f03ff2006-09-26 10:52:30 +02001035 int i = 0;
1036 int ioapic = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +03001038#if defined (CONFIG_MCA) || defined (CONFIG_EISA)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 /*
1040 * Fabricate the legacy ISA bus (bus #31).
1041 */
1042 mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +03001043#endif
Alexey Starikovskiya6333c32008-03-20 14:54:09 +03001044 set_bit(MP_ISA_BUS, mp_bus_not_pci);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 Dprintk("Bus #%d is ISA\n", MP_ISA_BUS);
1046
1047 /*
1048 * Older generations of ES7000 have no legacy identity mappings
1049 */
1050 if (es7000_plat == 1)
1051 return;
1052
1053 /*
1054 * Locate the IOAPIC that manages the ISA IRQs (0-15).
1055 */
1056 ioapic = mp_find_ioapic(0);
1057 if (ioapic < 0)
1058 return;
1059
1060 intsrc.mpc_type = MP_INTSRC;
1061 intsrc.mpc_irqflag = 0; /* Conforming */
1062 intsrc.mpc_srcbus = MP_ISA_BUS;
1063 intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid;
1064
1065 /*
1066 * Use the default configuration for the IRQs 0-15. Unless
Simon Arlott27b46d72007-10-20 01:13:56 +02001067 * overridden by (MADT) interrupt source override entries.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 */
1069 for (i = 0; i < 16; i++) {
1070 int idx;
1071
1072 for (idx = 0; idx < mp_irq_entries; idx++) {
1073 struct mpc_config_intsrc *irq = mp_irqs + idx;
1074
1075 /* Do we already have a mapping for this ISA IRQ? */
1076 if (irq->mpc_srcbus == MP_ISA_BUS && irq->mpc_srcbusirq == i)
1077 break;
1078
1079 /* Do we already have a mapping for this IOAPIC pin */
1080 if ((irq->mpc_dstapic == intsrc.mpc_dstapic) &&
1081 (irq->mpc_dstirq == i))
1082 break;
1083 }
1084
1085 if (idx != mp_irq_entries) {
1086 printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
1087 continue; /* IRQ already used */
1088 }
1089
1090 intsrc.mpc_irqtype = mp_INT;
1091 intsrc.mpc_srcbusirq = i; /* Identity mapped */
1092 intsrc.mpc_dstirq = i;
1093
1094 Dprintk("Int: type %d, pol %d, trig %d, bus %d, irq %d, "
1095 "%d-%d\n", intsrc.mpc_irqtype, intsrc.mpc_irqflag & 3,
1096 (intsrc.mpc_irqflag >> 2) & 3, intsrc.mpc_srcbus,
1097 intsrc.mpc_srcbusirq, intsrc.mpc_dstapic,
1098 intsrc.mpc_dstirq);
1099
1100 mp_irqs[mp_irq_entries] = intsrc;
1101 if (++mp_irq_entries == MAX_IRQ_SOURCES)
1102 panic("Max # of irq sources exceeded!\n");
1103 }
1104}
1105
Natalie Protasevichc434b7a2005-06-23 00:08:29 -07001106#define MAX_GSI_NUM 4096
Len Brown2ba7dee2008-01-30 13:31:02 +01001107#define IRQ_COMPRESSION_START 64
Natalie Protasevichc434b7a2005-06-23 00:08:29 -07001108
Andi Kleen19f03ff2006-09-26 10:52:30 +02001109int mp_register_gsi(u32 gsi, int triggering, int polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110{
Andi Kleen19f03ff2006-09-26 10:52:30 +02001111 int ioapic = -1;
1112 int ioapic_pin = 0;
1113 int idx, bit = 0;
Len Brown2ba7dee2008-01-30 13:31:02 +01001114 static int pci_irq = IRQ_COMPRESSION_START;
Natalie Protasevichc434b7a2005-06-23 00:08:29 -07001115 /*
Joe Perchesab4a5742008-01-30 13:31:42 +01001116 * Mapping between Global System Interrupts, which
Natalie Protasevichc434b7a2005-06-23 00:08:29 -07001117 * represent all possible interrupts, and IRQs
1118 * assigned to actual devices.
1119 */
1120 static int gsi_to_irq[MAX_GSI_NUM];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 /* Don't set up the ACPI SCI because it's already set up */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +03001123 if (acpi_gbl_FADT.sci_interrupt == gsi)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 return gsi;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125
1126 ioapic = mp_find_ioapic(gsi);
1127 if (ioapic < 0) {
1128 printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
1129 return gsi;
1130 }
1131
1132 ioapic_pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
1133
1134 if (ioapic_renumber_irq)
1135 gsi = ioapic_renumber_irq(ioapic, gsi);
1136
1137 /*
1138 * Avoid pin reprogramming. PRTs typically include entries
1139 * with redundant pin->gsi mappings (but unique PCI devices);
1140 * we only program the IOAPIC on the first.
1141 */
1142 bit = ioapic_pin % 32;
1143 idx = (ioapic_pin < 32) ? 0 : (ioapic_pin / 32);
1144 if (idx > 3) {
1145 printk(KERN_ERR "Invalid reference to IOAPIC pin "
1146 "%d-%d\n", mp_ioapic_routing[ioapic].apic_id,
1147 ioapic_pin);
1148 return gsi;
1149 }
1150 if ((1<<bit) & mp_ioapic_routing[ioapic].pin_programmed[idx]) {
1151 Dprintk(KERN_DEBUG "Pin %d-%d already programmed\n",
1152 mp_ioapic_routing[ioapic].apic_id, ioapic_pin);
Len Brown2ba7dee2008-01-30 13:31:02 +01001153 return (gsi < IRQ_COMPRESSION_START ? gsi : gsi_to_irq[gsi]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 }
1155
1156 mp_ioapic_routing[ioapic].pin_programmed[idx] |= (1<<bit);
1157
Len Brown2ba7dee2008-01-30 13:31:02 +01001158 /*
1159 * For GSI >= 64, use IRQ compression
1160 */
1161 if ((gsi >= IRQ_COMPRESSION_START)
1162 && (triggering == ACPI_LEVEL_SENSITIVE)) {
Natalie Protasevichc434b7a2005-06-23 00:08:29 -07001163 /*
1164 * For PCI devices assign IRQs in order, avoiding gaps
1165 * due to unused I/O APIC pins.
1166 */
1167 int irq = gsi;
1168 if (gsi < MAX_GSI_NUM) {
Kimball Murraye0c1e9b2006-05-08 15:17:16 +02001169 /*
1170 * Retain the VIA chipset work-around (gsi > 15), but
1171 * avoid a problem where the 8254 timer (IRQ0) is setup
1172 * via an override (so it's not on pin 0 of the ioapic),
1173 * and at the same time, the pin 0 interrupt is a PCI
1174 * type. The gsi > 15 test could cause these two pins
1175 * to be shared as IRQ0, and they are not shareable.
1176 * So test for this condition, and if necessary, avoid
1177 * the pin collision.
1178 */
Adrian Bunkede13892008-03-17 22:29:32 +02001179 gsi = pci_irq++;
Natalie.Protasevich@unisys.come1afc3f2005-07-29 14:03:32 -07001180 /*
1181 * Don't assign IRQ used by ACPI SCI
1182 */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +03001183 if (gsi == acpi_gbl_FADT.sci_interrupt)
Natalie.Protasevich@unisys.come1afc3f2005-07-29 14:03:32 -07001184 gsi = pci_irq++;
Natalie Protasevichc434b7a2005-06-23 00:08:29 -07001185 gsi_to_irq[irq] = gsi;
1186 } else {
1187 printk(KERN_ERR "GSI %u is too high\n", gsi);
1188 return gsi;
1189 }
1190 }
1191
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 io_apic_set_pci_routing(ioapic, ioapic_pin, gsi,
Len Browncb654692005-12-28 02:43:51 -05001193 triggering == ACPI_EDGE_SENSITIVE ? 0 : 1,
1194 polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 return gsi;
1196}
1197
Len Brown84663612005-08-24 12:09:07 -04001198#endif /* CONFIG_X86_IO_APIC */
Len Brown888ba6c2005-08-24 12:07:20 -04001199#endif /* CONFIG_ACPI */