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