1 /* $NetBSD: bus.h,v 1.12 1997/10/01 08:25:15 fvdl Exp $ */
3 * $Id: bus.h,v 1.6 2007/08/09 11:23:32 katta Exp $
5 * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
10 * NASA Ames Research Center.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
35 * Copyright (c) 1996 Charles M. Hannum. All rights reserved.
36 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by Christopher G. Demetriou
49 * for the NetBSD Project.
50 * 4. The name of the author may not be used to endorse or promote products
51 * derived from this software without specific prior written permission
53 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
54 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
55 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
56 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
57 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
58 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
62 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 * from: src/sys/alpha/include/bus.h,v 1.5 1999/08/28 00:38:40 peter
67 #include <sys/cdefs.h>
68 __FBSDID("$FreeBSD$");
70 #include <sys/param.h>
71 #include <sys/systm.h>
73 #include <sys/kernel.h>
74 #include <sys/malloc.h>
79 #include <vm/vm_kern.h>
80 #include <vm/vm_extern.h>
82 #include <machine/bus.h>
83 #include <machine/cache.h>
85 static struct bus_space generic_space = {
89 /* mapping/unmapping */
94 /* allocation/deallocation */
155 /* read (single) stream */
161 /* read multiple stream */
167 /* read region stream */
173 /* write (single) stream */
179 /* write multiple stream */
185 /* write region stream */
192 /* Ultra-gross kludge */
193 #include "opt_cputype.h"
194 #if defined(CPU_CNMIPS) && (defined(__mips_n32) || defined(__mips_o32))
195 #include <contrib/octeon-sdk/cvmx.h>
196 #define rd8(a) cvmx_read64_uint8(a)
197 #define rd16(a) cvmx_read64_uint16(a)
198 #define rd32(a) cvmx_read64_uint32(a)
199 #define wr8(a, v) cvmx_write64_uint8(a, v)
200 #define wr16(a, v) cvmx_write64_uint16(a, v)
201 #define wr32(a, v) cvmx_write64_uint32(a, v)
202 #elif defined(CPU_SB1) && _BYTE_ORDER == _BIG_ENDIAN
203 #include <mips/sibyte/sb_bus_space.h>
204 #define rd8(a) sb_big_endian_read8(a)
205 #define rd16(a) sb_big_endian_read16(a)
206 #define rd32(a) sb_big_endian_read32(a)
207 #define wr8(a, v) sb_big_endian_write8(a, v)
208 #define wr16(a, v) sb_big_endian_write16(a, v)
209 #define wr32(a, v) sb_big_endian_write32(a, v)
211 #define rd8(a) readb(a)
212 #define rd16(a) readw(a)
213 #define rd32(a) readl(a)
214 #define wr8(a, v) writeb(a, v)
215 #define wr16(a, v) writew(a, v)
216 #define wr32(a, v) writel(a, v)
219 /* generic bus_space tag */
220 bus_space_tag_t mips_bus_space_generic = &generic_space;
223 generic_bs_map(void *t __unused, bus_addr_t addr,
224 bus_size_t size __unused, int flags __unused,
225 bus_space_handle_t *bshp)
233 generic_bs_unmap(void *t __unused, bus_space_handle_t bh __unused,
234 bus_size_t size __unused)
241 generic_bs_subregion(void *t __unused, bus_space_handle_t handle __unused,
242 bus_size_t offset __unused, bus_size_t size __unused,
243 bus_space_handle_t *nhandle __unused)
246 printf("SUBREGION?!?!?!\n");
252 generic_bs_r_1(void *t, bus_space_handle_t handle,
256 return (rd8(handle + offset));
260 generic_bs_r_2(void *t, bus_space_handle_t handle,
264 return (rd16(handle + offset));
268 generic_bs_r_4(void *t, bus_space_handle_t handle,
272 return (rd32(handle + offset));
277 generic_bs_rm_1(void *t, bus_space_handle_t bsh,
278 bus_size_t offset, uint8_t *addr, size_t count)
282 *addr++ = rd8(bsh + offset);
286 generic_bs_rm_2(void *t, bus_space_handle_t bsh,
287 bus_size_t offset, uint16_t *addr, size_t count)
289 bus_addr_t baddr = bsh + offset;
292 *addr++ = rd16(baddr);
296 generic_bs_rm_4(void *t, bus_space_handle_t bsh,
297 bus_size_t offset, uint32_t *addr, size_t count)
299 bus_addr_t baddr = bsh + offset;
302 *addr++ = rd32(baddr);
307 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
308 * described by tag/handle and starting at `offset' and copy into
312 generic_bs_rr_1(void *t, bus_space_handle_t bsh,
313 bus_size_t offset, uint8_t *addr, size_t count)
315 bus_addr_t baddr = bsh + offset;
318 *addr++ = rd8(baddr);
324 generic_bs_rr_2(void *t, bus_space_handle_t bsh,
325 bus_size_t offset, uint16_t *addr, size_t count)
327 bus_addr_t baddr = bsh + offset;
330 *addr++ = rd16(baddr);
336 generic_bs_rr_4(void *t, bus_space_handle_t bsh,
337 bus_size_t offset, uint32_t *addr, size_t count)
339 bus_addr_t baddr = bsh + offset;
342 *addr++ = rd32(baddr);
348 * Write the 1, 2, 4, or 8 byte value `value' to bus space
349 * described by tag/handle/offset.
352 generic_bs_w_1(void *t, bus_space_handle_t bsh,
353 bus_size_t offset, uint8_t value)
356 wr8(bsh + offset, value);
360 generic_bs_w_2(void *t, bus_space_handle_t bsh,
361 bus_size_t offset, uint16_t value)
364 wr16(bsh + offset, value);
368 generic_bs_w_4(void *t, bus_space_handle_t bsh,
369 bus_size_t offset, uint32_t value)
372 wr32(bsh + offset, value);
376 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
377 * provided to bus space described by tag/handle/offset.
380 generic_bs_wm_1(void *t, bus_space_handle_t bsh,
381 bus_size_t offset, const uint8_t *addr, size_t count)
383 bus_addr_t baddr = bsh + offset;
390 generic_bs_wm_2(void *t, bus_space_handle_t bsh,
391 bus_size_t offset, const uint16_t *addr, size_t count)
393 bus_addr_t baddr = bsh + offset;
396 wr16(baddr, *addr++);
400 generic_bs_wm_4(void *t, bus_space_handle_t bsh,
401 bus_size_t offset, const uint32_t *addr, size_t count)
403 bus_addr_t baddr = bsh + offset;
406 wr32(baddr, *addr++);
410 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
411 * to bus space described by tag/handle starting at `offset'.
414 generic_bs_wr_1(void *t, bus_space_handle_t bsh,
415 bus_size_t offset, const uint8_t *addr, size_t count)
417 bus_addr_t baddr = bsh + offset;
426 generic_bs_wr_2(void *t, bus_space_handle_t bsh,
427 bus_size_t offset, const uint16_t *addr, size_t count)
429 bus_addr_t baddr = bsh + offset;
432 wr16(baddr, *addr++);
438 generic_bs_wr_4(void *t, bus_space_handle_t bsh,
439 bus_size_t offset, const uint32_t *addr, size_t count)
441 bus_addr_t baddr = bsh + offset;
444 wr32(baddr, *addr++);
450 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
451 * by tag/handle/offset `count' times.
454 generic_bs_sm_1(void *t, bus_space_handle_t bsh,
455 bus_size_t offset, uint8_t value, size_t count)
457 bus_addr_t addr = bsh + offset;
464 generic_bs_sm_2(void *t, bus_space_handle_t bsh,
465 bus_size_t offset, uint16_t value, size_t count)
467 bus_addr_t addr = bsh + offset;
474 generic_bs_sm_4(void *t, bus_space_handle_t bsh,
475 bus_size_t offset, uint32_t value, size_t count)
477 bus_addr_t addr = bsh + offset;
484 * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
485 * by tag/handle starting at `offset'.
488 generic_bs_sr_1(void *t, bus_space_handle_t bsh,
489 bus_size_t offset, uint8_t value, size_t count)
491 bus_addr_t addr = bsh + offset;
493 for (; count != 0; count--, addr++)
498 generic_bs_sr_2(void *t, bus_space_handle_t bsh,
499 bus_size_t offset, uint16_t value, size_t count)
501 bus_addr_t addr = bsh + offset;
503 for (; count != 0; count--, addr += 2)
508 generic_bs_sr_4(void *t, bus_space_handle_t bsh,
509 bus_size_t offset, uint32_t value, size_t count)
511 bus_addr_t addr = bsh + offset;
513 for (; count != 0; count--, addr += 4)
518 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
519 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
522 generic_bs_c_1(void *t, bus_space_handle_t bsh1,
523 bus_size_t off1, bus_space_handle_t bsh2,
524 bus_size_t off2, size_t count)
526 bus_addr_t addr1 = bsh1 + off1;
527 bus_addr_t addr2 = bsh2 + off2;
529 if (addr1 >= addr2) {
530 /* src after dest: copy forward */
531 for (; count != 0; count--, addr1++, addr2++)
532 wr8(addr2, rd8(addr1));
534 /* dest after src: copy backwards */
535 for (addr1 += (count - 1), addr2 += (count - 1);
536 count != 0; count--, addr1--, addr2--)
537 wr8(addr2, rd8(addr1));
542 generic_bs_c_2(void *t, bus_space_handle_t bsh1,
543 bus_size_t off1, bus_space_handle_t bsh2,
544 bus_size_t off2, size_t count)
546 bus_addr_t addr1 = bsh1 + off1;
547 bus_addr_t addr2 = bsh2 + off2;
549 if (addr1 >= addr2) {
550 /* src after dest: copy forward */
551 for (; count != 0; count--, addr1 += 2, addr2 += 2)
552 wr16(addr2, rd16(addr1));
554 /* dest after src: copy backwards */
555 for (addr1 += 2 * (count - 1), addr2 += 2 * (count - 1);
556 count != 0; count--, addr1 -= 2, addr2 -= 2)
557 wr16(addr2, rd16(addr1));
562 generic_bs_c_4(void *t, bus_space_handle_t bsh1,
563 bus_size_t off1, bus_space_handle_t bsh2,
564 bus_size_t off2, size_t count)
566 bus_addr_t addr1 = bsh1 + off1;
567 bus_addr_t addr2 = bsh2 + off2;
569 if (addr1 >= addr2) {
570 /* src after dest: copy forward */
571 for (; count != 0; count--, addr1 += 4, addr2 += 4)
572 wr32(addr2, rd32(addr1));
574 /* dest after src: copy backwards */
575 for (addr1 += 4 * (count - 1), addr2 += 4 * (count - 1);
576 count != 0; count--, addr1 -= 4, addr2 -= 4)
577 wr32(addr2, rd32(addr1));
582 generic_bs_barrier(void *t __unused,
583 bus_space_handle_t bsh __unused,
584 bus_size_t offset __unused, bus_size_t len __unused,
588 if (flags & BUS_SPACE_BARRIER_WRITE)
589 mips_dcache_wbinv_all();