1998-01-15 07:32:56 +00:00
|
|
|
/* $NetBSD: bus.h,v 1.12 1997/10/01 08:25:15 fvdl Exp $ */
|
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1996, 1997 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.
|
|
|
|
*/
|
|
|
|
|
2005-01-06 22:18:23 +00:00
|
|
|
/*-
|
1998-01-15 07:32:56 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
1999-08-28 01:08:13 +00:00
|
|
|
/* $FreeBSD$ */
|
1998-01-15 07:32:56 +00:00
|
|
|
|
2001-10-06 16:27:21 +00:00
|
|
|
#ifndef _I386_BUS_DMA_H_
|
|
|
|
#define _I386_BUS_DMA_H_
|
1998-01-15 07:32:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 */
|
2003-05-30 20:40:33 +00:00
|
|
|
#define BUS_DMA_COHERENT 0x04 /* hint: map memory in a coherent way */
|
2003-07-27 13:52:10 +00:00
|
|
|
#define BUS_DMA_ZERO 0x08 /* allocate zero'ed memory */
|
1998-01-15 07:32:56 +00:00
|
|
|
#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;
|
|
|
|
|
|
|
|
/*
|
2003-04-10 23:03:33 +00:00
|
|
|
* Operations performed by bus_dmamap_sync().
|
1998-01-15 07:32:56 +00:00
|
|
|
*/
|
2003-05-27 04:59:59 +00:00
|
|
|
typedef int bus_dmasync_op_t;
|
2003-04-10 23:03:33 +00:00
|
|
|
#define BUS_DMASYNC_PREREAD 1
|
|
|
|
#define BUS_DMASYNC_POSTREAD 2
|
|
|
|
#define BUS_DMASYNC_PREWRITE 4
|
|
|
|
#define BUS_DMASYNC_POSTWRITE 8
|
1998-01-15 07:32:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
2003-11-05 23:56:02 +00:00
|
|
|
* of S/G segments, amount of data per S/G segment, etc.
|
1998-01-15 07:32:56 +00:00
|
|
|
*/
|
|
|
|
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);
|
|
|
|
|
2003-07-01 15:52:06 +00:00
|
|
|
/*
|
2003-11-05 23:56:02 +00:00
|
|
|
* A function that performs driver-specific synchronization on behalf of
|
2003-07-01 15:52:06 +00:00
|
|
|
* 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);
|
|
|
|
|
1998-01-15 07:32:56 +00:00
|
|
|
/*
|
|
|
|
* Allocate a device specific dma_tag encapsulating the constraints of
|
|
|
|
* the parent tag in addition to other restrictions specified:
|
|
|
|
*
|
2003-11-05 23:56:02 +00:00
|
|
|
* alignment: Alignment for segments.
|
1998-01-15 07:32:56 +00:00
|
|
|
* 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.
|
1998-05-06 01:45:55 +00:00
|
|
|
* maxsize: Maximum mapping size supported by this tag.
|
|
|
|
* nsegments: Number of discontinuities allowed in maps.
|
|
|
|
* maxsegsz: Maximum size of a segment in the map.
|
1998-01-15 07:32:56 +00:00
|
|
|
* flags: Bus DMA flags.
|
2003-11-07 23:29:42 +00:00
|
|
|
* 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.
|
1998-01-15 07:32:56 +00:00
|
|
|
* dmat: A pointer to set to a valid dma tag should the return
|
|
|
|
* value of this function indicate success.
|
|
|
|
*/
|
1998-05-06 01:45:55 +00:00
|
|
|
/* XXX Should probably allow specification of alignment */
|
2001-06-16 15:28:28 +00:00
|
|
|
int bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment,
|
1998-05-06 01:45:55 +00:00
|
|
|
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,
|
2003-07-01 15:52:06 +00:00
|
|
|
bus_size_t maxsegsz, int flags, bus_dma_lock_t *lockfunc,
|
|
|
|
void *lockfuncarg, bus_dma_tag_t *dmat);
|
1998-01-15 07:32:56 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
/*
|
2003-11-05 23:56:02 +00:00
|
|
|
* Destroy a handle for mapping from kva/uva/physical
|
1998-01-15 07:32:56 +00:00
|
|
|
* address space into bus device space.
|
|
|
|
*/
|
|
|
|
int bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map);
|
|
|
|
|
1998-05-06 01:45:55 +00:00
|
|
|
/*
|
|
|
|
* Allocate a piece of memory that can be efficiently mapped into
|
2003-11-05 23:56:02 +00:00
|
|
|
* bus device space based on the constraints listed in the dma tag.
|
1998-05-06 01:45:55 +00:00
|
|
|
* 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);
|
|
|
|
|
|
|
|
/*
|
2003-11-05 23:56:02 +00:00
|
|
|
* Free a piece of memory and its allocated dmamap, that was allocated
|
1998-05-06 01:45:55 +00:00
|
|
|
* via bus_dmamem_alloc.
|
|
|
|
*/
|
|
|
|
void bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map);
|
|
|
|
|
1998-01-15 07:32:56 +00:00
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
|
2002-10-04 20:40:39 +00:00
|
|
|
/*
|
|
|
|
* Like bus_dmamap_callback but includes map size in bytes. This is
|
2003-11-05 23:56:02 +00:00
|
|
|
* defined as a separate interface to maintain compatibility for users
|
2002-10-04 20:40:39 +00:00
|
|
|
* 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);
|
2005-01-07 07:57:18 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2002-10-04 20:40:39 +00:00
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
|
1998-01-15 07:32:56 +00:00
|
|
|
/*
|
2003-11-05 23:56:02 +00:00
|
|
|
* Perform a synchronization operation on the given map.
|
1998-01-15 07:32:56 +00:00
|
|
|
*/
|
2003-05-27 04:59:59 +00:00
|
|
|
void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_dmasync_op_t);
|
1998-01-15 07:32:56 +00:00
|
|
|
#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)
|
|
|
|
|
2003-07-01 15:52:06 +00:00
|
|
|
/*
|
|
|
|
* Generic helper function for manipulating mutexes.
|
|
|
|
*/
|
|
|
|
void busdma_lock_mutex(void *arg, bus_dma_lock_op_t op);
|
2001-10-06 16:27:21 +00:00
|
|
|
#endif /* _I386_BUS_DMA_H_ */
|