Home | History | Annotate | Line # | Download | only in include
bus.h revision 1.3
      1  1.3     skrll /*	$NetBSD: bus.h,v 1.3 2019/09/23 16:17:56 skrll Exp $	*/
      2  1.1  kiyohara 
      3  1.1  kiyohara /*-
      4  1.1  kiyohara  * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
      5  1.1  kiyohara  * All rights reserved.
      6  1.1  kiyohara  *
      7  1.1  kiyohara  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  kiyohara  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  1.1  kiyohara  * NASA Ames Research Center.
     10  1.1  kiyohara  *
     11  1.1  kiyohara  * Redistribution and use in source and binary forms, with or without
     12  1.1  kiyohara  * modification, are permitted provided that the following conditions
     13  1.1  kiyohara  * are met:
     14  1.1  kiyohara  * 1. Redistributions of source code must retain the above copyright
     15  1.1  kiyohara  *    notice, this list of conditions and the following disclaimer.
     16  1.1  kiyohara  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1  kiyohara  *    notice, this list of conditions and the following disclaimer in the
     18  1.1  kiyohara  *    documentation and/or other materials provided with the distribution.
     19  1.1  kiyohara  * 3. All advertising materials mentioning features or use of this software
     20  1.1  kiyohara  *    must display the following acknowledgement:
     21  1.1  kiyohara  *	This product includes software developed by the NetBSD
     22  1.1  kiyohara  *	Foundation, Inc. and its contributors.
     23  1.1  kiyohara  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  1.1  kiyohara  *    contributors may be used to endorse or promote products derived
     25  1.1  kiyohara  *    from this software without specific prior written permission.
     26  1.1  kiyohara  *
     27  1.1  kiyohara  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  1.1  kiyohara  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  1.1  kiyohara  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  1.1  kiyohara  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  1.1  kiyohara  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  1.1  kiyohara  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  1.1  kiyohara  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  1.1  kiyohara  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  1.1  kiyohara  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  1.1  kiyohara  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  1.1  kiyohara  * POSSIBILITY OF SUCH DAMAGE.
     38  1.1  kiyohara  */
     39  1.1  kiyohara 
     40  1.1  kiyohara /*
     41  1.1  kiyohara  * Copyright (c) 1996 Charles M. Hannum.  All rights reserved.
     42  1.1  kiyohara  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
     43  1.1  kiyohara  *
     44  1.1  kiyohara  * Redistribution and use in source and binary forms, with or without
     45  1.1  kiyohara  * modification, are permitted provided that the following conditions
     46  1.1  kiyohara  * are met:
     47  1.1  kiyohara  * 1. Redistributions of source code must retain the above copyright
     48  1.1  kiyohara  *    notice, this list of conditions and the following disclaimer.
     49  1.1  kiyohara  * 2. Redistributions in binary form must reproduce the above copyright
     50  1.1  kiyohara  *    notice, this list of conditions and the following disclaimer in the
     51  1.1  kiyohara  *    documentation and/or other materials provided with the distribution.
     52  1.1  kiyohara  * 3. All advertising materials mentioning features or use of this software
     53  1.1  kiyohara  *    must display the following acknowledgement:
     54  1.1  kiyohara  *      This product includes software developed by Christopher G. Demetriou
     55  1.1  kiyohara  *	for the NetBSD Project.
     56  1.1  kiyohara  * 4. The name of the author may not be used to endorse or promote products
     57  1.1  kiyohara  *    derived from this software without specific prior written permission
     58  1.1  kiyohara  *
     59  1.1  kiyohara  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     60  1.1  kiyohara  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     61  1.1  kiyohara  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     62  1.1  kiyohara  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     63  1.1  kiyohara  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     64  1.1  kiyohara  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     65  1.1  kiyohara  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     66  1.1  kiyohara  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     67  1.1  kiyohara  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     68  1.1  kiyohara  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     69  1.1  kiyohara  */
     70  1.1  kiyohara 
     71  1.1  kiyohara #ifndef _IA64_BUS_H_
     72  1.1  kiyohara #define _IA64_BUS_H_
     73  1.1  kiyohara 
     74  1.1  kiyohara #include <sys/systm.h>
     75  1.1  kiyohara 
     76  1.1  kiyohara #include <machine/cpufunc.h>
     77  1.1  kiyohara #include <machine/vmparam.h>
     78  1.1  kiyohara 
     79  1.1  kiyohara #ifdef BUS_SPACE_DEBUG
     80  1.1  kiyohara /*
     81  1.1  kiyohara  * Macros for sanity-checking the aligned-ness of pointers passed to
     82  1.1  kiyohara  * bus space ops.  These are not strictly necessary on the x86, but
     83  1.1  kiyohara  * could lead to performance improvements, and help catch problems
     84  1.1  kiyohara  * with drivers that would creep up on other architectures.
     85  1.1  kiyohara  */
     86  1.1  kiyohara #define	__BUS_SPACE_ALIGNED_ADDRESS(p, t)				\
     87  1.1  kiyohara 	((((u_long)(p)) & (sizeof(t)-1)) == 0)
     88  1.1  kiyohara 
     89  1.1  kiyohara #define	__BUS_SPACE_ADDRESS_SANITY(p, t, d)				\
     90  1.1  kiyohara ({									\
     91  1.1  kiyohara 	if (__BUS_SPACE_ALIGNED_ADDRESS((p), t) == 0) {			\
     92  1.1  kiyohara 		printf("%s 0x%lx not aligned to %d bytes %s:%d\n",	\
     93  1.1  kiyohara 		    d, (u_long)(p), sizeof(t), __FILE__, __LINE__);	\
     94  1.1  kiyohara 	}								\
     95  1.1  kiyohara 	(void) 0;							\
     96  1.1  kiyohara })
     97  1.1  kiyohara 
     98  1.1  kiyohara #define BUS_SPACE_ALIGNED_POINTER(p, t) __BUS_SPACE_ALIGNED_ADDRESS(p, t)
     99  1.1  kiyohara #else
    100  1.1  kiyohara #define	__BUS_SPACE_ADDRESS_SANITY(p,t,d)	(void) 0
    101  1.1  kiyohara #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
    102  1.1  kiyohara #endif /* BUS_SPACE_DEBUG */
    103  1.1  kiyohara 
    104  1.1  kiyohara /*
    105  1.1  kiyohara  * bus_space_map flags
    106  1.1  kiyohara  */
    107  1.1  kiyohara 
    108  1.1  kiyohara #define	BUS_SPACE_MAP_CACHEABLE		0x01
    109  1.1  kiyohara #define	BUS_SPACE_MAP_LINEAR		0x02
    110  1.1  kiyohara #define	BUS_SPACE_MAP_PREFETCHABLE	0x04
    111  1.1  kiyohara 
    112  1.1  kiyohara /*
    113  1.1  kiyohara  * Derived from x86 implementation, ia64 has both i/o and mem spaces
    114  1.1  kiyohara  * These values are for bus space tag.
    115  1.1  kiyohara  */
    116  1.1  kiyohara #define IA64_BUS_SPACE_IO	 0	 /* space is i/o space */
    117  1.1  kiyohara #define IA64_BUS_SPACE_MEM	 1	 /* space is mem space */
    118  1.1  kiyohara 
    119  1.1  kiyohara #define __BUS_SPACE_HAS_STREAM_METHODS 1
    120  1.1  kiyohara 
    121  1.1  kiyohara /*
    122  1.1  kiyohara  * Bus address and size types
    123  1.1  kiyohara  */
    124  1.1  kiyohara typedef u_long bus_addr_t;
    125  1.1  kiyohara typedef u_long bus_size_t;
    126  1.1  kiyohara 
    127  1.3     skrll #define PRIxBUSADDR	"lx"
    128  1.3     skrll #define PRIxBUSSIZE	"lx"
    129  1.3     skrll #define PRIuBUSSIZE	"lu"
    130  1.3     skrll 
    131  1.1  kiyohara /*
    132  1.1  kiyohara  * Access methods for bus resources and address space.
    133  1.1  kiyohara  */
    134  1.1  kiyohara typedef	int bus_space_tag_t;
    135  1.1  kiyohara typedef	u_long bus_space_handle_t;
    136  1.1  kiyohara 
    137  1.3     skrll #define PRIxBSH		"lx"
    138  1.3     skrll 
    139  1.1  kiyohara /* map/unmap */
    140  1.1  kiyohara 
    141  1.1  kiyohara int	ia64_bus_space_map(bus_space_tag_t, bus_addr_t,
    142  1.1  kiyohara 	    bus_size_t, int, bus_space_handle_t *);
    143  1.1  kiyohara void	ia64_bus_space_unmap(bus_space_tag_t, bus_space_handle_t,
    144  1.1  kiyohara 	    bus_size_t);
    145  1.1  kiyohara int	ia64_bus_space_subregion(bus_space_tag_t, bus_space_handle_t,
    146  1.1  kiyohara 	    bus_size_t, bus_size_t, bus_space_handle_t *);
    147  1.1  kiyohara #define	bus_space_map(t, a, s, f, hp)					\
    148  1.1  kiyohara 	ia64_bus_space_map((t), (a), (s), (f), (hp))
    149  1.1  kiyohara #define bus_space_unmap(t, h, s)					\
    150  1.1  kiyohara 	ia64_bus_space_unmap((t), (h), (s))
    151  1.1  kiyohara #define bus_space_subregion(t, h, o, s, nhp)				\
    152  1.1  kiyohara 	ia64_bus_space_subregion((t), (h), (o), (s), (nhp))
    153  1.1  kiyohara 
    154  1.1  kiyohara /* vaddr */
    155  1.1  kiyohara 
    156  1.1  kiyohara #define bus_space_vaddr(t, h) \
    157  1.1  kiyohara 	((t) == IA64_BUS_SPACE_MEM ? (void *)(h) : (void *)0)
    158  1.1  kiyohara 
    159  1.1  kiyohara /* map to user space */
    160  1.1  kiyohara 
    161  1.1  kiyohara paddr_t	ia64_bus_space_mmap(bus_space_tag_t, bus_addr_t, off_t, int, int);
    162  1.1  kiyohara 
    163  1.1  kiyohara #define	bus_space_mmap(t, b, o, p, f)					\
    164  1.1  kiyohara 	ia64_bus_space_mmap((t), (b), (o), (p), (f))
    165  1.1  kiyohara 
    166  1.1  kiyohara /* alloc/free */
    167  1.1  kiyohara 
    168  1.1  kiyohara int	ia64_bus_space_alloc(bus_space_tag_t, bus_addr_t, bus_addr_t,
    169  1.1  kiyohara 	    bus_size_t, bus_size_t, bus_size_t, int, bus_addr_t *,
    170  1.1  kiyohara 	    bus_space_handle_t *);
    171  1.1  kiyohara void	ia64_bus_space_free(bus_space_tag_t, bus_space_handle_t, bus_size_t);
    172  1.1  kiyohara 
    173  1.1  kiyohara #define bus_space_alloc(t, rs, re, s, a, b, f, ap, hp)			\
    174  1.1  kiyohara 	ia64_bus_space__alloc((t), (rs), (re), (s), (a), (b), (f), (ap), (hp))
    175  1.1  kiyohara #define bus_space_free(t, h, s)						\
    176  1.1  kiyohara 	ia64_bus_space_free((t), (h), (s))
    177  1.1  kiyohara 
    178  1.1  kiyohara /*
    179  1.1  kiyohara  *	uintN_t bus_space_read_N(bus_space_tag_t tag,
    180  1.1  kiyohara  *	    bus_space_handle_t bsh, bus_size_t offset);
    181  1.1  kiyohara  *
    182  1.1  kiyohara  * Read a 1, 2, 4, or 8 byte quantity from bus space
    183  1.1  kiyohara  * described by tag/handle/offset.
    184  1.1  kiyohara  */
    185  1.1  kiyohara 
    186  1.1  kiyohara #define	bus_space_read_1(t, h, o)					\
    187  1.1  kiyohara 	((t) == IA64_BUS_SPACE_IO ? (inb((h) + (o))) :\
    188  1.1  kiyohara 	    (*(volatile uint8_t *)((h) + (o))))
    189  1.1  kiyohara 
    190  1.1  kiyohara #define	bus_space_read_2(t, h, o)					\
    191  1.1  kiyohara 	 (__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint16_t, "bus addr"),	\
    192  1.1  kiyohara 	  ((t) == IA64_BUS_SPACE_IO ? (inw((h) + (o))) :		\
    193  1.1  kiyohara 	    (*(volatile uint16_t *)((h) + (o)))))
    194  1.1  kiyohara 
    195  1.1  kiyohara #define	bus_space_read_4(t, h, o)					\
    196  1.1  kiyohara 	 (__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint32_t, "bus addr"),	\
    197  1.1  kiyohara 	  ((t) == IA64_BUS_SPACE_IO ? (inl((h) + (o))) :		\
    198  1.1  kiyohara 	    (*(volatile uint32_t *)((h) + (o)))))
    199  1.1  kiyohara 
    200  1.1  kiyohara #define	bus_space_read_8(t, h, o)					\
    201  1.1  kiyohara 	 (__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint64_t, "bus addr"),	\
    202  1.1  kiyohara 	  ((t) == IA64_BUS_SPACE_IO ?					\
    203  1.1  kiyohara 	    ({ printf("%s: can't read 8bytes from I/O space\n", __FUNCTION__); 0;}) : \
    204  1.1  kiyohara 	    (*(volatile uint64_t *)((h) + (o)))))
    205  1.1  kiyohara 
    206  1.1  kiyohara #define bus_space_read_stream_1 bus_space_read_1
    207  1.1  kiyohara #define bus_space_read_stream_2 bus_space_read_2
    208  1.1  kiyohara #define bus_space_read_stream_4 bus_space_read_4
    209  1.1  kiyohara #define bus_space_read_stream_8 bus_space_read_8
    210  1.1  kiyohara 
    211  1.1  kiyohara /*
    212  1.1  kiyohara  *	void bus_space_read_multi_N(bus_space_tag_t tag,
    213  1.1  kiyohara  *	    bus_space_handle_t bsh, bus_size_t offset,
    214  1.1  kiyohara  *	    uintN_t *addr, size_t count);
    215  1.1  kiyohara  *
    216  1.1  kiyohara  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
    217  1.1  kiyohara  * described by tag/handle/offset and copy into buffer provided.
    218  1.1  kiyohara  */
    219  1.1  kiyohara 
    220  1.1  kiyohara #define	bus_space_read_multi_1(t, h, o, ptr, cnt)			\
    221  1.1  kiyohara do {									\
    222  1.1  kiyohara 	if ((t) == IA64_BUS_SPACE_IO) {					\
    223  1.1  kiyohara 		insb((h) + (o), (ptr), (cnt));				\
    224  1.1  kiyohara 	} else {							\
    225  1.1  kiyohara 		int __i;						\
    226  1.1  kiyohara 		volatile uint8_t *__p = (uint8_t *)((h) + (o));		\
    227  1.1  kiyohara 		uint8_t *__dst = (ptr);					\
    228  1.1  kiyohara 		for (__i = 0; __i < (cnt); __i++)			\
    229  1.1  kiyohara 			*__dst++ = *__p;				\
    230  1.1  kiyohara 	}								\
    231  1.1  kiyohara } while (/* CONSTCOND */ 0)
    232  1.1  kiyohara 
    233  1.1  kiyohara #define	bus_space_read_multi_2(t, h, o, ptr, cnt)			\
    234  1.1  kiyohara do {									\
    235  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((ptr), uint16_t, "buffer");		\
    236  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint16_t, "bus addr");	\
    237  1.1  kiyohara 	if ((t) == IA64_BUS_SPACE_IO) {					\
    238  1.1  kiyohara 		insw((h) + (o), (ptr), (cnt));				\
    239  1.1  kiyohara 	} else {							\
    240  1.1  kiyohara 		int __i;						\
    241  1.1  kiyohara 		volatile uint16_t *__p = (uint16_t *)((h) + (o));	\
    242  1.1  kiyohara 		uint16_t *__dst = (ptr);				\
    243  1.1  kiyohara 		for (__i = 0; __i < (cnt); __i++)			\
    244  1.1  kiyohara 			*__dst++ = *__p;				\
    245  1.1  kiyohara 	}								\
    246  1.1  kiyohara } while (/* CONSTCOND */ 0)
    247  1.1  kiyohara 
    248  1.1  kiyohara #define	bus_space_read_multi_4(t, h, o, ptr, cnt)			\
    249  1.1  kiyohara do {									\
    250  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((ptr), uint32_t, "buffer");		\
    251  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint32_t, "bus addr");	\
    252  1.1  kiyohara 	if ((t) == IA64_BUS_SPACE_IO) {					\
    253  1.1  kiyohara 		insl((h) + (o), (ptr), (cnt));				\
    254  1.1  kiyohara 	} else {							\
    255  1.1  kiyohara 		int __i;						\
    256  1.1  kiyohara 		volatile uint32_t *__p = (uint32_t *)((h) + (o));	\
    257  1.1  kiyohara 		uint32_t *__dst = (ptr);				\
    258  1.1  kiyohara 		for (__i = 0; __i < (cnt); __i++)			\
    259  1.1  kiyohara 			*__dst++ = *__p;				\
    260  1.1  kiyohara 	}								\
    261  1.1  kiyohara } while (/* CONSTCOND */ 0)
    262  1.1  kiyohara 
    263  1.1  kiyohara #define	bus_space_read_multi_8(t, h, o, ptr, cnt)			\
    264  1.1  kiyohara do {									\
    265  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((ptr), uint64_t, "buffer");		\
    266  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint64_t, "bus addr");	\
    267  1.1  kiyohara 	if ((t) == IA64_BUS_SPACE_IO) {					\
    268  1.1  kiyohara 		printf("%s: can't read 8bytes from I/O space\n",	\
    269  1.1  kiyohara 		    __FUNCTION__);					\
    270  1.1  kiyohara 	} else {							\
    271  1.1  kiyohara 		int __i;						\
    272  1.1  kiyohara 		volatile uint64_t *__p = (uint64_t *)((h) + (o));	\
    273  1.1  kiyohara 		uint64_t *__dst = (ptr);				\
    274  1.1  kiyohara 		for (__i = 0; __i < (cnt); __i++)			\
    275  1.1  kiyohara 			*__dst++ = *__p;				\
    276  1.1  kiyohara 	}								\
    277  1.1  kiyohara } while (/* CONSTCOND */ 0)
    278  1.1  kiyohara 
    279  1.1  kiyohara #define bus_space_read_multi_stream_1 bus_space_read_multi_1
    280  1.1  kiyohara #define bus_space_read_multi_stream_2 bus_space_read_multi_2
    281  1.1  kiyohara #define bus_space_read_multi_stream_4 bus_space_read_multi_4
    282  1.1  kiyohara #define bus_space_read_multi_stream_8 bus_space_read_multi_8
    283  1.1  kiyohara 
    284  1.1  kiyohara 
    285  1.1  kiyohara /*
    286  1.1  kiyohara  *	void bus_space_read_region_N(bus_space_tag_t tag,
    287  1.1  kiyohara  *	    bus_space_handle_t bsh, bus_size_t offset,
    288  1.1  kiyohara  *	    uintN_t *addr, size_t count);
    289  1.1  kiyohara  *
    290  1.1  kiyohara  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
    291  1.1  kiyohara  * described by tag/handle and starting at `offset' and copy into
    292  1.1  kiyohara  * buffer provided.
    293  1.1  kiyohara  */
    294  1.1  kiyohara 
    295  1.1  kiyohara #define	bus_space_read_region_1(t, h, o, ptr, cnt)			\
    296  1.1  kiyohara do {									\
    297  1.1  kiyohara 	if ((t) == IA64_BUS_SPACE_IO) {					\
    298  1.1  kiyohara 		int __i;						\
    299  1.1  kiyohara 		volatile bus_addr_t __port = (h) + (o);			\
    300  1.1  kiyohara 		uint8_t *__dst = (ptr);					\
    301  1.1  kiyohara 		for (__i = 0; __i < (cnt); __i++) {			\
    302  1.1  kiyohara 			*__dst++ = inb(__port);				\
    303  1.1  kiyohara 			__port++;					\
    304  1.1  kiyohara 		}							\
    305  1.1  kiyohara 	} else {							\
    306  1.1  kiyohara 		int __i;						\
    307  1.1  kiyohara 		volatile uint8_t *__p = (uint8_t *)((h) + (o));		\
    308  1.1  kiyohara 		uint8_t *__dst = (ptr);					\
    309  1.1  kiyohara 		for (__i = 0; __i < (cnt); __i++)			\
    310  1.1  kiyohara 			*__dst++ = *__p++;				\
    311  1.1  kiyohara 	}								\
    312  1.1  kiyohara } while (/* CONSTCOND */ 0)
    313  1.1  kiyohara 
    314  1.1  kiyohara #define	bus_space_read_region_2(t, h, o, ptr, cnt)			\
    315  1.1  kiyohara do {									\
    316  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((ptr), uint16_t, "buffer");		\
    317  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint16_t, "bus addr");	\
    318  1.1  kiyohara 	if ((t) == IA64_BUS_SPACE_IO) {					\
    319  1.1  kiyohara 		int __i;						\
    320  1.1  kiyohara 		volatile bus_addr_t __port = (h) + (o);			\
    321  1.1  kiyohara 		uint8_t *__dst = (ptr);					\
    322  1.1  kiyohara 		for (__i = 0; __i < (cnt); __i++) {			\
    323  1.1  kiyohara 			*__dst++ = inb(__port);				\
    324  1.1  kiyohara 			__port += 2;					\
    325  1.1  kiyohara 		}							\
    326  1.1  kiyohara 	} else {							\
    327  1.1  kiyohara 		int __i;						\
    328  1.1  kiyohara 		volatile uint16_t *__p = (uint16_t *)((h) + (o));	\
    329  1.1  kiyohara 		uint16_t *__dst = (ptr);				\
    330  1.1  kiyohara 		for (__i = 0; __i < (cnt); __i++)			\
    331  1.1  kiyohara 			*__dst++ = *__p++;				\
    332  1.1  kiyohara 	}								\
    333  1.1  kiyohara } while (/* CONSTCOND */ 0)
    334  1.1  kiyohara 
    335  1.1  kiyohara #define	bus_space_read_region_4(t, h, o, ptr, cnt)			\
    336  1.1  kiyohara do {									\
    337  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((ptr), uint32_t, "buffer");		\
    338  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint32_t, "bus addr");	\
    339  1.1  kiyohara 	if ((t) == IA64_BUS_SPACE_IO) {					\
    340  1.1  kiyohara 		int __i;						\
    341  1.1  kiyohara 		volatile bus_addr_t __port = (h) + (o);			\
    342  1.1  kiyohara 		uint8_t *__dst = (ptr);					\
    343  1.1  kiyohara 		for (__i = 0; __i < (cnt); __i++) {			\
    344  1.1  kiyohara 			*__dst++ = inb(__port);				\
    345  1.1  kiyohara 			__port += 4;					\
    346  1.1  kiyohara 		}							\
    347  1.1  kiyohara 	} else {							\
    348  1.1  kiyohara 		volatile uint32_t *__p = (uint32_t *)((h) + (o));	\
    349  1.1  kiyohara 		uint32_t *__dst = (ptr);				\
    350  1.1  kiyohara 		for (__i = 0; __i < (cnt); __i++)			\
    351  1.1  kiyohara 			*__dst++ = *__p++;				\
    352  1.1  kiyohara 	}								\
    353  1.1  kiyohara } while (/* CONSTCOND */ 0)
    354  1.1  kiyohara 
    355  1.1  kiyohara #define	bus_space_read_region_8(t, h, o, ptr, cnt)			\
    356  1.1  kiyohara do {									\
    357  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((ptr), uint64_t, "buffer");		\
    358  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint64_t, "bus addr");	\
    359  1.1  kiyohara 	if ((t) == IA64_BUS_SPACE_IO) {					\
    360  1.1  kiyohara 		printf("%s: can't read 8bytes from I/O space\n",	\
    361  1.1  kiyohara 		    __FUNCTION__);					\
    362  1.1  kiyohara 	} else {							\
    363  1.1  kiyohara 		volatile uint64_t *__p = (uint64_t *)((h) + (o));	\
    364  1.1  kiyohara 		uint64_t *__dst = (ptr);				\
    365  1.1  kiyohara 		for (__i = 0; __i < (cnt); __i++)			\
    366  1.1  kiyohara 			*__dst++ = *__p++;				\
    367  1.1  kiyohara 	}								\
    368  1.1  kiyohara } while (/* CONSTCOND */ 0)
    369  1.1  kiyohara 
    370  1.1  kiyohara #define bus_space_read_region_stream_1 bus_space_read_region_1
    371  1.1  kiyohara #define bus_space_read_region_stream_2 bus_space_read_region_2
    372  1.1  kiyohara #define bus_space_read_region_stream_4 bus_space_read_region_4
    373  1.1  kiyohara #define bus_space_read_region_stream_8 bus_space_read_region_8
    374  1.1  kiyohara 
    375  1.1  kiyohara 
    376  1.1  kiyohara /*
    377  1.1  kiyohara  *	void bus_space_write_N(bus_space_tag_t tag,
    378  1.1  kiyohara  *	    bus_space_handle_t bsh, bus_size_t offset,
    379  1.1  kiyohara  *	    uintN_t value);
    380  1.1  kiyohara  *
    381  1.1  kiyohara  * Write the 1, 2, 4, or 8 byte value `value' to bus space
    382  1.1  kiyohara  * described by tag/handle/offset.
    383  1.1  kiyohara  */
    384  1.1  kiyohara 
    385  1.1  kiyohara #define	bus_space_write_1(t, h, o, v)					\
    386  1.1  kiyohara do {									\
    387  1.1  kiyohara 	if ((t) == IA64_BUS_SPACE_IO)					\
    388  1.1  kiyohara 		outb((h) + (o), (v));					\
    389  1.1  kiyohara 	else								\
    390  1.1  kiyohara 		((void)(*(volatile uint8_t *)((h) + (o)) = (v)));	\
    391  1.1  kiyohara } while (/* CONSTCOND */ 0)
    392  1.1  kiyohara 
    393  1.1  kiyohara #define	bus_space_write_2(t, h, o, v)					\
    394  1.1  kiyohara do {									\
    395  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint16_t, "bus addr");	\
    396  1.1  kiyohara 	if ((t) == IA64_BUS_SPACE_IO)					\
    397  1.1  kiyohara 		outw((h) + (o), (v));					\
    398  1.1  kiyohara 	else								\
    399  1.1  kiyohara 		((void)(*(volatile uint16_t *)((h) + (o)) = (v)));	\
    400  1.1  kiyohara } while (/* CONSTCOND */ 0)
    401  1.1  kiyohara 
    402  1.1  kiyohara #define	bus_space_write_4(t, h, o, v)					\
    403  1.1  kiyohara do {									\
    404  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint32_t, "bus addr");	\
    405  1.1  kiyohara 	if ((t) == IA64_BUS_SPACE_IO)					\
    406  1.1  kiyohara 		outl((h) + (o), (v));					\
    407  1.1  kiyohara 	else								\
    408  1.1  kiyohara 		((void)(*(volatile uint32_t *)((h) + (o)) = (v)));	\
    409  1.1  kiyohara } while (/* CONSTCOND */ 0)
    410  1.1  kiyohara 
    411  1.1  kiyohara #define	bus_space_write_8(t, h, o, v)					\
    412  1.1  kiyohara 	 __BUS_SPACE_ADDRESS_SANITY((h) + (o), uint64_t, "bus addr");	\
    413  1.1  kiyohara 	 if ((t) == IA64_BUS_SPACE_IO ?					\
    414  1.1  kiyohara 	     printf("%s: can't write 8bytes to I/O space\n", __FUNCTION__); : \
    415  1.1  kiyohara 	     (*(volatile uint64_t *)((h) + (o)) = (v)))
    416  1.1  kiyohara 
    417  1.1  kiyohara #define bus_space_write_stream_1 bus_space_write_1
    418  1.1  kiyohara #define bus_space_write_stream_2 bus_space_write_2
    419  1.1  kiyohara #define bus_space_write_stream_4 bus_space_write_4
    420  1.1  kiyohara #define bus_space_write_stream_8 bus_space_write_8
    421  1.1  kiyohara 
    422  1.1  kiyohara /*
    423  1.1  kiyohara  *	void bus_space_write_multi_N(bus_space_tag_t tag,
    424  1.1  kiyohara  *	    bus_space_handle_t bsh, bus_size_t offset,
    425  1.1  kiyohara  *	    const uintN_t *addr, size_t count);
    426  1.1  kiyohara  *
    427  1.1  kiyohara  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
    428  1.1  kiyohara  * provided to bus space described by tag/handle/offset.
    429  1.1  kiyohara  */
    430  1.1  kiyohara 
    431  1.1  kiyohara #define	bus_space_write_multi_1(t, h, o, ptr, cnt)			\
    432  1.1  kiyohara do {									\
    433  1.1  kiyohara 	if ((t) == IA64_BUS_SPACE_IO) {					\
    434  1.1  kiyohara 		outsb((h) + (o), (ptr), (cnt));				\
    435  1.1  kiyohara 	} else {							\
    436  1.1  kiyohara 		int __i;						\
    437  1.1  kiyohara 		volatile uint8_t *__p = (uint8_t *)((h) + (o));		\
    438  1.1  kiyohara 		uint8_t *__src = (ptr);					\
    439  1.1  kiyohara 		for (__i = 0; __i < (cnt); __i++)			\
    440  1.1  kiyohara 			*__p = *__src++;				\
    441  1.1  kiyohara 	}								\
    442  1.1  kiyohara } while (/* CONSTCOND */ 0)
    443  1.1  kiyohara 
    444  1.1  kiyohara #define bus_space_write_multi_2(t, h, o, ptr, cnt)			\
    445  1.1  kiyohara do {									\
    446  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((ptr), uint16_t, "buffer");		\
    447  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint16_t, "bus addr");	\
    448  1.1  kiyohara 	if ((t) == IA64_BUS_SPACE_IO) {					\
    449  1.1  kiyohara 		outsw((h) + (o), (ptr), (cnt));				\
    450  1.1  kiyohara 	} else {							\
    451  1.1  kiyohara 		int __i;						\
    452  1.1  kiyohara 		volatile uint16_t *__p = (uint16_t *)((h) + (o));	\
    453  1.1  kiyohara 		uint16_t *__src = (ptr);				\
    454  1.1  kiyohara 		for (__i = 0; __i < (cnt); __i++)			\
    455  1.1  kiyohara 			*__p = *__src++;				\
    456  1.1  kiyohara 	}								\
    457  1.1  kiyohara } while (/* CONSTCOND */ 0)
    458  1.1  kiyohara 
    459  1.1  kiyohara #define bus_space_write_multi_4(t, h, o, ptr, cnt)			\
    460  1.1  kiyohara do {									\
    461  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((ptr), uint32_t, "buffer");		\
    462  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint32_t, "bus addr");	\
    463  1.1  kiyohara 	if ((t) == IA64_BUS_SPACE_IO) {					\
    464  1.1  kiyohara 		outsl((h) + (o), (ptr), (cnt));				\
    465  1.1  kiyohara 	} else {							\
    466  1.1  kiyohara 		int __i;						\
    467  1.1  kiyohara 		volatile uint32_t *__p = (uint32_t *)((h) + (o));	\
    468  1.1  kiyohara 		uint32_t *__src = (ptr);				\
    469  1.1  kiyohara 		for (__i = 0; __i < (cnt); __i++)			\
    470  1.1  kiyohara 			*__p = *__src++;				\
    471  1.1  kiyohara 	}								\
    472  1.1  kiyohara } while (/* CONSTCOND */ 0)
    473  1.1  kiyohara 
    474  1.1  kiyohara #define bus_space_write_multi_8(t, h, o, ptr, cnt)			\
    475  1.1  kiyohara do {									\
    476  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((ptr), uint64_t, "buffer");		\
    477  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint64_t, "bus addr");	\
    478  1.1  kiyohara 	if ((t) == IA64_BUS_SPACE_IO) {					\
    479  1.1  kiyohara 		printf("%s: can't write 8bytes to I/O space\n", __FUNCTION__);\
    480  1.1  kiyohara 	} else {							\
    481  1.1  kiyohara 		int __i;						\
    482  1.1  kiyohara 		volatile uint64_t *__p = (uint64_t *)((h) + (o));	\
    483  1.1  kiyohara 		uint64_t *__src = (ptr);				\
    484  1.1  kiyohara 		for (__i = 0; __i < (cnt); __i++)			\
    485  1.1  kiyohara 			*__p = *__src++;				\
    486  1.1  kiyohara 	}								\
    487  1.1  kiyohara } while (/* CONSTCOND */ 0)
    488  1.1  kiyohara 
    489  1.1  kiyohara #define bus_space_write_multi_stream_1 bus_space_write_multi_1
    490  1.1  kiyohara #define bus_space_write_multi_stream_2 bus_space_write_multi_2
    491  1.1  kiyohara #define bus_space_write_multi_stream_4 bus_space_write_multi_4
    492  1.1  kiyohara #define bus_space_write_multi_stream_8 bus_space_write_multi_8
    493  1.1  kiyohara 
    494  1.1  kiyohara 
    495  1.1  kiyohara /*
    496  1.1  kiyohara  *	void bus_space_write_region_N(bus_space_tag_t tag,
    497  1.1  kiyohara  *	    bus_space_handle_t bsh, bus_size_t offset,
    498  1.1  kiyohara  *	    const uintN_t *addr, size_t count);
    499  1.1  kiyohara  *
    500  1.1  kiyohara  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
    501  1.1  kiyohara  * to bus space described by tag/handle starting at `offset'.
    502  1.1  kiyohara  */
    503  1.1  kiyohara 
    504  1.1  kiyohara #define	bus_space_write_region_1(t, h, o, ptr, cnt)			\
    505  1.1  kiyohara do {									\
    506  1.1  kiyohara 	if ((t) == IA64_BUS_SPACE_IO) {					\
    507  1.1  kiyohara 		int __i;						\
    508  1.1  kiyohara 		volatile bus_addr_t __port = (h) + (o);			\
    509  1.1  kiyohara 		uint8_t *__src = (ptr);					\
    510  1.1  kiyohara 		for (__i = 0; __i < (cnt); __i++) {			\
    511  1.1  kiyohara 			outb(__port, *__src);				\
    512  1.1  kiyohara 			__port++;					\
    513  1.1  kiyohara 			__src++;					\
    514  1.1  kiyohara 		}							\
    515  1.1  kiyohara 	} else {							\
    516  1.1  kiyohara 		int __i;						\
    517  1.1  kiyohara 		volatile uint8_t *__p = (uint8_t *)((h) + (o));		\
    518  1.1  kiyohara 		uint8_t *__src = (ptr);					\
    519  1.1  kiyohara 		for (__i = 0; __i < (cnt); __i++)			\
    520  1.1  kiyohara 			*__p++ = *__src++;				\
    521  1.1  kiyohara 	}								\
    522  1.1  kiyohara } while (/* CONSTCOND */ 0)
    523  1.1  kiyohara 
    524  1.1  kiyohara #define	bus_space_write_region_2(t, h, o, ptr, cnt)			\
    525  1.1  kiyohara do {									\
    526  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((ptr), uint16_t, "buffer");		\
    527  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint16_t, "bus addr");	\
    528  1.1  kiyohara 	if ((t) == IA64_BUS_SPACE_IO) {					\
    529  1.1  kiyohara 		int __i;						\
    530  1.1  kiyohara 		volatile bus_addr_t __port = (h) + (o);			\
    531  1.1  kiyohara 		uint16_t *__src = (ptr);				\
    532  1.1  kiyohara 		for (__i = 0; __i < (cnt); __i++) {			\
    533  1.1  kiyohara 			outw(__port, *__src);				\
    534  1.1  kiyohara 			__port += 2;					\
    535  1.1  kiyohara 			__src++;					\
    536  1.1  kiyohara 		}							\
    537  1.1  kiyohara 	} else {							\
    538  1.1  kiyohara 		int __i;						\
    539  1.1  kiyohara 		volatile uint16_t *__p = (uint16_t *)((h) + (o));	\
    540  1.1  kiyohara 		uint16_t *__src = (ptr);				\
    541  1.1  kiyohara 		for (__i = 0; __i < (cnt); __i++)			\
    542  1.1  kiyohara 			*__p++ = *__src++;				\
    543  1.1  kiyohara 	}								\
    544  1.1  kiyohara } while (/* CONSTCOND */ 0)
    545  1.1  kiyohara 
    546  1.1  kiyohara #define	bus_space_write_region_4(t, h, o, ptr, cnt)			\
    547  1.1  kiyohara do {									\
    548  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((ptr), uint32_t, "buffer");		\
    549  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint32_t, "bus addr");	\
    550  1.1  kiyohara 	if ((t) == IA64_BUS_SPACE_IO) {					\
    551  1.1  kiyohara 		int __i;						\
    552  1.1  kiyohara 		volatile bus_addr_t __port = (h) + (o);			\
    553  1.1  kiyohara 		uint32_t *__src = (ptr);				\
    554  1.1  kiyohara 		for (__i = 0; __i < (cnt); __i++) {			\
    555  1.1  kiyohara 			outl(__port, *__src);				\
    556  1.1  kiyohara 			__port += 4;					\
    557  1.1  kiyohara 			__src++;					\
    558  1.1  kiyohara 		}							\
    559  1.1  kiyohara 	} else {							\
    560  1.1  kiyohara 		int __i;						\
    561  1.1  kiyohara 		volatile uint32_t *__p = (uint32_t *)(h) + (o);		\
    562  1.1  kiyohara 		uint32_t *__src = (ptr);				\
    563  1.1  kiyohara 		for (__i = 0; __i < (cnt); __i++)			\
    564  1.1  kiyohara 			*__p++ = *__src++;				\
    565  1.1  kiyohara 	}								\
    566  1.1  kiyohara } while (/* CONSTCOND */ 0)
    567  1.1  kiyohara 
    568  1.1  kiyohara #define	bus_space_write_region_8(t, h, o, ptr, cnt)			\
    569  1.1  kiyohara do {									\
    570  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((ptr), uint64_t, "buffer");		\
    571  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint64_t, "bus addr");	\
    572  1.1  kiyohara 	if ((t) == IA64_BUS_SPACE_IO) {					\
    573  1.1  kiyohara 		printf("%s: can't write 8bytes to I/O space\n", __FUNCTION__);\
    574  1.1  kiyohara 	} else {							\
    575  1.1  kiyohara 		int __i;						\
    576  1.1  kiyohara 		volatile uint64_t *__p = (uint64_t *)((h) + (o));	\
    577  1.1  kiyohara 		uint64_t *__src = (ptr);				\
    578  1.1  kiyohara 		for (__i = 0; __i < (cnt); __i++)			\
    579  1.1  kiyohara 			*__p++ = *__src++;				\
    580  1.1  kiyohara 	}								\
    581  1.1  kiyohara } while (/* CONSTCOND */ 0)
    582  1.1  kiyohara 
    583  1.1  kiyohara #define bus_space_write_region_stream_1 bus_space_write_region_1
    584  1.1  kiyohara #define bus_space_write_region_stream_2 bus_space_write_region_2
    585  1.1  kiyohara #define bus_space_write_region_stream_4 bus_space_write_region_4
    586  1.1  kiyohara #define bus_space_write_region_stream_8 bus_space_write_region_8
    587  1.1  kiyohara 
    588  1.1  kiyohara 
    589  1.1  kiyohara /*
    590  1.1  kiyohara  *	void bus_space_set_multi_N(bus_space_tag_t tag,
    591  1.1  kiyohara  *	    bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
    592  1.1  kiyohara  *	    size_t count);
    593  1.1  kiyohara  *
    594  1.1  kiyohara  * Write the 1, 2, 4, or 8 byte value `val' to bus space described
    595  1.1  kiyohara  * by tag/handle/offset `count' times.
    596  1.1  kiyohara  */
    597  1.1  kiyohara 
    598  1.1  kiyohara static __inline void ia64_bus_space_set_multi_1(bus_space_tag_t,
    599  1.1  kiyohara 	bus_space_handle_t, bus_size_t, uint8_t, size_t);
    600  1.1  kiyohara static __inline void ia64_bus_space_set_multi_2(bus_space_tag_t,
    601  1.1  kiyohara 	bus_space_handle_t, bus_size_t, uint16_t, size_t);
    602  1.1  kiyohara static __inline void ia64_bus_space_set_multi_4(bus_space_tag_t,
    603  1.1  kiyohara 	bus_space_handle_t, bus_size_t, uint32_t, size_t);
    604  1.1  kiyohara static __inline void ia64_bus_space_set_multi_8(bus_space_tag_t,
    605  1.1  kiyohara 	bus_space_handle_t, bus_size_t, uint64_t, size_t);
    606  1.1  kiyohara 
    607  1.1  kiyohara #define	bus_space_set_multi_1(t, h, o, v, c)				\
    608  1.1  kiyohara 	ia64_bus_space_set_multi_1((t), (h), (o), (v), (c))
    609  1.1  kiyohara 
    610  1.1  kiyohara #define	bus_space_set_multi_2(t, h, o, v, c)				\
    611  1.1  kiyohara do {									\
    612  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint16_t, "bus addr");	\
    613  1.1  kiyohara 	ia64_bus_space_set_multi_2((t), (h), (o), (v), (c));		\
    614  1.1  kiyohara } while (/* CONSTCOND */ 0)
    615  1.1  kiyohara 
    616  1.1  kiyohara #define	bus_space_set_multi_4(t, h, o, v, c)				\
    617  1.1  kiyohara do {									\
    618  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint32_t, "bus addr");	\
    619  1.1  kiyohara 	ia64_bus_space_set_multi_4((t), (h), (o), (v), (c));		\
    620  1.1  kiyohara } while (/* CONSTCOND */ 0)
    621  1.1  kiyohara 
    622  1.1  kiyohara #define	bus_space_set_multi_8(t, h, o, v, c)				\
    623  1.1  kiyohara do {									\
    624  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint64_t, "bus addr");	\
    625  1.1  kiyohara 	ia64_bus_space_set_multi_8((t), (h), (o), (v), (c));		\
    626  1.1  kiyohara } while (/* CONSTCOND */ 0)
    627  1.1  kiyohara 
    628  1.1  kiyohara static __inline void
    629  1.1  kiyohara ia64_bus_space_set_multi_1(bus_space_tag_t t, bus_space_handle_t h,
    630  1.1  kiyohara     bus_size_t o, uint8_t v, size_t c)
    631  1.1  kiyohara {
    632  1.1  kiyohara 	bus_addr_t addr = h + o;
    633  1.1  kiyohara 
    634  1.1  kiyohara 	if (t == IA64_BUS_SPACE_IO)
    635  1.1  kiyohara 		while (c--)
    636  1.1  kiyohara 			outb(addr, v);
    637  1.1  kiyohara 	else
    638  1.1  kiyohara 		while (c--)
    639  1.1  kiyohara 			*(volatile uint8_t *)(addr) = v;
    640  1.1  kiyohara }
    641  1.1  kiyohara 
    642  1.1  kiyohara static __inline void
    643  1.1  kiyohara ia64_bus_space_set_multi_2(bus_space_tag_t t, bus_space_handle_t h,
    644  1.1  kiyohara     bus_size_t o, uint16_t v, size_t c)
    645  1.1  kiyohara {
    646  1.1  kiyohara 	bus_addr_t addr = h + o;
    647  1.1  kiyohara 
    648  1.1  kiyohara 	if (t == IA64_BUS_SPACE_IO)
    649  1.1  kiyohara 		while (c--)
    650  1.1  kiyohara 			outw(addr, v);
    651  1.1  kiyohara 	else
    652  1.1  kiyohara 		while (c--)
    653  1.1  kiyohara 			*(volatile uint16_t *)(addr) = v;
    654  1.1  kiyohara }
    655  1.1  kiyohara 
    656  1.1  kiyohara static __inline void
    657  1.1  kiyohara ia64_bus_space_set_multi_4(bus_space_tag_t t, bus_space_handle_t h,
    658  1.1  kiyohara     bus_size_t o, uint32_t v, size_t c)
    659  1.1  kiyohara {
    660  1.1  kiyohara 	bus_addr_t addr = h + o;
    661  1.1  kiyohara 
    662  1.1  kiyohara 	if (t == IA64_BUS_SPACE_IO)
    663  1.1  kiyohara 		while (c--)
    664  1.1  kiyohara 			outl(addr, v);
    665  1.1  kiyohara 	else
    666  1.1  kiyohara 		while (c--)
    667  1.1  kiyohara 			*(volatile uint32_t *)(addr) = v;
    668  1.1  kiyohara }
    669  1.1  kiyohara 
    670  1.1  kiyohara static __inline void
    671  1.1  kiyohara ia64_bus_space_set_multi_8(bus_space_tag_t t, bus_space_handle_t h,
    672  1.1  kiyohara     bus_size_t o, uint64_t v, size_t c)
    673  1.1  kiyohara {
    674  1.1  kiyohara 	bus_addr_t addr = h + o;
    675  1.1  kiyohara 
    676  1.1  kiyohara 	if (t == IA64_BUS_SPACE_IO)
    677  1.1  kiyohara 		printf("%s: can't write 8bytes to I/O space\n", __FUNCTION__);
    678  1.1  kiyohara 	else
    679  1.1  kiyohara 		while (c--)
    680  1.1  kiyohara 			*(volatile uint64_t *)(addr) = v;
    681  1.1  kiyohara }
    682  1.1  kiyohara 
    683  1.1  kiyohara 
    684  1.1  kiyohara /*
    685  1.1  kiyohara  *	void bus_space_set_region_N(bus_space_tag_t tag,
    686  1.1  kiyohara  *	    bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
    687  1.1  kiyohara  *	    size_t count);
    688  1.1  kiyohara  *
    689  1.1  kiyohara  * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
    690  1.1  kiyohara  * by tag/handle starting at `offset'.
    691  1.1  kiyohara  */
    692  1.1  kiyohara 
    693  1.1  kiyohara static __inline void ia64_bus_space_set_region_1(bus_space_tag_t,
    694  1.1  kiyohara 	bus_space_handle_t, bus_size_t, uint8_t, size_t);
    695  1.1  kiyohara static __inline void ia64_bus_space_set_region_2(bus_space_tag_t,
    696  1.1  kiyohara 	bus_space_handle_t, bus_size_t, uint16_t, size_t);
    697  1.1  kiyohara static __inline void ia64_bus_space_set_region_4(bus_space_tag_t,
    698  1.1  kiyohara 	bus_space_handle_t, bus_size_t, uint32_t, size_t);
    699  1.1  kiyohara 
    700  1.1  kiyohara #define	bus_space_set_region_1(t, h, o, v, c)				\
    701  1.1  kiyohara 	ia64_bus_space_set_region_1((t), (h), (o), (v), (c))
    702  1.1  kiyohara 
    703  1.1  kiyohara #define	bus_space_set_region_2(t, h, o, v, c)				\
    704  1.1  kiyohara do {									\
    705  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint16_t, "bus addr");	\
    706  1.1  kiyohara 	ia64_bus_space_set_region_2((t), (h), (o), (v), (c));		\
    707  1.1  kiyohara } while (/* CONSTCOND */ 0)
    708  1.1  kiyohara 
    709  1.1  kiyohara #define	bus_space_set_region_4(t, h, o, v, c)				\
    710  1.1  kiyohara do {									\
    711  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint32_t, "bus addr");	\
    712  1.1  kiyohara 	ia64_bus_space_set_region_4((t), (h), (o), (v), (c));		\
    713  1.1  kiyohara } while (/* CONSTCOND */ 0)
    714  1.1  kiyohara 
    715  1.1  kiyohara #define	bus_space_set_region_8(t, h, o, v, c)				\
    716  1.1  kiyohara do {									\
    717  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint64_t, "bus addr");	\
    718  1.1  kiyohara 	ia64_bus_space_set_region_8((t), (h), (o), (v), (c));		\
    719  1.1  kiyohara } while (/* CONSTCOND */ 0)
    720  1.1  kiyohara 
    721  1.1  kiyohara static __inline void
    722  1.1  kiyohara ia64_bus_space_set_region_1(bus_space_tag_t t, bus_space_handle_t h,
    723  1.1  kiyohara     bus_size_t o, uint8_t v, size_t c)
    724  1.1  kiyohara {
    725  1.1  kiyohara 	bus_addr_t addr = h + o;
    726  1.1  kiyohara 
    727  1.1  kiyohara 	if (t == IA64_BUS_SPACE_IO)
    728  1.1  kiyohara 		for (; c != 0; c--, addr++)
    729  1.1  kiyohara 			outb(addr, v);
    730  1.1  kiyohara 	else
    731  1.1  kiyohara 		for (; c != 0; c--, addr++)
    732  1.1  kiyohara 			*(volatile uint8_t *)(addr) = v;
    733  1.1  kiyohara }
    734  1.1  kiyohara 
    735  1.1  kiyohara static __inline void
    736  1.1  kiyohara ia64_bus_space_set_region_2(bus_space_tag_t t, bus_space_handle_t h,
    737  1.1  kiyohara     bus_size_t o, uint16_t v, size_t c)
    738  1.1  kiyohara {
    739  1.1  kiyohara 	bus_addr_t addr = h + o;
    740  1.1  kiyohara 
    741  1.1  kiyohara 	if (t == IA64_BUS_SPACE_IO)
    742  1.1  kiyohara 		for (; c != 0; c--, addr += 2)
    743  1.1  kiyohara 			outw(addr, v);
    744  1.1  kiyohara 	else
    745  1.1  kiyohara 		for (; c != 0; c--, addr += 2)
    746  1.1  kiyohara 			*(volatile uint16_t *)(addr) = v;
    747  1.1  kiyohara }
    748  1.1  kiyohara 
    749  1.1  kiyohara static __inline void
    750  1.1  kiyohara ia64_bus_space_set_region_4(bus_space_tag_t t, bus_space_handle_t h,
    751  1.1  kiyohara     bus_size_t o, uint32_t v, size_t c)
    752  1.1  kiyohara {
    753  1.1  kiyohara 	bus_addr_t addr = h + o;
    754  1.1  kiyohara 
    755  1.1  kiyohara 	if (t == IA64_BUS_SPACE_IO)
    756  1.1  kiyohara 		for (; c != 0; c--, addr += 4)
    757  1.1  kiyohara 			outl(addr, v);
    758  1.1  kiyohara 	else
    759  1.1  kiyohara 		for (; c != 0; c--, addr += 4)
    760  1.1  kiyohara 			*(volatile uint32_t *)(addr) = v;
    761  1.1  kiyohara }
    762  1.1  kiyohara 
    763  1.1  kiyohara static __inline void
    764  1.1  kiyohara ia64_bus_space_set_region_8(bus_space_tag_t t, bus_space_handle_t h,
    765  1.1  kiyohara     bus_size_t o, uint64_t v, size_t c)
    766  1.1  kiyohara {
    767  1.1  kiyohara 	bus_addr_t addr = h + o;
    768  1.1  kiyohara 
    769  1.1  kiyohara 	if (t == IA64_BUS_SPACE_IO)
    770  1.1  kiyohara 		printf("%s: can't write 8bytes to I/O space\n", __FUNCTION__);
    771  1.1  kiyohara 	else
    772  1.1  kiyohara 		for (; c != 0; c--, addr += 8)
    773  1.1  kiyohara 			*(volatile uint32_t *)(addr) = v;
    774  1.1  kiyohara }
    775  1.1  kiyohara 
    776  1.1  kiyohara 
    777  1.1  kiyohara /*
    778  1.1  kiyohara  *	void bus_space_copy_region_N(bus_space_tag_t tag,
    779  1.1  kiyohara  *	    bus_space_handle_t bsh1, bus_size_t off1,
    780  1.1  kiyohara  *	    bus_space_handle_t bsh2, bus_size_t off2,
    781  1.1  kiyohara  *	    size_t count);
    782  1.1  kiyohara  *
    783  1.1  kiyohara  * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
    784  1.1  kiyohara  * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
    785  1.1  kiyohara  */
    786  1.1  kiyohara 
    787  1.1  kiyohara static __inline void ia64_bus_space_copy_region_1(bus_space_tag_t,
    788  1.1  kiyohara 	bus_space_handle_t, bus_size_t, bus_space_handle_t,
    789  1.1  kiyohara 	bus_size_t, size_t);
    790  1.1  kiyohara static __inline void ia64_bus_space_copy_region_2(bus_space_tag_t,
    791  1.1  kiyohara 	bus_space_handle_t, bus_size_t, bus_space_handle_t,
    792  1.1  kiyohara 	bus_size_t, size_t);
    793  1.1  kiyohara static __inline void ia64_bus_space_copy_region_4(bus_space_tag_t,
    794  1.1  kiyohara 	bus_space_handle_t, bus_size_t, bus_space_handle_t,
    795  1.1  kiyohara 	bus_size_t, size_t);
    796  1.1  kiyohara 
    797  1.1  kiyohara #define	bus_space_copy_region_1(t, h1, o1, h2, o2, c)			\
    798  1.1  kiyohara 	ia64_bus_space_copy_region_1((t), (h1), (o1), (h2), (o2), (c))
    799  1.1  kiyohara 
    800  1.1  kiyohara #define	bus_space_copy_region_2(t, h1, o1, h2, o2, c)			\
    801  1.1  kiyohara do {									\
    802  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((h1) + (o1), uint16_t, "bus addr 1"); \
    803  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((h2) + (o2), uint16_t, "bus addr 2"); \
    804  1.1  kiyohara 	ia64_bus_space_copy_region_2((t), (h1), (o1), (h2), (o2), (c));	\
    805  1.1  kiyohara } while (/* CONSTCOND */ 0)
    806  1.1  kiyohara 
    807  1.1  kiyohara #define	bus_space_copy_region_4(t, h1, o1, h2, o2, c)			\
    808  1.1  kiyohara do {									\
    809  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((h1) + (o1), uint32_t, "bus addr 1"); \
    810  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((h2) + (o2), uint32_t, "bus addr 2"); \
    811  1.1  kiyohara 	ia64_bus_space_copy_region_4((t), (h1), (o1), (h2), (o2), (c));	\
    812  1.1  kiyohara } while (/* CONSTCOND */ 0)
    813  1.1  kiyohara 
    814  1.1  kiyohara #define	bus_space_copy_region_8(t, h1, o1, h2, o2, c)			\
    815  1.1  kiyohara do {									\
    816  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((h1) + (o1), uint64_t, "bus addr 1"); \
    817  1.1  kiyohara 	__BUS_SPACE_ADDRESS_SANITY((h2) + (o2), uint64_t, "bus addr 2"); \
    818  1.1  kiyohara 	ia64_bus_space_copy_region_8((t), (h1), (o1), (h2), (o2), (c));	\
    819  1.1  kiyohara } while (/* CONSTCOND */ 0)
    820  1.1  kiyohara 
    821  1.1  kiyohara static __inline void
    822  1.1  kiyohara ia64_bus_space_copy_region_1(bus_space_tag_t t,
    823  1.1  kiyohara     bus_space_handle_t h1, bus_size_t o1,
    824  1.1  kiyohara     bus_space_handle_t h2, bus_size_t o2, size_t c)
    825  1.1  kiyohara {
    826  1.1  kiyohara 	bus_addr_t addr1 = h1 + o1;
    827  1.1  kiyohara 	bus_addr_t addr2 = h2 + o2;
    828  1.1  kiyohara 
    829  1.1  kiyohara 	if (t == IA64_BUS_SPACE_IO) {
    830  1.1  kiyohara 		if (addr1 >= addr2) {
    831  1.1  kiyohara 			/* src after dest: copy forward */
    832  1.1  kiyohara 			for (; c != 0; c--, addr1++, addr2++)
    833  1.1  kiyohara 				outb(addr2, inb(addr1));
    834  1.1  kiyohara 		} else {
    835  1.1  kiyohara 			/* dest after src: copy backwards */
    836  1.1  kiyohara 			for (addr1 += (c - 1), addr2 += (c - 1);
    837  1.1  kiyohara 			    c != 0; c--, addr1--, addr2--)
    838  1.1  kiyohara 				outb(addr2, inb(addr1));
    839  1.1  kiyohara 		}
    840  1.1  kiyohara 	} else {
    841  1.1  kiyohara 		if (addr1 >= addr2) {
    842  1.1  kiyohara 			/* src after dest: copy forward */
    843  1.1  kiyohara 			for (; c != 0; c--, addr1++, addr2++)
    844  1.1  kiyohara 				*(volatile uint8_t *)(addr2) =
    845  1.1  kiyohara 				    *(volatile uint8_t *)(addr1);
    846  1.1  kiyohara 		} else {
    847  1.1  kiyohara 			/* dest after src: copy backwards */
    848  1.1  kiyohara 			for (addr1 += (c - 1), addr2 += (c - 1);
    849  1.1  kiyohara 			    c != 0; c--, addr1--, addr2--)
    850  1.1  kiyohara 				*(volatile uint8_t *)(addr2) =
    851  1.1  kiyohara 				    *(volatile uint8_t *)(addr1);
    852  1.1  kiyohara 		}
    853  1.1  kiyohara 	}
    854  1.1  kiyohara }
    855  1.1  kiyohara 
    856  1.1  kiyohara static __inline void
    857  1.1  kiyohara ia64_bus_space_copy_region_2(bus_space_tag_t t,
    858  1.1  kiyohara     bus_space_handle_t h1, bus_size_t o1,
    859  1.1  kiyohara     bus_space_handle_t h2, bus_size_t o2, size_t c)
    860  1.1  kiyohara {
    861  1.1  kiyohara 	bus_addr_t addr1 = h1 + o1;
    862  1.1  kiyohara 	bus_addr_t addr2 = h2 + o2;
    863  1.1  kiyohara 
    864  1.1  kiyohara 	if (t == IA64_BUS_SPACE_IO) {
    865  1.1  kiyohara 		if (addr1 >= addr2) {
    866  1.1  kiyohara 			/* src after dest: copy forward */
    867  1.1  kiyohara 			for (; c != 0; c--, addr1 += 2, addr2 += 2)
    868  1.1  kiyohara 				outw(addr2, inw(addr1));
    869  1.1  kiyohara 		} else {
    870  1.1  kiyohara 			/* dest after src: copy backwards */
    871  1.1  kiyohara 			for (addr1 += 2 * (c - 1), addr2 += 2 * (c - 1);
    872  1.1  kiyohara 			    c != 0; c--, addr1 -= 2, addr2 -= 2)
    873  1.1  kiyohara 				outw(addr2, inw(addr1));
    874  1.1  kiyohara 		}
    875  1.1  kiyohara 	} else {
    876  1.1  kiyohara 		if (addr1 >= addr2) {
    877  1.1  kiyohara 			/* src after dest: copy forward */
    878  1.1  kiyohara 			for (; c != 0; c--, addr1 += 2, addr2 += 2)
    879  1.1  kiyohara 				*(volatile uint16_t *)(addr2) =
    880  1.1  kiyohara 				    *(volatile uint16_t *)(addr1);
    881  1.1  kiyohara 		} else {
    882  1.1  kiyohara 			/* dest after src: copy backwards */
    883  1.1  kiyohara 			for (addr1 += 2 * (c - 1), addr2 += 2 * (c - 1);
    884  1.1  kiyohara 			    c != 0; c--, addr1 -= 2, addr2 -= 2)
    885  1.1  kiyohara 				*(volatile uint16_t *)(addr2) =
    886  1.1  kiyohara 				    *(volatile uint16_t *)(addr1);
    887  1.1  kiyohara 		}
    888  1.1  kiyohara 	}
    889  1.1  kiyohara }
    890  1.1  kiyohara 
    891  1.1  kiyohara static __inline void
    892  1.1  kiyohara ia64_bus_space_copy_region_4(bus_space_tag_t t,
    893  1.1  kiyohara     bus_space_handle_t h1, bus_size_t o1,
    894  1.1  kiyohara     bus_space_handle_t h2, bus_size_t o2, size_t c)
    895  1.1  kiyohara {
    896  1.1  kiyohara 	bus_addr_t addr1 = h1 + o1;
    897  1.1  kiyohara 	bus_addr_t addr2 = h2 + o2;
    898  1.1  kiyohara 
    899  1.1  kiyohara 	if (t == IA64_BUS_SPACE_IO) {
    900  1.1  kiyohara 		if (addr1 >= addr2) {
    901  1.1  kiyohara 			/* src after dest: copy forward */
    902  1.1  kiyohara 			for (; c != 0; c--, addr1 += 4, addr2 += 4)
    903  1.1  kiyohara 				outl(addr2, inl(addr1));
    904  1.1  kiyohara 		} else {
    905  1.1  kiyohara 			/* dest after src: copy backwards */
    906  1.1  kiyohara 			for (addr1 += 4 * (c - 1), addr2 += 4 * (c - 1);
    907  1.1  kiyohara 			    c != 0; c--, addr1 -= 4, addr2 -= 4)
    908  1.1  kiyohara 				outl(addr2, inl(addr1));
    909  1.1  kiyohara 		}
    910  1.1  kiyohara 	} else {
    911  1.1  kiyohara 		if (addr1 >= addr2) {
    912  1.1  kiyohara 			/* src after dest: copy forward */
    913  1.1  kiyohara 			for (; c != 0; c--, addr1 += 4, addr2 += 4)
    914  1.1  kiyohara 				*(volatile uint32_t *)(addr2) =
    915  1.1  kiyohara 				    *(volatile uint32_t *)(addr1);
    916  1.1  kiyohara 		} else {
    917  1.1  kiyohara 			/* dest after src: copy backwards */
    918  1.1  kiyohara 			for (addr1 += 4 * (c - 1), addr2 += 4 * (c - 1);
    919  1.1  kiyohara 			    c != 0; c--, addr1 -= 4, addr2 -= 4)
    920  1.1  kiyohara 				*(volatile uint32_t *)(addr2) =
    921  1.1  kiyohara 				    *(volatile uint32_t *)(addr1);
    922  1.1  kiyohara 		}
    923  1.1  kiyohara 	}
    924  1.1  kiyohara }
    925  1.1  kiyohara 
    926  1.1  kiyohara static __inline void
    927  1.1  kiyohara ia64_bus_space_copy_region_8(bus_space_tag_t t,
    928  1.1  kiyohara     bus_space_handle_t h1, bus_size_t o1,
    929  1.1  kiyohara     bus_space_handle_t h2, bus_size_t o2, size_t c)
    930  1.1  kiyohara {
    931  1.1  kiyohara 	bus_addr_t addr1 = h1 + o1;
    932  1.1  kiyohara 	bus_addr_t addr2 = h2 + o2;
    933  1.1  kiyohara 
    934  1.1  kiyohara 	if (t == IA64_BUS_SPACE_IO) {
    935  1.1  kiyohara 		printf("%s: can't write 8bytes to I/O space\n", __FUNCTION__);
    936  1.1  kiyohara 	} else {
    937  1.1  kiyohara 		if (addr1 >= addr2) {
    938  1.1  kiyohara 			/* src after dest: copy forward */
    939  1.1  kiyohara 			for (; c != 0; c--, addr1 += 8, addr2 += 8)
    940  1.1  kiyohara 				*(volatile uint64_t *)(addr2) =
    941  1.1  kiyohara 				    *(volatile uint64_t *)(addr1);
    942  1.1  kiyohara 		} else {
    943  1.1  kiyohara 			/* dest after src: copy backwards */
    944  1.1  kiyohara 			for (addr1 += 8 * (c - 1), addr2 += 8 * (c - 1);
    945  1.1  kiyohara 			    c != 0; c--, addr1 -= 8, addr2 -= 8)
    946  1.1  kiyohara 				*(volatile uint64_t *)(addr2) =
    947  1.1  kiyohara 				    *(volatile uint64_t *)(addr1);
    948  1.1  kiyohara 		}
    949  1.1  kiyohara 	}
    950  1.1  kiyohara }
    951  1.1  kiyohara 
    952  1.1  kiyohara 
    953  1.1  kiyohara /*
    954  1.1  kiyohara  * Bus read/write barrier methods.
    955  1.1  kiyohara  *
    956  1.1  kiyohara  *	void bus_space_barrier(bus_space_tag_t tag,
    957  1.1  kiyohara  *	    bus_space_handle_t bsh, bus_size_t offset,
    958  1.1  kiyohara  *	    bus_size_t len, int flags);
    959  1.1  kiyohara  *
    960  1.1  kiyohara  * Note: the x86 does not currently require barriers, but we must
    961  1.1  kiyohara  * provide the flags to MI code.
    962  1.1  kiyohara  */
    963  1.1  kiyohara #define	bus_space_barrier(t, h, o, l, f)	\
    964  1.1  kiyohara 	ia64_bus_space_barrier((t), (h), (o), (l), (f))
    965  1.1  kiyohara 
    966  1.1  kiyohara #define	BUS_SPACE_BARRIER_READ	0x01
    967  1.1  kiyohara #define	BUS_SPACE_BARRIER_WRITE	0x02
    968  1.1  kiyohara 
    969  1.1  kiyohara static __inline void
    970  1.1  kiyohara ia64_bus_space_barrier(bus_space_tag_t t, bus_space_handle_t handle,
    971  1.1  kiyohara     bus_size_t offset, bus_size_t length, int flags)
    972  1.1  kiyohara {
    973  1.1  kiyohara 	if (t == IA64_BUS_SPACE_IO)
    974  1.1  kiyohara 		return;
    975  1.1  kiyohara 
    976  1.1  kiyohara 	switch (flags) {
    977  1.1  kiyohara 	case BUS_SPACE_BARRIER_READ:
    978  1.1  kiyohara 		__asm volatile("mf" ::: "memory");
    979  1.1  kiyohara 		break;
    980  1.1  kiyohara 	case BUS_SPACE_BARRIER_WRITE:
    981  1.1  kiyohara 		__asm volatile("mf" ::: "memory");
    982  1.1  kiyohara 		break;
    983  1.1  kiyohara 	case BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE:
    984  1.1  kiyohara 		__asm volatile("mf" ::: "memory");
    985  1.1  kiyohara 		break;
    986  1.1  kiyohara 	default:
    987  1.1  kiyohara 		printf("%s: Unknown barrier %d\n", __FUNCTION__, flags);
    988  1.1  kiyohara 		break;
    989  1.1  kiyohara 	}
    990  1.1  kiyohara }
    991  1.1  kiyohara 
    992  1.1  kiyohara 
    993  1.1  kiyohara /*
    994  1.1  kiyohara  * Flags used in various bus DMA methods.
    995  1.1  kiyohara  */
    996  1.1  kiyohara #define	BUS_DMA_WAITOK		0x000	/* safe to sleep (pseudo-flag) */
    997  1.1  kiyohara #define	BUS_DMA_NOWAIT		0x001	/* not safe to sleep */
    998  1.1  kiyohara #define	BUS_DMA_ALLOCNOW	0x002	/* perform resource allocation now */
    999  1.1  kiyohara #define	BUS_DMA_COHERENT	0x004	/* hint: map memory DMA coherent */
   1000  1.1  kiyohara #define	BUS_DMA_STREAMING	0x008	/* hint: sequential, unidirectional */
   1001  1.1  kiyohara #define	BUS_DMA_BUS1		0x010	/* placeholders for bus functions... */
   1002  1.1  kiyohara #define	BUS_DMA_BUS2		0x020
   1003  1.1  kiyohara #define	BUS_DMA_BUS3		0x040
   1004  1.1  kiyohara #define	BUS_DMA_BUS4		0x080
   1005  1.1  kiyohara #define	BUS_DMA_READ		0x100	/* mapping is device -> memory only */
   1006  1.1  kiyohara #define	BUS_DMA_WRITE		0x200	/* mapping is memory -> device only */
   1007  1.1  kiyohara #define	BUS_DMA_NOCACHE		0x400	/* hint: map non-cached memory */
   1008  1.1  kiyohara 
   1009  1.1  kiyohara /* Forwards needed by prototypes below. */
   1010  1.1  kiyohara struct mbuf;
   1011  1.1  kiyohara struct uio;
   1012  1.1  kiyohara 
   1013  1.1  kiyohara /*
   1014  1.1  kiyohara  * Operations performed by bus_dmamap_sync().
   1015  1.1  kiyohara  */
   1016  1.1  kiyohara #define	BUS_DMASYNC_PREREAD	0x01	/* pre-read synchronization */
   1017  1.1  kiyohara #define	BUS_DMASYNC_POSTREAD	0x02	/* post-read synchronization */
   1018  1.1  kiyohara #define	BUS_DMASYNC_PREWRITE	0x04	/* pre-write synchronization */
   1019  1.1  kiyohara #define	BUS_DMASYNC_POSTWRITE	0x08	/* post-write synchronization */
   1020  1.1  kiyohara 
   1021  1.1  kiyohara typedef struct ia64_bus_dma_tag		*bus_dma_tag_t;
   1022  1.1  kiyohara typedef struct ia64_bus_dmamap		*bus_dmamap_t;
   1023  1.1  kiyohara 
   1024  1.1  kiyohara #define BUS_DMA_TAG_VALID(t)    ((t) != (bus_dma_tag_t)0)
   1025  1.1  kiyohara 
   1026  1.1  kiyohara /*
   1027  1.1  kiyohara  *	bus_dma_segment_t
   1028  1.1  kiyohara  *
   1029  1.1  kiyohara  *	Describes a single contiguous DMA transaction.  Values
   1030  1.1  kiyohara  *	are suitable for programming into DMA registers.
   1031  1.1  kiyohara  */
   1032  1.1  kiyohara struct ia64_bus_dma_segment {
   1033  1.1  kiyohara 	bus_addr_t	ds_addr;	/* DMA address */
   1034  1.1  kiyohara 	bus_size_t	ds_len;		/* length of transfer */
   1035  1.1  kiyohara };
   1036  1.1  kiyohara typedef struct ia64_bus_dma_segment	bus_dma_segment_t;
   1037  1.1  kiyohara 
   1038  1.1  kiyohara /*
   1039  1.1  kiyohara  *	bus_dma_tag_t
   1040  1.1  kiyohara  *
   1041  1.1  kiyohara  *	A machine-dependent opaque type describing the implementation of
   1042  1.1  kiyohara  *	DMA for a given bus.
   1043  1.1  kiyohara  */
   1044  1.1  kiyohara 
   1045  1.1  kiyohara struct ia64_bus_dma_tag {
   1046  1.1  kiyohara 	/*
   1047  1.1  kiyohara 	 * The `bounce threshold' is checked while we are loading
   1048  1.1  kiyohara 	 * the DMA map.  If the physical address of the segment
   1049  1.1  kiyohara 	 * exceeds the threshold, an error will be returned.  The
   1050  1.1  kiyohara 	 * caller can then take whatever action is necessary to
   1051  1.1  kiyohara 	 * bounce the transfer.  If this value is 0, it will be
   1052  1.1  kiyohara 	 * ignored.
   1053  1.1  kiyohara 	 */
   1054  1.1  kiyohara 	bus_addr_t _bounce_thresh;
   1055  1.1  kiyohara 	bus_addr_t _bounce_alloc_lo;
   1056  1.1  kiyohara 	bus_addr_t _bounce_alloc_hi;
   1057  1.1  kiyohara 	int	(*_may_bounce)(bus_dma_tag_t, bus_dmamap_t, int, int *);
   1058  1.1  kiyohara 
   1059  1.1  kiyohara 	/*
   1060  1.1  kiyohara 	 * DMA mapping methods.
   1061  1.1  kiyohara 	 */
   1062  1.1  kiyohara 	int	(*_dmamap_create)(bus_dma_tag_t, bus_size_t, int,
   1063  1.1  kiyohara 		    bus_size_t, bus_size_t, int, bus_dmamap_t *);
   1064  1.1  kiyohara 	void	(*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t);
   1065  1.1  kiyohara 	int	(*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *,
   1066  1.1  kiyohara 		    bus_size_t, struct proc *, int);
   1067  1.1  kiyohara 	int	(*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t,
   1068  1.1  kiyohara 		    struct mbuf *, int);
   1069  1.1  kiyohara 	int	(*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t,
   1070  1.1  kiyohara 		    struct uio *, int);
   1071  1.1  kiyohara 	int	(*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t,
   1072  1.1  kiyohara 		    bus_dma_segment_t *, int, bus_size_t, int);
   1073  1.1  kiyohara 	void	(*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t);
   1074  1.1  kiyohara 	void	(*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t,
   1075  1.1  kiyohara 		    bus_addr_t, bus_size_t, int);
   1076  1.1  kiyohara 
   1077  1.1  kiyohara 	/*
   1078  1.1  kiyohara 	 * DMA memory utility functions.
   1079  1.1  kiyohara 	 */
   1080  1.1  kiyohara 	int	(*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t,
   1081  1.1  kiyohara 		    bus_size_t, bus_dma_segment_t *, int, int *, int);
   1082  1.1  kiyohara 	void	(*_dmamem_free)(bus_dma_tag_t, bus_dma_segment_t *, int);
   1083  1.1  kiyohara 	int	(*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *,
   1084  1.1  kiyohara 		    int, size_t, void **, int);
   1085  1.1  kiyohara 	void	(*_dmamem_unmap)(bus_dma_tag_t, void *, size_t);
   1086  1.1  kiyohara 	paddr_t	(*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *,
   1087  1.1  kiyohara 		    int, off_t, int, int);
   1088  1.1  kiyohara };
   1089  1.1  kiyohara 
   1090  1.1  kiyohara static __inline void bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t,
   1091  1.1  kiyohara     bus_addr_t, bus_size_t, int) __attribute__((__unused__));
   1092  1.1  kiyohara 
   1093  1.1  kiyohara #define	bus_dmamap_create(t, s, n, m, b, f, p)			\
   1094  1.1  kiyohara 	(*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
   1095  1.1  kiyohara #define	bus_dmamap_destroy(t, p)				\
   1096  1.1  kiyohara 	(*(t)->_dmamap_destroy)((t), (p))
   1097  1.1  kiyohara #define	bus_dmamap_load(t, m, b, s, p, f)			\
   1098  1.1  kiyohara 	(*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
   1099  1.1  kiyohara #define	bus_dmamap_load_mbuf(t, m, b, f)			\
   1100  1.1  kiyohara 	(*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
   1101  1.1  kiyohara #define	bus_dmamap_load_uio(t, m, u, f)				\
   1102  1.1  kiyohara 	(*(t)->_dmamap_load_uio)((t), (m), (u), (f))
   1103  1.1  kiyohara #define	bus_dmamap_load_raw(t, m, sg, n, s, f)			\
   1104  1.1  kiyohara 	(*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
   1105  1.1  kiyohara #define	bus_dmamap_unload(t, p)					\
   1106  1.1  kiyohara 	(*(t)->_dmamap_unload)((t), (p))
   1107  1.1  kiyohara static __inline void
   1108  1.1  kiyohara bus_dmamap_sync(bus_dma_tag_t t, bus_dmamap_t p, bus_addr_t o, bus_size_t l,
   1109  1.1  kiyohara     int ops)
   1110  1.1  kiyohara {
   1111  1.1  kiyohara 	/* if (ops & BUS_DMASYNC_POSTREAD)
   1112  1.1  kiyohara 	   x86_lfence(); */
   1113  1.1  kiyohara 	if (t->_dmamap_sync)
   1114  1.1  kiyohara 		(*t->_dmamap_sync)(t, p, o, l, ops);
   1115  1.1  kiyohara }
   1116  1.1  kiyohara 
   1117  1.1  kiyohara #define	bus_dmamem_alloc(t, s, a, b, sg, n, r, f)		\
   1118  1.1  kiyohara 	(*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
   1119  1.1  kiyohara #define	bus_dmamem_free(t, sg, n)				\
   1120  1.1  kiyohara 	(*(t)->_dmamem_free)((t), (sg), (n))
   1121  1.1  kiyohara #define	bus_dmamem_map(t, sg, n, s, k, f)			\
   1122  1.1  kiyohara 	(*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
   1123  1.1  kiyohara #define	bus_dmamem_unmap(t, k, s)				\
   1124  1.1  kiyohara 	(*(t)->_dmamem_unmap)((t), (k), (s))
   1125  1.1  kiyohara #define	bus_dmamem_mmap(t, sg, n, o, p, f)			\
   1126  1.1  kiyohara 	(*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
   1127  1.1  kiyohara 
   1128  1.1  kiyohara /*
   1129  1.1  kiyohara  *	bus_dmamap_t
   1130  1.1  kiyohara  *
   1131  1.1  kiyohara  *	Describes a DMA mapping.
   1132  1.1  kiyohara  */
   1133  1.1  kiyohara struct ia64_bus_dmamap {
   1134  1.1  kiyohara 	/*
   1135  1.1  kiyohara 	 * PRIVATE MEMBERS: not for use by machine-independent code.
   1136  1.1  kiyohara 	 */
   1137  1.1  kiyohara 	bus_size_t	_dm_size;	/* largest DMA transfer mappable */
   1138  1.1  kiyohara 	int		_dm_segcnt;	/* number of segs this map can map */
   1139  1.1  kiyohara 	bus_size_t	_dm_maxmaxsegsz; /* fixed largest possible segment */
   1140  1.1  kiyohara 	bus_size_t	_dm_boundary;	/* don't cross this */
   1141  1.1  kiyohara 	bus_addr_t	_dm_bounce_thresh; /* bounce threshold; see tag */
   1142  1.1  kiyohara 	int		_dm_flags;	/* misc. flags */
   1143  1.1  kiyohara 
   1144  1.1  kiyohara 	void		*_dm_cookie;	/* cookie for bus-specific functions */
   1145  1.1  kiyohara 
   1146  1.1  kiyohara 	/*
   1147  1.1  kiyohara 	 * PUBLIC MEMBERS: these are used by machine-independent code.
   1148  1.1  kiyohara 	 */
   1149  1.1  kiyohara 	bus_size_t	dm_maxsegsz;	/* largest possible segment */
   1150  1.1  kiyohara 	bus_size_t	dm_mapsize;	/* size of the mapping */
   1151  1.1  kiyohara 	int		dm_nsegs;	/* # valid segments in mapping */
   1152  1.1  kiyohara 	bus_dma_segment_t dm_segs[1];	/* segments; variable length */
   1153  1.1  kiyohara };
   1154  1.1  kiyohara 
   1155  1.1  kiyohara #endif /* _IA64_BUS_H_ */
   1156