ath9k: Storage class should be before const qualifier
[safe/jmp/linux-2.6] / drivers / acpi / pci_irq.c
index 42b195e..843699e 100644 (file)
@@ -4,6 +4,8 @@
  *  Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
  *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  *  Copyright (C) 2002       Dominik Brodowski <devel@brodo.de>
+ *  (c) Copyright 2008 Hewlett-Packard Development Company, L.P.
+ *     Bjorn Helgaas <bjorn.helgaas@hp.com>
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
@@ -38,6 +40,8 @@
 #include <acpi/acpi_bus.h>
 #include <acpi/acpi_drivers.h>
 
+#define PREFIX "ACPI: "
+
 #define _COMPONENT             ACPI_PCI_COMPONENT
 ACPI_MODULE_NAME("pci_irq");
 
@@ -45,11 +49,8 @@ struct acpi_prt_entry {
        struct list_head        list;
        struct acpi_pci_id      id;
        u8                      pin;
-       struct {
-               acpi_handle             handle;
-               u32                     index;
-       }                       link;
-       u32                     irq;
+       acpi_handle             link;
+       u32                     index;          /* GSI, or link _CRS index */
 };
 
 static LIST_HEAD(acpi_prt_list);
@@ -87,7 +88,7 @@ static struct acpi_prt_entry *acpi_pci_irq_find_prt_entry(struct pci_dev *dev,
 }
 
 /* http://bugzilla.kernel.org/show_bug.cgi?id=4773 */
-static struct dmi_system_id medion_md9580[] = {
+static const struct dmi_system_id medion_md9580[] = {
        {
                .ident = "Medion MD9580-F laptop",
                .matches = {
@@ -99,7 +100,7 @@ static struct dmi_system_id medion_md9580[] = {
 };
 
 /* http://bugzilla.kernel.org/show_bug.cgi?id=5044 */
-static struct dmi_system_id dell_optiplex[] = {
+static const struct dmi_system_id dell_optiplex[] = {
        {
                .ident = "Dell Optiplex GX1",
                .matches = {
@@ -111,7 +112,7 @@ static struct dmi_system_id dell_optiplex[] = {
 };
 
 /* http://bugzilla.kernel.org/show_bug.cgi?id=10138 */
-static struct dmi_system_id hp_t5710[] = {
+static const struct dmi_system_id hp_t5710[] = {
        {
                .ident = "HP t5710",
                .matches = {
@@ -124,13 +125,13 @@ static struct dmi_system_id hp_t5710[] = {
 };
 
 struct prt_quirk {
-       struct dmi_system_id    *system;
+       const struct dmi_system_id *system;
        unsigned int            segment;
        unsigned int            bus;
        unsigned int            device;
        unsigned char           pin;
-       char                    *source;        /* according to BIOS */
-       char                    *actual_source;
+       const char              *source;        /* according to BIOS */
+       const char              *actual_source;
 };
 
 #define PCI_INTX_PIN(c)                (c - 'A' + 1)
@@ -140,7 +141,7 @@ struct prt_quirk {
  * interrupt at the listed segment/bus/device/pin is connected to the first
  * link device, but it is actually connected to the second.
  */
-static struct prt_quirk prt_quirks[] = {
+static const struct prt_quirk prt_quirks[] = {
        { medion_md9580, 0, 0, 9, PCI_INTX_PIN('A'),
                "\\_SB_.PCI0.ISA_.LNKA",
                "\\_SB_.PCI0.ISA_.LNKB"},
@@ -152,11 +153,11 @@ static struct prt_quirk prt_quirks[] = {
                "\\_SB_.PCI0.LNK3"},
 };
 
-static void
-do_prt_fixups(struct acpi_prt_entry *entry, struct acpi_pci_routing_table *prt)
+static void do_prt_fixups(struct acpi_prt_entry *entry,
+                         struct acpi_pci_routing_table *prt)
 {
        int i;
-       struct prt_quirk *quirk;
+       const struct prt_quirk *quirk;
 
        for (i = 0; i < ARRAY_SIZE(prt_quirks); i++) {
                quirk = &prt_quirks[i];
@@ -183,9 +184,8 @@ do_prt_fixups(struct acpi_prt_entry *entry, struct acpi_pci_routing_table *prt)
        }
 }
 
-static int
-acpi_pci_irq_add_entry(acpi_handle handle,
-                      int segment, int bus, struct acpi_pci_routing_table *prt)
+static int acpi_pci_irq_add_entry(acpi_handle handle, struct pci_bus *bus,
+                                 struct acpi_pci_routing_table *prt)
 {
        struct acpi_prt_entry *entry;
 
@@ -198,13 +198,15 @@ acpi_pci_irq_add_entry(acpi_handle handle,
         * 1=INTA, 2=INTB.  We use the PCI encoding throughout, so convert
         * it here.
         */
-       entry->id.segment = segment;
-       entry->id.bus = bus;
+       entry->id.segment = pci_domain_nr(bus);
+       entry->id.bus = bus->number;
        entry->id.device = (prt->address >> 16) & 0xFFFF;
        entry->pin = prt->pin + 1;
 
        do_prt_fixups(entry, prt);
 
+       entry->index = prt->source_index;
+
        /*
         * Type 1: Dynamic
         * ---------------
@@ -218,10 +220,9 @@ acpi_pci_irq_add_entry(acpi_handle handle,
         *       (e.g. exists somewhere 'below' this _PRT entry in the ACPI
         *       namespace).
         */
-       if (prt->source[0]) {
-               acpi_get_handle(handle, prt->source, &entry->link.handle);
-               entry->link.index = prt->source_index;
-       }
+       if (prt->source[0])
+               acpi_get_handle(handle, prt->source, &entry->link);
+
        /*
         * Type 2: Static
         * --------------
@@ -229,14 +230,12 @@ acpi_pci_irq_add_entry(acpi_handle handle,
         * the IRQ value, which is hardwired to specific interrupt inputs on
         * the interrupt controller.
         */
-       else
-               entry->link.index = prt->source_index;
 
        ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO,
                              "      %04x:%02x:%02x[%c] -> %s[%d]\n",
                              entry->id.segment, entry->id.bus,
                              entry->id.device, pin_name(entry->pin),
-                             prt->source, entry->link.index));
+                             prt->source, entry->index));
 
        spin_lock(&acpi_prt_lock);
        list_add_tail(&entry->list, &acpi_prt_list);
@@ -245,7 +244,7 @@ acpi_pci_irq_add_entry(acpi_handle handle,
        return 0;
 }
 
-int acpi_pci_irq_add_prt(acpi_handle handle, int segment, int bus)
+int acpi_pci_irq_add_prt(acpi_handle handle, struct pci_bus *bus)
 {
        acpi_status status;
        struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
@@ -274,7 +273,7 @@ int acpi_pci_irq_add_prt(acpi_handle handle, int segment, int bus)
 
        entry = buffer.pointer;
        while (entry && (entry->length > 0)) {
-               acpi_pci_irq_add_entry(handle, segment, bus, entry);
+               acpi_pci_irq_add_entry(handle, bus, entry);
                entry = (struct acpi_pci_routing_table *)
                    ((unsigned long)entry + entry->length);
        }
@@ -283,16 +282,17 @@ int acpi_pci_irq_add_prt(acpi_handle handle, int segment, int bus)
        return 0;
 }
 
-void acpi_pci_irq_del_prt(int segment, int bus)
+void acpi_pci_irq_del_prt(struct pci_bus *bus)
 {
        struct acpi_prt_entry *entry, *tmp;
 
        printk(KERN_DEBUG
               "ACPI: Delete PCI Interrupt Routing Table for %04x:%02x\n",
-              segment, bus);
+              pci_domain_nr(bus), bus->number);
        spin_lock(&acpi_prt_lock);
        list_for_each_entry_safe(entry, tmp, &acpi_prt_list, list) {
-               if (segment == entry->id.segment && bus == entry->id.bus) {
+               if (pci_domain_nr(bus) == entry->id.segment
+                       && bus->number == entry->id.bus) {
                        list_del(&entry->list);
                        kfree(entry);
                }
@@ -303,47 +303,7 @@ void acpi_pci_irq_del_prt(int segment, int bus)
 /* --------------------------------------------------------------------------
                           PCI Interrupt Routing Support
    -------------------------------------------------------------------------- */
-static int
-acpi_pci_allocate_irq(struct acpi_prt_entry *entry,
-                     int *triggering, int *polarity, char **link)
-{
-       int irq;
-
-
-       if (entry->link.handle) {
-               irq = acpi_pci_link_allocate_irq(entry->link.handle,
-                                                entry->link.index, triggering,
-                                                polarity, link);
-               if (irq < 0) {
-                       printk(KERN_WARNING PREFIX
-                                     "Invalid IRQ link routing entry\n");
-                       return -1;
-               }
-       } else {
-               irq = entry->link.index;
-               *triggering = ACPI_LEVEL_SENSITIVE;
-               *polarity = ACPI_ACTIVE_LOW;
-       }
-
-       ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found GSI %d\n", irq));
-       return irq;
-}
-
-static int
-acpi_pci_free_irq(struct acpi_prt_entry *entry)
-{
-       int irq;
-
-       if (entry->link.handle) {
-               irq = acpi_pci_link_free_irq(entry->link.handle);
-       } else {
-               irq = entry->link.index;
-       }
-       return irq;
-}
-
-static struct acpi_prt_entry *
-acpi_pci_irq_lookup(struct pci_dev *dev, int pin)
+static struct acpi_prt_entry *acpi_pci_irq_lookup(struct pci_dev *dev, int pin)
 {
        struct acpi_prt_entry *entry;
        struct pci_dev *bridge;
@@ -362,7 +322,7 @@ acpi_pci_irq_lookup(struct pci_dev *dev, int pin)
         */
        bridge = dev->bus->self;
        while (bridge) {
-               pin = (((pin - 1) + PCI_SLOT(dev->devfn)) % 4) + 1;
+               pin = pci_swizzle_interrupt_pin(dev, pin);
 
                if ((bridge->class >> 8) == PCI_CLASS_BRIDGE_CARDBUS) {
                        /* PC card has the same IRQ as its cardbridge */
@@ -394,24 +354,17 @@ acpi_pci_irq_lookup(struct pci_dev *dev, int pin)
        return NULL;
 }
 
-/*
- * acpi_pci_irq_enable
- * success: return 0
- * failure: return < 0
- */
-
 int acpi_pci_irq_enable(struct pci_dev *dev)
 {
        struct acpi_prt_entry *entry;
-       int gsi = 0;
-       u8 pin = 0;
+       int gsi;
+       u8 pin;
        int triggering = ACPI_LEVEL_SENSITIVE;
        int polarity = ACPI_ACTIVE_LOW;
        char *link = NULL;
        char link_desc[16];
        int rc;
 
-
        pin = dev->pin;
        if (!pin) {
                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
@@ -431,10 +384,15 @@ int acpi_pci_irq_enable(struct pci_dev *dev)
                        return 0;
        }
 
-       if (entry)
-               gsi = acpi_pci_allocate_irq(entry, &triggering, &polarity,
-                                           &link);
-       else
+       if (entry) {
+               if (entry->link)
+                       gsi = acpi_pci_link_allocate_irq(entry->link,
+                                                        entry->index,
+                                                        &triggering, &polarity,
+                                                        &link);
+               else
+                       gsi = entry->index;
+       } else
                gsi = -1;
 
        /*
@@ -446,7 +404,8 @@ int acpi_pci_irq_enable(struct pci_dev *dev)
                /* Interrupt Line values above 0xF are forbidden */
                if (dev->irq > 0 && (dev->irq <= 0xF)) {
                        printk(" - using IRQ %d\n", dev->irq);
-                       acpi_register_gsi(dev->irq, ACPI_LEVEL_SENSITIVE,
+                       acpi_register_gsi(&dev->dev, dev->irq,
+                                         ACPI_LEVEL_SENSITIVE,
                                          ACPI_ACTIVE_LOW);
                        return 0;
                } else {
@@ -455,7 +414,7 @@ int acpi_pci_irq_enable(struct pci_dev *dev)
                }
        }
 
-       rc = acpi_register_gsi(gsi, triggering, polarity);
+       rc = acpi_register_gsi(&dev->dev, gsi, triggering, polarity);
        if (rc < 0) {
                dev_warn(&dev->dev, "PCI INT %c: failed to register GSI\n",
                         pin_name(pin));
@@ -484,9 +443,8 @@ void __attribute__ ((weak)) acpi_unregister_gsi(u32 i)
 void acpi_pci_irq_disable(struct pci_dev *dev)
 {
        struct acpi_prt_entry *entry;
-       int gsi = 0;
-       u8 pin = 0;
-
+       int gsi;
+       u8 pin;
 
        pin = dev->pin;
        if (!pin)
@@ -496,7 +454,10 @@ void acpi_pci_irq_disable(struct pci_dev *dev)
        if (!entry)
                return;
 
-       gsi = acpi_pci_free_irq(entry);
+       if (entry->link)
+               gsi = acpi_pci_link_free_irq(entry->link);
+       else
+               gsi = entry->index;
 
        /*
         * TBD: It might be worth clearing dev->irq by magic constant