bus_funcs.h revision 1.2 1 1.2 skrll /* $NetBSD: bus_funcs.h,v 1.2 2014/07/29 21:21:44 skrll Exp $ */
2 1.1 dyoung
3 1.1 dyoung /*
4 1.1 dyoung * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
5 1.1 dyoung * All rights reserved.
6 1.1 dyoung *
7 1.1 dyoung * This code is derived from software contributed to The NetBSD Foundation
8 1.1 dyoung * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 1.1 dyoung * NASA Ames Research Center.
10 1.1 dyoung *
11 1.1 dyoung * Redistribution and use in source and binary forms, with or without
12 1.1 dyoung * modification, are permitted provided that the following conditions
13 1.1 dyoung * are met:
14 1.1 dyoung * 1. Redistributions of source code must retain the above copyright
15 1.1 dyoung * notice, this list of conditions and the following disclaimer.
16 1.1 dyoung * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 dyoung * notice, this list of conditions and the following disclaimer in the
18 1.1 dyoung * documentation and/or other materials provided with the distribution.
19 1.1 dyoung *
20 1.1 dyoung * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 1.1 dyoung * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 1.1 dyoung * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 1.1 dyoung * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 1.1 dyoung * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 1.1 dyoung * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 1.1 dyoung * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 1.1 dyoung * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 1.1 dyoung * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 1.1 dyoung * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 1.1 dyoung * POSSIBILITY OF SUCH DAMAGE.
31 1.1 dyoung */
32 1.1 dyoung
33 1.1 dyoung #ifndef _COBALT_BUS_FUNCS_H_
34 1.1 dyoung #define _COBALT_BUS_FUNCS_H_
35 1.1 dyoung
36 1.1 dyoung /*
37 1.1 dyoung * uintN_t bus_space_read_N(bus_space_tag_t tag,
38 1.1 dyoung * bus_space_handle_t bsh, bus_size_t offset);
39 1.1 dyoung *
40 1.1 dyoung * Read a 1, 2, 4, or 8 byte quantity from bus space
41 1.1 dyoung * described by tag/handle/offset.
42 1.1 dyoung */
43 1.1 dyoung
44 1.1 dyoung #define bus_space_read_1(t, h, o) \
45 1.1 dyoung ((void) t, (*(volatile uint8_t *)((h) + (o))))
46 1.1 dyoung
47 1.1 dyoung #define bus_space_read_2(t, h, o) \
48 1.1 dyoung ((void) t, (*(volatile uint16_t *)((h) + (o))))
49 1.1 dyoung
50 1.1 dyoung #define bus_space_read_4(t, h, o) \
51 1.1 dyoung ((void) t, (*(volatile uint32_t *)((h) + (o))))
52 1.1 dyoung
53 1.1 dyoung #if 0 /* Cause a link error for bus_space_read_8 */
54 1.1 dyoung #define bus_space_read_8(t, h, o) !!! bus_space_read_8 unimplemented !!!
55 1.1 dyoung #endif
56 1.1 dyoung
57 1.1 dyoung /*
58 1.1 dyoung * void bus_space_write_N(bus_space_tag_t tag,
59 1.1 dyoung * bus_space_handle_t bsh, bus_size_t offset,
60 1.1 dyoung * uintN_t value);
61 1.1 dyoung *
62 1.1 dyoung * Write the 1, 2, 4, or 8 byte value `value' to bus space
63 1.1 dyoung * described by tag/handle/offset.
64 1.1 dyoung */
65 1.1 dyoung
66 1.1 dyoung #define bus_space_write_1(t, h, o, v) \
67 1.1 dyoung do { \
68 1.1 dyoung (void) t; \
69 1.1 dyoung *(volatile uint8_t *)((h) + (o)) = (v); \
70 1.1 dyoung } while (0)
71 1.1 dyoung
72 1.1 dyoung #define bus_space_write_2(t, h, o, v) \
73 1.1 dyoung do { \
74 1.1 dyoung (void) t; \
75 1.1 dyoung *(volatile uint16_t *)((h) + (o)) = (v); \
76 1.1 dyoung } while (0)
77 1.1 dyoung
78 1.1 dyoung #define bus_space_write_4(t, h, o, v) \
79 1.1 dyoung do { \
80 1.1 dyoung (void) t; \
81 1.1 dyoung *(volatile uint32_t *)((h) + (o)) = (v); \
82 1.1 dyoung } while (0)
83 1.1 dyoung
84 1.1 dyoung #if 0 /* Cause a link error for bus_space_write_8 */
85 1.1 dyoung #define bus_space_write_8 !!! bus_space_write_8 not implemented !!!
86 1.1 dyoung #endif
87 1.1 dyoung
88 1.1 dyoung /*
89 1.1 dyoung * Operations which handle byte stream data on word access.
90 1.1 dyoung *
91 1.1 dyoung * These functions are defined to resolve endian mismatch, by either
92 1.1 dyoung * - When normal (i.e. stream-less) operations perform byte swap
93 1.1 dyoung * to resolve endian mismatch, these functions bypass the byte swap.
94 1.1 dyoung * or
95 1.1 dyoung * - When bus bridge performs automatic byte swap, these functions
96 1.1 dyoung * perform byte swap once more, to cancel the bridge's behavior.
97 1.1 dyoung *
98 1.1 dyoung * Currently these are just same as normal operations, since all
99 1.1 dyoung * supported buses are same endian with CPU (i.e. little-endian).
100 1.1 dyoung *
101 1.1 dyoung */
102 1.1 dyoung #define bus_space_read_stream_2(tag, bsh, offset) \
103 1.1 dyoung bus_space_read_2(tag, bsh, offset)
104 1.1 dyoung #define bus_space_read_stream_4(tag, bsh, offset) \
105 1.1 dyoung bus_space_read_4(tag, bsh, offset)
106 1.1 dyoung #define bus_space_read_stream_8(tag, bsh, offset) \
107 1.1 dyoung bus_space_read_8(tag, bsh, offset)
108 1.1 dyoung #define bus_space_read_multi_stream_2(tag, bsh, offset, datap, count) \
109 1.1 dyoung bus_space_read_multi_2(tag, bsh, offset, datap, count)
110 1.1 dyoung #define bus_space_read_multi_stream_4(tag, bsh, offset, datap, count) \
111 1.1 dyoung bus_space_read_multi_4(tag, bsh, offset, datap, count)
112 1.1 dyoung #define bus_space_read_multi_stream_8(tag, bsh, offset, datap, count) \
113 1.1 dyoung bus_space_read_multi_8(tag, bsh, offset, datap, count)
114 1.1 dyoung #define bus_space_read_region_stream_2(tag, bsh, offset, datap, count) \
115 1.1 dyoung bus_space_read_region_2(tag, bsh, offset, datap, count)
116 1.1 dyoung #define bus_space_read_region_stream_4(tag, bsh, offset, datap, count) \
117 1.1 dyoung bus_space_read_region_4(tag, bsh, offset, datap, count)
118 1.1 dyoung #define bus_space_read_region_stream_8(tag, bsh, offset, datap, count) \
119 1.1 dyoung bus_space_read_region_8(tag, bsh, offset, datap, count)
120 1.1 dyoung #define bus_space_write_stream_2(tag, bsh, offset, data) \
121 1.1 dyoung bus_space_write_2(tag, bsh, offset, data)
122 1.1 dyoung #define bus_space_write_stream_4(tag, bsh, offset, data) \
123 1.1 dyoung bus_space_write_4(tag, bsh, offset, data)
124 1.1 dyoung #define bus_space_write_stream_8(tag, bsh, offset, data) \
125 1.1 dyoung bus_space_write_8(tag, bsh, offset, data)
126 1.1 dyoung #define bus_space_write_multi_stream_2(tag, bsh, offset, datap, count) \
127 1.1 dyoung bus_space_write_multi_2(tag, bsh, offset, datap, count)
128 1.1 dyoung #define bus_space_write_multi_stream_4(tag, bsh, offset, datap, count) \
129 1.1 dyoung bus_space_write_multi_4(tag, bsh, offset, datap, count)
130 1.1 dyoung #define bus_space_write_multi_stream_8(tag, bsh, offset, datap, count) \
131 1.1 dyoung bus_space_write_multi_8(tag, bsh, offset, datap, count)
132 1.1 dyoung #define bus_space_write_region_stream_2(tag, bsh, offset, datap, count) \
133 1.1 dyoung bus_space_write_region_2(tag, bsh, offset, datap, count)
134 1.1 dyoung #define bus_space_write_region_stream_4(tag, bsh, offset, datap, count) \
135 1.1 dyoung bus_space_write_region_4(tag, bsh, offset, datap, count)
136 1.1 dyoung #define bus_space_write_region_stream_8(tag, bsh, offset, datap, count) \
137 1.1 dyoung bus_space_write_region_8(tag, bsh, offset, datap, count)
138 1.1 dyoung #define bus_space_write_region_stream_2(tag, bsh, offset, datap, count) \
139 1.1 dyoung bus_space_write_region_2(tag, bsh, offset, datap, count)
140 1.1 dyoung #define bus_space_write_region_stream_4(tag, bsh, offset, datap, count) \
141 1.1 dyoung bus_space_write_region_4(tag, bsh, offset, datap, count)
142 1.1 dyoung #define bus_space_write_region_stream_8(tag, bsh, offset, datap, count) \
143 1.1 dyoung bus_space_write_region_8(tag, bsh, offset, datap, count)
144 1.1 dyoung #define bus_space_set_multi_stream_2(tag, bsh, offset, data, count) \
145 1.1 dyoung bus_space_set_multi_2(tag, bsh, offset, data, count)
146 1.1 dyoung #define bus_space_set_multi_stream_4(tag, bsh, offset, data, count) \
147 1.1 dyoung bus_space_set_multi_4(tag, bsh, offset, data, count)
148 1.1 dyoung #define bus_space_set_multi_stream_8(tag, bsh, offset, data, count) \
149 1.1 dyoung bus_space_set_multi_8(tag, bsh, offset, data, count)
150 1.1 dyoung #define bus_space_set_region_stream_2(tag, bsh, offset, data, count) \
151 1.1 dyoung bus_space_set_region_2(tag, bsh, offset, data, count)
152 1.1 dyoung #define bus_space_set_region_stream_4(tag, bsh, offset, data, count) \
153 1.1 dyoung bus_space_set_region_4(tag, bsh, offset, data, count)
154 1.1 dyoung #define bus_space_set_region_stream_8(tag, bsh, offset, data, count) \
155 1.1 dyoung bus_space_set_region_8(tag, bsh, offset, data, count)
156 1.1 dyoung
157 1.1 dyoung /*
158 1.1 dyoung * Bus read/write barrier methods.
159 1.1 dyoung *
160 1.1 dyoung * void bus_space_barrier(bus_space_tag_t tag,
161 1.1 dyoung * bus_space_handle_t bsh, bus_size_t offset,
162 1.1 dyoung * bus_size_t len, int flags);
163 1.1 dyoung *
164 1.1 dyoung * On the MIPS, we just flush the write buffer.
165 1.1 dyoung */
166 1.1 dyoung #define bus_space_barrier(t, h, o, l, f) \
167 1.1 dyoung ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f), \
168 1.1 dyoung wbflush()))
169 1.1 dyoung
170 1.2 skrll #include <mips/bus_dma_funcs.h>
171 1.1 dyoung
172 1.1 dyoung #endif /* _COBALT_BUS_FUNCS_H_ */
173