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