sa11x0_io.c revision 1.4.4.4 1 1.4.4.4 nathanw /* $NetBSD: sa11x0_io.c,v 1.4.4.4 2002/06/20 03:38:14 nathanw Exp $ */
2 1.4.4.2 nathanw
3 1.4.4.2 nathanw /*
4 1.4.4.2 nathanw * Copyright (c) 1997 Mark Brinicombe.
5 1.4.4.2 nathanw * Copyright (c) 1997 Causality Limited.
6 1.4.4.2 nathanw * All rights reserved.
7 1.4.4.2 nathanw *
8 1.4.4.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
9 1.4.4.2 nathanw * by Ichiro FUKUHARA.
10 1.4.4.2 nathanw *
11 1.4.4.2 nathanw * Redistribution and use in source and binary forms, with or without
12 1.4.4.2 nathanw * modification, are permitted provided that the following conditions
13 1.4.4.2 nathanw * are met:
14 1.4.4.2 nathanw * 1. Redistributions of source code must retain the above copyright
15 1.4.4.2 nathanw * notice, this list of conditions and the following disclaimer.
16 1.4.4.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
17 1.4.4.2 nathanw * notice, this list of conditions and the following disclaimer in the
18 1.4.4.2 nathanw * documentation and/or other materials provided with the distribution.
19 1.4.4.2 nathanw * 3. All advertising materials mentioning features or use of this software
20 1.4.4.2 nathanw * must display the following acknowledgement:
21 1.4.4.2 nathanw * This product includes software developed by Mark Brinicombe.
22 1.4.4.2 nathanw * 4. The name of the company nor the name of the author may be used to
23 1.4.4.2 nathanw * endorse or promote products derived from this software without specific
24 1.4.4.2 nathanw * prior written permission.
25 1.4.4.2 nathanw *
26 1.4.4.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
27 1.4.4.2 nathanw * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28 1.4.4.2 nathanw * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 1.4.4.2 nathanw * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30 1.4.4.2 nathanw * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31 1.4.4.2 nathanw * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 1.4.4.2 nathanw * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 1.4.4.2 nathanw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 1.4.4.2 nathanw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 1.4.4.2 nathanw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 1.4.4.2 nathanw * SUCH DAMAGE.
37 1.4.4.2 nathanw */
38 1.4.4.2 nathanw
39 1.4.4.2 nathanw /*
40 1.4.4.2 nathanw * bus_space I/O functions for sa11x0
41 1.4.4.2 nathanw */
42 1.4.4.2 nathanw
43 1.4.4.2 nathanw #include <sys/param.h>
44 1.4.4.2 nathanw #include <sys/systm.h>
45 1.4.4.2 nathanw #include <sys/queue.h>
46 1.4.4.2 nathanw
47 1.4.4.2 nathanw #include <uvm/uvm.h>
48 1.4.4.2 nathanw
49 1.4.4.2 nathanw #include <machine/bus.h>
50 1.4.4.2 nathanw #include <machine/pmap.h>
51 1.4.4.2 nathanw
52 1.4.4.2 nathanw /* Proto types for all the bus_space structure functions */
53 1.4.4.2 nathanw
54 1.4.4.2 nathanw bs_protos(sa11x0);
55 1.4.4.2 nathanw bs_protos(bs_notimpl);
56 1.4.4.2 nathanw
57 1.4.4.2 nathanw /* Declare the sa11x0 bus space tag */
58 1.4.4.2 nathanw
59 1.4.4.2 nathanw struct bus_space sa11x0_bs_tag = {
60 1.4.4.2 nathanw /* cookie */
61 1.4.4.2 nathanw NULL,
62 1.4.4.2 nathanw
63 1.4.4.2 nathanw /* mapping/unmapping */
64 1.4.4.2 nathanw sa11x0_bs_map,
65 1.4.4.2 nathanw sa11x0_bs_unmap,
66 1.4.4.2 nathanw sa11x0_bs_subregion,
67 1.4.4.2 nathanw
68 1.4.4.2 nathanw /* allocation/deallocation */
69 1.4.4.2 nathanw sa11x0_bs_alloc,
70 1.4.4.2 nathanw sa11x0_bs_free,
71 1.4.4.2 nathanw
72 1.4.4.2 nathanw /* get kernel virtual address */
73 1.4.4.2 nathanw sa11x0_bs_vaddr,
74 1.4.4.2 nathanw
75 1.4.4.2 nathanw /* mmap bus space for userland */
76 1.4.4.2 nathanw bs_notimpl_bs_mmap,
77 1.4.4.2 nathanw
78 1.4.4.2 nathanw /* barrier */
79 1.4.4.2 nathanw sa11x0_bs_barrier,
80 1.4.4.2 nathanw
81 1.4.4.2 nathanw /* read (single) */
82 1.4.4.2 nathanw sa11x0_bs_r_1,
83 1.4.4.2 nathanw sa11x0_bs_r_2,
84 1.4.4.2 nathanw sa11x0_bs_r_4,
85 1.4.4.2 nathanw bs_notimpl_bs_r_8,
86 1.4.4.2 nathanw
87 1.4.4.2 nathanw /* read multiple */
88 1.4.4.2 nathanw sa11x0_bs_rm_1,
89 1.4.4.2 nathanw sa11x0_bs_rm_2,
90 1.4.4.2 nathanw sa11x0_bs_rm_4,
91 1.4.4.2 nathanw bs_notimpl_bs_rm_8,
92 1.4.4.2 nathanw
93 1.4.4.2 nathanw /* read region */
94 1.4.4.2 nathanw bs_notimpl_bs_rr_1,
95 1.4.4.2 nathanw sa11x0_bs_rr_2,
96 1.4.4.2 nathanw bs_notimpl_bs_rr_4,
97 1.4.4.2 nathanw bs_notimpl_bs_rr_8,
98 1.4.4.2 nathanw
99 1.4.4.2 nathanw /* write (single) */
100 1.4.4.2 nathanw sa11x0_bs_w_1,
101 1.4.4.2 nathanw sa11x0_bs_w_2,
102 1.4.4.2 nathanw sa11x0_bs_w_4,
103 1.4.4.2 nathanw bs_notimpl_bs_w_8,
104 1.4.4.2 nathanw
105 1.4.4.2 nathanw /* write multiple */
106 1.4.4.2 nathanw sa11x0_bs_wm_1,
107 1.4.4.2 nathanw sa11x0_bs_wm_2,
108 1.4.4.2 nathanw sa11x0_bs_wm_4,
109 1.4.4.2 nathanw bs_notimpl_bs_wm_8,
110 1.4.4.2 nathanw
111 1.4.4.2 nathanw /* write region */
112 1.4.4.2 nathanw bs_notimpl_bs_wr_1,
113 1.4.4.2 nathanw sa11x0_bs_wr_2,
114 1.4.4.2 nathanw bs_notimpl_bs_wr_4,
115 1.4.4.2 nathanw bs_notimpl_bs_wr_8,
116 1.4.4.2 nathanw
117 1.4.4.2 nathanw /* set multiple */
118 1.4.4.2 nathanw bs_notimpl_bs_sm_1,
119 1.4.4.2 nathanw bs_notimpl_bs_sm_2,
120 1.4.4.2 nathanw bs_notimpl_bs_sm_4,
121 1.4.4.2 nathanw bs_notimpl_bs_sm_8,
122 1.4.4.2 nathanw
123 1.4.4.2 nathanw /* set region */
124 1.4.4.2 nathanw bs_notimpl_bs_sr_1,
125 1.4.4.2 nathanw sa11x0_bs_sr_2,
126 1.4.4.2 nathanw bs_notimpl_bs_sr_4,
127 1.4.4.2 nathanw bs_notimpl_bs_sr_8,
128 1.4.4.2 nathanw
129 1.4.4.2 nathanw /* copy */
130 1.4.4.2 nathanw bs_notimpl_bs_c_1,
131 1.4.4.2 nathanw sa11x0_bs_c_2,
132 1.4.4.2 nathanw bs_notimpl_bs_c_4,
133 1.4.4.2 nathanw bs_notimpl_bs_c_8,
134 1.4.4.2 nathanw };
135 1.4.4.2 nathanw
136 1.4.4.2 nathanw /* bus space functions */
137 1.4.4.2 nathanw
138 1.4.4.2 nathanw int
139 1.4.4.2 nathanw sa11x0_bs_map(t, bpa, size, cacheable, bshp)
140 1.4.4.2 nathanw void *t;
141 1.4.4.2 nathanw bus_addr_t bpa;
142 1.4.4.2 nathanw bus_size_t size;
143 1.4.4.2 nathanw int cacheable;
144 1.4.4.2 nathanw bus_space_handle_t *bshp;
145 1.4.4.2 nathanw {
146 1.4.4.2 nathanw u_long startpa, endpa, pa;
147 1.4.4.2 nathanw vaddr_t va;
148 1.4.4.2 nathanw pt_entry_t *pte;
149 1.4.4.2 nathanw
150 1.4.4.3 nathanw if ((u_long)bpa > (u_long)KERNEL_BASE) {
151 1.4.4.2 nathanw /* XXX This is a temporary hack to aid transition. */
152 1.4.4.2 nathanw *bshp = bpa;
153 1.4.4.2 nathanw return(0);
154 1.4.4.2 nathanw }
155 1.4.4.2 nathanw
156 1.4.4.2 nathanw startpa = trunc_page(bpa);
157 1.4.4.2 nathanw endpa = round_page(bpa + size);
158 1.4.4.2 nathanw
159 1.4.4.2 nathanw /* XXX use extent manager to check duplicate mapping */
160 1.4.4.2 nathanw
161 1.4.4.2 nathanw va = uvm_km_valloc(kernel_map, endpa - startpa);
162 1.4.4.2 nathanw if (! va)
163 1.4.4.2 nathanw return(ENOMEM);
164 1.4.4.2 nathanw
165 1.4.4.2 nathanw *bshp = (bus_space_handle_t)(va + (bpa - startpa));
166 1.4.4.2 nathanw
167 1.4.4.2 nathanw for(pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
168 1.4.4.2 nathanw pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE);
169 1.4.4.3 nathanw pte = vtopte(va);
170 1.4.4.4 nathanw if (cacheable == 0)
171 1.4.4.4 nathanw *pte &= ~L2_S_CACHE_MASK;
172 1.4.4.2 nathanw }
173 1.4.4.2 nathanw pmap_update(pmap_kernel());
174 1.4.4.2 nathanw
175 1.4.4.2 nathanw return(0);
176 1.4.4.2 nathanw }
177 1.4.4.2 nathanw
178 1.4.4.2 nathanw int
179 1.4.4.2 nathanw sa11x0_bs_alloc(t, rstart, rend, size, alignment, boundary, cacheable,
180 1.4.4.2 nathanw bpap, bshp)
181 1.4.4.2 nathanw void *t;
182 1.4.4.2 nathanw bus_addr_t rstart, rend;
183 1.4.4.2 nathanw bus_size_t size, alignment, boundary;
184 1.4.4.2 nathanw int cacheable;
185 1.4.4.2 nathanw bus_addr_t *bpap;
186 1.4.4.2 nathanw bus_space_handle_t *bshp;
187 1.4.4.2 nathanw {
188 1.4.4.2 nathanw panic("sa11x0_alloc(): Help!\n");
189 1.4.4.2 nathanw }
190 1.4.4.2 nathanw
191 1.4.4.2 nathanw
192 1.4.4.2 nathanw void
193 1.4.4.2 nathanw sa11x0_bs_unmap(t, bsh, size)
194 1.4.4.2 nathanw void *t;
195 1.4.4.2 nathanw bus_space_handle_t bsh;
196 1.4.4.2 nathanw bus_size_t size;
197 1.4.4.2 nathanw {
198 1.4.4.2 nathanw /*
199 1.4.4.2 nathanw * Temporary implementation
200 1.4.4.2 nathanw */
201 1.4.4.2 nathanw }
202 1.4.4.2 nathanw
203 1.4.4.2 nathanw void
204 1.4.4.2 nathanw sa11x0_bs_free(t, bsh, size)
205 1.4.4.2 nathanw void *t;
206 1.4.4.2 nathanw bus_space_handle_t bsh;
207 1.4.4.2 nathanw bus_size_t size;
208 1.4.4.2 nathanw {
209 1.4.4.2 nathanw
210 1.4.4.2 nathanw panic("sa11x0_free(): Help!\n");
211 1.4.4.2 nathanw /* sa11x0_unmap() does all that we need to do. */
212 1.4.4.2 nathanw /* sa11x0_unmap(t, bsh, size);*/
213 1.4.4.2 nathanw }
214 1.4.4.2 nathanw
215 1.4.4.2 nathanw int
216 1.4.4.2 nathanw sa11x0_bs_subregion(t, bsh, offset, size, nbshp)
217 1.4.4.2 nathanw void *t;
218 1.4.4.2 nathanw bus_space_handle_t bsh;
219 1.4.4.2 nathanw bus_size_t offset, size;
220 1.4.4.2 nathanw bus_space_handle_t *nbshp;
221 1.4.4.2 nathanw {
222 1.4.4.2 nathanw
223 1.4.4.2 nathanw *nbshp = bsh + offset;
224 1.4.4.2 nathanw return (0);
225 1.4.4.2 nathanw }
226 1.4.4.2 nathanw
227 1.4.4.2 nathanw void *
228 1.4.4.2 nathanw sa11x0_bs_vaddr(t, bsh)
229 1.4.4.2 nathanw void *t;
230 1.4.4.2 nathanw bus_space_handle_t bsh;
231 1.4.4.2 nathanw {
232 1.4.4.2 nathanw return ((void *)bsh);
233 1.4.4.2 nathanw }
234 1.4.4.2 nathanw
235 1.4.4.2 nathanw void
236 1.4.4.2 nathanw sa11x0_bs_barrier(t, bsh, offset, len, flags)
237 1.4.4.2 nathanw void *t;
238 1.4.4.2 nathanw bus_space_handle_t bsh;
239 1.4.4.2 nathanw bus_size_t offset, len;
240 1.4.4.2 nathanw int flags;
241 1.4.4.2 nathanw {
242 1.4.4.2 nathanw /* NULL */
243 1.4.4.2 nathanw }
244 1.4.4.2 nathanw
245 1.4.4.2 nathanw /* End of sa11x0_io.c */
246