Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/sparc/sparc * Fix thinko in offset computations.



details:   https://anonhg.NetBSD.org/src/rev/a07f2bc514e3
branches:  trunk
changeset: 485983:a07f2bc514e3
user:      pk <pk%NetBSD.org@localhost>
date:      Wed May 10 11:17:50 2000 +0000

description:
* Fix thinko in offset computations.
* Add DIAGNOSTIC checks.

diffstat:

 sys/arch/sparc/sparc/iommu.c   |  17 ++++++++++-------
 sys/arch/sparc/sparc/machdep.c |  14 ++++++++++++--
 2 files changed, 22 insertions(+), 9 deletions(-)

diffs (99 lines):

diff -r e4835dbeb231 -r a07f2bc514e3 sys/arch/sparc/sparc/iommu.c
--- a/sys/arch/sparc/sparc/iommu.c      Wed May 10 11:15:32 2000 +0000
+++ b/sys/arch/sparc/sparc/iommu.c      Wed May 10 11:17:50 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iommu.c,v 1.39 2000/05/09 22:39:35 pk Exp $ */
+/*     $NetBSD: iommu.c,v 1.40 2000/05/10 11:17:50 pk Exp $ */
 
 /*
  * Copyright (c) 1996
@@ -596,6 +596,7 @@
        bus_addr_t dva;
        bus_size_t sgsize;
        struct pglist *mlist;
+       int pagesz = PAGE_SIZE;
        int error;
 
        map->dm_nsegs = 0;
@@ -632,8 +633,8 @@
                        panic("iommu_dmamap_load_raw: size botch");
                pa = VM_PAGE_TO_PHYS(m);
                iommu_enter(dva, pa);
-               dva += PAGE_SIZE;
-               sgsize -= PAGE_SIZE;
+               dva += pagesz;
+               sgsize -= pagesz;
        }
 
        map->dm_nsegs = 1;
@@ -710,12 +711,13 @@
        struct pglist *mlist;
        int cbit;
        u_long align;
+       int pagesz = PAGE_SIZE;
 
        if (nsegs != 1)
                panic("iommu_dmamem_map: nsegs = %d", nsegs);
 
        cbit = has_iocache ? 0 : PMAP_NC;
-       align = dvma_cachealign ? dvma_cachealign : PAGE_SIZE;
+       align = dvma_cachealign ? dvma_cachealign : pagesz;
 
        size = round_page(size);
 
@@ -724,7 +726,8 @@
         * iommu_dmamap_load_raw(), find a region of kernel virtual
         * addresses that can accomodate our aligment requirements.
         */
-       va = _bus_dma_valloc_skewed(size, 0, align, segs[0].ds_addr & -align);
+       va = _bus_dma_valloc_skewed(size, 0, align,
+                                   segs[0].ds_addr & (align - 1));
        if (va == 0)
                return (ENOMEM);
 
@@ -749,8 +752,8 @@
                        if (flags & BUS_DMA_COHERENT)
                                /* XXX */;
 #endif
-               va += PAGE_SIZE;
-               size -= PAGE_SIZE;
+               va += pagesz;
+               size -= pagesz;
        }
 
        return (0);
diff -r e4835dbeb231 -r a07f2bc514e3 sys/arch/sparc/sparc/machdep.c
--- a/sys/arch/sparc/sparc/machdep.c    Wed May 10 11:15:32 2000 +0000
+++ b/sys/arch/sparc/sparc/machdep.c    Wed May 10 11:17:50 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.161 2000/05/09 22:39:35 pk Exp $ */
+/*     $NetBSD: machdep.c,v 1.162 2000/05/10 11:17:50 pk Exp $ */
 
 /*-
  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@@ -1311,6 +1311,16 @@
         *      - `size' must be smaller than `boundary'
         */
 
+#ifdef DIAGNOSTIC
+       if ((size & PAGE_MASK) != 0)
+               panic("_bus_dma_valloc_skewed: invalid size %lx", size);
+       if ((align & PAGE_MASK) != 0)
+               panic("_bus_dma_valloc_skewed: invalid alignment %lx", align);
+       if (align < skew)
+               panic("_bus_dma_valloc_skewed: align %lx < skew %lx",
+                       align, skew);
+#endif
+
        /* XXX - Implement this! */
        if (boundary)
                panic("_bus_dma_valloc_skewed: not implemented");
@@ -1327,7 +1337,7 @@
         * Compute start of aligned region
         */
        va = sva;
-       va += (skew + align - va) & -align;
+       va += (skew + align - va) & (align - 1);
 
        /*
         * Return excess virtual addresses



Home | Main Index | Thread Index | Old Index