fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / arch / i386 / kernel / acpi / boot.c
index f1a2194..d8e257b 100644 (file)
  */
 
 #include <linux/init.h>
-#include <linux/config.h>
 #include <linux/acpi.h>
 #include <linux/efi.h>
+#include <linux/cpumask.h>
 #include <linux/module.h>
 #include <linux/dmi.h>
 #include <linux/irq.h>
+#include <linux/bootmem.h>
+#include <linux/ioport.h>
 
 #include <asm/pgtable.h>
 #include <asm/io_apic.h>
 #include <asm/io.h>
 #include <asm/mpspec.h>
 
-#ifdef CONFIG_X86_64
+static int __initdata acpi_force = 0;
 
-extern void __init clustered_apic_check(void);
+#ifdef CONFIG_ACPI
+int acpi_disabled = 0;
+#else
+int acpi_disabled = 1;
+#endif
+EXPORT_SYMBOL(acpi_disabled);
+
+#ifdef CONFIG_X86_64
 
-extern int gsi_irq_sharing(int gsi);
 #include <asm/proto.h>
 
 static inline int acpi_madt_oem_check(char *oem_id, char *oem_table_id) { return 0; }
@@ -54,17 +62,15 @@ static inline int acpi_madt_oem_check(char *oem_id, char *oem_table_id) { return
 #include <mach_mpparse.h>
 #endif                         /* CONFIG_X86_LOCAL_APIC */
 
-static inline int gsi_irq_sharing(int gsi) { return gsi; }
-
 #endif                         /* X86 */
 
 #define BAD_MADT_ENTRY(entry, end) (                                       \
                (!entry) || (unsigned long)entry + sizeof(*entry) > end ||  \
-               ((acpi_table_entry_header *)entry)->length != sizeof(*entry))
+               ((acpi_table_entry_header *)entry)->length < sizeof(*entry))
 
 #define PREFIX                 "ACPI: "
 
-int acpi_noirq __initdata;     /* skip ACPI IRQ initialization */
+int acpi_noirq;                                /* skip ACPI IRQ initialization */
 int acpi_pci_disabled __initdata;      /* skip ACPI PCI scan and IRQ initialization */
 int acpi_ht __initdata = 1;    /* enable HT */
 
@@ -76,6 +82,7 @@ EXPORT_SYMBOL(acpi_strict);
 acpi_interrupt_flags acpi_sci_flags __initdata;
 int acpi_sci_override_gsi __initdata;
 int acpi_skip_timer_override __initdata;
+int acpi_use_timer_override __initdata;
 
 #ifdef CONFIG_X86_LOCAL_APIC
 static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
@@ -100,7 +107,7 @@ EXPORT_SYMBOL(x86_acpiid_to_apicid);
  */
 enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
 
-#ifdef CONFIG_X86_64
+#if defined(CONFIG_X86_64) && !defined(CONFIG_XEN)
 
 /* rely on all ACPI tables being in the direct mapping */
 char *__acpi_map_table(unsigned long phys_addr, unsigned long size)
@@ -133,8 +140,10 @@ char *__acpi_map_table(unsigned long phys, unsigned long size)
        unsigned long base, offset, mapped_size;
        int idx;
 
+#ifndef CONFIG_XEN
        if (phys + size < 8 * 1024 * 1024)
                return __va(phys);
+#endif
 
        offset = phys & (PAGE_SIZE - 1);
        mapped_size = PAGE_SIZE - offset;
@@ -202,6 +211,8 @@ int __init acpi_parse_mcfg(unsigned long phys_addr, unsigned long size)
                if (mcfg->config[i].base_reserved) {
                        printk(KERN_ERR PREFIX
                               "MMCONFIG not in low 4GB of memory\n");
+                       kfree(pci_mmcfg_config);
+                       pci_mmcfg_config_num = 0;
                        return -ENODEV;
                }
        }
@@ -215,7 +226,7 @@ static int __init acpi_parse_madt(unsigned long phys_addr, unsigned long size)
 {
        struct acpi_table_madt *madt = NULL;
 
-       if (!phys_addr || !size)
+       if (!phys_addr || !size || !cpu_has_apic)
                return -EINVAL;
 
        madt = (struct acpi_table_madt *)__acpi_map_table(phys_addr, size);
@@ -324,7 +335,7 @@ acpi_parse_ioapic(acpi_table_entry_header * header, const unsigned long end)
 /*
  * Parse Interrupt Source Override for the ACPI SCI
  */
-static void acpi_sci_ioapic_setup(u32 gsi, u16 polarity, u16 trigger)
+static void __init acpi_sci_ioapic_setup(u32 gsi, u16 polarity, u16 trigger)
 {
        if (trigger == 0)       /* compatible SCI trigger is level */
                trigger = 3;
@@ -458,12 +469,7 @@ void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
 
 int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
 {
-#ifdef CONFIG_X86_IO_APIC
-       if (use_pci_vector() && !platform_legacy_irq(gsi))
-               *irq = IO_APIC_VECTOR(gsi);
-       else
-#endif
-               *irq = gsi_irq_sharing(gsi);
+       *irq = gsi;
        return 0;
 }
 
@@ -505,16 +511,76 @@ EXPORT_SYMBOL(acpi_register_gsi);
 #ifdef CONFIG_ACPI_HOTPLUG_CPU
 int acpi_map_lsapic(acpi_handle handle, int *pcpu)
 {
-       /* TBD */
-       return -EINVAL;
+       struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
+       union acpi_object *obj;
+       struct acpi_table_lapic *lapic;
+       cpumask_t tmp_map, new_map;
+       u8 physid;
+       int cpu;
+
+       if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
+               return -EINVAL;
+
+       if (!buffer.length || !buffer.pointer)
+               return -EINVAL;
+
+       obj = buffer.pointer;
+       if (obj->type != ACPI_TYPE_BUFFER ||
+           obj->buffer.length < sizeof(*lapic)) {
+               kfree(buffer.pointer);
+               return -EINVAL;
+       }
+
+       lapic = (struct acpi_table_lapic *)obj->buffer.pointer;
+
+       if ((lapic->header.type != ACPI_MADT_LAPIC) ||
+           (!lapic->flags.enabled)) {
+               kfree(buffer.pointer);
+               return -EINVAL;
+       }
+
+       physid = lapic->id;
+
+       kfree(buffer.pointer);
+       buffer.length = ACPI_ALLOCATE_BUFFER;
+       buffer.pointer = NULL;
+
+       tmp_map = cpu_present_map;
+       mp_register_lapic(physid, lapic->flags.enabled);
+
+       /*
+        * If mp_register_lapic successfully generates a new logical cpu
+        * number, then the following will get us exactly what was mapped
+        */
+       cpus_andnot(new_map, cpu_present_map, tmp_map);
+       if (cpus_empty(new_map)) {
+               printk ("Unable to map lapic to logical cpu number\n");
+               return -EINVAL;
+       }
+
+       cpu = first_cpu(new_map);
+
+       *pcpu = cpu;
+       return 0;
 }
 
 EXPORT_SYMBOL(acpi_map_lsapic);
 
 int acpi_unmap_lsapic(int cpu)
 {
-       /* TBD */
-       return -EINVAL;
+       int i;
+
+       for_each_possible_cpu(i) {
+               if (x86_acpiid_to_apicid[i] == x86_cpu_to_apicid[cpu]) {
+                       x86_acpiid_to_apicid[i] = -1;
+                       break;
+               }
+       }
+       x86_cpu_to_apicid[cpu] = -1;
+       cpu_clear(cpu, cpu_present_map);
+       num_processors--;
+
+       return (0);
 }
 
 EXPORT_SYMBOL(acpi_unmap_lsapic);
@@ -547,7 +613,11 @@ acpi_scan_rsdp(unsigned long start, unsigned long length)
         * RSDP signature.
         */
        for (offset = 0; offset < length; offset += 16) {
+#ifdef CONFIG_XEN
+               if (strncmp((char *)((unsigned long)isa_bus_to_virt(start) + offset), "RSD PTR ", sig_len))
+#else
                if (strncmp((char *)(phys_to_virt(start) + offset), "RSD PTR ", sig_len))
+#endif
                        continue;
                return (start + offset);
        }
@@ -578,6 +648,8 @@ static int __init acpi_parse_sbf(unsigned long phys_addr, unsigned long size)
 static int __init acpi_parse_hpet(unsigned long phys, unsigned long size)
 {
        struct acpi_table_hpet *hpet_tbl;
+       struct resource *hpet_res;
+       resource_size_t res_start;
 
        if (!phys || !size)
                return -EINVAL;
@@ -593,12 +665,26 @@ static int __init acpi_parse_hpet(unsigned long phys, unsigned long size)
                       "memory.\n");
                return -1;
        }
+
+#define HPET_RESOURCE_NAME_SIZE 9
+       hpet_res = alloc_bootmem(sizeof(*hpet_res) + HPET_RESOURCE_NAME_SIZE);
+       if (hpet_res) {
+               memset(hpet_res, 0, sizeof(*hpet_res));
+               hpet_res->name = (void *)&hpet_res[1];
+               hpet_res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
+               snprintf((char *)hpet_res->name, HPET_RESOURCE_NAME_SIZE,
+                        "HPET %u", hpet_tbl->number);
+               hpet_res->end = (1 * 1024) - 1;
+       }
+
 #ifdef CONFIG_X86_64
        vxtime.hpet_address = hpet_tbl->addr.addrl |
            ((long)hpet_tbl->addr.addrh << 32);
 
        printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
               hpet_tbl->id, vxtime.hpet_address);
+
+       res_start = vxtime.hpet_address;
 #else                          /* X86 */
        {
                extern unsigned long hpet_address;
@@ -606,9 +692,17 @@ static int __init acpi_parse_hpet(unsigned long phys, unsigned long size)
                hpet_address = hpet_tbl->addr.addrl;
                printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
                       hpet_tbl->id, hpet_address);
+
+               res_start = hpet_address;
        }
 #endif                         /* X86 */
 
+       if (hpet_res) {
+               hpet_res->start = res_start;
+               hpet_res->end += res_start;
+               insert_resource(&iomem_resource, hpet_res);
+       }
+
        return 0;
 }
 #else
@@ -621,9 +715,9 @@ extern u32 pmtmr_ioport;
 
 static int __init acpi_parse_fadt(unsigned long phys, unsigned long size)
 {
-       struct fadt_descriptor_rev2 *fadt = NULL;
+       struct fadt_descriptor *fadt = NULL;
 
-       fadt = (struct fadt_descriptor_rev2 *)__acpi_map_table(phys, size);
+       fadt = (struct fadt_descriptor *)__acpi_map_table(phys, size);
        if (!fadt) {
                printk(KERN_WARNING PREFIX "Unable to map FADT\n");
                return 0;
@@ -636,7 +730,7 @@ static int __init acpi_parse_fadt(unsigned long phys, unsigned long size)
        acpi_fadt.force_apic_physical_destination_mode =
            fadt->force_apic_physical_destination_mode;
 
-#ifdef CONFIG_X86_PM_TIMER
+#if defined(CONFIG_X86_PM_TIMER) && !defined(CONFIG_XEN)
        /* detect the location of the ACPI PM Timer */
        if (fadt->revision >= FADT2_REVISION_ID) {
                /* FADT rev. 2 */
@@ -668,10 +762,10 @@ unsigned long __init acpi_find_rsdp(void)
        unsigned long rsdp_phys = 0;
 
        if (efi_enabled) {
-               if (efi.acpi20)
-                       return __pa(efi.acpi20);
-               else if (efi.acpi)
-                       return __pa(efi.acpi);
+               if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
+                       return efi.acpi20;
+               else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
+                       return efi.acpi;
        }
        /*
         * Scan memory looking for the RSDP signature. First search EBDA (low
@@ -693,6 +787,9 @@ static int __init acpi_parse_madt_lapic_entries(void)
 {
        int count;
 
+       if (!cpu_has_apic)
+               return -ENODEV;
+
        /* 
         * Note that the LAPIC address is obtained from the MADT (32-bit value)
         * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
@@ -751,6 +848,9 @@ static int __init acpi_parse_madt_ioapic_entries(void)
                return -ENODEV;
        }
 
+       if (!cpu_has_apic) 
+               return -ENODEV;
+
        /*
         * if "noapic" boot option, don't look for IO-APICs
         */
@@ -853,8 +953,6 @@ static void __init acpi_process_madt(void)
        return;
 }
 
-extern int acpi_force;
-
 #ifdef __i386__
 
 static int __init disable_acpi_irq(struct dmi_system_id *d)
@@ -1156,3 +1254,104 @@ int __init acpi_boot_init(void)
 
        return 0;
 }
+
+static int __init parse_acpi(char *arg)
+{
+       if (!arg)
+               return -EINVAL;
+
+       /* "acpi=off" disables both ACPI table parsing and interpreter */
+       if (strcmp(arg, "off") == 0) {
+               disable_acpi();
+       }
+       /* acpi=force to over-ride black-list */
+       else if (strcmp(arg, "force") == 0) {
+               acpi_force = 1;
+               acpi_ht = 1;
+               acpi_disabled = 0;
+       }
+       /* acpi=strict disables out-of-spec workarounds */
+       else if (strcmp(arg, "strict") == 0) {
+               acpi_strict = 1;
+       }
+       /* Limit ACPI just to boot-time to enable HT */
+       else if (strcmp(arg, "ht") == 0) {
+               if (!acpi_force)
+                       disable_acpi();
+               acpi_ht = 1;
+       }
+       /* "acpi=noirq" disables ACPI interrupt routing */
+       else if (strcmp(arg, "noirq") == 0) {
+               acpi_noirq_set();
+       } else {
+               /* Core will printk when we return error. */
+               return -EINVAL;
+       }
+       return 0;
+}
+early_param("acpi", parse_acpi);
+
+/* FIXME: Using pci= for an ACPI parameter is a travesty. */
+static int __init parse_pci(char *arg)
+{
+       if (arg && strcmp(arg, "noacpi") == 0)
+               acpi_disable_pci();
+       return 0;
+}
+early_param("pci", parse_pci);
+
+#ifdef CONFIG_X86_IO_APIC
+static int __init parse_acpi_skip_timer_override(char *arg)
+{
+       acpi_skip_timer_override = 1;
+       return 0;
+}
+early_param("acpi_skip_timer_override", parse_acpi_skip_timer_override);
+
+static int __init parse_acpi_use_timer_override(char *arg)
+{
+       acpi_use_timer_override = 1;
+       return 0;
+}
+early_param("acpi_use_timer_override", parse_acpi_use_timer_override);
+#endif /* CONFIG_X86_IO_APIC */
+
+static int __init setup_acpi_sci(char *s)
+{
+       if (!s)
+               return -EINVAL;
+       if (!strcmp(s, "edge"))
+               acpi_sci_flags.trigger = 1;
+       else if (!strcmp(s, "level"))
+               acpi_sci_flags.trigger = 3;
+       else if (!strcmp(s, "high"))
+               acpi_sci_flags.polarity = 1;
+       else if (!strcmp(s, "low"))
+               acpi_sci_flags.polarity = 3;
+       else
+               return -EINVAL;
+       return 0;
+}
+early_param("acpi_sci", setup_acpi_sci);
+
+int __acpi_acquire_global_lock(unsigned int *lock)
+{
+       unsigned int old, new, val;
+       do {
+               old = *lock;
+               new = (((old & ~0x3) + 2) + ((old >> 1) & 0x1));
+               val = cmpxchg(lock, old, new);
+       } while (unlikely (val != old));
+       return (new < 3) ? -1 : 0;
+}
+
+int __acpi_release_global_lock(unsigned int *lock)
+{
+       unsigned int old, new, val;
+       do {
+               old = *lock;
+               new = old & ~0x3;
+               val = cmpxchg(lock, old, new);
+       } while (unlikely (val != old));
+       return old & 0x1;
+}