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>
76 #include <sys/endian.h>
80 #include <vm/vm_kern.h>
81 #include <vm/vm_extern.h>
83 #include <machine/bus.h>
84 #include <machine/cache.h>
86 #include <mips/cavium/octopcivar.h>
88 #include <contrib/octeon-sdk/cvmx.h>
90 static struct bus_space octopci_space = {
94 /* mapping/unmapping */
99 /* allocation/deallocation */
160 /* read (single) stream */
166 /* read multiple stream */
172 /* read region stream */
178 /* write (single) stream */
184 /* write multiple stream */
190 /* write region stream */
197 #define rd8(a) cvmx_read64_uint8(a)
198 #define rd16(a) le16toh(cvmx_read64_uint16(a))
199 #define rd32(a) le32toh(cvmx_read64_uint32(a))
200 #define wr8(a, v) cvmx_write64_uint8(a, v)
201 #define wr16(a, v) cvmx_write64_uint16(a, htole16(v))
202 #define wr32(a, v) cvmx_write64_uint32(a, htole32(v))
204 /* octopci bus_space tag */
205 bus_space_tag_t octopci_bus_space = &octopci_space;
208 octopci_bs_map(void *t __unused, bus_addr_t addr,
209 bus_size_t size __unused, int flags __unused,
210 bus_space_handle_t *bshp)
218 octopci_bs_unmap(void *t __unused, bus_space_handle_t bh __unused,
219 bus_size_t size __unused)
226 octopci_bs_subregion(void *t __unused, bus_space_handle_t handle,
227 bus_size_t offset, bus_size_t size __unused,
228 bus_space_handle_t *bshp)
231 *bshp = handle + offset;
236 octopci_bs_r_1(void *t, bus_space_handle_t handle,
240 return (rd8(handle + offset));
244 octopci_bs_r_2(void *t, bus_space_handle_t handle,
248 return (rd16(handle + offset));
252 octopci_bs_r_4(void *t, bus_space_handle_t handle,
256 return (rd32(handle + offset));
261 octopci_bs_rm_1(void *t, bus_space_handle_t bsh,
262 bus_size_t offset, uint8_t *addr, size_t count)
266 *addr++ = rd8(bsh + offset);
270 octopci_bs_rm_2(void *t, bus_space_handle_t bsh,
271 bus_size_t offset, uint16_t *addr, size_t count)
273 bus_addr_t baddr = bsh + offset;
276 *addr++ = rd16(baddr);
280 octopci_bs_rm_4(void *t, bus_space_handle_t bsh,
281 bus_size_t offset, uint32_t *addr, size_t count)
283 bus_addr_t baddr = bsh + offset;
286 *addr++ = rd32(baddr);
291 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
292 * described by tag/handle and starting at `offset' and copy into
296 octopci_bs_rr_1(void *t, bus_space_handle_t bsh,
297 bus_size_t offset, uint8_t *addr, size_t count)
299 bus_addr_t baddr = bsh + offset;
302 *addr++ = rd8(baddr);
308 octopci_bs_rr_2(void *t, bus_space_handle_t bsh,
309 bus_size_t offset, uint16_t *addr, size_t count)
311 bus_addr_t baddr = bsh + offset;
314 *addr++ = rd16(baddr);
320 octopci_bs_rr_4(void *t, bus_space_handle_t bsh,
321 bus_size_t offset, uint32_t *addr, size_t count)
323 bus_addr_t baddr = bsh + offset;
326 *addr++ = rd32(baddr);
332 * Write the 1, 2, 4, or 8 byte value `value' to bus space
333 * described by tag/handle/offset.
336 octopci_bs_w_1(void *t, bus_space_handle_t bsh,
337 bus_size_t offset, uint8_t value)
340 wr8(bsh + offset, value);
344 octopci_bs_w_2(void *t, bus_space_handle_t bsh,
345 bus_size_t offset, uint16_t value)
348 wr16(bsh + offset, value);
352 octopci_bs_w_4(void *t, bus_space_handle_t bsh,
353 bus_size_t offset, uint32_t value)
356 wr32(bsh + offset, value);
360 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
361 * provided to bus space described by tag/handle/offset.
364 octopci_bs_wm_1(void *t, bus_space_handle_t bsh,
365 bus_size_t offset, const uint8_t *addr, size_t count)
367 bus_addr_t baddr = bsh + offset;
374 octopci_bs_wm_2(void *t, bus_space_handle_t bsh,
375 bus_size_t offset, const uint16_t *addr, size_t count)
377 bus_addr_t baddr = bsh + offset;
380 wr16(baddr, *addr++);
384 octopci_bs_wm_4(void *t, bus_space_handle_t bsh,
385 bus_size_t offset, const uint32_t *addr, size_t count)
387 bus_addr_t baddr = bsh + offset;
390 wr32(baddr, *addr++);
394 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
395 * to bus space described by tag/handle starting at `offset'.
398 octopci_bs_wr_1(void *t, bus_space_handle_t bsh,
399 bus_size_t offset, const uint8_t *addr, size_t count)
401 bus_addr_t baddr = bsh + offset;
410 octopci_bs_wr_2(void *t, bus_space_handle_t bsh,
411 bus_size_t offset, const uint16_t *addr, size_t count)
413 bus_addr_t baddr = bsh + offset;
416 wr16(baddr, *addr++);
422 octopci_bs_wr_4(void *t, bus_space_handle_t bsh,
423 bus_size_t offset, const uint32_t *addr, size_t count)
425 bus_addr_t baddr = bsh + offset;
428 wr32(baddr, *addr++);
434 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
435 * by tag/handle/offset `count' times.
438 octopci_bs_sm_1(void *t, bus_space_handle_t bsh,
439 bus_size_t offset, uint8_t value, size_t count)
441 bus_addr_t addr = bsh + offset;
448 octopci_bs_sm_2(void *t, bus_space_handle_t bsh,
449 bus_size_t offset, uint16_t value, size_t count)
451 bus_addr_t addr = bsh + offset;
458 octopci_bs_sm_4(void *t, bus_space_handle_t bsh,
459 bus_size_t offset, uint32_t value, size_t count)
461 bus_addr_t addr = bsh + offset;
468 * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
469 * by tag/handle starting at `offset'.
472 octopci_bs_sr_1(void *t, bus_space_handle_t bsh,
473 bus_size_t offset, uint8_t value, size_t count)
475 bus_addr_t addr = bsh + offset;
477 for (; count != 0; count--, addr++)
482 octopci_bs_sr_2(void *t, bus_space_handle_t bsh,
483 bus_size_t offset, uint16_t value, size_t count)
485 bus_addr_t addr = bsh + offset;
487 for (; count != 0; count--, addr += 2)
492 octopci_bs_sr_4(void *t, bus_space_handle_t bsh,
493 bus_size_t offset, uint32_t value, size_t count)
495 bus_addr_t addr = bsh + offset;
497 for (; count != 0; count--, addr += 4)
502 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
503 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
506 octopci_bs_c_1(void *t, bus_space_handle_t bsh1,
507 bus_size_t off1, bus_space_handle_t bsh2,
508 bus_size_t off2, size_t count)
510 bus_addr_t addr1 = bsh1 + off1;
511 bus_addr_t addr2 = bsh2 + off2;
513 if (addr1 >= addr2) {
514 /* src after dest: copy forward */
515 for (; count != 0; count--, addr1++, addr2++)
516 wr8(addr2, rd8(addr1));
518 /* dest after src: copy backwards */
519 for (addr1 += (count - 1), addr2 += (count - 1);
520 count != 0; count--, addr1--, addr2--)
521 wr8(addr2, rd8(addr1));
526 octopci_bs_c_2(void *t, bus_space_handle_t bsh1,
527 bus_size_t off1, bus_space_handle_t bsh2,
528 bus_size_t off2, size_t count)
530 bus_addr_t addr1 = bsh1 + off1;
531 bus_addr_t addr2 = bsh2 + off2;
533 if (addr1 >= addr2) {
534 /* src after dest: copy forward */
535 for (; count != 0; count--, addr1 += 2, addr2 += 2)
536 wr16(addr2, rd16(addr1));
538 /* dest after src: copy backwards */
539 for (addr1 += 2 * (count - 1), addr2 += 2 * (count - 1);
540 count != 0; count--, addr1 -= 2, addr2 -= 2)
541 wr16(addr2, rd16(addr1));
546 octopci_bs_c_4(void *t, bus_space_handle_t bsh1,
547 bus_size_t off1, bus_space_handle_t bsh2,
548 bus_size_t off2, size_t count)
550 bus_addr_t addr1 = bsh1 + off1;
551 bus_addr_t addr2 = bsh2 + off2;
553 if (addr1 >= addr2) {
554 /* src after dest: copy forward */
555 for (; count != 0; count--, addr1 += 4, addr2 += 4)
556 wr32(addr2, rd32(addr1));
558 /* dest after src: copy backwards */
559 for (addr1 += 4 * (count - 1), addr2 += 4 * (count - 1);
560 count != 0; count--, addr1 -= 4, addr2 -= 4)
561 wr32(addr2, rd32(addr1));
566 octopci_bs_barrier(void *t __unused,
567 bus_space_handle_t bsh __unused,
568 bus_size_t offset __unused, bus_size_t len __unused,
572 if (flags & BUS_SPACE_BARRIER_WRITE)
573 mips_dcache_wbinv_all();