at91_bus_space.c revision 1.2 1 /* $NetBSD: at91_bus_space.c,v 1.2 2008/07/03 01:15:38 matt Exp $ */
2
3 /*
4 * Based on ep93xx_space.c
5 * Copyright (c) 2007 Embedtronics Oy
6 * All rights reserved.
7 *
8 * Copyright (c) 2004 Jesse Off
9 * All rights reserved.
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 by Ichiro FUKUHARA.
22 * 4. The name of the company nor the name of the author may be used to
23 * endorse or promote products derived from this software without specific
24 * prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR
27 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR
30 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: at91_bus_space.c,v 1.2 2008/07/03 01:15:38 matt Exp $");
41
42 /*
43 * bus_space I/O functions for ep93xx
44 */
45
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/queue.h>
49
50 #include <uvm/uvm.h>
51
52 #include <machine/bus.h>
53
54 #include <arm/at91/at91var.h>
55 //#include <arm/ep93xx/ep93xxreg.h>
56 //#include <arm/ep93xx/ep93xxvar.h>
57
58 /* Proto types for all the bus_space structure functions */
59 bs_protos(at91);
60 bs_protos(generic);
61 bs_protos(generic_armv4);
62 bs_protos(bs_notimpl);
63
64 struct bus_space at91_bs_tag = {
65 /* cookie */
66 (void *) 0,
67
68 /* mapping/unmapping */
69 at91_bs_map,
70 at91_bs_unmap,
71 at91_bs_subregion,
72
73 /* allocation/deallocation */
74 at91_bs_alloc,
75 at91_bs_free,
76
77 /* get kernel virtual address */
78 at91_bs_vaddr,
79
80 /* mmap bus space for userland */
81 at91_bs_mmap,
82
83 /* barrier */
84 at91_bs_barrier,
85
86 /* read (single) */
87 generic_bs_r_1,
88 generic_armv4_bs_r_2,
89 generic_bs_r_4,
90 bs_notimpl_bs_r_8,
91
92 /* read multiple */
93 generic_bs_rm_1,
94 generic_armv4_bs_rm_2,
95 generic_bs_rm_4,
96 bs_notimpl_bs_rm_8,
97
98 /* read region */
99 generic_bs_rr_1,
100 generic_armv4_bs_rr_2,
101 generic_bs_rr_4,
102 bs_notimpl_bs_rr_8,
103
104 /* write (single) */
105 generic_bs_w_1,
106 generic_armv4_bs_w_2,
107 generic_bs_w_4,
108 bs_notimpl_bs_w_8,
109
110 /* write multiple */
111 generic_bs_wm_1,
112 generic_armv4_bs_wm_2,
113 generic_bs_wm_4,
114 bs_notimpl_bs_wm_8,
115
116 /* write region */
117 generic_bs_wr_1,
118 generic_armv4_bs_wr_2,
119 generic_bs_wr_4,
120 bs_notimpl_bs_wr_8,
121
122 /* set multiple */
123 bs_notimpl_bs_sm_1,
124 bs_notimpl_bs_sm_2,
125 bs_notimpl_bs_sm_4,
126 bs_notimpl_bs_sm_8,
127
128 /* set region */
129 bs_notimpl_bs_sr_1,
130 generic_armv4_bs_sr_2,
131 generic_bs_sr_4,
132 bs_notimpl_bs_sr_8,
133
134 /* copy */
135 bs_notimpl_bs_c_1,
136 generic_armv4_bs_c_2,
137 bs_notimpl_bs_c_4,
138 bs_notimpl_bs_c_8,
139 };
140
141 int
142 at91_bs_map(void *t, bus_addr_t bpa, bus_size_t size,
143 int cacheable, bus_space_handle_t *bshp)
144 {
145 const struct pmap_devmap *pd;
146
147 paddr_t startpa;
148 paddr_t endpa;
149 paddr_t pa;
150 paddr_t offset;
151 vaddr_t va;
152
153 if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) {
154 /* Device was statically mapped. */
155 *bshp = pd->pd_va + (bpa - pd->pd_pa);
156 return 0;
157 }
158
159 endpa = round_page(bpa + size);
160 offset = bpa & PAGE_MASK;
161 startpa = trunc_page(bpa);
162
163 /* Get some VM. */
164 va = uvm_km_alloc(kernel_map, endpa - startpa, 0,
165 UVM_KMF_VAONLY | UVM_KMF_NOWAIT);
166 if (va == 0)
167 return ENOMEM;
168
169 /* Store the bus space handle */
170 *bshp = va + offset;
171
172 /* Now map the pages */
173 for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
174 pmap_enter(pmap_kernel(), va, pa,
175 VM_PROT_READ | VM_PROT_WRITE,
176 VM_PROT_READ | VM_PROT_WRITE | PMAP_WIRED);
177 }
178 pmap_update(pmap_kernel());
179
180 return(0);
181 }
182
183 void
184 at91_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
185 {
186 vaddr_t va;
187 vaddr_t endva;
188
189 if (pmap_devmap_find_va(bsh, size) != NULL) {
190 /* Device was statically mapped; nothing to do. */
191 return;
192 }
193
194 endva = round_page(bsh + size);
195 va = trunc_page(bsh);
196
197 pmap_remove(pmap_kernel(), va, endva);
198 pmap_update(pmap_kernel());
199 uvm_km_free(kernel_map, va, endva - va, UVM_KMF_VAONLY);
200 }
201
202 int
203 at91_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend,
204 bus_size_t size, bus_size_t alignment, bus_size_t boundary, int cacheable,
205 bus_addr_t *bpap, bus_space_handle_t *bshp)
206 {
207 panic("at91_bs_alloc(): not implemented\n");
208 }
209
210 void
211 at91_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
212 {
213 panic("at91_bs_free(): not implemented\n");
214 }
215
216 int
217 at91_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset,
218 bus_size_t size, bus_space_handle_t *nbshp)
219 {
220 *nbshp = bsh + offset;
221 return (0);
222 }
223
224 void *
225 at91_bs_vaddr(void *t, bus_space_handle_t bsh)
226 {
227 return ((void *)bsh);
228 }
229
230 paddr_t
231 at91_bs_mmap(void *t, bus_addr_t addr, off_t off, int prot, int flags)
232 {
233 /* Not supported. */
234 return (-1);
235 }
236
237 void
238 at91_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset,
239 bus_size_t len, int flags)
240 {
241 /* NULL */
242 }
243 /* End of at91_io.c */
244