Source-Changes-HG archive

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

[src/trunk]: src/sys/arch Use bus_dmamem_common.



details:   https://anonhg.NetBSD.org/src/rev/deebb73b5085
branches:  trunk
changeset: 746838:deebb73b5085
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Fri Aug 21 04:10:33 2009 +0000

description:
Use bus_dmamem_common.

diffstat:

 sys/arch/sgimips/conf/files.sgimips |    4 +-
 sys/arch/sgimips/sgimips/bus.c      |  122 ++++--------------------------
 sys/arch/x68k/conf/files.x68k       |    4 +-
 sys/arch/x68k/x68k/bus.c            |  142 ++++-------------------------------
 4 files changed, 42 insertions(+), 230 deletions(-)

diffs (truncated from 419 to 300 lines):

diff -r 4ab896e92331 -r deebb73b5085 sys/arch/sgimips/conf/files.sgimips
--- a/sys/arch/sgimips/conf/files.sgimips       Fri Aug 21 04:09:41 2009 +0000
+++ b/sys/arch/sgimips/conf/files.sgimips       Fri Aug 21 04:10:33 2009 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.sgimips,v 1.48 2009/02/12 06:33:56 rumble Exp $
+#      $NetBSD: files.sgimips,v 1.49 2009/08/21 04:10:33 thorpej Exp $
 
 maxpartitions 16
 
@@ -25,6 +25,8 @@
 file arch/sgimips/sgimips/disksubr.c
 file arch/sgimips/sgimips/machdep.c
 
+file common/bus_dma/bus_dmamem_common.c
+
 file arch/mips/mips/mips3_clock.c      mips3
 file arch/mips/mips/mips3_clockintr.c  mips3
 
diff -r 4ab896e92331 -r deebb73b5085 sys/arch/sgimips/sgimips/bus.c
--- a/sys/arch/sgimips/sgimips/bus.c    Fri Aug 21 04:09:41 2009 +0000
+++ b/sys/arch/sgimips/sgimips/bus.c    Fri Aug 21 04:10:33 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bus.c,v 1.56 2009/02/12 06:33:57 rumble Exp $  */
+/*     $NetBSD: bus.c,v 1.57 2009/08/21 04:10:33 thorpej Exp $ */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bus.c,v 1.56 2009/02/12 06:33:57 rumble Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus.c,v 1.57 2009/08/21 04:10:33 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -48,6 +48,8 @@
 #include <machine/cpu.h>
 #include <machine/machtype.h>
 
+#include <common/bus_dma/bus_dmamem_common.h>
+
 #include <uvm/uvm_extern.h>
 
 #include <mips/cpuregs.h>
@@ -1082,57 +1084,11 @@
                  int nsegs, int *rsegs, int flags)
 {
        extern paddr_t avail_start, avail_end;
-       vaddr_t curaddr, lastaddr;
-       psize_t high;
-       struct vm_page *m;
-       struct pglist mlist;
-       int curseg, error;
 
-       /* Always round the size. */
-       size = round_page(size);
-
-       high = avail_end - PAGE_SIZE;
-
-       /*
-        * Allocate pages from the VM system.
-        */
-       error = uvm_pglistalloc(size, avail_start, high, alignment, boundary,
-           &mlist, nsegs, (flags & BUS_DMA_NOWAIT) == 0);
-       if (error)
-               return error;
-
-       /*
-        * Compute the location, size, and number of segments actually
-        * returned by the VM code.
-        */
-       m = mlist.tqh_first;
-       curseg = 0;
-       lastaddr = segs[curseg].ds_addr = VM_PAGE_TO_PHYS(m);
-       segs[curseg].ds_len = PAGE_SIZE;
-       m = m->pageq.queue.tqe_next;
-
-       for (; m != NULL; m = m->pageq.queue.tqe_next) {
-               curaddr = VM_PAGE_TO_PHYS(m);
-#ifdef DIAGNOSTIC
-               if (curaddr < avail_start || curaddr >= high) {
-                       printf("uvm_pglistalloc returned non-sensical"
-                           " address 0x%lx\n", curaddr);
-                       panic("_bus_dmamem_alloc");
-               }
-#endif
-               if (curaddr == (lastaddr + PAGE_SIZE))
-                       segs[curseg].ds_len += PAGE_SIZE;
-               else {
-                       curseg++;
-                       segs[curseg].ds_addr = curaddr;
-                       segs[curseg].ds_len = PAGE_SIZE;
-               }
-               lastaddr = curaddr;
-       }
-
-       *rsegs = curseg + 1;
-
-       return 0;
+       return (_bus_dmamem_alloc_range_common(t, size, alignment, boundary,
+                                              segs, nsegs, rsegs, flags,
+                                              avail_start /*low*/,
+                                              avail_end - PAGE_SIZE /*high*/));
 }
 
 /*
@@ -1142,25 +1098,8 @@
 void
 _bus_dmamem_free(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs)
 {
-       struct vm_page *m;
-       bus_addr_t addr;
-       struct pglist mlist;
-       int curseg;
 
-       /*
-        * Build a list of pages to free back to the VM system.
-        */
-       TAILQ_INIT(&mlist);
-       for (curseg = 0; curseg < nsegs; curseg++) {
-               for (addr = segs[curseg].ds_addr;
-                   addr < (segs[curseg].ds_addr + segs[curseg].ds_len);
-                   addr += PAGE_SIZE) {
-                       m = PHYS_TO_VM_PAGE(addr);
-                       TAILQ_INSERT_TAIL(&mlist, m, pageq.queue);
-               }
-       }
-
-       uvm_pglistfree(&mlist);
+       _bus_dmamem_free_common(t, segs, nsegs);
 }
 
 /*
@@ -1229,11 +1168,6 @@
 _bus_dmamem_unmap(bus_dma_tag_t t, void *kva, size_t size)
 {
 
-#ifdef DIAGNOSTIC
-       if ((u_long)kva & PGOFSET)
-               panic("_bus_dmamem_unmap");
-#endif
-
        /*
         * Nothing to do if we mapped it with KSEG0 or KSEG1 (i.e.
         * not in KSEG2).
@@ -1242,10 +1176,7 @@
            kva < (void *)MIPS_KSEG2_START)
                return;
 
-       size = round_page(size);
-       pmap_remove(pmap_kernel(), (vaddr_t)kva, (vaddr_t)kva + size);
-       pmap_update(pmap_kernel());
-       uvm_km_free(kernel_map, (vaddr_t)kva, size, UVM_KMF_VAONLY);
+       _bus_dmamem_unmap_common(t, kva, size);
 }
 
 /*
@@ -1256,32 +1187,17 @@
 _bus_dmamem_mmap(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs,
                 off_t off, int prot, int flags)
 {
-       int i;
+       bus_addr_t rv;
 
-       for (i = 0; i < nsegs; i++) {
-#ifdef DIAGNOSTIC
-               if (off & PGOFSET)
-                       panic("_bus_dmamem_mmap: offset unaligned");
-               if (segs[i].ds_addr & PGOFSET)
-                       panic("_bus_dmamem_mmap: segment unaligned");
-               if (segs[i].ds_len & PGOFSET)
-                       panic("_bus_dmamem_mmap: segment size not multiple"
-                           " of page size");
+       rv = _bus_dmamem_mmap_common(t, segs, nsegs, off, prot, flags);
+       if (rv == (bus_addr_t)-1)
+               return (-1);
+       
+#if defined(_MIPS_PADDR_T_64BIT) || defined(_LP64)
+       return (mips_btop(rv | PMAP_NOCACHE));
+#else
+       return (mips_btop(rv));
 #endif
-               if (off >= segs[i].ds_len) {
-                       off -= segs[i].ds_len;
-                       continue;
-               }
-
-#if defined(_MIPS_PADDR_T_64BIT) || defined(_LP64)
-               return mips_btop((segs[i].ds_addr + off) | PMAP_NOCACHE);
-#else
-               return mips_btop(segs[i].ds_addr + off);
-#endif
-       }
-
-       /* Page not found. */
-       return -1;
 }
 
 paddr_t
diff -r 4ab896e92331 -r deebb73b5085 sys/arch/x68k/conf/files.x68k
--- a/sys/arch/x68k/conf/files.x68k     Fri Aug 21 04:09:41 2009 +0000
+++ b/sys/arch/x68k/conf/files.x68k     Fri Aug 21 04:10:33 2009 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.x68k,v 1.69 2008/12/21 09:20:40 isaki Exp $
+#      $NetBSD: files.x68k,v 1.70 2009/08/21 04:12:27 thorpej Exp $
 #
 # new style config file for x68k architecture
 #
@@ -43,6 +43,8 @@
 file   arch/m68k/m68k/sys_machdep.c
 file   arch/m68k/m68k/vm_machdep.c
 
+file   common/bus_dma/bus_dmamem_common.c
+
 file   dev/cons.c
 file   dev/cninit.c
 
diff -r 4ab896e92331 -r deebb73b5085 sys/arch/x68k/x68k/bus.c
--- a/sys/arch/x68k/x68k/bus.c  Fri Aug 21 04:09:41 2009 +0000
+++ b/sys/arch/x68k/x68k/bus.c  Fri Aug 21 04:10:33 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bus.c,v 1.33 2008/06/04 12:41:41 ad Exp $      */
+/*     $NetBSD: bus.c,v 1.34 2009/08/21 04:12:27 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bus.c,v 1.33 2008/06/04 12:41:41 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus.c,v 1.34 2009/08/21 04:12:27 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -51,6 +51,8 @@
 #include <m68k/cacheops.h>
 #include <machine/bus.h>
 
+#include <common/bus_dma/bus_dmamem_common.h>
+
 #if defined(M68040) || defined(M68060)
 static inline void dmasync_flush(bus_addr_t, bus_size_t);
 static inline void dmasync_inval(bus_addr_t, bus_size_t);
@@ -416,25 +418,8 @@
 void
 x68k_bus_dmamem_free(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs)
 {
-       struct vm_page *m;
-       bus_addr_t addr;
-       struct pglist mlist;
-       int curseg;
 
-       /*
-        * Build a list of pages to free back to the VM system.
-        */
-       TAILQ_INIT(&mlist);
-       for (curseg = 0; curseg < nsegs; curseg++) {
-               for (addr = segs[curseg].ds_addr;
-                   addr < (segs[curseg].ds_addr + segs[curseg].ds_len);
-                   addr += PAGE_SIZE) {
-                       m = PHYS_TO_VM_PAGE(addr);
-                       TAILQ_INSERT_TAIL(&mlist, m, pageq.queue);
-               }
-       }
-
-       uvm_pglistfree(&mlist);
+       _bus_dmamem_free_common(t, segs, nsegs);
 }
 
 /*
@@ -445,35 +430,9 @@
 x68k_bus_dmamem_map(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs,
     size_t size, void **kvap, int flags)
 {
-       vaddr_t va;
-       bus_addr_t addr;
-       int curseg;
-       const uvm_flag_t kmflags =
-           (flags & BUS_DMA_NOWAIT) != 0 ? UVM_KMF_NOWAIT : 0;
 
-       size = round_page(size);
-
-       va = uvm_km_alloc(kernel_map, size, 0, UVM_KMF_VAONLY | kmflags);
-
-       if (va == 0)
-               return (ENOMEM);
-
-       *kvap = (void *)va;
-
-       for (curseg = 0; curseg < nsegs; curseg++) {
-               for (addr = segs[curseg].ds_addr;
-                   addr < (segs[curseg].ds_addr + segs[curseg].ds_len);
-                   addr += PAGE_SIZE, va += PAGE_SIZE, size -= PAGE_SIZE) {
-                       if (size == 0)
-                               panic("x68k_bus_dmamem_map: size botch");
-                       pmap_enter(pmap_kernel(), va, addr,
-                           VM_PROT_READ | VM_PROT_WRITE,
-                           VM_PROT_READ | VM_PROT_WRITE | PMAP_WIRED);



Home | Main Index | Thread Index | Old Index