Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / arch / x86_64 / kernel / mpparse.c
index 7dcc1b5..083da7e 100644 (file)
@@ -14,7 +14,6 @@
  */
 
 #include <linux/mm.h>
-#include <linux/irq.h>
 #include <linux/init.h>
 #include <linux/delay.h>
 #include <linux/config.h>
@@ -23,6 +22,7 @@
 #include <linux/kernel_stat.h>
 #include <linux/mc146818rtc.h>
 #include <linux/acpi.h>
+#include <linux/module.h>
 
 #include <asm/smp.h>
 #include <asm/mtrr.h>
@@ -30,6 +30,7 @@
 #include <asm/pgalloc.h>
 #include <asm/io_apic.h>
 #include <asm/proto.h>
+#include <asm/acpi.h>
 
 /* Have we found an MP table */
 int smp_found_config;
@@ -41,12 +42,11 @@ int acpi_found_madt;
  * Various Linux-internal data structures created from the
  * MP-table.
  */
-int apic_version [MAX_APICS];
+unsigned char apic_version [MAX_APICS];
 unsigned char mp_bus_id_to_type [MAX_MP_BUSSES] = { [0 ... MAX_MP_BUSSES-1] = -1 };
 int mp_bus_id_to_pci_bus [MAX_MP_BUSSES] = { [0 ... MAX_MP_BUSSES-1] = -1 };
-cpumask_t mp_bus_to_cpumask [MAX_MP_BUSSES] = { [0 ... MAX_MP_BUSSES-1] = CPU_MASK_ALL };
 
-int mp_current_pci_id = 0;
+static int mp_current_pci_id = 0;
 /* I/O APIC entries */
 struct mpc_config_ioapic mp_ioapics[MAX_IO_APICS];
 
@@ -65,13 +65,15 @@ unsigned long mp_lapic_addr = 0;
 /* Processor that is doing the boot up */
 unsigned int boot_cpu_id = -1U;
 /* Internal processor count */
-static unsigned int num_processors = 0;
+unsigned int num_processors __initdata = 0;
+
+unsigned disabled_cpus __initdata;
 
 /* Bitmask of physically existing CPUs */
 physid_mask_t phys_cpu_present_map = PHYSID_MASK_NONE;
 
 /* ACPI MADT entry parsing functions */
-#ifdef CONFIG_ACPI_BOOT
+#ifdef CONFIG_ACPI
 extern struct acpi_boot_flags acpi_boot;
 #ifdef CONFIG_X86_LOCAL_APIC
 extern int acpi_parse_lapic (acpi_table_entry_header *header);
@@ -81,7 +83,7 @@ extern int acpi_parse_lapic_nmi (acpi_table_entry_header *header);
 #ifdef CONFIG_X86_IO_APIC
 extern int acpi_parse_ioapic (acpi_table_entry_header *header);
 #endif /*CONFIG_X86_IO_APIC*/
-#endif /*CONFIG_ACPI_BOOT*/
+#endif /*CONFIG_ACPI*/
 
 u8 bios_cpu_apicid[NR_CPUS] = { [0 ... NR_CPUS-1] = BAD_APICID };
 
@@ -104,12 +106,16 @@ static int __init mpf_checksum(unsigned char *mp, int len)
        return sum & 0xFF;
 }
 
-static void __init MP_processor_info (struct mpc_config_processor *m)
+static void __cpuinit MP_processor_info (struct mpc_config_processor *m)
 {
-       int ver;
+       int cpu;
+       unsigned char ver;
+       cpumask_t tmp_map;
 
-       if (!(m->mpc_cpuflag & CPU_ENABLED))
+       if (!(m->mpc_cpuflag & CPU_ENABLED)) {
+               disabled_cpus++;
                return;
+       }
 
        printk(KERN_INFO "Processor #%d %d:%d APIC version %d\n",
                m->mpc_apicid,
@@ -126,19 +132,18 @@ static void __init MP_processor_info (struct mpc_config_processor *m)
                        " Processor ignored.\n", NR_CPUS);
                return;
        }
-       if (num_processors >= maxcpus) {
-               printk(KERN_WARNING "WARNING: maxcpus limit of %i reached."
-                       " Processor ignored.\n", maxcpus);
-               return;
-       }
 
        num_processors++;
+       cpus_complement(tmp_map, cpu_present_map);
+       cpu = first_cpu(tmp_map);
 
-       if (m->mpc_apicid > MAX_APICS) {
+#if MAX_APICS < 255    
+       if ((int)m->mpc_apicid > MAX_APICS) {
                printk(KERN_ERR "Processor #%d INVALID. (Max ID: %d).\n",
                        m->mpc_apicid, MAX_APICS);
                return;
        }
+#endif
        ver = m->mpc_apicver;
 
        physid_set(m->mpc_apicid, phys_cpu_present_map);
@@ -150,7 +155,19 @@ static void __init MP_processor_info (struct mpc_config_processor *m)
                ver = 0x10;
        }
        apic_version[m->mpc_apicid] = ver;
-       bios_cpu_apicid[num_processors - 1] = m->mpc_apicid;
+       if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
+               /*
+                * bios_cpu_apicid is required to have processors listed
+                * in same order as logical cpu numbers. Hence the first
+                * entry is BSP, and so on.
+                */
+               cpu = 0;
+       }
+       bios_cpu_apicid[cpu] = m->mpc_apicid;
+       x86_cpu_to_apicid[cpu] = m->mpc_apicid;
+
+       cpu_set(cpu, cpu_possible_map);
+       cpu_set(cpu, cpu_present_map);
 }
 
 static void __init MP_bus_info (struct mpc_config_bus *m)
@@ -205,7 +222,7 @@ static void __init MP_intsrc_info (struct mpc_config_intsrc *m)
                        m->mpc_irqtype, m->mpc_irqflag & 3,
                        (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
                        m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
-       if (++mp_irq_entries == MAX_IRQ_SOURCES)
+       if (++mp_irq_entries >= MAX_IRQ_SOURCES)
                panic("Max # of irq sources exceeded!!\n");
 }
 
@@ -268,9 +285,9 @@ static int __init smp_read_mpc(struct mp_config_table *mpc)
 
        memcpy(str,mpc->mpc_productid,12);
        str[12]=0;
-       printk(KERN_INFO "Product ID: %s ",str);
+       printk("Product ID: %s ",str);
 
-       printk(KERN_INFO "APIC at: 0x%X\n",mpc->mpc_lapic);
+       printk("APIC at: 0x%X\n",mpc->mpc_lapic);
 
        /* save the local APIC address, it might be non-default */
        if (!acpi_lapic)
@@ -330,6 +347,7 @@ static int __init smp_read_mpc(struct mp_config_table *mpc)
                        }
                }
        }
+       clustered_apic_check();
        if (!num_processors)
                printk(KERN_ERR "SMP mptable: no processors registered!\n");
        return num_processors;
@@ -502,8 +520,6 @@ void __init get_smp_config (void)
        struct intel_mp_floating *mpf = mpf_found;
 
        /*
-        * ACPI may be used to obtain the entire SMP configuration or just to 
-        * enumerate/configure processors (CONFIG_ACPI_BOOT).  Note that 
         * ACPI supports both logical (e.g. Hyper-Threading) and physical 
         * processors, where MPS only supports physical.
         */
@@ -537,7 +553,7 @@ void __init get_smp_config (void)
                 * Read the physical hardware table.  Anything here will
                 * override the defaults.
                 */
-               if (!smp_read_mpc((void *)(unsigned long)mpf->mpf_physptr)) {
+               if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr))) {
                        smp_found_config = 0;
                        printk(KERN_ERR "BIOS bug, MP table errors detected!...\n");
                        printk(KERN_ERR "... disabling SMP support. (tell your hw vendor)\n");
@@ -575,7 +591,6 @@ static int __init smp_scan_config (unsigned long base, unsigned long length)
        extern void __bad_mpf_size(void); 
        unsigned int *bp = phys_to_virt(base);
        struct intel_mp_floating *mpf;
-       static int printed __initdata; 
 
        Dprintk("Scan SMP from %p for %ld bytes.\n", bp,length);
        if (sizeof(*mpf) != 16)
@@ -599,10 +614,6 @@ static int __init smp_scan_config (unsigned long base, unsigned long length)
                bp += 4;
                length -= 16;
        }
-       if (!printed) {         
-               printk(KERN_INFO "No mptable found.\n");
-               printed = 1;
-       }
        return 0;
 }
 
@@ -639,7 +650,11 @@ void __init find_intel_smp (void)
 
        address = *(unsigned short *)phys_to_virt(0x40E);
        address <<= 4;
-       smp_scan_config(address, 0x1000);
+       if (smp_scan_config(address, 0x1000))
+               return;
+
+       /* If we have come this far, we did not find an MP table  */
+        printk(KERN_INFO "No mptable found.\n");
 }
 
 /*
@@ -657,7 +672,7 @@ void __init find_smp_config (void)
                             ACPI-based MP Configuration
    -------------------------------------------------------------------------- */
 
-#ifdef CONFIG_ACPI_BOOT
+#ifdef CONFIG_ACPI
 
 void __init mp_register_lapic_address (
        u64                     address)
@@ -673,7 +688,7 @@ void __init mp_register_lapic_address (
 }
 
 
-void __init mp_register_lapic (
+void __cpuinit mp_register_lapic (
        u8                      id, 
        u8                      enabled)
 {
@@ -691,7 +706,7 @@ void __init mp_register_lapic (
 
        processor.mpc_type = MP_PROCESSOR;
        processor.mpc_apicid = id;
-       processor.mpc_apicver = 0x10; /* TBD: lapic version */
+       processor.mpc_apicver = GET_APIC_VERSION(apic_read(APIC_LVR));
        processor.mpc_cpuflag = (enabled ? CPU_ENABLED : 0);
        processor.mpc_cpuflag |= (boot_cpu ? CPU_BOOTPROCESSOR : 0);
        processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) | 
@@ -708,7 +723,7 @@ void __init mp_register_lapic (
 #define MP_ISA_BUS             0
 #define MP_MAX_IOAPIC_PIN      127
 
-struct mp_ioapic_routing {
+static struct mp_ioapic_routing {
        int                     apic_id;
        int                     gsi_start;
        int                     gsi_end;
@@ -716,7 +731,7 @@ struct mp_ioapic_routing {
 } mp_ioapic_routing[MAX_IO_APICS];
 
 
-static int __init mp_find_ioapic (
+static int mp_find_ioapic (
        int                     gsi)
 {
        int                     i = 0;
@@ -759,7 +774,7 @@ void __init mp_register_ioapic (
        mp_ioapics[idx].mpc_apicaddr = address;
 
        set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
-       mp_ioapics[idx].mpc_apicid = io_apic_get_unique_id(idx, id);
+       mp_ioapics[idx].mpc_apicid = id;
        mp_ioapics[idx].mpc_apicver = io_apic_get_version(idx);
        
        /* 
@@ -859,15 +874,22 @@ void __init mp_config_acpi_legacy_irqs (void)
        for (i = 0; i < 16; i++) {
                int idx;
 
-               for (idx = 0; idx < mp_irq_entries; idx++)
-                       if (mp_irqs[idx].mpc_srcbus == MP_ISA_BUS &&
-                               (mp_irqs[idx].mpc_srcbusirq == i ||
-                               mp_irqs[idx].mpc_dstirq == i))
-                                       break;
+               for (idx = 0; idx < mp_irq_entries; idx++) {
+                       struct mpc_config_intsrc *irq = mp_irqs + idx;
+
+                       /* Do we already have a mapping for this ISA IRQ? */
+                       if (irq->mpc_srcbus == MP_ISA_BUS && irq->mpc_srcbusirq == i)
+                               break;
+
+                       /* Do we already have a mapping for this IOAPIC pin */
+                       if ((irq->mpc_dstapic == intsrc.mpc_dstapic) &&
+                               (irq->mpc_dstirq == i))
+                               break;
+               }
 
                if (idx != mp_irq_entries) {
                        printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
-                       continue;                        /* IRQ already used */
+                       continue;                       /* IRQ already used */
                }
 
                intsrc.mpc_irqtype = mp_INT;
@@ -888,91 +910,93 @@ void __init mp_config_acpi_legacy_irqs (void)
        return;
 }
 
+#define MAX_GSI_NUM    4096
 
-extern FADT_DESCRIPTOR acpi_fadt;
-
-#ifdef CONFIG_ACPI_PCI
-
-void __init mp_parse_prt (void)
+int mp_register_gsi(u32 gsi, int triggering, int polarity)
 {
-       struct list_head        *node = NULL;
-       struct acpi_prt_entry   *entry = NULL;
        int                     ioapic = -1;
        int                     ioapic_pin = 0;
-       int                     gsi = 0;
        int                     idx, bit = 0;
-       int                     edge_level = 0;
-       int                     active_high_low = 0;
-
+       static int              pci_irq = 16;
        /*
-        * Parsing through the PCI Interrupt Routing Table (PRT) and program
-        * routing for all static (IOAPIC-direct) entries.
+        * Mapping between Global System Interrupts, which
+        * represent all possible interrupts, to the IRQs
+        * assigned to actual devices.
         */
-       list_for_each(node, &acpi_prt.entries) {
-               entry = list_entry(node, struct acpi_prt_entry, node);
-
-               /* Need to get gsi for dynamic entry */
-               if (entry->link.handle) {
-                       gsi = acpi_pci_link_get_irq(entry->link.handle, entry->link.index, &edge_level, &active_high_low);
-                       if (!gsi)
-                               continue;
-               } else {
-                       /* Hardwired GSI. Assume PCI standard settings */
-                       gsi = entry->link.index;
-                       edge_level = 1;
-                       active_high_low = 1;
-               }
+       static int              gsi_to_irq[MAX_GSI_NUM];
 
-               /* Don't set up the ACPI SCI because it's already set up */
-               if (acpi_fadt.sci_int == gsi) {
-                       /* we still need to set up the entry's irq */
-                       acpi_gsi_to_irq(gsi, &entry->irq);
-                       continue;
-               }
+       if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC)
+               return gsi;
+
+       /* Don't set up the ACPI SCI because it's already set up */
+       if (acpi_fadt.sci_int == gsi)
+               return gsi;
 
-               ioapic = mp_find_ioapic(gsi);
-               if (ioapic < 0)
-                       continue;
-               ioapic_pin = gsi - mp_ioapic_routing[ioapic].gsi_start;
+       ioapic = mp_find_ioapic(gsi);
+       if (ioapic < 0) {
+               printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
+               return gsi;
+       }
+
+       ioapic_pin = gsi - mp_ioapic_routing[ioapic].gsi_start;
 
-               /* 
-                * Avoid pin reprogramming.  PRTs typically include entries  
-                * with redundant pin->gsi mappings (but unique PCI devices);
-                * we only only program the IOAPIC on the first.
+       /* 
+        * Avoid pin reprogramming.  PRTs typically include entries  
+        * with redundant pin->gsi mappings (but unique PCI devices);
+        * we only program the IOAPIC on the first.
+        */
+       bit = ioapic_pin % 32;
+       idx = (ioapic_pin < 32) ? 0 : (ioapic_pin / 32);
+       if (idx > 3) {
+               printk(KERN_ERR "Invalid reference to IOAPIC pin "
+                       "%d-%d\n", mp_ioapic_routing[ioapic].apic_id, 
+                       ioapic_pin);
+               return gsi;
+       }
+       if ((1<<bit) & mp_ioapic_routing[ioapic].pin_programmed[idx]) {
+               Dprintk(KERN_DEBUG "Pin %d-%d already programmed\n",
+                       mp_ioapic_routing[ioapic].apic_id, ioapic_pin);
+               return gsi_to_irq[gsi];
+       }
+
+       mp_ioapic_routing[ioapic].pin_programmed[idx] |= (1<<bit);
+
+       if (triggering == ACPI_LEVEL_SENSITIVE) {
+               /*
+                * For PCI devices assign IRQs in order, avoiding gaps
+                * due to unused I/O APIC pins.
                 */
-               bit = ioapic_pin % 32;
-               idx = (ioapic_pin < 32) ? 0 : (ioapic_pin / 32);
-               if (idx > 3) {
-                       printk(KERN_ERR "Invalid reference to IOAPIC pin "
-                               "%d-%d\n", mp_ioapic_routing[ioapic].apic_id, 
-                               ioapic_pin);
-                       continue;
-               }
-               if ((1<<bit) & mp_ioapic_routing[ioapic].pin_programmed[idx]) {
-                       Dprintk(KERN_DEBUG "Pin %d-%d already programmed\n",
-                               mp_ioapic_routing[ioapic].apic_id, ioapic_pin);
-                       acpi_gsi_to_irq(gsi, &entry->irq);
-                       continue;
+               int irq = gsi;
+               if (gsi < MAX_GSI_NUM) {
+                       /*
+                        * Retain the VIA chipset work-around (gsi > 15), but
+                        * avoid a problem where the 8254 timer (IRQ0) is setup
+                        * via an override (so it's not on pin 0 of the ioapic),
+                        * and at the same time, the pin 0 interrupt is a PCI
+                        * type.  The gsi > 15 test could cause these two pins
+                        * to be shared as IRQ0, and they are not shareable.
+                        * So test for this condition, and if necessary, avoid
+                        * the pin collision.
+                        */
+                       if (gsi > 15 || (gsi == 0 && !timer_uses_ioapic_pin_0))
+                               gsi = pci_irq++;
+                       /*
+                        * Don't assign IRQ used by ACPI SCI
+                        */
+                       if (gsi == acpi_fadt.sci_int)
+                               gsi = pci_irq++;
+                       gsi_to_irq[irq] = gsi;
+               } else {
+                       printk(KERN_ERR "GSI %u is too high\n", gsi);
+                       return gsi;
                }
-
-               mp_ioapic_routing[ioapic].pin_programmed[idx] |= (1<<bit);
-               if (!io_apic_set_pci_routing(ioapic, ioapic_pin, gsi, edge_level, active_high_low)) {
-                       acpi_gsi_to_irq(gsi, &entry->irq);
-               }
-               printk(KERN_DEBUG "%02x:%02x:%02x[%c] -> %d-%d -> IRQ %d\n",
-                       entry->id.segment, entry->id.bus,
-                       entry->id.device, ('A' + entry->pin), 
-                       mp_ioapic_routing[ioapic].apic_id, ioapic_pin,
-                       entry->irq);
        }
-       
-       print_IO_APIC();
 
-       return;
+       io_apic_set_pci_routing(ioapic, ioapic_pin, gsi,
+               triggering == ACPI_EDGE_SENSITIVE ? 0 : 1,
+               polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
+       return gsi;
 }
 
-#endif /*CONFIG_ACPI_PCI*/
-
 #endif /*CONFIG_X86_IO_APIC*/
-
-#endif /*CONFIG_ACPI_BOOT*/
+#endif /*CONFIG_ACPI*/