]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/arm/xscale/pxa/pxa_space.c
Import Intel Processor Trace decoder library from
[FreeBSD/FreeBSD.git] / sys / arm / xscale / pxa / pxa_space.c
1 /*      $NetBSD: obio_space.c,v 1.6 2003/07/15 00:25:05 lukem Exp $     */
2
3 /*-
4  * SPDX-License-Identifier: BSD-4-Clause
5  *
6  * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
7  * All rights reserved.
8  *
9  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
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
25  *    written permission.
26  *
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.
38  */
39
40 /*
41  * bus_space functions for PXA devices
42  */
43
44 #include <sys/cdefs.h>
45 __FBSDID("$FreeBSD$");
46
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/bus.h>
50 #include <sys/kernel.h>
51 #include <sys/malloc.h>
52
53 #include <machine/bus.h>
54
55 #include <arm/xscale/pxa/pxareg.h>
56 #include <arm/xscale/pxa/pxavar.h>
57
58 static MALLOC_DEFINE(M_PXATAG, "PXA bus_space tags", "Bus_space tags for PXA");
59
60 /* Prototypes for all the bus_space structure functions */
61 bs_protos(generic);
62 bs_protos(pxa);
63
64 /*
65  * The obio bus space tag.  This is constant for all instances, so
66  * we never have to explicitly "create" it.
67  */
68 struct bus_space _base_tag = {
69         /* cookie */
70         .bs_privdata    = NULL,
71
72         /* mapping/unmapping */
73         .bs_map         = generic_bs_map,
74         .bs_unmap       = generic_bs_unmap,
75         .bs_subregion   = generic_bs_subregion,
76
77         /* allocation/deallocation */
78         .bs_alloc       = generic_bs_alloc,
79         .bs_free        = generic_bs_free,
80
81         /* barrier */
82         .bs_barrier     = generic_bs_barrier,
83
84         /* read (single) */
85         .bs_r_1         = pxa_bs_r_1,
86         .bs_r_2         = pxa_bs_r_2,
87         .bs_r_4         = pxa_bs_r_4,
88         .bs_r_8         = BS_UNIMPLEMENTED,
89
90         /* read multiple */
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,
95
96         /* read region */
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,
101
102         /* write (single) */
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,
107
108         /* write multiple */
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,
113
114         /* write region */
115         .bs_wr_1        = BS_UNIMPLEMENTED,
116         .bs_wr_2        = BS_UNIMPLEMENTED,
117         .bs_wr_4        = BS_UNIMPLEMENTED,
118         .bs_wr_8        = BS_UNIMPLEMENTED,
119
120         /* set multiple */
121         .bs_sm_1        = BS_UNIMPLEMENTED,
122         .bs_sm_2        = BS_UNIMPLEMENTED,
123         .bs_sm_4        = BS_UNIMPLEMENTED,
124         .bs_sm_8        = BS_UNIMPLEMENTED,
125
126         /* set region */
127         .bs_sr_1        = BS_UNIMPLEMENTED,
128         .bs_sr_2        = BS_UNIMPLEMENTED,
129         .bs_sr_4        = BS_UNIMPLEMENTED,
130         .bs_sr_8        = BS_UNIMPLEMENTED,
131
132         /* copy */
133         .bs_c_1         = BS_UNIMPLEMENTED,
134         .bs_c_2         = BS_UNIMPLEMENTED,
135         .bs_c_4         = BS_UNIMPLEMENTED,
136         .bs_c_8         = BS_UNIMPLEMENTED,
137
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,
143
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,
149
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,
155
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, 
161
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,
167
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,
173 };
174
175 static struct bus_space _obio_tag;
176
177 bus_space_tag_t         base_tag = &_base_tag;
178 bus_space_tag_t         obio_tag = NULL;
179
180 void
181 pxa_obio_tag_init(void)
182 {
183
184         bcopy(&_base_tag, &_obio_tag, sizeof(struct bus_space));
185         _obio_tag.bs_privdata = (void *)PXA2X0_PERIPH_OFFSET;
186         obio_tag = &_obio_tag;
187 }
188
189 bus_space_tag_t
190 pxa_bus_tag_alloc(bus_addr_t offset)
191 {
192         struct  bus_space *tag;
193
194         tag = (struct bus_space *)malloc(sizeof(struct bus_space), M_PXATAG,
195             M_WAITOK);
196
197         bcopy(&_base_tag, tag, sizeof(struct bus_space));
198         tag->bs_privdata = (void *)offset;
199
200         return ((bus_space_tag_t)tag);
201 }
202
203
204 #define READ_SINGLE(type, proto, base)                                  \
205         type                                                            \
206         proto(bus_space_tag_t tag, bus_space_handle_t bsh, bus_size_t offset)   \
207         {                                                               \
208                 bus_addr_t      tag_offset;                             \
209                 type            value;                                  \
210                 tag_offset = (bus_addr_t)tag->bs_privdata;              \
211                 value = base(NULL, bsh + tag_offset, offset);           \
212                 return (value);                                         \
213         }
214
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)
218
219 #undef READ_SINGLE
220
221 #define WRITE_SINGLE(type, proto, base)                                 \
222         void                                                            \
223         proto(bus_space_tag_t tag, bus_space_handle_t bsh, bus_size_t offset,   \
224             type value)                                                 \
225         {                                                               \
226                 bus_addr_t      tag_offset;                             \
227                 tag_offset = (bus_addr_t)tag->bs_privdata;              \
228                 base(NULL, bsh + tag_offset, offset, value);            \
229         }
230
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)
234
235 #undef WRITE_SINGLE
236
237 #define READ_MULTI(type, proto, base)                                   \
238         void                                                            \
239         proto(bus_space_tag_t tag, bus_space_handle_t bsh, bus_size_t offset,   \
240             type *dest, bus_size_t count)                               \
241         {                                                               \
242                 bus_addr_t      tag_offset;                             \
243                 tag_offset = (bus_addr_t)tag->bs_privdata;              \
244                 base(NULL, bsh + tag_offset, offset, dest, count);      \
245         }
246
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)
249
250 READ_MULTI(u_int8_t,  pxa_bs_rr_1, generic_bs_rr_1)
251
252 #undef READ_MULTI
253
254 #define WRITE_MULTI(type, proto, base)                                  \
255         void                                                            \
256         proto(bus_space_tag_t tag, bus_space_handle_t bsh, bus_size_t offset,   \
257             const type *src, bus_size_t count)                          \
258         {                                                               \
259                 bus_addr_t      tag_offset;                             \
260                 tag_offset = (bus_addr_t)tag->bs_privdata;              \
261                 base(NULL, bsh + tag_offset, offset, src, count);       \
262         }
263
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)
266
267 #undef WRITE_MULTI