2 * acpi.c - Architecture-Specific Low-Level ACPI Support
4 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
5 * Copyright (C) 2001 Jun Nakajima <jun.nakajima@intel.com>
6 * Copyright (C) 2001 Patrick Mochel <mochel@osdl.org>
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27 #include <linux/config.h>
28 #include <linux/kernel.h>
29 #include <linux/init.h>
30 #include <linux/types.h>
31 #include <linux/stddef.h>
32 #include <linux/slab.h>
33 #include <linux/pci.h>
34 #include <linux/bootmem.h>
35 #include <linux/irq.h>
36 #include <linux/acpi.h>
37 #include <asm/mpspec.h>
40 #include <asm/apicdef.h>
42 #include <asm/pgtable.h>
43 #include <asm/pgalloc.h>
44 #include <asm/io_apic.h>
46 #include <asm/save_state.h>
47 #include <asm/smpboot.h>
50 #define PREFIX "ACPI: "
56 acpi_interrupt_flags acpi_sci_flags __initdata;
57 int acpi_sci_override_gsi __initdata;
58 int acpi_skip_timer_override __initdata;
59 /* --------------------------------------------------------------------------
60 Boot-time Configuration
61 -------------------------------------------------------------------------- */
63 #ifdef CONFIG_ACPI_PCI
64 int acpi_noirq __initdata; /* skip ACPI IRQ initialization */
65 int acpi_pci_disabled __initdata; /* skip ACPI PCI scan and IRQ initialization */
67 int acpi_ht __initdata = 1; /* enable HT */
69 enum acpi_irq_model_id acpi_irq_model;
73 * Temporarily use the virtual area starting from FIX_IO_APIC_BASE_END,
74 * to map the target physical address. The problem is that set_fixmap()
75 * provides a single page, and it is possible that the page is not
77 * By using this area, we can map up to MAX_IO_APICS pages temporarily,
78 * i.e. until the next __va_range() call.
80 * Important Safety Note: The fixed I/O APIC page numbers are *subtracted*
81 * from the fixed base. That's why we start at FIX_IO_APIC_BASE_END and
82 * count idx down while incrementing the phys address.
84 char *__acpi_map_table(unsigned long phys, unsigned long size)
86 unsigned long base, offset, mapped_size;
89 if (phys + size < 8*1024*1024)
92 offset = phys & (PAGE_SIZE - 1);
93 mapped_size = PAGE_SIZE - offset;
94 set_fixmap(FIX_ACPI_END, phys);
95 base = fix_to_virt(FIX_ACPI_END);
98 * Most cases can be covered by the below.
101 while (mapped_size < size) {
102 if (--idx < FIX_ACPI_BEGIN)
103 return 0; /* cannot handle this */
105 set_fixmap(idx, phys);
106 mapped_size += PAGE_SIZE;
109 return ((unsigned char *) base + offset);
112 #ifdef CONFIG_ACPI_MMCONFIG
114 u32 pci_mmcfg_base_addr;
117 acpi_parse_mcfg(unsigned long phys_addr,
120 struct acpi_table_mcfg *mcfg = NULL;
122 if (!phys_addr || !size)
125 mcfg = (struct acpi_table_mcfg *) __acpi_map_table(phys_addr, size);
127 printk(KERN_WARNING PREFIX "Unable to map MCFG\n");
131 if (mcfg->base_reserved) {
132 printk(KERN_ERR PREFIX "MMCONFIG not in low 4GB of memory\n");
136 pci_mmcfg_base_addr = mcfg->base_address;
140 #endif /* CONFIG_ACPI_MMCONFIG */
142 #ifdef CONFIG_X86_LOCAL_APIC
144 static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
149 unsigned long phys_addr,
152 struct acpi_table_madt *madt = NULL;
154 if (!phys_addr || !size)
157 madt = (struct acpi_table_madt *) __acpi_map_table(phys_addr, size);
159 printk(KERN_WARNING PREFIX "Unable to map MADT\n");
163 if (madt->lapic_address)
164 acpi_lapic_addr = (u64) madt->lapic_address;
166 printk(KERN_INFO PREFIX "Local APIC address 0x%08x\n",
167 madt->lapic_address);
169 detect_clustered_apic(madt->header.oem_id, madt->header.oem_table_id);
177 acpi_table_entry_header *header)
179 struct acpi_table_lapic *processor = NULL;
181 processor = (struct acpi_table_lapic*) header;
185 acpi_table_print_madt_entry(header);
188 processor->id, /* APIC ID */
189 processor->flags.enabled); /* Enabled? */
196 acpi_parse_lapic_addr_ovr (
197 acpi_table_entry_header *header)
199 struct acpi_table_lapic_addr_ovr *lapic_addr_ovr = NULL;
201 lapic_addr_ovr = (struct acpi_table_lapic_addr_ovr*) header;
205 acpi_lapic_addr = lapic_addr_ovr->address;
211 acpi_parse_lapic_nmi (
212 acpi_table_entry_header *header)
214 struct acpi_table_lapic_nmi *lapic_nmi = NULL;
216 lapic_nmi = (struct acpi_table_lapic_nmi*) header;
220 acpi_table_print_madt_entry(header);
222 if (lapic_nmi->lint != 1)
223 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
228 #endif /*CONFIG_X86_LOCAL_APIC*/
230 #if defined(CONFIG_X86_IO_APIC) && defined(CONFIG_ACPI_INTERPRETER)
234 acpi_table_entry_header *header)
236 struct acpi_table_ioapic *ioapic = NULL;
238 ioapic = (struct acpi_table_ioapic*) header;
242 acpi_table_print_madt_entry(header);
247 ioapic->global_irq_base);
253 * Parse Interrupt Source Override for the ACPI SCI
256 acpi_sci_ioapic_setup(u32 gsi, u16 polarity, u16 trigger)
258 if (trigger == 0) /* compatible SCI trigger is level */
261 if (polarity == 0) /* compatible SCI polarity is low */
264 /* Command-line over-ride via acpi_sci= */
265 if (acpi_sci_flags.trigger)
266 trigger = acpi_sci_flags.trigger;
268 if (acpi_sci_flags.polarity)
269 polarity = acpi_sci_flags.polarity;
272 * mp_config_acpi_legacy_irqs() already setup IRQs < 16
273 * If GSI is < 16, this will update its flags,
274 * else it will create a new mp_irqs[] entry.
276 mp_override_legacy_irq(gsi, polarity, trigger, gsi);
279 * stash over-ride to indicate we've been here
280 * and for later update of acpi_fadt
282 acpi_sci_override_gsi = gsi;
287 acpi_parse_fadt(unsigned long phys, unsigned long size)
289 struct fadt_descriptor_rev2 *fadt =0;
291 fadt = (struct fadt_descriptor_rev2*) __acpi_map_table(phys,size);
293 printk(KERN_WARNING PREFIX "Unable to map FADT\n");
297 #ifdef CONFIG_ACPI_INTERPRETER
298 /* initialize sci_int early for INT_SRC_OVR MADT parsing */
299 acpi_fadt.sci_int = fadt->sci_int;
307 acpi_parse_int_src_ovr (
308 acpi_table_entry_header *header)
310 struct acpi_table_int_src_ovr *intsrc = NULL;
312 intsrc = (struct acpi_table_int_src_ovr*) header;
316 acpi_table_print_madt_entry(header);
318 if (intsrc->bus_irq == acpi_fadt.sci_int) {
319 acpi_sci_ioapic_setup(intsrc->global_irq,
320 intsrc->flags.polarity, intsrc->flags.trigger);
324 if (acpi_skip_timer_override &&
325 intsrc->bus_irq == 0 && intsrc->global_irq == 2) {
326 printk(PREFIX "BIOS IRQ0 pin2 override ignored.\n");
330 mp_override_legacy_irq (
332 intsrc->flags.polarity,
333 intsrc->flags.trigger,
342 acpi_table_entry_header *header)
344 struct acpi_table_nmi_src *nmi_src = NULL;
346 nmi_src = (struct acpi_table_nmi_src*) header;
350 acpi_table_print_madt_entry(header);
352 /* TBD: Support nimsrc entries? */
357 #endif /*CONFIG_X86_IO_APIC && CONFIG_ACPI_INTERPRETER*/
360 static unsigned long __init
363 unsigned long length)
365 unsigned long offset = 0;
366 unsigned long sig_len = sizeof("RSD PTR ") - 1;
369 * Scan all 16-byte boundaries of the physical memory region for the
372 for (offset = 0; offset < length; offset += 16) {
373 if (strncmp((char *) (start + offset), "RSD PTR ", sig_len))
375 return (start + offset);
383 acpi_find_rsdp (void)
385 unsigned long rsdp_phys = 0;
388 * Scan memory looking for the RSDP signature. First search EBDA (low
389 * memory) paragraphs and then search upper memory (E0000-FFFFF).
391 rsdp_phys = acpi_scan_rsdp (0, 0x400);
393 rsdp_phys = acpi_scan_rsdp (0xE0000, 0xFFFFF);
399 extern int mp_irqs_alloc(void);
403 * called from setup_arch(), always.
404 * 1. maps ACPI tables for later use
405 * 2. enumerates lapics
406 * 3. enumerates io-apics
409 * acpi_lapic = 1 if LAPIC found
410 * acpi_ioapic = 1 if IOAPIC found
411 * if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
412 * if acpi_blacklisted() disable_acpi()
416 * return value: (currently ignored)
421 acpi_boot_init (void)
425 if (acpi_disabled && !acpi_ht)
429 * The default interrupt routing model is PIC (8259). This gets
430 * overriden if IOAPICs are enumerated (below).
432 acpi_irq_model = ACPI_IRQ_MODEL_PIC;
435 * Initialize the ACPI boot-time table parser.
437 result = acpi_table_init();
443 #ifdef CONFIG_X86_IOAPIC
447 result = acpi_blacklisted();
449 printk(KERN_NOTICE PREFIX "BIOS listed in blacklist, disabling ACPI support\n");
454 #ifdef CONFIG_ACPI_MMCONFIG
455 result = acpi_table_parse(ACPI_MCFG, acpi_parse_mcfg);
457 printk(KERN_ERR PREFIX "Error %d parsing MCFG\n", result);
458 } else if (result > 1) {
459 printk(KERN_WARNING PREFIX "Multiple MCFG tables exist\n");
463 #ifdef CONFIG_X86_LOCAL_APIC
468 * Parse the Multiple APIC Description Table (MADT), if exists.
469 * Note that this table provides platform SMP configuration
470 * information -- the successor to MPS tables.
473 result = acpi_table_parse(ACPI_APIC, acpi_parse_madt);
477 else if (result < 0) {
478 printk(KERN_ERR PREFIX "Error parsing MADT\n");
482 printk(KERN_WARNING PREFIX "Multiple MADT tables exist\n");
487 * Note that the LAPIC address is obtained from the MADT (32-bit value)
488 * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
491 result = acpi_table_parse_madt(ACPI_MADT_LAPIC_ADDR_OVR, acpi_parse_lapic_addr_ovr);
493 printk(KERN_ERR PREFIX "Error parsing LAPIC address override entry\n");
497 mp_register_lapic_address(acpi_lapic_addr);
499 result = acpi_table_parse_madt(ACPI_MADT_LAPIC, acpi_parse_lapic);
501 printk(KERN_ERR PREFIX "No LAPIC entries present\n");
502 /* TBD: Cleanup to allow fallback to MPS */
505 else if (result < 0) {
506 printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
507 /* TBD: Cleanup to allow fallback to MPS */
511 result = acpi_table_parse_madt(ACPI_MADT_LAPIC_NMI, acpi_parse_lapic_nmi);
513 printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
514 /* TBD: Cleanup to allow fallback to MPS */
520 #endif /*CONFIG_X86_LOCAL_APIC*/
522 #if defined(CONFIG_X86_IO_APIC) && defined(CONFIG_ACPI_INTERPRETER)
530 * ACPI interpreter is required to complete interrupt setup,
531 * so if it is off, don't enumerate the io-apics with ACPI.
532 * If MPS is present, it will handle them,
533 * otherwise the system will stay in PIC mode
535 if (acpi_disabled || acpi_noirq) {
540 * if "noapic" boot option, don't look for IO-APICs
542 if (ioapic_setup_disabled()) {
543 printk(KERN_INFO PREFIX "Skipping IOAPIC probe "
544 "due to 'noapic' option.\n");
548 result = mp_irqs_alloc(); /* Dynamically allocate mp_irqs[] */
554 result = acpi_table_parse_madt(ACPI_MADT_IOAPIC, acpi_parse_ioapic);
556 printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
559 else if (result < 0) {
560 printk(KERN_ERR PREFIX "Error parsing IOAPIC entry\n");
564 /* Record sci_int for use when looking for MADT sci_int override */
565 acpi_table_parse(ACPI_FADT, acpi_parse_fadt);
567 result = acpi_table_parse_madt(ACPI_MADT_INT_SRC_OVR, acpi_parse_int_src_ovr);
569 printk(KERN_ERR PREFIX "Error parsing interrupt source overrides entry\n");
570 /* TBD: Cleanup to allow fallback to MPS */
575 * If BIOS did not supply an INT_SRC_OVR for the SCI
576 * pretend we got one so we can set the SCI flags.
578 if (!acpi_sci_override_gsi)
579 acpi_sci_ioapic_setup(acpi_fadt.sci_int, 0, 0);
581 /* Fill in identity legacy mapings where no override */
582 mp_config_acpi_legacy_irqs();
584 result = acpi_table_parse_madt(ACPI_MADT_NMI_SRC, acpi_parse_nmi_src);
586 printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
587 /* TBD: Cleanup to allow fallback to MPS */
591 acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
593 acpi_irq_balance_set(NULL);
597 if (acpi_lapic && acpi_ioapic)
598 smp_found_config = 1;
600 #endif /*CONFIG_X86_IO_APIC && CONFIG_ACPI_INTERPRETER*/
606 #ifdef CONFIG_ACPI_BUS
608 * acpi_pic_sci_set_trigger()
610 * use ELCR to set PIC-mode trigger type for SCI
612 * If a PIC-mode SCI is not recognized or gives spurious IRQ7's
613 * it may require Edge Trigger -- use "acpi_sci=edge"
615 * Port 0x4d0-4d1 are ECLR1 and ECLR2, the Edge/Level Control Registers
616 * for the 8259 PIC. bit[n] = 1 means irq[n] is Level, otherwise Edge.
617 * ECLR1 is IRQ's 0-7 (IRQ 0, 1, 2 must be 0)
618 * ECLR2 is IRQ's 8-15 (IRQ 8, 13 must be 0)
622 acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
624 unsigned char mask = 1 << (irq & 7);
625 unsigned int port = 0x4d0 + (irq >> 3);
626 unsigned char val = inb(port);
629 printk(PREFIX "IRQ%d SCI:", irq);
634 printk(" set to Level");
635 outb(val | mask, port);
641 printk(" set to Edge");
642 outb(val & ~mask, port);
645 printk(" Trigger.\n");
648 #endif /* CONFIG_ACPI_BUS */
652 #ifndef __HAVE_ARCH_CMPXCHG
653 #warning ACPI uses CMPXCHG, i486 and later hardware
656 /* --------------------------------------------------------------------------
657 Low-Level Sleep Support
658 -------------------------------------------------------------------------- */
660 #ifdef CONFIG_ACPI_SLEEP
665 #include <linux/serial.h>
668 /* address in low memory of the wakeup routine. */
669 unsigned long acpi_wakeup_address = 0;
671 /* new page directory that we will be using */
674 /* saved page directory */
675 static pmd_t saved_pmd;
677 /* page which we'll use for the new page directory */
680 extern unsigned long FASTCALL(acpi_copy_wakeup_routine(unsigned long));
683 * acpi_create_identity_pmd
685 * Create a new, identity mapped pmd.
687 * Do this by creating new page directory, and marking all the pages as R/W
688 * Then set it as the new Page Middle Directory.
689 * And, of course, flush the TLB so it takes effect.
691 * We save the address of the old one, for later restoration.
693 static void acpi_create_identity_pmd (void)
698 ptep = (pte_t*)__get_free_page(GFP_KERNEL);
700 /* fill page with low mapping */
701 for (i = 0; i < PTRS_PER_PTE; i++)
702 set_pte(ptep + i, mk_pte_phys(i << PAGE_SHIFT, PAGE_SHARED));
704 pgd = pgd_offset(current->active_mm, 0);
705 pmd = pmd_alloc(current->mm,pgd, 0);
707 /* save the old pmd */
710 /* set the new one */
711 set_pmd(pmd, __pmd(_PAGE_TABLE + __pa(ptep)));
720 * Restore the old pmd saved by acpi_create_identity_pmd and
721 * free the page that said function alloc'd
723 static void acpi_restore_pmd (void)
725 set_pmd(pmd, saved_pmd);
727 free_page((unsigned long)ptep);
731 * acpi_save_state_mem - save kernel state
733 * Create an identity mapped page table and copy the wakeup routine to
736 int acpi_save_state_mem (void)
738 acpi_create_identity_pmd();
739 acpi_copy_wakeup_routine(acpi_wakeup_address);
745 * acpi_save_state_disk - save kernel state to disk
748 int acpi_save_state_disk (void)
756 void acpi_restore_state_mem (void)
762 * acpi_reserve_bootmem - do _very_ early ACPI initialisation
764 * We allocate a page in low memory for the wakeup
765 * routine for when we come back from a sleep state. The
766 * runtime allocator allows specification of <16M pages, but not
769 void __init acpi_reserve_bootmem(void)
771 acpi_wakeup_address = (unsigned long)alloc_bootmem_low(PAGE_SIZE);
772 if (!acpi_wakeup_address)
773 printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
776 void do_suspend_lowlevel_s4bios(int resume)
779 save_processor_context();
780 acpi_save_register_state((unsigned long)&&acpi_sleep_done);
781 acpi_enter_sleep_state_s4bios();
785 restore_processor_context();
789 #endif /*CONFIG_ACPI_SLEEP*/