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.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the NetBSD
23 * Foundation, Inc. and its contributors.
24 * 4. Neither the name of The NetBSD Foundation nor the names of its
25 * contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
42 * Copyright (c) 1996 Charles M. Hannum. All rights reserved.
43 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that the following conditions
48 * 1. Redistributions of source code must retain the above copyright
49 * notice, this list of conditions and the following disclaimer.
50 * 2. Redistributions in binary form must reproduce the above copyright
51 * notice, this list of conditions and the following disclaimer in the
52 * documentation and/or other materials provided with the distribution.
53 * 3. All advertising materials mentioning features or use of this software
54 * must display the following acknowledgement:
55 * This product includes software developed by Christopher G. Demetriou
56 * for the NetBSD Project.
57 * 4. The name of the author may not be used to endorse or promote products
58 * derived from this software without specific prior written permission
60 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
61 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
62 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
63 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
64 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
65 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
66 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
67 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
68 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
69 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
71 * from: src/sys/alpha/include/bus.h,v 1.5 1999/08/28 00:38:40 peter
74 #include <sys/cdefs.h>
75 __FBSDID("$FreeBSD$");
77 #include <sys/param.h>
78 #include <sys/systm.h>
80 #include <sys/kernel.h>
81 #include <sys/malloc.h>
83 #include <sys/endian.h>
87 #include <vm/vm_kern.h>
88 #include <vm/vm_extern.h>
90 #include <machine/bus.h>
91 #include <machine/cache.h>
93 #include <mips/cavium/octopcivar.h>
95 #include <contrib/octeon-sdk/cvmx.h>
97 static struct bus_space octopci_space = {
101 /* mapping/unmapping */
104 octopci_bs_subregion,
106 /* allocation/deallocation */
167 /* read (single) stream */
173 /* read multiple stream */
179 /* read region stream */
185 /* write (single) stream */
191 /* write multiple stream */
197 /* write region stream */
204 #define rd8(a) cvmx_read64_uint8(a)
205 #define rd16(a) le16toh(cvmx_read64_uint16(a))
206 #define rd32(a) le32toh(cvmx_read64_uint32(a))
207 #define wr8(a, v) cvmx_write64_uint8(a, v)
208 #define wr16(a, v) cvmx_write64_uint16(a, htole16(v))
209 #define wr32(a, v) cvmx_write64_uint32(a, htole32(v))
211 /* octopci bus_space tag */
212 bus_space_tag_t octopci_bus_space = &octopci_space;
215 octopci_bs_map(void *t __unused, bus_addr_t addr,
216 bus_size_t size __unused, int flags __unused,
217 bus_space_handle_t *bshp)
225 octopci_bs_unmap(void *t __unused, bus_space_handle_t bh __unused,
226 bus_size_t size __unused)
233 octopci_bs_subregion(void *t __unused, bus_space_handle_t handle __unused,
234 bus_size_t offset __unused, bus_size_t size __unused,
235 bus_space_handle_t *nhandle __unused)
238 printf("SUBREGION?!?!?!\n");
244 octopci_bs_r_1(void *t, bus_space_handle_t handle,
248 return (rd8(handle + offset));
252 octopci_bs_r_2(void *t, bus_space_handle_t handle,
256 return (rd16(handle + offset));
260 octopci_bs_r_4(void *t, bus_space_handle_t handle,
264 return (rd32(handle + offset));
269 octopci_bs_rm_1(void *t, bus_space_handle_t bsh,
270 bus_size_t offset, uint8_t *addr, size_t count)
274 *addr++ = rd8(bsh + offset);
278 octopci_bs_rm_2(void *t, bus_space_handle_t bsh,
279 bus_size_t offset, uint16_t *addr, size_t count)
281 bus_addr_t baddr = bsh + offset;
284 *addr++ = rd16(baddr);
288 octopci_bs_rm_4(void *t, bus_space_handle_t bsh,
289 bus_size_t offset, uint32_t *addr, size_t count)
291 bus_addr_t baddr = bsh + offset;
294 *addr++ = rd32(baddr);
299 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
300 * described by tag/handle and starting at `offset' and copy into
304 octopci_bs_rr_1(void *t, bus_space_handle_t bsh,
305 bus_size_t offset, uint8_t *addr, size_t count)
307 bus_addr_t baddr = bsh + offset;
310 *addr++ = rd8(baddr);
316 octopci_bs_rr_2(void *t, bus_space_handle_t bsh,
317 bus_size_t offset, uint16_t *addr, size_t count)
319 bus_addr_t baddr = bsh + offset;
322 *addr++ = rd16(baddr);
328 octopci_bs_rr_4(void *t, bus_space_handle_t bsh,
329 bus_size_t offset, uint32_t *addr, size_t count)
331 bus_addr_t baddr = bsh + offset;
334 *addr++ = rd32(baddr);
340 * Write the 1, 2, 4, or 8 byte value `value' to bus space
341 * described by tag/handle/offset.
344 octopci_bs_w_1(void *t, bus_space_handle_t bsh,
345 bus_size_t offset, uint8_t value)
348 wr8(bsh + offset, value);
352 octopci_bs_w_2(void *t, bus_space_handle_t bsh,
353 bus_size_t offset, uint16_t value)
356 wr16(bsh + offset, value);
360 octopci_bs_w_4(void *t, bus_space_handle_t bsh,
361 bus_size_t offset, uint32_t value)
364 wr32(bsh + offset, value);
368 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
369 * provided to bus space described by tag/handle/offset.
372 octopci_bs_wm_1(void *t, bus_space_handle_t bsh,
373 bus_size_t offset, const uint8_t *addr, size_t count)
375 bus_addr_t baddr = bsh + offset;
382 octopci_bs_wm_2(void *t, bus_space_handle_t bsh,
383 bus_size_t offset, const uint16_t *addr, size_t count)
385 bus_addr_t baddr = bsh + offset;
388 wr16(baddr, *addr++);
392 octopci_bs_wm_4(void *t, bus_space_handle_t bsh,
393 bus_size_t offset, const uint32_t *addr, size_t count)
395 bus_addr_t baddr = bsh + offset;
398 wr32(baddr, *addr++);
402 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
403 * to bus space described by tag/handle starting at `offset'.
406 octopci_bs_wr_1(void *t, bus_space_handle_t bsh,
407 bus_size_t offset, const uint8_t *addr, size_t count)
409 bus_addr_t baddr = bsh + offset;
418 octopci_bs_wr_2(void *t, bus_space_handle_t bsh,
419 bus_size_t offset, const uint16_t *addr, size_t count)
421 bus_addr_t baddr = bsh + offset;
424 wr16(baddr, *addr++);
430 octopci_bs_wr_4(void *t, bus_space_handle_t bsh,
431 bus_size_t offset, const uint32_t *addr, size_t count)
433 bus_addr_t baddr = bsh + offset;
436 wr32(baddr, *addr++);
442 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
443 * by tag/handle/offset `count' times.
446 octopci_bs_sm_1(void *t, bus_space_handle_t bsh,
447 bus_size_t offset, uint8_t value, size_t count)
449 bus_addr_t addr = bsh + offset;
456 octopci_bs_sm_2(void *t, bus_space_handle_t bsh,
457 bus_size_t offset, uint16_t value, size_t count)
459 bus_addr_t addr = bsh + offset;
466 octopci_bs_sm_4(void *t, bus_space_handle_t bsh,
467 bus_size_t offset, uint32_t value, size_t count)
469 bus_addr_t addr = bsh + offset;
476 * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
477 * by tag/handle starting at `offset'.
480 octopci_bs_sr_1(void *t, bus_space_handle_t bsh,
481 bus_size_t offset, uint8_t value, size_t count)
483 bus_addr_t addr = bsh + offset;
485 for (; count != 0; count--, addr++)
490 octopci_bs_sr_2(void *t, bus_space_handle_t bsh,
491 bus_size_t offset, uint16_t value, size_t count)
493 bus_addr_t addr = bsh + offset;
495 for (; count != 0; count--, addr += 2)
500 octopci_bs_sr_4(void *t, bus_space_handle_t bsh,
501 bus_size_t offset, uint32_t value, size_t count)
503 bus_addr_t addr = bsh + offset;
505 for (; count != 0; count--, addr += 4)
510 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
511 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
514 octopci_bs_c_1(void *t, bus_space_handle_t bsh1,
515 bus_size_t off1, bus_space_handle_t bsh2,
516 bus_size_t off2, size_t count)
518 bus_addr_t addr1 = bsh1 + off1;
519 bus_addr_t addr2 = bsh2 + off2;
521 if (addr1 >= addr2) {
522 /* src after dest: copy forward */
523 for (; count != 0; count--, addr1++, addr2++)
524 wr8(addr2, rd8(addr1));
526 /* dest after src: copy backwards */
527 for (addr1 += (count - 1), addr2 += (count - 1);
528 count != 0; count--, addr1--, addr2--)
529 wr8(addr2, rd8(addr1));
534 octopci_bs_c_2(void *t, bus_space_handle_t bsh1,
535 bus_size_t off1, bus_space_handle_t bsh2,
536 bus_size_t off2, size_t count)
538 bus_addr_t addr1 = bsh1 + off1;
539 bus_addr_t addr2 = bsh2 + off2;
541 if (addr1 >= addr2) {
542 /* src after dest: copy forward */
543 for (; count != 0; count--, addr1 += 2, addr2 += 2)
544 wr16(addr2, rd16(addr1));
546 /* dest after src: copy backwards */
547 for (addr1 += 2 * (count - 1), addr2 += 2 * (count - 1);
548 count != 0; count--, addr1 -= 2, addr2 -= 2)
549 wr16(addr2, rd16(addr1));
554 octopci_bs_c_4(void *t, bus_space_handle_t bsh1,
555 bus_size_t off1, bus_space_handle_t bsh2,
556 bus_size_t off2, size_t count)
558 bus_addr_t addr1 = bsh1 + off1;
559 bus_addr_t addr2 = bsh2 + off2;
561 if (addr1 >= addr2) {
562 /* src after dest: copy forward */
563 for (; count != 0; count--, addr1 += 4, addr2 += 4)
564 wr32(addr2, rd32(addr1));
566 /* dest after src: copy backwards */
567 for (addr1 += 4 * (count - 1), addr2 += 4 * (count - 1);
568 count != 0; count--, addr1 -= 4, addr2 -= 4)
569 wr32(addr2, rd32(addr1));
574 octopci_bs_barrier(void *t __unused,
575 bus_space_handle_t bsh __unused,
576 bus_size_t offset __unused, bus_size_t len __unused,
580 if (flags & BUS_SPACE_BARRIER_WRITE)
581 mips_dcache_wbinv_all();