mainbus_io.c revision 1.23 1 1.23 matt /* $NetBSD: mainbus_io.c,v 1.23 2014/02/22 20:33:00 matt Exp $ */
2 1.1 reinoud
3 1.1 reinoud /*
4 1.1 reinoud * Copyright (c) 1997 Mark Brinicombe.
5 1.1 reinoud * All rights reserved.
6 1.1 reinoud *
7 1.1 reinoud * Redistribution and use in source and binary forms, with or without
8 1.1 reinoud * modification, are permitted provided that the following conditions
9 1.1 reinoud * are met:
10 1.1 reinoud * 1. Redistributions of source code must retain the above copyright
11 1.1 reinoud * notice, this list of conditions and the following disclaimer.
12 1.1 reinoud * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 reinoud * notice, this list of conditions and the following disclaimer in the
14 1.1 reinoud * documentation and/or other materials provided with the distribution.
15 1.1 reinoud * 3. All advertising materials mentioning features or use of this software
16 1.1 reinoud * must display the following acknowledgement:
17 1.1 reinoud * This product includes software developed by Mark Brinicombe.
18 1.1 reinoud * 4. The name of the company nor the name of the author may be used to
19 1.1 reinoud * endorse or promote products derived from this software without specific
20 1.1 reinoud * prior written permission.
21 1.1 reinoud *
22 1.1 reinoud * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
23 1.1 reinoud * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 1.1 reinoud * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 reinoud * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
26 1.1 reinoud * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 1.1 reinoud * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 1.1 reinoud * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.1 reinoud * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.1 reinoud * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.1 reinoud * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.1 reinoud * SUCH DAMAGE.
33 1.1 reinoud */
34 1.1 reinoud
35 1.1 reinoud /*
36 1.1 reinoud * bus_space I/O functions for mainbus
37 1.1 reinoud */
38 1.13 lukem
39 1.13 lukem #include <sys/cdefs.h>
40 1.23 matt __KERNEL_RCSID(0, "$NetBSD: mainbus_io.c,v 1.23 2014/02/22 20:33:00 matt Exp $");
41 1.1 reinoud
42 1.1 reinoud #include <sys/param.h>
43 1.1 reinoud #include <sys/systm.h>
44 1.1 reinoud #include <sys/queue.h>
45 1.1 reinoud
46 1.1 reinoud #include <uvm/uvm.h>
47 1.1 reinoud
48 1.21 dyoung #include <sys/bus.h>
49 1.1 reinoud #include <machine/pmap.h>
50 1.1 reinoud
51 1.1 reinoud /* Proto types for all the bus_space structure functions */
52 1.1 reinoud
53 1.1 reinoud bs_protos(mainbus);
54 1.1 reinoud bs_protos(bs_notimpl);
55 1.1 reinoud
56 1.1 reinoud /* Declare the mainbus bus space tag */
57 1.1 reinoud
58 1.1 reinoud struct bus_space mainbus_bs_tag = {
59 1.1 reinoud /* cookie */
60 1.1 reinoud NULL,
61 1.1 reinoud
62 1.1 reinoud /* mapping/unmapping */
63 1.1 reinoud mainbus_bs_map,
64 1.1 reinoud mainbus_bs_unmap,
65 1.1 reinoud mainbus_bs_subregion,
66 1.1 reinoud
67 1.1 reinoud /* allocation/deallocation */
68 1.1 reinoud mainbus_bs_alloc,
69 1.1 reinoud mainbus_bs_free,
70 1.1 reinoud
71 1.1 reinoud /* get kernel virtual address */
72 1.1 reinoud 0, /* there is no linear mapping */
73 1.1 reinoud
74 1.4 reinoud /* Mmap bus space for user */
75 1.4 reinoud mainbus_bs_mmap,
76 1.4 reinoud
77 1.1 reinoud /* barrier */
78 1.1 reinoud mainbus_bs_barrier,
79 1.1 reinoud
80 1.1 reinoud /* read (single) */
81 1.1 reinoud mainbus_bs_r_1,
82 1.1 reinoud mainbus_bs_r_2,
83 1.1 reinoud mainbus_bs_r_4,
84 1.1 reinoud bs_notimpl_bs_r_8,
85 1.1 reinoud
86 1.1 reinoud /* read multiple */
87 1.1 reinoud bs_notimpl_bs_rm_1,
88 1.1 reinoud mainbus_bs_rm_2,
89 1.1 reinoud bs_notimpl_bs_rm_4,
90 1.1 reinoud bs_notimpl_bs_rm_8,
91 1.1 reinoud
92 1.1 reinoud /* read region */
93 1.1 reinoud bs_notimpl_bs_rr_1,
94 1.1 reinoud bs_notimpl_bs_rr_2,
95 1.1 reinoud bs_notimpl_bs_rr_4,
96 1.1 reinoud bs_notimpl_bs_rr_8,
97 1.1 reinoud
98 1.1 reinoud /* write (single) */
99 1.1 reinoud mainbus_bs_w_1,
100 1.1 reinoud mainbus_bs_w_2,
101 1.1 reinoud mainbus_bs_w_4,
102 1.1 reinoud bs_notimpl_bs_w_8,
103 1.1 reinoud
104 1.1 reinoud /* write multiple */
105 1.1 reinoud mainbus_bs_wm_1,
106 1.1 reinoud mainbus_bs_wm_2,
107 1.1 reinoud bs_notimpl_bs_wm_4,
108 1.1 reinoud bs_notimpl_bs_wm_8,
109 1.1 reinoud
110 1.1 reinoud /* write region */
111 1.1 reinoud bs_notimpl_bs_wr_1,
112 1.1 reinoud bs_notimpl_bs_wr_2,
113 1.1 reinoud bs_notimpl_bs_wr_4,
114 1.1 reinoud bs_notimpl_bs_wr_8,
115 1.1 reinoud
116 1.1 reinoud bs_notimpl_bs_sm_1,
117 1.1 reinoud bs_notimpl_bs_sm_2,
118 1.1 reinoud bs_notimpl_bs_sm_4,
119 1.1 reinoud bs_notimpl_bs_sm_8,
120 1.1 reinoud
121 1.1 reinoud /* set region */
122 1.1 reinoud bs_notimpl_bs_sr_1,
123 1.1 reinoud bs_notimpl_bs_sr_2,
124 1.1 reinoud bs_notimpl_bs_sr_4,
125 1.1 reinoud bs_notimpl_bs_sr_8,
126 1.1 reinoud
127 1.1 reinoud /* copy */
128 1.1 reinoud bs_notimpl_bs_c_1,
129 1.1 reinoud bs_notimpl_bs_c_2,
130 1.1 reinoud bs_notimpl_bs_c_4,
131 1.1 reinoud bs_notimpl_bs_c_8,
132 1.22 matt
133 1.22 matt #ifdef __BUS_SPACE_HAS_STREAM_METHODS
134 1.22 matt /* stream methods */
135 1.22 matt /* read (single) */
136 1.22 matt mainbus_bs_r_1,
137 1.22 matt mainbus_bs_r_2,
138 1.22 matt mainbus_bs_r_4,
139 1.22 matt bs_notimpl_bs_r_8,
140 1.22 matt
141 1.22 matt /* read multiple */
142 1.22 matt bs_notimpl_bs_rm_1,
143 1.22 matt mainbus_bs_rm_2,
144 1.22 matt bs_notimpl_bs_rm_4,
145 1.22 matt bs_notimpl_bs_rm_8,
146 1.22 matt
147 1.22 matt /* read region */
148 1.22 matt bs_notimpl_bs_rr_1,
149 1.22 matt bs_notimpl_bs_rr_2,
150 1.22 matt bs_notimpl_bs_rr_4,
151 1.22 matt bs_notimpl_bs_rr_8,
152 1.22 matt
153 1.22 matt /* write (single) */
154 1.22 matt mainbus_bs_w_1,
155 1.22 matt mainbus_bs_w_2,
156 1.22 matt mainbus_bs_w_4,
157 1.22 matt bs_notimpl_bs_w_8,
158 1.22 matt
159 1.22 matt /* write multiple */
160 1.22 matt mainbus_bs_wm_1,
161 1.22 matt mainbus_bs_wm_2,
162 1.22 matt bs_notimpl_bs_wm_4,
163 1.22 matt bs_notimpl_bs_wm_8,
164 1.22 matt
165 1.22 matt /* write region */
166 1.22 matt bs_notimpl_bs_wr_1,
167 1.22 matt bs_notimpl_bs_wr_2,
168 1.22 matt bs_notimpl_bs_wr_4,
169 1.22 matt bs_notimpl_bs_wr_8,
170 1.22 matt #endif
171 1.1 reinoud };
172 1.1 reinoud
173 1.1 reinoud /* bus space functions */
174 1.1 reinoud
175 1.1 reinoud int
176 1.18 dsl mainbus_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags, bus_space_handle_t *bshp)
177 1.1 reinoud {
178 1.1 reinoud u_long startpa, endpa, pa;
179 1.1 reinoud vaddr_t va;
180 1.1 reinoud
181 1.7 thorpej if ((u_long)bpa > (u_long)KERNEL_BASE) {
182 1.1 reinoud /* XXX This is a temporary hack to aid transition. */
183 1.1 reinoud *bshp = bpa;
184 1.1 reinoud return(0);
185 1.1 reinoud }
186 1.1 reinoud
187 1.1 reinoud startpa = trunc_page(bpa);
188 1.1 reinoud endpa = round_page(bpa + size);
189 1.1 reinoud
190 1.1 reinoud /* XXX use extent manager to check duplicate mapping */
191 1.1 reinoud
192 1.17 yamt va = uvm_km_alloc(kernel_map, endpa - startpa, 0,
193 1.17 yamt UVM_KMF_VAONLY | UVM_KMF_NOWAIT);
194 1.1 reinoud if (! va)
195 1.1 reinoud return(ENOMEM);
196 1.1 reinoud
197 1.1 reinoud *bshp = (bus_space_handle_t)(va + (bpa - startpa));
198 1.1 reinoud
199 1.23 matt const int pmapflags =
200 1.23 matt (flags & (BUS_SPACE_MAP_CACHEABLE|BUS_SPACE_MAP_PREFETCHABLE))
201 1.23 matt ? 0
202 1.23 matt : PMAP_NOCACHE;
203 1.23 matt for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
204 1.23 matt pmap_kenter_pa(va, pa, VM_PROT_READ|VM_PROT_WRITE, pmapflags);
205 1.1 reinoud }
206 1.5 chris pmap_update(pmap_kernel());
207 1.2 thorpej
208 1.1 reinoud return(0);
209 1.1 reinoud }
210 1.1 reinoud
211 1.1 reinoud int
212 1.19 cegger mainbus_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend,
213 1.19 cegger bus_size_t size, bus_size_t alignment, bus_size_t boundary,
214 1.19 cegger int cacheable,
215 1.19 cegger bus_addr_t *bpap, bus_space_handle_t *bshp)
216 1.1 reinoud {
217 1.12 provos panic("mainbus_bs_alloc(): Help!");
218 1.1 reinoud }
219 1.1 reinoud
220 1.1 reinoud
221 1.1 reinoud void
222 1.18 dsl mainbus_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
223 1.1 reinoud {
224 1.1 reinoud /*
225 1.1 reinoud * Temporary implementation
226 1.1 reinoud */
227 1.1 reinoud }
228 1.1 reinoud
229 1.1 reinoud void
230 1.18 dsl mainbus_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
231 1.1 reinoud {
232 1.1 reinoud
233 1.12 provos panic("mainbus_bs_free(): Help!");
234 1.1 reinoud /* mainbus_bs_unmap() does all that we need to do. */
235 1.1 reinoud /* mainbus_bs_unmap(t, bsh, size);*/
236 1.1 reinoud }
237 1.1 reinoud
238 1.1 reinoud int
239 1.18 dsl mainbus_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp)
240 1.1 reinoud {
241 1.1 reinoud
242 1.14 bjh21 *nbshp = bsh + (offset << 2);
243 1.1 reinoud return (0);
244 1.4 reinoud }
245 1.4 reinoud
246 1.4 reinoud paddr_t
247 1.18 dsl mainbus_bs_mmap(void *t, bus_addr_t paddr, off_t offset, int prot, int flags)
248 1.4 reinoud {
249 1.4 reinoud /*
250 1.4 reinoud * mmap from address `paddr+offset' for one page
251 1.4 reinoud */
252 1.8 thorpej return (arm_btop((paddr + offset)));
253 1.1 reinoud }
254 1.1 reinoud
255 1.1 reinoud void
256 1.18 dsl mainbus_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t len, int flags)
257 1.1 reinoud {
258 1.1 reinoud }
259 1.1 reinoud
260 1.1 reinoud /* End of mainbus_io.c */
261