From 3df3eb3b8b322a2a7f2ce6bbbff3b7296d910867 Mon Sep 17 00:00:00 2001 From: kettenis Date: Sat, 24 Jan 2015 15:13:55 +0000 Subject: [PATCH] Add bus_dmamem_alloc_range(9) to allow drivers to allocate DMA'able memory within a range that is more (or less) restrictive than the default range. ok deraadt@, stsp@ --- sys/arch/amd64/amd64/bus_dma.c | 6 +++--- sys/arch/amd64/include/bus.h | 10 ++++++++-- sys/arch/amd64/isa/isa_machdep.c | 5 +++-- sys/arch/amd64/pci/pci_machdep.c | 3 ++- sys/arch/i386/eisa/eisa_machdep.c | 3 ++- sys/arch/i386/i386/bus_dma.c | 6 +++--- sys/arch/i386/include/bus.h | 8 +++++++- sys/arch/i386/isa/isa_machdep.c | 5 +++-- sys/arch/i386/pci/pci_machdep.c | 3 ++- 9 files changed, 33 insertions(+), 16 deletions(-) diff --git a/sys/arch/amd64/amd64/bus_dma.c b/sys/arch/amd64/amd64/bus_dma.c index 9f86bdaa4ec..9ecb23bdee1 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.46 2014/11/16 12:30:56 deraadt Exp $ */ +/* $OpenBSD: bus_dma.c,v 1.47 2015/01/24 15:13:55 kettenis Exp $ */ /* $NetBSD: bus_dma.c,v 1.3 2003/05/07 21:33:58 fvdl Exp $ */ /*- @@ -424,7 +424,7 @@ _bus_dmamem_alloc(bus_dma_tag_t t, bus_size_t size, bus_size_t alignment, * memory under the 4gig boundary. */ return (_bus_dmamem_alloc_range(t, size, alignment, boundary, - segs, nsegs, rsegs, flags, (paddr_t)0, (paddr_t)0xffffffff)); + segs, nsegs, rsegs, flags, (bus_addr_t)0, (bus_addr_t)0xffffffff)); } /* @@ -662,7 +662,7 @@ _bus_dmamap_load_buffer(bus_dma_tag_t t, bus_dmamap_t map, void *buf, int _bus_dmamem_alloc_range(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 low, paddr_t high) + int flags, bus_addr_t low, bus_addr_t high) { paddr_t curaddr, lastaddr; struct vm_page *m; diff --git a/sys/arch/amd64/include/bus.h b/sys/arch/amd64/include/bus.h index 2056c18fda7..92a80a37e1c 100644 --- a/sys/arch/amd64/include/bus.h +++ b/sys/arch/amd64/include/bus.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bus.h,v 1.31 2014/03/29 18:09:28 guenther Exp $ */ +/* $OpenBSD: bus.h,v 1.32 2015/01/24 15:13:55 kettenis Exp $ */ /* $NetBSD: bus.h,v 1.6 1996/11/10 03:19:25 thorpej Exp $ */ /*- @@ -594,6 +594,9 @@ struct bus_dma_tag { */ int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t, bus_size_t, bus_dma_segment_t *, int, int *, int); + int (*_dmamem_alloc_range)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int, + bus_addr_t, bus_addr_t); void (*_dmamem_free)(bus_dma_tag_t, bus_dma_segment_t *, int); int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *, @@ -622,6 +625,9 @@ struct bus_dma_tag { #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \ (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f)) +#define bus_dmamem_alloc_range(t, s, a, b, sg, n, r, f, l, h) \ + (*(t)->_dmamem_alloc_range)((t), (s), (a), (b), (sg), \ + (n), (r), (f), (l), (h)) #define bus_dmamem_free(t, sg, n) \ (*(t)->_dmamem_free)((t), (sg), (n)) #define bus_dmamem_map(t, sg, n, s, k, f) \ @@ -686,6 +692,6 @@ paddr_t _bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs, int _bus_dmamem_alloc_range(bus_dma_tag_t tag, 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 low, paddr_t high); + bus_addr_t low, bus_addr_t high); #endif /* _MACHINE_BUS_H_ */ diff --git a/sys/arch/amd64/isa/isa_machdep.c b/sys/arch/amd64/isa/isa_machdep.c index 0757f0cddea..8197caa7008 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.25 2014/12/22 03:13:45 deraadt Exp $ */ +/* $OpenBSD: isa_machdep.c,v 1.26 2015/01/24 15:13:55 kettenis Exp $ */ /* $NetBSD: isa_machdep.c,v 1.22 1997/06/12 23:57:32 thorpej Exp $ */ #define ISA_DMA_STATS @@ -151,6 +151,7 @@ struct bus_dma_tag isa_bus_dma_tag = { _isa_bus_dmamap_unload, _isa_bus_dmamap_sync, _isa_bus_dmamem_alloc, + _bus_dmamem_alloc_range, _bus_dmamem_free, _bus_dmamem_map, _bus_dmamem_unmap, @@ -666,7 +667,7 @@ _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, (paddr_t)0, (paddr_t)-1); + segs, nsegs, rsegs, flags, (bus_addr_t)0, (bus_addr_t)-1); return (error); } diff --git a/sys/arch/amd64/pci/pci_machdep.c b/sys/arch/amd64/pci/pci_machdep.c index 650ecb656a2..d854cc3e237 100644 --- a/sys/arch/amd64/pci/pci_machdep.c +++ b/sys/arch/amd64/pci/pci_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pci_machdep.c,v 1.60 2014/12/16 23:13:20 jmatthew Exp $ */ +/* $OpenBSD: pci_machdep.c,v 1.61 2015/01/24 15:13:55 kettenis Exp $ */ /* $NetBSD: pci_machdep.c,v 1.3 2003/05/07 21:33:58 fvdl Exp $ */ /*- @@ -141,6 +141,7 @@ struct bus_dma_tag pci_bus_dma_tag = { _bus_dmamap_unload, _bus_dmamap_sync, _bus_dmamem_alloc, + _bus_dmamem_alloc_range, _bus_dmamem_free, _bus_dmamem_map, _bus_dmamem_unmap, diff --git a/sys/arch/i386/eisa/eisa_machdep.c b/sys/arch/i386/eisa/eisa_machdep.c index 60fe079a710..e9e34186547 100644 --- a/sys/arch/i386/eisa/eisa_machdep.c +++ b/sys/arch/i386/eisa/eisa_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: eisa_machdep.c,v 1.14 2010/09/06 19:05:48 kettenis Exp $ */ +/* $OpenBSD: eisa_machdep.c,v 1.15 2015/01/24 15:13:55 kettenis Exp $ */ /* $NetBSD: eisa_machdep.c,v 1.10.22.2 2000/06/25 19:36:58 sommerfeld Exp $ */ /*- @@ -93,6 +93,7 @@ struct bus_dma_tag eisa_bus_dma_tag = { _bus_dmamap_unload, _bus_dmamap_sync, _bus_dmamem_alloc, + _bus_dmamem_alloc_range, _bus_dmamem_free, _bus_dmamem_map, _bus_dmamem_unmap, diff --git a/sys/arch/i386/i386/bus_dma.c b/sys/arch/i386/i386/bus_dma.c index 87c5825902b..5026980388c 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.33 2014/11/16 12:30:57 deraadt Exp $ */ +/* $OpenBSD: bus_dma.c,v 1.34 2015/01/24 15:13:55 kettenis Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. * All rights reserved. @@ -387,7 +387,7 @@ _bus_dmamem_alloc(bus_dma_tag_t t, bus_size_t size, bus_size_t alignment, { return (_bus_dmamem_alloc_range(t, size, alignment, boundary, - segs, nsegs, rsegs, flags, (paddr_t)0, (paddr_t)-1)); + segs, nsegs, rsegs, flags, (bus_addr_t)0, (bus_addr_t)-1)); } /* @@ -619,7 +619,7 @@ _bus_dmamap_load_buffer(bus_dma_tag_t t, bus_dmamap_t map, void *buf, int _bus_dmamem_alloc_range(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 low, paddr_t high) + int flags, bus_addr_t low, bus_addr_t high) { paddr_t curaddr, lastaddr; struct vm_page *m; diff --git a/sys/arch/i386/include/bus.h b/sys/arch/i386/include/bus.h index a12891fff71..eaf54e03a79 100644 --- a/sys/arch/i386/include/bus.h +++ b/sys/arch/i386/include/bus.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bus.h,v 1.64 2014/10/17 20:37:57 sthen Exp $ */ +/* $OpenBSD: bus.h,v 1.65 2015/01/24 15:13:55 kettenis Exp $ */ /* $NetBSD: bus.h,v 1.6 1996/11/10 03:19:25 thorpej Exp $ */ /*- @@ -596,6 +596,9 @@ struct bus_dma_tag { */ int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t, bus_size_t, bus_dma_segment_t *, int, int *, int); + int (*_dmamem_alloc_range)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int, + bus_addr_t, bus_addr_t); void (*_dmamem_free)(bus_dma_tag_t, bus_dma_segment_t *, int); int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *, @@ -624,6 +627,9 @@ struct bus_dma_tag { #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \ (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f)) +#define bus_dmamem_alloc_range(t, s, a, b, sg, n, r, f, l, h) \ + (*(t)->_dmamem_alloc_range)((t), (s), (a), (b), (sg), \ + (n), (r), (f), (l), (h)) #define bus_dmamem_free(t, sg, n) \ (*(t)->_dmamem_free)((t), (sg), (n)) #define bus_dmamem_map(t, sg, n, s, k, f) \ diff --git a/sys/arch/i386/isa/isa_machdep.c b/sys/arch/i386/isa/isa_machdep.c index cef9b3e6b0c..f7daed5d7d5 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.78 2014/12/22 03:14:59 deraadt Exp $ */ +/* $OpenBSD: isa_machdep.c,v 1.79 2015/01/24 15:13:55 kettenis Exp $ */ /* $NetBSD: isa_machdep.c,v 1.22 1997/06/12 23:57:32 thorpej Exp $ */ /*- @@ -148,6 +148,7 @@ struct bus_dma_tag isa_bus_dma_tag = { _isa_bus_dmamap_unload, _isa_bus_dmamap_sync, _isa_bus_dmamem_alloc, + _bus_dmamem_alloc_range, _bus_dmamem_free, _bus_dmamem_map, _bus_dmamem_unmap, @@ -939,7 +940,7 @@ _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, (paddr_t)0, (paddr_t)-1); + segs, nsegs, rsegs, flags, (bus_addr_t)0, (bus_addr_t)-1); return (error); } diff --git a/sys/arch/i386/pci/pci_machdep.c b/sys/arch/i386/pci/pci_machdep.c index cf0a5f607ea..27cbc973889 100644 --- a/sys/arch/i386/pci/pci_machdep.c +++ b/sys/arch/i386/pci/pci_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pci_machdep.c,v 1.79 2014/07/12 18:44:42 tedu Exp $ */ +/* $OpenBSD: pci_machdep.c,v 1.80 2015/01/24 15:13:55 kettenis Exp $ */ /* $NetBSD: pci_machdep.c,v 1.28 1997/06/06 23:29:17 thorpej Exp $ */ /*- @@ -185,6 +185,7 @@ struct bus_dma_tag pci_bus_dma_tag = { _bus_dmamap_unload, _bus_dmamap_sync, _bus_dmamem_alloc, + _bus_dmamem_alloc_range, _bus_dmamem_free, _bus_dmamem_map, _bus_dmamem_unmap, -- 2.20.1