xref: /openbsd-src/sys/arch/i386/include/bus.h (revision b0002153e68e19a4277a3f21e84cea855054f754)
1*b0002153Sdlg /*	$OpenBSD: bus.h,v 1.67 2017/05/08 00:27:45 dlg Exp $	*/
21efd494fSniklas /*	$NetBSD: bus.h,v 1.6 1996/11/10 03:19:25 thorpej Exp $	*/
39bb8a3b1Sniklas 
4c44e1821Sniklas /*-
5c44e1821Sniklas  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
6c44e1821Sniklas  * All rights reserved.
7c44e1821Sniklas  *
8c44e1821Sniklas  * This code is derived from software contributed to The NetBSD Foundation
9c44e1821Sniklas  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
10c44e1821Sniklas  * NASA Ames Research Center.
11c44e1821Sniklas  *
12c44e1821Sniklas  * Redistribution and use in source and binary forms, with or without
13c44e1821Sniklas  * modification, are permitted provided that the following conditions
14c44e1821Sniklas  * are met:
15c44e1821Sniklas  * 1. Redistributions of source code must retain the above copyright
16c44e1821Sniklas  *    notice, this list of conditions and the following disclaimer.
17c44e1821Sniklas  * 2. Redistributions in binary form must reproduce the above copyright
18c44e1821Sniklas  *    notice, this list of conditions and the following disclaimer in the
19c44e1821Sniklas  *    documentation and/or other materials provided with the distribution.
20c44e1821Sniklas  *
21c44e1821Sniklas  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22c44e1821Sniklas  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23c44e1821Sniklas  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24c44e1821Sniklas  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25c44e1821Sniklas  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26c44e1821Sniklas  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27c44e1821Sniklas  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28c44e1821Sniklas  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29c44e1821Sniklas  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30c44e1821Sniklas  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31c44e1821Sniklas  * POSSIBILITY OF SUCH DAMAGE.
32c44e1821Sniklas  */
33c44e1821Sniklas 
349bb8a3b1Sniklas /*
35ecbe32ebSniklas  * Copyright (c) 1996 Charles M. Hannum.  All rights reserved.
36ecbe32ebSniklas  * Copyright (c) 1996 Jason R. Thorpe.  All rights reserved.
379bb8a3b1Sniklas  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
389bb8a3b1Sniklas  *
399bb8a3b1Sniklas  * Redistribution and use in source and binary forms, with or without
409bb8a3b1Sniklas  * modification, are permitted provided that the following conditions
419bb8a3b1Sniklas  * are met:
429bb8a3b1Sniklas  * 1. Redistributions of source code must retain the above copyright
439bb8a3b1Sniklas  *    notice, this list of conditions and the following disclaimer.
449bb8a3b1Sniklas  * 2. Redistributions in binary form must reproduce the above copyright
459bb8a3b1Sniklas  *    notice, this list of conditions and the following disclaimer in the
469bb8a3b1Sniklas  *    documentation and/or other materials provided with the distribution.
479bb8a3b1Sniklas  * 3. All advertising materials mentioning features or use of this software
489bb8a3b1Sniklas  *    must display the following acknowledgement:
499bb8a3b1Sniklas  *	This product includes software developed by Christopher G. Demetriou
509bb8a3b1Sniklas  *	for the NetBSD Project.
519bb8a3b1Sniklas  * 4. The name of the author may not be used to endorse or promote products
529bb8a3b1Sniklas  *    derived from this software without specific prior written permission
539bb8a3b1Sniklas  *
549bb8a3b1Sniklas  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
559bb8a3b1Sniklas  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
569bb8a3b1Sniklas  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
579bb8a3b1Sniklas  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
589bb8a3b1Sniklas  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
599bb8a3b1Sniklas  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
609bb8a3b1Sniklas  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
619bb8a3b1Sniklas  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
629bb8a3b1Sniklas  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
639bb8a3b1Sniklas  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
649bb8a3b1Sniklas  */
659bb8a3b1Sniklas 
662fa72412Spirofti #ifndef _MACHINE_BUS_H_
672fa72412Spirofti #define _MACHINE_BUS_H_
689bb8a3b1Sniklas 
6912beee02Soga #include <sys/mutex.h>
703d6bf9c2Soga #include <sys/tree.h>
7112beee02Soga 
729bb8a3b1Sniklas #include <machine/pio.h>
739bb8a3b1Sniklas 
749bb8a3b1Sniklas /*
75ecbe32ebSniklas  * Bus address and size types
769bb8a3b1Sniklas  */
77ecbe32ebSniklas typedef u_long bus_addr_t;
78ecbe32ebSniklas typedef u_long bus_size_t;
799bb8a3b1Sniklas 
809bb8a3b1Sniklas /*
81ecbe32ebSniklas  * Access methods for bus resources and address space.
829bb8a3b1Sniklas  */
8380d7446cSsthen struct	i386_bus_space_ops;
8480d7446cSsthen typedef	const struct i386_bus_space_ops *bus_space_tag_t;
85ecbe32ebSniklas typedef	u_long bus_space_handle_t;
869bb8a3b1Sniklas 
87c4071fd1Smillert int	bus_space_map(bus_space_tag_t t, bus_addr_t addr,
882ab138fdSmiod 	    bus_size_t size, int flags, bus_space_handle_t *bshp);
89e77beeccSaaron /* like bus_space_map(), but without extent map checking/allocation */
90c4071fd1Smillert int	_bus_space_map(bus_space_tag_t t, bus_addr_t addr,
912ab138fdSmiod 	    bus_size_t size, int flags, bus_space_handle_t *bshp);
92c4071fd1Smillert void	bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh,
93c4071fd1Smillert 	    bus_size_t size);
94a365f409Sgrange /* like bus_space_unmap(), but without extent map deallocation */
95a365f409Sgrange void	_bus_space_unmap(bus_space_tag_t, bus_space_handle_t,
96a365f409Sgrange 	    bus_size_t, bus_addr_t *);
97c4071fd1Smillert int	bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh,
98c4071fd1Smillert 	    bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp);
998e7cf9b1Skettenis paddr_t	bus_space_mmap(bus_space_tag_t, bus_addr_t, off_t, int, int);
1009bb8a3b1Sniklas 
101c4071fd1Smillert int	bus_space_alloc(bus_space_tag_t t, bus_addr_t rstart,
102ecbe32ebSniklas 	    bus_addr_t rend, bus_size_t size, bus_size_t align,
1032ab138fdSmiod 	    bus_size_t boundary, int flags, bus_addr_t *addrp,
104c4071fd1Smillert 	    bus_space_handle_t *bshp);
105c4071fd1Smillert void	bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh,
106c4071fd1Smillert 	    bus_size_t size);
107ecbe32ebSniklas 
10880d7446cSsthen struct i386_bus_space_ops {
10980d7446cSsthen 
110ecbe32ebSniklas /*
111c4071fd1Smillert  *	u_intN_t bus_space_read_N(bus_space_tag_t tag,
112c4071fd1Smillert  *	    bus_space_handle_t bsh, bus_size_t offset);
113ecbe32ebSniklas  *
114ecbe32ebSniklas  * Read a 1, 2, 4, or 8 byte quantity from bus space
115ecbe32ebSniklas  * described by tag/handle/offset.
116ecbe32ebSniklas  */
11780d7446cSsthen 	u_int8_t	(*read_1)(bus_space_handle_t, bus_size_t);
11880d7446cSsthen 	u_int16_t	(*read_2)(bus_space_handle_t, bus_size_t);
11980d7446cSsthen 	u_int32_t	(*read_4)(bus_space_handle_t, bus_size_t);
120ecbe32ebSniklas 
12180d7446cSsthen #define bus_space_read_1(_t, _h, _o) ((_t)->read_1((_h), (_o)))
12280d7446cSsthen #define bus_space_read_2(_t, _h, _o) ((_t)->read_2((_h), (_o)))
12380d7446cSsthen #define bus_space_read_4(_t, _h, _o) ((_t)->read_4((_h), (_o)))
124ecbe32ebSniklas 
125aacc3e86Sdlg #define bus_space_read_raw_2(t, h, o) \
126aacc3e86Sdlg     bus_space_read_2((t), (h), (o))
127aacc3e86Sdlg #define bus_space_read_raw_4(t, h, o) \
128aacc3e86Sdlg     bus_space_read_4((t), (h), (o))
129aacc3e86Sdlg 
130aacc3e86Sdlg #if 0
131aacc3e86Sdlg /* Cause a link error for bus_space_read_8 and bus_space_read_raw_8 */
1324868469aSoga #define	bus_space_read_8(t, h, o)	!!! bus_space_read_8 unimplemented !!!
133aacc3e86Sdlg #define	bus_space_read_raw_8(t, h, o)	!!! bus_space_read_raw_8 unimplemented !!!
1344868469aSoga #endif
135ecbe32ebSniklas 
136ecbe32ebSniklas /*
137c4071fd1Smillert  *	void bus_space_read_multi_N(bus_space_tag_t tag,
138ecbe32ebSniklas  *	    bus_space_handle_t bsh, bus_size_t offset,
139c4071fd1Smillert  *	    u_intN_t *addr, size_t count);
140ecbe32ebSniklas  *
141ecbe32ebSniklas  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
142ecbe32ebSniklas  * described by tag/handle/offset and copy into buffer provided.
143ecbe32ebSniklas  */
144ecbe32ebSniklas 
14580d7446cSsthen 	void		(*read_multi_1)(bus_space_handle_t, bus_size_t,
146e77b97d3Ssthen 			    u_int8_t *, bus_size_t);
14780d7446cSsthen 	void		(*read_multi_2)(bus_space_handle_t, bus_size_t,
148e77b97d3Ssthen 			    u_int16_t *, bus_size_t);
14980d7446cSsthen 	void		(*read_multi_4)(bus_space_handle_t, bus_size_t,
150e77b97d3Ssthen 			    u_int32_t *, bus_size_t);
15185056c11Sdlg 
15280d7446cSsthen #define bus_space_read_multi_1(_t, _h, _o, _a, _c) \
15380d7446cSsthen 	((_t)->read_multi_1((_h), (_o), (_a), (_c)))
15480d7446cSsthen #define bus_space_read_multi_2(_t, _h, _o, _a, _c) \
15580d7446cSsthen 	((_t)->read_multi_2((_h), (_o), (_a), (_c)))
15680d7446cSsthen #define bus_space_read_multi_4(_t, _h, _o, _a, _c) \
15780d7446cSsthen 	((_t)->read_multi_4((_h), (_o), (_a), (_c)))
15880d7446cSsthen 
159ecbe32ebSniklas #if 0	/* Cause a link error for bus_space_read_multi_8 */
160ecbe32ebSniklas #define	bus_space_read_multi_8	!!! bus_space_read_multi_8 unimplemented !!!
161d724e01aSderaadt #endif
162d724e01aSderaadt 
163ecbe32ebSniklas /*
164c4071fd1Smillert  *	void bus_space_read_raw_multi_N(bus_space_tag_t tag,
165c0981ad2Sniklas  *	    bus_space_handle_t bsh, bus_size_t offset,
166c4071fd1Smillert  *	    u_int8_t *addr, size_t count);
167c0981ad2Sniklas  *
168c0981ad2Sniklas  * Read `count' bytes in 2, 4 or 8 byte wide quantities from bus space
169c0981ad2Sniklas  * described by tag/handle/offset and copy into buffer provided.  The buffer
170c0981ad2Sniklas  * must have proper alignment for the N byte wide entities.  Furthermore
171c0981ad2Sniklas  * possible byte-swapping should be done by these functions.
172c0981ad2Sniklas  */
173c0981ad2Sniklas 
174c0981ad2Sniklas #define	bus_space_read_raw_multi_2(t, h, o, a, c) \
175c0981ad2Sniklas     bus_space_read_multi_2((t), (h), (o), (u_int16_t *)(a), (c) >> 1)
176c0981ad2Sniklas #define	bus_space_read_raw_multi_4(t, h, o, a, c) \
177c0981ad2Sniklas     bus_space_read_multi_4((t), (h), (o), (u_int32_t *)(a), (c) >> 2)
178c0981ad2Sniklas 
179c0981ad2Sniklas #if 0	/* Cause a link error for bus_space_read_raw_multi_8 */
180c0981ad2Sniklas #define	bus_space_read_raw_multi_8 \
181c0981ad2Sniklas     !!! bus_space_read_raw_multi_8 unimplemented !!!
182c0981ad2Sniklas #endif
183c0981ad2Sniklas 
184c0981ad2Sniklas /*
185c4071fd1Smillert  *	void bus_space_read_region_N(bus_space_tag_t tag,
186ecbe32ebSniklas  *	    bus_space_handle_t bsh, bus_size_t offset,
187c4071fd1Smillert  *	    u_intN_t *addr, size_t count);
188ecbe32ebSniklas  *
189ecbe32ebSniklas  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
190ecbe32ebSniklas  * described by tag/handle and starting at `offset' and copy into
191ecbe32ebSniklas  * buffer provided.
192ecbe32ebSniklas  */
193ecbe32ebSniklas 
19480d7446cSsthen 	void		(*read_region_1)(bus_space_handle_t,
1954868469aSoga 			    bus_size_t, u_int8_t *, bus_size_t);
19680d7446cSsthen 	void		(*read_region_2)(bus_space_handle_t,
1974868469aSoga 			    bus_size_t, u_int16_t *, bus_size_t);
19880d7446cSsthen 	void		(*read_region_4)(bus_space_handle_t,
1994868469aSoga 			    bus_size_t, u_int32_t *, bus_size_t);
200ecbe32ebSniklas 
20180d7446cSsthen #define bus_space_read_region_1(_t, _h, _o, _a, _c) \
20280d7446cSsthen 	((_t)->read_region_1((_h), (_o), (_a), (_c)))
20380d7446cSsthen #define bus_space_read_region_2(_t, _h, _o, _a, _c) \
20480d7446cSsthen 	((_t)->read_region_2((_h), (_o), (_a), (_c)))
20580d7446cSsthen #define bus_space_read_region_4(_t, _h, _o, _a, _c) \
20680d7446cSsthen 	((_t)->read_region_4((_h), (_o), (_a), (_c)))
20780d7446cSsthen 
208ecbe32ebSniklas #if 0	/* Cause a link error for bus_space_read_region_8 */
209ecbe32ebSniklas #define	bus_space_read_region_8	!!! bus_space_read_region_8 unimplemented !!!
2109bb8a3b1Sniklas #endif
2119bb8a3b1Sniklas 
212ecbe32ebSniklas /*
213c4071fd1Smillert  *	void bus_space_read_raw_region_N(bus_space_tag_t tag,
2148b27e511Sniklas  *	    bus_space_handle_t bsh, bus_size_t offset,
215c4071fd1Smillert  *	    u_int8_t *addr, size_t count);
2168b27e511Sniklas  *
2178b27e511Sniklas  * Read `count' bytes in 2, 4 or 8 byte wide quantities from bus space
2188b27e511Sniklas  * described by tag/handle and starting at `offset' and copy into
2198b27e511Sniklas  * buffer provided.  The buffer must have proper alignment for the N byte
2208b27e511Sniklas  * wide entities.  Furthermore possible byte-swapping should be done by
2218b27e511Sniklas  * these functions.
2228b27e511Sniklas  */
2238b27e511Sniklas 
22480d7446cSsthen #define bus_space_read_raw_region_2(_t, _h, _o, _a, _c) \
22580d7446cSsthen 	((_t)->read_region_2((_h), (_o), (u_int16_t *)(_a), (_c) >> 1))
22680d7446cSsthen #define bus_space_read_raw_region_4(_t, _h, _o, _a, _c) \
22780d7446cSsthen 	((_t)->read_region_4((_h), (_o), (u_int32_t *)(_a), (_c) >> 2))
2288b27e511Sniklas 
2298b27e511Sniklas #if 0	/* Cause a link error for bus_space_read_raw_region_8 */
2308b27e511Sniklas #define	bus_space_read_raw_region_8 \
2318b27e511Sniklas     !!! bus_space_read_raw_region_8 unimplemented !!!
2328b27e511Sniklas #endif
2338b27e511Sniklas 
2348b27e511Sniklas /*
235c4071fd1Smillert  *	void bus_space_write_N(bus_space_tag_t tag,
236ecbe32ebSniklas  *	    bus_space_handle_t bsh, bus_size_t offset,
237c4071fd1Smillert  *	    u_intN_t value);
238ecbe32ebSniklas  *
239ecbe32ebSniklas  * Write the 1, 2, 4, or 8 byte value `value' to bus space
240ecbe32ebSniklas  * described by tag/handle/offset.
241ecbe32ebSniklas  */
242ecbe32ebSniklas 
24380d7446cSsthen 	void		(*write_1)(bus_space_handle_t, bus_size_t, u_int8_t);
24480d7446cSsthen 	void		(*write_2)(bus_space_handle_t, bus_size_t, u_int16_t);
24580d7446cSsthen 	void		(*write_4)(bus_space_handle_t, bus_size_t, u_int32_t);
24680d7446cSsthen 
24780d7446cSsthen #define bus_space_write_1(_t, _h, _o, _v) \
24880d7446cSsthen 	((_t)->write_1((_h), (_o), (_v)))
24980d7446cSsthen #define bus_space_write_2(_t, _h, _o, _v) \
25080d7446cSsthen 	((_t)->write_2((_h), (_o), (_v)))
25180d7446cSsthen #define bus_space_write_4(_t, _h, _o, _v) \
25280d7446cSsthen 	((_t)->write_4((_h), (_o), (_v)))
253ecbe32ebSniklas 
254aacc3e86Sdlg #define bus_space_write_raw_2(t, h, o, v) \
255aacc3e86Sdlg     bus_space_write_2((t), (h), (o), (v))
256aacc3e86Sdlg #define bus_space_write_raw_4(t, h, o, v) \
257aacc3e86Sdlg     bus_space_write_4((t), (h), (o), (v))
258aacc3e86Sdlg 
259aacc3e86Sdlg #if 0
260aacc3e86Sdlg /* Cause a link error for bus_space_write_8 and bus_space_write_raw_8  */
261ecbe32ebSniklas #define	bus_space_write_8	!!! bus_space_write_8 not implemented !!!
262aacc3e86Sdlg #define	bus_space_write_raw_8	!!! bus_space_write_raw_8 not implemented !!!
263d724e01aSderaadt #endif
264d724e01aSderaadt 
265ecbe32ebSniklas /*
266c4071fd1Smillert  *	void bus_space_write_multi_N(bus_space_tag_t tag,
267ecbe32ebSniklas  *	    bus_space_handle_t bsh, bus_size_t offset,
268c4071fd1Smillert  *	    const u_intN_t *addr, size_t count);
269ecbe32ebSniklas  *
270ecbe32ebSniklas  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
271ecbe32ebSniklas  * provided to bus space described by tag/handle/offset.
272ecbe32ebSniklas  */
2739bb8a3b1Sniklas 
27480d7446cSsthen 	void		(*write_multi_1)(bus_space_handle_t,
2754868469aSoga 			    bus_size_t, const u_int8_t *, bus_size_t);
27680d7446cSsthen 	void		(*write_multi_2)(bus_space_handle_t,
2774868469aSoga 			    bus_size_t, const u_int16_t *, bus_size_t);
27880d7446cSsthen 	void		(*write_multi_4)(bus_space_handle_t,
2794868469aSoga 			    bus_size_t, const u_int32_t *, bus_size_t);
280ecbe32ebSniklas 
28180d7446cSsthen #define bus_space_write_multi_1(_t, _h, _o, _a, _c) \
28280d7446cSsthen 	((_t)->write_multi_1((_h), (_o), (_a), (_c)))
28380d7446cSsthen #define bus_space_write_multi_2(_t, _h, _o, _a, _c) \
28480d7446cSsthen 	((_t)->write_multi_2((_h), (_o), (_a), (_c)))
28580d7446cSsthen #define bus_space_write_multi_4(_t, _h, _o, _a, _c) \
28680d7446cSsthen 	((_t)->write_multi_4((_h), (_o), (_a), (_c)))
28780d7446cSsthen 
288ecbe32ebSniklas #if 0	/* Cause a link error for bus_space_write_multi_8 */
289ecbe32ebSniklas #define	bus_space_write_multi_8(t, h, o, a, c)				\
29071775055Stodd 			!!! bus_space_write_multi_8 unimplemented !!!
291dcc1c779Sniklas #endif
2925ef2daf4Sniklas 
293ecbe32ebSniklas /*
294c4071fd1Smillert  *	void bus_space_write_raw_multi_N(bus_space_tag_t tag,
295c0981ad2Sniklas  *	    bus_space_handle_t bsh, bus_size_t offset,
296c4071fd1Smillert  *	    const u_int8_t *addr, size_t count);
297c0981ad2Sniklas  *
298c0981ad2Sniklas  * Write `count' bytes in 2, 4 or 8 byte wide quantities from the buffer
299c0981ad2Sniklas  * provided to bus space described by tag/handle/offset.  The buffer
300c0981ad2Sniklas  * must have proper alignment for the N byte wide entities.  Furthermore
301c0981ad2Sniklas  * possible byte-swapping should be done by these functions.
302c0981ad2Sniklas  */
303c0981ad2Sniklas 
30480d7446cSsthen #define bus_space_write_raw_multi_2(_t, _h, _o, _a, _c) \
30580d7446cSsthen 	((_t)->write_multi_2((_h), (_o), (const u_int16_t *)(_a), (_c) >> 1))
30680d7446cSsthen #define bus_space_write_raw_multi_4(_t, _h, _o, _a, _c) \
30780d7446cSsthen 	((_t)->write_multi_4((_h), (_o), (const u_int32_t *)(_a), (_c) >> 2))
308c0981ad2Sniklas 
309c0981ad2Sniklas #if 0	/* Cause a link error for bus_space_write_raw_multi_8 */
310c0981ad2Sniklas #define	bus_space_write_raw_multi_8 \
311c0981ad2Sniklas     !!! bus_space_write_raw_multi_8 unimplemented !!!
312c0981ad2Sniklas #endif
313c0981ad2Sniklas 
314c0981ad2Sniklas /*
315c4071fd1Smillert  *	void bus_space_write_region_N(bus_space_tag_t tag,
316ecbe32ebSniklas  *	    bus_space_handle_t bsh, bus_size_t offset,
317c4071fd1Smillert  *	    const u_intN_t *addr, size_t count);
318ecbe32ebSniklas  *
319ecbe32ebSniklas  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
320ecbe32ebSniklas  * to bus space described by tag/handle starting at `offset'.
321ecbe32ebSniklas  */
322ecbe32ebSniklas 
32380d7446cSsthen 	void		(*write_region_1)(bus_space_handle_t,
3244868469aSoga 			    bus_size_t, const u_int8_t *, bus_size_t);
32580d7446cSsthen 	void		(*write_region_2)(bus_space_handle_t,
3264868469aSoga 			    bus_size_t, const u_int16_t *, bus_size_t);
32780d7446cSsthen 	void		(*write_region_4)(bus_space_handle_t,
3284868469aSoga 			    bus_size_t, const u_int32_t *, bus_size_t);
329ecbe32ebSniklas 
33080d7446cSsthen #define bus_space_write_region_1(_t, _h, _o, _a, _c) \
33180d7446cSsthen 	((_t)->write_region_1((_h), (_o), (_a), (_c)))
33280d7446cSsthen #define bus_space_write_region_2(_t, _h, _o, _a, _c) \
33380d7446cSsthen 	((_t)->write_region_2((_h), (_o), (_a), (_c)))
33480d7446cSsthen #define bus_space_write_region_4(_t, _h, _o, _a, _c) \
33580d7446cSsthen 	((_t)->write_region_4((_h), (_o), (_a), (_c)))
33680d7446cSsthen 
337ecbe32ebSniklas #if 0	/* Cause a link error for bus_space_write_region_8 */
338ecbe32ebSniklas #define	bus_space_write_region_8					\
339ecbe32ebSniklas 			!!! bus_space_write_region_8 unimplemented !!!
340dcc1c779Sniklas #endif
3415ef2daf4Sniklas 
342ecbe32ebSniklas /*
343c4071fd1Smillert  *	void bus_space_write_raw_region_N(bus_space_tag_t tag,
3448b27e511Sniklas  *	    bus_space_handle_t bsh, bus_size_t offset,
345c4071fd1Smillert  *	    const u_int8_t *addr, size_t count);
3468b27e511Sniklas  *
3478b27e511Sniklas  * Write `count' bytes in 2, 4 or 8 byte wide quantities to bus space
3488b27e511Sniklas  * described by tag/handle and starting at `offset' from the
3498b27e511Sniklas  * buffer provided.  The buffer must have proper alignment for the N byte
3508b27e511Sniklas  * wide entities.  Furthermore possible byte-swapping should be done by
3518b27e511Sniklas  * these functions.
3528b27e511Sniklas  */
3538b27e511Sniklas 
35480d7446cSsthen #define bus_space_write_raw_region_2(_t, _h, _o, _a, _c) \
35580d7446cSsthen 	((_t)->write_region_2((_h), (_o), (const u_int16_t *)(_a), (_c) >> 1))
35680d7446cSsthen #define bus_space_write_raw_region_4(_t, _h, _o, _a, _c) \
35780d7446cSsthen 	((_t)->write_region_4((_h), (_o), (const u_int32_t *)(_a), (_c) >> 2))
3588b27e511Sniklas 
3598b27e511Sniklas #if 0	/* Cause a link error for bus_space_write_raw_region_8 */
3608b27e511Sniklas #define	bus_space_write_raw_region_8 \
3618b27e511Sniklas     !!! bus_space_write_raw_region_8 unimplemented !!!
3628b27e511Sniklas #endif
3638b27e511Sniklas 
3648b27e511Sniklas /*
365c4071fd1Smillert  *	void bus_space_set_multi_N(bus_space_tag_t tag,
3668a5c44b7Smickey  *	    bus_space_handle_t bsh, bus_size_t offset,
367c4071fd1Smillert  *	    u_intN_t val, size_t count);
368ecbe32ebSniklas  *
369ecbe32ebSniklas  * Write the 1, 2, 4, or 8 byte value `val' to bus space described
370ecbe32ebSniklas  * by tag/handle/offset `count' times.
371ecbe32ebSniklas  */
372ecbe32ebSniklas 
37380d7446cSsthen 	void		(*set_multi_1)(bus_space_handle_t,
3744868469aSoga 			    bus_size_t, u_int8_t, size_t);
37580d7446cSsthen 	void		(*set_multi_2)(bus_space_handle_t,
3764868469aSoga 			    bus_size_t, u_int16_t, size_t);
37780d7446cSsthen 	void		(*set_multi_4)(bus_space_handle_t,
3784868469aSoga 			    bus_size_t, u_int32_t, size_t);
3798a5c44b7Smickey 
38080d7446cSsthen #define bus_space_set_multi_1(_t, _h, _o, _a, _c) \
38180d7446cSsthen 	((_t)->set_multi_1((_h), (_o), (_a), (_c)))
38280d7446cSsthen #define bus_space_set_multi_2(_t, _h, _o, _a, _c) \
38380d7446cSsthen 	((_t)->set_multi_2((_h), (_o), (_a), (_c)))
38480d7446cSsthen #define bus_space_set_multi_4(_t, _h, _o, _a, _c) \
38580d7446cSsthen 	((_t)->set_multi_4((_h), (_o), (_a), (_c)))
38680d7446cSsthen 
387a565967eSniklas #if 0	/* Cause a link error for bus_space_set_multi_8 */
3888a5c44b7Smickey #define	bus_space_set_multi_8					\
3898a5c44b7Smickey 			!!! bus_space_set_multi_8 unimplemented !!!
3908a5c44b7Smickey #endif
391ecbe32ebSniklas 
392ecbe32ebSniklas /*
393c4071fd1Smillert  *	void bus_space_set_region_N(bus_space_tag_t tag,
3948a5c44b7Smickey  *	    bus_space_handle_t bsh, bus_size_t offset,
395c4071fd1Smillert  *	    u_intN_t val, size_t count);
396ecbe32ebSniklas  *
397ecbe32ebSniklas  * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
398ecbe32ebSniklas  * by tag/handle starting at `offset'.
399ecbe32ebSniklas  */
40080d7446cSsthen 
40180d7446cSsthen 	void		(*set_region_1)(bus_space_handle_t,
4024868469aSoga 			    bus_size_t, u_int8_t, size_t);
40380d7446cSsthen 	void		(*set_region_2)(bus_space_handle_t,
4044868469aSoga 			    bus_size_t, u_int16_t, size_t);
40580d7446cSsthen 	void		(*set_region_4)(bus_space_handle_t,
4064868469aSoga 			    bus_size_t, u_int32_t, size_t);
407ecbe32ebSniklas 
40880d7446cSsthen #define bus_space_set_region_1(_t, _h, _o, _a, _c) \
40980d7446cSsthen 	((_t)->set_region_1((_h), (_o), (_a), (_c)))
41080d7446cSsthen #define bus_space_set_region_2(_t, _h, _o, _a, _c) \
41180d7446cSsthen 	((_t)->set_region_2((_h), (_o), (_a), (_c)))
41280d7446cSsthen #define bus_space_set_region_4(_t, _h, _o, _a, _c) \
41380d7446cSsthen 	((_t)->set_region_4((_h), (_o), (_a), (_c)))
4148a5c44b7Smickey 
4158a5c44b7Smickey #if 0	/* Cause a link error for bus_space_set_region_8 */
4168a5c44b7Smickey #define	bus_space_set_region_8					\
4178a5c44b7Smickey 			!!! bus_space_set_region_8 unimplemented !!!
4188a5c44b7Smickey #endif
419ecbe32ebSniklas 
420ecbe32ebSniklas /*
421c4071fd1Smillert  *	void bus_space_copy_N(bus_space_tag_t tag,
422ecbe32ebSniklas  *	    bus_space_handle_t bsh1, bus_size_t off1,
423ecbe32ebSniklas  *	    bus_space_handle_t bsh2, bus_size_t off2,
424c4071fd1Smillert  *	    size_t count);
425ecbe32ebSniklas  *
426ecbe32ebSniklas  * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
427ecbe32ebSniklas  * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
428ecbe32ebSniklas  */
429ecbe32ebSniklas 
43080d7446cSsthen 	void		(*copy_1)(bus_space_handle_t,
43180d7446cSsthen 			    bus_size_t, bus_space_handle_t, bus_size_t, size_t);
43280d7446cSsthen 	void		(*copy_2)(bus_space_handle_t,
43380d7446cSsthen 			    bus_size_t, bus_space_handle_t, bus_size_t, size_t);
43480d7446cSsthen 	void		(*copy_4)(bus_space_handle_t,
43580d7446cSsthen 			    bus_size_t, bus_space_handle_t, bus_size_t, size_t);
43680d7446cSsthen 
43780d7446cSsthen #define bus_space_copy_1(_t, _h1, _o1, _h2, _o2, _c) \
43880d7446cSsthen 	((_t)->copy_1((_h1), (_o1), (_h2), (_o2), (_c)))
43980d7446cSsthen #define bus_space_copy_2(_t, _h1, _o1, _h2, _o2, _c) \
44080d7446cSsthen 	((_t)->copy_2((_h1), (_o1), (_h2), (_o2), (_c)))
44180d7446cSsthen #define bus_space_copy_4(_t, _h1, _o1, _h2, _o2, _c) \
44280d7446cSsthen 	((_t)->copy_4((_h1), (_o1), (_h2), (_o2), (_c)))
4438a5c44b7Smickey 
44487694f8dSniklas #if 0	/* Cause a link error for bus_space_copy_8 */
4458a5c44b7Smickey #define	bus_space_copy_8					\
4468a5c44b7Smickey 			!!! bus_space_copy_8 unimplemented !!!
4478a5c44b7Smickey #endif
448ecbe32ebSniklas 
4498574a60aSmickey #define	i386_space_copy1(a1, a2, cnt, movs, df)		\
4502df76cc2Sguenther 	__asm volatile(df "\n\trep\n\t" movs :		\
4518574a60aSmickey 	    "+S" (a1), "+D" (a2), "+c" (cnt)	:: "memory", "cc");
4528574a60aSmickey 
4538574a60aSmickey #define	i386_space_copy(a1, a2, sz, cnt) do {				\
454cc2d5520Smickey 	if ((void *)(a1) < (void *)(a2)) {				\
455fe96dbb9Smickey 		a1 += ((cnt) - 1) * (sz); a2 += ((cnt) - 1) * (sz);	\
4568574a60aSmickey 		switch (sz) {						\
4578574a60aSmickey 		case 1:	i386_space_copy1(a1,a2,cnt,"movsb","std");break;\
4588574a60aSmickey 		case 2:	i386_space_copy1(a1,a2,cnt,"movsw","std");break;\
4598574a60aSmickey 		case 4:	i386_space_copy1(a1,a2,cnt,"movsl","std");break;\
4608574a60aSmickey 		}							\
4618367b419Sguenther 		__asm volatile("cld");	/* must restore before func ret */ \
4628574a60aSmickey 	} else								\
4638574a60aSmickey 		switch (sz) {						\
4648574a60aSmickey 		case 1:	i386_space_copy1(a1,a2,cnt,"movsb","cld");break;\
4658574a60aSmickey 		case 2:	i386_space_copy1(a1,a2,cnt,"movsw","cld");break;\
4668574a60aSmickey 		case 4:	i386_space_copy1(a1,a2,cnt,"movsl","cld");break;\
4678574a60aSmickey 		}							\
4688574a60aSmickey } while (0)
4698574a60aSmickey 
470ecbe32ebSniklas /*
47180d7446cSsthen  *	void *bus_space_vaddr(bus_space_tag_t, bus_space_handle_t);
47280d7446cSsthen  *
47380d7446cSsthen  * Get the kernel virtual address for the mapped bus space.
47480d7446cSsthen  * Only allowed for regions mapped with BUS_SPACE_MAP_LINEAR.
47580d7446cSsthen  */
47680d7446cSsthen 	void *		(*vaddr)(bus_space_handle_t);
47780d7446cSsthen 
47880d7446cSsthen #define bus_space_vaddr(_t, _h) \
47980d7446cSsthen 	((_t)->vaddr((_h)))
48080d7446cSsthen };
48180d7446cSsthen 
48280d7446cSsthen /*
483ecbe32ebSniklas  * Bus read/write barrier methods.
484ecbe32ebSniklas  *
485c4071fd1Smillert  *	void bus_space_barrier(bus_space_tag_t tag,
486ecbe32ebSniklas  *	    bus_space_handle_t bsh, bus_size_t offset,
487c4071fd1Smillert  *	    bus_size_t len, int flags);
488ecbe32ebSniklas  *
489ecbe32ebSniklas  * Note: the i386 does not currently require barriers, but we must
490ecbe32ebSniklas  * provide the flags to MI code.
491ecbe32ebSniklas  */
49267421e49Skettenis #define	bus_space_barrier(t, h, o, l, f) do {				\
49367421e49Skettenis 	((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)));\
4942df76cc2Sguenther 	__asm volatile("" : : : "memory");				\
49567421e49Skettenis } while (0)
4968b27e511Sniklas #define	BUS_SPACE_BARRIER_READ	0x01		/* force read barrier */
4978b27e511Sniklas #define	BUS_SPACE_BARRIER_WRITE	0x02		/* force write barrier */
4987107682fSmiod 
499808436bbSmarco #define	BUS_SPACE_MAP_CACHEABLE		0x0001
500808436bbSmarco #define	BUS_SPACE_MAP_LINEAR		0x0002
501808436bbSmarco #define	BUS_SPACE_MAP_PREFETCHABLE	0x0008
502808436bbSmarco 
503808436bbSmarco /*
50480d7446cSsthen  * Values for the i386 bus space tag, not to be used directly by MI code.
505808436bbSmarco  */
50680d7446cSsthen 
50780d7446cSsthen /* space is i/o space */
50880d7446cSsthen extern const struct i386_bus_space_ops i386_bus_space_io_ops;
50980d7446cSsthen #define	I386_BUS_SPACE_IO	(&i386_bus_space_io_ops)
51080d7446cSsthen 
51180d7446cSsthen /* space is mem space */
51280d7446cSsthen extern const struct i386_bus_space_ops i386_bus_space_mem_ops;
51380d7446cSsthen #define I386_BUS_SPACE_MEM	(&i386_bus_space_mem_ops)
514ecbe32ebSniklas 
515c44e1821Sniklas /*
516c44e1821Sniklas  * Flags used in various bus DMA methods.
517c44e1821Sniklas  */
518471ccd18Soga #define	BUS_DMA_WAITOK		0x0000	/* safe to sleep (pseudo-flag) */
519471ccd18Soga #define	BUS_DMA_NOWAIT		0x0001	/* not safe to sleep */
520471ccd18Soga #define	BUS_DMA_ALLOCNOW	0x0002	/* perform resource allocation now */
521471ccd18Soga #define	BUS_DMA_COHERENT	0x0004	/* hint: map memory DMA coherent */
522471ccd18Soga #define	BUS_DMA_BUS1		0x0010	/* placeholders for bus functions... */
523471ccd18Soga #define	BUS_DMA_BUS2		0x0020
524471ccd18Soga #define	BUS_DMA_BUS3		0x0040
525471ccd18Soga #define	BUS_DMA_24BIT		0x0080	/* isadma map */
526471ccd18Soga #define	BUS_DMA_STREAMING	0x0100	/* hint: sequential, unidirectional */
527471ccd18Soga #define	BUS_DMA_READ		0x0200	/* mapping is device -> memory only */
528471ccd18Soga #define	BUS_DMA_WRITE		0x0400	/* mapping is memory -> device only */
529471ccd18Soga #define	BUS_DMA_NOCACHE		0x0800	/* map memory uncached */
530471ccd18Soga #define	BUS_DMA_ZERO		0x1000	/* dmamem_alloc return zeroed mem */
531*b0002153Sdlg #define	BUS_DMA_64BIT		0x2000	/* device handles 64bit dva */
5323d6bf9c2Soga 
533c44e1821Sniklas /* Forwards needed by prototypes below. */
534c44e1821Sniklas struct mbuf;
53502a233baSniklas struct proc;
536c44e1821Sniklas struct uio;
537c44e1821Sniklas 
538c44e1821Sniklas /*
539c44e1821Sniklas  * Operations performed by bus_dmamap_sync().
540c44e1821Sniklas  */
5410065d83cSart #define BUS_DMASYNC_PREREAD	0x01
5420065d83cSart #define BUS_DMASYNC_POSTREAD	0x02
5430065d83cSart #define BUS_DMASYNC_PREWRITE	0x04
5440065d83cSart #define BUS_DMASYNC_POSTWRITE	0x08
545c44e1821Sniklas 
54613fad3d0Soga typedef struct bus_dma_tag		*bus_dma_tag_t;
54713fad3d0Soga typedef struct bus_dmamap		*bus_dmamap_t;
548c44e1821Sniklas 
549c44e1821Sniklas /*
550c44e1821Sniklas  *	bus_dma_segment_t
551c44e1821Sniklas  *
552c44e1821Sniklas  *	Describes a single contiguous DMA transaction.  Values
553c44e1821Sniklas  *	are suitable for programming into DMA registers.
554c44e1821Sniklas  */
55513fad3d0Soga struct bus_dma_segment {
556c44e1821Sniklas 	bus_addr_t	ds_addr;	/* DMA address */
557c44e1821Sniklas 	bus_size_t	ds_len;		/* length of transfer */
55812beee02Soga 	/*
55912beee02Soga 	 * Ugh. need this so can pass alignment down from bus_dmamem_alloc
56012beee02Soga 	 * to scatter gather maps. only the first one is used so the rest is
56112beee02Soga 	 * wasted space. bus_dma could do with fixing the api for this.
56212beee02Soga 	 */
56312beee02Soga 	 bus_size_t	_ds_boundary;	/* don't cross */
56412beee02Soga 	 bus_size_t	_ds_align;	/* align to me */
565c44e1821Sniklas };
56613fad3d0Soga typedef struct bus_dma_segment	bus_dma_segment_t;
567c44e1821Sniklas 
568c44e1821Sniklas /*
569c44e1821Sniklas  *	bus_dma_tag_t
570c44e1821Sniklas  *
571c44e1821Sniklas  *	A machine-dependent opaque type describing the implementation of
572c44e1821Sniklas  *	DMA for a given bus.
573c44e1821Sniklas  */
574c44e1821Sniklas 
57513fad3d0Soga struct bus_dma_tag {
576c44e1821Sniklas 	void	*_cookie;		/* cookie used in the guts */
577c44e1821Sniklas 
578c44e1821Sniklas 	/*
579c44e1821Sniklas 	 * DMA mapping methods.
580c44e1821Sniklas 	 */
581c4071fd1Smillert 	int	(*_dmamap_create)(bus_dma_tag_t, bus_size_t, int,
582c4071fd1Smillert 		    bus_size_t, bus_size_t, int, bus_dmamap_t *);
583c4071fd1Smillert 	void	(*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t);
584c4071fd1Smillert 	int	(*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *,
585c4071fd1Smillert 		    bus_size_t, struct proc *, int);
586c4071fd1Smillert 	int	(*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t,
587c4071fd1Smillert 		    struct mbuf *, int);
588c4071fd1Smillert 	int	(*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t,
589c4071fd1Smillert 		    struct uio *, int);
590c4071fd1Smillert 	int	(*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t,
591c4071fd1Smillert 		    bus_dma_segment_t *, int, bus_size_t, int);
592c4071fd1Smillert 	void	(*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t);
593c4071fd1Smillert 	void	(*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t,
594c4071fd1Smillert 		    bus_addr_t, bus_size_t, int);
595c44e1821Sniklas 
596c44e1821Sniklas 	/*
597c44e1821Sniklas 	 * DMA memory utility functions.
598c44e1821Sniklas 	 */
599c4071fd1Smillert 	int	(*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t,
600c4071fd1Smillert 		    bus_size_t, bus_dma_segment_t *, int, int *, int);
6013df3eb3bSkettenis 	int	(*_dmamem_alloc_range)(bus_dma_tag_t, bus_size_t, bus_size_t,
6023df3eb3bSkettenis 		    bus_size_t, bus_dma_segment_t *, int, int *, int,
6033df3eb3bSkettenis 		    bus_addr_t, bus_addr_t);
604c4071fd1Smillert 	void	(*_dmamem_free)(bus_dma_tag_t,
605c4071fd1Smillert 		    bus_dma_segment_t *, int);
606c4071fd1Smillert 	int	(*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *,
607c4071fd1Smillert 		    int, size_t, caddr_t *, int);
608c4071fd1Smillert 	void	(*_dmamem_unmap)(bus_dma_tag_t, caddr_t, size_t);
609c4071fd1Smillert 	paddr_t	(*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *,
610c4071fd1Smillert 		    int, off_t, int, int);
611c44e1821Sniklas };
612c44e1821Sniklas 
613c44e1821Sniklas #define	bus_dmamap_create(t, s, n, m, b, f, p)			\
614c44e1821Sniklas 	(*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
615c44e1821Sniklas #define	bus_dmamap_destroy(t, p)				\
616c44e1821Sniklas 	(*(t)->_dmamap_destroy)((t), (p))
617c44e1821Sniklas #define	bus_dmamap_load(t, m, b, s, p, f)			\
618c44e1821Sniklas 	(*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
619c44e1821Sniklas #define	bus_dmamap_load_mbuf(t, m, b, f)			\
620c44e1821Sniklas 	(*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
621c44e1821Sniklas #define	bus_dmamap_load_uio(t, m, u, f)				\
622c44e1821Sniklas 	(*(t)->_dmamap_load_uio)((t), (m), (u), (f))
623c44e1821Sniklas #define	bus_dmamap_load_raw(t, m, sg, n, s, f)			\
624c44e1821Sniklas 	(*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
625c44e1821Sniklas #define	bus_dmamap_unload(t, p)					\
626c44e1821Sniklas 	(*(t)->_dmamap_unload)((t), (p))
6270065d83cSart #define	bus_dmamap_sync(t, p, o, l, ops)			\
628bcc3a45bSkettenis 	(*(t)->_dmamap_sync)((t), (p), (o), (l), (ops))
629c44e1821Sniklas 
630c44e1821Sniklas #define	bus_dmamem_alloc(t, s, a, b, sg, n, r, f)		\
631c44e1821Sniklas 	(*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
6323df3eb3bSkettenis #define	bus_dmamem_alloc_range(t, s, a, b, sg, n, r, f, l, h)	\
6333df3eb3bSkettenis 	(*(t)->_dmamem_alloc_range)((t), (s), (a), (b), (sg),	\
6343df3eb3bSkettenis 		(n), (r), (f), (l), (h))
635c44e1821Sniklas #define	bus_dmamem_free(t, sg, n)				\
636c44e1821Sniklas 	(*(t)->_dmamem_free)((t), (sg), (n))
637c44e1821Sniklas #define	bus_dmamem_map(t, sg, n, s, k, f)			\
638c44e1821Sniklas 	(*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
639c44e1821Sniklas #define	bus_dmamem_unmap(t, k, s)				\
640c44e1821Sniklas 	(*(t)->_dmamem_unmap)((t), (k), (s))
641c44e1821Sniklas #define	bus_dmamem_mmap(t, sg, n, o, p, f)			\
642c44e1821Sniklas 	(*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
643c44e1821Sniklas 
644c44e1821Sniklas /*
645c44e1821Sniklas  *	bus_dmamap_t
646c44e1821Sniklas  *
647c44e1821Sniklas  *	Describes a DMA mapping.
648c44e1821Sniklas  */
64913fad3d0Soga struct bus_dmamap {
650c44e1821Sniklas 	/*
651da6a775aSjason 	 * PRIVATE MEMBERS: not for use by machine-independent code.
652c44e1821Sniklas 	 */
653c44e1821Sniklas 	bus_size_t	_dm_size;	/* largest DMA transfer mappable */
654c44e1821Sniklas 	int		_dm_segcnt;	/* number of segs this map can map */
655c44e1821Sniklas 	bus_size_t	_dm_maxsegsz;	/* largest possible segment */
656c44e1821Sniklas 	bus_size_t	_dm_boundary;	/* don't cross this */
657c44e1821Sniklas 	int		_dm_flags;	/* misc. flags */
658c44e1821Sniklas 
659c44e1821Sniklas 	void		*_dm_cookie;	/* cookie for bus-specific functions */
660c44e1821Sniklas 
661c44e1821Sniklas 	/*
662c44e1821Sniklas 	 * PUBLIC MEMBERS: these are used by machine-independent code.
663c44e1821Sniklas 	 */
6647709b8f4Sjason 	bus_size_t	dm_mapsize;	/* size of the mapping */
665c44e1821Sniklas 	int		dm_nsegs;	/* # valid segments in mapping */
666c44e1821Sniklas 	bus_dma_segment_t dm_segs[1];	/* segments; variable length */
667c44e1821Sniklas };
668c44e1821Sniklas 
669c4071fd1Smillert int	_bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t,
670c4071fd1Smillert 	    bus_size_t, int, bus_dmamap_t *);
671c4071fd1Smillert void	_bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
672c4071fd1Smillert int	_bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *,
673c4071fd1Smillert 	    bus_size_t, struct proc *, int);
674c4071fd1Smillert int	_bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t,
675c4071fd1Smillert 	    struct mbuf *, int);
676c4071fd1Smillert int	_bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t,
677c4071fd1Smillert 	    struct uio *, int);
678c4071fd1Smillert int	_bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t,
679c4071fd1Smillert 	    bus_dma_segment_t *, int, bus_size_t, int);
680c4071fd1Smillert void	_bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
681c4071fd1Smillert void	_bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
682c4071fd1Smillert 	    bus_size_t, int);
683c44e1821Sniklas 
684c4071fd1Smillert int	_bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size,
685c44e1821Sniklas 	    bus_size_t alignment, bus_size_t boundary,
686c4071fd1Smillert 	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags);
687c4071fd1Smillert void	_bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs,
688c4071fd1Smillert 	    int nsegs);
689c4071fd1Smillert int	_bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs,
690c4071fd1Smillert 	    int nsegs, size_t size, caddr_t *kvap, int flags);
691c4071fd1Smillert void	_bus_dmamem_unmap(bus_dma_tag_t tag, caddr_t kva,
692c4071fd1Smillert 	    size_t size);
693c4071fd1Smillert paddr_t	_bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs,
694c4071fd1Smillert 	    int nsegs, off_t off, int prot, int flags);
695c44e1821Sniklas 
696c4071fd1Smillert int	_bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size,
697c44e1821Sniklas 	    bus_size_t alignment, bus_size_t boundary,
698c44e1821Sniklas 	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
6996f30aa89Sart 	    paddr_t low, paddr_t high);
700c44e1821Sniklas 
7012fa72412Spirofti #endif /* _MACHINE_BUS_H_ */
702