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