Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[cascardo/linux.git] / arch / sparc64 / kernel / pci_sun4v.c
index ce0417e..1ccf4c9 100644 (file)
@@ -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,55 +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 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;
 
@@ -773,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;
@@ -1208,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);
 
@@ -1243,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,
@@ -1301,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;
 
@@ -1319,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;
@@ -1359,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;
 
@@ -1375,10 +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;
 #ifdef CONFIG_PCI_MSI
        p->setup_msi_irq = pci_sun4v_setup_msi_irq;
        p->teardown_msi_irq = pci_sun4v_teardown_msi_irq;