2 * boot.c - Architecture-Specific Low-Level ACPI Boot Support
4 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
5 * Copyright (C) 2001 Jun Nakajima <jun.nakajima@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
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.
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
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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>
38 #include <asm/mpspec.h>
42 static inline void acpi_madt_oem_check(char *oem_id, char *oem_table_id) { }
43 static inline void clustered_apic_check(void) { }
44 static inline int ioapic_setup_disabled(void) { return 0; }
45 #include <asm/proto.h>
49 #ifdef CONFIG_X86_LOCAL_APIC
50 #include <mach_apic.h>
51 #include <mach_mpparse.h>
52 #endif /* CONFIG_X86_LOCAL_APIC */
56 #define BAD_MADT_ENTRY(entry, end) ( \
57 (!entry) || (unsigned long)entry + sizeof(*entry) > end || \
58 ((acpi_table_entry_header *)entry)->length != sizeof(*entry))
60 #define PREFIX "ACPI: "
62 #ifdef CONFIG_ACPI_PCI
63 int acpi_noirq __initdata; /* skip ACPI IRQ initialization */
64 int acpi_pci_disabled __initdata; /* skip ACPI PCI scan and IRQ initialization */
66 int acpi_noirq __initdata = 1;
67 int acpi_pci_disabled __initdata = 1;
69 int acpi_ht __initdata = 1; /* enable HT */
74 EXPORT_SYMBOL(acpi_strict);
76 acpi_interrupt_flags acpi_sci_flags __initdata;
77 int acpi_sci_override_gsi __initdata;
78 int acpi_skip_timer_override __initdata;
80 #ifdef CONFIG_X86_LOCAL_APIC
81 static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
84 #ifndef __HAVE_ARCH_CMPXCHG
85 #warning ACPI uses CMPXCHG, i486 and later hardware
88 #define MAX_MADT_ENTRIES 256
89 u8 x86_acpiid_to_apicid[MAX_MADT_ENTRIES] =
90 { [0 ... MAX_MADT_ENTRIES-1] = 0xff };
91 EXPORT_SYMBOL(x86_acpiid_to_apicid);
93 /* --------------------------------------------------------------------------
94 Boot-time Configuration
95 -------------------------------------------------------------------------- */
98 * The default interrupt routing model is PIC (8259). This gets
99 * overriden if IOAPICs are enumerated (below).
101 enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
105 /* rely on all ACPI tables being in the direct mapping */
106 char *__acpi_map_table(unsigned long phys_addr, unsigned long size)
108 if (!phys_addr || !size)
111 if (phys_addr < (end_pfn_map << PAGE_SHIFT))
112 return __va(phys_addr);
120 * Temporarily use the virtual area starting from FIX_IO_APIC_BASE_END,
121 * to map the target physical address. The problem is that set_fixmap()
122 * provides a single page, and it is possible that the page is not
124 * By using this area, we can map up to MAX_IO_APICS pages temporarily,
125 * i.e. until the next __va_range() call.
127 * Important Safety Note: The fixed I/O APIC page numbers are *subtracted*
128 * from the fixed base. That's why we start at FIX_IO_APIC_BASE_END and
129 * count idx down while incrementing the phys address.
131 char *__acpi_map_table(unsigned long phys, unsigned long size)
133 unsigned long base, offset, mapped_size;
136 if (phys + size < 8*1024*1024)
139 offset = phys & (PAGE_SIZE - 1);
140 mapped_size = PAGE_SIZE - offset;
141 set_fixmap(FIX_ACPI_END, phys);
142 base = fix_to_virt(FIX_ACPI_END);
145 * Most cases can be covered by the below.
148 while (mapped_size < size) {
149 if (--idx < FIX_ACPI_BEGIN)
150 return NULL; /* cannot handle this */
152 set_fixmap(idx, phys);
153 mapped_size += PAGE_SIZE;
156 return ((unsigned char *) base + offset);
160 #ifdef CONFIG_PCI_MMCONFIG
161 static int __init acpi_parse_mcfg(unsigned long phys_addr, unsigned long size)
163 struct acpi_table_mcfg *mcfg;
165 if (!phys_addr || !size)
168 mcfg = (struct acpi_table_mcfg *) __acpi_map_table(phys_addr, size);
170 printk(KERN_WARNING PREFIX "Unable to map MCFG\n");
174 if (mcfg->base_reserved) {
175 printk(KERN_ERR PREFIX "MMCONFIG not in low 4GB of memory\n");
179 pci_mmcfg_base_addr = mcfg->base_address;
184 #define acpi_parse_mcfg NULL
185 #endif /* !CONFIG_PCI_MMCONFIG */
187 #ifdef CONFIG_X86_LOCAL_APIC
190 unsigned long phys_addr,
193 struct acpi_table_madt *madt = NULL;
195 if (!phys_addr || !size)
198 madt = (struct acpi_table_madt *) __acpi_map_table(phys_addr, size);
200 printk(KERN_WARNING PREFIX "Unable to map MADT\n");
204 if (madt->lapic_address) {
205 acpi_lapic_addr = (u64) madt->lapic_address;
207 printk(KERN_DEBUG PREFIX "Local APIC address 0x%08x\n",
208 madt->lapic_address);
211 acpi_madt_oem_check(madt->header.oem_id, madt->header.oem_table_id);
219 acpi_table_entry_header *header, const unsigned long end)
221 struct acpi_table_lapic *processor = NULL;
223 processor = (struct acpi_table_lapic*) header;
225 if (BAD_MADT_ENTRY(processor, end))
228 acpi_table_print_madt_entry(header);
230 /* no utility in registering a disabled processor */
231 if (processor->flags.enabled == 0)
234 x86_acpiid_to_apicid[processor->acpi_id] = processor->id;
237 processor->id, /* APIC ID */
238 processor->flags.enabled); /* Enabled? */
244 acpi_parse_lapic_addr_ovr (
245 acpi_table_entry_header *header, const unsigned long end)
247 struct acpi_table_lapic_addr_ovr *lapic_addr_ovr = NULL;
249 lapic_addr_ovr = (struct acpi_table_lapic_addr_ovr*) header;
251 if (BAD_MADT_ENTRY(lapic_addr_ovr, end))
254 acpi_lapic_addr = lapic_addr_ovr->address;
260 acpi_parse_lapic_nmi (
261 acpi_table_entry_header *header, const unsigned long end)
263 struct acpi_table_lapic_nmi *lapic_nmi = NULL;
265 lapic_nmi = (struct acpi_table_lapic_nmi*) header;
267 if (BAD_MADT_ENTRY(lapic_nmi, end))
270 acpi_table_print_madt_entry(header);
272 if (lapic_nmi->lint != 1)
273 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
279 #endif /*CONFIG_X86_LOCAL_APIC*/
281 #if defined(CONFIG_X86_IO_APIC) && defined(CONFIG_ACPI_INTERPRETER)
285 acpi_table_entry_header *header, const unsigned long end)
287 struct acpi_table_ioapic *ioapic = NULL;
289 ioapic = (struct acpi_table_ioapic*) header;
291 if (BAD_MADT_ENTRY(ioapic, end))
294 acpi_table_print_madt_entry(header);
299 ioapic->global_irq_base);
305 * Parse Interrupt Source Override for the ACPI SCI
308 acpi_sci_ioapic_setup(u32 gsi, u16 polarity, u16 trigger)
310 if (trigger == 0) /* compatible SCI trigger is level */
313 if (polarity == 0) /* compatible SCI polarity is low */
316 /* Command-line over-ride via acpi_sci= */
317 if (acpi_sci_flags.trigger)
318 trigger = acpi_sci_flags.trigger;
320 if (acpi_sci_flags.polarity)
321 polarity = acpi_sci_flags.polarity;
324 * mp_config_acpi_legacy_irqs() already setup IRQs < 16
325 * If GSI is < 16, this will update its flags,
326 * else it will create a new mp_irqs[] entry.
328 mp_override_legacy_irq(gsi, polarity, trigger, gsi);
331 * stash over-ride to indicate we've been here
332 * and for later update of acpi_fadt
334 acpi_sci_override_gsi = gsi;
339 acpi_parse_int_src_ovr (
340 acpi_table_entry_header *header, const unsigned long end)
342 struct acpi_table_int_src_ovr *intsrc = NULL;
344 intsrc = (struct acpi_table_int_src_ovr*) header;
346 if (BAD_MADT_ENTRY(intsrc, end))
349 acpi_table_print_madt_entry(header);
351 if (intsrc->bus_irq == acpi_fadt.sci_int) {
352 acpi_sci_ioapic_setup(intsrc->global_irq,
353 intsrc->flags.polarity, intsrc->flags.trigger);
357 if (acpi_skip_timer_override &&
358 intsrc->bus_irq == 0 && intsrc->global_irq == 2) {
359 printk(PREFIX "BIOS IRQ0 pin2 override ignored.\n");
363 mp_override_legacy_irq (
365 intsrc->flags.polarity,
366 intsrc->flags.trigger,
375 acpi_table_entry_header *header, const unsigned long end)
377 struct acpi_table_nmi_src *nmi_src = NULL;
379 nmi_src = (struct acpi_table_nmi_src*) header;
381 if (BAD_MADT_ENTRY(nmi_src, end))
384 acpi_table_print_madt_entry(header);
386 /* TBD: Support nimsrc entries? */
391 #endif /* CONFIG_X86_IO_APIC */
393 #ifdef CONFIG_ACPI_BUS
396 * acpi_pic_sci_set_trigger()
398 * use ELCR to set PIC-mode trigger type for SCI
400 * If a PIC-mode SCI is not recognized or gives spurious IRQ7's
401 * it may require Edge Trigger -- use "acpi_sci=edge"
403 * Port 0x4d0-4d1 are ECLR1 and ECLR2, the Edge/Level Control Registers
404 * for the 8259 PIC. bit[n] = 1 means irq[n] is Level, otherwise Edge.
405 * ECLR1 is IRQ's 0-7 (IRQ 0, 1, 2 must be 0)
406 * ECLR2 is IRQ's 8-15 (IRQ 8, 13 must be 0)
410 acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
412 unsigned char mask = 1 << (irq & 7);
413 unsigned int port = 0x4d0 + (irq >> 3);
414 unsigned char val = inb(port);
417 printk(PREFIX "IRQ%d SCI:", irq);
422 printk(" set to Level");
423 outb(val | mask, port);
429 printk(" set to Edge");
430 outb(val & ~mask, port);
433 printk(" Trigger.\n");
437 #endif /* CONFIG_ACPI_BUS */
439 int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
441 #ifdef CONFIG_X86_IO_APIC
442 if (use_pci_vector() && !platform_legacy_irq(gsi))
443 *irq = IO_APIC_VECTOR(gsi);
450 unsigned int acpi_register_gsi(u32 gsi, int edge_level, int active_high_low)
456 * Make sure all (legacy) PCI IRQs are set as level-triggered.
458 if (acpi_irq_model == ACPI_IRQ_MODEL_PIC) {
460 extern void eisa_set_level_irq(unsigned int irq);
462 if (edge_level == ACPI_LEVEL_SENSITIVE) {
463 if ((gsi < 16) && !((1 << gsi) & irq_mask)) {
464 Dprintk(KERN_DEBUG PREFIX "Setting GSI %u as level-triggered\n", gsi);
465 irq_mask |= (1 << gsi);
466 eisa_set_level_irq(gsi);
472 #ifdef CONFIG_X86_IO_APIC
473 if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC) {
474 mp_register_gsi(gsi, edge_level, active_high_low);
477 acpi_gsi_to_irq(gsi, &irq);
480 EXPORT_SYMBOL(acpi_register_gsi);
482 static unsigned long __init
485 unsigned long length)
487 unsigned long offset = 0;
488 unsigned long sig_len = sizeof("RSD PTR ") - 1;
491 * Scan all 16-byte boundaries of the physical memory region for the
494 for (offset = 0; offset < length; offset += 16) {
495 if (strncmp((char *) (start + offset), "RSD PTR ", sig_len))
497 return (start + offset);
503 static int __init acpi_parse_sbf(unsigned long phys_addr, unsigned long size)
505 struct acpi_table_sbf *sb;
507 if (!phys_addr || !size)
510 sb = (struct acpi_table_sbf *) __acpi_map_table(phys_addr, size);
512 printk(KERN_WARNING PREFIX "Unable to map SBF\n");
516 sbf_port = sb->sbf_cmos; /* Save CMOS port */
522 #ifdef CONFIG_HPET_TIMER
524 static int __init acpi_parse_hpet(unsigned long phys, unsigned long size)
526 struct acpi_table_hpet *hpet_tbl;
531 hpet_tbl = (struct acpi_table_hpet *) __acpi_map_table(phys, size);
533 printk(KERN_WARNING PREFIX "Unable to map HPET\n");
537 if (hpet_tbl->addr.space_id != ACPI_SPACE_MEM) {
538 printk(KERN_WARNING PREFIX "HPET timers must be located in "
544 vxtime.hpet_address = hpet_tbl->addr.addrl |
545 ((long) hpet_tbl->addr.addrh << 32);
547 printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
548 hpet_tbl->id, vxtime.hpet_address);
551 extern unsigned long hpet_address;
553 hpet_address = hpet_tbl->addr.addrl;
554 printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
555 hpet_tbl->id, hpet_address);
562 #define acpi_parse_hpet NULL
565 #ifdef CONFIG_X86_PM_TIMER
566 extern u32 pmtmr_ioport;
569 static int __init acpi_parse_fadt(unsigned long phys, unsigned long size)
571 struct fadt_descriptor_rev2 *fadt = NULL;
573 fadt = (struct fadt_descriptor_rev2*) __acpi_map_table(phys,size);
575 printk(KERN_WARNING PREFIX "Unable to map FADT\n");
579 #ifdef CONFIG_ACPI_INTERPRETER
580 /* initialize sci_int early for INT_SRC_OVR MADT parsing */
581 acpi_fadt.sci_int = fadt->sci_int;
584 #ifdef CONFIG_X86_PM_TIMER
585 /* detect the location of the ACPI PM Timer */
586 if (fadt->revision >= FADT2_REVISION_ID) {
588 if (fadt->xpm_tmr_blk.address_space_id != ACPI_ADR_SPACE_SYSTEM_IO)
591 pmtmr_ioport = fadt->xpm_tmr_blk.address;
594 pmtmr_ioport = fadt->V1_pm_tmr_blk;
597 printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n", pmtmr_ioport);
604 acpi_find_rsdp (void)
606 unsigned long rsdp_phys = 0;
610 return __pa(efi.acpi20);
612 return __pa(efi.acpi);
615 * Scan memory looking for the RSDP signature. First search EBDA (low
616 * memory) paragraphs and then search upper memory (E0000-FFFFF).
618 rsdp_phys = acpi_scan_rsdp (0, 0x400);
620 rsdp_phys = acpi_scan_rsdp (0xE0000, 0xFFFFF);
625 #ifdef CONFIG_X86_LOCAL_APIC
627 * Parse LAPIC entries in MADT
628 * returns 0 on success, < 0 on error
631 acpi_parse_madt_lapic_entries(void)
636 * Note that the LAPIC address is obtained from the MADT (32-bit value)
637 * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
640 count = acpi_table_parse_madt(ACPI_MADT_LAPIC_ADDR_OVR, acpi_parse_lapic_addr_ovr, 0);
642 printk(KERN_ERR PREFIX "Error parsing LAPIC address override entry\n");
646 mp_register_lapic_address(acpi_lapic_addr);
648 count = acpi_table_parse_madt(ACPI_MADT_LAPIC, acpi_parse_lapic,
651 printk(KERN_ERR PREFIX "No LAPIC entries present\n");
652 /* TBD: Cleanup to allow fallback to MPS */
655 else if (count < 0) {
656 printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
657 /* TBD: Cleanup to allow fallback to MPS */
661 count = acpi_table_parse_madt(ACPI_MADT_LAPIC_NMI, acpi_parse_lapic_nmi, 0);
663 printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
664 /* TBD: Cleanup to allow fallback to MPS */
669 #endif /* CONFIG_X86_LOCAL_APIC */
671 #if defined(CONFIG_X86_IO_APIC) && defined(CONFIG_ACPI_INTERPRETER)
673 * Parse IOAPIC related entries in MADT
674 * returns 0 on success, < 0 on error
677 acpi_parse_madt_ioapic_entries(void)
682 * ACPI interpreter is required to complete interrupt setup,
683 * so if it is off, don't enumerate the io-apics with ACPI.
684 * If MPS is present, it will handle them,
685 * otherwise the system will stay in PIC mode
687 if (acpi_disabled || acpi_noirq) {
692 * if "noapic" boot option, don't look for IO-APICs
694 if (skip_ioapic_setup) {
695 printk(KERN_INFO PREFIX "Skipping IOAPIC probe "
696 "due to 'noapic' option.\n");
700 count = acpi_table_parse_madt(ACPI_MADT_IOAPIC, acpi_parse_ioapic, MAX_IO_APICS);
702 printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
705 else if (count < 0) {
706 printk(KERN_ERR PREFIX "Error parsing IOAPIC entry\n");
710 count = acpi_table_parse_madt(ACPI_MADT_INT_SRC_OVR, acpi_parse_int_src_ovr, NR_IRQ_VECTORS);
712 printk(KERN_ERR PREFIX "Error parsing interrupt source overrides entry\n");
713 /* TBD: Cleanup to allow fallback to MPS */
718 * If BIOS did not supply an INT_SRC_OVR for the SCI
719 * pretend we got one so we can set the SCI flags.
721 if (!acpi_sci_override_gsi)
722 acpi_sci_ioapic_setup(acpi_fadt.sci_int, 0, 0);
724 /* Fill in identity legacy mapings where no override */
725 mp_config_acpi_legacy_irqs();
727 count = acpi_table_parse_madt(ACPI_MADT_NMI_SRC, acpi_parse_nmi_src, NR_IRQ_VECTORS);
729 printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
730 /* TBD: Cleanup to allow fallback to MPS */
737 static inline int acpi_parse_madt_ioapic_entries(void)
741 #endif /* !(CONFIG_X86_IO_APIC && CONFIG_ACPI_INTERPRETER) */
745 acpi_process_madt(void)
747 #ifdef CONFIG_X86_LOCAL_APIC
750 count = acpi_table_parse(ACPI_APIC, acpi_parse_madt);
754 * Parse MADT LAPIC entries
756 error = acpi_parse_madt_lapic_entries();
761 * Parse MADT IO-APIC entries
763 error = acpi_parse_madt_ioapic_entries();
765 acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
766 acpi_irq_balance_set(NULL);
769 smp_found_config = 1;
770 clustered_apic_check();
773 if (error == -EINVAL) {
775 * Dell Precision Workstation 410, 610 come here.
777 printk(KERN_ERR PREFIX "Invalid BIOS MADT, disabling ACPI\n");
787 * called from setup_arch(), always.
788 * 1. checksums all tables
789 * 2. enumerates lapics
790 * 3. enumerates io-apics
793 * acpi_lapic = 1 if LAPIC found
794 * acpi_ioapic = 1 if IOAPIC found
795 * if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
796 * if acpi_blacklisted() acpi_disabled = 1;
800 * return value: (currently ignored)
806 acpi_boot_init (void)
811 * If acpi_disabled, bail out
812 * One exception: acpi=ht continues far enough to enumerate LAPICs
814 if (acpi_disabled && !acpi_ht)
818 * Initialize the ACPI boot-time table parser.
820 error = acpi_table_init();
826 acpi_table_parse(ACPI_BOOT, acpi_parse_sbf);
829 * blacklist may disable ACPI entirely
831 error = acpi_blacklisted();
833 extern int acpi_force;
836 printk(KERN_WARNING PREFIX "acpi=force override\n");
838 printk(KERN_WARNING PREFIX "Disabling ACPI support\n");
845 * set sci_int and PM timer address
847 acpi_table_parse(ACPI_FADT, acpi_parse_fadt);
850 * Process the Multiple APIC Description Table (MADT), if present
854 acpi_table_parse(ACPI_HPET, acpi_parse_hpet);
855 acpi_table_parse(ACPI_MCFG, acpi_parse_mcfg);