diff options
author | Scott Long <scottl@FreeBSD.org> | 2005-03-14 16:46:28 +0000 |
---|---|---|
committer | Scott Long <scottl@FreeBSD.org> | 2005-03-14 16:46:28 +0000 |
commit | 5974e5c71cb4a1d9b23559c1f17f291e911dfb6a (patch) | |
tree | ea782fb9f8249533af78a2cb005772cd4ace3515 /sys | |
parent | 0e3b5c73b258bfec5744855774ef36e9ea813fd8 (diff) | |
download | src-5974e5c71cb4a1d9b23559c1f17f291e911dfb6a.tar.gz src-5974e5c71cb4a1d9b23559c1f17f291e911dfb6a.zip |
Refactor the bus_dma header files so that the interface is described in
sys/bus_dma.h instead of being copied in every single arch. This slightly
reorders a flag that was specific to AXP and thus changes the ABI there.
The interface still relies on bus_space definitions found in <machine/bus.h>
so it cannot be included on its own yet, but that will be fixed at a later
date. Add an MD <machine/bus_dma.h> for ever arch for consistency and to
allow for future MD augmentation of the API. sparc64 makes heavy use of
this right now due to its different bus_dma implemenation.
Notes
Notes:
svn path=/head/; revision=143598
Diffstat (limited to 'sys')
-rw-r--r-- | sys/alpha/include/bus.h | 191 | ||||
-rw-r--r-- | sys/alpha/include/bus_dma.h | 33 | ||||
-rw-r--r-- | sys/amd64/include/bus_dma.h | 260 | ||||
-rw-r--r-- | sys/arm/include/bus.h | 154 | ||||
-rw-r--r-- | sys/arm/include/bus_dma.h | 106 | ||||
-rw-r--r-- | sys/i386/include/bus_dma.h | 237 | ||||
-rw-r--r-- | sys/ia64/include/bus.h | 195 | ||||
-rw-r--r-- | sys/ia64/include/bus_dma.h | 33 | ||||
-rw-r--r-- | sys/powerpc/include/bus.h | 183 | ||||
-rw-r--r-- | sys/powerpc/include/bus_dma.h | 33 | ||||
-rw-r--r-- | sys/sparc64/include/bus.h | 148 | ||||
-rw-r--r-- | sys/sparc64/include/bus_dma.h | 152 | ||||
-rw-r--r-- | sys/sys/bus_dma.h | 64 |
13 files changed, 423 insertions, 1366 deletions
diff --git a/sys/alpha/include/bus.h b/sys/alpha/include/bus.h index ae8983483203..a5ea27524349 100644 --- a/sys/alpha/include/bus.h +++ b/sys/alpha/include/bus.h @@ -481,195 +481,6 @@ void busspace_generic_barrier(struct alpha_busspace *space, #define bus_space_copy_region_stream_4(t, h1, o1, h2, o2, c) \ bus_space_copy_region_4((t), (h1), (o1), (h2), (o2), (c)) -/* - * Flags used in various bus DMA methods. - */ -#define BUS_DMA_WAITOK 0x00 /* safe to sleep (pseudo-flag) */ -#define BUS_DMA_NOWAIT 0x01 /* not safe to sleep */ -#define BUS_DMA_ALLOCNOW 0x02 /* perform resource allocation now */ -#define BUS_DMA_COHERENT 0x04 /* hint: map memory in a coherent way */ -#define BUS_DMA_ZERO 0x08 /* allocate zero'ed memory */ -#define BUS_DMA_ISA 0x10 /* map memory for ISA dma */ -#define BUS_DMA_BUS2 0x20 /* placeholders for bus functions... */ -#define BUS_DMA_BUS3 0x40 -#define BUS_DMA_BUS4 0x80 - -/* Forwards needed by prototypes below. */ -struct mbuf; -struct uio; - -/* - * Operations performed by bus_dmamap_sync(). - */ -typedef int bus_dmasync_op_t; -#define BUS_DMASYNC_PREREAD 1 -#define BUS_DMASYNC_POSTREAD 2 -#define BUS_DMASYNC_PREWRITE 4 -#define BUS_DMASYNC_POSTWRITE 8 - -/* - * bus_dma_tag_t - * - * A machine-dependent opaque type describing the characteristics - * of how to perform DMA mappings. This structure encapsultes - * information concerning address and alignment restrictions, number - * of S/G segments, amount of data per S/G segment, etc. - */ -typedef struct bus_dma_tag *bus_dma_tag_t; - -/* - * bus_dmamap_t - * - * DMA mapping instance information. - */ -typedef struct bus_dmamap *bus_dmamap_t; - -/* - * bus_dma_segment_t - * - * Describes a single contiguous DMA transaction. Values - * are suitable for programming into DMA registers. - */ -typedef struct bus_dma_segment { - bus_addr_t ds_addr; /* DMA address */ - bus_size_t ds_len; /* length of transfer */ -} bus_dma_segment_t; - -/* - * A function that returns 1 if the address cannot be accessed by - * a device and 0 if it can be. - */ -typedef int bus_dma_filter_t(void *, bus_addr_t); - -/* - * A function that performs driver-specific syncronization on behalf of - * busdma. - */ -typedef enum { - BUS_DMA_LOCK = 0x01, - BUS_DMA_UNLOCK = 0x02, -} bus_dma_lock_op_t; - -typedef void bus_dma_lock_t(void *, bus_dma_lock_op_t); - -/* - * Allocate a device specific dma_tag encapsulating the constraints of - * the parent tag in addition to other restrictions specified: - * - * alignment: alignment for segments. - * boundary: Boundary that segments cannot cross. - * lowaddr: Low restricted address that cannot appear in a mapping. - * highaddr: High restricted address that cannot appear in a mapping. - * filtfunc: An optional function to further test if an address - * within the range of lowaddr and highaddr cannot appear - * in a mapping. - * filtfuncarg: An argument that will be passed to filtfunc in addition - * to the address to test. - * maxsize: Maximum mapping size supported by this tag. - * nsegments: Number of discontinuities allowed in maps. - * maxsegsz: Maximum size of a segment in the map. - * flags: Bus DMA flags. - * lockfunc: An optional function to handle driver-defined lock - * operations. - * lockfuncarg: An argument that will be passed to lockfunc in addition - * to the lock operation. - * dmat: A pointer to set to a valid dma tag should the return - * value of this function indicate success. - */ -/* XXX Should probably allow specification of alignment */ -int bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignemnt, - bus_size_t boundary, bus_addr_t lowaddr, - bus_addr_t highaddr, bus_dma_filter_t *filtfunc, - void *filtfuncarg, bus_size_t maxsize, int nsegments, - bus_size_t maxsegsz, int flags, bus_dma_lock_t *lockfunc, - void *lockfuncarg, bus_dma_tag_t *dmat); - -int bus_dma_tag_destroy(bus_dma_tag_t dmat); - -/* - * Allocate a handle for mapping from kva/uva/physical - * address space into bus device space. - */ -int bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp); - -/* - * Destroy a handle for mapping from kva/uva/physical - * address space into bus device space. - */ -int bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map); - -/* - * Allocate a piece of memory that can be efficiently mapped into - * bus device space based on the constraints lited in the dma tag. - * A dmamap to for use with dmamap_load is also allocated. - */ -int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, - bus_dmamap_t *mapp); - -/* - * Free a piece of memory and it's allociated dmamap, that was allocated - * via bus_dmamem_alloc. - */ -void bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map); - -/* - * A function that processes a successfully loaded dma map or an error - * from a delayed load map. - */ -typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int); - -/* - * Map the buffer buf into bus space using the dmamap map. - */ -int bus_dmamap_load(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf, - bus_size_t buflen, bus_dmamap_callback_t *callback, - void *callback_arg, int flags); - -/* - * Like bus_dmamap_callback but includes map size in bytes. This is - * defined as a separate interface to maintain compatiiblity for users - * of bus_dmamap_callback_t--at some point these interfaces should be merged. - */ -typedef void bus_dmamap_callback2_t(void *, bus_dma_segment_t *, int, bus_size_t, int); -/* - * Like bus_dmamap_load but for mbufs. Note the use of the - * bus_dmamap_callback2_t interface. - */ -int bus_dmamap_load_mbuf(bus_dma_tag_t dmat, bus_dmamap_t map, - struct mbuf *mbuf, - bus_dmamap_callback2_t *callback, void *callback_arg, - int flags); -int bus_dmamap_load_mbuf_sg(bus_dma_tag_t dmat, bus_dmamap_t map, - struct mbuf *mbuf, bus_dma_segment_t *segs, - int *nsegs, int flags); -/* - * Like bus_dmamap_load but for uios. Note the use of the - * bus_dmamap_callback2_t interface. - */ -int bus_dmamap_load_uio(bus_dma_tag_t dmat, bus_dmamap_t map, - struct uio *ui, - bus_dmamap_callback2_t *callback, void *callback_arg, - int flags); - -/* - * Perform a syncronization operation on the given map. - */ -void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_dmasync_op_t); -#define bus_dmamap_sync(dmat, dmamap, op) \ - if ((dmamap) != NULL) \ - _bus_dmamap_sync(dmat, dmamap, op) - -/* - * Release the mapping held by map. - */ -void _bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map); -#define bus_dmamap_unload(dmat, dmamap) \ - if ((dmamap) != NULL) \ - _bus_dmamap_unload(dmat, dmamap) - -/* - * Generic helper function for manipulating mutexes. - */ -void busdma_lock_mutex(void *arg, bus_dma_lock_op_t op); +#include <machine/bus_dma.h> #endif /* _ALPHA_BUS_H_ */ diff --git a/sys/alpha/include/bus_dma.h b/sys/alpha/include/bus_dma.h new file mode 100644 index 000000000000..141fff0dea34 --- /dev/null +++ b/sys/alpha/include/bus_dma.h @@ -0,0 +1,33 @@ +/*- + * Copyright (c) 2005 Scott Long + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +/* $FreeBSD$ */ + +#ifndef _ALPHA_BUS_DMA_H_ +#define _ALPHA_BUS_DMA_H_ + +#include <sys/bus_dma.h> + +#endif /* _ALPHA_BUS_DMA_H_ */ diff --git a/sys/amd64/include/bus_dma.h b/sys/amd64/include/bus_dma.h index 95435da24d91..9820d310adba 100644 --- a/sys/amd64/include/bus_dma.h +++ b/sys/amd64/include/bus_dma.h @@ -1,46 +1,7 @@ -/* $NetBSD: bus.h,v 1.12 1997/10/01 08:25:15 fvdl Exp $ */ - /*- - * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. + * Copyright (c) 2005 Scott Long * All rights reserved. * - * This code is derived from software contributed to The NetBSD Foundation - * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, - * NASA Ames Research Center. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/*- - * Copyright (c) 1996 Charles M. Hannum. All rights reserved. - * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -49,219 +10,24 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Christopher G. Demetriou - * for the NetBSD Project. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. */ /* $FreeBSD$ */ #ifndef _AMD64_BUS_DMA_H_ #define _AMD64_BUS_DMA_H_ -/* - * Flags used in various bus DMA methods. - */ -#define BUS_DMA_WAITOK 0x00 /* safe to sleep (pseudo-flag) */ -#define BUS_DMA_NOWAIT 0x01 /* not safe to sleep */ -#define BUS_DMA_ALLOCNOW 0x02 /* perform resource allocation now */ -#define BUS_DMA_COHERENT 0x04 /* hint: map memory in a coherent way */ -#define BUS_DMA_ZERO 0x08 /* allocate zero'ed memory */ -#define BUS_DMA_BUS1 0x10 /* placeholders for bus functions... */ -#define BUS_DMA_BUS2 0x20 -#define BUS_DMA_BUS3 0x40 -#define BUS_DMA_BUS4 0x80 - -/* Forwards needed by prototypes below. */ -struct mbuf; -struct uio; - -/* - * Operations performed by bus_dmamap_sync(). - */ -typedef int bus_dmasync_op_t; -#define BUS_DMASYNC_PREREAD 1 -#define BUS_DMASYNC_POSTREAD 2 -#define BUS_DMASYNC_PREWRITE 4 -#define BUS_DMASYNC_POSTWRITE 8 - -/* - * bus_dma_tag_t - * - * A machine-dependent opaque type describing the characteristics - * of how to perform DMA mappings. This structure encapsultes - * information concerning address and alignment restrictions, number - * of S/G segments, amount of data per S/G segment, etc. - */ -typedef struct bus_dma_tag *bus_dma_tag_t; - -/* - * bus_dmamap_t - * - * DMA mapping instance information. - */ -typedef struct bus_dmamap *bus_dmamap_t; - -/* - * bus_dma_segment_t - * - * Describes a single contiguous DMA transaction. Values - * are suitable for programming into DMA registers. - */ -typedef struct bus_dma_segment { - bus_addr_t ds_addr; /* DMA address */ - bus_size_t ds_len; /* length of transfer */ -} bus_dma_segment_t; - -/* - * A function that returns 1 if the address cannot be accessed by - * a device and 0 if it can be. - */ -typedef int bus_dma_filter_t(void *, bus_addr_t); - -/* - * A function that performs driver-specific synchronization on behalf of - * busdma. - */ -typedef enum { - BUS_DMA_LOCK = 0x01, - BUS_DMA_UNLOCK = 0x02, -} bus_dma_lock_op_t; - -typedef void bus_dma_lock_t(void *, bus_dma_lock_op_t); - -/* - * Allocate a device specific dma_tag encapsulating the constraints of - * the parent tag in addition to other restrictions specified: - * - * alignment: Alignment for segments. - * boundary: Boundary that segments cannot cross. - * lowaddr: Low restricted address that cannot appear in a mapping. - * highaddr: High restricted address that cannot appear in a mapping. - * filtfunc: An optional function to further test if an address - * within the range of lowaddr and highaddr cannot appear - * in a mapping. - * filtfuncarg: An argument that will be passed to filtfunc in addition - * to the address to test. - * maxsize: Maximum mapping size supported by this tag. - * nsegments: Number of discontinuities allowed in maps. - * maxsegsz: Maximum size of a segment in the map. - * flags: Bus DMA flags. - * lockfunc: An optional function to handle driver-defined lock - * operations. - * lockfuncarg: An argument that will be passed to lockfunc in addition - * to the lock operation. - * dmat: A pointer to set to a valid dma tag should the return - * value of this function indicate success. - */ -/* XXX Should probably allow specification of alignment */ -int bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment, - bus_size_t boundary, bus_addr_t lowaddr, - bus_addr_t highaddr, bus_dma_filter_t *filtfunc, - void *filtfuncarg, bus_size_t maxsize, int nsegments, - bus_size_t maxsegsz, int flags, bus_dma_lock_t *lockfunc, - void *lockfuncarg, bus_dma_tag_t *dmat); - -int bus_dma_tag_destroy(bus_dma_tag_t dmat); - -/* - * Allocate a handle for mapping from kva/uva/physical - * address space into bus device space. - */ -int bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp); - -/* - * Destroy a handle for mapping from kva/uva/physical - * address space into bus device space. - */ -int bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map); - -/* - * Allocate a piece of memory that can be efficiently mapped into - * bus device space based on the constraints listed in the dma tag. - * A dmamap to for use with dmamap_load is also allocated. - */ -int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, - bus_dmamap_t *mapp); - -/* - * Free a piece of memory and its allocated dmamap, that was allocated - * via bus_dmamem_alloc. - */ -void bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map); - -/* - * A function that processes a successfully loaded dma map or an error - * from a delayed load map. - */ -typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int); - -/* - * Map the buffer buf into bus space using the dmamap map. - */ -int bus_dmamap_load(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf, - bus_size_t buflen, bus_dmamap_callback_t *callback, - void *callback_arg, int flags); - -/* - * Like bus_dmamap_callback but includes map size in bytes. This is - * defined as a separate interface to maintain compatibility for users - * of bus_dmamap_callback_t--at some point these interfaces should be merged. - */ -typedef void bus_dmamap_callback2_t(void *, bus_dma_segment_t *, int, bus_size_t, int); -/* - * Like bus_dmamap_load but for mbufs. Note the use of the - * bus_dmamap_callback2_t interface. - */ -int bus_dmamap_load_mbuf(bus_dma_tag_t dmat, bus_dmamap_t map, - struct mbuf *mbuf, - bus_dmamap_callback2_t *callback, void *callback_arg, - int flags); - -int bus_dmamap_load_mbuf_sg(bus_dma_tag_t dmat, bus_dmamap_t map, - struct mbuf *mbuf, bus_dma_segment_t *segs, - int *nsegs, int flags); +#include <sys/bus_dma.h> -/* - * Like bus_dmamap_load but for uios. Note the use of the - * bus_dmamap_callback2_t interface. - */ -int bus_dmamap_load_uio(bus_dma_tag_t dmat, bus_dmamap_t map, - struct uio *ui, - bus_dmamap_callback2_t *callback, void *callback_arg, - int flags); - -/* - * Perform a synchronization operation on the given map. - */ -void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_dmasync_op_t); -#define bus_dmamap_sync(dmat, dmamap, op) \ - if ((dmamap) != NULL) \ - _bus_dmamap_sync(dmat, dmamap, op) - -/* - * Release the mapping held by map. - */ -void _bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map); -#define bus_dmamap_unload(dmat, dmamap) \ - if ((dmamap) != NULL) \ - _bus_dmamap_unload(dmat, dmamap) - -/* - * Generic helper function for manipulating mutexes. - */ -void busdma_lock_mutex(void *arg, bus_dma_lock_op_t op); #endif /* _AMD64_BUS_DMA_H_ */ diff --git a/sys/arm/include/bus.h b/sys/arm/include/bus.h index d51584570967..70f743847271 100644 --- a/sys/arm/include/bus.h +++ b/sys/arm/include/bus.h @@ -592,158 +592,6 @@ bs_c_8_proto(f); #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t) -/* Bus Space DMA macros */ - -/* - * Flags used in various bus DMA methods. - */ -#define BUS_DMA_WAITOK 0x000 /* safe to sleep (pseudo-flag) */ -#define BUS_DMA_NOWAIT 0x001 /* not safe to sleep */ -#define BUS_DMA_ALLOCNOW 0x002 /* perform resource allocation now */ -#define BUS_DMA_COHERENT 0x004 /* hint: map memory DMA coherent */ -#define BUS_DMA_ZERO 0x008 /* hint: sequential, unidirectional */ -#define BUS_DMA_BUS1 0x010 /* placeholders for bus functions... */ -#define BUS_DMA_BUS2 0x020 -#define BUS_DMA_BUS3 0x040 -#define BUS_DMA_BUS4 0x080 - -/* Forwards needed by prototypes below. */ -struct mbuf; -struct uio; - -/* - * Operations performed by bus_dmamap_sync(). - */ -#define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */ -#define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */ -#define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */ -#define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */ - -typedef struct bus_dma_tag *bus_dma_tag_t; -typedef struct bus_dmamap *bus_dmamap_t; - -#define BUS_DMA_TAG_VALID(t) ((t) != (bus_dma_tag_t)0) - -/* - * bus_dma_segment_t - * - * Describes a single contiguous DMA transaction. Values - * are suitable for programming into DMA registers. - */ -struct bus_dma_segment { - /* - * PUBLIC MEMBERS: these are used by machine-independent code. - */ - bus_addr_t ds_addr; /* DMA address */ - bus_size_t ds_len; /* length of transfer */ -}; -typedef struct bus_dma_segment bus_dma_segment_t; - -/* - * arm32_dma_range - * - * This structure describes a valid DMA range. - */ -struct arm32_dma_range { - bus_addr_t dr_sysbase; /* system base address */ - bus_addr_t dr_busbase; /* appears here on bus */ - bus_size_t dr_len; /* length of range */ -}; - -/* - * bus_dma_tag_t - * - * A machine-dependent opaque type describing the implementation of - * DMA for a given bus. - */ - -typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int); -typedef int bus_dmasync_op_t; -typedef void bus_dmamap_callback2_t(void *, bus_dma_segment_t *, int, bus_size_t, int); - - -#ifdef _ARM32_BUS_DMA_PRIVATE - -/* _dm_buftype */ -#define ARM32_BUFTYPE_INVALID 0 -#define ARM32_BUFTYPE_LINEAR 1 -#define ARM32_BUFTYPE_MBUF 2 -#define ARM32_BUFTYPE_UIO 3 -#define ARM32_BUFTYPE_RAW 4 - -struct arm32_dma_range *bus_dma_get_range(void); -int bus_dma_get_range_nb(void); -#endif /* _ARM32_BUS_DMA_PRIVATE */ - -/* - * A function that returns 1 if the address cannot be accessed by - * a device and 0 if it can be. - */ -typedef int bus_dma_filter_t(void *, bus_addr_t); - -/* - * A function that performs driver-specific syncronization on behalf of - * busdma. - */ -typedef enum { - BUS_DMA_LOCK = 0x01, - BUS_DMA_UNLOCK = 0x02, -} bus_dma_lock_op_t; - -typedef void bus_dma_lock_t(void *, bus_dma_lock_op_t); - -/* - * Allocate a device specific dma_tag encapsulating the constraints of - * the parent tag in addition to other restrictions specified: - * - * alignment: alignment for segments. - * boundary: Boundary that segments cannot cross. - * lowaddr: Low restricted address that cannot appear in a mapping. - * highaddr: High restricted address that cannot appear in a mapping. - * filtfunc: An optional function to further test if an address - * within the range of lowaddr and highaddr cannot appear - * in a mapping. - * filtfuncarg: An argument that will be passed to filtfunc in addition - * to the address to test. - * maxsize: Maximum mapping size supported by this tag. - * nsegments: Number of discontinuities allowed in maps. - * maxsegsz: Maximum size of a segment in the map. - * flags: Bus DMA flags. - * dmat: A pointer to set to a valid dma tag should the return - * value of this function indicate success. - */ -int bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment, - bus_size_t boundary, bus_addr_t lowaddr, - bus_addr_t highaddr, bus_dma_filter_t *filtfunc, - void *filtfuncarg, bus_size_t maxsize, int nsegments, - bus_size_t maxsegsz, int flags, bus_dma_lock_t *lockfunc, - void *lockfuncarg, bus_dma_tag_t *dmat); - -int bus_dma_tag_destroy(bus_dma_tag_t dmat); - -int bus_dmamap_create (bus_dma_tag_t, int, bus_dmamap_t *); -int bus_dmamap_destroy (bus_dma_tag_t, bus_dmamap_t); -int bus_dmamap_load (bus_dma_tag_t, bus_dmamap_t, void *, - bus_size_t, bus_dmamap_callback_t *, void *, int); -int bus_dmamap_load_mbuf (bus_dma_tag_t, bus_dmamap_t, - struct mbuf *, bus_dmamap_callback2_t *, void *, int); -int bus_dmamap_load_mbuf_sg(bus_dma_tag_t dmat, bus_dmamap_t map, - struct mbuf *mbuf, bus_dma_segment_t *segs, - int *nsegs, int flags); -int bus_dmamap_load_uio (bus_dma_tag_t, bus_dmamap_t, - struct uio *, bus_dmamap_callback2_t *, void *, int); -void bus_dmamap_unload (bus_dma_tag_t, bus_dmamap_t); -void bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_dmasync_op_t); - -int bus_dmamem_alloc (bus_dma_tag_t tag, void **vaddr, int flag, - bus_dmamap_t *mapp); -void bus_dmamem_free (bus_dma_tag_t tag, void *vaddr, bus_dmamap_t map); - -/* - * Generic helper function for manipulating mutexes. - */ -void busdma_lock_mutex(void *arg, bus_dma_lock_op_t op); - #define BUS_SPACE_MAXADDR_24BIT 0xFFFFFF #define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF #define BUS_SPACE_MAXADDR 0xFFFFFFFF @@ -778,4 +626,6 @@ void busdma_lock_mutex(void *arg, bus_dma_lock_op_t op); bus_space_write_multi_4((t), (h), (o), (a), (c)) +#include <machine/bus_dma.h> + #endif /* _MACHINE_BUS_H_ */ diff --git a/sys/arm/include/bus_dma.h b/sys/arm/include/bus_dma.h new file mode 100644 index 000000000000..f239197df0ca --- /dev/null +++ b/sys/arm/include/bus_dma.h @@ -0,0 +1,106 @@ +/* $NetBSD: bus.h,v 1.11 2003/07/28 17:35:54 thorpej Exp $ */ + +/*- + * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*- + * Copyright (c) 1996 Charles M. Hannum. All rights reserved. + * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christopher G. Demetriou + * for the NetBSD Project. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _ARM_BUS_DMA_H +#define _ARM_BUS_DMA_H + +#include <sys/bus_dma.h> + +/* Bus Space DMA macros */ + +#define BUS_DMA_TAG_VALID(t) ((t) != (bus_dma_tag_t)0) + +#ifdef _ARM32_BUS_DMA_PRIVATE +/* + * arm32_dma_range + * + * This structure describes a valid DMA range. + */ +struct arm32_dma_range { + bus_addr_t dr_sysbase; /* system base address */ + bus_addr_t dr_busbase; /* appears here on bus */ + bus_size_t dr_len; /* length of range */ +}; + +/* _dm_buftype */ +#define ARM32_BUFTYPE_INVALID 0 +#define ARM32_BUFTYPE_LINEAR 1 +#define ARM32_BUFTYPE_MBUF 2 +#define ARM32_BUFTYPE_UIO 3 +#define ARM32_BUFTYPE_RAW 4 + +struct arm32_dma_range *bus_dma_get_range(void); +int bus_dma_get_range_nb(void); + +#endif /* _ARM32_BUS_DMA_PRIVATE */ + +#endif /* _ARM_BUS_DMA_H */ diff --git a/sys/i386/include/bus_dma.h b/sys/i386/include/bus_dma.h index 03d608576c87..95e98a7e43c2 100644 --- a/sys/i386/include/bus_dma.h +++ b/sys/i386/include/bus_dma.h @@ -1,13 +1,7 @@ -/* $NetBSD: bus.h,v 1.12 1997/10/01 08:25:15 fvdl Exp $ */ - /*- - * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. + * Copyright (c) 2005 Scott Long * All rights reserved. * - * This code is derived from software contributed to The NetBSD Foundation - * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, - * NASA Ames Research Center. - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -16,13 +10,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED @@ -37,231 +24,11 @@ * POSSIBILITY OF SUCH DAMAGE. */ -/*- - * Copyright (c) 1996 Charles M. Hannum. All rights reserved. - * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Christopher G. Demetriou - * for the NetBSD Project. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ /* $FreeBSD$ */ #ifndef _I386_BUS_DMA_H_ #define _I386_BUS_DMA_H_ -/* - * Flags used in various bus DMA methods. - */ -#define BUS_DMA_WAITOK 0x00 /* safe to sleep (pseudo-flag) */ -#define BUS_DMA_NOWAIT 0x01 /* not safe to sleep */ -#define BUS_DMA_ALLOCNOW 0x02 /* perform resource allocation now */ -#define BUS_DMA_COHERENT 0x04 /* hint: map memory in a coherent way */ -#define BUS_DMA_ZERO 0x08 /* allocate zero'ed memory */ -#define BUS_DMA_BUS1 0x10 /* placeholders for bus functions... */ -#define BUS_DMA_BUS2 0x20 -#define BUS_DMA_BUS3 0x40 -#define BUS_DMA_BUS4 0x80 - -/* Forwards needed by prototypes below. */ -struct mbuf; -struct uio; - -/* - * Operations performed by bus_dmamap_sync(). - */ -typedef int bus_dmasync_op_t; -#define BUS_DMASYNC_PREREAD 1 -#define BUS_DMASYNC_POSTREAD 2 -#define BUS_DMASYNC_PREWRITE 4 -#define BUS_DMASYNC_POSTWRITE 8 - -/* - * bus_dma_tag_t - * - * A machine-dependent opaque type describing the characteristics - * of how to perform DMA mappings. This structure encapsultes - * information concerning address and alignment restrictions, number - * of S/G segments, amount of data per S/G segment, etc. - */ -typedef struct bus_dma_tag *bus_dma_tag_t; +#include <sys/bus_dma.h> -/* - * bus_dmamap_t - * - * DMA mapping instance information. - */ -typedef struct bus_dmamap *bus_dmamap_t; - -/* - * bus_dma_segment_t - * - * Describes a single contiguous DMA transaction. Values - * are suitable for programming into DMA registers. - */ -typedef struct bus_dma_segment { - bus_addr_t ds_addr; /* DMA address */ - bus_size_t ds_len; /* length of transfer */ -} bus_dma_segment_t; - -/* - * A function that returns 1 if the address cannot be accessed by - * a device and 0 if it can be. - */ -typedef int bus_dma_filter_t(void *, bus_addr_t); - -/* - * A function that performs driver-specific synchronization on behalf of - * busdma. - */ -typedef enum { - BUS_DMA_LOCK = 0x01, - BUS_DMA_UNLOCK = 0x02, -} bus_dma_lock_op_t; - -typedef void bus_dma_lock_t(void *, bus_dma_lock_op_t); - -/* - * Allocate a device specific dma_tag encapsulating the constraints of - * the parent tag in addition to other restrictions specified: - * - * alignment: Alignment for segments. - * boundary: Boundary that segments cannot cross. - * lowaddr: Low restricted address that cannot appear in a mapping. - * highaddr: High restricted address that cannot appear in a mapping. - * filtfunc: An optional function to further test if an address - * within the range of lowaddr and highaddr cannot appear - * in a mapping. - * filtfuncarg: An argument that will be passed to filtfunc in addition - * to the address to test. - * maxsize: Maximum mapping size supported by this tag. - * nsegments: Number of discontinuities allowed in maps. - * maxsegsz: Maximum size of a segment in the map. - * flags: Bus DMA flags. - * lockfunc: An optional function to handle driver-defined lock - * operations. - * lockfuncarg: An argument that will be passed to lockfunc in addition - * to the lock operation. - * dmat: A pointer to set to a valid dma tag should the return - * value of this function indicate success. - */ -/* XXX Should probably allow specification of alignment */ -int bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment, - bus_size_t boundary, bus_addr_t lowaddr, - bus_addr_t highaddr, bus_dma_filter_t *filtfunc, - void *filtfuncarg, bus_size_t maxsize, int nsegments, - bus_size_t maxsegsz, int flags, bus_dma_lock_t *lockfunc, - void *lockfuncarg, bus_dma_tag_t *dmat); - -int bus_dma_tag_destroy(bus_dma_tag_t dmat); - -/* - * Allocate a handle for mapping from kva/uva/physical - * address space into bus device space. - */ -int bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp); - -/* - * Destroy a handle for mapping from kva/uva/physical - * address space into bus device space. - */ -int bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map); - -/* - * Allocate a piece of memory that can be efficiently mapped into - * bus device space based on the constraints listed in the dma tag. - * A dmamap to for use with dmamap_load is also allocated. - */ -int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, - bus_dmamap_t *mapp); - -/* - * Free a piece of memory and its allocated dmamap, that was allocated - * via bus_dmamem_alloc. - */ -void bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map); - -/* - * A function that processes a successfully loaded dma map or an error - * from a delayed load map. - */ -typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int); - -/* - * Map the buffer buf into bus space using the dmamap map. - */ -int bus_dmamap_load(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf, - bus_size_t buflen, bus_dmamap_callback_t *callback, - void *callback_arg, int flags); - -/* - * Like bus_dmamap_callback but includes map size in bytes. This is - * defined as a separate interface to maintain compatibility for users - * of bus_dmamap_callback_t--at some point these interfaces should be merged. - */ -typedef void bus_dmamap_callback2_t(void *, bus_dma_segment_t *, int, bus_size_t, int); -/* - * Like bus_dmamap_load but for mbufs. Note the use of the - * bus_dmamap_callback2_t interface. - */ -int bus_dmamap_load_mbuf(bus_dma_tag_t dmat, bus_dmamap_t map, - struct mbuf *mbuf, - bus_dmamap_callback2_t *callback, void *callback_arg, - int flags); - -int bus_dmamap_load_mbuf_sg(bus_dma_tag_t dmat, bus_dmamap_t map, - struct mbuf *mbuf, bus_dma_segment_t *segs, - int *nsegs, int flags); - -/* - * Like bus_dmamap_load but for uios. Note the use of the - * bus_dmamap_callback2_t interface. - */ -int bus_dmamap_load_uio(bus_dma_tag_t dmat, bus_dmamap_t map, - struct uio *ui, - bus_dmamap_callback2_t *callback, void *callback_arg, - int flags); - -/* - * Perform a synchronization operation on the given map. - */ -void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_dmasync_op_t); -#define bus_dmamap_sync(dmat, dmamap, op) \ - if ((dmamap) != NULL) \ - _bus_dmamap_sync(dmat, dmamap, op) - -/* - * Release the mapping held by map. - */ -void _bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map); -#define bus_dmamap_unload(dmat, dmamap) \ - if ((dmamap) != NULL) \ - _bus_dmamap_unload(dmat, dmamap) - -/* - * Generic helper function for manipulating mutexes. - */ -void busdma_lock_mutex(void *arg, bus_dma_lock_op_t op); #endif /* _I386_BUS_DMA_H_ */ diff --git a/sys/ia64/include/bus.h b/sys/ia64/include/bus.h index 0f0f40c90ea4..3b50d8a820c9 100644 --- a/sys/ia64/include/bus.h +++ b/sys/ia64/include/bus.h @@ -851,199 +851,6 @@ bus_space_copy_region_8(bus_space_tag_t bst, bus_space_handle_t bsh1, #define bus_space_copy_region_stream_8(t, h1, o1, h2, o2, c) \ bus_space_copy_region_8(t, h1, o1, h2, o2, c) +#include <machine/bus_dma.h> -/* - * Flags used in various bus DMA methods. - */ -#define BUS_DMA_WAITOK 0x00 /* safe to sleep (pseudo-flag) */ -#define BUS_DMA_NOWAIT 0x01 /* not safe to sleep */ -#define BUS_DMA_ALLOCNOW 0x02 /* perform resource allocation now */ -#define BUS_DMA_COHERENT 0x04 /* hint: map memory in a coherent way */ -#define BUS_DMA_ZERO 0x08 /* allocate zero'ed memory */ -#define BUS_DMA_ISA 0x10 /* map memory for ISA dma */ -#define BUS_DMA_BUS2 0x20 /* placeholders for bus functions... */ -#define BUS_DMA_BUS3 0x40 -#define BUS_DMA_BUS4 0x80 - -/* Forwards needed by prototypes below. */ -struct mbuf; -struct uio; - -/* - * Operations performed by bus_dmamap_sync(). - */ -typedef int bus_dmasync_op_t; -#define BUS_DMASYNC_PREREAD 1 -#define BUS_DMASYNC_POSTREAD 2 -#define BUS_DMASYNC_PREWRITE 4 -#define BUS_DMASYNC_POSTWRITE 8 - -/* - * bus_dma_tag_t - * - * A machine-dependent opaque type describing the characteristics - * of how to perform DMA mappings. This structure encapsultes - * information concerning address and alignment restrictions, number - * of S/G segments, amount of data per S/G segment, etc. - */ -typedef struct bus_dma_tag *bus_dma_tag_t; - -/* - * bus_dmamap_t - * - * DMA mapping instance information. - */ -typedef struct bus_dmamap *bus_dmamap_t; - -/* - * bus_dma_segment_t - * - * Describes a single contiguous DMA transaction. Values - * are suitable for programming into DMA registers. - */ -typedef struct bus_dma_segment { - bus_addr_t ds_addr; /* DMA address */ - bus_size_t ds_len; /* length of transfer */ -} bus_dma_segment_t; - -/* - * A function that returns 1 if the address cannot be accessed by - * a device and 0 if it can be. - */ -typedef int bus_dma_filter_t(void *, bus_addr_t); - -/* - * A function that performs driver-specific syncronization on behalf of - * busdma. - */ -typedef enum { - BUS_DMA_LOCK = 0x01, - BUS_DMA_UNLOCK = 0x02, -} bus_dma_lock_op_t; - -typedef void bus_dma_lock_t(void *, bus_dma_lock_op_t); - -/* - * Allocate a device specific dma_tag encapsulating the constraints of - * the parent tag in addition to other restrictions specified: - * - * alignment: alignment for segments. - * boundary: Boundary that segments cannot cross. - * lowaddr: Low restricted address that cannot appear in a mapping. - * highaddr: High restricted addr. that cannot appear in a mapping. - * filtfunc: An optional function to further test if an address - * within the range of lowaddr and highaddr cannot appear - * in a mapping. - * filtfuncarg: An argument that will be passed to filtfunc in addition - * to the address to test. - * maxsize: Maximum mapping size supported by this tag. - * nsegments: Number of discontinuities allowed in maps. - * maxsegsz: Maximum size of a segment in the map. - * flags: Bus DMA flags. - * lockfunc: An optional function to handle driver-defined lock - * operations. - * lockfuncarg: An argument that will be passed to lockfunc in addition - * to the lock operation. - * dmat: A pointer to set to a valid dma tag should the return - * value of this function indicate success. - */ -/* XXX Should probably allow specification of alignment */ -int bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignemnt, - bus_size_t boundary, bus_addr_t lowaddr, bus_addr_t highaddr, - bus_dma_filter_t *filtfunc, void *filtfuncarg, bus_size_t maxsize, - int nsegments, bus_size_t maxsegsz, int flags, bus_dma_lock_t *lockfunc, - void *lockfuncarg, bus_dma_tag_t *dmat); - -int bus_dma_tag_destroy(bus_dma_tag_t dmat); - -/* - * Allocate a handle for mapping from kva/uva/physical - * address space into bus device space. - */ -int bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp); - -/* - * Destroy a handle for mapping from kva/uva/physical - * address space into bus device space. - */ -int bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map); - -/* - * Allocate a piece of memory that can be efficiently mapped into - * bus device space based on the constraints lited in the dma tag. - * A dmamap to for use with dmamap_load is also allocated. - */ -int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, - bus_dmamap_t *mapp); - -/* - * Free a piece of memory and it's allociated dmamap, that was allocated - * via bus_dmamem_alloc. - */ -void bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map); - -/* - * A function that processes a successfully loaded dma map or an error - * from a delayed load map. - */ -typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int); - -/* - * Map the buffer buf into bus space using the dmamap map. - */ -int bus_dmamap_load(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf, - bus_size_t buflen, bus_dmamap_callback_t *callback, void *callback_arg, - int flags); - -/* - * Like bus_dmamap_callback but includes map size in bytes. This is - * defined as a separate interface to maintain compatiiblity for users - * of bus_dmamap_callback_t--at some point these interfaces should be merged. - */ -typedef void bus_dmamap_callback2_t(void *, bus_dma_segment_t *, int, - bus_size_t, int); - -/* - * Like bus_dmamap_load but for mbufs. Note the use of the - * bus_dmamap_callback2_t interface. - */ -int bus_dmamap_load_mbuf(bus_dma_tag_t dmat, bus_dmamap_t map, - struct mbuf *mbuf, bus_dmamap_callback2_t *callback, void *callback_arg, - int flags); -int bus_dmamap_load_mbuf_sg(bus_dma_tag_t dmat, bus_dmamap_t map, - struct mbuf *mbuf, bus_dma_segment_t *segs, int *nsegs, int flags); - -/* - * Like bus_dmamap_load but for uios. Note the use of the - * bus_dmamap_callback2_t interface. - */ -int bus_dmamap_load_uio(bus_dma_tag_t dmat, bus_dmamap_t map, struct uio *ui, - bus_dmamap_callback2_t *callback, void *callback_arg, int flags); - -/* - * Perform a syncronization operation on the given map. - */ -void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, int); -static __inline void -bus_dmamap_sync(bus_dma_tag_t dmat, bus_dmamap_t dmamap, bus_dmasync_op_t op) -{ - if ((dmamap) != NULL) - _bus_dmamap_sync(dmat, dmamap, op); -} - -/* - * Release the mapping held by map. - */ -void _bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map); -static __inline void -bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t dmamap) -{ - if ((dmamap) != NULL) - _bus_dmamap_unload(dmat, dmamap); -} - -/* - * Generic helper function for manipulating mutexes. - */ -void busdma_lock_mutex(void *arg, bus_dma_lock_op_t op); #endif /* _MACHINE_BUS_H_ */ diff --git a/sys/ia64/include/bus_dma.h b/sys/ia64/include/bus_dma.h new file mode 100644 index 000000000000..0a80f2fd56d8 --- /dev/null +++ b/sys/ia64/include/bus_dma.h @@ -0,0 +1,33 @@ +/*- + * Copyright (c) 2005 Scott Long + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +/* $FreeBSD$ */ + +#ifndef _IA64_BUS_DMA_H_ +#define _IA64_BUS_DMA_H_ + +#include <sys/bus_dma.h> + +#endif /* _IA64_BUS_DMA_H_ */ diff --git a/sys/powerpc/include/bus.h b/sys/powerpc/include/bus.h index af47fc69420f..5892eefc22c6 100644 --- a/sys/powerpc/include/bus.h +++ b/sys/powerpc/include/bus.h @@ -740,187 +740,6 @@ bus_space_barrier(bus_space_tag_t tag __unused, #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t) -/* - * Bus DMA methods. - */ - -/* - * Flags used in various bus DMA methods. - */ -#define BUS_DMA_WAITOK 0x00 /* safe to sleep (pseudo-flag) */ -#define BUS_DMA_NOWAIT 0x01 /* not safe to sleep */ -#define BUS_DMA_ALLOCNOW 0x02 /* perform resource allocation now */ -#define BUS_DMA_COHERENT 0x04 /* hint: map memory DMA coherent */ -#define BUS_DMA_ZERO 0x08 /* allocate zero'ed memory */ -#define BUS_DMA_BUS1 0x10 /* placeholders for bus functions... */ -#define BUS_DMA_BUS2 0x20 -#define BUS_DMA_BUS3 0x40 -#define BUS_DMA_BUS4 0x80 - -/* Forwards needed by prototypes below. */ -struct mbuf; -struct uio; - -/* - * Operations performed by bus_dmamap_sync(). - */ -typedef int bus_dmasync_op_t; -#define BUS_DMASYNC_PREREAD 1 -#define BUS_DMASYNC_POSTREAD 2 -#define BUS_DMASYNC_PREWRITE 4 -#define BUS_DMASYNC_POSTWRITE 8 - -/* - * bus_dma_tag_t - * - * A machine-dependent opaque type describing the characteristics - * of how to perform DMA mappings. This structure encapsultes - * information concerning address and alignment restrictions, number - * of S/G segments, amount of data per S/G segment, etc. - */ -typedef struct bus_dma_tag *bus_dma_tag_t; - -/* - * bus_dmamap_t - * - * DMA mapping instance information. - */ -typedef struct bus_dmamap *bus_dmamap_t; - -/* - * bus_dma_segment_t - * - * Describes a single contiguous DMA transaction. Values - * are suitable for programming into DMA registers. - */ -typedef struct bus_dma_segment { - bus_addr_t ds_addr; /* DMA address */ - bus_size_t ds_len; /* length of transfer */ -} bus_dma_segment_t; - -/* - * A function that returns 1 if the address cannot be accessed by - * a device and 0 if it can be. - */ -typedef int bus_dma_filter_t(void *, bus_addr_t); - -/* - * A function that performs driver-specific syncronization on behalf of - * busdma. - */ -typedef enum { - BUS_DMA_LOCK = 0x01, - BUS_DMA_UNLOCK = 0x02, -} bus_dma_lock_op_t; - -typedef void bus_dma_lock_t(void *, bus_dma_lock_op_t); - -/* - * Allocate a device specific dma_tag encapsulating the constraints of - * the parent tag in addition to other restrictions specified: - * - * alignment: alignment for segments. - * boundary: Boundary that segments cannot cross. - * lowaddr: Low restricted address that cannot appear in a mapping. - * highaddr: High restricted address that cannot appear in a mapping. - * filtfunc: An optional function to further test if an address - * within the range of lowaddr and highaddr cannot appear - * in a mapping. - * filtfuncarg: An argument that will be passed to filtfunc in addition - * to the address to test. - * maxsize: Maximum mapping size supported by this tag. - * nsegments: Number of discontinuities allowed in maps. - * maxsegsz: Maximum size of a segment in the map. - * flags: Bus DMA flags. - * dmat: A pointer to set to a valid dma tag should the return - * value of this function indicate success. - */ -int bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment, - bus_size_t boundary, bus_addr_t lowaddr, - bus_addr_t highaddr, bus_dma_filter_t *filtfunc, - void *filtfuncarg, bus_size_t maxsize, int nsegments, - bus_size_t maxsegsz, int flags, bus_dma_lock_t *lockfunc, - void *lockfuncarg, bus_dma_tag_t *dmat); - -int bus_dma_tag_destroy(bus_dma_tag_t dmat); - -/* - * Allocate a handle for mapping from kva/uva/physical - * address space into bus device space. - */ -int bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp); - -/* - * Destroy a handle for mapping from kva/uva/physical - * address space into bus device space. - */ -int bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map); - -/* - * Allocate a piece of memory that can be efficiently mapped into - * bus device space based on the constraints lited in the dma tag. - * A dmamap to for use with dmamap_load is also allocated. - */ -int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, - bus_dmamap_t *mapp); +#include <machine/bus_dma.h> -/* - * Free a piece of memory and it's allociated dmamap, that was allocated - * via bus_dmamem_alloc. - */ -void bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map); - -/* - * A function that processes a successfully loaded dma map or an error - * from a delayed load map. - */ -typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int); - -/* - * Map the buffer buf into bus space using the dmamap map. - */ -int bus_dmamap_load(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf, - bus_size_t buflen, bus_dmamap_callback_t *callback, - void *callback_arg, int flags); - -/* - * Like bus_dmamap_callback but includes map size in bytes. This is - * defined as a separate interface to maintain compatiiblity for users - * of bus_dmamap_callback_t--at some point these interfaces should be merged. - */ -typedef void bus_dmamap_callback2_t(void *, bus_dma_segment_t *, int, bus_size_t, int); -/* - * Like bus_dmamap_load but for mbufs. Note the use of the - * bus_dmamap_callback2_t interface. - */ -int bus_dmamap_load_mbuf(bus_dma_tag_t dmat, bus_dmamap_t map, - struct mbuf *mbuf, - bus_dmamap_callback2_t *callback, void *callback_arg, - int flags); -int bus_dmamap_load_mbuf_sg(bus_dma_tag_t dmat, bus_dmamap_t map, - struct mbuf *mbuf, bus_dma_segment_t *segs, - int *nsegs, int flags); -/* - * Like bus_dmamap_load but for uios. Note the use of the - * bus_dmamap_callback2_t interface. - */ -int bus_dmamap_load_uio(bus_dma_tag_t dmat, bus_dmamap_t map, - struct uio *ui, - bus_dmamap_callback2_t *callback, void *callback_arg, - int flags); - -/* - * Perform a syncronization operation on the given map. - */ -void bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_dmasync_op_t); - -/* - * Release the mapping held by map. - */ -void bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map); - -/* - * Generic helper function for manipulating mutexes. - */ -void busdma_lock_mutex(void *arg, bus_dma_lock_op_t op); #endif /* _MACPPC_BUS_H_ */ diff --git a/sys/powerpc/include/bus_dma.h b/sys/powerpc/include/bus_dma.h new file mode 100644 index 000000000000..d10a0557bc6b --- /dev/null +++ b/sys/powerpc/include/bus_dma.h @@ -0,0 +1,33 @@ +/*- + * Copyright (c) 2005 Scott Long + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +/* $FreeBSD$ */ + +#ifndef _POWERPC_BUS_DMA_H_ +#define _POWERPC_BUS_DMA_H_ + +#include <sys/bus_dma.h> + +#endif /* _POWERPC_BUS_DMA_H_ */ diff --git a/sys/sparc64/include/bus.h b/sys/sparc64/include/bus.h index 86407bea0118..ed134af5d44c 100644 --- a/sys/sparc64/include/bus.h +++ b/sys/sparc64/include/bus.h @@ -910,152 +910,6 @@ memsetw(void *d, int val, size_t size) *sp++ = val; } -/* DMA support */ +#include <machine/bus_dma.h> -/* - * Flags used in various bus DMA methods. - */ -#define BUS_DMA_WAITOK 0x000 /* safe to sleep (pseudo-flag) */ -#define BUS_DMA_NOWAIT 0x001 /* not safe to sleep */ -#define BUS_DMA_ALLOCNOW 0x002 /* perform resource allocation now */ -#define BUS_DMA_COHERENT 0x004 /* hint: map memory in a coherent way */ -#define BUS_DMA_ZERO 0x008 /* allocate zero'ed memory */ -#define BUS_DMA_BUS1 0x010 -#define BUS_DMA_BUS2 0x020 -#define BUS_DMA_BUS3 0x040 -#define BUS_DMA_BUS4 0x080 - -/* The following two flags are non-standard. */ -#define BUS_DMA_NOWRITE 0x100 -#define BUS_DMA_NOCACHE 0x200 - -/* Forwards needed by prototypes below. */ -struct mbuf; -struct uio; - -typedef int bus_dmasync_op_t; -#define BUS_DMASYNC_PREREAD 1 -#define BUS_DMASYNC_POSTREAD 2 -#define BUS_DMASYNC_PREWRITE 4 -#define BUS_DMASYNC_POSTWRITE 8 - -/* - * A function that returns 1 if the address cannot be accessed by - * a device and 0 if it can be. - */ -typedef int bus_dma_filter_t(void *, bus_addr_t); - -typedef struct bus_dma_tag *bus_dma_tag_t; -typedef struct bus_dmamap *bus_dmamap_t; - -struct bus_dma_segment { - bus_addr_t ds_addr; /* DVMA address */ - bus_size_t ds_len; /* length of transfer */ -}; -typedef struct bus_dma_segment bus_dma_segment_t; - -/* - * A function that processes a successfully loaded dma map or an error - * from a delayed load map. - */ -typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int); - -/* - * Like bus_dmamap_callback but includes map size in bytes. This is - * defined as a separate interface to maintain compatiiblity for users - * of bus_dmamap_callback_t--at some point these interfaces should be merged. - */ -typedef void bus_dmamap_callback2_t(void *, bus_dma_segment_t *, int, bus_size_t, int); - -/* - * A function that performs driver-specific syncronization on behalf of - * busdma. - */ -typedef enum { - BUS_DMA_LOCK = 0x01, - BUS_DMA_UNLOCK = 0x02, -} bus_dma_lock_op_t; - -typedef void bus_dma_lock_t(void *, bus_dma_lock_op_t); - -/* - * Method table for a bus_dma_tag. - */ -struct bus_dma_methods { - int (*dm_dmamap_create)(bus_dma_tag_t, int, bus_dmamap_t *); - int (*dm_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t); - int (*dm_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *, - bus_size_t, bus_dmamap_callback_t *, void *, int); - int (*dm_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t, - struct mbuf *, bus_dmamap_callback2_t *, void *, int); - int (*dm_dmamap_load_mbuf_sg)(bus_dma_tag_t, bus_dmamap_t, - struct mbuf *, bus_dma_segment_t *segs, int *nsegs, int); - int (*dm_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t, struct uio *, - bus_dmamap_callback2_t *, void *, int); - void (*dm_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t); - void (*dm_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t, - bus_dmasync_op_t); - int (*dm_dmamem_alloc)(bus_dma_tag_t, void **, int, bus_dmamap_t *); - void (*dm_dmamem_free)(bus_dma_tag_t, void *, bus_dmamap_t); -}; - -/* - * bus_dma_tag_t - * - * A machine-dependent opaque type describing the implementation of - * DMA for a given bus. - */ -struct bus_dma_tag { - void *dt_cookie; /* cookie used in the guts */ - bus_dma_tag_t dt_parent; - bus_size_t dt_alignment; - bus_size_t dt_boundary; - bus_addr_t dt_lowaddr; - bus_addr_t dt_highaddr; - bus_dma_filter_t *dt_filter; - void *dt_filterarg; - bus_size_t dt_maxsize; - int dt_nsegments; - bus_size_t dt_maxsegsz; - int dt_flags; - int dt_ref_count; - int dt_map_count; - bus_dma_lock_t *dt_lockfunc; - void * *dt_lockfuncarg; - bus_dma_segment_t *dt_segments; - - struct bus_dma_methods *dt_mt; -}; - -int bus_dma_tag_create(bus_dma_tag_t, bus_size_t, bus_size_t, bus_addr_t, - bus_addr_t, bus_dma_filter_t *, void *, bus_size_t, int, bus_size_t, - int, bus_dma_lock_t *, void *, bus_dma_tag_t *); - -int bus_dma_tag_destroy(bus_dma_tag_t); - -#define bus_dmamap_create(t, f, p) \ - ((t)->dt_mt->dm_dmamap_create((t), (f), (p))) -#define bus_dmamap_destroy(t, p) \ - ((t)->dt_mt->dm_dmamap_destroy((t), (p))) -#define bus_dmamap_load(t, m, p, s, cb, cba, f) \ - ((t)->dt_mt->dm_dmamap_load((t), (m), (p), (s), (cb), (cba), (f))) -#define bus_dmamap_load_mbuf(t, m, mb, cb, cba, f) \ - ((t)->dt_mt->dm_dmamap_load_mbuf((t), (m), (mb), (cb), (cba), (f))) -#define bus_dmamap_load_mbuf_sg(t, m, mb, segs, nsegs, f) \ - ((t)->dt_mt->dm_dmamap_load_mbuf_sg((t), (m), (mb), (segs), (nsegs), (f))) -#define bus_dmamap_load_uio(t, m, ui, cb, cba, f) \ - ((t)->dt_mt->dm_dmamap_load_uio((t), (m), (ui), (cb), (cba), (f))) -#define bus_dmamap_unload(t, p) \ - ((t)->dt_mt->dm_dmamap_unload((t), (p))) -#define bus_dmamap_sync(t, m, op) \ - ((t)->dt_mt->dm_dmamap_sync((t), (m), (op))) -#define bus_dmamem_alloc(t, v, f, m) \ - ((t)->dt_mt->dm_dmamem_alloc((t), (v), (f), (m))) -#define bus_dmamem_free(t, v, m) \ - ((t)->dt_mt->dm_dmamem_free((t), (v), (m))) - -/* - * Generic helper function for manipulating mutexes. - */ -void busdma_lock_mutex(void *arg, bus_dma_lock_op_t op); #endif /* !_MACHINE_BUS_H_ */ diff --git a/sys/sparc64/include/bus_dma.h b/sys/sparc64/include/bus_dma.h new file mode 100644 index 000000000000..e2b89a1263a5 --- /dev/null +++ b/sys/sparc64/include/bus_dma.h @@ -0,0 +1,152 @@ +/*- + * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/* + * Copyright (c) 1997-1999 Eduardo E. Horvath. All rights reserved. + * Copyright (c) 1996 Charles M. Hannum. All rights reserved. + * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christopher G. Demetriou + * for the NetBSD Project. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * from: NetBSD: bus.h,v 1.28 2001/07/19 15:32:19 thorpej Exp + * and + * from: FreeBSD: src/sys/alpha/include/bus.h,v 1.9 2001/01/09 + * + * $FreeBSD$ + */ + +#ifndef _SPARC64_BUS_DMA_H +#define _SPARC64_BUS_DMA_H + +#include <sys/bus_dma.h> + +/* DMA support */ + +/* + * Method table for a bus_dma_tag. + */ +struct bus_dma_methods { + int (*dm_dmamap_create)(bus_dma_tag_t, int, bus_dmamap_t *); + int (*dm_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t); + int (*dm_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, bus_dmamap_callback_t *, void *, int); + int (*dm_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t, + struct mbuf *, bus_dmamap_callback2_t *, void *, int); + int (*dm_dmamap_load_mbuf_sg)(bus_dma_tag_t, bus_dmamap_t, + struct mbuf *, bus_dma_segment_t *segs, int *nsegs, int); + int (*dm_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t, struct uio *, + bus_dmamap_callback2_t *, void *, int); + void (*dm_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t); + void (*dm_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t, + bus_dmasync_op_t); + int (*dm_dmamem_alloc)(bus_dma_tag_t, void **, int, bus_dmamap_t *); + void (*dm_dmamem_free)(bus_dma_tag_t, void *, bus_dmamap_t); +}; + +/* + * bus_dma_tag_t + * + * A machine-dependent opaque type describing the implementation of + * DMA for a given bus. + */ +struct bus_dma_tag { + void *dt_cookie; /* cookie used in the guts */ + bus_dma_tag_t dt_parent; + bus_size_t dt_alignment; + bus_size_t dt_boundary; + bus_addr_t dt_lowaddr; + bus_addr_t dt_highaddr; + bus_dma_filter_t *dt_filter; + void *dt_filterarg; + bus_size_t dt_maxsize; + int dt_nsegments; + bus_size_t dt_maxsegsz; + int dt_flags; + int dt_ref_count; + int dt_map_count; + bus_dma_lock_t *dt_lockfunc; + void * *dt_lockfuncarg; + bus_dma_segment_t *dt_segments; + + struct bus_dma_methods *dt_mt; +}; + +#define bus_dmamap_create(t, f, p) \ + ((t)->dt_mt->dm_dmamap_create((t), (f), (p))) +#define bus_dmamap_destroy(t, p) \ + ((t)->dt_mt->dm_dmamap_destroy((t), (p))) +#define bus_dmamap_load(t, m, p, s, cb, cba, f) \ + ((t)->dt_mt->dm_dmamap_load((t), (m), (p), (s), (cb), (cba), (f))) +#define bus_dmamap_load_mbuf(t, m, mb, cb, cba, f) \ + ((t)->dt_mt->dm_dmamap_load_mbuf((t), (m), (mb), (cb), (cba), (f))) +#define bus_dmamap_load_mbuf_sg(t, m, mb, segs, nsegs, f) \ + ((t)->dt_mt->dm_dmamap_load_mbuf_sg((t), (m), (mb), (segs), (nsegs), (f))) +#define bus_dmamap_load_uio(t, m, ui, cb, cba, f) \ + ((t)->dt_mt->dm_dmamap_load_uio((t), (m), (ui), (cb), (cba), (f))) +#define bus_dmamap_unload(t, p) \ + ((t)->dt_mt->dm_dmamap_unload((t), (p))) +#define bus_dmamap_sync(t, m, op) \ + ((t)->dt_mt->dm_dmamap_sync((t), (m), (op))) +#define bus_dmamem_alloc(t, v, f, m) \ + ((t)->dt_mt->dm_dmamem_alloc((t), (v), (f), (m))) +#define bus_dmamem_free(t, v, m) \ + ((t)->dt_mt->dm_dmamem_free((t), (v), (m))) + +#endif /* !_SPARC64_BUS_DMA_H_ */ diff --git a/sys/sys/bus_dma.h b/sys/sys/bus_dma.h index 03d608576c87..0ef2c5f29cef 100644 --- a/sys/sys/bus_dma.h +++ b/sys/sys/bus_dma.h @@ -69,8 +69,16 @@ */ /* $FreeBSD$ */ -#ifndef _I386_BUS_DMA_H_ -#define _I386_BUS_DMA_H_ +#ifndef _BUS_DMA_H_ +#define _BUS_DMA_H_ + +/* + * Machine independent interface for mapping physical addresses to peripheral + * bus 'physical' addresses, and assisting with DMA operations. + * + * XXX This file is always included from <machine/bus_dma.h> and should not + * (yet) be included directly. + */ /* * Flags used in various bus DMA methods. @@ -85,6 +93,14 @@ #define BUS_DMA_BUS3 0x40 #define BUS_DMA_BUS4 0x80 +/* + * The following two flags are non-standard or specific to only certain + * architectures + */ +#define BUS_DMA_NOWRITE 0x100 +#define BUS_DMA_NOCACHE 0x200 +#define BUS_DMA_ISA 0x400 /* map memory for AXP ISA dma */ + /* Forwards needed by prototypes below. */ struct mbuf; struct uio; @@ -144,6 +160,11 @@ typedef enum { typedef void bus_dma_lock_t(void *, bus_dma_lock_op_t); /* + * Generic helper function for manipulating mutexes. + */ +void busdma_lock_mutex(void *arg, bus_dma_lock_op_t op); + +/* * Allocate a device specific dma_tag encapsulating the constraints of * the parent tag in addition to other restrictions specified: * @@ -178,6 +199,26 @@ int bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment, int bus_dma_tag_destroy(bus_dma_tag_t dmat); /* + * A function that processes a successfully loaded dma map or an error + * from a delayed load map. + */ +typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int); + +/* + * Like bus_dmamap_callback but includes map size in bytes. This is + * defined as a separate interface to maintain compatibility for users + * of bus_dmamap_callback_t--at some point these interfaces should be merged. + */ +typedef void bus_dmamap_callback2_t(void *, bus_dma_segment_t *, int, bus_size_t, int); + +/* + * XXX sparc64 uses the same interface, but a much different implementation. + * <machine/bus_dma.h> for the sparc64 arch contains the equivalent + * declarations. + */ +#if !defined(__sparc64__) + +/* * Allocate a handle for mapping from kva/uva/physical * address space into bus device space. */ @@ -204,12 +245,6 @@ int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, void bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map); /* - * A function that processes a successfully loaded dma map or an error - * from a delayed load map. - */ -typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int); - -/* * Map the buffer buf into bus space using the dmamap map. */ int bus_dmamap_load(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf, @@ -217,12 +252,6 @@ int bus_dmamap_load(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf, void *callback_arg, int flags); /* - * Like bus_dmamap_callback but includes map size in bytes. This is - * defined as a separate interface to maintain compatibility for users - * of bus_dmamap_callback_t--at some point these interfaces should be merged. - */ -typedef void bus_dmamap_callback2_t(void *, bus_dma_segment_t *, int, bus_size_t, int); -/* * Like bus_dmamap_load but for mbufs. Note the use of the * bus_dmamap_callback2_t interface. */ @@ -259,9 +288,6 @@ void _bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map); #define bus_dmamap_unload(dmat, dmamap) \ if ((dmamap) != NULL) \ _bus_dmamap_unload(dmat, dmamap) +#endif /* __sparc64__ */ -/* - * Generic helper function for manipulating mutexes. - */ -void busdma_lock_mutex(void *arg, bus_dma_lock_op_t op); -#endif /* _I386_BUS_DMA_H_ */ +#endif /* _BUS_DMA_H_ */ |