180708Sjake/*-
286228Stmm * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
380708Sjake * All rights reserved.
480708Sjake *
586228Stmm * This code is derived from software contributed to The NetBSD Foundation
686228Stmm * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
786228Stmm * NASA Ames Research Center.
886228Stmm *
980708Sjake * Redistribution and use in source and binary forms, with or without
1080708Sjake * modification, are permitted provided that the following conditions
1180708Sjake * are met:
1280708Sjake * 1. Redistributions of source code must retain the above copyright
1380708Sjake *    notice, this list of conditions and the following disclaimer.
1480708Sjake * 2. Redistributions in binary form must reproduce the above copyright
1580708Sjake *    notice, this list of conditions and the following disclaimer in the
1680708Sjake *    documentation and/or other materials provided with the distribution.
1780708Sjake *
1886228Stmm * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1986228Stmm * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2086228Stmm * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2186228Stmm * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2286228Stmm * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2386228Stmm * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2486228Stmm * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2586228Stmm * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2686228Stmm * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2786228Stmm * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2886228Stmm * POSSIBILITY OF SUCH DAMAGE.
2986228Stmm */
3086228Stmm/*
3186228Stmm * Copyright (c) 1997-1999 Eduardo E. Horvath. All rights reserved.
3286228Stmm * Copyright (c) 1996 Charles M. Hannum.  All rights reserved.
3386228Stmm * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
3480708Sjake *
3586228Stmm * Redistribution and use in source and binary forms, with or without
3686228Stmm * modification, are permitted provided that the following conditions
3786228Stmm * are met:
3886228Stmm * 1. Redistributions of source code must retain the above copyright
3986228Stmm *    notice, this list of conditions and the following disclaimer.
4086228Stmm * 2. Redistributions in binary form must reproduce the above copyright
4186228Stmm *    notice, this list of conditions and the following disclaimer in the
4286228Stmm *    documentation and/or other materials provided with the distribution.
4386228Stmm * 3. All advertising materials mentioning features or use of this software
4486228Stmm *    must display the following acknowledgement:
4586228Stmm *      This product includes software developed by Christopher G. Demetriou
4686228Stmm *	for the NetBSD Project.
4786228Stmm * 4. The name of the author may not be used to endorse or promote products
4886228Stmm *    derived from this software without specific prior written permission
4986228Stmm *
5086228Stmm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
5186228Stmm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
5286228Stmm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
5386228Stmm * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
5486228Stmm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
5586228Stmm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
5686228Stmm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
5786228Stmm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
5886228Stmm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
5986228Stmm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6086228Stmm *
61257066Smarius *	from: NetBSD: bus.h,v 1.58 2008/04/28 20:23:36 martin Exp
6286228Stmm *	and
6386228Stmm *	from: FreeBSD: src/sys/alpha/include/bus.h,v 1.9 2001/01/09
6486228Stmm *
6580708Sjake * $FreeBSD$
6680708Sjake */
6780708Sjake
6880708Sjake#ifndef	_MACHINE_BUS_H_
6980708Sjake#define	_MACHINE_BUS_H_
7080708Sjake
7190615Stmm#ifdef BUS_SPACE_DEBUG
7290615Stmm#include <sys/ktr.h>
7390615Stmm#endif
7490615Stmm
75145253Simp#include <machine/_bus.h>
7686228Stmm#include <machine/cpufunc.h>
7780708Sjake
7886228Stmm/*
79166096Smarius * Nexus and SBus spaces are non-cached and big endian
8086228Stmm * (except for RAM and PROM)
8186228Stmm *
8286228Stmm * PCI spaces are non-cached and little endian
8386228Stmm */
84166096Smarius#define	NEXUS_BUS_SPACE		0
8586228Stmm#define	SBUS_BUS_SPACE		1
8686228Stmm#define	PCI_CONFIG_BUS_SPACE	2
8786228Stmm#define	PCI_IO_BUS_SPACE	3
8886228Stmm#define	PCI_MEMORY_BUS_SPACE	4
8986228Stmm#define	LAST_BUS_SPACE		5
9086228Stmm
91177565Smariusextern const int bus_type_asi[];
92177565Smariusextern const int bus_stream_asi[];
9386228Stmm
94178860Smarius#define	__BUS_SPACE_HAS_STREAM_METHODS	1
9586228Stmm
96178860Smarius#define	BUS_SPACE_MAXSIZE_24BIT	0xFFFFFF
97178860Smarius#define	BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF
98178860Smarius#define	BUS_SPACE_MAXSIZE	0xFFFFFFFFFFFFFFFF
99178860Smarius#define	BUS_SPACE_MAXADDR_24BIT	0xFFFFFF
100178860Smarius#define	BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF
101297792Smarius#define	BUS_SPACE_MAXADDR	0xFFFFFFFFFFFFFFFF
10286228Stmm
103178860Smarius#define	BUS_SPACE_UNRESTRICTED	(~0)
10486228Stmm
10586228Stmmstruct bus_space_tag {
106108815Stmm	void		*bst_cookie;
107108815Stmm	int		bst_type;
10886228Stmm};
10986228Stmm
11086228Stmm/*
11186228Stmm * Bus space function prototypes.
11286228Stmm */
11393052Stmmstatic void bus_space_barrier(bus_space_tag_t, bus_space_handle_t, bus_size_t,
11493052Stmm    bus_size_t, int);
115108917Sjakestatic int bus_space_subregion(bus_space_tag_t, bus_space_handle_t,
116108917Sjake    bus_size_t, bus_size_t, bus_space_handle_t *);
117120375Snyan
118111347Sobrien/*
119120375Snyan * Map a region of device bus space into CPU virtual address space.
120120375Snyan */
121225931Smariusint bus_space_map(bus_space_tag_t tag, bus_addr_t address, bus_size_t size,
122225931Smarius    int flags, bus_space_handle_t *handlep);
123120375Snyan
124120375Snyan/*
125111347Sobrien * Unmap a region of device bus space.
126111347Sobrien */
127225931Smariusvoid bus_space_unmap(bus_space_tag_t tag, bus_space_handle_t handle,
128178860Smarius    bus_size_t size);
12986228Stmm
13093052Stmmstatic __inline void
131257066Smariusbus_space_barrier(bus_space_tag_t t __unused, bus_space_handle_t h __unused,
132257066Smarius    bus_size_t o __unused, bus_size_t s __unused, int f __unused)
13386228Stmm{
134178860Smarius
135257066Smarius	/*
136257066Smarius	 * We have lots of alternatives depending on whether we're
137257066Smarius	 * synchronizing loads with loads, loads with stores, stores
138257066Smarius	 * with loads, or stores with stores.  The only ones that seem
139257066Smarius	 * generic are #Sync and #MemIssue.  We use #Sync for safety.
140257066Smarius	 */
141257066Smarius	membar(Sync);
14286228Stmm}
14386228Stmm
144108917Sjakestatic __inline int
145257066Smariusbus_space_subregion(bus_space_tag_t t __unused, bus_space_handle_t h,
146257066Smarius    bus_size_t o __unused, bus_size_t s __unused, bus_space_handle_t *hp)
147108917Sjake{
148178860Smarius
149108917Sjake	*hp = h + o;
150108917Sjake	return (0);
151108917Sjake}
152108917Sjake
15386228Stmm/* flags for bus space map functions */
154178860Smarius#define	BUS_SPACE_MAP_CACHEABLE		0x0001
155178860Smarius#define	BUS_SPACE_MAP_LINEAR		0x0002
156178860Smarius#define	BUS_SPACE_MAP_READONLY		0x0004
157178860Smarius#define	BUS_SPACE_MAP_PREFETCHABLE	0x0008
15886228Stmm/* placeholders for bus functions... */
159178860Smarius#define	BUS_SPACE_MAP_BUS1		0x0100
160178860Smarius#define	BUS_SPACE_MAP_BUS2		0x0200
161178860Smarius#define	BUS_SPACE_MAP_BUS3		0x0400
162178860Smarius#define	BUS_SPACE_MAP_BUS4		0x0800
16386228Stmm
16486228Stmm/* flags for bus_space_barrier() */
16586228Stmm#define	BUS_SPACE_BARRIER_READ		0x01	/* force read barrier */
16686228Stmm#define	BUS_SPACE_BARRIER_WRITE		0x02	/* force write barrier */
16786228Stmm
16890615Stmm#ifdef BUS_SPACE_DEBUG
169210334Sattilio#define	KTR_BUS				KTR_SPARE2
17090615Stmm#define	__BUS_DEBUG_ACCESS(h, o, desc, sz) do {				\
17190615Stmm	CTR4(KTR_BUS, "bus space: %s %d: handle %#lx, offset %#lx",	\
17290615Stmm	    (desc), (sz), (h), (o));					\
17390615Stmm} while (0)
17490615Stmm#else
17590615Stmm#define	__BUS_DEBUG_ACCESS(h, o, desc, sz)
17690615Stmm#endif
17790615Stmm
178104304Sjakestatic __inline uint8_t
179104304Sjakebus_space_read_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
180104304Sjake{
18186228Stmm
182104304Sjake	__BUS_DEBUG_ACCESS(h, o, "read", 1);
183108815Stmm	return (lduba_nc((caddr_t)(h + o), bus_type_asi[t->bst_type]));
184104304Sjake}
18586228Stmm
186104304Sjakestatic __inline uint16_t
187104304Sjakebus_space_read_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
188104304Sjake{
18986228Stmm
190104304Sjake	__BUS_DEBUG_ACCESS(h, o, "read", 2);
191108815Stmm	return (lduha_nc((caddr_t)(h + o), bus_type_asi[t->bst_type]));
192104304Sjake}
19386228Stmm
194104304Sjakestatic __inline uint32_t
195104304Sjakebus_space_read_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
196104304Sjake{
19786228Stmm
198104304Sjake	__BUS_DEBUG_ACCESS(h, o, "read", 4);
199108815Stmm	return (lduwa_nc((caddr_t)(h + o), bus_type_asi[t->bst_type]));
200104304Sjake}
20186228Stmm
202104304Sjakestatic __inline uint64_t
203104304Sjakebus_space_read_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
204104304Sjake{
20586228Stmm
206104304Sjake	__BUS_DEBUG_ACCESS(h, o, "read", 8);
207108815Stmm	return (ldxa_nc((caddr_t)(h + o), bus_type_asi[t->bst_type]));
208104304Sjake}
20986228Stmm
210104304Sjakestatic __inline void
211104304Sjakebus_space_read_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
212104304Sjake    uint8_t *a, size_t c)
213104304Sjake{
214216143Sbrucec
215104304Sjake	while (c-- > 0)
216104304Sjake		*a++ = bus_space_read_1(t, h, o);
217104304Sjake}
21886228Stmm
219104304Sjakestatic __inline void
220104304Sjakebus_space_read_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
221104304Sjake    uint16_t *a, size_t c)
222104304Sjake{
223216143Sbrucec
224104304Sjake	while (c-- > 0)
225104304Sjake		*a++ = bus_space_read_2(t, h, o);
226104304Sjake}
22786228Stmm
228104304Sjakestatic __inline void
229104304Sjakebus_space_read_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
230104304Sjake    uint32_t *a, size_t c)
231104304Sjake{
232216143Sbrucec
233104304Sjake	while (c-- > 0)
234104304Sjake		*a++ = bus_space_read_4(t, h, o);
235104304Sjake}
23686228Stmm
237104304Sjakestatic __inline void
238104304Sjakebus_space_read_multi_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
239104304Sjake    uint64_t *a, size_t c)
240104304Sjake{
241216143Sbrucec
242104304Sjake	while (c-- > 0)
243104304Sjake		*a++ = bus_space_read_8(t, h, o);
244104304Sjake}
24586228Stmm
246104304Sjakestatic __inline void
247104304Sjakebus_space_write_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
248104304Sjake    uint8_t v)
249104304Sjake{
25086228Stmm
251104304Sjake	__BUS_DEBUG_ACCESS(h, o, "write", 1);
252108815Stmm	stba_nc((caddr_t)(h + o), bus_type_asi[t->bst_type], v);
253104304Sjake}
25486228Stmm
255104304Sjakestatic __inline void
256104304Sjakebus_space_write_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
257104304Sjake    uint16_t v)
258104304Sjake{
25986228Stmm
260104304Sjake	__BUS_DEBUG_ACCESS(h, o, "write", 2);
261108815Stmm	stha_nc((caddr_t)(h + o), bus_type_asi[t->bst_type], v);
262104304Sjake}
26386228Stmm
26493052Stmmstatic __inline void
265104304Sjakebus_space_write_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
266104304Sjake    uint32_t v)
267104304Sjake{
268104304Sjake
269104304Sjake	__BUS_DEBUG_ACCESS(h, o, "write", 4);
270108815Stmm	stwa_nc((caddr_t)(h + o), bus_type_asi[t->bst_type], v);
271104304Sjake}
272104304Sjake
273104304Sjakestatic __inline void
274104304Sjakebus_space_write_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
275104304Sjake    uint64_t v)
276104304Sjake{
277104304Sjake
278104304Sjake	__BUS_DEBUG_ACCESS(h, o, "write", 8);
279108815Stmm	stxa_nc((caddr_t)(h + o), bus_type_asi[t->bst_type], v);
280104304Sjake}
281104304Sjake
282104304Sjakestatic __inline void
283104304Sjakebus_space_write_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
284157224Smarius    const uint8_t *a, size_t c)
285104304Sjake{
286216143Sbrucec
287104304Sjake	while (c-- > 0)
288104304Sjake		bus_space_write_1(t, h, o, *a++);
289104304Sjake}
290104304Sjake
291104304Sjakestatic __inline void
292104304Sjakebus_space_write_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
293157224Smarius    const uint16_t *a, size_t c)
294104304Sjake{
295216143Sbrucec
296104304Sjake	while (c-- > 0)
297104304Sjake		bus_space_write_2(t, h, o, *a++);
298104304Sjake}
299104304Sjake
300104304Sjakestatic __inline void
301104304Sjakebus_space_write_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
302157224Smarius    const uint32_t *a, size_t c)
303104304Sjake{
304216143Sbrucec
305104304Sjake	while (c-- > 0)
306104304Sjake		bus_space_write_4(t, h, o, *a++);
307104304Sjake}
308104304Sjake
309104304Sjakestatic __inline void
310104304Sjakebus_space_write_multi_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
311157224Smarius    const uint64_t *a, size_t c)
312104304Sjake{
313216143Sbrucec
314104304Sjake	while (c-- > 0)
315104304Sjake		bus_space_write_8(t, h, o, *a++);
316104304Sjake}
317104304Sjake
318104304Sjakestatic __inline void
319104304Sjakebus_space_set_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
320104304Sjake    uint8_t v, size_t c)
321104304Sjake{
322216143Sbrucec
323104304Sjake	while (c-- > 0)
324104304Sjake		bus_space_write_1(t, h, o, v);
325104304Sjake}
326104304Sjake
327104304Sjakestatic __inline void
328104304Sjakebus_space_set_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
329104304Sjake    uint16_t v, size_t c)
330104304Sjake{
331216143Sbrucec
332104304Sjake	while (c-- > 0)
333104304Sjake		bus_space_write_2(t, h, o, v);
334104304Sjake}
335104304Sjake
336104304Sjakestatic __inline void
337104304Sjakebus_space_set_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
338104304Sjake    uint32_t v, size_t c)
339104304Sjake{
340216143Sbrucec
341104304Sjake	while (c-- > 0)
342104304Sjake		bus_space_write_4(t, h, o, v);
343104304Sjake}
344104304Sjake
345104304Sjakestatic __inline void
346104304Sjakebus_space_set_multi_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
347104304Sjake    uint64_t v, size_t c)
348104304Sjake{
349216143Sbrucec
350104304Sjake	while (c-- > 0)
351104304Sjake		bus_space_write_8(t, h, o, v);
352104304Sjake}
353104304Sjake
354104304Sjakestatic __inline void
35593052Stmmbus_space_read_region_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
356178860Smarius    uint8_t *a, bus_size_t c)
35786228Stmm{
358216143Sbrucec
35986228Stmm	for (; c; a++, c--, o++)
36086228Stmm		*a = bus_space_read_1(t, h, o);
36186228Stmm}
36286228Stmm
36393052Stmmstatic __inline void
36493052Stmmbus_space_read_region_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
365178860Smarius    uint16_t *a, bus_size_t c)
36686228Stmm{
367216143Sbrucec
368178860Smarius	for (; c; a++, c--, o += 2)
36986228Stmm		*a = bus_space_read_2(t, h, o);
37086228Stmm}
37186228Stmm
37293052Stmmstatic __inline void
37393052Stmmbus_space_read_region_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
374178860Smarius    uint32_t *a, bus_size_t c)
37586228Stmm{
376216143Sbrucec
377178860Smarius	for (; c; a++, c--, o += 4)
37886228Stmm		*a = bus_space_read_4(t, h, o);
37986228Stmm}
38086228Stmm
38193052Stmmstatic __inline void
38293052Stmmbus_space_read_region_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
383178860Smarius    uint64_t *a, bus_size_t c)
38486228Stmm{
385216143Sbrucec
386178860Smarius	for (; c; a++, c--, o += 8)
38786228Stmm		*a = bus_space_read_8(t, h, o);
38886228Stmm}
38986228Stmm
39093052Stmmstatic __inline void
39193052Stmmbus_space_write_region_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
392178860Smarius    const uint8_t *a, bus_size_t c)
39386228Stmm{
394216143Sbrucec
39586228Stmm	for (; c; a++, c--, o++)
39686228Stmm		bus_space_write_1(t, h, o, *a);
39786228Stmm}
39886228Stmm
39993052Stmmstatic __inline void
40093052Stmmbus_space_write_region_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
401178860Smarius    const uint16_t *a, bus_size_t c)
40286228Stmm{
403216143Sbrucec
404178860Smarius	for (; c; a++, c--, o += 2)
40586228Stmm		bus_space_write_2(t, h, o, *a);
40686228Stmm}
40786228Stmm
40893052Stmmstatic __inline void
40993052Stmmbus_space_write_region_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
410178860Smarius    const uint32_t *a, bus_size_t c)
41186228Stmm{
412216143Sbrucec
413178860Smarius	for (; c; a++, c--, o += 4)
41486228Stmm		bus_space_write_4(t, h, o, *a);
41586228Stmm}
41686228Stmm
41793052Stmmstatic __inline void
41893052Stmmbus_space_write_region_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
419178860Smarius    const uint64_t *a, bus_size_t c)
42086228Stmm{
421216143Sbrucec
422178860Smarius	for (; c; a++, c--, o += 8)
42386228Stmm		bus_space_write_8(t, h, o, *a);
42486228Stmm}
42586228Stmm
42693052Stmmstatic __inline void
42793052Stmmbus_space_set_region_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
428178860Smarius    const uint8_t v, bus_size_t c)
42986228Stmm{
430216143Sbrucec
43186228Stmm	for (; c; c--, o++)
43286228Stmm		bus_space_write_1(t, h, o, v);
43386228Stmm}
43486228Stmm
43593052Stmmstatic __inline void
43693052Stmmbus_space_set_region_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
437178860Smarius    const uint16_t v, bus_size_t c)
43886228Stmm{
439216143Sbrucec
440178860Smarius	for (; c; c--, o += 2)
44186228Stmm		bus_space_write_2(t, h, o, v);
44286228Stmm}
44386228Stmm
44493052Stmmstatic __inline void
44593052Stmmbus_space_set_region_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
446178860Smarius    const uint32_t v, bus_size_t c)
44786228Stmm{
448216143Sbrucec
449178860Smarius	for (; c; c--, o += 4)
45086228Stmm		bus_space_write_4(t, h, o, v);
45186228Stmm}
45286228Stmm
45393052Stmmstatic __inline void
45493052Stmmbus_space_set_region_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
455178860Smarius    const uint64_t v, bus_size_t c)
45686228Stmm{
457216143Sbrucec
458178860Smarius	for (; c; c--, o += 8)
45986228Stmm		bus_space_write_8(t, h, o, v);
46086228Stmm}
46186228Stmm
46293052Stmmstatic __inline void
46393052Stmmbus_space_copy_region_1(bus_space_tag_t t, bus_space_handle_t h1,
46493052Stmm    bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
46586228Stmm{
466216143Sbrucec
46786228Stmm	for (; c; c--, o1++, o2++)
46886228Stmm	    bus_space_write_1(t, h1, o1, bus_space_read_1(t, h2, o2));
46986228Stmm}
47086228Stmm
47193052Stmmstatic __inline void
47293052Stmmbus_space_copy_region_2(bus_space_tag_t t, bus_space_handle_t h1,
47393052Stmm    bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
47486228Stmm{
475216143Sbrucec
476178860Smarius	for (; c; c--, o1 += 2, o2 += 2)
47786228Stmm	    bus_space_write_2(t, h1, o1, bus_space_read_2(t, h2, o2));
47886228Stmm}
47986228Stmm
48093052Stmmstatic __inline void
48193052Stmmbus_space_copy_region_4(bus_space_tag_t t, bus_space_handle_t h1,
48293052Stmm    bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
48386228Stmm{
484216143Sbrucec
485178860Smarius	for (; c; c--, o1 += 4, o2 += 4)
48686228Stmm	    bus_space_write_4(t, h1, o1, bus_space_read_4(t, h2, o2));
48786228Stmm}
48886228Stmm
48993052Stmmstatic __inline void
49093052Stmmbus_space_copy_region_8(bus_space_tag_t t, bus_space_handle_t h1,
49193052Stmm    bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
49286228Stmm{
493216143Sbrucec
494178860Smarius	for (; c; c--, o1 += 8, o2 += 8)
49586228Stmm	    bus_space_write_8(t, h1, o1, bus_space_read_8(t, h2, o2));
49686228Stmm}
49786228Stmm
498104304Sjakestatic __inline uint8_t
499104304Sjakebus_space_read_stream_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
500104304Sjake{
50186228Stmm
502104304Sjake	__BUS_DEBUG_ACCESS(h, o, "read stream", 1);
503108815Stmm	return (lduba_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type]));
504104304Sjake}
50586228Stmm
506104304Sjakestatic __inline uint16_t
507104304Sjakebus_space_read_stream_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
508104304Sjake{
50986228Stmm
510104304Sjake	__BUS_DEBUG_ACCESS(h, o, "read stream", 2);
511108815Stmm	return (lduha_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type]));
512104304Sjake}
51386228Stmm
514104304Sjakestatic __inline uint32_t
515104304Sjakebus_space_read_stream_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
516104304Sjake{
51786228Stmm
518104304Sjake	__BUS_DEBUG_ACCESS(h, o, "read stream", 4);
519108815Stmm	return (lduwa_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type]));
520104304Sjake}
52186228Stmm
522104304Sjakestatic __inline uint64_t
523104304Sjakebus_space_read_stream_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
524104304Sjake{
52586228Stmm
526104304Sjake	__BUS_DEBUG_ACCESS(h, o, "read stream", 8);
527108815Stmm	return (ldxa_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type]));
528104304Sjake}
52986228Stmm
530104304Sjakestatic __inline void
531104304Sjakebus_space_read_multi_stream_1(bus_space_tag_t t, bus_space_handle_t h,
532104304Sjake    bus_size_t o, uint8_t *a, size_t c)
533104304Sjake{
534216143Sbrucec
535104304Sjake	while (c-- > 0)
536104304Sjake		*a++ = bus_space_read_stream_1(t, h, o);
537104304Sjake}
53886228Stmm
539104304Sjakestatic __inline void
540104304Sjakebus_space_read_multi_stream_2(bus_space_tag_t t, bus_space_handle_t h,
541104304Sjake    bus_size_t o, uint16_t *a, size_t c)
542104304Sjake{
543216143Sbrucec
544104304Sjake	while (c-- > 0)
545104304Sjake		*a++ = bus_space_read_stream_2(t, h, o);
546104304Sjake}
54786228Stmm
548104304Sjakestatic __inline void
549104304Sjakebus_space_read_multi_stream_4(bus_space_tag_t t, bus_space_handle_t h,
550104304Sjake    bus_size_t o, uint32_t *a, size_t c)
551104304Sjake{
552216143Sbrucec
553104304Sjake	while (c-- > 0)
554104304Sjake		*a++ = bus_space_read_stream_4(t, h, o);
555104304Sjake}
55686228Stmm
557104304Sjakestatic __inline void
558104304Sjakebus_space_read_multi_stream_8(bus_space_tag_t t, bus_space_handle_t h,
559104304Sjake    bus_size_t o, uint64_t *a, size_t c)
560104304Sjake{
561216143Sbrucec
562104304Sjake	while (c-- > 0)
563104304Sjake		*a++ = bus_space_read_stream_8(t, h, o);
564104304Sjake}
56586228Stmm
566104304Sjakestatic __inline void
567104304Sjakebus_space_write_stream_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
568104304Sjake    uint8_t v)
569104304Sjake{
57086228Stmm
571104304Sjake	__BUS_DEBUG_ACCESS(h, o, "write stream", 1);
572108815Stmm	stba_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type], v);
573104304Sjake}
57486228Stmm
575104304Sjakestatic __inline void
576104304Sjakebus_space_write_stream_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
577104304Sjake    uint16_t v)
578104304Sjake{
57986228Stmm
580104304Sjake	__BUS_DEBUG_ACCESS(h, o, "write stream", 2);
581108815Stmm	stha_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type], v);
582104304Sjake}
58386228Stmm
58493052Stmmstatic __inline void
585104304Sjakebus_space_write_stream_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
586104304Sjake    uint32_t v)
587104304Sjake{
588104304Sjake
589104304Sjake	__BUS_DEBUG_ACCESS(h, o, "write stream", 4);
590108815Stmm	stwa_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type], v);
591104304Sjake}
592104304Sjake
593104304Sjakestatic __inline void
594104304Sjakebus_space_write_stream_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
595104304Sjake    uint64_t v)
596104304Sjake{
597104304Sjake
598104304Sjake	__BUS_DEBUG_ACCESS(h, o, "write stream", 8);
599108815Stmm	stxa_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type], v);
600104304Sjake}
601104304Sjake
602104304Sjakestatic __inline void
603104304Sjakebus_space_write_multi_stream_1(bus_space_tag_t t, bus_space_handle_t h,
604111383Sobrien    bus_size_t o, const uint8_t *a, size_t c)
605104304Sjake{
606216143Sbrucec
607104304Sjake	while (c-- > 0)
608104304Sjake		bus_space_write_stream_1(t, h, o, *a++);
609104304Sjake}
610104304Sjake
611104304Sjakestatic __inline void
612104304Sjakebus_space_write_multi_stream_2(bus_space_tag_t t, bus_space_handle_t h,
613111353Sobrien    bus_size_t o, const uint16_t *a, size_t c)
614104304Sjake{
615216143Sbrucec
616104304Sjake	while (c-- > 0)
617104304Sjake		bus_space_write_stream_2(t, h, o, *a++);
618104304Sjake}
619104304Sjake
620104304Sjakestatic __inline void
621104304Sjakebus_space_write_multi_stream_4(bus_space_tag_t t, bus_space_handle_t h,
622111383Sobrien    bus_size_t o, const uint32_t *a, size_t c)
623104304Sjake{
624216143Sbrucec
625104304Sjake	while (c-- > 0)
626104304Sjake		bus_space_write_stream_4(t, h, o, *a++);
627104304Sjake}
628104304Sjake
629104304Sjakestatic __inline void
630104304Sjakebus_space_write_multi_stream_8(bus_space_tag_t t, bus_space_handle_t h,
631111383Sobrien    bus_size_t o, const uint64_t *a, size_t c)
632104304Sjake{
633216143Sbrucec
634104304Sjake	while (c-- > 0)
635104304Sjake		bus_space_write_stream_8(t, h, o, *a++);
636104304Sjake}
637104304Sjake
638104304Sjakestatic __inline void
639104304Sjakebus_space_set_multi_stream_1(bus_space_tag_t t, bus_space_handle_t h,
640104304Sjake    bus_size_t o, uint8_t v, size_t c)
641104304Sjake{
642216143Sbrucec
643104304Sjake	while (c-- > 0)
644104304Sjake		bus_space_write_stream_1(t, h, o, v);
645104304Sjake}
646104304Sjake
647104304Sjakestatic __inline void
648104304Sjakebus_space_set_multi_stream_2(bus_space_tag_t t, bus_space_handle_t h,
649104304Sjake    bus_size_t o, uint16_t v, size_t c)
650104304Sjake{
651216143Sbrucec
652104304Sjake	while (c-- > 0)
653104304Sjake		bus_space_write_stream_2(t, h, o, v);
654104304Sjake}
655104304Sjake
656104304Sjakestatic __inline void
657104304Sjakebus_space_set_multi_stream_4(bus_space_tag_t t, bus_space_handle_t h,
658104304Sjake    bus_size_t o, uint32_t v, size_t c)
659104304Sjake{
660216143Sbrucec
661104304Sjake	while (c-- > 0)
662104304Sjake		bus_space_write_stream_4(t, h, o, v);
663104304Sjake}
664104304Sjake
665104304Sjakestatic __inline void
666104304Sjakebus_space_set_multi_stream_8(bus_space_tag_t t, bus_space_handle_t h,
667104304Sjake    bus_size_t o, uint64_t v, size_t c)
668104304Sjake{
669216143Sbrucec
670104304Sjake	while (c-- > 0)
671104304Sjake		bus_space_write_stream_8(t, h, o, v);
672104304Sjake}
673104304Sjake
674104304Sjakestatic __inline void
67593052Stmmbus_space_read_region_stream_1(bus_space_tag_t t, bus_space_handle_t h,
676178860Smarius    bus_size_t o, uint8_t *a, bus_size_t c)
67786228Stmm{
678216143Sbrucec
67986228Stmm	for (; c; a++, c--, o++)
68086228Stmm		*a = bus_space_read_stream_1(t, h, o);
68186228Stmm}
68286228Stmm
68393052Stmmstatic __inline void
68493052Stmmbus_space_read_region_stream_2(bus_space_tag_t t, bus_space_handle_t h,
685178860Smarius    bus_size_t o, uint16_t *a, bus_size_t c)
68686228Stmm{
687216143Sbrucec
688178860Smarius	for (; c; a++, c--, o += 2)
68986228Stmm		*a = bus_space_read_stream_2(t, h, o);
69086228Stmm}
69186228Stmm
69293052Stmmstatic __inline void
69393052Stmmbus_space_read_region_stream_4(bus_space_tag_t t, bus_space_handle_t h,
694178860Smarius    bus_size_t o, uint32_t *a, bus_size_t c)
69586228Stmm{
696216143Sbrucec
697178860Smarius	for (; c; a++, c--, o += 4)
69886228Stmm		*a = bus_space_read_stream_4(t, h, o);
69986228Stmm}
70086228Stmm
70193052Stmmstatic __inline void
70293052Stmmbus_space_read_region_stream_8(bus_space_tag_t t, bus_space_handle_t h,
703178860Smarius    bus_size_t o, uint64_t *a, bus_size_t c)
70486228Stmm{
705216143Sbrucec
706178860Smarius	for (; c; a++, c--, o += 8)
70786228Stmm		*a = bus_space_read_stream_8(t, h, o);
70886228Stmm}
70986228Stmm
71093052Stmmstatic __inline void
71193052Stmmbus_space_write_region_stream_1(bus_space_tag_t t, bus_space_handle_t h,
712178860Smarius    bus_size_t o, const uint8_t *a, bus_size_t c)
71386228Stmm{
714216143Sbrucec
71586228Stmm	for (; c; a++, c--, o++)
71686228Stmm		bus_space_write_stream_1(t, h, o, *a);
71786228Stmm}
71886228Stmm
71993052Stmmstatic __inline void
72093052Stmmbus_space_write_region_stream_2(bus_space_tag_t t, bus_space_handle_t h,
721178860Smarius    bus_size_t o, const uint16_t *a, bus_size_t c)
72286228Stmm{
723216143Sbrucec
724178860Smarius	for (; c; a++, c--, o += 2)
72586228Stmm		bus_space_write_stream_2(t, h, o, *a);
72686228Stmm}
72786228Stmm
72893052Stmmstatic __inline void
72993052Stmmbus_space_write_region_stream_4(bus_space_tag_t t, bus_space_handle_t h,
730178860Smarius    bus_size_t o, const uint32_t *a, bus_size_t c)
73186228Stmm{
732216143Sbrucec
733178860Smarius	for (; c; a++, c--, o += 4)
73486228Stmm		bus_space_write_stream_4(t, h, o, *a);
73586228Stmm}
73686228Stmm
73793052Stmmstatic __inline void
73893052Stmmbus_space_write_region_stream_8(bus_space_tag_t t, bus_space_handle_t h,
739178860Smarius    bus_size_t o, const uint64_t *a, bus_size_t c)
74086228Stmm{
741216143Sbrucec
742178860Smarius	for (; c; a++, c--, o += 8)
74386228Stmm		bus_space_write_stream_8(t, h, o, *a);
74486228Stmm}
74586228Stmm
74693052Stmmstatic __inline void
74793052Stmmbus_space_set_region_stream_1(bus_space_tag_t t, bus_space_handle_t h,
748178860Smarius    bus_size_t o, const uint8_t v, bus_size_t c)
74986228Stmm{
750216143Sbrucec
75186228Stmm	for (; c; c--, o++)
75286228Stmm		bus_space_write_stream_1(t, h, o, v);
75386228Stmm}
75486228Stmm
75593052Stmmstatic __inline void
75693052Stmmbus_space_set_region_stream_2(bus_space_tag_t t, bus_space_handle_t h,
757178860Smarius    bus_size_t o, const uint16_t v, bus_size_t c)
75886228Stmm{
759216143Sbrucec
760178860Smarius	for (; c; c--, o += 2)
76186228Stmm		bus_space_write_stream_2(t, h, o, v);
76286228Stmm}
76386228Stmm
76493052Stmmstatic __inline void
76593052Stmmbus_space_set_region_stream_4(bus_space_tag_t t, bus_space_handle_t h,
766178860Smarius    bus_size_t o, const uint32_t v, bus_size_t c)
76786228Stmm{
768216143Sbrucec
769178860Smarius	for (; c; c--, o += 4)
77086228Stmm		bus_space_write_stream_4(t, h, o, v);
77186228Stmm}
77286228Stmm
77393052Stmmstatic __inline void
77493052Stmmbus_space_set_region_stream_8(bus_space_tag_t t, bus_space_handle_t h,
775178860Smarius    bus_size_t o, const uint64_t v, bus_size_t c)
77686228Stmm{
777216143Sbrucec
778178860Smarius	for (; c; c--, o += 8)
77986228Stmm		bus_space_write_stream_8(t, h, o, v);
78086228Stmm}
78186228Stmm
78293052Stmmstatic __inline void
78393052Stmmbus_space_copy_region_stream_1(bus_space_tag_t t, bus_space_handle_t h1,
78493052Stmm    bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
78586228Stmm{
786216143Sbrucec
78786228Stmm	for (; c; c--, o1++, o2++)
78886228Stmm	    bus_space_write_stream_1(t, h1, o1, bus_space_read_stream_1(t, h2,
78986228Stmm		o2));
79086228Stmm}
79186228Stmm
79293052Stmmstatic __inline void
79393052Stmmbus_space_copy_region_stream_2(bus_space_tag_t t, bus_space_handle_t h1,
79493052Stmm    bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
79586228Stmm{
796216143Sbrucec
797178860Smarius	for (; c; c--, o1 += 2, o2 += 2)
79886228Stmm	    bus_space_write_stream_2(t, h1, o1, bus_space_read_stream_2(t, h2,
79986228Stmm		o2));
80086228Stmm}
80186228Stmm
80293052Stmmstatic __inline void
80393052Stmmbus_space_copy_region_stream_4(bus_space_tag_t t, bus_space_handle_t h1,
80493052Stmm    bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
80586228Stmm{
806216143Sbrucec
807178860Smarius	for (; c; c--, o1 += 4, o2 += 4)
80886228Stmm	    bus_space_write_stream_4(t, h1, o1, bus_space_read_stream_4(t, h2,
80986228Stmm		o2));
81086228Stmm}
81186228Stmm
81293052Stmmstatic __inline void
81393052Stmmbus_space_copy_region_stream_8(bus_space_tag_t t, bus_space_handle_t h1,
81493052Stmm    bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
81586228Stmm{
816216143Sbrucec
817178860Smarius	for (; c; c--, o1 += 8, o2 += 8)
81886228Stmm	    bus_space_write_stream_8(t, h1, o1, bus_space_read_8(t, h2, o2));
81986228Stmm}
82086228Stmm
821116659Sjmgstatic __inline int
822116659Sjmgbus_space_peek_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
823178860Smarius	uint8_t *a)
824116659Sjmg{
825116659Sjmg
826116659Sjmg	__BUS_DEBUG_ACCESS(h, o, "peek", 1);
827116659Sjmg	return (fasword8(bus_type_asi[t->bst_type], (caddr_t)(h + o), a));
828116659Sjmg}
829116659Sjmg
830116659Sjmgstatic __inline int
831116659Sjmgbus_space_peek_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
832178860Smarius	uint16_t *a)
833116659Sjmg{
834116659Sjmg
835116659Sjmg	__BUS_DEBUG_ACCESS(h, o, "peek", 2);
836116659Sjmg	return (fasword16(bus_type_asi[t->bst_type], (caddr_t)(h + o), a));
837116659Sjmg}
838116659Sjmg
839116659Sjmgstatic __inline int
840116659Sjmgbus_space_peek_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
841178860Smarius	uint32_t *a)
842116659Sjmg{
843116659Sjmg
844116659Sjmg	__BUS_DEBUG_ACCESS(h, o, "peek", 4);
845116659Sjmg	return (fasword32(bus_type_asi[t->bst_type], (caddr_t)(h + o), a));
846116659Sjmg}
847116659Sjmg
848143598Sscottl#include <machine/bus_dma.h>
84986228Stmm
85080708Sjake#endif /* !_MACHINE_BUS_H_ */
851