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 *
61219567Smarius * 	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
101178860Smarius#define	BUS_SPACE_MAXADDR	0xFFFFFFFF
10286228Stmm
103178860Smarius#define	BUS_SPACE_UNRESTRICTED	(~0)
10486228Stmm
10586228Stmmstruct bus_space_tag {
106108815Stmm	void		*bst_cookie;
107108815Stmm	bus_space_tag_t	bst_parent;
108108815Stmm	int		bst_type;
10986228Stmm
110108815Stmm	void		(*bst_bus_barrier)(bus_space_tag_t, bus_space_handle_t,
111178860Smarius			    bus_size_t, bus_size_t, int);
11286228Stmm};
11386228Stmm
11486228Stmm/*
11586228Stmm * Bus space function prototypes.
11686228Stmm */
11793052Stmmstatic void bus_space_barrier(bus_space_tag_t, bus_space_handle_t, bus_size_t,
11893052Stmm    bus_size_t, int);
119108917Sjakestatic int bus_space_subregion(bus_space_tag_t, bus_space_handle_t,
120108917Sjake    bus_size_t, bus_size_t, bus_space_handle_t *);
121120375Snyan
122111347Sobrien/*
123120375Snyan * Map a region of device bus space into CPU virtual address space.
124120375Snyan */
125230687Smariusint bus_space_map(bus_space_tag_t tag, bus_addr_t address, bus_size_t size,
126230687Smarius    int flags, bus_space_handle_t *handlep);
127120375Snyan
128120375Snyan/*
129111347Sobrien * Unmap a region of device bus space.
130111347Sobrien */
131230687Smariusvoid bus_space_unmap(bus_space_tag_t tag, bus_space_handle_t handle,
132178860Smarius    bus_size_t size);
13386228Stmm
13486228Stmm/* This macro finds the first "upstream" implementation of method `f' */
135178860Smarius#define	_BS_CALL(t,f)							\
13693052Stmm	while (t->f == NULL)						\
137178860Smarius		t = t->bst_parent;					\
13886228Stmm	return (*(t)->f)
13986228Stmm
14093052Stmmstatic __inline void
14193052Stmmbus_space_barrier(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
14293052Stmm    bus_size_t s, int f)
14386228Stmm{
144178860Smarius
145108815Stmm	_BS_CALL(t, bst_bus_barrier)(t, h, o, s, f);
14686228Stmm}
14786228Stmm
148108917Sjakestatic __inline int
149108917Sjakebus_space_subregion(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
150108917Sjake    bus_size_t s, bus_space_handle_t *hp)
151108917Sjake{
152178860Smarius
153108917Sjake	*hp = h + o;
154108917Sjake	return (0);
155108917Sjake}
156108917Sjake
15786228Stmm/* flags for bus space map functions */
158178860Smarius#define	BUS_SPACE_MAP_CACHEABLE		0x0001
159178860Smarius#define	BUS_SPACE_MAP_LINEAR		0x0002
160178860Smarius#define	BUS_SPACE_MAP_READONLY		0x0004
161178860Smarius#define	BUS_SPACE_MAP_PREFETCHABLE	0x0008
16286228Stmm/* placeholders for bus functions... */
163178860Smarius#define	BUS_SPACE_MAP_BUS1		0x0100
164178860Smarius#define	BUS_SPACE_MAP_BUS2		0x0200
165178860Smarius#define	BUS_SPACE_MAP_BUS3		0x0400
166178860Smarius#define	BUS_SPACE_MAP_BUS4		0x0800
16786228Stmm
16886228Stmm/* flags for bus_space_barrier() */
16986228Stmm#define	BUS_SPACE_BARRIER_READ		0x01	/* force read barrier */
17086228Stmm#define	BUS_SPACE_BARRIER_WRITE		0x02	/* force write barrier */
17186228Stmm
17290615Stmm#ifdef BUS_SPACE_DEBUG
173210334Sattilio#define	KTR_BUS				KTR_SPARE2
17490615Stmm#define	__BUS_DEBUG_ACCESS(h, o, desc, sz) do {				\
17590615Stmm	CTR4(KTR_BUS, "bus space: %s %d: handle %#lx, offset %#lx",	\
17690615Stmm	    (desc), (sz), (h), (o));					\
17790615Stmm} while (0)
17890615Stmm#else
17990615Stmm#define	__BUS_DEBUG_ACCESS(h, o, desc, sz)
18090615Stmm#endif
18190615Stmm
182104304Sjakestatic __inline uint8_t
183104304Sjakebus_space_read_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
184104304Sjake{
18586228Stmm
186104304Sjake	__BUS_DEBUG_ACCESS(h, o, "read", 1);
187108815Stmm	return (lduba_nc((caddr_t)(h + o), bus_type_asi[t->bst_type]));
188104304Sjake}
18986228Stmm
190104304Sjakestatic __inline uint16_t
191104304Sjakebus_space_read_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
192104304Sjake{
19386228Stmm
194104304Sjake	__BUS_DEBUG_ACCESS(h, o, "read", 2);
195108815Stmm	return (lduha_nc((caddr_t)(h + o), bus_type_asi[t->bst_type]));
196104304Sjake}
19786228Stmm
198104304Sjakestatic __inline uint32_t
199104304Sjakebus_space_read_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
200104304Sjake{
20186228Stmm
202104304Sjake	__BUS_DEBUG_ACCESS(h, o, "read", 4);
203108815Stmm	return (lduwa_nc((caddr_t)(h + o), bus_type_asi[t->bst_type]));
204104304Sjake}
20586228Stmm
206104304Sjakestatic __inline uint64_t
207104304Sjakebus_space_read_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
208104304Sjake{
20986228Stmm
210104304Sjake	__BUS_DEBUG_ACCESS(h, o, "read", 8);
211108815Stmm	return (ldxa_nc((caddr_t)(h + o), bus_type_asi[t->bst_type]));
212104304Sjake}
21386228Stmm
214104304Sjakestatic __inline void
215104304Sjakebus_space_read_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
216104304Sjake    uint8_t *a, size_t c)
217104304Sjake{
218216143Sbrucec
219104304Sjake	while (c-- > 0)
220104304Sjake		*a++ = bus_space_read_1(t, h, o);
221104304Sjake}
22286228Stmm
223104304Sjakestatic __inline void
224104304Sjakebus_space_read_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
225104304Sjake    uint16_t *a, size_t c)
226104304Sjake{
227216143Sbrucec
228104304Sjake	while (c-- > 0)
229104304Sjake		*a++ = bus_space_read_2(t, h, o);
230104304Sjake}
23186228Stmm
232104304Sjakestatic __inline void
233104304Sjakebus_space_read_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
234104304Sjake    uint32_t *a, size_t c)
235104304Sjake{
236216143Sbrucec
237104304Sjake	while (c-- > 0)
238104304Sjake		*a++ = bus_space_read_4(t, h, o);
239104304Sjake}
24086228Stmm
241104304Sjakestatic __inline void
242104304Sjakebus_space_read_multi_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
243104304Sjake    uint64_t *a, size_t c)
244104304Sjake{
245216143Sbrucec
246104304Sjake	while (c-- > 0)
247104304Sjake		*a++ = bus_space_read_8(t, h, o);
248104304Sjake}
24986228Stmm
250104304Sjakestatic __inline void
251104304Sjakebus_space_write_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
252104304Sjake    uint8_t v)
253104304Sjake{
25486228Stmm
255104304Sjake	__BUS_DEBUG_ACCESS(h, o, "write", 1);
256108815Stmm	stba_nc((caddr_t)(h + o), bus_type_asi[t->bst_type], v);
257104304Sjake}
25886228Stmm
259104304Sjakestatic __inline void
260104304Sjakebus_space_write_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
261104304Sjake    uint16_t v)
262104304Sjake{
26386228Stmm
264104304Sjake	__BUS_DEBUG_ACCESS(h, o, "write", 2);
265108815Stmm	stha_nc((caddr_t)(h + o), bus_type_asi[t->bst_type], v);
266104304Sjake}
26786228Stmm
26893052Stmmstatic __inline void
269104304Sjakebus_space_write_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
270104304Sjake    uint32_t v)
271104304Sjake{
272104304Sjake
273104304Sjake	__BUS_DEBUG_ACCESS(h, o, "write", 4);
274108815Stmm	stwa_nc((caddr_t)(h + o), bus_type_asi[t->bst_type], v);
275104304Sjake}
276104304Sjake
277104304Sjakestatic __inline void
278104304Sjakebus_space_write_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
279104304Sjake    uint64_t v)
280104304Sjake{
281104304Sjake
282104304Sjake	__BUS_DEBUG_ACCESS(h, o, "write", 8);
283108815Stmm	stxa_nc((caddr_t)(h + o), bus_type_asi[t->bst_type], v);
284104304Sjake}
285104304Sjake
286104304Sjakestatic __inline void
287104304Sjakebus_space_write_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
288157224Smarius    const uint8_t *a, size_t c)
289104304Sjake{
290216143Sbrucec
291104304Sjake	while (c-- > 0)
292104304Sjake		bus_space_write_1(t, h, o, *a++);
293104304Sjake}
294104304Sjake
295104304Sjakestatic __inline void
296104304Sjakebus_space_write_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
297157224Smarius    const uint16_t *a, size_t c)
298104304Sjake{
299216143Sbrucec
300104304Sjake	while (c-- > 0)
301104304Sjake		bus_space_write_2(t, h, o, *a++);
302104304Sjake}
303104304Sjake
304104304Sjakestatic __inline void
305104304Sjakebus_space_write_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
306157224Smarius    const uint32_t *a, size_t c)
307104304Sjake{
308216143Sbrucec
309104304Sjake	while (c-- > 0)
310104304Sjake		bus_space_write_4(t, h, o, *a++);
311104304Sjake}
312104304Sjake
313104304Sjakestatic __inline void
314104304Sjakebus_space_write_multi_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
315157224Smarius    const uint64_t *a, size_t c)
316104304Sjake{
317216143Sbrucec
318104304Sjake	while (c-- > 0)
319104304Sjake		bus_space_write_8(t, h, o, *a++);
320104304Sjake}
321104304Sjake
322104304Sjakestatic __inline void
323104304Sjakebus_space_set_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
324104304Sjake    uint8_t v, size_t c)
325104304Sjake{
326216143Sbrucec
327104304Sjake	while (c-- > 0)
328104304Sjake		bus_space_write_1(t, h, o, v);
329104304Sjake}
330104304Sjake
331104304Sjakestatic __inline void
332104304Sjakebus_space_set_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
333104304Sjake    uint16_t v, size_t c)
334104304Sjake{
335216143Sbrucec
336104304Sjake	while (c-- > 0)
337104304Sjake		bus_space_write_2(t, h, o, v);
338104304Sjake}
339104304Sjake
340104304Sjakestatic __inline void
341104304Sjakebus_space_set_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
342104304Sjake    uint32_t v, size_t c)
343104304Sjake{
344216143Sbrucec
345104304Sjake	while (c-- > 0)
346104304Sjake		bus_space_write_4(t, h, o, v);
347104304Sjake}
348104304Sjake
349104304Sjakestatic __inline void
350104304Sjakebus_space_set_multi_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
351104304Sjake    uint64_t v, size_t c)
352104304Sjake{
353216143Sbrucec
354104304Sjake	while (c-- > 0)
355104304Sjake		bus_space_write_8(t, h, o, v);
356104304Sjake}
357104304Sjake
358104304Sjakestatic __inline void
35993052Stmmbus_space_read_region_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
360178860Smarius    uint8_t *a, bus_size_t c)
36186228Stmm{
362216143Sbrucec
36386228Stmm	for (; c; a++, c--, o++)
36486228Stmm		*a = bus_space_read_1(t, h, o);
36586228Stmm}
36686228Stmm
36793052Stmmstatic __inline void
36893052Stmmbus_space_read_region_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
369178860Smarius    uint16_t *a, bus_size_t c)
37086228Stmm{
371216143Sbrucec
372178860Smarius	for (; c; a++, c--, o += 2)
37386228Stmm		*a = bus_space_read_2(t, h, o);
37486228Stmm}
37586228Stmm
37693052Stmmstatic __inline void
37793052Stmmbus_space_read_region_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
378178860Smarius    uint32_t *a, bus_size_t c)
37986228Stmm{
380216143Sbrucec
381178860Smarius	for (; c; a++, c--, o += 4)
38286228Stmm		*a = bus_space_read_4(t, h, o);
38386228Stmm}
38486228Stmm
38593052Stmmstatic __inline void
38693052Stmmbus_space_read_region_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
387178860Smarius    uint64_t *a, bus_size_t c)
38886228Stmm{
389216143Sbrucec
390178860Smarius	for (; c; a++, c--, o += 8)
39186228Stmm		*a = bus_space_read_8(t, h, o);
39286228Stmm}
39386228Stmm
39493052Stmmstatic __inline void
39593052Stmmbus_space_write_region_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
396178860Smarius    const uint8_t *a, bus_size_t c)
39786228Stmm{
398216143Sbrucec
39986228Stmm	for (; c; a++, c--, o++)
40086228Stmm		bus_space_write_1(t, h, o, *a);
40186228Stmm}
40286228Stmm
40393052Stmmstatic __inline void
40493052Stmmbus_space_write_region_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
405178860Smarius    const uint16_t *a, bus_size_t c)
40686228Stmm{
407216143Sbrucec
408178860Smarius	for (; c; a++, c--, o += 2)
40986228Stmm		bus_space_write_2(t, h, o, *a);
41086228Stmm}
41186228Stmm
41293052Stmmstatic __inline void
41393052Stmmbus_space_write_region_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
414178860Smarius    const uint32_t *a, bus_size_t c)
41586228Stmm{
416216143Sbrucec
417178860Smarius	for (; c; a++, c--, o += 4)
41886228Stmm		bus_space_write_4(t, h, o, *a);
41986228Stmm}
42086228Stmm
42193052Stmmstatic __inline void
42293052Stmmbus_space_write_region_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
423178860Smarius    const uint64_t *a, bus_size_t c)
42486228Stmm{
425216143Sbrucec
426178860Smarius	for (; c; a++, c--, o += 8)
42786228Stmm		bus_space_write_8(t, h, o, *a);
42886228Stmm}
42986228Stmm
43093052Stmmstatic __inline void
43193052Stmmbus_space_set_region_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
432178860Smarius    const uint8_t v, bus_size_t c)
43386228Stmm{
434216143Sbrucec
43586228Stmm	for (; c; c--, o++)
43686228Stmm		bus_space_write_1(t, h, o, v);
43786228Stmm}
43886228Stmm
43993052Stmmstatic __inline void
44093052Stmmbus_space_set_region_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
441178860Smarius    const uint16_t v, bus_size_t c)
44286228Stmm{
443216143Sbrucec
444178860Smarius	for (; c; c--, o += 2)
44586228Stmm		bus_space_write_2(t, h, o, v);
44686228Stmm}
44786228Stmm
44893052Stmmstatic __inline void
44993052Stmmbus_space_set_region_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
450178860Smarius    const uint32_t v, bus_size_t c)
45186228Stmm{
452216143Sbrucec
453178860Smarius	for (; c; c--, o += 4)
45486228Stmm		bus_space_write_4(t, h, o, v);
45586228Stmm}
45686228Stmm
45793052Stmmstatic __inline void
45893052Stmmbus_space_set_region_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
459178860Smarius    const uint64_t v, bus_size_t c)
46086228Stmm{
461216143Sbrucec
462178860Smarius	for (; c; c--, o += 8)
46386228Stmm		bus_space_write_8(t, h, o, v);
46486228Stmm}
46586228Stmm
46693052Stmmstatic __inline void
46793052Stmmbus_space_copy_region_1(bus_space_tag_t t, bus_space_handle_t h1,
46893052Stmm    bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
46986228Stmm{
470216143Sbrucec
47186228Stmm	for (; c; c--, o1++, o2++)
47286228Stmm	    bus_space_write_1(t, h1, o1, bus_space_read_1(t, h2, o2));
47386228Stmm}
47486228Stmm
47593052Stmmstatic __inline void
47693052Stmmbus_space_copy_region_2(bus_space_tag_t t, bus_space_handle_t h1,
47793052Stmm    bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
47886228Stmm{
479216143Sbrucec
480178860Smarius	for (; c; c--, o1 += 2, o2 += 2)
48186228Stmm	    bus_space_write_2(t, h1, o1, bus_space_read_2(t, h2, o2));
48286228Stmm}
48386228Stmm
48493052Stmmstatic __inline void
48593052Stmmbus_space_copy_region_4(bus_space_tag_t t, bus_space_handle_t h1,
48693052Stmm    bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
48786228Stmm{
488216143Sbrucec
489178860Smarius	for (; c; c--, o1 += 4, o2 += 4)
49086228Stmm	    bus_space_write_4(t, h1, o1, bus_space_read_4(t, h2, o2));
49186228Stmm}
49286228Stmm
49393052Stmmstatic __inline void
49493052Stmmbus_space_copy_region_8(bus_space_tag_t t, bus_space_handle_t h1,
49593052Stmm    bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
49686228Stmm{
497216143Sbrucec
498178860Smarius	for (; c; c--, o1 += 8, o2 += 8)
49986228Stmm	    bus_space_write_8(t, h1, o1, bus_space_read_8(t, h2, o2));
50086228Stmm}
50186228Stmm
502104304Sjakestatic __inline uint8_t
503104304Sjakebus_space_read_stream_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
504104304Sjake{
50586228Stmm
506104304Sjake	__BUS_DEBUG_ACCESS(h, o, "read stream", 1);
507108815Stmm	return (lduba_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type]));
508104304Sjake}
50986228Stmm
510104304Sjakestatic __inline uint16_t
511104304Sjakebus_space_read_stream_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
512104304Sjake{
51386228Stmm
514104304Sjake	__BUS_DEBUG_ACCESS(h, o, "read stream", 2);
515108815Stmm	return (lduha_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type]));
516104304Sjake}
51786228Stmm
518104304Sjakestatic __inline uint32_t
519104304Sjakebus_space_read_stream_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
520104304Sjake{
52186228Stmm
522104304Sjake	__BUS_DEBUG_ACCESS(h, o, "read stream", 4);
523108815Stmm	return (lduwa_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type]));
524104304Sjake}
52586228Stmm
526104304Sjakestatic __inline uint64_t
527104304Sjakebus_space_read_stream_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
528104304Sjake{
52986228Stmm
530104304Sjake	__BUS_DEBUG_ACCESS(h, o, "read stream", 8);
531108815Stmm	return (ldxa_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type]));
532104304Sjake}
53386228Stmm
534104304Sjakestatic __inline void
535104304Sjakebus_space_read_multi_stream_1(bus_space_tag_t t, bus_space_handle_t h,
536104304Sjake    bus_size_t o, uint8_t *a, size_t c)
537104304Sjake{
538216143Sbrucec
539104304Sjake	while (c-- > 0)
540104304Sjake		*a++ = bus_space_read_stream_1(t, h, o);
541104304Sjake}
54286228Stmm
543104304Sjakestatic __inline void
544104304Sjakebus_space_read_multi_stream_2(bus_space_tag_t t, bus_space_handle_t h,
545104304Sjake    bus_size_t o, uint16_t *a, size_t c)
546104304Sjake{
547216143Sbrucec
548104304Sjake	while (c-- > 0)
549104304Sjake		*a++ = bus_space_read_stream_2(t, h, o);
550104304Sjake}
55186228Stmm
552104304Sjakestatic __inline void
553104304Sjakebus_space_read_multi_stream_4(bus_space_tag_t t, bus_space_handle_t h,
554104304Sjake    bus_size_t o, uint32_t *a, size_t c)
555104304Sjake{
556216143Sbrucec
557104304Sjake	while (c-- > 0)
558104304Sjake		*a++ = bus_space_read_stream_4(t, h, o);
559104304Sjake}
56086228Stmm
561104304Sjakestatic __inline void
562104304Sjakebus_space_read_multi_stream_8(bus_space_tag_t t, bus_space_handle_t h,
563104304Sjake    bus_size_t o, uint64_t *a, size_t c)
564104304Sjake{
565216143Sbrucec
566104304Sjake	while (c-- > 0)
567104304Sjake		*a++ = bus_space_read_stream_8(t, h, o);
568104304Sjake}
56986228Stmm
570104304Sjakestatic __inline void
571104304Sjakebus_space_write_stream_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
572104304Sjake    uint8_t v)
573104304Sjake{
57486228Stmm
575104304Sjake	__BUS_DEBUG_ACCESS(h, o, "write stream", 1);
576108815Stmm	stba_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type], v);
577104304Sjake}
57886228Stmm
579104304Sjakestatic __inline void
580104304Sjakebus_space_write_stream_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
581104304Sjake    uint16_t v)
582104304Sjake{
58386228Stmm
584104304Sjake	__BUS_DEBUG_ACCESS(h, o, "write stream", 2);
585108815Stmm	stha_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type], v);
586104304Sjake}
58786228Stmm
58893052Stmmstatic __inline void
589104304Sjakebus_space_write_stream_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
590104304Sjake    uint32_t v)
591104304Sjake{
592104304Sjake
593104304Sjake	__BUS_DEBUG_ACCESS(h, o, "write stream", 4);
594108815Stmm	stwa_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type], v);
595104304Sjake}
596104304Sjake
597104304Sjakestatic __inline void
598104304Sjakebus_space_write_stream_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
599104304Sjake    uint64_t v)
600104304Sjake{
601104304Sjake
602104304Sjake	__BUS_DEBUG_ACCESS(h, o, "write stream", 8);
603108815Stmm	stxa_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type], v);
604104304Sjake}
605104304Sjake
606104304Sjakestatic __inline void
607104304Sjakebus_space_write_multi_stream_1(bus_space_tag_t t, bus_space_handle_t h,
608111383Sobrien    bus_size_t o, const uint8_t *a, size_t c)
609104304Sjake{
610216143Sbrucec
611104304Sjake	while (c-- > 0)
612104304Sjake		bus_space_write_stream_1(t, h, o, *a++);
613104304Sjake}
614104304Sjake
615104304Sjakestatic __inline void
616104304Sjakebus_space_write_multi_stream_2(bus_space_tag_t t, bus_space_handle_t h,
617111353Sobrien    bus_size_t o, const uint16_t *a, size_t c)
618104304Sjake{
619216143Sbrucec
620104304Sjake	while (c-- > 0)
621104304Sjake		bus_space_write_stream_2(t, h, o, *a++);
622104304Sjake}
623104304Sjake
624104304Sjakestatic __inline void
625104304Sjakebus_space_write_multi_stream_4(bus_space_tag_t t, bus_space_handle_t h,
626111383Sobrien    bus_size_t o, const uint32_t *a, size_t c)
627104304Sjake{
628216143Sbrucec
629104304Sjake	while (c-- > 0)
630104304Sjake		bus_space_write_stream_4(t, h, o, *a++);
631104304Sjake}
632104304Sjake
633104304Sjakestatic __inline void
634104304Sjakebus_space_write_multi_stream_8(bus_space_tag_t t, bus_space_handle_t h,
635111383Sobrien    bus_size_t o, const uint64_t *a, size_t c)
636104304Sjake{
637216143Sbrucec
638104304Sjake	while (c-- > 0)
639104304Sjake		bus_space_write_stream_8(t, h, o, *a++);
640104304Sjake}
641104304Sjake
642104304Sjakestatic __inline void
643104304Sjakebus_space_set_multi_stream_1(bus_space_tag_t t, bus_space_handle_t h,
644104304Sjake    bus_size_t o, uint8_t v, size_t c)
645104304Sjake{
646216143Sbrucec
647104304Sjake	while (c-- > 0)
648104304Sjake		bus_space_write_stream_1(t, h, o, v);
649104304Sjake}
650104304Sjake
651104304Sjakestatic __inline void
652104304Sjakebus_space_set_multi_stream_2(bus_space_tag_t t, bus_space_handle_t h,
653104304Sjake    bus_size_t o, uint16_t v, size_t c)
654104304Sjake{
655216143Sbrucec
656104304Sjake	while (c-- > 0)
657104304Sjake		bus_space_write_stream_2(t, h, o, v);
658104304Sjake}
659104304Sjake
660104304Sjakestatic __inline void
661104304Sjakebus_space_set_multi_stream_4(bus_space_tag_t t, bus_space_handle_t h,
662104304Sjake    bus_size_t o, uint32_t v, size_t c)
663104304Sjake{
664216143Sbrucec
665104304Sjake	while (c-- > 0)
666104304Sjake		bus_space_write_stream_4(t, h, o, v);
667104304Sjake}
668104304Sjake
669104304Sjakestatic __inline void
670104304Sjakebus_space_set_multi_stream_8(bus_space_tag_t t, bus_space_handle_t h,
671104304Sjake    bus_size_t o, uint64_t v, size_t c)
672104304Sjake{
673216143Sbrucec
674104304Sjake	while (c-- > 0)
675104304Sjake		bus_space_write_stream_8(t, h, o, v);
676104304Sjake}
677104304Sjake
678104304Sjakestatic __inline void
67993052Stmmbus_space_read_region_stream_1(bus_space_tag_t t, bus_space_handle_t h,
680178860Smarius    bus_size_t o, uint8_t *a, bus_size_t c)
68186228Stmm{
682216143Sbrucec
68386228Stmm	for (; c; a++, c--, o++)
68486228Stmm		*a = bus_space_read_stream_1(t, h, o);
68586228Stmm}
68686228Stmm
68793052Stmmstatic __inline void
68893052Stmmbus_space_read_region_stream_2(bus_space_tag_t t, bus_space_handle_t h,
689178860Smarius    bus_size_t o, uint16_t *a, bus_size_t c)
69086228Stmm{
691216143Sbrucec
692178860Smarius	for (; c; a++, c--, o += 2)
69386228Stmm		*a = bus_space_read_stream_2(t, h, o);
69486228Stmm}
69586228Stmm
69693052Stmmstatic __inline void
69793052Stmmbus_space_read_region_stream_4(bus_space_tag_t t, bus_space_handle_t h,
698178860Smarius    bus_size_t o, uint32_t *a, bus_size_t c)
69986228Stmm{
700216143Sbrucec
701178860Smarius	for (; c; a++, c--, o += 4)
70286228Stmm		*a = bus_space_read_stream_4(t, h, o);
70386228Stmm}
70486228Stmm
70593052Stmmstatic __inline void
70693052Stmmbus_space_read_region_stream_8(bus_space_tag_t t, bus_space_handle_t h,
707178860Smarius    bus_size_t o, uint64_t *a, bus_size_t c)
70886228Stmm{
709216143Sbrucec
710178860Smarius	for (; c; a++, c--, o += 8)
71186228Stmm		*a = bus_space_read_stream_8(t, h, o);
71286228Stmm}
71386228Stmm
71493052Stmmstatic __inline void
71593052Stmmbus_space_write_region_stream_1(bus_space_tag_t t, bus_space_handle_t h,
716178860Smarius    bus_size_t o, const uint8_t *a, bus_size_t c)
71786228Stmm{
718216143Sbrucec
71986228Stmm	for (; c; a++, c--, o++)
72086228Stmm		bus_space_write_stream_1(t, h, o, *a);
72186228Stmm}
72286228Stmm
72393052Stmmstatic __inline void
72493052Stmmbus_space_write_region_stream_2(bus_space_tag_t t, bus_space_handle_t h,
725178860Smarius    bus_size_t o, const uint16_t *a, bus_size_t c)
72686228Stmm{
727216143Sbrucec
728178860Smarius	for (; c; a++, c--, o += 2)
72986228Stmm		bus_space_write_stream_2(t, h, o, *a);
73086228Stmm}
73186228Stmm
73293052Stmmstatic __inline void
73393052Stmmbus_space_write_region_stream_4(bus_space_tag_t t, bus_space_handle_t h,
734178860Smarius    bus_size_t o, const uint32_t *a, bus_size_t c)
73586228Stmm{
736216143Sbrucec
737178860Smarius	for (; c; a++, c--, o += 4)
73886228Stmm		bus_space_write_stream_4(t, h, o, *a);
73986228Stmm}
74086228Stmm
74193052Stmmstatic __inline void
74293052Stmmbus_space_write_region_stream_8(bus_space_tag_t t, bus_space_handle_t h,
743178860Smarius    bus_size_t o, const uint64_t *a, bus_size_t c)
74486228Stmm{
745216143Sbrucec
746178860Smarius	for (; c; a++, c--, o += 8)
74786228Stmm		bus_space_write_stream_8(t, h, o, *a);
74886228Stmm}
74986228Stmm
75093052Stmmstatic __inline void
75193052Stmmbus_space_set_region_stream_1(bus_space_tag_t t, bus_space_handle_t h,
752178860Smarius    bus_size_t o, const uint8_t v, bus_size_t c)
75386228Stmm{
754216143Sbrucec
75586228Stmm	for (; c; c--, o++)
75686228Stmm		bus_space_write_stream_1(t, h, o, v);
75786228Stmm}
75886228Stmm
75993052Stmmstatic __inline void
76093052Stmmbus_space_set_region_stream_2(bus_space_tag_t t, bus_space_handle_t h,
761178860Smarius    bus_size_t o, const uint16_t v, bus_size_t c)
76286228Stmm{
763216143Sbrucec
764178860Smarius	for (; c; c--, o += 2)
76586228Stmm		bus_space_write_stream_2(t, h, o, v);
76686228Stmm}
76786228Stmm
76893052Stmmstatic __inline void
76993052Stmmbus_space_set_region_stream_4(bus_space_tag_t t, bus_space_handle_t h,
770178860Smarius    bus_size_t o, const uint32_t v, bus_size_t c)
77186228Stmm{
772216143Sbrucec
773178860Smarius	for (; c; c--, o += 4)
77486228Stmm		bus_space_write_stream_4(t, h, o, v);
77586228Stmm}
77686228Stmm
77793052Stmmstatic __inline void
77893052Stmmbus_space_set_region_stream_8(bus_space_tag_t t, bus_space_handle_t h,
779178860Smarius    bus_size_t o, const uint64_t v, bus_size_t c)
78086228Stmm{
781216143Sbrucec
782178860Smarius	for (; c; c--, o += 8)
78386228Stmm		bus_space_write_stream_8(t, h, o, v);
78486228Stmm}
78586228Stmm
78693052Stmmstatic __inline void
78793052Stmmbus_space_copy_region_stream_1(bus_space_tag_t t, bus_space_handle_t h1,
78893052Stmm    bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
78986228Stmm{
790216143Sbrucec
79186228Stmm	for (; c; c--, o1++, o2++)
79286228Stmm	    bus_space_write_stream_1(t, h1, o1, bus_space_read_stream_1(t, h2,
79386228Stmm		o2));
79486228Stmm}
79586228Stmm
79693052Stmmstatic __inline void
79793052Stmmbus_space_copy_region_stream_2(bus_space_tag_t t, bus_space_handle_t h1,
79893052Stmm    bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
79986228Stmm{
800216143Sbrucec
801178860Smarius	for (; c; c--, o1 += 2, o2 += 2)
80286228Stmm	    bus_space_write_stream_2(t, h1, o1, bus_space_read_stream_2(t, h2,
80386228Stmm		o2));
80486228Stmm}
80586228Stmm
80693052Stmmstatic __inline void
80793052Stmmbus_space_copy_region_stream_4(bus_space_tag_t t, bus_space_handle_t h1,
80893052Stmm    bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
80986228Stmm{
810216143Sbrucec
811178860Smarius	for (; c; c--, o1 += 4, o2 += 4)
81286228Stmm	    bus_space_write_stream_4(t, h1, o1, bus_space_read_stream_4(t, h2,
81386228Stmm		o2));
81486228Stmm}
81586228Stmm
81693052Stmmstatic __inline void
81793052Stmmbus_space_copy_region_stream_8(bus_space_tag_t t, bus_space_handle_t h1,
81893052Stmm    bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
81986228Stmm{
820216143Sbrucec
821178860Smarius	for (; c; c--, o1 += 8, o2 += 8)
82286228Stmm	    bus_space_write_stream_8(t, h1, o1, bus_space_read_8(t, h2, o2));
82386228Stmm}
82486228Stmm
825116659Sjmgstatic __inline int
826116659Sjmgbus_space_peek_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
827178860Smarius	uint8_t *a)
828116659Sjmg{
829116659Sjmg
830116659Sjmg	__BUS_DEBUG_ACCESS(h, o, "peek", 1);
831116659Sjmg	return (fasword8(bus_type_asi[t->bst_type], (caddr_t)(h + o), a));
832116659Sjmg}
833116659Sjmg
834116659Sjmgstatic __inline int
835116659Sjmgbus_space_peek_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
836178860Smarius	uint16_t *a)
837116659Sjmg{
838116659Sjmg
839116659Sjmg	__BUS_DEBUG_ACCESS(h, o, "peek", 2);
840116659Sjmg	return (fasword16(bus_type_asi[t->bst_type], (caddr_t)(h + o), a));
841116659Sjmg}
842116659Sjmg
843116659Sjmgstatic __inline int
844116659Sjmgbus_space_peek_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
845178860Smarius	uint32_t *a)
846116659Sjmg{
847116659Sjmg
848116659Sjmg	__BUS_DEBUG_ACCESS(h, o, "peek", 4);
849116659Sjmg	return (fasword32(bus_type_asi[t->bst_type], (caddr_t)(h + o), a));
850116659Sjmg}
851116659Sjmg
852143598Sscottl#include <machine/bus_dma.h>
85386228Stmm
85480708Sjake#endif /* !_MACHINE_BUS_H_ */
855