Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/alpha Simplify the SGMAP code a bit, and move SGVA ...



details:   https://anonhg.NetBSD.org/src/rev/fc1e6898ce77
branches:  trunk
changeset: 512910:fc1e6898ce77
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Thu Jul 19 04:27:37 2001 +0000

description:
Simplify the SGMAP code a bit, and move SGVA allocation out of a
common routine into the individual load routines, since each load
routine needs to muddle with the "internals" of this operation.

Add a `prefetch threshold' member to the bus_dma_tag_t, so that
eventually we can determine whether or not to allocate a spill
page on a per-mapping basis.

diffstat:

 sys/arch/alpha/common/sgmap_common.c  |   85 +------------
 sys/arch/alpha/common/sgmap_typedep.c |  219 +++++++++++++--------------------
 sys/arch/alpha/common/sgmapvar.h      |   22 +---
 sys/arch/alpha/include/bus.h          |   22 +-
 4 files changed, 107 insertions(+), 241 deletions(-)

diffs (truncated from 533 to 300 lines):

diff -r 3d4c4ef56ae4 -r fc1e6898ce77 sys/arch/alpha/common/sgmap_common.c
--- a/sys/arch/alpha/common/sgmap_common.c      Thu Jul 19 01:46:15 2001 +0000
+++ b/sys/arch/alpha/common/sgmap_common.c      Thu Jul 19 04:27:37 2001 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: sgmap_common.c,v 1.17 2001/07/12 23:25:40 thorpej Exp $ */
+/* $NetBSD: sgmap_common.c,v 1.18 2001/07/19 04:27:37 thorpej Exp $ */
 
 /*-
- * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
+ * Copyright (c) 1997, 1998, 2001 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -39,7 +39,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: sgmap_common.c,v 1.17 2001/07/12 23:25:40 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sgmap_common.c,v 1.18 2001/07/19 04:27:37 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -143,78 +143,6 @@
 }
 
 int
-alpha_sgmap_alloc(bus_dmamap_t map, bus_size_t origlen,
-    struct alpha_sgmap *sgmap, int flags)
-{
-       int error;
-       bus_size_t len = origlen, boundary, alignment;
-
-#ifdef DIAGNOSTIC
-       if (map->_dm_flags & DMAMAP_HAS_SGMAP)
-               panic("alpha_sgmap_alloc: already have sgva space");
-#endif
-       /*
-        * Add a range for spill page.
-        */
-       len += NBPG;
-
-       /*
-        * And add an additional amount in case of ALLOCNOW.
-        */
-       if (flags & BUS_DMA_ALLOCNOW)
-               len += NBPG;
-
-       map->_dm_sgvalen = round_page(len);
-
-       /*
-        * ARGH! If the addition of spill pages bumped us over our
-        * boundary, we have to 2x the boundary limit.
-        */
-       boundary = map->_dm_boundary;
-       if (boundary && boundary < map->_dm_sgvalen) {
-               alignment = boundary;
-               do {
-                       boundary <<= 1;
-               } while (boundary < map->_dm_sgvalen);
-       } else
-               alignment = NBPG;
-#if 0
-       printf("len %x -> %x, _dm_sgvalen %x _dm_boundary %x boundary %x -> ",
-           origlen, len, map->_dm_sgvalen, map->_dm_boundary, boundary);
-#endif
-
-       error = extent_alloc(sgmap->aps_ex, map->_dm_sgvalen, alignment,
-           boundary, (flags & BUS_DMA_NOWAIT) ? EX_NOWAIT : EX_WAITOK,
-           &map->_dm_sgva);
-#if 0
-       printf("error %d _dm_sgva %x\n", error, map->_dm_sgva);
-#endif
-
-       if (error == 0)
-               map->_dm_flags |= DMAMAP_HAS_SGMAP;
-       else
-               map->_dm_flags &= ~DMAMAP_HAS_SGMAP;
-       
-       return (error);
-}
-
-void
-alpha_sgmap_free(bus_dmamap_t map, struct alpha_sgmap *sgmap)
-{
-
-#ifdef DIAGNOSTIC
-       if ((map->_dm_flags & DMAMAP_HAS_SGMAP) == 0)
-               panic("alpha_sgmap_free: no sgva space to free");
-#endif
-
-       if (extent_free(sgmap->aps_ex, map->_dm_sgva, map->_dm_sgvalen,
-           EX_NOWAIT))
-               panic("alpha_sgmap_free");
-
-       map->_dm_flags &= ~DMAMAP_HAS_SGMAP;
-}
-
-int
 alpha_sgmap_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments,
     bus_size_t maxsegsz, bus_size_t boundary, int flags, bus_dmamap_t *dmamp)
 {
@@ -226,9 +154,7 @@
        if (error)
                return (error);
 
-       if (flags & BUS_DMA_ALLOCNOW)
-               error = alpha_sgmap_alloc(map, round_page(size),
-                   t->_sgmap, flags);
+       /* XXX BUS_DMA_ALLOCNOW */
 
        if (error == 0)
                *dmamp = map;
@@ -242,8 +168,7 @@
 alpha_sgmap_dmamap_destroy(bus_dma_tag_t t, bus_dmamap_t map)
 {
 
-       if (map->_dm_flags & DMAMAP_HAS_SGMAP)
-               alpha_sgmap_free(map, t->_sgmap);
+       KASSERT(map->dm_mapsize == 0);
 
        _bus_dmamap_destroy(t, map);
 }
diff -r 3d4c4ef56ae4 -r fc1e6898ce77 sys/arch/alpha/common/sgmap_typedep.c
--- a/sys/arch/alpha/common/sgmap_typedep.c     Thu Jul 19 01:46:15 2001 +0000
+++ b/sys/arch/alpha/common/sgmap_typedep.c     Thu Jul 19 04:27:37 2001 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: sgmap_typedep.c,v 1.16 2001/07/12 23:35:43 thorpej Exp $ */
+/* $NetBSD: sgmap_typedep.c,v 1.17 2001/07/19 04:27:37 thorpej Exp $ */
 
 /*-
- * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
+ * Copyright (c) 1997, 1998, 2001 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -37,24 +37,10 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-__KERNEL_RCSID(0, "$NetBSD: sgmap_typedep.c,v 1.16 2001/07/12 23:35:43 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sgmap_typedep.c,v 1.17 2001/07/19 04:27:37 thorpej Exp $");
 
 #include "opt_ddb.h"
 
-#ifdef SGMAP_LOG
-
-#ifndef SGMAP_LOGSIZE
-#define        SGMAP_LOGSIZE   4096
-#endif
-
-struct sgmap_log_entry __C(SGMAP_TYPE,_log)[SGMAP_LOGSIZE];
-int                    __C(SGMAP_TYPE,_log_next);
-int                    __C(SGMAP_TYPE,_log_last);
-u_long                 __C(SGMAP_TYPE,_log_loads);
-u_long                 __C(SGMAP_TYPE,_log_unloads);
-
-#endif /* SGMAP_LOG */
-
 #ifdef SGMAP_DEBUG
 int                    __C(SGMAP_TYPE,_debug) = 0;
 #endif
@@ -76,13 +62,10 @@
 {
        vaddr_t endva, va = (vaddr_t)buf;
        paddr_t pa;
-       bus_addr_t dmaoffset;
-       bus_size_t dmalen;
+       bus_addr_t dmaoffset, sgva;
+       bus_size_t sgvalen, boundary, alignment;
        SGMAP_PTE_TYPE *pte, *page_table = sgmap->aps_pt;
-       int pteidx, error;
-#ifdef SGMAP_LOG
-       struct sgmap_log_entry sl;
-#endif
+       int pteidx, error, spill;
 
        /*
         * Initialize the spill page PTE if that hasn't already been done.
@@ -104,65 +87,70 @@
         * transfer length.
         */
        dmaoffset = ((u_long)buf) & PGOFSET;
-       dmalen = buflen;
 
 #ifdef SGMAP_DEBUG
        if (__C(SGMAP_TYPE,_debug)) {
                printf("sgmap_load: ----- buf = %p -----\n", buf);
-               printf("sgmap_load: dmaoffset = 0x%lx, dmalen = 0x%lx\n",
-                   dmaoffset, dmalen);
-       }
-#endif
-
-#ifdef SGMAP_LOG
-       if (panicstr == NULL) {
-               sl.sl_op = 1;
-               sl.sl_sgmap = sgmap;
-               sl.sl_origbuf = buf;
-               sl.sl_pgoffset = dmaoffset;
-               sl.sl_origlen = dmalen;
+               printf("sgmap_load: dmaoffset = 0x%lx, buflen = 0x%lx\n",
+                   dmaoffset, buflen);
        }
 #endif
 
        /*
         * Allocate the necessary virtual address space for the
         * mapping.  Round the size, since we deal with whole pages.
-        *
-        * alpha_sgmap_alloc will deal with the appropriate spill page
-        * allocations.
-        *
         */
+
+       /* XXX Always allocate a spill page for now. */
+       spill = 1;
+
        endva = round_page(va + buflen);
        va = trunc_page(va);
-       if ((map->_dm_flags & DMAMAP_HAS_SGMAP) == 0) {
-               error = alpha_sgmap_alloc(map, (endva - va), sgmap, flags);
-               if (error)
-                       return (error);
+
+       boundary = map->_dm_boundary;
+       alignment = NBPG;
+
+       sgvalen = (endva - va);
+       if (spill) {
+               sgvalen += NBPG;
+
+               /*
+                * ARGH!  If the addition of the spill page bumped us
+                * over our boundary, we have to 2x the boundary limit.
+                */
+               if (boundary && boundary < sgvalen) {
+                       alignment = boundary;
+                       do {
+                               boundary <<= 1;
+                       } while (boundary < sgvalen);
+               }
        }
 
-       pteidx = map->_dm_sgva >> PGSHIFT;
+#if 0
+       printf("len 0x%lx -> 0x%lx, boundary 0x%lx -> 0x%lx -> ",
+           (endva - va), sgvalen, map->_dm_boundary, boundary);
+#endif
+
+       error = extent_alloc(sgmap->aps_ex, sgvalen, alignment, boundary,
+           (flags & BUS_DMA_NOWAIT) ? EX_NOWAIT : EX_WAITOK, &sgva);
+
+#if 0
+       printf("error %d sgva 0x%lx\n", error, sgva);
+#endif
+
+       pteidx = sgva >> SGMAP_ADDR_PTEIDX_SHIFT;
        pte = &page_table[pteidx * SGMAP_PTE_SPACING];
 
 #ifdef SGMAP_DEBUG
        if (__C(SGMAP_TYPE,_debug))
                printf("sgmap_load: sgva = 0x%lx, pteidx = %d, "
-                   "pte = %p (pt = %p)\n", map->_dm_sgva, pteidx, pte,
+                   "pte = %p (pt = %p)\n", sgva, pteidx, pte,
                    page_table);
 #endif
 
-       /*
-        * Generate the DMA address.
-        */
-       map->dm_segs[0].ds_addr = sgmap->aps_wbase |
-           (pteidx << SGMAP_ADDR_PTEIDX_SHIFT) | dmaoffset;
-       map->dm_segs[0].ds_len = dmalen;
-
-#ifdef SGMAP_LOG
-       if (panicstr == NULL) {
-               sl.sl_sgva = map->_dm_sgva;
-               sl.sl_dmaaddr = map->dm_segs[0].ds_addr;
-       }
-#endif
+       /* Generate the DMA address. */
+       map->dm_segs[0].ds_addr = sgmap->aps_wbase | sgva | dmaoffset;
+       map->dm_segs[0].ds_len = buflen;
 
 #ifdef SGMAP_DEBUG
        if (__C(SGMAP_TYPE,_debug))
@@ -172,24 +160,16 @@
                    map->dm_segs[0].ds_addr);
 #endif
 
-       map->_dm_pteidx = pteidx;
-       map->_dm_ptecnt = 0;
-
        for (; va < endva; va += NBPG, pteidx++,
-               pte = &page_table[pteidx * SGMAP_PTE_SPACING],
-               map->_dm_ptecnt++) {
-               /*
-                * Get the physical address for this segment.
-                */
+            pte = &page_table[pteidx * SGMAP_PTE_SPACING]) {
+               /* Get the physical address for this segment. */



Home | Main Index | Thread Index | Old Index