summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMarco Peereboom <marco@cvs.openbsd.org>2009-04-08 20:58:25 +0000
committerMarco Peereboom <marco@cvs.openbsd.org>2009-04-08 20:58:25 +0000
commit8238133246ae3851704cd0610f21634538e47b8f (patch)
tree087b8bba115496398e1b4ae5c935670b2e663006 /sys
parent9c942e72a6f27fe5bd9c18a6376056c5b8030e39 (diff)
Rever _raw change from dlg because it breaks iwn.
ok oga
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/amd64/amd64/bus_dma.c73
-rw-r--r--sys/arch/i386/i386/bus_dma.c73
2 files changed, 32 insertions, 114 deletions
diff --git a/sys/arch/amd64/amd64/bus_dma.c b/sys/arch/amd64/amd64/bus_dma.c
index d1627286da0..676eca4143f 100644
--- a/sys/arch/amd64/amd64/bus_dma.c
+++ b/sys/arch/amd64/amd64/bus_dma.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bus_dma.c,v 1.18 2009/04/04 13:48:55 dlg Exp $ */
+/* $OpenBSD: bus_dma.c,v 1.19 2009/04/08 20:58:24 marco Exp $ */
/* $NetBSD: bus_dma.c,v 1.3 2003/05/07 21:33:58 fvdl Exp $ */
/*-
@@ -308,68 +308,27 @@ int
_bus_dmamap_load_raw(bus_dma_tag_t t, bus_dmamap_t map, bus_dma_segment_t *segs,
int nsegs, bus_size_t size, int flags)
{
- bus_addr_t paddr, baddr, bmask, lastaddr = 0;
- bus_size_t plen, sgsize;
- int first = 1;
- int i, seg = 0;
-
if (nsegs > map->_dm_segcnt || size > map->_dm_size)
return (EINVAL);
- bmask = ~(map->_dm_boundary - 1);
-
- for (i = 0; i < nsegs; i++) {
- paddr = segs[i].ds_addr;
- plen = segs[i].ds_len;
-
- while (plen > 0) {
- /*
- * Compute the segment size, and adjust counts.
- */
- sgsize = PAGE_SIZE - ((u_long)paddr & PGOFSET);
- if (plen < sgsize)
- sgsize = plen;
-
- /*
- * Make sure we don't cross any boundaries.
- */
- if (map->_dm_boundary > 0) {
- baddr = (paddr + map->_dm_boundary) & bmask;
- if (sgsize > (baddr - paddr))
- sgsize = (baddr - paddr);
- }
-
- /*
- * Insert chunk into a segment, coalescing with
- * previous segment if possible.
- */
- if (first) {
- map->dm_segs[seg].ds_addr = paddr;
- map->dm_segs[seg].ds_len = sgsize;
- first = 0;
- } else {
- if (paddr == lastaddr &&
- (map->dm_segs[seg].ds_len + sgsize) <=
- map->_dm_maxsegsz &&
- (map->_dm_boundary == 0 ||
- (map->dm_segs[seg].ds_addr & bmask) ==
- (paddr & bmask)))
- map->dm_segs[seg].ds_len += sgsize;
- else {
- if (++seg >= map->_dm_segcnt)
- return (EINVAL);
- map->dm_segs[seg].ds_addr = paddr;
- map->dm_segs[seg].ds_len = sgsize;
- }
- }
-
- lastaddr = paddr + sgsize;
- paddr += sgsize;
- plen -= sgsize;
+ /*
+ * Make sure we don't cross any boundaries.
+ */
+ if (map->_dm_boundary) {
+ bus_addr_t bmask = ~(map->_dm_boundary - 1);
+ int i;
+
+ for (i = 0; i < nsegs; i++) {
+ if (segs[i].ds_len > map->_dm_maxsegsz)
+ return (EINVAL);
+ if ((segs[i].ds_addr & bmask) !=
+ ((segs[i].ds_addr + segs[i].ds_len - 1) & bmask))
+ return (EINVAL);
}
}
- map->dm_nsegs = seg + 1;
+ bcopy(segs, map->dm_segs, nsegs * sizeof(*segs));
+ map->dm_nsegs = nsegs;
return (0);
}
diff --git a/sys/arch/i386/i386/bus_dma.c b/sys/arch/i386/i386/bus_dma.c
index ebfa4198da5..188024b691f 100644
--- a/sys/arch/i386/i386/bus_dma.c
+++ b/sys/arch/i386/i386/bus_dma.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bus_dma.c,v 1.8 2009/04/04 14:07:22 dlg Exp $ */
+/* $OpenBSD: bus_dma.c,v 1.9 2009/04/08 20:58:24 marco Exp $ */
/*-
* Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -275,68 +275,27 @@ int
_bus_dmamap_load_raw(bus_dma_tag_t t, bus_dmamap_t map, bus_dma_segment_t *segs,
int nsegs, bus_size_t size, int flags)
{
- bus_addr_t paddr, baddr, bmask, lastaddr = 0;
- bus_size_t plen, sgsize;
- int first = 1;
- int i, seg = 0;
-
if (nsegs > map->_dm_segcnt || size > map->_dm_size)
return (EINVAL);
- bmask = ~(map->_dm_boundary - 1);
-
- for (i = 0; i < nsegs; i++) {
- paddr = segs[i].ds_addr;
- plen = segs[i].ds_len;
-
- while (plen > 0) {
- /*
- * Compute the segment size, and adjust counts.
- */
- sgsize = PAGE_SIZE - ((u_long)paddr & PGOFSET);
- if (plen < sgsize)
- sgsize = plen;
-
- /*
- * Make sure we don't cross any boundaries.
- */
- if (map->_dm_boundary > 0) {
- baddr = (paddr + map->_dm_boundary) & bmask;
- if (sgsize > (baddr - paddr))
- sgsize = (baddr - paddr);
- }
-
- /*
- * Insert chunk into a segment, coalescing with
- * previous segment if possible.
- */
- if (first) {
- map->dm_segs[seg].ds_addr = paddr;
- map->dm_segs[seg].ds_len = sgsize;
- first = 0;
- } else {
- if (paddr == lastaddr &&
- (map->dm_segs[seg].ds_len + sgsize) <=
- map->_dm_maxsegsz &&
- (map->_dm_boundary == 0 ||
- (map->dm_segs[seg].ds_addr & bmask) ==
- (paddr & bmask)))
- map->dm_segs[seg].ds_len += sgsize;
- else {
- if (++seg >= map->_dm_segcnt)
- return (EINVAL);
- map->dm_segs[seg].ds_addr = paddr;
- map->dm_segs[seg].ds_len = sgsize;
- }
- }
-
- lastaddr = paddr + sgsize;
- paddr += sgsize;
- plen -= sgsize;
+ /*
+ * Make sure we don't cross any boundaries.
+ */
+ if (map->_dm_boundary) {
+ bus_addr_t bmask = ~(map->_dm_boundary - 1);
+ int i;
+
+ for (i = 0; i < nsegs; i++) {
+ if (segs[i].ds_len > map->_dm_maxsegsz)
+ return (EINVAL);
+ if ((segs[i].ds_addr & bmask) !=
+ ((segs[i].ds_addr + segs[i].ds_len - 1) & bmask))
+ return (EINVAL);
}
}
- map->dm_nsegs = seg + 1;
+ bcopy(segs, map->dm_segs, nsegs * sizeof(*segs));
+ map->dm_nsegs = nsegs;
return (0);
}