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 * SPDX-License-Identifier: BSD-2-Clause-NetBSD AND BSD-4-Clause
7 * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
10 * This code is derived from software contributed to The NetBSD Foundation
11 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
12 * NASA Ames Research Center.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
23 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
37 * Copyright (c) 1996 Charles M. Hannum. All rights reserved.
38 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 3. All advertising materials mentioning features or use of this software
49 * must display the following acknowledgement:
50 * This product includes software developed by Christopher G. Demetriou
51 * for the NetBSD Project.
52 * 4. The name of the author may not be used to endorse or promote products
53 * derived from this software without specific prior written permission
55 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
56 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
57 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
58 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
59 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
60 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
61 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
62 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
63 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
64 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
66 * from: src/sys/alpha/include/bus.h,v 1.5 1999/08/28 00:38:40 peter
69 #include <sys/cdefs.h>
70 __FBSDID("$FreeBSD$");
72 #include <sys/param.h>
73 #include <sys/systm.h>
75 #include <sys/kernel.h>
76 #include <sys/malloc.h>
78 #include <sys/endian.h>
82 #include <vm/vm_kern.h>
83 #include <vm/vm_extern.h>
85 #include <machine/bus.h>
86 #include <machine/cache.h>
88 #include <mips/cavium/octopcivar.h>
90 #include <contrib/octeon-sdk/cvmx.h>
92 static struct bus_space octopci_space = {
96 /* mapping/unmapping */
101 /* allocation/deallocation */
162 /* read (single) stream */
168 /* read multiple stream */
174 /* read region stream */
180 /* write (single) stream */
186 /* write multiple stream */
192 /* write region stream */
199 #define rd8(a) cvmx_read64_uint8(a)
200 #define rd16(a) le16toh(cvmx_read64_uint16(a))
201 #define rd32(a) le32toh(cvmx_read64_uint32(a))
202 #define wr8(a, v) cvmx_write64_uint8(a, v)
203 #define wr16(a, v) cvmx_write64_uint16(a, htole16(v))
204 #define wr32(a, v) cvmx_write64_uint32(a, htole32(v))
206 /* octopci bus_space tag */
207 bus_space_tag_t octopci_bus_space = &octopci_space;
210 octopci_bs_map(void *t __unused, bus_addr_t addr,
211 bus_size_t size __unused, int flags __unused,
212 bus_space_handle_t *bshp)
220 octopci_bs_unmap(void *t __unused, bus_space_handle_t bh __unused,
221 bus_size_t size __unused)
228 octopci_bs_subregion(void *t __unused, bus_space_handle_t handle,
229 bus_size_t offset, bus_size_t size __unused,
230 bus_space_handle_t *bshp)
233 *bshp = handle + offset;
238 octopci_bs_r_1(void *t, bus_space_handle_t handle,
242 return (rd8(handle + offset));
246 octopci_bs_r_2(void *t, bus_space_handle_t handle,
250 return (rd16(handle + offset));
254 octopci_bs_r_4(void *t, bus_space_handle_t handle,
258 return (rd32(handle + offset));
263 octopci_bs_rm_1(void *t, bus_space_handle_t bsh,
264 bus_size_t offset, uint8_t *addr, size_t count)
268 *addr++ = rd8(bsh + offset);
272 octopci_bs_rm_2(void *t, bus_space_handle_t bsh,
273 bus_size_t offset, uint16_t *addr, size_t count)
275 bus_addr_t baddr = bsh + offset;
278 *addr++ = rd16(baddr);
282 octopci_bs_rm_4(void *t, bus_space_handle_t bsh,
283 bus_size_t offset, uint32_t *addr, size_t count)
285 bus_addr_t baddr = bsh + offset;
288 *addr++ = rd32(baddr);
293 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
294 * described by tag/handle and starting at `offset' and copy into
298 octopci_bs_rr_1(void *t, bus_space_handle_t bsh,
299 bus_size_t offset, uint8_t *addr, size_t count)
301 bus_addr_t baddr = bsh + offset;
304 *addr++ = rd8(baddr);
310 octopci_bs_rr_2(void *t, bus_space_handle_t bsh,
311 bus_size_t offset, uint16_t *addr, size_t count)
313 bus_addr_t baddr = bsh + offset;
316 *addr++ = rd16(baddr);
322 octopci_bs_rr_4(void *t, bus_space_handle_t bsh,
323 bus_size_t offset, uint32_t *addr, size_t count)
325 bus_addr_t baddr = bsh + offset;
328 *addr++ = rd32(baddr);
334 * Write the 1, 2, 4, or 8 byte value `value' to bus space
335 * described by tag/handle/offset.
338 octopci_bs_w_1(void *t, bus_space_handle_t bsh,
339 bus_size_t offset, uint8_t value)
342 wr8(bsh + offset, value);
346 octopci_bs_w_2(void *t, bus_space_handle_t bsh,
347 bus_size_t offset, uint16_t value)
350 wr16(bsh + offset, value);
354 octopci_bs_w_4(void *t, bus_space_handle_t bsh,
355 bus_size_t offset, uint32_t value)
358 wr32(bsh + offset, value);
362 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
363 * provided to bus space described by tag/handle/offset.
366 octopci_bs_wm_1(void *t, bus_space_handle_t bsh,
367 bus_size_t offset, const uint8_t *addr, size_t count)
369 bus_addr_t baddr = bsh + offset;
376 octopci_bs_wm_2(void *t, bus_space_handle_t bsh,
377 bus_size_t offset, const uint16_t *addr, size_t count)
379 bus_addr_t baddr = bsh + offset;
382 wr16(baddr, *addr++);
386 octopci_bs_wm_4(void *t, bus_space_handle_t bsh,
387 bus_size_t offset, const uint32_t *addr, size_t count)
389 bus_addr_t baddr = bsh + offset;
392 wr32(baddr, *addr++);
396 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
397 * to bus space described by tag/handle starting at `offset'.
400 octopci_bs_wr_1(void *t, bus_space_handle_t bsh,
401 bus_size_t offset, const uint8_t *addr, size_t count)
403 bus_addr_t baddr = bsh + offset;
412 octopci_bs_wr_2(void *t, bus_space_handle_t bsh,
413 bus_size_t offset, const uint16_t *addr, size_t count)
415 bus_addr_t baddr = bsh + offset;
418 wr16(baddr, *addr++);
424 octopci_bs_wr_4(void *t, bus_space_handle_t bsh,
425 bus_size_t offset, const uint32_t *addr, size_t count)
427 bus_addr_t baddr = bsh + offset;
430 wr32(baddr, *addr++);
436 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
437 * by tag/handle/offset `count' times.
440 octopci_bs_sm_1(void *t, bus_space_handle_t bsh,
441 bus_size_t offset, uint8_t value, size_t count)
443 bus_addr_t addr = bsh + offset;
450 octopci_bs_sm_2(void *t, bus_space_handle_t bsh,
451 bus_size_t offset, uint16_t value, size_t count)
453 bus_addr_t addr = bsh + offset;
460 octopci_bs_sm_4(void *t, bus_space_handle_t bsh,
461 bus_size_t offset, uint32_t value, size_t count)
463 bus_addr_t addr = bsh + offset;
470 * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
471 * by tag/handle starting at `offset'.
474 octopci_bs_sr_1(void *t, bus_space_handle_t bsh,
475 bus_size_t offset, uint8_t value, size_t count)
477 bus_addr_t addr = bsh + offset;
479 for (; count != 0; count--, addr++)
484 octopci_bs_sr_2(void *t, bus_space_handle_t bsh,
485 bus_size_t offset, uint16_t value, size_t count)
487 bus_addr_t addr = bsh + offset;
489 for (; count != 0; count--, addr += 2)
494 octopci_bs_sr_4(void *t, bus_space_handle_t bsh,
495 bus_size_t offset, uint32_t value, size_t count)
497 bus_addr_t addr = bsh + offset;
499 for (; count != 0; count--, addr += 4)
504 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
505 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
508 octopci_bs_c_1(void *t, bus_space_handle_t bsh1,
509 bus_size_t off1, bus_space_handle_t bsh2,
510 bus_size_t off2, size_t count)
512 bus_addr_t addr1 = bsh1 + off1;
513 bus_addr_t addr2 = bsh2 + off2;
515 if (addr1 >= addr2) {
516 /* src after dest: copy forward */
517 for (; count != 0; count--, addr1++, addr2++)
518 wr8(addr2, rd8(addr1));
520 /* dest after src: copy backwards */
521 for (addr1 += (count - 1), addr2 += (count - 1);
522 count != 0; count--, addr1--, addr2--)
523 wr8(addr2, rd8(addr1));
528 octopci_bs_c_2(void *t, bus_space_handle_t bsh1,
529 bus_size_t off1, bus_space_handle_t bsh2,
530 bus_size_t off2, size_t count)
532 bus_addr_t addr1 = bsh1 + off1;
533 bus_addr_t addr2 = bsh2 + off2;
535 if (addr1 >= addr2) {
536 /* src after dest: copy forward */
537 for (; count != 0; count--, addr1 += 2, addr2 += 2)
538 wr16(addr2, rd16(addr1));
540 /* dest after src: copy backwards */
541 for (addr1 += 2 * (count - 1), addr2 += 2 * (count - 1);
542 count != 0; count--, addr1 -= 2, addr2 -= 2)
543 wr16(addr2, rd16(addr1));
548 octopci_bs_c_4(void *t, bus_space_handle_t bsh1,
549 bus_size_t off1, bus_space_handle_t bsh2,
550 bus_size_t off2, size_t count)
552 bus_addr_t addr1 = bsh1 + off1;
553 bus_addr_t addr2 = bsh2 + off2;
555 if (addr1 >= addr2) {
556 /* src after dest: copy forward */
557 for (; count != 0; count--, addr1 += 4, addr2 += 4)
558 wr32(addr2, rd32(addr1));
560 /* dest after src: copy backwards */
561 for (addr1 += 4 * (count - 1), addr2 += 4 * (count - 1);
562 count != 0; count--, addr1 -= 4, addr2 -= 4)
563 wr32(addr2, rd32(addr1));
568 octopci_bs_barrier(void *t __unused,
569 bus_space_handle_t bsh __unused,
570 bus_size_t offset __unused, bus_size_t len __unused,
574 if (flags & BUS_SPACE_BARRIER_WRITE)
575 mips_dcache_wbinv_all();