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