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