dcr.h revision 1.2 1 1.2 andvar /* $NetBSD: dcr.h,v 1.2 2021/10/21 13:21:54 andvar Exp $ */
2 1.1 freza
3 1.1 freza /*
4 1.1 freza * Copyright (c) 2006 Jachym Holecek
5 1.1 freza * All rights reserved.
6 1.1 freza *
7 1.1 freza * Written for DFC Design, s.r.o.
8 1.1 freza *
9 1.1 freza * Redistribution and use in source and binary forms, with or without
10 1.1 freza * modification, are permitted provided that the following conditions
11 1.1 freza * are met:
12 1.1 freza *
13 1.1 freza * 1. Redistributions of source code must retain the above copyright
14 1.1 freza * notice, this list of conditions and the following disclaimer.
15 1.1 freza *
16 1.1 freza * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 freza * notice, this list of conditions and the following disclaimer in the
18 1.1 freza * documentation and/or other materials provided with the distribution.
19 1.1 freza *
20 1.1 freza * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.1 freza * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.1 freza * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.1 freza * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.1 freza * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.1 freza * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.1 freza * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.1 freza * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.1 freza * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.1 freza * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1 freza */
31 1.1 freza
32 1.1 freza /*
33 1.2 andvar * DCR is an user accessible bus on Xilinx PPC405D5Xn cores and may contain
34 1.1 freza * arbitrary devices. Because we want to be able to share drivers with
35 1.1 freza * OPB/PLB, we make it a bus space backend. Each platform ("design", "board")
36 1.1 freza * has to provide the leaf _read_4/_write_4 routines specific to device
37 1.1 freza * instances. This is dictated by the fact that DCR can only by accessed
38 1.1 freza * by m{f,t}dcr instructions for which the address is encoded as immediate
39 1.1 freza * operand (and hence needs to be a compile-time constant).
40 1.1 freza *
41 1.1 freza * The flexibility is well worth the price of one indirection (and a sum
42 1.1 freza * and a branch), critical paths can still be implemented with m{f,t}dcr().
43 1.1 freza */
44 1.1 freza
45 1.1 freza #ifndef _VIRTEX_DCRVAR_H_
46 1.1 freza #define _VIRTEX_DCRVAR_H_
47 1.1 freza
48 1.1 freza
49 1.1 freza /* From evbppc/virtex/machdep.c */
50 1.1 freza int dcr_subregion(bus_space_tag_t, bus_space_handle_t, bus_size_t,
51 1.1 freza bus_size_t, bus_space_handle_t *);
52 1.1 freza int dcr_map(bus_space_tag_t, bus_addr_t, bus_size_t, int,
53 1.1 freza bus_space_handle_t *);
54 1.1 freza void dcr_unmap(bus_space_tag_t, bus_space_handle_t, bus_size_t);
55 1.1 freza
56 1.1 freza /* Bus space tag contents, one tag per DCR device. */
57 1.1 freza #define DCR_BST_BODY(base, read, write) \
58 1.1 freza .pbs_flags = _BUS_SPACE_BIG_ENDIAN, \
59 1.1 freza .pbs_offset = 0, \
60 1.1 freza .pbs_base = (base), \
61 1.1 freza .pbs_limit = 0x03ff, \
62 1.1 freza .pbs_scalar = { \
63 1.1 freza .pbss_write_4 = (write), \
64 1.1 freza .pbss_read_4 = (read), \
65 1.1 freza }, \
66 1.1 freza .pbs_map = dcr_map, \
67 1.1 freza .pbs_unmap = dcr_unmap, \
68 1.1 freza .pbs_subregion = dcr_subregion,
69 1.1 freza
70 1.1 freza /*
71 1.1 freza * Utility macros for leaf access routines. Note they assume variables
72 1.1 freza * in local scope, and are furthermore assumed to be used in switch()
73 1.1 freza * dispatch over destination address.
74 1.1 freza */
75 1.1 freza #define WCASE(base, addr) \
76 1.1 freza case (addr): mtdcr((base) + (addr) / 4, val); break
77 1.1 freza
78 1.1 freza #define WDEAD(addr) \
79 1.1 freza default: panic("%s: unexpected offset %#08x", __func__, (addr))
80 1.1 freza
81 1.1 freza #define RCASE(base, addr) \
82 1.1 freza case (addr): val = mfdcr((base) + (addr) / 4); break
83 1.1 freza
84 1.1 freza #define RDEAD(addr) \
85 1.1 freza default: panic("%s: unexpected offset %#08x", __func__, (addr))
86 1.1 freza
87 1.1 freza #endif /* _VIRTEX_DCRVAR_H_ */
88