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