]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
[PATCH] SPARC64: Don't be picky about virtual-dma values on sun4v.
authorDavid Miller <davem@davemloft.net>
Thu, 7 Jun 2007 05:59:24 +0000 (22:59 -0700)
committerChris Wright <chrisw@sous-sol.org>
Mon, 11 Jun 2007 18:36:53 +0000 (11:36 -0700)
Handle arbitrary base and length values as long as they
are multiples of IO_PAGE_SIZE.

Bug found by Arun Kumar Rao.

Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
arch/sparc64/kernel/pci_sun4v.c

index ec22cd61ec8ce8eeab6689a6de6ff4d04efc948d..f6fd0733f144ab7c168c8b51510bcfadef378792 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/percpu.h>
 #include <linux/irq.h>
 #include <linux/msi.h>
+#include <linux/log2.h>
 
 #include <asm/pbm.h>
 #include <asm/iommu.h>
@@ -996,9 +997,8 @@ static void pci_sun4v_iommu_init(struct pci_pbm_info *pbm)
 {
        struct pci_iommu *iommu = pbm->iommu;
        struct property *prop;
-       unsigned long num_tsb_entries, sz;
+       unsigned long num_tsb_entries, sz, tsbsize;
        u32 vdma[2], dma_mask, dma_offset;
-       int tsbsize;
 
        prop = of_find_property(pbm->prom_node, "virtual-dma", NULL);
        if (prop) {
@@ -1012,31 +1012,15 @@ static void pci_sun4v_iommu_init(struct pci_pbm_info *pbm)
                vdma[1] = 0x80000000;
        }
 
-       dma_mask = vdma[0];
-       switch (vdma[1]) {
-               case 0x20000000:
-                       dma_mask |= 0x1fffffff;
-                       tsbsize = 64;
-                       break;
-
-               case 0x40000000:
-                       dma_mask |= 0x3fffffff;
-                       tsbsize = 128;
-                       break;
-
-               case 0x80000000:
-                       dma_mask |= 0x7fffffff;
-                       tsbsize = 256;
-                       break;
-
-               default:
-                       prom_printf("PCI-SUN4V: strange virtual-dma size.\n");
-                       prom_halt();
+       if ((vdma[0] | vdma[1]) & ~IO_PAGE_MASK) {
+               prom_printf("PCI-SUN4V: strange virtual-dma[%08x:%08x].\n",
+                           vdma[0], vdma[1]);
+               prom_halt();
        };
 
-       tsbsize *= (8 * 1024);
-
-       num_tsb_entries = tsbsize / sizeof(iopte_t);
+       dma_mask = (roundup_pow_of_two(vdma[1]) - 1UL);
+       num_tsb_entries = vdma[1] / IO_PAGE_SIZE;
+       tsbsize = num_tsb_entries * sizeof(iopte_t);
 
        dma_offset = vdma[0];
 
@@ -1047,7 +1031,7 @@ static void pci_sun4v_iommu_init(struct pci_pbm_info *pbm)
        iommu->dma_addr_mask = dma_mask;
 
        /* Allocate and initialize the free area map.  */
-       sz = num_tsb_entries / 8;
+       sz = (num_tsb_entries + 7) / 8;
        sz = (sz + 7UL) & ~7UL;
        iommu->arena.map = kzalloc(sz, GFP_KERNEL);
        if (!iommu->arena.map) {