blob: b0aed978eef1de37980544c8cbcdc82540729378 [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
Alexey Starikovskiyc853c672008-03-27 23:54:13 +0300112static void __cpuinit generic_processor_info(int apicid, int version)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113{
Alexey Starikovskiyc853c672008-03-27 23:54:13 +0300114 int cpu;
Glauber de Oliveira Costaa6c422c2008-03-19 14:25:25 -0300115 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
Alexey Starikovskiyc853c672008-03-27 23:54:13 +0300118
119 /*
120 * Validate version
121 */
122 if (version == 0x0) {
123 printk(KERN_WARNING "BIOS bug, APIC version is 0 for CPU#%d! "
124 "fixing up to 0x10. (tell your hw vendor)\n",
125 version);
126 version = 0x10;
127 }
128 apic_version[apicid] = version;
129
130 phys_cpu = apicid_to_cpu_present(apicid);
131 physids_or(phys_cpu_present_map, phys_cpu_present_map, phys_cpu);
132
133 if (num_processors >= NR_CPUS) {
134 printk(KERN_WARNING "WARNING: NR_CPUS limit of %i reached."
135 " Processor ignored.\n", NR_CPUS);
136 return;
137 }
138
139 if (num_processors >= maxcpus) {
140 printk(KERN_WARNING "WARNING: maxcpus limit of %i reached."
141 " Processor ignored.\n", maxcpus);
142 return;
143 }
144
145 num_processors++;
146 cpus_complement(tmp_map, cpu_present_map);
147 cpu = first_cpu(tmp_map);
148
149 if (apicid == boot_cpu_physical_apicid)
150 /*
151 * x86_bios_cpu_apicid is required to have processors listed
152 * in same order as logical cpu numbers. Hence the first
153 * entry is BSP, and so on.
154 */
155 cpu = 0;
156
157 /*
158 * Would be preferable to switch to bigsmp when CONFIG_HOTPLUG_CPU=y
159 * but we need to work other dependencies like SMP_SUSPEND etc
160 * before this can be done without some confusion.
161 * if (CPU_HOTPLUG_ENABLED || num_processors > 8)
162 * - Ashok Raj <ashok.raj@intel.com>
163 */
164 if (num_processors > 8) {
165 switch (boot_cpu_data.x86_vendor) {
166 case X86_VENDOR_INTEL:
167 if (!APIC_XAPIC(version)) {
168 def_to_bigsmp = 0;
169 break;
170 }
171 /* If P4 and above fall through */
172 case X86_VENDOR_AMD:
173 def_to_bigsmp = 1;
174 }
175 }
176#ifdef CONFIG_SMP
177 /* are we being called early in kernel startup? */
178 if (x86_cpu_to_apicid_early_ptr) {
179 u16 *cpu_to_apicid = x86_cpu_to_apicid_early_ptr;
180 u16 *bios_cpu_apicid = x86_bios_cpu_apicid_early_ptr;
181
182 cpu_to_apicid[cpu] = apicid;
183 bios_cpu_apicid[cpu] = apicid;
184 } else {
185 per_cpu(x86_cpu_to_apicid, cpu) = apicid;
186 per_cpu(x86_bios_cpu_apicid, cpu) = apicid;
187 }
188#endif
189 cpu_set(cpu, cpu_possible_map);
190 cpu_set(cpu, cpu_present_map);
191}
192
193static void __cpuinit MP_processor_info(struct mpc_config_processor *m)
194{
195 int apicid;
196
Glauber Costa7b1292e2008-03-03 14:12:41 -0300197 if (!(m->mpc_cpuflag & CPU_ENABLED)) {
198 disabled_cpus++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 return;
Glauber Costa7b1292e2008-03-03 14:12:41 -0300200 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
Alexey Starikovskiy4655c7d2008-03-17 22:08:36 +0300202#ifdef CONFIG_X86_NUMAQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 apicid = mpc_apic_id(m, translation_table[mpc_record]);
Alexey Starikovskiy4655c7d2008-03-17 22:08:36 +0300204#else
205 Dprintk("Processor #%d %u:%u APIC version %d\n",
206 m->mpc_apicid,
207 (m->mpc_cpufeature & CPU_FAMILY_MASK) >> 8,
208 (m->mpc_cpufeature & CPU_MODEL_MASK) >> 4,
209 m->mpc_apicver);
210 apicid = m->mpc_apicid;
211#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
213 if (m->mpc_featureflag&(1<<0))
214 Dprintk(" Floating point unit present.\n");
215 if (m->mpc_featureflag&(1<<7))
216 Dprintk(" Machine Exception supported.\n");
217 if (m->mpc_featureflag&(1<<8))
218 Dprintk(" 64 bit compare & exchange supported.\n");
219 if (m->mpc_featureflag&(1<<9))
220 Dprintk(" Internal APIC present.\n");
221 if (m->mpc_featureflag&(1<<11))
222 Dprintk(" SEP present.\n");
223 if (m->mpc_featureflag&(1<<12))
224 Dprintk(" MTRR present.\n");
225 if (m->mpc_featureflag&(1<<13))
226 Dprintk(" PGE present.\n");
227 if (m->mpc_featureflag&(1<<14))
228 Dprintk(" MCA present.\n");
229 if (m->mpc_featureflag&(1<<15))
230 Dprintk(" CMOV present.\n");
231 if (m->mpc_featureflag&(1<<16))
232 Dprintk(" PAT present.\n");
233 if (m->mpc_featureflag&(1<<17))
234 Dprintk(" PSE present.\n");
235 if (m->mpc_featureflag&(1<<18))
236 Dprintk(" PSN present.\n");
237 if (m->mpc_featureflag&(1<<19))
238 Dprintk(" Cache Line Flush Instruction present.\n");
239 /* 20 Reserved */
240 if (m->mpc_featureflag&(1<<21))
241 Dprintk(" Debug Trace and EMON Store present.\n");
242 if (m->mpc_featureflag&(1<<22))
243 Dprintk(" ACPI Thermal Throttle Registers present.\n");
244 if (m->mpc_featureflag&(1<<23))
245 Dprintk(" MMX present.\n");
246 if (m->mpc_featureflag&(1<<24))
247 Dprintk(" FXSR present.\n");
248 if (m->mpc_featureflag&(1<<25))
249 Dprintk(" XMM present.\n");
250 if (m->mpc_featureflag&(1<<26))
251 Dprintk(" Willamette New Instructions present.\n");
252 if (m->mpc_featureflag&(1<<27))
253 Dprintk(" Self Snoop present.\n");
254 if (m->mpc_featureflag&(1<<28))
255 Dprintk(" HT present.\n");
256 if (m->mpc_featureflag&(1<<29))
257 Dprintk(" Thermal Monitor present.\n");
258 /* 30, 31 Reserved */
259
260
261 if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
262 Dprintk(" Bootup CPU\n");
263 boot_cpu_physical_apicid = m->mpc_apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 }
265
Alexey Starikovskiyc853c672008-03-27 23:54:13 +0300266 generic_processor_info(apicid, m->mpc_apicver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267}
268
269static void __init MP_bus_info (struct mpc_config_bus *m)
270{
271 char str[7];
272
273 memcpy(str, m->mpc_bustype, 6);
274 str[6] = 0;
275
Alexey Starikovskiy0ec153a2008-03-17 22:08:48 +0300276#ifdef CONFIG_X86_NUMAQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 mpc_oem_bus_info(m, str, translation_table[mpc_record]);
Alexey Starikovskiy0ec153a2008-03-17 22:08:48 +0300278#else
279 Dprintk("Bus #%d is %s\n", m->mpc_busid, str);
280#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
Andi Kleen5e4edbb2006-09-26 10:52:35 +0200282#if MAX_MP_BUSSES < 256
Randy Dunlapc0ec31a2006-04-10 22:53:13 -0700283 if (m->mpc_busid >= MAX_MP_BUSSES) {
284 printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
285 " is too large, max. supported is %d\n",
286 m->mpc_busid, str, MAX_MP_BUSSES - 1);
287 return;
288 }
Andi Kleen5e4edbb2006-09-26 10:52:35 +0200289#endif
Randy Dunlapc0ec31a2006-04-10 22:53:13 -0700290
Alexey Starikovskiya6333c32008-03-20 14:54:09 +0300291 set_bit(m->mpc_busid, mp_bus_not_pci);
Alexey Starikovskiy9e0a2de2008-03-20 14:54:56 +0300292 if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI)-1) == 0) {
Alexey Starikovskiyd285e332008-03-17 22:08:42 +0300293#ifdef CONFIG_X86_NUMAQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 mpc_oem_pci_bus(m, translation_table[mpc_record]);
Alexey Starikovskiyd285e332008-03-17 22:08:42 +0300295#endif
Alexey Starikovskiya6333c32008-03-20 14:54:09 +0300296 clear_bit(m->mpc_busid, mp_bus_not_pci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 mp_bus_id_to_pci_bus[m->mpc_busid] = mp_current_pci_id;
298 mp_current_pci_id++;
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +0300299#if defined(CONFIG_EISA) || defined (CONFIG_MCA)
300 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI;
Alexey Starikovskiy9e0a2de2008-03-20 14:54:56 +0300301 } else if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA)-1) == 0) {
302 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA;
303 } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA)-1) == 0) {
304 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA)-1) == 0) {
306 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_MCA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 } else {
308 printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +0300309#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 }
311}
312
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300313static int bad_ioapic(unsigned long address)
314{
315 if (nr_ioapics >= MAX_IO_APICS) {
316 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
317 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
318 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
319 }
320 if (!address) {
321 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
322 " found in table, skipping!\n");
323 return 1;
324 }
325 return 0;
326}
327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328static void __init MP_ioapic_info (struct mpc_config_ioapic *m)
329{
330 if (!(m->mpc_flags & MPC_APIC_USABLE))
331 return;
332
Thomas Gleixner64883ab2008-01-30 13:30:35 +0100333 printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 m->mpc_apicid, m->mpc_apicver, m->mpc_apicaddr);
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300335
336 if (bad_ioapic(m->mpc_apicaddr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 return;
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300338
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 mp_ioapics[nr_ioapics] = *m;
340 nr_ioapics++;
341}
342
343static void __init MP_intsrc_info (struct mpc_config_intsrc *m)
344{
345 mp_irqs [mp_irq_entries] = *m;
346 Dprintk("Int: type %d, pol %d, trig %d, bus %d,"
347 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
348 m->mpc_irqtype, m->mpc_irqflag & 3,
349 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
350 m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
351 if (++mp_irq_entries == MAX_IRQ_SOURCES)
352 panic("Max # of irq sources exceeded!!\n");
353}
354
355static void __init MP_lintsrc_info (struct mpc_config_lintsrc *m)
356{
357 Dprintk("Lint: type %d, pol %d, trig %d, bus %d,"
358 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
359 m->mpc_irqtype, m->mpc_irqflag & 3,
360 (m->mpc_irqflag >> 2) &3, m->mpc_srcbusid,
361 m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362}
363
364#ifdef CONFIG_X86_NUMAQ
365static void __init MP_translation_info (struct mpc_config_translation *m)
366{
367 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);
368
369 if (mpc_record >= MAX_MPC_ENTRY)
370 printk(KERN_ERR "MAX_MPC_ENTRY exceeded!\n");
371 else
372 translation_table[mpc_record] = m; /* stash this for later */
373 if (m->trans_quad < MAX_NUMNODES && !node_online(m->trans_quad))
374 node_set_online(m->trans_quad);
375}
376
377/*
378 * Read/parse the MPC oem tables
379 */
380
381static void __init smp_read_mpc_oem(struct mp_config_oemtable *oemtable, \
382 unsigned short oemsize)
383{
384 int count = sizeof (*oemtable); /* the header size */
385 unsigned char *oemptr = ((unsigned char *)oemtable)+count;
386
387 mpc_record = 0;
388 printk(KERN_INFO "Found an OEM MPC table at %8p - parsing it ... \n", oemtable);
389 if (memcmp(oemtable->oem_signature,MPC_OEM_SIGNATURE,4))
390 {
391 printk(KERN_WARNING "SMP mpc oemtable: bad signature [%c%c%c%c]!\n",
392 oemtable->oem_signature[0],
393 oemtable->oem_signature[1],
394 oemtable->oem_signature[2],
395 oemtable->oem_signature[3]);
396 return;
397 }
398 if (mpf_checksum((unsigned char *)oemtable,oemtable->oem_length))
399 {
400 printk(KERN_WARNING "SMP oem mptable: checksum error!\n");
401 return;
402 }
403 while (count < oemtable->oem_length) {
404 switch (*oemptr) {
405 case MP_TRANSLATION:
406 {
407 struct mpc_config_translation *m=
408 (struct mpc_config_translation *)oemptr;
409 MP_translation_info(m);
410 oemptr += sizeof(*m);
411 count += sizeof(*m);
412 ++mpc_record;
413 break;
414 }
415 default:
416 {
417 printk(KERN_WARNING "Unrecognised OEM table entry type! - %d\n", (int) *oemptr);
418 return;
419 }
420 }
421 }
422}
423
424static inline void mps_oem_check(struct mp_config_table *mpc, char *oem,
425 char *productid)
426{
427 if (strncmp(oem, "IBM NUMA", 8))
428 printk("Warning! May not be a NUMA-Q system!\n");
429 if (mpc->mpc_oemptr)
430 smp_read_mpc_oem((struct mp_config_oemtable *) mpc->mpc_oemptr,
431 mpc->mpc_oemsize);
432}
433#endif /* CONFIG_X86_NUMAQ */
434
435/*
436 * Read/parse the MPC
437 */
438
439static int __init smp_read_mpc(struct mp_config_table *mpc)
440{
441 char str[16];
442 char oem[10];
443 int count=sizeof(*mpc);
444 unsigned char *mpt=((unsigned char *)mpc)+count;
445
446 if (memcmp(mpc->mpc_signature,MPC_SIGNATURE,4)) {
447 printk(KERN_ERR "SMP mptable: bad signature [0x%x]!\n",
448 *(u32 *)mpc->mpc_signature);
449 return 0;
450 }
451 if (mpf_checksum((unsigned char *)mpc,mpc->mpc_length)) {
452 printk(KERN_ERR "SMP mptable: checksum error!\n");
453 return 0;
454 }
455 if (mpc->mpc_spec!=0x01 && mpc->mpc_spec!=0x04) {
456 printk(KERN_ERR "SMP mptable: bad table version (%d)!!\n",
457 mpc->mpc_spec);
458 return 0;
459 }
460 if (!mpc->mpc_lapic) {
461 printk(KERN_ERR "SMP mptable: null local APIC address!\n");
462 return 0;
463 }
464 memcpy(oem,mpc->mpc_oem,8);
465 oem[8]=0;
466 printk(KERN_INFO "OEM ID: %s ",oem);
467
468 memcpy(str,mpc->mpc_productid,12);
469 str[12]=0;
470 printk("Product ID: %s ",str);
471
472 mps_oem_check(mpc, oem, str);
473
Thomas Gleixner64883ab2008-01-30 13:30:35 +0100474 printk("APIC at: 0x%X\n", mpc->mpc_lapic);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
Thomas Gleixner64883ab2008-01-30 13:30:35 +0100476 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 * Save the local APIC address (it might be non-default) -- but only
478 * if we're not using ACPI.
479 */
480 if (!acpi_lapic)
481 mp_lapic_addr = mpc->mpc_lapic;
482
483 /*
484 * Now process the configuration blocks.
485 */
Alexey Starikovskiy86420502008-03-17 22:08:55 +0300486#ifdef CONFIG_X86_NUMAQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 mpc_record = 0;
Alexey Starikovskiy86420502008-03-17 22:08:55 +0300488#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 while (count < mpc->mpc_length) {
490 switch(*mpt) {
491 case MP_PROCESSOR:
492 {
493 struct mpc_config_processor *m=
494 (struct mpc_config_processor *)mpt;
495 /* ACPI may have already provided this data */
496 if (!acpi_lapic)
497 MP_processor_info(m);
498 mpt += sizeof(*m);
499 count += sizeof(*m);
500 break;
501 }
502 case MP_BUS:
503 {
504 struct mpc_config_bus *m=
505 (struct mpc_config_bus *)mpt;
506 MP_bus_info(m);
507 mpt += sizeof(*m);
508 count += sizeof(*m);
509 break;
510 }
511 case MP_IOAPIC:
512 {
513 struct mpc_config_ioapic *m=
514 (struct mpc_config_ioapic *)mpt;
515 MP_ioapic_info(m);
516 mpt+=sizeof(*m);
517 count+=sizeof(*m);
518 break;
519 }
520 case MP_INTSRC:
521 {
522 struct mpc_config_intsrc *m=
523 (struct mpc_config_intsrc *)mpt;
524
525 MP_intsrc_info(m);
526 mpt+=sizeof(*m);
527 count+=sizeof(*m);
528 break;
529 }
530 case MP_LINTSRC:
531 {
532 struct mpc_config_lintsrc *m=
533 (struct mpc_config_lintsrc *)mpt;
534 MP_lintsrc_info(m);
535 mpt+=sizeof(*m);
536 count+=sizeof(*m);
537 break;
538 }
539 default:
540 {
541 count = mpc->mpc_length;
542 break;
543 }
544 }
Alexey Starikovskiy86420502008-03-17 22:08:55 +0300545#ifdef CONFIG_X86_NUMAQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 ++mpc_record;
Alexey Starikovskiy86420502008-03-17 22:08:55 +0300547#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 }
Ingo Molnar3c43f032007-05-02 19:27:04 +0200549 setup_apic_routing();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 if (!num_processors)
551 printk(KERN_ERR "SMP mptable: no processors registered!\n");
552 return num_processors;
553}
554
555static int __init ELCR_trigger(unsigned int irq)
556{
557 unsigned int port;
558
559 port = 0x4d0 + (irq >> 3);
560 return (inb(port) >> (irq & 7)) & 1;
561}
562
563static void __init construct_default_ioirq_mptable(int mpc_default_type)
564{
565 struct mpc_config_intsrc intsrc;
566 int i;
567 int ELCR_fallback = 0;
568
569 intsrc.mpc_type = MP_INTSRC;
570 intsrc.mpc_irqflag = 0; /* conforming */
571 intsrc.mpc_srcbus = 0;
572 intsrc.mpc_dstapic = mp_ioapics[0].mpc_apicid;
573
574 intsrc.mpc_irqtype = mp_INT;
575
576 /*
577 * If true, we have an ISA/PCI system with no IRQ entries
578 * in the MP table. To prevent the PCI interrupts from being set up
579 * incorrectly, we try to use the ELCR. The sanity check to see if
580 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
581 * never be level sensitive, so we simply see if the ELCR agrees.
582 * If it does, we assume it's valid.
583 */
584 if (mpc_default_type == 5) {
585 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... falling back to ELCR\n");
586
587 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) || ELCR_trigger(13))
588 printk(KERN_WARNING "ELCR contains invalid data... not using ELCR\n");
589 else {
590 printk(KERN_INFO "Using ELCR to identify PCI interrupts\n");
591 ELCR_fallback = 1;
592 }
593 }
594
595 for (i = 0; i < 16; i++) {
596 switch (mpc_default_type) {
597 case 2:
598 if (i == 0 || i == 13)
599 continue; /* IRQ0 & IRQ13 not connected */
600 /* fall through */
601 default:
602 if (i == 2)
603 continue; /* IRQ2 is never connected */
604 }
605
606 if (ELCR_fallback) {
607 /*
608 * If the ELCR indicates a level-sensitive interrupt, we
609 * copy that information over to the MP table in the
610 * irqflag field (level sensitive, active high polarity).
611 */
612 if (ELCR_trigger(i))
613 intsrc.mpc_irqflag = 13;
614 else
615 intsrc.mpc_irqflag = 0;
616 }
617
618 intsrc.mpc_srcbusirq = i;
619 intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
620 MP_intsrc_info(&intsrc);
621 }
622
623 intsrc.mpc_irqtype = mp_ExtINT;
624 intsrc.mpc_srcbusirq = 0;
625 intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */
626 MP_intsrc_info(&intsrc);
627}
628
629static inline void __init construct_default_ISA_mptable(int mpc_default_type)
630{
631 struct mpc_config_processor processor;
632 struct mpc_config_bus bus;
633 struct mpc_config_ioapic ioapic;
634 struct mpc_config_lintsrc lintsrc;
635 int linttypes[2] = { mp_ExtINT, mp_NMI };
636 int i;
637
638 /*
639 * local APIC has default address
640 */
641 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
642
643 /*
644 * 2 CPUs, numbered 0 & 1.
645 */
646 processor.mpc_type = MP_PROCESSOR;
647 /* Either an integrated APIC or a discrete 82489DX. */
648 processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
649 processor.mpc_cpuflag = CPU_ENABLED;
650 processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
651 (boot_cpu_data.x86_model << 4) |
652 boot_cpu_data.x86_mask;
653 processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
654 processor.mpc_reserved[0] = 0;
655 processor.mpc_reserved[1] = 0;
656 for (i = 0; i < 2; i++) {
657 processor.mpc_apicid = i;
658 MP_processor_info(&processor);
659 }
660
661 bus.mpc_type = MP_BUS;
662 bus.mpc_busid = 0;
663 switch (mpc_default_type) {
664 default:
665 printk("???\n");
666 printk(KERN_ERR "Unknown standard configuration %d\n",
667 mpc_default_type);
668 /* fall through */
669 case 1:
670 case 5:
671 memcpy(bus.mpc_bustype, "ISA ", 6);
672 break;
673 case 2:
674 case 6:
675 case 3:
676 memcpy(bus.mpc_bustype, "EISA ", 6);
677 break;
678 case 4:
679 case 7:
680 memcpy(bus.mpc_bustype, "MCA ", 6);
681 }
682 MP_bus_info(&bus);
683 if (mpc_default_type > 4) {
684 bus.mpc_busid = 1;
685 memcpy(bus.mpc_bustype, "PCI ", 6);
686 MP_bus_info(&bus);
687 }
688
689 ioapic.mpc_type = MP_IOAPIC;
690 ioapic.mpc_apicid = 2;
691 ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
692 ioapic.mpc_flags = MPC_APIC_USABLE;
693 ioapic.mpc_apicaddr = 0xFEC00000;
694 MP_ioapic_info(&ioapic);
695
696 /*
697 * We set up most of the low 16 IO-APIC pins according to MPS rules.
698 */
699 construct_default_ioirq_mptable(mpc_default_type);
700
701 lintsrc.mpc_type = MP_LINTSRC;
702 lintsrc.mpc_irqflag = 0; /* conforming */
703 lintsrc.mpc_srcbusid = 0;
704 lintsrc.mpc_srcbusirq = 0;
705 lintsrc.mpc_destapic = MP_APIC_ALL;
706 for (i = 0; i < 2; i++) {
707 lintsrc.mpc_irqtype = linttypes[i];
708 lintsrc.mpc_destapiclint = i;
709 MP_lintsrc_info(&lintsrc);
710 }
711}
712
713static struct intel_mp_floating *mpf_found;
714
715/*
716 * Scan the memory blocks for an SMP configuration block.
717 */
718void __init get_smp_config (void)
719{
720 struct intel_mp_floating *mpf = mpf_found;
721
722 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 * ACPI supports both logical (e.g. Hyper-Threading) and physical
724 * processors, where MPS only supports physical.
725 */
726 if (acpi_lapic && acpi_ioapic) {
727 printk(KERN_INFO "Using ACPI (MADT) for SMP configuration information\n");
728 return;
729 }
730 else if (acpi_lapic)
731 printk(KERN_INFO "Using ACPI for processor (LAPIC) configuration information\n");
732
733 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n", mpf->mpf_specification);
734 if (mpf->mpf_feature2 & (1<<7)) {
735 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
736 pic_mode = 1;
737 } else {
738 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
739 pic_mode = 0;
740 }
741
742 /*
743 * Now see if we need to read further.
744 */
745 if (mpf->mpf_feature1 != 0) {
746
747 printk(KERN_INFO "Default MP configuration #%d\n", mpf->mpf_feature1);
748 construct_default_ISA_mptable(mpf->mpf_feature1);
749
750 } else if (mpf->mpf_physptr) {
751
752 /*
753 * Read the physical hardware table. Anything here will
754 * override the defaults.
755 */
Daniel Yeisley7d4c8e52006-02-20 18:27:54 -0800756 if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 smp_found_config = 0;
758 printk(KERN_ERR "BIOS bug, MP table errors detected!...\n");
759 printk(KERN_ERR "... disabling SMP support. (tell your hw vendor)\n");
760 return;
761 }
762 /*
763 * If there are no explicit MP IRQ entries, then we are
764 * broken. We set up most of the low 16 IO-APIC pins to
765 * ISA defaults and hope it will work.
766 */
767 if (!mp_irq_entries) {
768 struct mpc_config_bus bus;
769
770 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, using default mptable. (tell your hw vendor)\n");
771
772 bus.mpc_type = MP_BUS;
773 bus.mpc_busid = 0;
774 memcpy(bus.mpc_bustype, "ISA ", 6);
775 MP_bus_info(&bus);
776
777 construct_default_ioirq_mptable(0);
778 }
779
780 } else
781 BUG();
782
783 printk(KERN_INFO "Processors: %d\n", num_processors);
784 /*
785 * Only use the first configuration found.
786 */
787}
788
789static int __init smp_scan_config (unsigned long base, unsigned long length)
790{
791 unsigned long *bp = phys_to_virt(base);
792 struct intel_mp_floating *mpf;
793
Ingo Molnare91a3b42008-01-30 13:33:08 +0100794 printk(KERN_INFO "Scan SMP from %p for %ld bytes.\n", bp,length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 if (sizeof(*mpf) != 16)
796 printk("Error: MPF size\n");
797
798 while (length > 0) {
799 mpf = (struct intel_mp_floating *)bp;
800 if ((*bp == SMP_MAGIC_IDENT) &&
801 (mpf->mpf_length == 1) &&
802 !mpf_checksum((unsigned char *)bp, 16) &&
803 ((mpf->mpf_specification == 1)
804 || (mpf->mpf_specification == 4)) ) {
805
806 smp_found_config = 1;
Ingo Molnare91a3b42008-01-30 13:33:08 +0100807 printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
808 mpf, virt_to_phys(mpf));
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800809 reserve_bootmem(virt_to_phys(mpf), PAGE_SIZE,
810 BOOTMEM_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 if (mpf->mpf_physptr) {
812 /*
813 * We cannot access to MPC table to compute
814 * table size yet, as only few megabytes from
815 * the bottom is mapped now.
816 * PC-9800's MPC table places on the very last
817 * of physical memory; so that simply reserving
818 * PAGE_SIZE from mpg->mpf_physptr yields BUG()
819 * in reserve_bootmem.
820 */
821 unsigned long size = PAGE_SIZE;
822 unsigned long end = max_low_pfn * PAGE_SIZE;
823 if (mpf->mpf_physptr + size > end)
824 size = end - mpf->mpf_physptr;
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800825 reserve_bootmem(mpf->mpf_physptr, size,
826 BOOTMEM_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 }
828
829 mpf_found = mpf;
830 return 1;
831 }
832 bp += 4;
833 length -= 16;
834 }
835 return 0;
836}
837
838void __init find_smp_config (void)
839{
840 unsigned int address;
841
842 /*
843 * FIXME: Linux assumes you have 640K of base ram..
844 * this continues the error...
845 *
846 * 1) Scan the bottom 1K for a signature
847 * 2) Scan the top 1K of base RAM
848 * 3) Scan the 64K of bios
849 */
850 if (smp_scan_config(0x0,0x400) ||
851 smp_scan_config(639*0x400,0x400) ||
852 smp_scan_config(0xF0000,0x10000))
853 return;
854 /*
855 * If it is an SMP machine we should know now, unless the
856 * configuration is in an EISA/MCA bus machine with an
857 * extended bios data area.
858 *
859 * there is a real-mode segmented pointer pointing to the
860 * 4K EBDA area at 0x40E, calculate and scan it here.
861 *
862 * NOTE! There are Linux loaders that will corrupt the EBDA
863 * area, and as such this kind of SMP config may be less
864 * trustworthy, simply because the SMP table may have been
865 * stomped on during early boot. These loaders are buggy and
866 * should be fixed.
867 *
868 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
869 */
870
871 address = get_bios_ebda();
872 if (address)
873 smp_scan_config(address, 0x400);
874}
875
876/* --------------------------------------------------------------------------
877 ACPI-based MP Configuration
878 -------------------------------------------------------------------------- */
879
Len Brown888ba6c2005-08-24 12:07:20 -0400880#ifdef CONFIG_ACPI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
Andi Kleen19f03ff2006-09-26 10:52:30 +0200882void __init mp_register_lapic_address(u64 address)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883{
884 mp_lapic_addr = (unsigned long) address;
885
886 set_fixmap_nocache(FIX_APIC_BASE, mp_lapic_addr);
887
888 if (boot_cpu_physical_apicid == -1U)
889 boot_cpu_physical_apicid = GET_APIC_ID(apic_read(APIC_ID));
890
891 Dprintk("Boot CPU = %d\n", boot_cpu_physical_apicid);
892}
893
Vivek Goyal4a5d1072007-01-11 01:52:44 +0100894void __cpuinit mp_register_lapic (u8 id, u8 enabled)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895{
896 struct mpc_config_processor processor;
Andi Kleen19f03ff2006-09-26 10:52:30 +0200897 int boot_cpu = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
899 if (MAX_APICS - id <= 0) {
900 printk(KERN_WARNING "Processor #%d invalid (max %d)\n",
901 id, MAX_APICS);
902 return;
903 }
Alexey Starikovskiy987dd2d2008-03-27 23:54:06 +0300904 if (!enabled) {
905 ++disabled_cpus;
906 return;
907 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
909 if (id == boot_cpu_physical_apicid)
910 boot_cpu = 1;
911
912 processor.mpc_type = MP_PROCESSOR;
913 processor.mpc_apicid = id;
914 processor.mpc_apicver = GET_APIC_VERSION(apic_read(APIC_LVR));
915 processor.mpc_cpuflag = (enabled ? CPU_ENABLED : 0);
916 processor.mpc_cpuflag |= (boot_cpu ? CPU_BOOTPROCESSOR : 0);
917 processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
918 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
919 processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
920 processor.mpc_reserved[0] = 0;
921 processor.mpc_reserved[1] = 0;
922
923 MP_processor_info(&processor);
924}
925
Len Brown84663612005-08-24 12:09:07 -0400926#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
928#define MP_ISA_BUS 0
929#define MP_MAX_IOAPIC_PIN 127
930
931static struct mp_ioapic_routing {
932 int apic_id;
933 int gsi_base;
934 int gsi_end;
935 u32 pin_programmed[4];
936} mp_ioapic_routing[MAX_IO_APICS];
937
Andi Kleen19f03ff2006-09-26 10:52:30 +0200938static int mp_find_ioapic (int gsi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939{
Andi Kleen19f03ff2006-09-26 10:52:30 +0200940 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
942 /* Find the IOAPIC that manages this GSI. */
943 for (i = 0; i < nr_ioapics; i++) {
944 if ((gsi >= mp_ioapic_routing[i].gsi_base)
945 && (gsi <= mp_ioapic_routing[i].gsi_end))
946 return i;
947 }
948
949 printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %d\n", gsi);
950
951 return -1;
952}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953
Alexey Starikovskiye3e3ffa2008-03-17 22:08:11 +0300954static u8 uniq_ioapic_id(u8 id)
955{
956 if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) &&
957 !APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
958 return io_apic_get_unique_id(nr_ioapics, id);
959 else
960 return id;
961}
962
Andi Kleen19f03ff2006-09-26 10:52:30 +0200963void __init mp_register_ioapic(u8 id, u32 address, u32 gsi_base)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964{
Andi Kleen19f03ff2006-09-26 10:52:30 +0200965 int idx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
Alexey Starikovskiy857033a2008-03-17 22:08:05 +0300967 if (bad_ioapic(address))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
Alexey Starikovskiye3e3ffa2008-03-17 22:08:11 +0300970 idx = nr_ioapics;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971
972 mp_ioapics[idx].mpc_type = MP_IOAPIC;
973 mp_ioapics[idx].mpc_flags = MPC_APIC_USABLE;
974 mp_ioapics[idx].mpc_apicaddr = address;
975
976 set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
Alexey Starikovskiye3e3ffa2008-03-17 22:08:11 +0300977 mp_ioapics[idx].mpc_apicid = uniq_ioapic_id(id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 mp_ioapics[idx].mpc_apicver = io_apic_get_version(idx);
979
980 /*
981 * Build basic GSI lookup table to facilitate gsi->io_apic lookups
982 * and to prevent reprogramming of IOAPIC pins (PCI GSIs).
983 */
984 mp_ioapic_routing[idx].apic_id = mp_ioapics[idx].mpc_apicid;
985 mp_ioapic_routing[idx].gsi_base = gsi_base;
Thomas Gleixner64883ab2008-01-30 13:30:35 +0100986 mp_ioapic_routing[idx].gsi_end = gsi_base +
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 io_apic_get_redir_entries(idx);
988
Thomas Gleixner64883ab2008-01-30 13:30:35 +0100989 printk("IOAPIC[%d]: apic_id %d, version %d, address 0x%x, "
990 "GSI %d-%d\n", idx, mp_ioapics[idx].mpc_apicid,
Alexey Starikovskiye3e3ffa2008-03-17 22:08:11 +0300991 mp_ioapics[idx].mpc_apicver,
992 mp_ioapics[idx].mpc_apicaddr,
Thomas Gleixner64883ab2008-01-30 13:30:35 +0100993 mp_ioapic_routing[idx].gsi_base,
994 mp_ioapic_routing[idx].gsi_end);
Alexey Starikovskiye3e3ffa2008-03-17 22:08:11 +0300995
996 nr_ioapics++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997}
998
Andi Kleen19f03ff2006-09-26 10:52:30 +0200999void __init
1000mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001{
1002 struct mpc_config_intsrc intsrc;
1003 int ioapic = -1;
1004 int pin = -1;
1005
1006 /*
1007 * Convert 'gsi' to 'ioapic.pin'.
1008 */
1009 ioapic = mp_find_ioapic(gsi);
1010 if (ioapic < 0)
1011 return;
1012 pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
1013
1014 /*
1015 * TBD: This check is for faulty timer entries, where the override
1016 * erroneously sets the trigger to level, resulting in a HUGE
1017 * increase of timer interrupts!
1018 */
1019 if ((bus_irq == 0) && (trigger == 3))
1020 trigger = 1;
1021
1022 intsrc.mpc_type = MP_INTSRC;
1023 intsrc.mpc_irqtype = mp_INT;
1024 intsrc.mpc_irqflag = (trigger << 2) | polarity;
1025 intsrc.mpc_srcbus = MP_ISA_BUS;
1026 intsrc.mpc_srcbusirq = bus_irq; /* IRQ */
1027 intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid; /* APIC ID */
1028 intsrc.mpc_dstirq = pin; /* INTIN# */
1029
1030 Dprintk("Int: type %d, pol %d, trig %d, bus %d, irq %d, %d-%d\n",
1031 intsrc.mpc_irqtype, intsrc.mpc_irqflag & 3,
1032 (intsrc.mpc_irqflag >> 2) & 3, intsrc.mpc_srcbus,
1033 intsrc.mpc_srcbusirq, intsrc.mpc_dstapic, intsrc.mpc_dstirq);
1034
1035 mp_irqs[mp_irq_entries] = intsrc;
1036 if (++mp_irq_entries == MAX_IRQ_SOURCES)
1037 panic("Max # of irq sources exceeded!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038}
1039
Alexey Starikovskiy2df29722008-03-27 23:53:54 +03001040int es7000_plat;
1041
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042void __init mp_config_acpi_legacy_irqs (void)
1043{
1044 struct mpc_config_intsrc intsrc;
Andi Kleen19f03ff2006-09-26 10:52:30 +02001045 int i = 0;
1046 int ioapic = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +03001048#if defined (CONFIG_MCA) || defined (CONFIG_EISA)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 /*
1050 * Fabricate the legacy ISA bus (bus #31).
1051 */
1052 mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +03001053#endif
Alexey Starikovskiya6333c32008-03-20 14:54:09 +03001054 set_bit(MP_ISA_BUS, mp_bus_not_pci);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 Dprintk("Bus #%d is ISA\n", MP_ISA_BUS);
1056
1057 /*
1058 * Older generations of ES7000 have no legacy identity mappings
1059 */
1060 if (es7000_plat == 1)
1061 return;
1062
1063 /*
1064 * Locate the IOAPIC that manages the ISA IRQs (0-15).
1065 */
1066 ioapic = mp_find_ioapic(0);
1067 if (ioapic < 0)
1068 return;
1069
1070 intsrc.mpc_type = MP_INTSRC;
1071 intsrc.mpc_irqflag = 0; /* Conforming */
1072 intsrc.mpc_srcbus = MP_ISA_BUS;
1073 intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid;
1074
1075 /*
1076 * Use the default configuration for the IRQs 0-15. Unless
Simon Arlott27b46d72007-10-20 01:13:56 +02001077 * overridden by (MADT) interrupt source override entries.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 */
1079 for (i = 0; i < 16; i++) {
1080 int idx;
1081
1082 for (idx = 0; idx < mp_irq_entries; idx++) {
1083 struct mpc_config_intsrc *irq = mp_irqs + idx;
1084
1085 /* Do we already have a mapping for this ISA IRQ? */
1086 if (irq->mpc_srcbus == MP_ISA_BUS && irq->mpc_srcbusirq == i)
1087 break;
1088
1089 /* Do we already have a mapping for this IOAPIC pin */
1090 if ((irq->mpc_dstapic == intsrc.mpc_dstapic) &&
1091 (irq->mpc_dstirq == i))
1092 break;
1093 }
1094
1095 if (idx != mp_irq_entries) {
1096 printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
1097 continue; /* IRQ already used */
1098 }
1099
1100 intsrc.mpc_irqtype = mp_INT;
1101 intsrc.mpc_srcbusirq = i; /* Identity mapped */
1102 intsrc.mpc_dstirq = i;
1103
1104 Dprintk("Int: type %d, pol %d, trig %d, bus %d, irq %d, "
1105 "%d-%d\n", intsrc.mpc_irqtype, intsrc.mpc_irqflag & 3,
1106 (intsrc.mpc_irqflag >> 2) & 3, intsrc.mpc_srcbus,
1107 intsrc.mpc_srcbusirq, intsrc.mpc_dstapic,
1108 intsrc.mpc_dstirq);
1109
1110 mp_irqs[mp_irq_entries] = intsrc;
1111 if (++mp_irq_entries == MAX_IRQ_SOURCES)
1112 panic("Max # of irq sources exceeded!\n");
1113 }
1114}
1115
Natalie Protasevichc434b7a2005-06-23 00:08:29 -07001116#define MAX_GSI_NUM 4096
Len Brown2ba7dee2008-01-30 13:31:02 +01001117#define IRQ_COMPRESSION_START 64
Natalie Protasevichc434b7a2005-06-23 00:08:29 -07001118
Andi Kleen19f03ff2006-09-26 10:52:30 +02001119int mp_register_gsi(u32 gsi, int triggering, int polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120{
Andi Kleen19f03ff2006-09-26 10:52:30 +02001121 int ioapic = -1;
1122 int ioapic_pin = 0;
1123 int idx, bit = 0;
Len Brown2ba7dee2008-01-30 13:31:02 +01001124 static int pci_irq = IRQ_COMPRESSION_START;
Natalie Protasevichc434b7a2005-06-23 00:08:29 -07001125 /*
Joe Perchesab4a5742008-01-30 13:31:42 +01001126 * Mapping between Global System Interrupts, which
Natalie Protasevichc434b7a2005-06-23 00:08:29 -07001127 * represent all possible interrupts, and IRQs
1128 * assigned to actual devices.
1129 */
1130 static int gsi_to_irq[MAX_GSI_NUM];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 /* Don't set up the ACPI SCI because it's already set up */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +03001133 if (acpi_gbl_FADT.sci_interrupt == gsi)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 return gsi;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
1136 ioapic = mp_find_ioapic(gsi);
1137 if (ioapic < 0) {
1138 printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
1139 return gsi;
1140 }
1141
1142 ioapic_pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
1143
1144 if (ioapic_renumber_irq)
1145 gsi = ioapic_renumber_irq(ioapic, gsi);
1146
1147 /*
1148 * Avoid pin reprogramming. PRTs typically include entries
1149 * with redundant pin->gsi mappings (but unique PCI devices);
1150 * we only program the IOAPIC on the first.
1151 */
1152 bit = ioapic_pin % 32;
1153 idx = (ioapic_pin < 32) ? 0 : (ioapic_pin / 32);
1154 if (idx > 3) {
1155 printk(KERN_ERR "Invalid reference to IOAPIC pin "
1156 "%d-%d\n", mp_ioapic_routing[ioapic].apic_id,
1157 ioapic_pin);
1158 return gsi;
1159 }
1160 if ((1<<bit) & mp_ioapic_routing[ioapic].pin_programmed[idx]) {
1161 Dprintk(KERN_DEBUG "Pin %d-%d already programmed\n",
1162 mp_ioapic_routing[ioapic].apic_id, ioapic_pin);
Len Brown2ba7dee2008-01-30 13:31:02 +01001163 return (gsi < IRQ_COMPRESSION_START ? gsi : gsi_to_irq[gsi]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 }
1165
1166 mp_ioapic_routing[ioapic].pin_programmed[idx] |= (1<<bit);
1167
Len Brown2ba7dee2008-01-30 13:31:02 +01001168 /*
1169 * For GSI >= 64, use IRQ compression
1170 */
1171 if ((gsi >= IRQ_COMPRESSION_START)
1172 && (triggering == ACPI_LEVEL_SENSITIVE)) {
Natalie Protasevichc434b7a2005-06-23 00:08:29 -07001173 /*
1174 * For PCI devices assign IRQs in order, avoiding gaps
1175 * due to unused I/O APIC pins.
1176 */
1177 int irq = gsi;
1178 if (gsi < MAX_GSI_NUM) {
Kimball Murraye0c1e9b2006-05-08 15:17:16 +02001179 /*
1180 * Retain the VIA chipset work-around (gsi > 15), but
1181 * avoid a problem where the 8254 timer (IRQ0) is setup
1182 * via an override (so it's not on pin 0 of the ioapic),
1183 * and at the same time, the pin 0 interrupt is a PCI
1184 * type. The gsi > 15 test could cause these two pins
1185 * to be shared as IRQ0, and they are not shareable.
1186 * So test for this condition, and if necessary, avoid
1187 * the pin collision.
1188 */
Adrian Bunkede13892008-03-17 22:29:32 +02001189 gsi = pci_irq++;
Natalie.Protasevich@unisys.come1afc3f2005-07-29 14:03:32 -07001190 /*
1191 * Don't assign IRQ used by ACPI SCI
1192 */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +03001193 if (gsi == acpi_gbl_FADT.sci_interrupt)
Natalie.Protasevich@unisys.come1afc3f2005-07-29 14:03:32 -07001194 gsi = pci_irq++;
Natalie Protasevichc434b7a2005-06-23 00:08:29 -07001195 gsi_to_irq[irq] = gsi;
1196 } else {
1197 printk(KERN_ERR "GSI %u is too high\n", gsi);
1198 return gsi;
1199 }
1200 }
1201
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 io_apic_set_pci_routing(ioapic, ioapic_pin, gsi,
Len Browncb654692005-12-28 02:43:51 -05001203 triggering == ACPI_EDGE_SENSITIVE ? 0 : 1,
1204 polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 return gsi;
1206}
1207
Len Brown84663612005-08-24 12:09:07 -04001208#endif /* CONFIG_X86_IO_APIC */
Len Brown888ba6c2005-08-24 12:07:20 -04001209#endif /* CONFIG_ACPI */