Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[cascardo/linux.git] / arch / sparc64 / kernel / pci_sun4v.c
index eec7def..1ccf4c9 100644 (file)
@@ -1,6 +1,6 @@
 /* pci_sun4v.c: SUN4V specific PCI controller support.
  *
- * Copyright (C) 2006 David S. Miller (davem@davemloft.net)
+ * Copyright (C) 2006, 2007 David S. Miller (davem@davemloft.net)
  */
 
 #include <linux/kernel.h>
@@ -29,7 +29,7 @@
 
 #define PGLIST_NENTS   (PAGE_SIZE / sizeof(u64))
 
-struct pci_iommu_batch {
+struct iommu_batch {
        struct pci_dev  *pdev;          /* Device mapping is for.       */
        unsigned long   prot;           /* IOMMU page protections       */
        unsigned long   entry;          /* Index into IOTSB.            */
@@ -37,12 +37,12 @@ struct pci_iommu_batch {
        unsigned long   npages;         /* Number of pages in list.     */
 };
 
-static DEFINE_PER_CPU(struct pci_iommu_batch, pci_iommu_batch);
+static DEFINE_PER_CPU(struct iommu_batch, pci_iommu_batch);
 
 /* Interrupts must be disabled.  */
 static inline void pci_iommu_batch_start(struct pci_dev *pdev, unsigned long prot, unsigned long entry)
 {
-       struct pci_iommu_batch *p = &__get_cpu_var(pci_iommu_batch);
+       struct iommu_batch *p = &__get_cpu_var(pci_iommu_batch);
 
        p->pdev         = pdev;
        p->prot         = prot;
@@ -51,7 +51,7 @@ static inline void pci_iommu_batch_start(struct pci_dev *pdev, unsigned long pro
 }
 
 /* Interrupts must be disabled.  */
-static long pci_iommu_batch_flush(struct pci_iommu_batch *p)
+static long pci_iommu_batch_flush(struct iommu_batch *p)
 {
        struct pci_pbm_info *pbm = p->pdev->dev.archdata.host_controller;
        unsigned long devhandle = pbm->devhandle;
@@ -89,7 +89,7 @@ static long pci_iommu_batch_flush(struct pci_iommu_batch *p)
 /* Interrupts must be disabled.  */
 static inline long pci_iommu_batch_add(u64 phys_page)
 {
-       struct pci_iommu_batch *p = &__get_cpu_var(pci_iommu_batch);
+       struct iommu_batch *p = &__get_cpu_var(pci_iommu_batch);
 
        BUG_ON(p->npages >= PGLIST_NENTS);
 
@@ -103,14 +103,14 @@ static inline long pci_iommu_batch_add(u64 phys_page)
 /* Interrupts must be disabled.  */
 static inline long pci_iommu_batch_end(void)
 {
-       struct pci_iommu_batch *p = &__get_cpu_var(pci_iommu_batch);
+       struct iommu_batch *p = &__get_cpu_var(pci_iommu_batch);
 
        BUG_ON(p->npages >= PGLIST_NENTS);
 
        return pci_iommu_batch_flush(p);
 }
 
-static long pci_arena_alloc(struct pci_iommu_arena *arena, unsigned long npages)
+static long pci_arena_alloc(struct iommu_arena *arena, unsigned long npages)
 {
        unsigned long n, i, start, end, limit;
        int pass;
@@ -149,7 +149,7 @@ again:
        return n;
 }
 
-static void pci_arena_free(struct pci_iommu_arena *arena, unsigned long base, unsigned long npages)
+static void pci_arena_free(struct iommu_arena *arena, unsigned long base, unsigned long npages)
 {
        unsigned long i;
 
@@ -159,7 +159,7 @@ static void pci_arena_free(struct pci_iommu_arena *arena, unsigned long base, un
 
 static void *pci_4v_alloc_consistent(struct pci_dev *pdev, size_t size, dma_addr_t *dma_addrp, gfp_t gfp)
 {
-       struct pci_iommu *iommu;
+       struct iommu *iommu;
        unsigned long flags, order, first_page, npages, n;
        void *ret;
        long entry;
@@ -225,7 +225,7 @@ arena_alloc_fail:
 static void pci_4v_free_consistent(struct pci_dev *pdev, size_t size, void *cpu, dma_addr_t dvma)
 {
        struct pci_pbm_info *pbm;
-       struct pci_iommu *iommu;
+       struct iommu *iommu;
        unsigned long flags, order, npages, entry;
        u32 devhandle;
 
@@ -257,7 +257,7 @@ static void pci_4v_free_consistent(struct pci_dev *pdev, size_t size, void *cpu,
 
 static dma_addr_t pci_4v_map_single(struct pci_dev *pdev, void *ptr, size_t sz, int direction)
 {
-       struct pci_iommu *iommu;
+       struct iommu *iommu;
        unsigned long flags, npages, oaddr;
        unsigned long i, base_paddr;
        u32 bus_addr, ret;
@@ -321,7 +321,7 @@ iommu_map_fail:
 static void pci_4v_unmap_single(struct pci_dev *pdev, dma_addr_t bus_addr, size_t sz, int direction)
 {
        struct pci_pbm_info *pbm;
-       struct pci_iommu *iommu;
+       struct iommu *iommu;
        unsigned long flags, npages;
        long entry;
        u32 devhandle;
@@ -456,7 +456,7 @@ iommu_map_failed:
 
 static int pci_4v_map_sg(struct pci_dev *pdev, struct scatterlist *sglist, int nelems, int direction)
 {
-       struct pci_iommu *iommu;
+       struct iommu *iommu;
        unsigned long flags, npages, prot;
        u32 dma_base;
        struct scatterlist *sgtmp;
@@ -532,7 +532,7 @@ iommu_map_failed:
 static void pci_4v_unmap_sg(struct pci_dev *pdev, struct scatterlist *sglist, int nelems, int direction)
 {
        struct pci_pbm_info *pbm;
-       struct pci_iommu *iommu;
+       struct iommu *iommu;
        unsigned long flags, i, npages;
        long entry;
        u32 devhandle, bus_addr;
@@ -583,7 +583,7 @@ static void pci_4v_dma_sync_sg_for_cpu(struct pci_dev *pdev, struct scatterlist
        /* Nothing to do... */
 }
 
-struct pci_iommu_ops pci_sun4v_iommu_ops = {
+const struct pci_iommu_ops pci_sun4v_iommu_ops = {
        .alloc_consistent               = pci_4v_alloc_consistent,
        .free_consistent                = pci_4v_free_consistent,
        .map_single                     = pci_4v_map_single,
@@ -612,6 +612,9 @@ static int pci_sun4v_read_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
        unsigned int func = PCI_FUNC(devfn);
        unsigned long ret;
 
+       if (bus_dev == pbm->pci_bus && devfn == 0x00)
+               return pci_host_bridge_read_pci_cfg(bus_dev, devfn, where,
+                                                   size, value);
        if (pci_sun4v_out_of_range(pbm, bus, device, func)) {
                ret = ~0UL;
        } else {
@@ -650,6 +653,9 @@ static int pci_sun4v_write_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
        unsigned int func = PCI_FUNC(devfn);
        unsigned long ret;
 
+       if (bus_dev == pbm->pci_bus && devfn == 0x00)
+               return pci_host_bridge_write_pci_cfg(bus_dev, devfn, where,
+                                                    size, value);
        if (pci_sun4v_out_of_range(pbm, bus, device, func)) {
                /* Do nothing. */
        } else {
@@ -698,129 +704,10 @@ static void pci_sun4v_scan_bus(struct pci_controller_info *p)
        /* XXX register error interrupt handlers XXX */
 }
 
-static void pci_sun4v_base_address_update(struct pci_dev *pdev, int resource)
-{
-       struct pci_pbm_info *pbm = pdev->dev.archdata.host_controller;
-       struct resource *res, *root;
-       u32 reg;
-       int where, size, is_64bit;
-
-       res = &pdev->resource[resource];
-       if (resource < 6) {
-               where = PCI_BASE_ADDRESS_0 + (resource * 4);
-       } else if (resource == PCI_ROM_RESOURCE) {
-               where = pdev->rom_base_reg;
-       } else {
-               /* Somebody might have asked allocation of a non-standard resource */
-               return;
-       }
-
-       /* XXX 64-bit MEM handling is not %100 correct... XXX */
-       is_64bit = 0;
-       if (res->flags & IORESOURCE_IO)
-               root = &pbm->io_space;
-       else {
-               root = &pbm->mem_space;
-               if ((res->flags & PCI_BASE_ADDRESS_MEM_TYPE_MASK)
-                   == PCI_BASE_ADDRESS_MEM_TYPE_64)
-                       is_64bit = 1;
-       }
-
-       size = res->end - res->start;
-       pci_read_config_dword(pdev, where, &reg);
-       reg = ((reg & size) |
-              (((u32)(res->start - root->start)) & ~size));
-       if (resource == PCI_ROM_RESOURCE) {
-               reg |= PCI_ROM_ADDRESS_ENABLE;
-               res->flags |= IORESOURCE_ROM_ENABLE;
-       }
-       pci_write_config_dword(pdev, where, reg);
-
-       /* This knows that the upper 32-bits of the address
-        * must be zero.  Our PCI common layer enforces this.
-        */
-       if (is_64bit)
-               pci_write_config_dword(pdev, where + 4, 0);
-}
-
-static void pci_sun4v_resource_adjust(struct pci_dev *pdev,
-                                     struct resource *res,
-                                     struct resource *root)
-{
-       res->start += root->start;
-       res->end += root->start;
-}
-
-/* Use ranges property to determine where PCI MEM, I/O, and Config
- * space are for this PCI bus module.
- */
-static void pci_sun4v_determine_mem_io_space(struct pci_pbm_info *pbm)
-{
-       int i, saw_mem, saw_io;
-
-       saw_mem = saw_io = 0;
-       for (i = 0; i < pbm->num_pbm_ranges; i++) {
-               struct linux_prom_pci_ranges *pr = &pbm->pbm_ranges[i];
-               unsigned long a;
-               int type;
-
-               type = (pr->child_phys_hi >> 24) & 0x3;
-               a = (((unsigned long)pr->parent_phys_hi << 32UL) |
-                    ((unsigned long)pr->parent_phys_lo  <<  0UL));
-
-               switch (type) {
-               case 1:
-                       /* 16-bit IO space, 16MB */
-                       pbm->io_space.start = a;
-                       pbm->io_space.end = a + ((16UL*1024UL*1024UL) - 1UL);
-                       pbm->io_space.flags = IORESOURCE_IO;
-                       saw_io = 1;
-                       break;
-
-               case 2:
-                       /* 32-bit MEM space, 2GB */
-                       pbm->mem_space.start = a;
-                       pbm->mem_space.end = a + (0x80000000UL - 1UL);
-                       pbm->mem_space.flags = IORESOURCE_MEM;
-                       saw_mem = 1;
-                       break;
-
-               case 3:
-                       /* XXX 64-bit MEM handling XXX */
-
-               default:
-                       break;
-               };
-       }
-
-       if (!saw_io || !saw_mem) {
-               prom_printf("%s: Fatal error, missing %s PBM range.\n",
-                           pbm->name,
-                           (!saw_io ? "IO" : "MEM"));
-               prom_halt();
-       }
-
-       printk("%s: PCI IO[%lx] MEM[%lx]\n",
-              pbm->name,
-              pbm->io_space.start,
-              pbm->mem_space.start);
-}
-
-static void pbm_register_toplevel_resources(struct pci_controller_info *p,
-                                           struct pci_pbm_info *pbm)
-{
-       pbm->io_space.name = pbm->mem_space.name = pbm->name;
-
-       request_resource(&ioport_resource, &pbm->io_space);
-       request_resource(&iomem_resource, &pbm->mem_space);
-       pci_register_legacy_regions(&pbm->io_space,
-                                   &pbm->mem_space);
-}
-
 static unsigned long probe_existing_entries(struct pci_pbm_info *pbm,
-                                           struct pci_iommu *iommu)
+                                           struct iommu *iommu)
 {
-       struct pci_iommu_arena *arena = &iommu->arena;
+       struct iommu_arena *arena = &iommu->arena;
        unsigned long i, cnt = 0;
        u32 devhandle;
 
@@ -847,7 +734,7 @@ static unsigned long probe_existing_entries(struct pci_pbm_info *pbm,
 
 static void pci_sun4v_iommu_init(struct pci_pbm_info *pbm)
 {
-       struct pci_iommu *iommu = pbm->iommu;
+       struct iommu *iommu = pbm->iommu;
        struct property *prop;
        unsigned long num_tsb_entries, sz;
        u32 vdma[2], dma_mask, dma_offset;
@@ -1282,8 +1169,6 @@ static int pci_sun4v_setup_msi_irq(unsigned int *virt_irq_p,
        if (!devino)
                goto out_err;
 
-       set_irq_msi(*virt_irq_p, entry);
-
        msiqid = ((devino - pbm->msiq_first_devino) +
                  pbm->msiq_first);
 
@@ -1317,6 +1202,8 @@ static int pci_sun4v_setup_msi_irq(unsigned int *virt_irq_p,
                msg.address_lo = pbm->msi32_start;
        }
        msg.data = msi_num;
+
+       set_irq_msi(*virt_irq_p, entry);
        write_msi_msg(*virt_irq_p, &msg);
 
        irq_install_pre_handler(*virt_irq_p,
@@ -1367,8 +1254,6 @@ static void pci_sun4v_msi_init(struct pci_pbm_info *pbm)
 static void pci_sun4v_pbm_init(struct pci_controller_info *p, struct device_node *dp, u32 devhandle)
 {
        struct pci_pbm_info *pbm;
-       struct property *prop;
-       int len, i;
 
        if (devhandle & 0x40)
                pbm = &p->pbm_B;
@@ -1377,7 +1262,6 @@ static void pci_sun4v_pbm_init(struct pci_controller_info *p, struct device_node
 
        pbm->parent = p;
        pbm->prom_node = dp;
-       pbm->pci_first_slot = 1;
 
        pbm->devhandle = devhandle;
 
@@ -1385,27 +1269,7 @@ static void pci_sun4v_pbm_init(struct pci_controller_info *p, struct device_node
 
        printk("%s: SUN4V PCI Bus Module\n", pbm->name);
 
-       prop = of_find_property(dp, "ranges", &len);
-       pbm->pbm_ranges = prop->value;
-       pbm->num_pbm_ranges =
-               (len / sizeof(struct linux_prom_pci_ranges));
-
-       /* Mask out the top 8 bits of the ranges, leaving the real
-        * physical address.
-        */
-       for (i = 0; i < pbm->num_pbm_ranges; i++)
-               pbm->pbm_ranges[i].parent_phys_hi &= 0x0fffffff;
-
-       pci_sun4v_determine_mem_io_space(pbm);
-       pbm_register_toplevel_resources(p, pbm);
-
-       prop = of_find_property(dp, "interrupt-map", &len);
-       pbm->pbm_intmap = prop->value;
-       pbm->num_pbm_intmap =
-               (len / sizeof(struct linux_prom_pci_intmap));
-
-       prop = of_find_property(dp, "interrupt-map-mask", NULL);
-       pbm->pbm_intmask = prop->value;
+       pci_determine_mem_io_space(pbm);
 
        pci_sun4v_get_bus_range(pbm);
        pci_sun4v_iommu_init(pbm);
@@ -1415,7 +1279,7 @@ static void pci_sun4v_pbm_init(struct pci_controller_info *p, struct device_node
 void sun4v_pci_init(struct device_node *dp, char *model_name)
 {
        struct pci_controller_info *p;
-       struct pci_iommu *iommu;
+       struct iommu *iommu;
        struct property *prop;
        struct linux_prom64_registers *regs;
        u32 devhandle;
@@ -1455,13 +1319,13 @@ void sun4v_pci_init(struct device_node *dp, char *model_name)
        if (!p)
                goto fatal_memory_error;
 
-       iommu = kzalloc(sizeof(struct pci_iommu), GFP_ATOMIC);
+       iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
        if (!iommu)
                goto fatal_memory_error;
 
        p->pbm_A.iommu = iommu;
 
-       iommu = kzalloc(sizeof(struct pci_iommu), GFP_ATOMIC);
+       iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
        if (!iommu)
                goto fatal_memory_error;
 
@@ -1471,11 +1335,8 @@ void sun4v_pci_init(struct device_node *dp, char *model_name)
        pci_controller_root = p;
 
        p->index = pci_num_controllers++;
-       p->pbms_same_domain = 0;
 
        p->scan_bus = pci_sun4v_scan_bus;
-       p->base_address_update = pci_sun4v_base_address_update;
-       p->resource_adjust = pci_sun4v_resource_adjust;
 #ifdef CONFIG_PCI_MSI
        p->setup_msi_irq = pci_sun4v_setup_msi_irq;
        p->teardown_msi_irq = pci_sun4v_teardown_msi_irq;