ia64/xen-unstable

view linux-2.6-xen-sparse/arch/xen/i386/kernel/acpi/boot.c @ 6563:331c256d8e5c

Add back missing part of XenLinux acpi/boot.c.
This fixes bug #76 (IRQ sharing fails under load).
Signed-off-by: Natasha Jarymowycz <natasha@us.ibm.com>
author kaf24@firebug.cl.cam.ac.uk
date Wed Aug 31 08:43:57 2005 +0000 (2005-08-31)
parents 38312fe7ec38
children f41f8d753b7a
line source
1 /*
2 * boot.c - Architecture-Specific Low-Level ACPI Boot Support
3 *
4 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
5 * Copyright (C) 2001 Jun Nakajima <jun.nakajima@intel.com>
6 *
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24 */
26 #include <linux/init.h>
27 #include <linux/config.h>
28 #include <linux/acpi.h>
29 #include <linux/efi.h>
30 #include <linux/irq.h>
31 #include <linux/module.h>
33 #include <asm/pgtable.h>
34 #include <asm/io_apic.h>
35 #include <asm/apic.h>
36 #include <asm/io.h>
37 #include <asm/irq.h>
38 #include <asm/mpspec.h>
39 #ifdef CONFIG_XEN
40 #include <asm/fixmap.h>
41 #endif
43 void (*pm_power_off)(void) = NULL;
45 #ifdef CONFIG_X86_64
47 static inline void acpi_madt_oem_check(char *oem_id, char *oem_table_id) { }
48 extern void __init clustered_apic_check(void);
49 static inline int ioapic_setup_disabled(void) { return 0; }
50 #include <asm/proto.h>
52 #else /* X86 */
54 #ifdef CONFIG_X86_LOCAL_APIC
55 #include <mach_apic.h>
56 #include <mach_mpparse.h>
57 #endif /* CONFIG_X86_LOCAL_APIC */
59 #endif /* X86 */
61 #define BAD_MADT_ENTRY(entry, end) ( \
62 (!entry) || (unsigned long)entry + sizeof(*entry) > end || \
63 ((acpi_table_entry_header *)entry)->length != sizeof(*entry))
65 #define PREFIX "ACPI: "
67 #ifdef CONFIG_ACPI_PCI
68 int acpi_noirq __initdata; /* skip ACPI IRQ initialization */
69 int acpi_pci_disabled __initdata; /* skip ACPI PCI scan and IRQ initialization */
70 #else
71 int acpi_noirq __initdata = 1;
72 int acpi_pci_disabled __initdata = 1;
73 #endif
74 int acpi_ht __initdata = 1; /* enable HT */
76 int acpi_lapic;
77 int acpi_ioapic;
78 int acpi_strict;
79 EXPORT_SYMBOL(acpi_strict);
81 acpi_interrupt_flags acpi_sci_flags __initdata;
82 int acpi_sci_override_gsi __initdata;
83 int acpi_skip_timer_override __initdata;
85 #ifdef CONFIG_X86_LOCAL_APIC
86 static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
87 #endif
89 #ifndef __HAVE_ARCH_CMPXCHG
90 #warning ACPI uses CMPXCHG, i486 and later hardware
91 #endif
93 #define MAX_MADT_ENTRIES 256
94 u8 x86_acpiid_to_apicid[MAX_MADT_ENTRIES] =
95 { [0 ... MAX_MADT_ENTRIES-1] = 0xff };
96 EXPORT_SYMBOL(x86_acpiid_to_apicid);
98 /* --------------------------------------------------------------------------
99 Boot-time Configuration
100 -------------------------------------------------------------------------- */
102 /*
103 * The default interrupt routing model is PIC (8259). This gets
104 * overriden if IOAPICs are enumerated (below).
105 */
106 enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
108 #if defined(CONFIG_X86_64) && !defined(CONFIG_XEN)
110 /* rely on all ACPI tables being in the direct mapping */
111 char *__acpi_map_table(unsigned long phys_addr, unsigned long size)
112 {
113 if (!phys_addr || !size)
114 return NULL;
116 if (phys_addr < (end_pfn_map << PAGE_SHIFT))
117 return __va(phys_addr);
119 return NULL;
120 }
122 #else
124 /*
125 * Temporarily use the virtual area starting from FIX_IO_APIC_BASE_END,
126 * to map the target physical address. The problem is that set_fixmap()
127 * provides a single page, and it is possible that the page is not
128 * sufficient.
129 * By using this area, we can map up to MAX_IO_APICS pages temporarily,
130 * i.e. until the next __va_range() call.
131 *
132 * Important Safety Note: The fixed I/O APIC page numbers are *subtracted*
133 * from the fixed base. That's why we start at FIX_IO_APIC_BASE_END and
134 * count idx down while incrementing the phys address.
135 */
136 char *__acpi_map_table(unsigned long phys, unsigned long size)
137 {
138 unsigned long base, offset, mapped_size;
139 int idx;
141 #ifndef CONFIG_XEN
142 if (phys + size < 8*1024*1024)
143 return __va(phys);
144 #endif
146 offset = phys & (PAGE_SIZE - 1);
147 mapped_size = PAGE_SIZE - offset;
148 set_fixmap(FIX_ACPI_END, phys);
149 base = fix_to_virt(FIX_ACPI_END);
151 /*
152 * Most cases can be covered by the below.
153 */
154 idx = FIX_ACPI_END;
155 while (mapped_size < size) {
156 if (--idx < FIX_ACPI_BEGIN)
157 return NULL; /* cannot handle this */
158 phys += PAGE_SIZE;
159 set_fixmap(idx, phys);
160 mapped_size += PAGE_SIZE;
161 }
163 return ((unsigned char *) base + offset);
164 }
165 #endif
167 #ifdef CONFIG_PCI_MMCONFIG
168 static int __init acpi_parse_mcfg(unsigned long phys_addr, unsigned long size)
169 {
170 struct acpi_table_mcfg *mcfg;
172 if (!phys_addr || !size)
173 return -EINVAL;
175 mcfg = (struct acpi_table_mcfg *) __acpi_map_table(phys_addr, size);
176 if (!mcfg) {
177 printk(KERN_WARNING PREFIX "Unable to map MCFG\n");
178 return -ENODEV;
179 }
181 if (mcfg->base_reserved) {
182 printk(KERN_ERR PREFIX "MMCONFIG not in low 4GB of memory\n");
183 return -ENODEV;
184 }
186 pci_mmcfg_base_addr = mcfg->base_address;
188 return 0;
189 }
190 #else
191 #define acpi_parse_mcfg NULL
192 #endif /* !CONFIG_PCI_MMCONFIG */
194 #ifdef CONFIG_X86_LOCAL_APIC
195 static int __init
196 acpi_parse_madt (
197 unsigned long phys_addr,
198 unsigned long size)
199 {
200 struct acpi_table_madt *madt = NULL;
202 if (!phys_addr || !size)
203 return -EINVAL;
205 madt = (struct acpi_table_madt *) __acpi_map_table(phys_addr, size);
206 if (!madt) {
207 printk(KERN_WARNING PREFIX "Unable to map MADT\n");
208 return -ENODEV;
209 }
211 if (madt->lapic_address) {
212 acpi_lapic_addr = (u64) madt->lapic_address;
214 printk(KERN_DEBUG PREFIX "Local APIC address 0x%08x\n",
215 madt->lapic_address);
216 }
218 acpi_madt_oem_check(madt->header.oem_id, madt->header.oem_table_id);
220 return 0;
221 }
224 static int __init
225 acpi_parse_lapic (
226 acpi_table_entry_header *header, const unsigned long end)
227 {
228 struct acpi_table_lapic *processor = NULL;
230 processor = (struct acpi_table_lapic*) header;
232 if (BAD_MADT_ENTRY(processor, end))
233 return -EINVAL;
235 acpi_table_print_madt_entry(header);
237 /* no utility in registering a disabled processor */
238 if (processor->flags.enabled == 0)
239 return 0;
241 x86_acpiid_to_apicid[processor->acpi_id] = processor->id;
243 mp_register_lapic (
244 processor->id, /* APIC ID */
245 processor->flags.enabled); /* Enabled? */
247 return 0;
248 }
250 static int __init
251 acpi_parse_lapic_addr_ovr (
252 acpi_table_entry_header *header, const unsigned long end)
253 {
254 struct acpi_table_lapic_addr_ovr *lapic_addr_ovr = NULL;
256 lapic_addr_ovr = (struct acpi_table_lapic_addr_ovr*) header;
258 if (BAD_MADT_ENTRY(lapic_addr_ovr, end))
259 return -EINVAL;
261 acpi_lapic_addr = lapic_addr_ovr->address;
263 return 0;
264 }
266 static int __init
267 acpi_parse_lapic_nmi (
268 acpi_table_entry_header *header, const unsigned long end)
269 {
270 struct acpi_table_lapic_nmi *lapic_nmi = NULL;
272 lapic_nmi = (struct acpi_table_lapic_nmi*) header;
274 if (BAD_MADT_ENTRY(lapic_nmi, end))
275 return -EINVAL;
277 acpi_table_print_madt_entry(header);
279 if (lapic_nmi->lint != 1)
280 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
282 return 0;
283 }
286 #endif /*CONFIG_X86_LOCAL_APIC*/
288 #if defined(CONFIG_X86_IO_APIC) && defined(CONFIG_ACPI_INTERPRETER)
290 static int __init
291 acpi_parse_ioapic (
292 acpi_table_entry_header *header, const unsigned long end)
293 {
294 struct acpi_table_ioapic *ioapic = NULL;
296 ioapic = (struct acpi_table_ioapic*) header;
298 if (BAD_MADT_ENTRY(ioapic, end))
299 return -EINVAL;
301 acpi_table_print_madt_entry(header);
303 mp_register_ioapic (
304 ioapic->id,
305 ioapic->address,
306 ioapic->global_irq_base);
308 return 0;
309 }
311 /*
312 * Parse Interrupt Source Override for the ACPI SCI
313 */
314 static void
315 acpi_sci_ioapic_setup(u32 gsi, u16 polarity, u16 trigger)
316 {
317 if (trigger == 0) /* compatible SCI trigger is level */
318 trigger = 3;
320 if (polarity == 0) /* compatible SCI polarity is low */
321 polarity = 3;
323 /* Command-line over-ride via acpi_sci= */
324 if (acpi_sci_flags.trigger)
325 trigger = acpi_sci_flags.trigger;
327 if (acpi_sci_flags.polarity)
328 polarity = acpi_sci_flags.polarity;
330 /*
331 * mp_config_acpi_legacy_irqs() already setup IRQs < 16
332 * If GSI is < 16, this will update its flags,
333 * else it will create a new mp_irqs[] entry.
334 */
335 mp_override_legacy_irq(gsi, polarity, trigger, gsi);
337 /*
338 * stash over-ride to indicate we've been here
339 * and for later update of acpi_fadt
340 */
341 acpi_sci_override_gsi = gsi;
342 return;
343 }
345 static int __init
346 acpi_parse_int_src_ovr (
347 acpi_table_entry_header *header, const unsigned long end)
348 {
349 struct acpi_table_int_src_ovr *intsrc = NULL;
351 intsrc = (struct acpi_table_int_src_ovr*) header;
353 if (BAD_MADT_ENTRY(intsrc, end))
354 return -EINVAL;
356 acpi_table_print_madt_entry(header);
358 if (intsrc->bus_irq == acpi_fadt.sci_int) {
359 acpi_sci_ioapic_setup(intsrc->global_irq,
360 intsrc->flags.polarity, intsrc->flags.trigger);
361 return 0;
362 }
364 if (acpi_skip_timer_override &&
365 intsrc->bus_irq == 0 && intsrc->global_irq == 2) {
366 printk(PREFIX "BIOS IRQ0 pin2 override ignored.\n");
367 return 0;
368 }
370 mp_override_legacy_irq (
371 intsrc->bus_irq,
372 intsrc->flags.polarity,
373 intsrc->flags.trigger,
374 intsrc->global_irq);
376 return 0;
377 }
380 static int __init
381 acpi_parse_nmi_src (
382 acpi_table_entry_header *header, const unsigned long end)
383 {
384 struct acpi_table_nmi_src *nmi_src = NULL;
386 nmi_src = (struct acpi_table_nmi_src*) header;
388 if (BAD_MADT_ENTRY(nmi_src, end))
389 return -EINVAL;
391 acpi_table_print_madt_entry(header);
393 /* TBD: Support nimsrc entries? */
395 return 0;
396 }
398 #endif /* CONFIG_X86_IO_APIC */
400 #ifdef CONFIG_ACPI_BUS
402 /*
403 * acpi_pic_sci_set_trigger()
404 *
405 * use ELCR to set PIC-mode trigger type for SCI
406 *
407 * If a PIC-mode SCI is not recognized or gives spurious IRQ7's
408 * it may require Edge Trigger -- use "acpi_sci=edge"
409 *
410 * Port 0x4d0-4d1 are ECLR1 and ECLR2, the Edge/Level Control Registers
411 * for the 8259 PIC. bit[n] = 1 means irq[n] is Level, otherwise Edge.
412 * ECLR1 is IRQ's 0-7 (IRQ 0, 1, 2 must be 0)
413 * ECLR2 is IRQ's 8-15 (IRQ 8, 13 must be 0)
414 */
416 void __init
417 acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
418 {
419 unsigned int mask = 1 << irq;
420 unsigned int old, new;
422 /* Real old ELCR mask */
423 old = inb(0x4d0) | (inb(0x4d1) << 8);
425 /*
426 * If we use ACPI to set PCI irq's, then we should clear ELCR
427 * since we will set it correctly as we enable the PCI irq
428 * routing.
429 */
430 new = acpi_noirq ? old : 0;
432 /*
433 * Update SCI information in the ELCR, it isn't in the PCI
434 * routing tables..
435 */
436 switch (trigger) {
437 case 1: /* Edge - clear */
438 new &= ~mask;
439 break;
440 case 3: /* Level - set */
441 new |= mask;
442 break;
443 }
445 if (old == new)
446 return;
448 printk(PREFIX "setting ELCR to %04x (from %04x)\n", new, old);
449 outb(new, 0x4d0);
450 outb(new >> 8, 0x4d1);
451 }
454 #endif /* CONFIG_ACPI_BUS */
456 int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
457 {
458 #ifdef CONFIG_X86_IO_APIC
459 if (use_pci_vector() && !platform_legacy_irq(gsi))
460 *irq = IO_APIC_VECTOR(gsi);
461 else
462 #endif
463 *irq = gsi;
464 return 0;
465 }
467 unsigned int acpi_register_gsi(u32 gsi, int edge_level, int active_high_low)
468 {
469 unsigned int irq;
470 unsigned int plat_gsi = gsi;
472 #ifdef CONFIG_PCI
473 /*
474 * Make sure all (legacy) PCI IRQs are set as level-triggered.
475 */
476 if (acpi_irq_model == ACPI_IRQ_MODEL_PIC) {
477 extern void eisa_set_level_irq(unsigned int irq);
479 if (edge_level == ACPI_LEVEL_SENSITIVE)
480 eisa_set_level_irq(gsi);
481 }
482 #endif
484 #ifdef CONFIG_X86_IO_APIC
485 if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC) {
486 plat_gsi = mp_register_gsi(gsi, edge_level, active_high_low);
487 }
488 #endif
489 acpi_gsi_to_irq(plat_gsi, &irq);
490 return irq;
491 }
492 EXPORT_SYMBOL(acpi_register_gsi);
494 /*
495 * ACPI based hotplug support for CPU
496 */
497 #ifdef CONFIG_ACPI_HOTPLUG_CPU
498 int
499 acpi_map_lsapic(acpi_handle handle, int *pcpu)
500 {
501 /* TBD */
502 return -EINVAL;
503 }
504 EXPORT_SYMBOL(acpi_map_lsapic);
507 int
508 acpi_unmap_lsapic(int cpu)
509 {
510 /* TBD */
511 return -EINVAL;
512 }
513 EXPORT_SYMBOL(acpi_unmap_lsapic);
514 #endif /* CONFIG_ACPI_HOTPLUG_CPU */
516 static unsigned long __init
517 acpi_scan_rsdp (
518 unsigned long start,
519 unsigned long length)
520 {
521 unsigned long offset = 0;
522 unsigned long sig_len = sizeof("RSD PTR ") - 1;
523 unsigned long vstart = (unsigned long)isa_bus_to_virt(start);
525 /*
526 * Scan all 16-byte boundaries of the physical memory region for the
527 * RSDP signature.
528 */
529 for (offset = 0; offset < length; offset += 16) {
530 if (strncmp((char *) (vstart + offset), "RSD PTR ", sig_len))
531 continue;
532 return (start + offset);
533 }
535 return 0;
536 }
538 static int __init acpi_parse_sbf(unsigned long phys_addr, unsigned long size)
539 {
540 struct acpi_table_sbf *sb;
542 if (!phys_addr || !size)
543 return -EINVAL;
545 sb = (struct acpi_table_sbf *) __acpi_map_table(phys_addr, size);
546 if (!sb) {
547 printk(KERN_WARNING PREFIX "Unable to map SBF\n");
548 return -ENODEV;
549 }
551 sbf_port = sb->sbf_cmos; /* Save CMOS port */
553 return 0;
554 }
557 #ifdef CONFIG_HPET_TIMER
559 static int __init acpi_parse_hpet(unsigned long phys, unsigned long size)
560 {
561 struct acpi_table_hpet *hpet_tbl;
563 if (!phys || !size)
564 return -EINVAL;
566 hpet_tbl = (struct acpi_table_hpet *) __acpi_map_table(phys, size);
567 if (!hpet_tbl) {
568 printk(KERN_WARNING PREFIX "Unable to map HPET\n");
569 return -ENODEV;
570 }
572 if (hpet_tbl->addr.space_id != ACPI_SPACE_MEM) {
573 printk(KERN_WARNING PREFIX "HPET timers must be located in "
574 "memory.\n");
575 return -1;
576 }
578 #ifdef CONFIG_X86_64
579 vxtime.hpet_address = hpet_tbl->addr.addrl |
580 ((long) hpet_tbl->addr.addrh << 32);
582 printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
583 hpet_tbl->id, vxtime.hpet_address);
584 #else /* X86 */
585 {
586 extern unsigned long hpet_address;
588 hpet_address = hpet_tbl->addr.addrl;
589 printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
590 hpet_tbl->id, hpet_address);
591 }
592 #endif /* X86 */
594 return 0;
595 }
596 #else
597 #define acpi_parse_hpet NULL
598 #endif
600 #ifdef CONFIG_X86_PM_TIMER
601 extern u32 pmtmr_ioport;
602 #endif
604 static int __init acpi_parse_fadt(unsigned long phys, unsigned long size)
605 {
606 struct fadt_descriptor_rev2 *fadt = NULL;
608 fadt = (struct fadt_descriptor_rev2*) __acpi_map_table(phys,size);
609 if(!fadt) {
610 printk(KERN_WARNING PREFIX "Unable to map FADT\n");
611 return 0;
612 }
614 #ifdef CONFIG_ACPI_INTERPRETER
615 /* initialize sci_int early for INT_SRC_OVR MADT parsing */
616 acpi_fadt.sci_int = fadt->sci_int;
617 #endif
619 #ifdef CONFIG_ACPI_BUS
620 /* initialize rev and apic_phys_dest_mode for x86_64 genapic */
621 acpi_fadt.revision = fadt->revision;
622 acpi_fadt.force_apic_physical_destination_mode = fadt->force_apic_physical_destination_mode;
623 #endif
625 #if defined(CONFIG_X86_PM_TIMER) && !defined(CONFIG_XEN)
626 /* detect the location of the ACPI PM Timer */
627 if (fadt->revision >= FADT2_REVISION_ID) {
628 /* FADT rev. 2 */
629 if (fadt->xpm_tmr_blk.address_space_id != ACPI_ADR_SPACE_SYSTEM_IO)
630 return 0;
632 pmtmr_ioport = fadt->xpm_tmr_blk.address;
633 } else {
634 /* FADT rev. 1 */
635 pmtmr_ioport = fadt->V1_pm_tmr_blk;
636 }
637 if (pmtmr_ioport)
638 printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n", pmtmr_ioport);
639 #endif
640 return 0;
641 }
644 unsigned long __init
645 acpi_find_rsdp (void)
646 {
647 unsigned long rsdp_phys = 0;
649 if (efi_enabled) {
650 if (efi.acpi20)
651 return __pa(efi.acpi20);
652 else if (efi.acpi)
653 return __pa(efi.acpi);
654 }
655 /*
656 * Scan memory looking for the RSDP signature. First search EBDA (low
657 * memory) paragraphs and then search upper memory (E0000-FFFFF).
658 */
659 rsdp_phys = acpi_scan_rsdp (0, 0x400);
660 if (!rsdp_phys)
661 rsdp_phys = acpi_scan_rsdp (0xE0000, 0x20000);
663 set_fixmap(FIX_ACPI_RSDP_PAGE, rsdp_phys);
665 return rsdp_phys;
666 }
668 #ifdef CONFIG_X86_LOCAL_APIC
669 /*
670 * Parse LAPIC entries in MADT
671 * returns 0 on success, < 0 on error
672 */
673 static int __init
674 acpi_parse_madt_lapic_entries(void)
675 {
676 int count;
678 /*
679 * Note that the LAPIC address is obtained from the MADT (32-bit value)
680 * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
681 */
683 count = acpi_table_parse_madt(ACPI_MADT_LAPIC_ADDR_OVR, acpi_parse_lapic_addr_ovr, 0);
684 if (count < 0) {
685 printk(KERN_ERR PREFIX "Error parsing LAPIC address override entry\n");
686 return count;
687 }
689 mp_register_lapic_address(acpi_lapic_addr);
691 count = acpi_table_parse_madt(ACPI_MADT_LAPIC, acpi_parse_lapic,
692 MAX_APICS);
693 if (!count) {
694 printk(KERN_ERR PREFIX "No LAPIC entries present\n");
695 /* TBD: Cleanup to allow fallback to MPS */
696 return -ENODEV;
697 }
698 else if (count < 0) {
699 printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
700 /* TBD: Cleanup to allow fallback to MPS */
701 return count;
702 }
704 count = acpi_table_parse_madt(ACPI_MADT_LAPIC_NMI, acpi_parse_lapic_nmi, 0);
705 if (count < 0) {
706 printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
707 /* TBD: Cleanup to allow fallback to MPS */
708 return count;
709 }
710 return 0;
711 }
712 #endif /* CONFIG_X86_LOCAL_APIC */
714 #if defined(CONFIG_X86_IO_APIC) && defined(CONFIG_ACPI_INTERPRETER)
715 /*
716 * Parse IOAPIC related entries in MADT
717 * returns 0 on success, < 0 on error
718 */
719 static int __init
720 acpi_parse_madt_ioapic_entries(void)
721 {
722 int count;
724 /*
725 * ACPI interpreter is required to complete interrupt setup,
726 * so if it is off, don't enumerate the io-apics with ACPI.
727 * If MPS is present, it will handle them,
728 * otherwise the system will stay in PIC mode
729 */
730 if (acpi_disabled || acpi_noirq) {
731 return -ENODEV;
732 }
734 /*
735 * if "noapic" boot option, don't look for IO-APICs
736 */
737 if (skip_ioapic_setup) {
738 printk(KERN_INFO PREFIX "Skipping IOAPIC probe "
739 "due to 'noapic' option.\n");
740 return -ENODEV;
741 }
743 count = acpi_table_parse_madt(ACPI_MADT_IOAPIC, acpi_parse_ioapic, MAX_IO_APICS);
744 if (!count) {
745 printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
746 return -ENODEV;
747 }
748 else if (count < 0) {
749 printk(KERN_ERR PREFIX "Error parsing IOAPIC entry\n");
750 return count;
751 }
753 count = acpi_table_parse_madt(ACPI_MADT_INT_SRC_OVR, acpi_parse_int_src_ovr, NR_IRQ_VECTORS);
754 if (count < 0) {
755 printk(KERN_ERR PREFIX "Error parsing interrupt source overrides entry\n");
756 /* TBD: Cleanup to allow fallback to MPS */
757 return count;
758 }
760 /*
761 * If BIOS did not supply an INT_SRC_OVR for the SCI
762 * pretend we got one so we can set the SCI flags.
763 */
764 if (!acpi_sci_override_gsi)
765 acpi_sci_ioapic_setup(acpi_fadt.sci_int, 0, 0);
767 /* Fill in identity legacy mapings where no override */
768 mp_config_acpi_legacy_irqs();
770 count = acpi_table_parse_madt(ACPI_MADT_NMI_SRC, acpi_parse_nmi_src, NR_IRQ_VECTORS);
771 if (count < 0) {
772 printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
773 /* TBD: Cleanup to allow fallback to MPS */
774 return count;
775 }
777 return 0;
778 }
779 #else
780 static inline int acpi_parse_madt_ioapic_entries(void)
781 {
782 return -1;
783 }
784 #endif /* !(CONFIG_X86_IO_APIC && CONFIG_ACPI_INTERPRETER) */
787 static void __init
788 acpi_process_madt(void)
789 {
790 #ifdef CONFIG_X86_LOCAL_APIC
791 int count, error;
793 count = acpi_table_parse(ACPI_APIC, acpi_parse_madt);
794 if (count >= 1) {
796 /*
797 * Parse MADT LAPIC entries
798 */
799 error = acpi_parse_madt_lapic_entries();
800 if (!error) {
801 acpi_lapic = 1;
803 /*
804 * Parse MADT IO-APIC entries
805 */
806 error = acpi_parse_madt_ioapic_entries();
807 if (!error) {
808 acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
809 acpi_irq_balance_set(NULL);
810 acpi_ioapic = 1;
812 smp_found_config = 1;
813 clustered_apic_check();
814 }
815 }
816 if (error == -EINVAL) {
817 /*
818 * Dell Precision Workstation 410, 610 come here.
819 */
820 printk(KERN_ERR PREFIX "Invalid BIOS MADT, disabling ACPI\n");
821 disable_acpi();
822 }
823 }
824 #endif
825 return;
826 }
828 /*
829 * acpi_boot_table_init() and acpi_boot_init()
830 * called from setup_arch(), always.
831 * 1. checksums all tables
832 * 2. enumerates lapics
833 * 3. enumerates io-apics
834 *
835 * acpi_table_init() is separate to allow reading SRAT without
836 * other side effects.
837 *
838 * side effects of acpi_boot_init:
839 * acpi_lapic = 1 if LAPIC found
840 * acpi_ioapic = 1 if IOAPIC found
841 * if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
842 * if acpi_blacklisted() acpi_disabled = 1;
843 * acpi_irq_model=...
844 * ...
845 *
846 * return value: (currently ignored)
847 * 0: success
848 * !0: failure
849 */
851 int __init
852 acpi_boot_table_init(void)
853 {
854 int error;
856 /*
857 * If acpi_disabled, bail out
858 * One exception: acpi=ht continues far enough to enumerate LAPICs
859 */
860 if (acpi_disabled && !acpi_ht)
861 return 1;
863 /*
864 * Initialize the ACPI boot-time table parser.
865 */
866 error = acpi_table_init();
867 if (error) {
868 disable_acpi();
869 return error;
870 }
872 #ifdef __i386__
873 check_acpi_pci();
874 #endif
876 acpi_table_parse(ACPI_BOOT, acpi_parse_sbf);
878 /*
879 * blacklist may disable ACPI entirely
880 */
881 error = acpi_blacklisted();
882 if (error) {
883 extern int acpi_force;
885 if (acpi_force) {
886 printk(KERN_WARNING PREFIX "acpi=force override\n");
887 } else {
888 printk(KERN_WARNING PREFIX "Disabling ACPI support\n");
889 disable_acpi();
890 return error;
891 }
892 }
894 return 0;
895 }
898 int __init acpi_boot_init(void)
899 {
900 /*
901 * If acpi_disabled, bail out
902 * One exception: acpi=ht continues far enough to enumerate LAPICs
903 */
904 if (acpi_disabled && !acpi_ht)
905 return 1;
907 acpi_table_parse(ACPI_BOOT, acpi_parse_sbf);
909 /*
910 * set sci_int and PM timer address
911 */
912 acpi_table_parse(ACPI_FADT, acpi_parse_fadt);
914 /*
915 * Process the Multiple APIC Description Table (MADT), if present
916 */
917 acpi_process_madt();
919 acpi_table_parse(ACPI_HPET, acpi_parse_hpet);
920 acpi_table_parse(ACPI_MCFG, acpi_parse_mcfg);
922 return 0;
923 }