[PATCH] kill wall_jiffies
[safe/jmp/linux-2.6] / arch / powerpc / kernel / pci_32.c
index 8474355..9b49f86 100644 (file)
@@ -2,7 +2,6 @@
  * Common pmac/prep/chrp pci routines. -- Cort
  */
 
-#include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/pci.h>
 #include <linux/delay.h>
@@ -12,6 +11,7 @@
 #include <linux/sched.h>
 #include <linux/errno.h>
 #include <linux/bootmem.h>
+#include <linux/irq.h>
 
 #include <asm/processor.h>
 #include <asm/io.h>
@@ -19,7 +19,6 @@
 #include <asm/sections.h>
 #include <asm/pci-bridge.h>
 #include <asm/byteorder.h>
-#include <asm/irq.h>
 #include <asm/uaccess.h>
 #include <asm/machdep.h>
 
@@ -634,12 +633,12 @@ pcibios_alloc_controller(void)
 static void
 make_one_node_map(struct device_node* node, u8 pci_bus)
 {
-       int *bus_range;
+       const int *bus_range;
        int len;
 
        if (pci_bus >= pci_bus_count)
                return;
-       bus_range = (int *) get_property(node, "bus-range", &len);
+       bus_range = get_property(node, "bus-range", &len);
        if (bus_range == NULL || len < 2 * sizeof(int)) {
                printk(KERN_WARNING "Can't get bus-range for %s, "
                       "assuming it starts at 0\n", node->full_name);
@@ -649,13 +648,13 @@ make_one_node_map(struct device_node* node, u8 pci_bus)
 
        for (node=node->child; node != 0;node = node->sibling) {
                struct pci_dev* dev;
-               unsigned int *class_code, *reg;
+               const unsigned int *class_code, *reg;
        
-               class_code = (unsigned int *) get_property(node, "class-code", NULL);
+               class_code = get_property(node, "class-code", NULL);
                if (!class_code || ((*class_code >> 8) != PCI_CLASS_BRIDGE_PCI &&
                        (*class_code >> 8) != PCI_CLASS_BRIDGE_CARDBUS))
                        continue;
-               reg = (unsigned int *)get_property(node, "reg", NULL);
+               reg = get_property(node, "reg", NULL);
                if (!reg)
                        continue;
                dev = pci_find_slot(pci_bus, ((reg[0] >> 8) & 0xff));
@@ -670,7 +669,7 @@ pcibios_make_OF_bus_map(void)
 {
        int i;
        struct pci_controller* hose;
-       u8* of_prop_map;
+       struct property *map_prop;
 
        pci_to_OF_bus_map = (u8*)kmalloc(pci_bus_count, GFP_KERNEL);
        if (!pci_to_OF_bus_map) {
@@ -692,9 +691,12 @@ pcibios_make_OF_bus_map(void)
                        continue;
                make_one_node_map(node, hose->first_busno);
        }
-       of_prop_map = get_property(find_path_device("/"), "pci-OF-bus-map", NULL);
-       if (of_prop_map)
-               memcpy(of_prop_map, pci_to_OF_bus_map, pci_bus_count);
+       map_prop = of_find_property(find_path_device("/"),
+                       "pci-OF-bus-map", NULL);
+       if (map_prop) {
+               BUG_ON(pci_bus_count > map_prop->length);
+               memcpy(map_prop->value, pci_to_OF_bus_map, pci_bus_count);
+       }
 #ifdef DEBUG
        printk("PCI->OF bus map:\n");
        for (i=0; i<pci_bus_count; i++) {
@@ -713,7 +715,7 @@ scan_OF_pci_childs(struct device_node* node, pci_OF_scan_iterator filter, void*
        struct device_node* sub_node;
 
        for (; node != 0;node = node->sibling) {
-               unsigned int *class_code;
+               const unsigned int *class_code;
        
                if (filter(node, data))
                        return node;
@@ -723,7 +725,7 @@ scan_OF_pci_childs(struct device_node* node, pci_OF_scan_iterator filter, void*
                 * a fake root for all functions of a multi-function device,
                 * we go down them as well.
                 */
-               class_code = (unsigned int *) get_property(node, "class-code", NULL);
+               class_code = get_property(node, "class-code", NULL);
                if ((!class_code || ((*class_code >> 8) != PCI_CLASS_BRIDGE_PCI &&
                        (*class_code >> 8) != PCI_CLASS_BRIDGE_CARDBUS)) &&
                        strcmp(node->name, "multifunc-device"))
@@ -738,10 +740,10 @@ scan_OF_pci_childs(struct device_node* node, pci_OF_scan_iterator filter, void*
 static int
 scan_OF_pci_childs_iterator(struct device_node* node, void* data)
 {
-       unsigned int *reg;
+       const unsigned int *reg;
        u8* fdata = (u8*)data;
        
-       reg = (unsigned int *) get_property(node, "reg", NULL);
+       reg = get_property(node, "reg", NULL);
        if (reg && ((reg[0] >> 8) & 0xff) == fdata[1]
                && ((reg[0] >> 16) & 0xff) == fdata[0])
                return 1;
@@ -842,7 +844,7 @@ find_OF_pci_device_filter(struct device_node* node, void* data)
 int
 pci_device_from_OF_node(struct device_node* node, u8* bus, u8* devfn)
 {
-       unsigned int *reg;
+       const unsigned int *reg;
        struct pci_controller* hose;
        struct pci_dev* dev = NULL;
        
@@ -855,7 +857,7 @@ pci_device_from_OF_node(struct device_node* node, u8* bus, u8* devfn)
        if (!scan_OF_pci_childs(((struct device_node*)hose->arch_data)->child,
                        find_OF_pci_device_filter, (void *)node))
                return -ENODEV;
-       reg = (unsigned int *) get_property(node, "reg", NULL);
+       reg = get_property(node, "reg", NULL);
        if (!reg)
                return -ENODEV;
        *bus = (reg[0] >> 16) & 0xff;
@@ -886,8 +888,8 @@ pci_process_bridge_OF_ranges(struct pci_controller *hose,
                           struct device_node *dev, int primary)
 {
        static unsigned int static_lc_ranges[256] __initdata;
-       unsigned int *dt_ranges, *lc_ranges, *ranges, *prev;
-       unsigned int size;
+       const unsigned int *dt_ranges;
+       unsigned int *lc_ranges, *ranges, *prev, size;
        int rlen = 0, orig_rlen;
        int memno = 0;
        struct resource *res;
@@ -898,7 +900,7 @@ pci_process_bridge_OF_ranges(struct pci_controller *hose,
         * that can have more than 3 ranges, fortunately using contiguous
         * addresses -- BenH
         */
-       dt_ranges = (unsigned int *) get_property(dev, "ranges", &rlen);
+       dt_ranges = get_property(dev, "ranges", &rlen);
        if (!dt_ranges)
                return;
        /* Sanity check, though hopefully that never happens */
@@ -1405,6 +1407,65 @@ pcibios_update_irq(struct pci_dev *dev, int irq)
        /* XXX FIXME - update OF device tree node interrupt property */
 }
 
+#ifdef CONFIG_PPC_MERGE
+/* XXX This is a copy of the ppc64 version. This is temporary until we start
+ * merging the 2 PCI layers
+ */
+/*
+ * Reads the interrupt pin to determine if interrupt is use by card.
+ * If the interrupt is used, then gets the interrupt line from the
+ * openfirmware and sets it in the pci_dev and pci_config line.
+ */
+int pci_read_irq_line(struct pci_dev *pci_dev)
+{
+       struct of_irq oirq;
+       unsigned int virq;
+
+       DBG("Try to map irq for %s...\n", pci_name(pci_dev));
+
+       /* Try to get a mapping from the device-tree */
+       if (of_irq_map_pci(pci_dev, &oirq)) {
+               u8 line, pin;
+
+               /* If that fails, lets fallback to what is in the config
+                * space and map that through the default controller. We
+                * also set the type to level low since that's what PCI
+                * interrupts are. If your platform does differently, then
+                * either provide a proper interrupt tree or don't use this
+                * function.
+                */
+               if (pci_read_config_byte(pci_dev, PCI_INTERRUPT_PIN, &pin))
+                       return -1;
+               if (pin == 0)
+                       return -1;
+               if (pci_read_config_byte(pci_dev, PCI_INTERRUPT_LINE, &line) ||
+                   line == 0xff) {
+                       return -1;
+               }
+               DBG(" -> no map ! Using irq line %d from PCI config\n", line);
+
+               virq = irq_create_mapping(NULL, line);
+               if (virq != NO_IRQ)
+                       set_irq_type(virq, IRQ_TYPE_LEVEL_LOW);
+       } else {
+               DBG(" -> got one, spec %d cells (0x%08x...) on %s\n",
+                   oirq.size, oirq.specifier[0], oirq.controller->full_name);
+
+               virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
+                                            oirq.size);
+       }
+       if(virq == NO_IRQ) {
+               DBG(" -> failed to map !\n");
+               return -1;
+       }
+       pci_dev->irq = virq;
+       pci_write_config_byte(pci_dev, PCI_INTERRUPT_LINE, virq);
+
+       return 0;
+}
+EXPORT_SYMBOL(pci_read_irq_line);
+#endif /* CONFIG_PPC_MERGE */
+
 int pcibios_enable_device(struct pci_dev *dev, int mask)
 {
        u16 cmd, old_cmd;