[SPARC64]: Provide mmu statistics via sysfs.
[sfrench/cifs-2.6.git] / arch / sparc64 / kernel / pci.c
index 023af41ad68d99845dc9a4a1f5644d492282d63c..38a32bc95d22bb0423a6bd28b2ff75f18e69fef1 100644 (file)
 #include <linux/sched.h>
 #include <linux/capability.h>
 #include <linux/errno.h>
-#include <linux/smp_lock.h>
+#include <linux/pci.h>
 #include <linux/msi.h>
 #include <linux/irq.h>
 #include <linux/init.h>
 
 #include <asm/uaccess.h>
-#include <asm/pbm.h>
 #include <asm/pgtable.h>
 #include <asm/irq.h>
 #include <asm/ebus.h>
@@ -49,10 +48,10 @@ asmlinkage int sys_pciconfig_write(unsigned long bus, unsigned long dfn,
 #else
 
 /* List of all PCI controllers found in the system. */
-struct pci_controller_info *pci_controller_root = NULL;
+struct pci_pbm_info *pci_pbm_root = NULL;
 
-/* Each PCI controller found gets a unique index. */
-int pci_num_controllers = 0;
+/* Each PBM found gets a unique index. */
+int pci_num_pbms = 0;
 
 volatile int pci_poke_in_progress;
 volatile int pci_poke_cpu = -1;
@@ -190,6 +189,7 @@ extern void schizo_init(struct device_node *, const char *);
 extern void schizo_plus_init(struct device_node *, const char *);
 extern void tomatillo_init(struct device_node *, const char *);
 extern void sun4v_pci_init(struct device_node *, const char *);
+extern void fire_pci_init(struct device_node *, const char *);
 
 static struct {
        char *model_name;
@@ -207,6 +207,7 @@ static struct {
        { "SUNW,tomatillo", tomatillo_init },
        { "pci108e,a801", tomatillo_init },
        { "SUNW,sun4v-pci", sun4v_pci_init },
+       { "pciex108e,80f0", fire_pci_init },
 };
 #define PCI_NUM_CONTROLLER_TYPES (sizeof(pci_controller_table) / \
                                  sizeof(pci_controller_table[0]))
@@ -290,7 +291,7 @@ extern const struct pci_iommu_ops pci_sun4u_iommu_ops,
 
 /* Find each controller in the system, attach and initialize
  * software state structure for each and link into the
- * pci_controller_root.  Setup the controller enough such
+ * pci_pbm_root.  Setup the controller enough such
  * that bus scanning can be done.
  */
 static void __init pci_controller_probe(void)
@@ -305,6 +306,20 @@ static void __init pci_controller_probe(void)
        pci_controller_scan(pci_controller_init);
 }
 
+static int ofpci_verbose;
+
+static int __init ofpci_debug(char *str)
+{
+       int val = 0;
+
+       get_option(&str, &val);
+       if (val)
+               ofpci_verbose = 1;
+       return 1;
+}
+
+__setup("ofpci_debug=", ofpci_debug);
+
 static unsigned long pci_parse_of_flags(u32 addr0)
 {
        unsigned long flags = 0;
@@ -336,7 +351,9 @@ static void pci_parse_of_addrs(struct of_device *op,
        addrs = of_get_property(node, "assigned-addresses", &proplen);
        if (!addrs)
                return;
-       printk("    parse addresses (%d bytes) @ %p\n", proplen, addrs);
+       if (ofpci_verbose)
+               printk("    parse addresses (%d bytes) @ %p\n",
+                      proplen, addrs);
        op_res = &op->resource[0];
        for (; proplen >= 20; proplen -= 20, addrs += 5, op_res++) {
                struct resource *res;
@@ -347,8 +364,9 @@ static void pci_parse_of_addrs(struct of_device *op,
                if (!flags)
                        continue;
                i = addrs[0] & 0xff;
-               printk("  start: %lx, end: %lx, i: %x\n",
-                      op_res->start, op_res->end, i);
+               if (ofpci_verbose)
+                       printk("  start: %lx, end: %lx, i: %x\n",
+                              op_res->start, op_res->end, i);
 
                if (PCI_BASE_ADDRESS_0 <= i && i <= PCI_BASE_ADDRESS_5) {
                        res = &dev->resource[(i - PCI_BASE_ADDRESS_0) >> 2];
@@ -376,7 +394,7 @@ struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm,
        const char *type;
        u32 class;
 
-       dev = kzalloc(sizeof(struct pci_dev), GFP_KERNEL);
+       dev = alloc_pci_dev();
        if (!dev)
                return NULL;
 
@@ -392,8 +410,9 @@ struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm,
        if (type == NULL)
                type = "";
 
-       printk("    create device, devfn: %x, type: %s hostcontroller(%d)\n",
-              devfn, type, host_controller);
+       if (ofpci_verbose)
+               printk("    create device, devfn: %x, type: %s\n",
+                      devfn, type);
 
        dev->bus = bus;
        dev->sysdata = node;
@@ -433,8 +452,16 @@ struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm,
                sprintf(pci_name(dev), "%04x:%02x:%02x.%d", pci_domain_nr(bus),
                        dev->bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn));
        }
-       printk("    class: 0x%x device name: %s\n",
-              dev->class, pci_name(dev));
+       if (ofpci_verbose)
+               printk("    class: 0x%x device name: %s\n",
+                      dev->class, pci_name(dev));
+
+       /* I have seen IDE devices which will not respond to
+        * the bmdma simplex check reads if bus mastering is
+        * disabled.
+        */
+       if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
+               pci_set_master(dev);
 
        dev->current_state = 4;         /* unknown power state */
        dev->error_state = pci_channel_io_normal;
@@ -461,14 +488,15 @@ struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm,
        }
        pci_parse_of_addrs(sd->op, node, dev);
 
-       printk("    adding to system ...\n");
+       if (ofpci_verbose)
+               printk("    adding to system ...\n");
 
        pci_device_add(dev, bus);
 
        return dev;
 }
 
-static void __init apb_calc_first_last(u8 map, u32 *first_p, u32 *last_p)
+static void __devinit apb_calc_first_last(u8 map, u32 *first_p, u32 *last_p)
 {
        u32 idx, first, last;
 
@@ -487,8 +515,8 @@ static void __init apb_calc_first_last(u8 map, u32 *first_p, u32 *last_p)
        *last_p = last;
 }
 
-static void __init pci_resource_adjust(struct resource *res,
-                                      struct resource *root)
+static void pci_resource_adjust(struct resource *res,
+                               struct resource *root)
 {
        res->start += root->start;
        res->end += root->start;
@@ -497,9 +525,9 @@ static void __init pci_resource_adjust(struct resource *res,
 /* Cook up fake bus resources for SUNW,simba PCI bridges which lack
  * a proper 'ranges' property.
  */
-static void __init apb_fake_ranges(struct pci_dev *dev,
-                                  struct pci_bus *bus,
-                                  struct pci_pbm_info *pbm)
+static void __devinit apb_fake_ranges(struct pci_dev *dev,
+                                     struct pci_bus *bus,
+                                     struct pci_pbm_info *pbm)
 {
        struct resource *res;
        u32 first, last;
@@ -522,15 +550,15 @@ static void __init apb_fake_ranges(struct pci_dev *dev,
        pci_resource_adjust(res, &pbm->mem_space);
 }
 
-static void __init pci_of_scan_bus(struct pci_pbm_info *pbm,
-                                  struct device_node *node,
-                                  struct pci_bus *bus);
+static void __devinit pci_of_scan_bus(struct pci_pbm_info *pbm,
+                                     struct device_node *node,
+                                     struct pci_bus *bus);
 
 #define GET_64BIT(prop, i)     ((((u64) (prop)[(i)]) << 32) | (prop)[(i)+1])
 
-void __devinit of_scan_pci_bridge(struct pci_pbm_info *pbm,
-                                 struct device_node *node,
-                                 struct pci_dev *dev)
+static void __devinit of_scan_pci_bridge(struct pci_pbm_info *pbm,
+                                        struct device_node *node,
+                                        struct pci_dev *dev)
 {
        struct pci_bus *bus;
        const u32 *busrange, *ranges;
@@ -539,7 +567,8 @@ void __devinit of_scan_pci_bridge(struct pci_pbm_info *pbm,
        unsigned int flags;
        u64 size;
 
-       printk("of_scan_pci_bridge(%s)\n", node->full_name);
+       if (ofpci_verbose)
+               printk("of_scan_pci_bridge(%s)\n", node->full_name);
 
        /* parse bus-range property */
        busrange = of_get_property(node, "bus-range", &len);
@@ -624,26 +653,29 @@ void __devinit of_scan_pci_bridge(struct pci_pbm_info *pbm,
 simba_cont:
        sprintf(bus->name, "PCI Bus %04x:%02x", pci_domain_nr(bus),
                bus->number);
-       printk("    bus name: %s\n", bus->name);
+       if (ofpci_verbose)
+               printk("    bus name: %s\n", bus->name);
 
        pci_of_scan_bus(pbm, node, bus);
 }
 
-static void __init pci_of_scan_bus(struct pci_pbm_info *pbm,
-                                  struct device_node *node,
-                                  struct pci_bus *bus)
+static void __devinit pci_of_scan_bus(struct pci_pbm_info *pbm,
+                                     struct device_node *node,
+                                     struct pci_bus *bus)
 {
        struct device_node *child;
        const u32 *reg;
        int reglen, devfn;
        struct pci_dev *dev;
 
-       printk("PCI: scan_bus[%s] bus no %d\n",
-              node->full_name, bus->number);
+       if (ofpci_verbose)
+               printk("PCI: scan_bus[%s] bus no %d\n",
+                      node->full_name, bus->number);
 
        child = NULL;
        while ((child = of_get_next_child(node, child)) != NULL) {
-               printk("  * %s\n", child->full_name);
+               if (ofpci_verbose)
+                       printk("  * %s\n", child->full_name);
                reg = of_get_property(child, "reg", &reglen);
                if (reg == NULL || reglen < 20)
                        continue;
@@ -653,7 +685,9 @@ static void __init pci_of_scan_bus(struct pci_pbm_info *pbm,
                dev = of_create_pci_dev(pbm, child, bus, devfn, 0);
                if (!dev)
                        continue;
-               printk("PCI: dev header type: %x\n", dev->hdr_type);
+               if (ofpci_verbose)
+                       printk("PCI: dev header type: %x\n",
+                              dev->hdr_type);
 
                if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
                    dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
@@ -733,9 +767,8 @@ int pci_host_bridge_write_pci_cfg(struct pci_bus *bus_dev,
        return PCIBIOS_SUCCESSFUL;
 }
 
-struct pci_bus * __init pci_scan_one_pbm(struct pci_pbm_info *pbm)
+struct pci_bus * __devinit pci_scan_one_pbm(struct pci_pbm_info *pbm)
 {
-       struct pci_controller_info *p = pbm->parent;
        struct device_node *node = pbm->prom_node;
        struct pci_dev *host_pdev;
        struct pci_bus *bus;
@@ -743,7 +776,7 @@ struct pci_bus * __init pci_scan_one_pbm(struct pci_pbm_info *pbm)
        printk("PCI: Scanning PBM %s\n", node->full_name);
 
        /* XXX parent device? XXX */
-       bus = pci_create_bus(NULL, pbm->pci_first_busno, p->pci_ops, pbm);
+       bus = pci_create_bus(NULL, pbm->pci_first_busno, pbm->pci_ops, pbm);
        if (!bus) {
                printk(KERN_ERR "Failed to create bus for %s\n",
                       node->full_name);
@@ -768,10 +801,10 @@ struct pci_bus * __init pci_scan_one_pbm(struct pci_pbm_info *pbm)
 
 static void __init pci_scan_each_controller_bus(void)
 {
-       struct pci_controller_info *p;
+       struct pci_pbm_info *pbm;
 
-       for (p = pci_controller_root; p; p = p->next)
-               p->scan_bus(p);
+       for (pbm = pci_pbm_root; pbm; pbm = pbm->next)
+               pbm->scan_bus(pbm);
 }
 
 extern void power_init(void);
@@ -779,7 +812,7 @@ extern void power_init(void);
 static int __init pcibios_init(void)
 {
        pci_controller_probe();
-       if (pci_controller_root == NULL)
+       if (pci_pbm_root == NULL)
                return 0;
 
        pci_scan_each_controller_bus();
@@ -914,10 +947,8 @@ static int __pci_mmap_make_offset_bus(struct pci_dev *pdev, struct vm_area_struc
                                      enum pci_mmap_state mmap_state)
 {
        struct pci_pbm_info *pbm = pdev->dev.archdata.host_controller;
-       struct pci_controller_info *p;
        unsigned long space_size, user_offset, user_size;
 
-       p = pbm->parent;
        if (mmap_state == pci_mmap_io) {
                space_size = (pbm->io_space.end -
                              pbm->io_space.start) + 1;
@@ -1070,11 +1101,7 @@ int pci_domain_nr(struct pci_bus *pbus)
        if (pbm == NULL || pbm->parent == NULL) {
                ret = -ENXIO;
        } else {
-               struct pci_controller_info *p = pbm->parent;
-
-               ret = p->index;
-               ret = ((ret << 1) +
-                      ((pbm == &pbm->parent->pbm_B) ? 1 : 0));
+               ret = pbm->index;
        }
 
        return ret;
@@ -1085,17 +1112,12 @@ EXPORT_SYMBOL(pci_domain_nr);
 int arch_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *desc)
 {
        struct pci_pbm_info *pbm = pdev->dev.archdata.host_controller;
-       struct pci_controller_info *p = pbm->parent;
-       int virt_irq, err;
+       int virt_irq;
 
-       if (!pbm->msi_num || !p->setup_msi_irq)
+       if (!pbm->setup_msi_irq)
                return -EINVAL;
 
-       err = p->setup_msi_irq(&virt_irq, pdev, desc);
-       if (err < 0)
-               return err;
-
-       return virt_irq;
+       return pbm->setup_msi_irq(&virt_irq, pdev, desc);
 }
 
 void arch_teardown_msi_irq(unsigned int virt_irq)
@@ -1103,12 +1125,11 @@ void arch_teardown_msi_irq(unsigned int virt_irq)
        struct msi_desc *entry = get_irq_msi(virt_irq);
        struct pci_dev *pdev = entry->dev;
        struct pci_pbm_info *pbm = pdev->dev.archdata.host_controller;
-       struct pci_controller_info *p = pbm->parent;
 
-       if (!pbm->msi_num || !p->setup_msi_irq)
+       if (!pbm->teardown_msi_irq)
                return;
 
-       return p->teardown_msi_irq(virt_irq, pdev);
+       return pbm->teardown_msi_irq(virt_irq, pdev);
 }
 #endif /* !(CONFIG_PCI_MSI) */