Home | History | Annotate | Line # | Download | only in include
bus_space.h revision 1.16.52.2
      1 /*	$NetBSD: bus_space.h,v 1.16.52.2 2023/02/15 19:28:29 martin Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  * NASA Ames Research Center.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  * POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 /*
     34  * Copyright (C) 1997 Scott Reynolds.  All rights reserved.
     35  *
     36  * Redistribution and use in source and binary forms, with or without
     37  * modification, are permitted provided that the following conditions
     38  * are met:
     39  * 1. Redistributions of source code must retain the above copyright
     40  *    notice, this list of conditions and the following disclaimer.
     41  * 2. Redistributions in binary form must reproduce the above copyright
     42  *    notice, this list of conditions and the following disclaimer in the
     43  *    documentation and/or other materials provided with the distribution.
     44  * 3. The name of the author may not be used to endorse or promote products
     45  *    derived from this software without specific prior written permission
     46  *
     47  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     48  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     49  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     50  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     51  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     52  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     53  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     54  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     55  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     56  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     57  */
     58 
     59 #ifndef _NEXT68K_BUS_SPACE_H_
     60 #define	_NEXT68K_BUS_SPACE_H_
     61 /*
     62  * Addresses (in bus space).
     63  */
     64 typedef u_long bus_addr_t;
     65 typedef u_long bus_size_t;
     66 
     67 /*
     68  * Access methods for bus resources and address space.
     69  */
     70 typedef volatile char *  bus_space_tag_t;
     71 typedef u_long	bus_space_handle_t;
     72 
     73 /*
     74  * Value for the next68k bus space tag, not to be used directly by MI code.
     75  */
     76 #define NEXT68K_INTIO_BUS_SPACE		((bus_space_tag_t)intiobase)
     77 
     78 /*
     79  * Mapping and unmapping operations.
     80  */
     81 
     82 int bus_space_map(bus_space_tag_t, bus_addr_t, bus_size_t, int,
     83     bus_space_handle_t *);
     84 
     85 #define	bus_space_unmap(t, h, s)
     86 
     87 #define	bus_space_subregion(t, h, o, s, hp)				\
     88      (*(hp)=(h)+(o))
     89 
     90 #define	BUS_SPACE_MAP_CACHEABLE		0x01
     91 #define	BUS_SPACE_MAP_LINEAR		0x02
     92 
     93 /*
     94  * Allocation and deallocation operations.
     95  */
     96 #define	bus_space_alloc(t, rs, re, s, a, b, f, ap, hp)  		\
     97      (-1)
     98 
     99 #define	bus_space_free(t, h, s)
    100 
    101 /*
    102  *	paddr_t bus_space_mmap(bus_space_tag_t t, bus_addr_t base,
    103  *	    off_t offset, int prot, int flags);
    104  *
    105  * Mmap an area of bus space.
    106  */
    107 
    108 paddr_t bus_space_mmap(bus_space_tag_t, bus_addr_t, off_t, int, int);
    109 
    110 /*
    111  *	uintN_t bus_space_read_N(bus_space_tag_t tag,
    112  *	    bus_space_handle_t bsh, bus_size_t offset);
    113  *
    114  * Read a 1, 2, 4, or 8 byte quantity from bus space
    115  * described by tag/handle/offset.
    116  */
    117 
    118 #define	bus_space_read_1(t, h, o)					\
    119     ((void) t, (*(volatile uint8_t *)((h) + (o))))
    120 
    121 #define	bus_space_read_2(t, h, o)					\
    122     ((void) t, (*(volatile uint16_t *)((h) + (o))))
    123 
    124 #define	bus_space_read_4(t, h, o)					\
    125     ((void) t, (*(volatile uint32_t *)((h) + (o))))
    126 
    127 /*
    128  *	void bus_space_read_multi_N(bus_space_tag_t tag,
    129  *	    bus_space_handle_t bsh, bus_size_t offset,
    130  *	    uintN_t *addr, size_t count);
    131  *
    132  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
    133  * described by tag/handle/offset and copy into buffer provided.
    134  */
    135 
    136 #define	bus_space_read_multi_1(t, h, o, a, c) do {			\
    137 	(void) t;							\
    138 	__asm volatile ("						\
    139 		movl	%0,%%a0					;	\
    140 		movl	%1,%%a1					;	\
    141 		movl	%2,%%d0					;	\
    142 	1:	movb	%%a0@,%%a1@+				;	\
    143 		subql	#1,%%d0					;	\
    144 		jne	1b"					:	\
    145 								:	\
    146 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    147 		    "a0","a1","d0","memory");				\
    148 } while (0);
    149 
    150 #define	bus_space_read_multi_2(t, h, o, a, c) do {			\
    151 	(void) t;							\
    152 	__asm volatile ("						\
    153 		movl	%0,%%a0					;	\
    154 		movl	%1,%%a1					;	\
    155 		movl	%2,%%d0					;	\
    156 	1:	movw	%%a0@,%%a1@+				;	\
    157 		subql	#1,%%d0					;	\
    158 		jne	1b"					:	\
    159 								:	\
    160 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    161 		    "a0","a1","d0","memory");				\
    162 } while (0);
    163 
    164 #define	bus_space_read_multi_4(t, h, o, a, c) do {			\
    165 	(void) t;							\
    166 	__asm volatile ("						\
    167 		movl	%0,%%a0					;	\
    168 		movl	%1,%%a1					;	\
    169 		movl	%2,%%d0					;	\
    170 	1:	movl	%%a0@,%%a1@+				;	\
    171 		subql	#1,%%d0					;	\
    172 		jne	1b"					:	\
    173 								:	\
    174 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    175 		    "a0","a1","d0","memory");				\
    176 } while (0);
    177 
    178 /*
    179  *	void bus_space_read_region_N(bus_space_tag_t tag,
    180  *	    bus_space_handle_t bsh, bus_size_t offset,
    181  *	    uintN_t *addr, size_t count);
    182  *
    183  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
    184  * described by tag/handle and starting at `offset' and copy into
    185  * buffer provided.
    186  */
    187 
    188 #define	bus_space_read_region_1(t, h, o, a, c) do {			\
    189 	(void) t;							\
    190 	__asm volatile ("						\
    191 		movl	%0,%%a0					;	\
    192 		movl	%1,%%a1					;	\
    193 		movl	%2,%%d0					;	\
    194 	1:	movb	%%a0@+,%%a1@+				;	\
    195 		subql	#1,%%d0					;	\
    196 		jne	1b"					:	\
    197 								:	\
    198 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    199 		    "a0","a1","d0","memory");				\
    200 } while (0);
    201 
    202 #define	bus_space_read_region_2(t, h, o, a, c) do {			\
    203 	(void) t;							\
    204 	__asm volatile ("						\
    205 		movl	%0,%%a0					;	\
    206 		movl	%1,%%a1					;	\
    207 		movl	%2,%%d0					;	\
    208 	1:	movw	%%a0@+,%%a1@+				;	\
    209 		subql	#1,%%d0					;	\
    210 		jne	1b"					:	\
    211 								:	\
    212 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    213 		    "a0","a1","d0","memory");					\
    214 } while (0);
    215 
    216 #define	bus_space_read_region_4(t, h, o, a, c) do {			\
    217 	(void) t;							\
    218 	__asm volatile ("						\
    219 		movl	%0,%%a0					;	\
    220 		movl	%1,%%a1					;	\
    221 		movl	%2,%%d0					;	\
    222 	1:	movl	%%a0@+,%%a1@+				;	\
    223 		subql	#1,%%d0					;	\
    224 		jne	1b"					:	\
    225 								:	\
    226 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    227 		    "a0","a1","d0","memory");					\
    228 } while (0);
    229 
    230 /*
    231  *	void bus_space_write_N(bus_space_tag_t tag,
    232  *	    bus_space_handle_t bsh, bus_size_t offset,
    233  *	    uintN_t value);
    234  *
    235  * Write the 1, 2, 4, or 8 byte value `value' to bus space
    236  * described by tag/handle/offset.
    237  */
    238 
    239 #define	bus_space_write_1(t, h, o, v)					\
    240     ((void) t, ((void)(*(volatile uint8_t *)((h) + (o)) = (v))))
    241 
    242 #define	bus_space_write_2(t, h, o, v)					\
    243     ((void) t, ((void)(*(volatile uint16_t *)((h) + (o)) = (v))))
    244 
    245 #define	bus_space_write_4(t, h, o, v)					\
    246     ((void) t, ((void)(*(volatile uint32_t *)((h) + (o)) = (v))))
    247 
    248 /*
    249  *	void bus_space_write_multi_N(bus_space_tag_t tag,
    250  *	    bus_space_handle_t bsh, bus_size_t offset,
    251  *	    const uintN_t *addr, size_t count);
    252  *
    253  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
    254  * provided to bus space described by tag/handle/offset.
    255  */
    256 
    257 #define	bus_space_write_multi_1(t, h, o, a, c) do {			\
    258 	(void) t;							\
    259 	__asm volatile ("						\
    260 		movl	%0,%%a0					;	\
    261 		movl	%1,%%a1					;	\
    262 		movl	%2,%%d0					;	\
    263 	1:	movb	%%a1@+,%%a0@				;	\
    264 		subql	#1,%%d0					;	\
    265 		jne	1b"					:	\
    266 								:	\
    267 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    268 		    "a0","a1","d0");					\
    269 } while (0);
    270 
    271 #define	bus_space_write_multi_2(t, h, o, a, c) do {			\
    272 	(void) t;							\
    273 	__asm volatile ("						\
    274 		movl	%0,%%a0					;	\
    275 		movl	%1,%%a1					;	\
    276 		movl	%2,%%d0					;	\
    277 	1:	movw	%%a1@+,%%a0@				;	\
    278 		subql	#1,%%d0					;	\
    279 		jne	1b"					:	\
    280 								:	\
    281 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    282 		    "a0","a1","d0");					\
    283 } while (0);
    284 
    285 #define	bus_space_write_multi_4(t, h, o, a, c) do {			\
    286 	(void) t;							\
    287 	__asm volatile ("						\
    288 		movl	%0,%%a0					;	\
    289 		movl	%1,%%a1					;	\
    290 		movl	%2,%%d0					;	\
    291 	1:	movl	%%a1@+,%%a0@				;	\
    292 		subql	#1,%%d0					;	\
    293 		jne	1b"					:	\
    294 								:	\
    295 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    296 		    "a0","a1","d0");					\
    297 } while (0);
    298 
    299 /*
    300  *	void bus_space_write_region_N(bus_space_tag_t tag,
    301  *	    bus_space_handle_t bsh, bus_size_t offset,
    302  *	    const uintN_t *addr, size_t count);
    303  *
    304  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
    305  * to bus space described by tag/handle starting at `offset'.
    306  */
    307 
    308 #define	bus_space_write_region_1(t, h, o, a, c) do {			\
    309 	(void) t;							\
    310 	__asm volatile ("						\
    311 		movl	%0,%%a0					;	\
    312 		movl	%1,%%a1					;	\
    313 		movl	%2,%%d0					;	\
    314 	1:	movb	%%a1@+,%%a0@+				;	\
    315 		subql	#1,%%d0					;	\
    316 		jne	1b"					:	\
    317 								:	\
    318 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    319 		    "a0","a1","d0");					\
    320 } while (0);
    321 
    322 #define	bus_space_write_region_2(t, h, o, a, c) do {			\
    323 	(void) t;							\
    324 	__asm volatile ("						\
    325 		movl	%0,%%a0					;	\
    326 		movl	%1,%%a1					;	\
    327 		movl	%2,%%d0					;	\
    328 	1:	movw	%%a1@+,%%a0@+				;	\
    329 		subql	#1,%%d0					;	\
    330 		jne	1b"					:	\
    331 								:	\
    332 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    333 		    "a0","a1","d0");					\
    334 } while (0);
    335 
    336 #define	bus_space_write_region_4(t, h, o, a, c) do {			\
    337 	(void) t;							\
    338 	__asm volatile ("						\
    339 		movl	%0,%%a0					;	\
    340 		movl	%1,%%a1					;	\
    341 		movl	%2,%%d0					;	\
    342 	1:	movl	%%a1@+,%%a0@+				;	\
    343 		subql	#1,%%d0					;	\
    344 		jne	1b"					:	\
    345 								:	\
    346 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    347 		    "a0","a1","d0");					\
    348 } while (0);
    349 
    350 /*
    351  *	void bus_space_set_multi_N(bus_space_tag_t tag,
    352  *	    bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
    353  *	    size_t count);
    354  *
    355  * Write the 1, 2, 4, or 8 byte value `val' to bus space described
    356  * by tag/handle/offset `count' times.
    357  */
    358 
    359 #define	bus_space_set_multi_1(t, h, o, val, c) do {			\
    360 	(void) t;							\
    361 	__asm volatile ("						\
    362 		movl	%0,%%a0					;	\
    363 		movl	%1,%%d1					;	\
    364 		movl	%2,%%d0					;	\
    365 	1:	movb	%%d1,%%a0@				;	\
    366 		subql	#1,%%d0					;	\
    367 		jne	1b"					:	\
    368 								:	\
    369 		    "r" ((h) + (o)), "g" (val), "g" (c)		:	\
    370 		    "a0","d0","d1");					\
    371 } while (0);
    372 
    373 #define	bus_space_set_multi_2(t, h, o, val, c) do {			\
    374 	(void) t;							\
    375 	__asm volatile ("						\
    376 		movl	%0,%%a0					;	\
    377 		movl	%1,%%d1					;	\
    378 		movl	%2,%%d0					;	\
    379 	1:	movw	%%d1,%%a0@				;	\
    380 		subql	#1,%%d0					;	\
    381 		jne	1b"					:	\
    382 								:	\
    383 		    "r" ((h) + (o)), "g" (val), "g" (c)		:	\
    384 		    "a0","d0","d1");					\
    385 } while (0);
    386 
    387 #define	bus_space_set_multi_4(t, h, o, val, c) do {			\
    388 	(void) t;							\
    389 	__asm volatile ("						\
    390 		movl	%0,%%a0					;	\
    391 		movl	%1,%%d1					;	\
    392 		movl	%2,%%d0					;	\
    393 	1:	movl	%%d1,%%a0@				;	\
    394 		subql	#1,%%d0					;	\
    395 		jne	1b"					:	\
    396 								:	\
    397 		    "r" ((h) + (o)), "g" (val), "g" (c)		:	\
    398 		    "a0","d0","d1");					\
    399 } while (0);
    400 
    401 /*
    402  *	void bus_space_set_region_N(bus_space_tag_t tag,
    403  *	    bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
    404  *	    size_t count);
    405  *
    406  * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
    407  * by tag/handle starting at `offset'.
    408  */
    409 
    410 #define	bus_space_set_region_1(t, h, o, val, c) do {			\
    411 	(void) t;							\
    412 	__asm volatile ("						\
    413 		movl	%0,%%a0					;	\
    414 		movl	%1,%%d1					;	\
    415 		movl	%2,%%d0					;	\
    416 	1:	movb	%%d1,%%a0@+				;	\
    417 		subql	#1,%%d0					;	\
    418 		jne	1b"					:	\
    419 								:	\
    420 		    "r" ((h) + (o)), "g" (val), "g" (c)		:	\
    421 		    "a0","d0","d1");					\
    422 } while (0);
    423 
    424 #define	bus_space_set_region_2(t, h, o, val, c) do {			\
    425 	(void) t;							\
    426 	__asm volatile ("						\
    427 		movl	%0,%%a0					;	\
    428 		movl	%1,%%d1					;	\
    429 		movl	%2,%%d0					;	\
    430 	1:	movw	%%d1,%%a0@+				;	\
    431 		subql	#1,%%d0					;	\
    432 		jne	1b"					:	\
    433 								:	\
    434 		    "r" ((h) + (o)), "g" (val), "g" (c)		:	\
    435 		    "a0","d0","d1");					\
    436 } while (0);
    437 
    438 #define	bus_space_set_region_4(t, h, o, val, c) do {			\
    439 	(void) t;							\
    440 	__asm volatile ("						\
    441 		movl	%0,%%a0					;	\
    442 		movl	%1,%%d1					;	\
    443 		movl	%2,%%d0					;	\
    444 	1:	movl	%%d1,%%a0@+				;	\
    445 		subql	#1,%%d0					;	\
    446 		jne	1b"					:	\
    447 								:	\
    448 		    "r" ((h) + (o)), "g" (val), "g" (c)		:	\
    449 		    "a0","d0","d1");					\
    450 } while (0);
    451 
    452 /*
    453  *	void bus_space_copy_N(bus_space_tag_t tag,
    454  *	    bus_space_handle_t bsh1, bus_size_t off1,
    455  *	    bus_space_handle_t bsh2, bus_size_t off2,
    456  *	    size_t count);
    457  *
    458  * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
    459  * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
    460  */
    461 
    462 #define	__NEXT68K_copy_region_N(BYTES)					\
    463 static __inline void __CONCAT(bus_space_copy_region_,BYTES)		\
    464 	(bus_space_tag_t,						\
    465 	 bus_space_handle_t, bus_size_t,				\
    466 	 bus_space_handle_t, bus_size_t,				\
    467 	 bus_size_t);							\
    468 									\
    469 static __inline void							\
    470 __CONCAT(bus_space_copy_region_,BYTES)(					\
    471 	bus_space_tag_t t,						\
    472 	bus_space_handle_t h1,						\
    473 	bus_size_t o1,							\
    474 	bus_space_handle_t h2,						\
    475 	bus_size_t o2,							\
    476 	bus_size_t c)							\
    477 {									\
    478 	bus_size_t o;							\
    479 									\
    480 	if ((h1 + o1) >= (h2 + o2)) {					\
    481 		/* src after dest: copy forward */			\
    482 		for (o = 0; c != 0; c--, o += BYTES)			\
    483 			__CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o,	\
    484 			    __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
    485 	} else {							\
    486 		/* dest after src: copy backwards */			\
    487 		for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES)	\
    488 			__CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o,	\
    489 			    __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
    490 	}								\
    491 }
    492 __NEXT68K_copy_region_N(1)
    493 __NEXT68K_copy_region_N(2)
    494 __NEXT68K_copy_region_N(4)
    495 
    496 #undef __NEXT68K_copy_region_N
    497 
    498 /*
    499  * Bus read/write barrier methods.
    500  *
    501  *	void bus_space_barrier(bus_space_tag_t tag,
    502  *	    bus_space_handle_t bsh, bus_size_t offset,
    503  *	    bus_size_t len, int flags);
    504  *
    505  * Note: the 680x0 does not currently require barriers, but we must
    506  * provide the flags to MI code.
    507  */
    508 #define	bus_space_barrier(t, h, o, l, f)	\
    509 	((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)))
    510 #define	BUS_SPACE_BARRIER_READ	0x01		/* force read barrier */
    511 #define	BUS_SPACE_BARRIER_WRITE	0x02		/* force write barrier */
    512 
    513 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
    514 
    515 #endif /* _NEXT68K_BUS_SPACE_H_ */
    516