Deleted Added
full compact
ixp425_space.c (164426) ixp425_space.c (177887)
1/* $NetBSD: ixp425_space.c,v 1.6 2006/04/10 03:36:03 simonb Exp $ */
2
3/*
4 * Copyright (c) 2003
5 * Ichiro FUKUHARA <ichiro@ichiro.org>.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Ichiro FUKUHARA.
19 * 4. The name of the company nor the name of the author may be used to
20 * endorse or promote products derived from this software without specific
21 * prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR
27 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36#include <sys/cdefs.h>
1/* $NetBSD: ixp425_space.c,v 1.6 2006/04/10 03:36:03 simonb Exp $ */
2
3/*
4 * Copyright (c) 2003
5 * Ichiro FUKUHARA <ichiro@ichiro.org>.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Ichiro FUKUHARA.
19 * 4. The name of the company nor the name of the author may be used to
20 * endorse or promote products derived from this software without specific
21 * prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR
27 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36#include <sys/cdefs.h>
37__FBSDID("$FreeBSD: head/sys/arm/xscale/ixp425/ixp425_space.c 164426 2006-11-19 23:55:23Z sam $");
37__FBSDID("$FreeBSD: head/sys/arm/xscale/ixp425/ixp425_space.c 177887 2008-04-03 18:22:08Z raj $");
38
39/*
40 * bus_space I/O functions for ixp425
41 */
42
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/bus.h>
46
47#include <machine/pcb.h>
48
49#include <vm/vm.h>
50#include <vm/vm_kern.h>
51#include <vm/pmap.h>
52#include <vm/vm_page.h>
53#include <vm/vm_extern.h>
54
55#include <machine/bus.h>
56
57#include <arm/xscale/ixp425/ixp425reg.h>
58#include <arm/xscale/ixp425/ixp425var.h>
59
60/* Proto types for all the bus_space structure functions */
38
39/*
40 * bus_space I/O functions for ixp425
41 */
42
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/bus.h>
46
47#include <machine/pcb.h>
48
49#include <vm/vm.h>
50#include <vm/vm_kern.h>
51#include <vm/pmap.h>
52#include <vm/vm_page.h>
53#include <vm/vm_extern.h>
54
55#include <machine/bus.h>
56
57#include <arm/xscale/ixp425/ixp425reg.h>
58#include <arm/xscale/ixp425/ixp425var.h>
59
60/* Proto types for all the bus_space structure functions */
61bs_protos(ixp425);
62bs_protos(generic);
63bs_protos(generic_armv4);
64
65struct bus_space ixp425_bs_tag = {
66 /* cookie */
67 .bs_cookie = (void *) 0,
68
69 /* mapping/unmapping */
61bs_protos(generic);
62bs_protos(generic_armv4);
63
64struct bus_space ixp425_bs_tag = {
65 /* cookie */
66 .bs_cookie = (void *) 0,
67
68 /* mapping/unmapping */
70 .bs_map = ixp425_bs_map,
71 .bs_unmap = ixp425_bs_unmap,
72 .bs_subregion = ixp425_bs_subregion,
69 .bs_map = generic_bs_map,
70 .bs_unmap = generic_bs_unmap,
71 .bs_subregion = generic_bs_subregion,
73
74 /* allocation/deallocation */
72
73 /* allocation/deallocation */
75 .bs_alloc = ixp425_bs_alloc,
76 .bs_free = ixp425_bs_free,
74 .bs_alloc = generic_bs_alloc,
75 .bs_free = generic_bs_free,
77
78 /* barrier */
76
77 /* barrier */
79 .bs_barrier = ixp425_bs_barrier,
78 .bs_barrier = generic_bs_barrier,
80
81 /* read (single) */
82 .bs_r_1 = generic_bs_r_1,
83 .bs_r_2 = generic_armv4_bs_r_2,
84 .bs_r_4 = generic_bs_r_4,
85 .bs_r_8 = NULL,
86
87 /* read multiple */
88 .bs_rm_1 = generic_bs_rm_1,
89 .bs_rm_2 = generic_armv4_bs_rm_2,
90 .bs_rm_4 = generic_bs_rm_4,
91 .bs_rm_8 = NULL,
92
93 /* read region */
94 .bs_rr_1 = generic_bs_rr_1,
95 .bs_rr_2 = generic_armv4_bs_rr_2,
96 .bs_rr_4 = generic_bs_rr_4,
97 .bs_rr_8 = NULL,
98
99 /* write (single) */
100 .bs_w_1 = generic_bs_w_1,
101 .bs_w_2 = generic_armv4_bs_w_2,
102 .bs_w_4 = generic_bs_w_4,
103 .bs_w_8 = NULL,
104
105 /* write multiple */
106 .bs_wm_1 = generic_bs_wm_1,
107 .bs_wm_2 = generic_armv4_bs_wm_2,
108 .bs_wm_4 = generic_bs_wm_4,
109 .bs_wm_8 = NULL,
110
111 /* write region */
112 .bs_wr_1 = generic_bs_wr_1,
113 .bs_wr_2 = generic_armv4_bs_wr_2,
114 .bs_wr_4 = generic_bs_wr_4,
115 .bs_wr_8 = NULL,
116
117 /* set multiple */
118 /* XXX not implemented */
119
120 /* set region */
121 .bs_sr_1 = NULL,
122 .bs_sr_2 = generic_armv4_bs_sr_2,
123 .bs_sr_4 = generic_bs_sr_4,
124 .bs_sr_8 = NULL,
125
126 /* copy */
127 .bs_c_1 = NULL,
128 .bs_c_2 = generic_armv4_bs_c_2,
129 .bs_c_4 = NULL,
130 .bs_c_8 = NULL,
131};
79
80 /* read (single) */
81 .bs_r_1 = generic_bs_r_1,
82 .bs_r_2 = generic_armv4_bs_r_2,
83 .bs_r_4 = generic_bs_r_4,
84 .bs_r_8 = NULL,
85
86 /* read multiple */
87 .bs_rm_1 = generic_bs_rm_1,
88 .bs_rm_2 = generic_armv4_bs_rm_2,
89 .bs_rm_4 = generic_bs_rm_4,
90 .bs_rm_8 = NULL,
91
92 /* read region */
93 .bs_rr_1 = generic_bs_rr_1,
94 .bs_rr_2 = generic_armv4_bs_rr_2,
95 .bs_rr_4 = generic_bs_rr_4,
96 .bs_rr_8 = NULL,
97
98 /* write (single) */
99 .bs_w_1 = generic_bs_w_1,
100 .bs_w_2 = generic_armv4_bs_w_2,
101 .bs_w_4 = generic_bs_w_4,
102 .bs_w_8 = NULL,
103
104 /* write multiple */
105 .bs_wm_1 = generic_bs_wm_1,
106 .bs_wm_2 = generic_armv4_bs_wm_2,
107 .bs_wm_4 = generic_bs_wm_4,
108 .bs_wm_8 = NULL,
109
110 /* write region */
111 .bs_wr_1 = generic_bs_wr_1,
112 .bs_wr_2 = generic_armv4_bs_wr_2,
113 .bs_wr_4 = generic_bs_wr_4,
114 .bs_wr_8 = NULL,
115
116 /* set multiple */
117 /* XXX not implemented */
118
119 /* set region */
120 .bs_sr_1 = NULL,
121 .bs_sr_2 = generic_armv4_bs_sr_2,
122 .bs_sr_4 = generic_bs_sr_4,
123 .bs_sr_8 = NULL,
124
125 /* copy */
126 .bs_c_1 = NULL,
127 .bs_c_2 = generic_armv4_bs_c_2,
128 .bs_c_4 = NULL,
129 .bs_c_8 = NULL,
130};
132
133int
134ixp425_bs_map(void *t, bus_addr_t bpa, bus_size_t size,
135 int cacheable, bus_space_handle_t *bshp)
136{
137 const struct pmap_devmap *pd;
138 vm_paddr_t startpa, endpa, pa, offset;
139 vm_offset_t va;
140 pt_entry_t *pte;
141
142 if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) {
143 /* Device was statically mapped. */
144 *bshp = pd->pd_va + (bpa - pd->pd_pa);
145 return (0);
146 }
147
148 endpa = round_page(bpa + size);
149 offset = bpa & PAGE_MASK;
150 startpa = trunc_page(bpa);
151
152 va = kmem_alloc(kernel_map, endpa - startpa);
153 if (va == 0)
154 return (ENOMEM);
155
156 *bshp = va + offset;
157
158 for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
159 pmap_kenter(va, pa);
160 pte = vtopte(va);
161 *pte &= ~L2_S_CACHE_MASK;
162 PTE_SYNC(pte);
163 }
164
165 return (0);
166}
167
168void
169ixp425_bs_unmap(void *t, bus_space_handle_t h, bus_size_t size)
170{
171 vm_offset_t va, endva;
172
173 if (pmap_devmap_find_va((vm_offset_t)t, size) != NULL) {
174 /* Device was statically mapped; nothing to do. */
175 return;
176 }
177
178 endva = round_page((vm_offset_t)t + size);
179 va = trunc_page((vm_offset_t)t);
180
181 while (va < endva) {
182 pmap_kremove(va);
183 va += PAGE_SIZE;
184 }
185 kmem_free(kernel_map, va, endva - va);
186}
187
188int
189ixp425_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend,
190 bus_size_t size, bus_size_t alignment, bus_size_t boundary, int cacheable,
191 bus_addr_t *bpap, bus_space_handle_t *bshp)
192{
193 panic("ixp425_bs_alloc(): not implemented");
194}
195
196void
197ixp425_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
198{
199 panic("ixp425_bs_free(): not implemented");
200}
201
202int
203ixp425_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset,
204 bus_size_t size, bus_space_handle_t *nbshp)
205{
206 *nbshp = bsh + offset;
207 return (0);
208}
209
210void
211ixp425_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset,
212 bus_size_t len, int flags)
213{
214 /* Nothing to do. */
215}