1 /* $NetBSD: mainbus_io.c,v 1.19 2009/03/15 22:25:46 cegger Exp $ */
4 * Copyright (c) 1997 Mark Brinicombe.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
36 * bus_space I/O functions for mainbus
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: mainbus_io.c,v 1.19 2009/03/15 22:25:46 cegger Exp $");
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/queue.h>
48 #include <machine/bus.h>
49 #include <machine/pmap.h>
51 /* Proto types for all the bus_space structure functions */
54 bs_protos(bs_notimpl
);
56 /* Declare the mainbus bus space tag */
58 struct bus_space mainbus_bs_tag
= {
62 /* mapping/unmapping */
67 /* allocation/deallocation */
71 /* get kernel virtual address */
72 0, /* there is no linear mapping */
74 /* Mmap bus space for user */
134 /* bus space functions */
137 mainbus_bs_map(void *t
, bus_addr_t bpa
, bus_size_t size
, int flags
, bus_space_handle_t
*bshp
)
139 u_long startpa
, endpa
, pa
;
143 if ((u_long
)bpa
> (u_long
)KERNEL_BASE
) {
144 /* XXX This is a temporary hack to aid transition. */
149 startpa
= trunc_page(bpa
);
150 endpa
= round_page(bpa
+ size
);
152 /* XXX use extent manager to check duplicate mapping */
154 va
= uvm_km_alloc(kernel_map
, endpa
- startpa
, 0,
155 UVM_KMF_VAONLY
| UVM_KMF_NOWAIT
);
159 *bshp
= (bus_space_handle_t
)(va
+ (bpa
- startpa
));
161 for(pa
= startpa
; pa
< endpa
; pa
+= PAGE_SIZE
, va
+= PAGE_SIZE
) {
162 pmap_kenter_pa(va
, pa
, VM_PROT_READ
| VM_PROT_WRITE
, 0);
163 if ((flags
& BUS_SPACE_MAP_CACHEABLE
) == 0) {
165 *pte
&= ~L2_S_CACHE_MASK
;
169 pmap_update(pmap_kernel());
175 mainbus_bs_alloc(void *t
, bus_addr_t rstart
, bus_addr_t rend
,
176 bus_size_t size
, bus_size_t alignment
, bus_size_t boundary
,
178 bus_addr_t
*bpap
, bus_space_handle_t
*bshp
)
180 panic("mainbus_bs_alloc(): Help!");
185 mainbus_bs_unmap(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
188 * Temporary implementation
193 mainbus_bs_free(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
196 panic("mainbus_bs_free(): Help!");
197 /* mainbus_bs_unmap() does all that we need to do. */
198 /* mainbus_bs_unmap(t, bsh, size);*/
202 mainbus_bs_subregion(void *t
, bus_space_handle_t bsh
, bus_size_t offset
, bus_size_t size
, bus_space_handle_t
*nbshp
)
205 *nbshp
= bsh
+ (offset
<< 2);
210 mainbus_bs_mmap(void *t
, bus_addr_t paddr
, off_t offset
, int prot
, int flags
)
213 * mmap from address `paddr+offset' for one page
215 return (arm_btop((paddr
+ offset
)));
219 mainbus_bs_barrier(void *t
, bus_space_handle_t bsh
, bus_size_t offset
, bus_size_t len
, int flags
)
223 /* End of mainbus_io.c */