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/1e83b89b9ada
branches:  trunk
changeset: 746836:1e83b89b9ada
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Fri Aug 21 03:56:58 2009 +0000

description:
Use bus_dmamem_common.

diffstat:

 sys/arch/hpcmips/conf/files.hpcmips           |    4 +-
 sys/arch/hpcmips/hpcmips/bus_dma.c            |  143 ++----------------------
 sys/arch/mipsco/conf/files.mipsco             |    4 +-
 sys/arch/mipsco/mipsco/bus_dma.c              |  148 ++-----------------------
 sys/arch/newsmips/conf/files.newsmips         |    4 +-
 sys/arch/newsmips/newsmips/bus.c              |  148 +++----------------------
 sys/arch/playstation2/conf/files.playstation2 |    3 +-
 sys/arch/playstation2/playstation2/bus_dma.c  |  148 +++----------------------
 sys/arch/pmax/conf/files.pmax                 |    4 +-
 sys/arch/pmax/pmax/bus_dma.c                  |  147 ++----------------------
 10 files changed, 101 insertions(+), 652 deletions(-)

diffs (truncated from 1184 to 300 lines):

diff -r 7dd600edcf27 -r 1e83b89b9ada sys/arch/hpcmips/conf/files.hpcmips
--- a/sys/arch/hpcmips/conf/files.hpcmips       Fri Aug 21 03:45:10 2009 +0000
+++ b/sys/arch/hpcmips/conf/files.hpcmips       Fri Aug 21 03:56:58 2009 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.hpcmips,v 1.102 2008/02/20 21:43:34 drochner Exp $
+#      $NetBSD: files.hpcmips,v 1.103 2009/08/21 03:56:58 thorpej Exp $
 
 # maxpartitions must be first item in files.${ARCH}.
 maxpartitions 8
@@ -60,6 +60,8 @@
 file   arch/hpcmips/hpcmips/machdep.c
 file   arch/hpcmips/hpcmips/mainbus.c
 
+file   common/bus_dma/bus_dmamem_common.c
+
 file   dev/kloader.c                           kloader
 file   arch/hpcmips/hpcmips/kloader_machdep.c  kloader
 file   arch/hpcmips/hpcmips/kloader_vr41.S     vr41xx & kloader
diff -r 7dd600edcf27 -r 1e83b89b9ada sys/arch/hpcmips/hpcmips/bus_dma.c
--- a/sys/arch/hpcmips/hpcmips/bus_dma.c        Fri Aug 21 03:45:10 2009 +0000
+++ b/sys/arch/hpcmips/hpcmips/bus_dma.c        Fri Aug 21 03:56:58 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bus_dma.c,v 1.33 2009/03/18 16:00:12 cegger Exp $      */
+/*     $NetBSD: bus_dma.c,v 1.34 2009/08/21 03:56:58 thorpej Exp $     */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.33 2009/03/18 16:00:12 cegger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.34 2009/08/21 03:56:58 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -44,6 +44,8 @@
 #include <machine/bus.h>
 #include <machine/bus_dma_hpcmips.h>
 
+#include <common/bus_dma/bus_dmamem_common.h>
+
 static int _hpcmips_bd_map_load_buffer(bus_dmamap_t, void *, bus_size_t,
     struct vmspace *, int, vaddr_t *, int *, int);
 
@@ -531,59 +533,16 @@
     bus_dma_segment_t *segs, int nsegs, int *rsegs,
     int flags, paddr_t low, paddr_t high)
 {
-       vaddr_t curaddr, lastaddr;
-       struct vm_page *m;
-       struct pglist mlist;
-       int curseg, error;
 #ifdef DIAGNOSTIC
        extern paddr_t avail_start, avail_end;          /* XXX */
 
        high = high<(avail_end - PAGE_SIZE)? high: (avail_end - PAGE_SIZE);
        low = low>avail_start? low: avail_start;
 #endif
-       /* Always round the size. */
-       size = round_page(size);
 
-       /*
-        * Allocate pages from the VM system.
-        */
-       error = uvm_pglistalloc(size, low, 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 < low || curaddr >= high) {
-                       printf("uvm_pglistalloc returned non-sensical"
-                           " address 0x%lx\n", curaddr);
-                       panic("_hpcmips_bd_mem_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,
+                                              low, high));
 }
 
 /*
@@ -593,25 +552,8 @@
 void
 _hpcmips_bd_mem_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);
 }
 
 /*
@@ -622,11 +564,6 @@
 _hpcmips_bd_mem_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;
 
        /*
         * If we're only mapping 1 segment, use KSEG0 or KSEG1, to avoid
@@ -640,31 +577,8 @@
                return (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("_hpcmips_bd_mem_map: size botch");
-                       pmap_enter(pmap_kernel(), va, addr,
-                           VM_PROT_READ | VM_PROT_WRITE,
-                           VM_PROT_READ | VM_PROT_WRITE | PMAP_WIRED);
-
-                       /* XXX Do something about COHERENT here. */
-               }
-       }
-       pmap_update(pmap_kernel());
-
-       return (0);
+       /* XXX BUS_DMA_COHERENT */
+       return (_bus_dmamem_map_common(t, segs, nsegs, size, kvap, flags, 0));
 }
 
 /*
@@ -675,11 +589,6 @@
 _hpcmips_bd_mem_unmap(bus_dma_tag_t t, void *kva, size_t size)
 {
 
-#ifdef DIAGNOSTIC
-       if ((u_long)kva & PGOFSET)
-               panic("_hpcmips_bd_mem_unmap");
-#endif
-
        /*
         * Nothing to do if we mapped it with KSEG0 or KSEG1 (i.e.
         * not in KSEG2).
@@ -688,10 +597,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);
 }
 
 /*
@@ -702,26 +608,11 @@
 _hpcmips_bd_mem_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("_hpcmips_bd_mem_mmap: offset unaligned");
-               if (segs[i].ds_addr & PGOFSET)
-                       panic("_hpcmips_bd_mem_mmap: segment unaligned");
-               if (segs[i].ds_len & PGOFSET)
-                       panic("_hpcmips_bd_mem_mmap: segment size not multiple"
-                           " of page size");
-#endif
-               if (off >= segs[i].ds_len) {
-                       off -= segs[i].ds_len;
-                       continue;
-               }
-
-               return (mips_btop((char *)segs[i].ds_addr + off));
-       }
-
-       /* Page not found. */
-       return (-1);
+       rv = _bus_dmamem_mmap_common(t, segs, nsegs, off, prot, flags);
+       if (rv == (bus_addr_t)-1)
+               return (-1);
+       
+       return (mips_btop((char *)rv));
 }
diff -r 7dd600edcf27 -r 1e83b89b9ada sys/arch/mipsco/conf/files.mipsco
--- a/sys/arch/mipsco/conf/files.mipsco Fri Aug 21 03:45:10 2009 +0000
+++ b/sys/arch/mipsco/conf/files.mipsco Fri Aug 21 03:56:58 2009 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.mipsco,v 1.13 2006/09/01 13:28:17 cube Exp $
+#      $NetBSD: files.mipsco,v 1.14 2009/08/21 04:00:56 thorpej Exp $
 
 #  MIPS Computer Corp -specific configuration info
 
@@ -61,6 +61,8 @@
 file arch/mipsco/mipsco/prom.c
 file dev/cons.c
 
+file common/bus_dma/bus_dmamem_common.c
+
 # Memory Disk
 file dev/md_root.c                     memory_disk_hooks
 
diff -r 7dd600edcf27 -r 1e83b89b9ada sys/arch/mipsco/mipsco/bus_dma.c
--- a/sys/arch/mipsco/mipsco/bus_dma.c  Fri Aug 21 03:45:10 2009 +0000
+++ b/sys/arch/mipsco/mipsco/bus_dma.c  Fri Aug 21 03:56:58 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bus_dma.c,v 1.24 2009/03/14 21:04:12 dsl Exp $ */
+/*     $NetBSD: bus_dma.c,v 1.25 2009/08/21 04:00:57 thorpej Exp $     */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.24 2009/03/14 21:04:12 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.25 2009/08/21 04:00:57 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -44,6 +44,8 @@
 #define _MIPSCO_BUS_DMA_PRIVATE
 #include <machine/bus.h>
 
+#include <common/bus_dma/bus_dmamem_common.h>
+
 #include <mips/cache.h>
 
 paddr_t        kvtophys(vaddr_t);      /* XXX */
@@ -510,58 +512,10 @@
        paddr_t low;
        paddr_t high;
 {
-       paddr_t curaddr, lastaddr;
-       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.
-        */



Home | Main Index | Thread Index | Old Index