xref: /freebsd-12.1/sys/sparc64/include/bus_dma.h (revision 6ce70ec7)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-NetBSD AND BSD-4-Clause
3  *
4  * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9  * NASA Ames Research Center.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*
33  * Copyright (c) 1997-1999 Eduardo E. Horvath. All rights reserved.
34  * Copyright (c) 1996 Charles M. Hannum.  All rights reserved.
35  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
36  *
37  * Redistribution and use in source and binary forms, with or without
38  * modification, are permitted provided that the following conditions
39  * are met:
40  * 1. Redistributions of source code must retain the above copyright
41  *    notice, this list of conditions and the following disclaimer.
42  * 2. Redistributions in binary form must reproduce the above copyright
43  *    notice, this list of conditions and the following disclaimer in the
44  *    documentation and/or other materials provided with the distribution.
45  * 3. All advertising materials mentioning features or use of this software
46  *    must display the following acknowledgement:
47  *      This product includes software developed by Christopher G. Demetriou
48  *	for the NetBSD Project.
49  * 4. The name of the author may not be used to endorse or promote products
50  *    derived from this software without specific prior written permission
51  *
52  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
53  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
54  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
55  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
56  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
57  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
61  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62  *
63  * 	from: NetBSD: bus.h,v 1.58 2008/04/28 20:23:36 martin Exp
64  *	and
65  *	from: FreeBSD: src/sys/alpha/include/bus.h,v 1.9 2001/01/09
66  *
67  * $FreeBSD$
68  */
69 
70 #ifndef _SPARC64_BUS_DMA_H
71 #define _SPARC64_BUS_DMA_H
72 
73 #define WANT_INLINE_DMAMAP
74 #include <sys/bus_dma.h>
75 
76 /* DMA support */
77 
78 /*
79  * Method table for a bus_dma_tag.
80  */
81 struct bus_dma_methods {
82 	int	(*dm_dmamap_create)(bus_dma_tag_t, int, bus_dmamap_t *);
83 	int	(*dm_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t);
84 	int	(*dm_dmamap_load_phys)(bus_dma_tag_t dmat, bus_dmamap_t map,
85 	    vm_paddr_t buf, bus_size_t buflen, int flags,
86 	    bus_dma_segment_t *segs, int *segp);
87 	int	(*dm_dmamap_load_buffer)(bus_dma_tag_t dmat, bus_dmamap_t map,
88 	    void *buf, bus_size_t buflen, struct pmap *pmap, int flags,
89 	    bus_dma_segment_t *segs, int *segp);
90 	void	(*dm_dmamap_waitok)(bus_dma_tag_t dmat, bus_dmamap_t map,
91 	    struct memdesc *mem, bus_dmamap_callback_t *callback,
92 	    void *callback_arg);
93 	bus_dma_segment_t *(*dm_dmamap_complete)(bus_dma_tag_t dmat,
94 	    bus_dmamap_t map, bus_dma_segment_t *segs, int nsegs, int error);
95 	void	(*dm_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t);
96 	void	(*dm_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t,
97 	    bus_dmasync_op_t);
98 	int	(*dm_dmamem_alloc)(bus_dma_tag_t, void **, int, bus_dmamap_t *);
99 	void	(*dm_dmamem_free)(bus_dma_tag_t, void *, bus_dmamap_t);
100 };
101 
102 /*
103  * bus_dma_tag_t
104  *
105  * A machine-dependent opaque type describing the implementation of
106  * DMA for a given bus.
107  */
108 struct bus_dma_tag {
109 	void		*dt_cookie;		/* cookie used in the guts */
110 	bus_dma_tag_t	dt_parent;
111 	bus_size_t	dt_alignment;
112 	bus_addr_t	dt_boundary;
113 	bus_addr_t	dt_lowaddr;
114 	bus_addr_t	dt_highaddr;
115 	bus_dma_filter_t	*dt_filter;
116 	void		*dt_filterarg;
117 	bus_size_t	dt_maxsize;
118 	int		dt_nsegments;
119 	bus_size_t	dt_maxsegsz;
120 	int		dt_flags;
121 	int		dt_ref_count;
122 	int		dt_map_count;
123 	bus_dma_lock_t	*dt_lockfunc;
124 	void *		*dt_lockfuncarg;
125 	bus_dma_segment_t *dt_segments;
126 
127 	struct bus_dma_methods	*dt_mt;
128 };
129 
130 static inline int
bus_dmamap_create(bus_dma_tag_t dmat,int flags,bus_dmamap_t * mapp)131 bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp)
132 {
133 
134 	return (dmat->dt_mt->dm_dmamap_create(dmat, flags, mapp));
135 }
136 
137 static inline int
bus_dmamap_destroy(bus_dma_tag_t dmat,bus_dmamap_t map)138 bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map)
139 {
140 
141 	return (dmat->dt_mt->dm_dmamap_destroy(dmat, map));
142 }
143 
144 static inline void
bus_dmamap_sync(bus_dma_tag_t dmat,bus_dmamap_t map,bus_dmasync_op_t op)145 bus_dmamap_sync(bus_dma_tag_t dmat, bus_dmamap_t map, bus_dmasync_op_t op)
146 {
147 
148 	dmat->dt_mt->dm_dmamap_sync(dmat, map, op);
149 }
150 
151 static inline void
bus_dmamap_unload(bus_dma_tag_t dmat,bus_dmamap_t map)152 bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map)
153 {
154 
155 	dmat->dt_mt->dm_dmamap_unload(dmat, map);
156 }
157 
158 static inline int
bus_dmamem_alloc(bus_dma_tag_t dmat,void ** vaddr,int flags,bus_dmamap_t * mapp)159 bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, bus_dmamap_t *mapp)
160 {
161 
162 	return (dmat->dt_mt->dm_dmamem_alloc(dmat, vaddr, flags, mapp));
163 }
164 
165 static inline void
bus_dmamem_free(bus_dma_tag_t dmat,void * vaddr,bus_dmamap_t map)166 bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map)
167 {
168 
169 	dmat->dt_mt->dm_dmamem_free(dmat, vaddr, map);
170 }
171 
172 static inline bus_dma_segment_t*
_bus_dmamap_complete(bus_dma_tag_t dmat,bus_dmamap_t map,bus_dma_segment_t * segs,int nsegs,int error)173 _bus_dmamap_complete(bus_dma_tag_t dmat, bus_dmamap_t map,
174     bus_dma_segment_t *segs, int nsegs, int error)
175 {
176 
177 	return (dmat->dt_mt->dm_dmamap_complete(dmat, map, segs,
178 	    nsegs, error));
179 }
180 
181 static inline int
_bus_dmamap_load_buffer(bus_dma_tag_t dmat,bus_dmamap_t map,void * buf,bus_size_t buflen,struct pmap * pmap,int flags,bus_dma_segment_t * segs,int * segp)182 _bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dmamap_t map,
183     void *buf, bus_size_t buflen, struct pmap *pmap,
184     int flags, bus_dma_segment_t *segs, int *segp)
185 {
186 
187 	return (dmat->dt_mt->dm_dmamap_load_buffer(dmat, map, buf, buflen,
188 	    pmap, flags, segs, segp));
189 }
190 
191 static inline int
_bus_dmamap_load_ma(bus_dma_tag_t dmat,bus_dmamap_t map,struct vm_page ** ma,bus_size_t tlen,int ma_offs,int flags,bus_dma_segment_t * segs,int * segp)192 _bus_dmamap_load_ma(bus_dma_tag_t dmat, bus_dmamap_t map,
193     struct vm_page **ma, bus_size_t tlen, int ma_offs,
194     int flags, bus_dma_segment_t *segs, int *segp)
195 {
196 
197 	return (bus_dmamap_load_ma_triv(dmat, map, ma, tlen, ma_offs, flags,
198 	    segs, segp));
199 }
200 
201 static inline int
_bus_dmamap_load_phys(bus_dma_tag_t dmat,bus_dmamap_t map,vm_paddr_t paddr,bus_size_t buflen,int flags,bus_dma_segment_t * segs,int * segp)202 _bus_dmamap_load_phys(bus_dma_tag_t dmat, bus_dmamap_t map,
203     vm_paddr_t paddr, bus_size_t buflen,
204     int flags, bus_dma_segment_t *segs, int *segp)
205 {
206 
207 	return (dmat->dt_mt->dm_dmamap_load_phys(dmat, map, paddr, buflen,
208 	    flags, segs, segp));
209 }
210 
211 static inline void
_bus_dmamap_waitok(bus_dma_tag_t dmat,bus_dmamap_t map,struct memdesc * mem,bus_dmamap_callback_t * callback,void * callback_arg)212 _bus_dmamap_waitok(bus_dma_tag_t dmat, bus_dmamap_t map,
213     struct memdesc *mem, bus_dmamap_callback_t *callback,
214     void *callback_arg)
215 {
216 
217 	return (dmat->dt_mt->dm_dmamap_waitok(dmat, map, mem, callback,
218 	    callback_arg));
219 }
220 
221 #endif /* !_SPARC64_BUS_DMA_H_ */
222