1 /* $NetBSD: obio_space.c,v 1.6 2003/07/15 00:25:05 lukem Exp $ */
4 * SPDX-License-Identifier: BSD-4-Clause
6 * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
9 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed for the NetBSD Project by
22 * Wasabi Systems, Inc.
23 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
24 * or promote products derived from this software without specific prior
27 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
41 * bus_space functions for PXA devices
44 #include <sys/cdefs.h>
45 __FBSDID("$FreeBSD$");
47 #include <sys/param.h>
48 #include <sys/systm.h>
50 #include <sys/kernel.h>
51 #include <sys/malloc.h>
53 #include <machine/bus.h>
55 #include <arm/xscale/pxa/pxareg.h>
56 #include <arm/xscale/pxa/pxavar.h>
58 static MALLOC_DEFINE(M_PXATAG, "PXA bus_space tags", "Bus_space tags for PXA");
60 /* Prototypes for all the bus_space structure functions */
65 * The obio bus space tag. This is constant for all instances, so
66 * we never have to explicitly "create" it.
68 struct bus_space _base_tag = {
72 /* mapping/unmapping */
73 .bs_map = generic_bs_map,
74 .bs_unmap = generic_bs_unmap,
75 .bs_subregion = generic_bs_subregion,
77 /* allocation/deallocation */
78 .bs_alloc = generic_bs_alloc,
79 .bs_free = generic_bs_free,
82 .bs_barrier = generic_bs_barrier,
88 .bs_r_8 = BS_UNIMPLEMENTED,
91 .bs_rm_1 = pxa_bs_rm_1,
92 .bs_rm_2 = pxa_bs_rm_2,
93 .bs_rm_4 = BS_UNIMPLEMENTED,
94 .bs_rm_8 = BS_UNIMPLEMENTED,
97 .bs_rr_1 = pxa_bs_rr_1,
98 .bs_rr_2 = BS_UNIMPLEMENTED,
99 .bs_rr_4 = BS_UNIMPLEMENTED,
100 .bs_rr_8 = BS_UNIMPLEMENTED,
103 .bs_w_1 = pxa_bs_w_1,
104 .bs_w_2 = pxa_bs_w_2,
105 .bs_w_4 = pxa_bs_w_4,
106 .bs_w_8 = BS_UNIMPLEMENTED,
109 .bs_wm_1 = pxa_bs_wm_1,
110 .bs_wm_2 = pxa_bs_wm_2,
111 .bs_wm_4 = BS_UNIMPLEMENTED,
112 .bs_wm_8 = BS_UNIMPLEMENTED,
115 .bs_wr_1 = BS_UNIMPLEMENTED,
116 .bs_wr_2 = BS_UNIMPLEMENTED,
117 .bs_wr_4 = BS_UNIMPLEMENTED,
118 .bs_wr_8 = BS_UNIMPLEMENTED,
121 .bs_sm_1 = BS_UNIMPLEMENTED,
122 .bs_sm_2 = BS_UNIMPLEMENTED,
123 .bs_sm_4 = BS_UNIMPLEMENTED,
124 .bs_sm_8 = BS_UNIMPLEMENTED,
127 .bs_sr_1 = BS_UNIMPLEMENTED,
128 .bs_sr_2 = BS_UNIMPLEMENTED,
129 .bs_sr_4 = BS_UNIMPLEMENTED,
130 .bs_sr_8 = BS_UNIMPLEMENTED,
133 .bs_c_1 = BS_UNIMPLEMENTED,
134 .bs_c_2 = BS_UNIMPLEMENTED,
135 .bs_c_4 = BS_UNIMPLEMENTED,
136 .bs_c_8 = BS_UNIMPLEMENTED,
138 /* read stream (single) */
139 .bs_r_1_s = BS_UNIMPLEMENTED,
140 .bs_r_2_s = BS_UNIMPLEMENTED,
141 .bs_r_4_s = BS_UNIMPLEMENTED,
142 .bs_r_8_s = BS_UNIMPLEMENTED,
144 /* read multiple stream */
145 .bs_rm_1_s = BS_UNIMPLEMENTED,
146 .bs_rm_2_s = BS_UNIMPLEMENTED,
147 .bs_rm_4_s = BS_UNIMPLEMENTED,
148 .bs_rm_8_s = BS_UNIMPLEMENTED,
150 /* read region stream */
151 .bs_rr_1_s = BS_UNIMPLEMENTED,
152 .bs_rr_2_s = BS_UNIMPLEMENTED,
153 .bs_rr_4_s = BS_UNIMPLEMENTED,
154 .bs_rr_8_s = BS_UNIMPLEMENTED,
156 /* write stream (single) */
157 .bs_w_1_s = BS_UNIMPLEMENTED,
158 .bs_w_2_s = BS_UNIMPLEMENTED,
159 .bs_w_4_s = BS_UNIMPLEMENTED,
160 .bs_w_8_s = BS_UNIMPLEMENTED,
162 /* write multiple stream */
163 .bs_wm_1_s = BS_UNIMPLEMENTED,
164 .bs_wm_2_s = BS_UNIMPLEMENTED,
165 .bs_wm_4_s = BS_UNIMPLEMENTED,
166 .bs_wm_8_s = BS_UNIMPLEMENTED,
168 /* write region stream */
169 .bs_wr_1_s = BS_UNIMPLEMENTED,
170 .bs_wr_2_s = BS_UNIMPLEMENTED,
171 .bs_wr_4_s = BS_UNIMPLEMENTED,
172 .bs_wr_8_s = BS_UNIMPLEMENTED,
175 static struct bus_space _obio_tag;
177 bus_space_tag_t base_tag = &_base_tag;
178 bus_space_tag_t obio_tag = NULL;
181 pxa_obio_tag_init(void)
184 bcopy(&_base_tag, &_obio_tag, sizeof(struct bus_space));
185 _obio_tag.bs_privdata = (void *)PXA2X0_PERIPH_OFFSET;
186 obio_tag = &_obio_tag;
190 pxa_bus_tag_alloc(bus_addr_t offset)
192 struct bus_space *tag;
194 tag = (struct bus_space *)malloc(sizeof(struct bus_space), M_PXATAG,
197 bcopy(&_base_tag, tag, sizeof(struct bus_space));
198 tag->bs_privdata = (void *)offset;
200 return ((bus_space_tag_t)tag);
204 #define READ_SINGLE(type, proto, base) \
206 proto(bus_space_tag_t tag, bus_space_handle_t bsh, bus_size_t offset) \
208 bus_addr_t tag_offset; \
210 tag_offset = (bus_addr_t)tag->bs_privdata; \
211 value = base(NULL, bsh + tag_offset, offset); \
215 READ_SINGLE(u_int8_t, pxa_bs_r_1, generic_bs_r_1)
216 READ_SINGLE(u_int16_t, pxa_bs_r_2, generic_bs_r_2)
217 READ_SINGLE(u_int32_t, pxa_bs_r_4, generic_bs_r_4)
221 #define WRITE_SINGLE(type, proto, base) \
223 proto(bus_space_tag_t tag, bus_space_handle_t bsh, bus_size_t offset, \
226 bus_addr_t tag_offset; \
227 tag_offset = (bus_addr_t)tag->bs_privdata; \
228 base(NULL, bsh + tag_offset, offset, value); \
231 WRITE_SINGLE(u_int8_t, pxa_bs_w_1, generic_bs_w_1)
232 WRITE_SINGLE(u_int16_t, pxa_bs_w_2, generic_bs_w_2)
233 WRITE_SINGLE(u_int32_t, pxa_bs_w_4, generic_bs_w_4)
237 #define READ_MULTI(type, proto, base) \
239 proto(bus_space_tag_t tag, bus_space_handle_t bsh, bus_size_t offset, \
240 type *dest, bus_size_t count) \
242 bus_addr_t tag_offset; \
243 tag_offset = (bus_addr_t)tag->bs_privdata; \
244 base(NULL, bsh + tag_offset, offset, dest, count); \
247 READ_MULTI(u_int8_t, pxa_bs_rm_1, generic_bs_rm_1)
248 READ_MULTI(u_int16_t, pxa_bs_rm_2, generic_bs_rm_2)
250 READ_MULTI(u_int8_t, pxa_bs_rr_1, generic_bs_rr_1)
254 #define WRITE_MULTI(type, proto, base) \
256 proto(bus_space_tag_t tag, bus_space_handle_t bsh, bus_size_t offset, \
257 const type *src, bus_size_t count) \
259 bus_addr_t tag_offset; \
260 tag_offset = (bus_addr_t)tag->bs_privdata; \
261 base(NULL, bsh + tag_offset, offset, src, count); \
264 WRITE_MULTI(u_int8_t, pxa_bs_wm_1, generic_bs_wm_1)
265 WRITE_MULTI(u_int16_t, pxa_bs_wm_2, generic_bs_wm_2)