diff options
author | Owain Ainsworth <oga@cvs.openbsd.org> | 2010-03-25 22:44:58 +0000 |
---|---|---|
committer | Owain Ainsworth <oga@cvs.openbsd.org> | 2010-03-25 22:44:58 +0000 |
commit | f477292ed82c5aeb90ff7c13194259da9f8cc94c (patch) | |
tree | 89daeb8f4b463880817f6392395b90ec355c6d5a /sys/arch | |
parent | 7b68292916de8c4eca8a13c6aa756f093a881c90 (diff) |
Make the i386 and amd64 bus_dma functions for isa less stupid:
1) when you have a wrapper function in a dmatag that just calls the
_bus_dmamem original, you don't need it, just put the original function
in the tag
2) don't trunc_page the avail_end/ISA_BOUNCE_THRESHOLD stuff (see icb
for a discussion of why this is wrong about 00:00 gmt). make i386 and
amd64 both do this the same (the amd64 way is cleaner and makes the
third diff actually possible without a lot of pain). just do
dmamem_alloc_range(0, threshold) and if that fails do a alloc_range(0,
-1) and assume we'll bounce to pick up the pieces. Also using avail_end
for alloc_range is not nice (miod has been trying to avoid these abuses
iirc), so just use (paddr_t)-1, which is equivalent since you want "any"
memory.
3) now this is the funny one. consider point 2. then considering why
using the same bloody function to allocate your bouncebuffer is just
f'ing wrong. instead allocate with alloc_range(0, threshold) to make
sure that our bouncebuffer is actually uner 16megs.
ok deraadt@, kettenis@. Tested by several people.
Diffstat (limited to 'sys/arch')
-rw-r--r-- | sys/arch/amd64/isa/isa_machdep.c | 74 | ||||
-rw-r--r-- | sys/arch/i386/i386/bus_dma.c | 9 | ||||
-rw-r--r-- | sys/arch/i386/isa/isa_machdep.c | 88 |
3 files changed, 38 insertions, 133 deletions
diff --git a/sys/arch/amd64/isa/isa_machdep.c b/sys/arch/amd64/isa/isa_machdep.c index 99c25c181a5..619c8d12996 100644 --- a/sys/arch/amd64/isa/isa_machdep.c +++ b/sys/arch/amd64/isa/isa_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: isa_machdep.c,v 1.20 2009/03/10 15:03:17 oga Exp $ */ +/* $OpenBSD: isa_machdep.c,v 1.21 2010/03/25 22:44:57 oga Exp $ */ /* $NetBSD: isa_machdep.c,v 1.22 1997/06/12 23:57:32 thorpej Exp $ */ #define ISA_DMA_STATS @@ -128,13 +128,6 @@ void _isa_bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, int _isa_bus_dmamem_alloc(bus_dma_tag_t, bus_size_t, bus_size_t, bus_size_t, bus_dma_segment_t *, int, int *, int); -void _isa_bus_dmamem_free(bus_dma_tag_t, - bus_dma_segment_t *, int); -int _isa_bus_dmamem_map(bus_dma_tag_t, bus_dma_segment_t *, - int, size_t, caddr_t *, int); -void _isa_bus_dmamem_unmap(bus_dma_tag_t, caddr_t, size_t); -paddr_t _isa_bus_dmamem_mmap(bus_dma_tag_t, bus_dma_segment_t *, - int, off_t, int, int); int _isa_dma_check_buffer(void *, bus_size_t, int, bus_size_t, struct proc *); @@ -158,10 +151,10 @@ struct bus_dma_tag isa_bus_dma_tag = { _isa_bus_dmamap_unload, _isa_bus_dmamap_sync, _isa_bus_dmamem_alloc, - _isa_bus_dmamem_free, - _isa_bus_dmamem_map, - _isa_bus_dmamem_unmap, - _isa_bus_dmamem_mmap, + _bus_dmamem_free, + _bus_dmamem_map, + _bus_dmamem_unmap, + _bus_dmamem_mmap, }; #endif /* NISADMA > 0 */ @@ -676,52 +669,10 @@ _isa_bus_dmamem_alloc(bus_dma_tag_t t, bus_size_t size, bus_size_t alignment, /* Otherwise try anywhere (we'll bounce later) */ error = _bus_dmamem_alloc_range(t, size, alignment, boundary, - segs, nsegs, rsegs, flags, 0, trunc_page(avail_end)); + segs, nsegs, rsegs, flags, (paddr_t)0, (paddr_t)-1); return (error); } -/* - * Free memory safe for ISA DMA. - */ -void -_isa_bus_dmamem_free(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs) -{ - - _bus_dmamem_free(t, segs, nsegs); -} - -/* - * Map ISA DMA-safe memory into kernel virtual address space. - */ -int -_isa_bus_dmamem_map(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs, - size_t size, caddr_t *kvap, int flags) -{ - - return (_bus_dmamem_map(t, segs, nsegs, size, kvap, flags)); -} - -/* - * Unmap ISA DMA-safe memory from kernel virtual address space. - */ -void -_isa_bus_dmamem_unmap(bus_dma_tag_t t, caddr_t kva, size_t size) -{ - - _bus_dmamem_unmap(t, kva, size); -} - -/* - * mmap(2) ISA DMA-safe memory. - */ -paddr_t -_isa_bus_dmamem_mmap(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs, - off_t off, int prot, int flags) -{ - - return (_bus_dmamem_mmap(t, segs, nsegs, off, prot, flags)); -} - /********************************************************************** * ISA DMA utility functions **********************************************************************/ @@ -795,18 +746,19 @@ _isa_dma_alloc_bouncebuf(bus_dma_tag_t t, bus_dmamap_t map, bus_size_t size, int error = 0; cookie->id_bouncebuflen = round_page(size); - error = _isa_bus_dmamem_alloc(t, cookie->id_bouncebuflen, + error = _bus_dmamem_alloc_range(t, cookie->id_bouncebuflen, NBPG, map->_dm_boundary, cookie->id_bouncesegs, - map->_dm_segcnt, &cookie->id_nbouncesegs, flags); + map->_dm_segcnt, &cookie->id_nbouncesegs, flags, + 0, ISA_DMA_BOUNCE_THRESHOLD); if (error) goto out; - error = _isa_bus_dmamem_map(t, cookie->id_bouncesegs, + error = _bus_dmamem_map(t, cookie->id_bouncesegs, cookie->id_nbouncesegs, cookie->id_bouncebuflen, (caddr_t *)&cookie->id_bouncebuf, flags); out: if (error) { - _isa_bus_dmamem_free(t, cookie->id_bouncesegs, + _bus_dmamem_free(t, cookie->id_bouncesegs, cookie->id_nbouncesegs); cookie->id_bouncebuflen = 0; cookie->id_nbouncesegs = 0; @@ -825,9 +777,9 @@ _isa_dma_free_bouncebuf(bus_dma_tag_t t, bus_dmamap_t map) STAT_DECR(isa_dma_stats_nbouncebufs); - _isa_bus_dmamem_unmap(t, cookie->id_bouncebuf, + _bus_dmamem_unmap(t, cookie->id_bouncebuf, cookie->id_bouncebuflen); - _isa_bus_dmamem_free(t, cookie->id_bouncesegs, + _bus_dmamem_free(t, cookie->id_bouncesegs, cookie->id_nbouncesegs); cookie->id_bouncebuflen = 0; cookie->id_nbouncesegs = 0; diff --git a/sys/arch/i386/i386/bus_dma.c b/sys/arch/i386/i386/bus_dma.c index 0a9c664b02e..973bf82a706 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.19 2009/11/03 17:21:46 damien Exp $ */ +/* $OpenBSD: bus_dma.c,v 1.20 2010/03/25 22:44:57 oga Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. * All rights reserved. @@ -618,11 +618,8 @@ _bus_dmamem_alloc_range(bus_dma_tag_t t, bus_size_t size, bus_size_t alignment, plaflag |= UVM_PLA_ZERO; TAILQ_INIT(&mlist); - if (high <= ISA_DMA_BOUNCE_THRESHOLD || (error = uvm_pglistalloc(size, - round_page(ISA_DMA_BOUNCE_THRESHOLD), high, alignment, boundary, - &mlist, nsegs, plaflag))) - error = uvm_pglistalloc(size, low, high, alignment, boundary, - &mlist, nsegs, plaflag); + error = uvm_pglistalloc(size, low, high, alignment, boundary, + &mlist, nsegs, plaflag); if (error) return (error); diff --git a/sys/arch/i386/isa/isa_machdep.c b/sys/arch/i386/isa/isa_machdep.c index e3ac008cd7e..3b77563db12 100644 --- a/sys/arch/i386/isa/isa_machdep.c +++ b/sys/arch/i386/isa/isa_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: isa_machdep.c,v 1.68 2009/08/22 02:54:50 mk Exp $ */ +/* $OpenBSD: isa_machdep.c,v 1.69 2010/03/25 22:44:57 oga Exp $ */ /* $NetBSD: isa_machdep.c,v 1.22 1997/06/12 23:57:32 thorpej Exp $ */ /*- @@ -125,13 +125,6 @@ void _isa_bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, int _isa_bus_dmamem_alloc(bus_dma_tag_t, bus_size_t, bus_size_t, bus_size_t, bus_dma_segment_t *, int, int *, int); -void _isa_bus_dmamem_free(bus_dma_tag_t, - bus_dma_segment_t *, int); -int _isa_bus_dmamem_map(bus_dma_tag_t, bus_dma_segment_t *, - int, size_t, caddr_t *, int); -void _isa_bus_dmamem_unmap(bus_dma_tag_t, caddr_t, size_t); -paddr_t _isa_bus_dmamem_mmap(bus_dma_tag_t, bus_dma_segment_t *, - int, off_t, int, int); int _isa_dma_check_buffer(void *, bus_size_t, int, bus_size_t, struct proc *); @@ -155,10 +148,10 @@ struct bus_dma_tag isa_bus_dma_tag = { _isa_bus_dmamap_unload, _isa_bus_dmamap_sync, _isa_bus_dmamem_alloc, - _isa_bus_dmamem_free, - _isa_bus_dmamem_map, - _isa_bus_dmamem_unmap, - _isa_bus_dmamem_mmap, + _bus_dmamem_free, + _bus_dmamem_map, + _bus_dmamem_unmap, + _bus_dmamem_mmap, }; #endif /* NISADMA > 0 */ @@ -930,58 +923,20 @@ _isa_bus_dmamem_alloc(bus_dma_tag_t t, bus_size_t size, bus_size_t alignment, bus_size_t boundary, bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags) { - paddr_t high; - - if (avail_end > ISA_DMA_BOUNCE_THRESHOLD) - high = trunc_page(ISA_DMA_BOUNCE_THRESHOLD); - else - high = trunc_page(avail_end); - - return (_bus_dmamem_alloc_range(t, size, alignment, boundary, - segs, nsegs, rsegs, flags, 0, high)); -} - -/* - * Free memory safe for ISA DMA. - */ -void -_isa_bus_dmamem_free(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs) -{ - - _bus_dmamem_free(t, segs, nsegs); -} - -/* - * Map ISA DMA-safe memory into kernel virtual address space. - */ -int -_isa_bus_dmamem_map(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs, - size_t size, caddr_t *kvap, int flags) -{ - - return (_bus_dmamem_map(t, segs, nsegs, size, kvap, flags)); -} + int error; -/* - * Unmap ISA DMA-safe memory from kernel virtual address space. - */ -void -_isa_bus_dmamem_unmap(bus_dma_tag_t t, caddr_t kva, size_t size) -{ + /* Try in ISA addressable region first */ + error = _bus_dmamem_alloc_range(t, size, alignment, boundary, + segs, nsegs, rsegs, flags, 0, ISA_DMA_BOUNCE_THRESHOLD); + if (!error) + return (error); - _bus_dmamem_unmap(t, kva, size); + /* Otherwise try anywhere (we'll bounce later) */ + error = _bus_dmamem_alloc_range(t, size, alignment, boundary, + segs, nsegs, rsegs, flags, (paddr_t)0, (paddr_t)-1); + return (error); } -/* - * mmap(2) ISA DMA-safe memory. - */ -paddr_t -_isa_bus_dmamem_mmap(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs, - off_t off, int prot, int flags) -{ - - return (_bus_dmamem_mmap(t, segs, nsegs, off, prot, flags)); -} /********************************************************************** * ISA DMA utility functions @@ -1055,18 +1010,19 @@ _isa_dma_alloc_bouncebuf(bus_dma_tag_t t, bus_dmamap_t map, bus_size_t size, int int error = 0; cookie->id_bouncebuflen = round_page(size); - error = _isa_bus_dmamem_alloc(t, cookie->id_bouncebuflen, + error = _bus_dmamem_alloc_range(t, cookie->id_bouncebuflen, NBPG, map->_dm_boundary, cookie->id_bouncesegs, - map->_dm_segcnt, &cookie->id_nbouncesegs, flags); + map->_dm_segcnt, &cookie->id_nbouncesegs, flags, + 0, ISA_DMA_BOUNCE_THRESHOLD); if (error) goto out; - error = _isa_bus_dmamem_map(t, cookie->id_bouncesegs, + error = _bus_dmamem_map(t, cookie->id_bouncesegs, cookie->id_nbouncesegs, cookie->id_bouncebuflen, (caddr_t *)&cookie->id_bouncebuf, flags); out: if (error) { - _isa_bus_dmamem_free(t, cookie->id_bouncesegs, + _bus_dmamem_free(t, cookie->id_bouncesegs, cookie->id_nbouncesegs); cookie->id_bouncebuflen = 0; cookie->id_nbouncesegs = 0; @@ -1085,9 +1041,9 @@ _isa_dma_free_bouncebuf(bus_dma_tag_t t, bus_dmamap_t map) STAT_DECR(isa_dma_stats_nbouncebufs); - _isa_bus_dmamem_unmap(t, cookie->id_bouncebuf, + _bus_dmamem_unmap(t, cookie->id_bouncebuf, cookie->id_bouncebuflen); - _isa_bus_dmamem_free(t, cookie->id_bouncesegs, + _bus_dmamem_free(t, cookie->id_bouncesegs, cookie->id_nbouncesegs); cookie->id_bouncebuflen = 0; cookie->id_nbouncesegs = 0; |