Home | History | Annotate | Line # | Download | only in include
bus_dma.h revision 1.4.2.1
      1 /* $NetBSD: bus_dma.h,v 1.4.2.1 2001/04/09 01:54:23 nathanw Exp $ */
      2 
      3 /*
      4  * This file was extracted from from alpha/include/bus.h
      5  * and should probably be resynced when needed.
      6  * Darrin B. Jewell <dbj (at) netbsd.org> Sat Jul 31 06:11:33 UTC 1999
      7  * original cvs id: NetBSD: bus.h,v 1.29 1999/06/18 04:49:24 cgd Exp
      8  */
      9 
     10 
     11 /*-
     12  * Copyright (c) 1997, 1998, 2001 The NetBSD Foundation, Inc.
     13  * All rights reserved.
     14  *
     15  * This code is derived from software contributed to The NetBSD Foundation
     16  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
     17  * NASA Ames Research Center.
     18  *
     19  * Redistribution and use in source and binary forms, with or without
     20  * modification, are permitted provided that the following conditions
     21  * are met:
     22  * 1. Redistributions of source code must retain the above copyright
     23  *    notice, this list of conditions and the following disclaimer.
     24  * 2. Redistributions in binary form must reproduce the above copyright
     25  *    notice, this list of conditions and the following disclaimer in the
     26  *    documentation and/or other materials provided with the distribution.
     27  * 3. All advertising materials mentioning features or use of this software
     28  *    must display the following acknowledgement:
     29  *	This product includes software developed by the NetBSD
     30  *	Foundation, Inc. and its contributors.
     31  * 4. Neither the name of The NetBSD Foundation nor the names of its
     32  *    contributors may be used to endorse or promote products derived
     33  *    from this software without specific prior written permission.
     34  *
     35  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     36  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     37  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     38  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     39  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     40  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     41  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     42  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     43  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     44  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     45  * POSSIBILITY OF SUCH DAMAGE.
     46  */
     47 
     48 /*
     49  * Copyright (c) 1996 Carnegie-Mellon University.
     50  * All rights reserved.
     51  *
     52  * Author: Chris G. Demetriou
     53  *
     54  * Permission to use, copy, modify and distribute this software and
     55  * its documentation is hereby granted, provided that both the copyright
     56  * notice and this permission notice appear in all copies of the
     57  * software, derivative works or modified versions, and any portions
     58  * thereof, and that both notices appear in supporting documentation.
     59  *
     60  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     61  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     62  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     63  *
     64  * Carnegie Mellon requests users of this software to return to
     65  *
     66  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     67  *  School of Computer Science
     68  *  Carnegie Mellon University
     69  *  Pittsburgh PA 15213-3890
     70  *
     71  * any improvements or extensions that they make and grant Carnegie the
     72  * rights to redistribute these changes.
     73  */
     74 
     75 #ifndef _NEXT68K_BUS_DMA_H_
     76 #define	_NEXT68K_BUS_DMA_H_
     77 
     78 /*
     79  * Bus DMA methods.
     80  */
     81 
     82 /*
     83  * Flags used in various bus DMA methods.
     84  */
     85 #define	BUS_DMA_WAITOK		0x00	/* safe to sleep (pseudo-flag) */
     86 #define	BUS_DMA_NOWAIT		0x01	/* not safe to sleep */
     87 #define	BUS_DMA_ALLOCNOW	0x02	/* perform resource allocation now */
     88 #define	BUS_DMA_COHERENT	0x04	/* hint: map memory DMA coherent */
     89 #define	BUS_DMA_STREAMING	0x08	/* hint: sequential, unidirectional */
     90 #define	BUS_DMA_BUS1		0x10	/* placeholders for bus functions... */
     91 #define	BUS_DMA_BUS2		0x20
     92 #define	BUS_DMA_BUS3		0x40
     93 #define	BUS_DMA_BUS4		0x80
     94 
     95 /* Forwards needed by prototypes below. */
     96 struct mbuf;
     97 struct uio;
     98 
     99 /*
    100  * Operations performed by bus_dmamap_sync().
    101  */
    102 #define	BUS_DMASYNC_PREREAD	0x01	/* pre-read synchronization */
    103 #define	BUS_DMASYNC_POSTREAD	0x02	/* post-read synchronization */
    104 #define	BUS_DMASYNC_PREWRITE	0x04	/* pre-write synchronization */
    105 #define	BUS_DMASYNC_POSTWRITE	0x08	/* post-write synchronization */
    106 
    107 typedef struct next68k_bus_dma_tag *bus_dma_tag_t;
    108 typedef struct next68k_bus_dmamap *bus_dmamap_t;
    109 
    110 /*
    111  *	bus_dma_segment_t
    112  *
    113  *	Describes a single contiguous DMA transaction.  Values
    114  *	are suitable for programming into DMA registers.
    115  */
    116 struct next68k_bus_dma_segment {
    117 	bus_addr_t	ds_addr;	/* DMA address */
    118 	bus_size_t	ds_len;		/* length of transfer */
    119 
    120 	/* Machine dependant fields: */
    121 	bus_size_t  ds_xfer_len;			/* length of successful transfer */
    122 };
    123 typedef struct next68k_bus_dma_segment	bus_dma_segment_t;
    124 
    125 /*
    126  *	bus_dma_tag_t
    127  *
    128  *	A machine-dependent opaque type describing the implementation of
    129  *	DMA for a given bus.
    130  */
    131 struct next68k_bus_dma_tag {
    132 	void	*_cookie;		/* cookie used in the guts */
    133 
    134 	/*
    135 	 * Some chipsets have a built-in boundary constraint, independent
    136 	 * of what the device requests.  This allows that boundary to
    137 	 * be specified.  If the device has a more restrictive contraint,
    138 	 * the map will use that, otherwise this boundary will be used.
    139 	 * This value is ignored if 0.
    140 	 */
    141 	bus_size_t _boundary;
    142 
    143 	/*
    144 	 * DMA mapping methods.
    145 	 */
    146 	int	(*_dmamap_create) __P((bus_dma_tag_t, bus_size_t, int,
    147 		    bus_size_t, bus_size_t, int, bus_dmamap_t *));
    148 	void	(*_dmamap_destroy) __P((bus_dma_tag_t, bus_dmamap_t));
    149 	int	(*_dmamap_load) __P((bus_dma_tag_t, bus_dmamap_t, void *,
    150 		    bus_size_t, struct proc *, int));
    151 	int	(*_dmamap_load_mbuf) __P((bus_dma_tag_t, bus_dmamap_t,
    152 		    struct mbuf *, int));
    153 	int	(*_dmamap_load_uio) __P((bus_dma_tag_t, bus_dmamap_t,
    154 		    struct uio *, int));
    155 	int	(*_dmamap_load_raw) __P((bus_dma_tag_t, bus_dmamap_t,
    156 		    bus_dma_segment_t *, int, bus_size_t, int));
    157 	void	(*_dmamap_unload) __P((bus_dma_tag_t, bus_dmamap_t));
    158 	void	(*_dmamap_sync) __P((bus_dma_tag_t, bus_dmamap_t,
    159 		    bus_addr_t, bus_size_t, int));
    160 
    161 	/*
    162 	 * DMA memory utility functions.
    163 	 */
    164 	int	(*_dmamem_alloc) __P((bus_dma_tag_t, bus_size_t, bus_size_t,
    165 		    bus_size_t, bus_dma_segment_t *, int, int *, int));
    166 	void	(*_dmamem_free) __P((bus_dma_tag_t,
    167 		    bus_dma_segment_t *, int));
    168 	int	(*_dmamem_map) __P((bus_dma_tag_t, bus_dma_segment_t *,
    169 		    int, size_t, caddr_t *, int));
    170 	void	(*_dmamem_unmap) __P((bus_dma_tag_t, caddr_t, size_t));
    171 	paddr_t	(*_dmamem_mmap) __P((bus_dma_tag_t, bus_dma_segment_t *,
    172 		    int, off_t, int, int));
    173 };
    174 
    175 #define	bus_dmamap_create(t, s, n, m, b, f, p)			\
    176 	(*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
    177 #define	bus_dmamap_destroy(t, p)				\
    178 	(*(t)->_dmamap_destroy)((t), (p))
    179 #define	bus_dmamap_load(t, m, b, s, p, f)			\
    180 	(*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
    181 #define	bus_dmamap_load_mbuf(t, m, b, f)			\
    182 	(*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
    183 #define	bus_dmamap_load_uio(t, m, u, f)				\
    184 	(*(t)->_dmamap_load_uio)((t), (m), (u), (f))
    185 #define	bus_dmamap_load_raw(t, m, sg, n, s, f)			\
    186 	(*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
    187 #define	bus_dmamap_unload(t, p)					\
    188 	(*(t)->_dmamap_unload)((t), (p))
    189 #define	bus_dmamap_sync(t, p, o, l, ops)			\
    190 	(*(t)->_dmamap_sync)((t), (p), (o), (l), (ops))
    191 #define	bus_dmamem_alloc(t, s, a, b, sg, n, r, f)		\
    192 	(*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
    193 #define	bus_dmamem_free(t, sg, n)				\
    194 	(*(t)->_dmamem_free)((t), (sg), (n))
    195 #define	bus_dmamem_map(t, sg, n, s, k, f)			\
    196 	(*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
    197 #define	bus_dmamem_unmap(t, k, s)				\
    198 	(*(t)->_dmamem_unmap)((t), (k), (s))
    199 #define	bus_dmamem_mmap(t, sg, n, o, p, f)			\
    200 	(*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
    201 
    202 /*
    203  *	bus_dmamap_t
    204  *
    205  *	Describes a DMA mapping.
    206  */
    207 struct next68k_bus_dmamap {
    208 	/*
    209 	 * PRIVATE MEMBERS: not for use by machine-independent code.
    210 	 */
    211 	bus_size_t	_dm_size;	/* largest DMA transfer mappable */
    212 	int		_dm_segcnt;	/* number of segs this map can map */
    213 	bus_size_t	_dm_maxsegsz;	/* largest possible segment */
    214 	bus_size_t	_dm_boundary;	/* don't cross this */
    215 	int		_dm_flags;	/* misc. flags */
    216 
    217 	/*
    218 	 * PUBLIC MEMBERS: these are used by machine-independent code.
    219 	 */
    220 	bus_size_t	dm_mapsize;	/* size of the mapping */
    221 	int		dm_nsegs;	/* # valid segments in mapping */
    222 	bus_dma_segment_t dm_segs[1];	/* segments; variable length */
    223 };
    224 
    225 #ifdef _NEXT68K_BUS_DMA_PRIVATE
    226 int	_bus_dmamap_create __P((bus_dma_tag_t, bus_size_t, int, bus_size_t,
    227 	    bus_size_t, int, bus_dmamap_t *));
    228 void	_bus_dmamap_destroy __P((bus_dma_tag_t, bus_dmamap_t));
    229 
    230 int	_bus_dmamap_load_direct __P((bus_dma_tag_t, bus_dmamap_t,
    231 	    void *, bus_size_t, struct proc *, int));
    232 int	_bus_dmamap_load_mbuf_direct __P((bus_dma_tag_t,
    233 	    bus_dmamap_t, struct mbuf *, int));
    234 int	_bus_dmamap_load_uio_direct __P((bus_dma_tag_t,
    235 	    bus_dmamap_t, struct uio *, int));
    236 int	_bus_dmamap_load_raw_direct __P((bus_dma_tag_t,
    237 	    bus_dmamap_t, bus_dma_segment_t *, int, bus_size_t, int));
    238 
    239 void	_bus_dmamap_unload __P((bus_dma_tag_t, bus_dmamap_t));
    240 void	_bus_dmamap_sync __P((bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
    241 	    bus_size_t, int));
    242 
    243 int	_bus_dmamem_alloc __P((bus_dma_tag_t tag, bus_size_t size,
    244 	    bus_size_t alignment, bus_size_t boundary,
    245 	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags));
    246 void	_bus_dmamem_free __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
    247 	    int nsegs));
    248 int	_bus_dmamem_map __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
    249 	    int nsegs, size_t size, caddr_t *kvap, int flags));
    250 void	_bus_dmamem_unmap __P((bus_dma_tag_t tag, caddr_t kva,
    251 	    size_t size));
    252 paddr_t	_bus_dmamem_mmap __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
    253 	    int nsegs, off_t off, int prot, int flags));
    254 #endif /* _NEXT68K_BUS_DMA_PRIVATE */
    255 
    256 #endif /* _NEXT68K_BUS_DMA_H_ */
    257