g2bus_bus_mem.c revision 1.13 1 1.13 tsutsui /* $NetBSD: g2bus_bus_mem.c,v 1.13 2006/08/07 17:36:53 tsutsui Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*-
4 1.1 thorpej * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 1.1 thorpej * All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.1 thorpej * by Jason R. Thorpe.
9 1.1 thorpej *
10 1.1 thorpej * Redistribution and use in source and binary forms, with or without
11 1.1 thorpej * modification, are permitted provided that the following conditions
12 1.1 thorpej * are met:
13 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.1 thorpej * notice, this list of conditions and the following disclaimer.
15 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.1 thorpej * documentation and/or other materials provided with the distribution.
18 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
19 1.1 thorpej * must display the following acknowledgement:
20 1.1 thorpej * This product includes software developed by the NetBSD
21 1.1 thorpej * Foundation, Inc. and its contributors.
22 1.1 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 thorpej * contributors may be used to endorse or promote products derived
24 1.1 thorpej * from this software without specific prior written permission.
25 1.1 thorpej *
26 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
37 1.1 thorpej */
38 1.1 thorpej
39 1.1 thorpej /*
40 1.1 thorpej * Bus space implementation for the SEGA G2 bus.
41 1.1 thorpej *
42 1.1 thorpej * NOTE: We only implement a small subset of what the bus_space(9)
43 1.1 thorpej * API specifies. Right now, the GAPS PCI bridge is only used for
44 1.1 thorpej * the Dreamcast Broadband Adatper, so we only provide what the
45 1.1 thorpej * pci(4) and rtk(4) drivers need.
46 1.1 thorpej */
47 1.1 thorpej
48 1.1 thorpej #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
49 1.13 tsutsui __KERNEL_RCSID(0, "$NetBSD: g2bus_bus_mem.c,v 1.13 2006/08/07 17:36:53 tsutsui Exp $");
50 1.1 thorpej
51 1.1 thorpej #include <sys/param.h>
52 1.13 tsutsui #include <sys/systm.h>
53 1.1 thorpej #include <sys/device.h>
54 1.1 thorpej
55 1.13 tsutsui #include <machine/cpu.h>
56 1.1 thorpej #include <machine/bus.h>
57 1.1 thorpej
58 1.1 thorpej #include <dreamcast/dev/g2/g2busvar.h>
59 1.1 thorpej
60 1.1 thorpej int g2bus_bus_mem_map(void *, bus_addr_t, bus_size_t, int,
61 1.1 thorpej bus_space_handle_t *);
62 1.1 thorpej void g2bus_bus_mem_unmap(void *, bus_space_handle_t, bus_size_t);
63 1.1 thorpej
64 1.10 tsutsui uint8_t g2bus_bus_mem_read_1(void *, bus_space_handle_t, bus_size_t);
65 1.10 tsutsui uint16_t g2bus_bus_mem_read_2(void *, bus_space_handle_t, bus_size_t);
66 1.10 tsutsui uint32_t g2bus_bus_mem_read_4(void *, bus_space_handle_t, bus_size_t);
67 1.1 thorpej
68 1.1 thorpej void g2bus_bus_mem_write_1(void *, bus_space_handle_t, bus_size_t,
69 1.10 tsutsui uint8_t);
70 1.1 thorpej void g2bus_bus_mem_write_2(void *, bus_space_handle_t, bus_size_t,
71 1.10 tsutsui uint16_t);
72 1.1 thorpej void g2bus_bus_mem_write_4(void *, bus_space_handle_t, bus_size_t,
73 1.10 tsutsui uint32_t);
74 1.1 thorpej
75 1.3 thorpej void g2bus_bus_mem_read_region_1(void *, bus_space_handle_t, bus_size_t,
76 1.10 tsutsui uint8_t *, bus_size_t);
77 1.9 marcus void g2bus_bus_mem_read_region_2(void *, bus_space_handle_t, bus_size_t,
78 1.10 tsutsui uint16_t *, bus_size_t);
79 1.9 marcus void g2bus_bus_mem_read_region_4(void *, bus_space_handle_t, bus_size_t,
80 1.10 tsutsui uint32_t *, bus_size_t);
81 1.3 thorpej
82 1.3 thorpej void g2bus_bus_mem_write_region_1(void *, bus_space_handle_t, bus_size_t,
83 1.10 tsutsui const uint8_t *, bus_size_t);
84 1.9 marcus void g2bus_bus_mem_write_region_2(void *, bus_space_handle_t, bus_size_t,
85 1.10 tsutsui const uint16_t *, bus_size_t);
86 1.9 marcus void g2bus_bus_mem_write_region_4(void *, bus_space_handle_t, bus_size_t,
87 1.10 tsutsui const uint32_t *, bus_size_t);
88 1.9 marcus
89 1.9 marcus void g2bus_bus_mem_set_region_4(void *, bus_space_handle_t, bus_size_t,
90 1.10 tsutsui uint32_t, bus_size_t);
91 1.3 thorpej
92 1.10 tsutsui uint8_t g2bus_sparse_bus_mem_read_1(void *, bus_space_handle_t, bus_size_t);
93 1.10 tsutsui uint16_t g2bus_sparse_bus_mem_read_2(void *, bus_space_handle_t, bus_size_t);
94 1.10 tsutsui uint32_t g2bus_sparse_bus_mem_read_4(void *, bus_space_handle_t, bus_size_t);
95 1.6 tsutsui
96 1.6 tsutsui void g2bus_sparse_bus_mem_write_1(void *, bus_space_handle_t, bus_size_t,
97 1.10 tsutsui uint8_t);
98 1.6 tsutsui void g2bus_sparse_bus_mem_write_2(void *, bus_space_handle_t, bus_size_t,
99 1.10 tsutsui uint16_t);
100 1.6 tsutsui void g2bus_sparse_bus_mem_write_4(void *, bus_space_handle_t, bus_size_t,
101 1.10 tsutsui uint32_t);
102 1.6 tsutsui
103 1.6 tsutsui void g2bus_sparse_bus_mem_read_region_1(void *, bus_space_handle_t,
104 1.10 tsutsui bus_size_t, uint8_t *, bus_size_t);
105 1.6 tsutsui
106 1.6 tsutsui void g2bus_sparse_bus_mem_write_region_1(void *, bus_space_handle_t,
107 1.10 tsutsui bus_size_t, const uint8_t *, bus_size_t);
108 1.6 tsutsui
109 1.6 tsutsui void g2bus_sparse_bus_mem_read_multi_1(void *, bus_space_handle_t,
110 1.10 tsutsui bus_size_t, uint8_t *, bus_size_t);
111 1.6 tsutsui
112 1.6 tsutsui void g2bus_sparse_bus_mem_write_multi_1(void *, bus_space_handle_t,
113 1.10 tsutsui bus_size_t, const uint8_t *, bus_size_t);
114 1.6 tsutsui
115 1.1 thorpej void
116 1.1 thorpej g2bus_bus_mem_init(struct g2bus_softc *sc)
117 1.1 thorpej {
118 1.1 thorpej bus_space_tag_t t = &sc->sc_memt;
119 1.1 thorpej
120 1.1 thorpej memset(t, 0, sizeof(*t));
121 1.1 thorpej
122 1.1 thorpej t->dbs_map = g2bus_bus_mem_map;
123 1.1 thorpej t->dbs_unmap = g2bus_bus_mem_unmap;
124 1.1 thorpej
125 1.1 thorpej t->dbs_r_1 = g2bus_bus_mem_read_1;
126 1.1 thorpej t->dbs_r_2 = g2bus_bus_mem_read_2;
127 1.1 thorpej t->dbs_r_4 = g2bus_bus_mem_read_4;
128 1.1 thorpej
129 1.1 thorpej t->dbs_w_1 = g2bus_bus_mem_write_1;
130 1.1 thorpej t->dbs_w_2 = g2bus_bus_mem_write_2;
131 1.1 thorpej t->dbs_w_4 = g2bus_bus_mem_write_4;
132 1.3 thorpej
133 1.3 thorpej t->dbs_rr_1 = g2bus_bus_mem_read_region_1;
134 1.9 marcus t->dbs_rr_2 = g2bus_bus_mem_read_region_2;
135 1.9 marcus t->dbs_rr_4 = g2bus_bus_mem_read_region_4;
136 1.3 thorpej
137 1.3 thorpej t->dbs_wr_1 = g2bus_bus_mem_write_region_1;
138 1.9 marcus t->dbs_wr_2 = g2bus_bus_mem_write_region_2;
139 1.9 marcus t->dbs_wr_4 = g2bus_bus_mem_write_region_4;
140 1.9 marcus
141 1.9 marcus t->dbs_sr_4 = g2bus_bus_mem_set_region_4;
142 1.1 thorpej }
143 1.1 thorpej
144 1.1 thorpej int
145 1.1 thorpej g2bus_bus_mem_map(void *v, bus_addr_t addr, bus_size_t size, int flags,
146 1.1 thorpej bus_space_handle_t *shp)
147 1.1 thorpej {
148 1.1 thorpej
149 1.1 thorpej KASSERT((addr & SH3_PHYS_MASK) == addr);
150 1.1 thorpej *shp = SH3_PHYS_TO_P2SEG(addr);
151 1.1 thorpej
152 1.10 tsutsui return 0;
153 1.1 thorpej }
154 1.1 thorpej
155 1.1 thorpej void
156 1.1 thorpej g2bus_bus_mem_unmap(void *v, bus_space_handle_t sh, bus_size_t size)
157 1.1 thorpej {
158 1.1 thorpej
159 1.1 thorpej KASSERT(sh >= SH3_P2SEG_BASE && sh <= SH3_P2SEG_END);
160 1.1 thorpej /* Nothing to do. */
161 1.1 thorpej }
162 1.1 thorpej
163 1.1 thorpej /*
164 1.2 marcus * G2 bus cycles must not be interrupted by IRQs or G2 DMA.
165 1.2 marcus * The following paired macros will take the necessary precautions.
166 1.1 thorpej */
167 1.1 thorpej
168 1.7 tsutsui #define G2LOCK_DECL \
169 1.7 tsutsui int __s
170 1.7 tsutsui
171 1.7 tsutsui #define G2_LOCK() \
172 1.2 marcus do { \
173 1.7 tsutsui __s = _cpu_intr_suspend(); \
174 1.2 marcus /* suspend any G2 DMA here... */ \
175 1.12 perry while ((*(volatile uint32_t *)0xa05f688c) & 0x20) \
176 1.7 tsutsui ; \
177 1.7 tsutsui } while (/*CONSTCOND*/0)
178 1.2 marcus
179 1.7 tsutsui #define G2_UNLOCK() \
180 1.2 marcus do { \
181 1.2 marcus /* resume any G2 DMA here... */ \
182 1.7 tsutsui _cpu_intr_resume(__s); \
183 1.7 tsutsui } while (/*CONSTCOND*/0)
184 1.2 marcus
185 1.10 tsutsui uint8_t
186 1.1 thorpej g2bus_bus_mem_read_1(void *v, bus_space_handle_t sh, bus_size_t off)
187 1.1 thorpej {
188 1.7 tsutsui G2LOCK_DECL;
189 1.10 tsutsui uint8_t rv;
190 1.1 thorpej
191 1.7 tsutsui G2_LOCK();
192 1.2 marcus
193 1.12 perry rv = *(volatile uint8_t *)(sh + off);
194 1.1 thorpej
195 1.7 tsutsui G2_UNLOCK();
196 1.2 marcus
197 1.10 tsutsui return rv;
198 1.1 thorpej }
199 1.1 thorpej
200 1.10 tsutsui uint16_t
201 1.1 thorpej g2bus_bus_mem_read_2(void *v, bus_space_handle_t sh, bus_size_t off)
202 1.1 thorpej {
203 1.7 tsutsui G2LOCK_DECL;
204 1.10 tsutsui uint16_t rv;
205 1.1 thorpej
206 1.7 tsutsui G2_LOCK();
207 1.2 marcus
208 1.12 perry rv = *(volatile uint16_t *)(sh + off);
209 1.1 thorpej
210 1.7 tsutsui G2_UNLOCK();
211 1.2 marcus
212 1.10 tsutsui return rv;
213 1.1 thorpej }
214 1.1 thorpej
215 1.10 tsutsui uint32_t
216 1.1 thorpej g2bus_bus_mem_read_4(void *v, bus_space_handle_t sh, bus_size_t off)
217 1.1 thorpej {
218 1.7 tsutsui G2LOCK_DECL;
219 1.10 tsutsui uint32_t rv;
220 1.1 thorpej
221 1.7 tsutsui G2_LOCK();
222 1.2 marcus
223 1.12 perry rv = *(volatile uint32_t *)(sh + off);
224 1.1 thorpej
225 1.7 tsutsui G2_UNLOCK();
226 1.2 marcus
227 1.10 tsutsui return rv;
228 1.1 thorpej }
229 1.1 thorpej
230 1.1 thorpej void
231 1.1 thorpej g2bus_bus_mem_write_1(void *v, bus_space_handle_t sh, bus_size_t off,
232 1.10 tsutsui uint8_t val)
233 1.1 thorpej {
234 1.7 tsutsui G2LOCK_DECL;
235 1.1 thorpej
236 1.7 tsutsui G2_LOCK();
237 1.2 marcus
238 1.12 perry *(volatile uint8_t *)(sh + off) = val;
239 1.2 marcus
240 1.7 tsutsui G2_UNLOCK();
241 1.1 thorpej }
242 1.1 thorpej
243 1.1 thorpej void
244 1.1 thorpej g2bus_bus_mem_write_2(void *v, bus_space_handle_t sh, bus_size_t off,
245 1.10 tsutsui uint16_t val)
246 1.1 thorpej {
247 1.7 tsutsui G2LOCK_DECL;
248 1.1 thorpej
249 1.7 tsutsui G2_LOCK();
250 1.2 marcus
251 1.12 perry *(volatile uint16_t *)(sh + off) = val;
252 1.2 marcus
253 1.7 tsutsui G2_UNLOCK();
254 1.1 thorpej }
255 1.1 thorpej
256 1.1 thorpej void
257 1.1 thorpej g2bus_bus_mem_write_4(void *v, bus_space_handle_t sh, bus_size_t off,
258 1.10 tsutsui uint32_t val)
259 1.1 thorpej {
260 1.7 tsutsui G2LOCK_DECL;
261 1.1 thorpej
262 1.7 tsutsui G2_LOCK();
263 1.2 marcus
264 1.12 perry *(volatile uint32_t *)(sh + off) = val;
265 1.3 thorpej
266 1.7 tsutsui G2_UNLOCK();
267 1.3 thorpej }
268 1.3 thorpej
269 1.3 thorpej void
270 1.3 thorpej g2bus_bus_mem_read_region_1(void *v, bus_space_handle_t sh, bus_size_t off,
271 1.10 tsutsui uint8_t *addr, bus_size_t len)
272 1.3 thorpej {
273 1.7 tsutsui G2LOCK_DECL;
274 1.12 perry volatile const uint8_t *baddr = (uint8_t *)(sh + off);
275 1.3 thorpej
276 1.7 tsutsui G2_LOCK();
277 1.3 thorpej
278 1.3 thorpej while (len--)
279 1.3 thorpej *addr++ = *baddr++;
280 1.3 thorpej
281 1.7 tsutsui G2_UNLOCK();
282 1.3 thorpej }
283 1.3 thorpej
284 1.3 thorpej void
285 1.9 marcus g2bus_bus_mem_read_region_2(void *v, bus_space_handle_t sh, bus_size_t off,
286 1.10 tsutsui uint16_t *addr, bus_size_t len)
287 1.9 marcus {
288 1.9 marcus G2LOCK_DECL;
289 1.12 perry volatile const uint16_t *baddr = (uint16_t *)(sh + off);
290 1.9 marcus
291 1.9 marcus G2_LOCK();
292 1.9 marcus
293 1.9 marcus while (len--)
294 1.9 marcus *addr++ = *baddr++;
295 1.9 marcus
296 1.9 marcus G2_UNLOCK();
297 1.9 marcus }
298 1.9 marcus
299 1.9 marcus void
300 1.9 marcus g2bus_bus_mem_read_region_4(void *v, bus_space_handle_t sh, bus_size_t off,
301 1.10 tsutsui uint32_t *addr, bus_size_t len)
302 1.9 marcus {
303 1.9 marcus G2LOCK_DECL;
304 1.12 perry volatile const uint32_t *baddr = (uint32_t *)(sh + off);
305 1.9 marcus
306 1.9 marcus G2_LOCK();
307 1.9 marcus
308 1.9 marcus while (len--)
309 1.9 marcus *addr++ = *baddr++;
310 1.9 marcus
311 1.9 marcus G2_UNLOCK();
312 1.9 marcus }
313 1.9 marcus
314 1.9 marcus void
315 1.3 thorpej g2bus_bus_mem_write_region_1(void *v, bus_space_handle_t sh, bus_size_t off,
316 1.10 tsutsui const uint8_t *addr, bus_size_t len)
317 1.3 thorpej {
318 1.7 tsutsui G2LOCK_DECL;
319 1.12 perry volatile uint8_t *baddr = (uint8_t *)(sh + off);
320 1.3 thorpej
321 1.7 tsutsui G2_LOCK();
322 1.3 thorpej
323 1.3 thorpej while (len--)
324 1.3 thorpej *baddr++ = *addr++;
325 1.9 marcus
326 1.9 marcus G2_UNLOCK();
327 1.9 marcus }
328 1.9 marcus
329 1.9 marcus void
330 1.9 marcus g2bus_bus_mem_write_region_2(void *v, bus_space_handle_t sh, bus_size_t off,
331 1.10 tsutsui const uint16_t *addr, bus_size_t len)
332 1.9 marcus {
333 1.9 marcus G2LOCK_DECL;
334 1.12 perry volatile uint16_t *baddr = (uint16_t *)(sh + off);
335 1.9 marcus
336 1.9 marcus G2_LOCK();
337 1.9 marcus
338 1.9 marcus while (len--)
339 1.9 marcus *baddr++ = *addr++;
340 1.9 marcus
341 1.9 marcus G2_UNLOCK();
342 1.9 marcus }
343 1.9 marcus
344 1.9 marcus void
345 1.9 marcus g2bus_bus_mem_write_region_4(void *v, bus_space_handle_t sh, bus_size_t off,
346 1.10 tsutsui const uint32_t *addr, bus_size_t len)
347 1.9 marcus {
348 1.9 marcus G2LOCK_DECL;
349 1.12 perry volatile uint32_t *baddr = (uint32_t *)(sh + off);
350 1.9 marcus
351 1.9 marcus G2_LOCK();
352 1.9 marcus
353 1.9 marcus while (len--)
354 1.9 marcus *baddr++ = *addr++;
355 1.9 marcus
356 1.9 marcus G2_UNLOCK();
357 1.9 marcus }
358 1.9 marcus
359 1.9 marcus void
360 1.9 marcus g2bus_bus_mem_set_region_4(void *v, bus_space_handle_t sh, bus_size_t off,
361 1.10 tsutsui uint32_t val, bus_size_t len)
362 1.9 marcus {
363 1.9 marcus G2LOCK_DECL;
364 1.12 perry volatile uint32_t *baddr = (uint32_t *)(sh + off);
365 1.9 marcus
366 1.9 marcus G2_LOCK();
367 1.9 marcus
368 1.9 marcus while (len--)
369 1.9 marcus *baddr++ = val;
370 1.6 tsutsui
371 1.7 tsutsui G2_UNLOCK();
372 1.6 tsutsui }
373 1.6 tsutsui
374 1.6 tsutsui void
375 1.6 tsutsui g2bus_set_bus_mem_sparse(bus_space_tag_t memt)
376 1.6 tsutsui {
377 1.6 tsutsui
378 1.6 tsutsui memt->dbs_r_1 = g2bus_sparse_bus_mem_read_1;
379 1.6 tsutsui memt->dbs_r_2 = g2bus_sparse_bus_mem_read_2;
380 1.6 tsutsui memt->dbs_r_4 = g2bus_sparse_bus_mem_read_4;
381 1.6 tsutsui
382 1.6 tsutsui memt->dbs_w_1 = g2bus_sparse_bus_mem_write_1;
383 1.6 tsutsui memt->dbs_w_2 = g2bus_sparse_bus_mem_write_2;
384 1.6 tsutsui memt->dbs_w_4 = g2bus_sparse_bus_mem_write_4;
385 1.6 tsutsui
386 1.6 tsutsui memt->dbs_rr_1 = g2bus_sparse_bus_mem_read_region_1;
387 1.6 tsutsui
388 1.6 tsutsui memt->dbs_wr_1 = g2bus_sparse_bus_mem_write_region_1;
389 1.6 tsutsui
390 1.6 tsutsui memt->dbs_rm_1 = g2bus_sparse_bus_mem_read_multi_1;
391 1.6 tsutsui
392 1.6 tsutsui memt->dbs_wm_1 = g2bus_sparse_bus_mem_write_multi_1;
393 1.6 tsutsui }
394 1.6 tsutsui
395 1.10 tsutsui uint8_t
396 1.6 tsutsui g2bus_sparse_bus_mem_read_1(void *v, bus_space_handle_t sh, bus_size_t off)
397 1.6 tsutsui {
398 1.7 tsutsui G2LOCK_DECL;
399 1.10 tsutsui uint8_t rv;
400 1.6 tsutsui
401 1.7 tsutsui G2_LOCK();
402 1.6 tsutsui
403 1.12 perry rv = *(volatile uint8_t *)(sh + (off * 4));
404 1.6 tsutsui
405 1.7 tsutsui G2_UNLOCK();
406 1.6 tsutsui
407 1.10 tsutsui return rv;
408 1.6 tsutsui }
409 1.6 tsutsui
410 1.10 tsutsui uint16_t
411 1.6 tsutsui g2bus_sparse_bus_mem_read_2(void *v, bus_space_handle_t sh, bus_size_t off)
412 1.6 tsutsui {
413 1.7 tsutsui G2LOCK_DECL;
414 1.10 tsutsui uint16_t rv;
415 1.6 tsutsui
416 1.7 tsutsui G2_LOCK();
417 1.6 tsutsui
418 1.12 perry rv = *(volatile uint16_t *)(sh + (off * 4));
419 1.6 tsutsui
420 1.7 tsutsui G2_UNLOCK();
421 1.6 tsutsui
422 1.10 tsutsui return rv;
423 1.6 tsutsui }
424 1.6 tsutsui
425 1.10 tsutsui uint32_t
426 1.6 tsutsui g2bus_sparse_bus_mem_read_4(void *v, bus_space_handle_t sh, bus_size_t off)
427 1.6 tsutsui {
428 1.7 tsutsui G2LOCK_DECL;
429 1.10 tsutsui uint32_t rv;
430 1.6 tsutsui
431 1.7 tsutsui G2_LOCK();
432 1.6 tsutsui
433 1.12 perry rv = *(volatile uint32_t *)(sh + (off * 4));
434 1.6 tsutsui
435 1.7 tsutsui G2_UNLOCK();
436 1.6 tsutsui
437 1.10 tsutsui return rv;
438 1.6 tsutsui }
439 1.6 tsutsui
440 1.6 tsutsui void
441 1.6 tsutsui g2bus_sparse_bus_mem_write_1(void *v, bus_space_handle_t sh, bus_size_t off,
442 1.10 tsutsui uint8_t val)
443 1.6 tsutsui {
444 1.7 tsutsui G2LOCK_DECL;
445 1.6 tsutsui
446 1.7 tsutsui G2_LOCK();
447 1.6 tsutsui
448 1.12 perry *(volatile uint8_t *)(sh + (off * 4)) = val;
449 1.6 tsutsui
450 1.7 tsutsui G2_UNLOCK();
451 1.6 tsutsui }
452 1.6 tsutsui
453 1.6 tsutsui void
454 1.6 tsutsui g2bus_sparse_bus_mem_write_2(void *v, bus_space_handle_t sh, bus_size_t off,
455 1.10 tsutsui uint16_t val)
456 1.6 tsutsui {
457 1.7 tsutsui G2LOCK_DECL;
458 1.6 tsutsui
459 1.7 tsutsui G2_LOCK();
460 1.6 tsutsui
461 1.12 perry *(volatile uint16_t *)(sh + (off * 4)) = val;
462 1.6 tsutsui
463 1.7 tsutsui G2_UNLOCK();
464 1.6 tsutsui }
465 1.6 tsutsui
466 1.6 tsutsui void
467 1.6 tsutsui g2bus_sparse_bus_mem_write_4(void *v, bus_space_handle_t sh, bus_size_t off,
468 1.10 tsutsui uint32_t val)
469 1.6 tsutsui {
470 1.7 tsutsui G2LOCK_DECL;
471 1.6 tsutsui
472 1.7 tsutsui G2_LOCK();
473 1.6 tsutsui
474 1.12 perry *(volatile uint32_t *)(sh + (off * 4)) = val;
475 1.6 tsutsui
476 1.7 tsutsui G2_UNLOCK();
477 1.6 tsutsui }
478 1.6 tsutsui
479 1.6 tsutsui void
480 1.6 tsutsui g2bus_sparse_bus_mem_read_region_1(void *v, bus_space_handle_t sh,
481 1.10 tsutsui bus_size_t off, uint8_t *addr, bus_size_t len)
482 1.6 tsutsui {
483 1.7 tsutsui G2LOCK_DECL;
484 1.12 perry volatile const uint8_t *baddr = (uint8_t *)(sh + (off * 4));
485 1.6 tsutsui
486 1.7 tsutsui G2_LOCK();
487 1.6 tsutsui
488 1.6 tsutsui while (len--) {
489 1.6 tsutsui *addr++ = *baddr;
490 1.6 tsutsui baddr += 4;
491 1.6 tsutsui }
492 1.6 tsutsui
493 1.7 tsutsui G2_UNLOCK();
494 1.6 tsutsui }
495 1.6 tsutsui
496 1.6 tsutsui void
497 1.6 tsutsui g2bus_sparse_bus_mem_write_region_1(void *v, bus_space_handle_t sh,
498 1.10 tsutsui bus_size_t off, const uint8_t *addr, bus_size_t len)
499 1.6 tsutsui {
500 1.7 tsutsui G2LOCK_DECL;
501 1.12 perry volatile uint8_t *baddr = (uint8_t *)(sh + (off * 4));
502 1.6 tsutsui
503 1.7 tsutsui G2_LOCK();
504 1.6 tsutsui
505 1.6 tsutsui while (len--) {
506 1.6 tsutsui *baddr = *addr++;
507 1.6 tsutsui baddr += 4;
508 1.6 tsutsui }
509 1.6 tsutsui
510 1.7 tsutsui G2_UNLOCK();
511 1.6 tsutsui }
512 1.6 tsutsui
513 1.6 tsutsui void
514 1.6 tsutsui g2bus_sparse_bus_mem_read_multi_1(void *v, bus_space_handle_t sh,
515 1.10 tsutsui bus_size_t off, uint8_t *addr, bus_size_t len)
516 1.6 tsutsui {
517 1.7 tsutsui G2LOCK_DECL;
518 1.12 perry volatile const uint8_t *baddr = (uint8_t *)(sh + (off * 4));
519 1.6 tsutsui
520 1.7 tsutsui G2_LOCK();
521 1.6 tsutsui
522 1.6 tsutsui while (len--)
523 1.6 tsutsui *addr++ = *baddr;
524 1.6 tsutsui
525 1.7 tsutsui G2_UNLOCK();
526 1.6 tsutsui }
527 1.6 tsutsui
528 1.6 tsutsui void
529 1.6 tsutsui g2bus_sparse_bus_mem_write_multi_1(void *v, bus_space_handle_t sh,
530 1.10 tsutsui bus_size_t off, const uint8_t *addr, bus_size_t len)
531 1.6 tsutsui {
532 1.7 tsutsui G2LOCK_DECL;
533 1.12 perry volatile uint8_t *baddr = (uint8_t *)(sh + (off * 4));
534 1.6 tsutsui
535 1.7 tsutsui G2_LOCK();
536 1.6 tsutsui
537 1.6 tsutsui while (len--)
538 1.6 tsutsui *baddr = *addr++;
539 1.2 marcus
540 1.7 tsutsui G2_UNLOCK();
541 1.1 thorpej }
542