xref: /netbsd/sys/arch/arm/s3c2xx0/s3c2xx0_space.c (revision c4a72b64)
1 /*	$NetBSD: s3c2xx0_space.c,v 1.1 2002/11/20 17:52:51 bsh Exp $ */
2 
3 /*
4  * Copyright (c) 2002 Fujitsu Component Limited
5  * Copyright (c) 2002 Genetec Corporation
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. Neither the name of The Fujitsu Component Limited nor the name of
17  *    Genetec corporation may not be used to endorse or promote products
18  *    derived from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY FUJITSU COMPONENT LIMITED AND GENETEC
21  * CORPORATION ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24  * DISCLAIMED.  IN NO EVENT SHALL FUJITSU COMPONENT LIMITED OR GENETEC
25  * CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
28  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
34 /* derived from sa11x0_io.c */
35 
36 /*
37  * Copyright (c) 1997 Mark Brinicombe.
38  * Copyright (c) 1997 Causality Limited.
39  * All rights reserved.
40  *
41  * This code is derived from software contributed to The NetBSD Foundation
42  * by Ichiro FUKUHARA.
43  *
44  * Redistribution and use in source and binary forms, with or without
45  * modification, are permitted provided that the following conditions
46  * are met:
47  * 1. Redistributions of source code must retain the above copyright
48  *    notice, this list of conditions and the following disclaimer.
49  * 2. Redistributions in binary form must reproduce the above copyright
50  *    notice, this list of conditions and the following disclaimer in the
51  *    documentation and/or other materials provided with the distribution.
52  * 3. All advertising materials mentioning features or use of this software
53  *    must display the following acknowledgement:
54  *	This product includes software developed by Mark Brinicombe.
55  * 4. The name of the company nor the name of the author may be used to
56  *    endorse or promote products derived from this software without specific
57  *    prior written permission.
58  *
59  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
60  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
61  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
62  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
63  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
64  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
65  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69  * SUCH DAMAGE.
70  */
71 
72 /*
73  * bus_space functions for Samsung S3C2800/2400/2410.
74  */
75 
76 #include <sys/param.h>
77 #include <sys/systm.h>
78 
79 #include <uvm/uvm_extern.h>
80 
81 #include <machine/bus.h>
82 
83 /* Prototypes for all the bus_space structure functions */
84 bs_protos(s3c2xx0);
85 bs_protos(generic);
86 bs_protos(generic_armv4);
87 bs_protos(bs_notimpl);
88 
89 struct bus_space s3c2xx0_bs_tag = {
90 	/* cookie */
91 	(void *) 0,
92 
93 	/* mapping/unmapping */
94 	s3c2xx0_bs_map,
95 	s3c2xx0_bs_unmap,
96 	s3c2xx0_bs_subregion,
97 
98 	/* allocation/deallocation */
99 	s3c2xx0_bs_alloc,	/* not implemented */
100 	s3c2xx0_bs_free,	/* not implemented */
101 
102 	/* get kernel virtual address */
103 	s3c2xx0_bs_vaddr,
104 
105 	/* mmap */
106 	bs_notimpl_bs_mmap,
107 
108 	/* barrier */
109 	s3c2xx0_bs_barrier,
110 
111 	/* read (single) */
112 	generic_bs_r_1,
113 	generic_armv4_bs_r_2,
114 	generic_bs_r_4,
115 	bs_notimpl_bs_r_8,
116 
117 	/* read multiple */
118 	generic_bs_rm_1,
119 	generic_armv4_bs_rm_2,
120 	generic_bs_rm_4,
121 	bs_notimpl_bs_rm_8,
122 
123 	/* read region */
124 	bs_notimpl_bs_rr_1,
125 	generic_armv4_bs_rr_2,
126 	generic_bs_rr_4,
127 	bs_notimpl_bs_rr_8,
128 
129 	/* write (single) */
130 	generic_bs_w_1,
131 	generic_armv4_bs_w_2,
132 	generic_bs_w_4,
133 	bs_notimpl_bs_w_8,
134 
135 	/* write multiple */
136 	generic_bs_wm_1,
137 	generic_armv4_bs_wm_2,
138 	generic_bs_wm_4,
139 	bs_notimpl_bs_wm_8,
140 
141 	/* write region */
142 	bs_notimpl_bs_wr_1,
143 	generic_armv4_bs_wr_2,
144 	generic_bs_wr_4,
145 	bs_notimpl_bs_wr_8,
146 
147 	/* set multiple */
148 	bs_notimpl_bs_sm_1,
149 	bs_notimpl_bs_sm_2,
150 	bs_notimpl_bs_sm_4,
151 	bs_notimpl_bs_sm_8,
152 
153 	/* set region */
154 	bs_notimpl_bs_sr_1,
155 	generic_armv4_bs_sr_2,
156 	bs_notimpl_bs_sr_4,
157 	bs_notimpl_bs_sr_8,
158 
159 	/* copy */
160 	bs_notimpl_bs_c_1,
161 	generic_armv4_bs_c_2,
162 	bs_notimpl_bs_c_4,
163 	bs_notimpl_bs_c_8,
164 };
165 
166 int
167 s3c2xx0_bs_map(void *t, bus_addr_t bpa, bus_size_t size,
168 	       int flag, bus_space_handle_t * bshp)
169 {
170 	u_long startpa, endpa, pa;
171 	vaddr_t va;
172 	pt_entry_t *pte;
173 
174 	if ((u_long) bpa > (u_long) KERNEL_BASE) {
175 		/* Some IO registers (ex. UART ports for console) are mapped
176 		 * to fixed address by board specific routine. */
177 		*bshp = bpa;
178 		return (0);
179 	}
180 	startpa = trunc_page(bpa);
181 	endpa = round_page(bpa + size);
182 
183 	/* XXX use extent manager to check duplicate mapping */
184 
185 	va = uvm_km_valloc(kernel_map, endpa - startpa);
186 	if (!va)
187 		return (ENOMEM);
188 
189 	*bshp = (bus_space_handle_t) (va + (bpa - startpa));
190 
191 	for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
192 		pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE);
193 		pte = vtopte(va);
194 		if ((flag & BUS_SPACE_MAP_CACHEABLE) == 0)
195 			*pte &= ~L2_S_CACHE_MASK;
196 	}
197 	pmap_update(pmap_kernel());
198 
199 	return (0);
200 }
201 
202 void
203 s3c2xx0_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
204 {
205 
206 	/* Nothing to do. */
207 }
208 
209 
210 int
211 s3c2xx0_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset,
212 		     bus_size_t size, bus_space_handle_t * nbshp)
213 {
214 
215 	*nbshp = bsh + offset;
216 	return (0);
217 }
218 
219 void
220 s3c2xx0_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset,
221 		   bus_size_t len, int flags)
222 {
223 
224 	/* Nothing to do. */
225 }
226 
227 void *
228 s3c2xx0_bs_vaddr(void *t, bus_space_handle_t bsh)
229 {
230 
231 	return ((void *) bsh);
232 }
233 
234 
235 int
236 s3c2xx0_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend,
237 		 bus_size_t size, bus_size_t alignment, bus_size_t boundary,
238     		 int flags, bus_addr_t * bpap, bus_space_handle_t * bshp)
239 {
240 
241 	panic("s3c2xx0_io_bs_alloc(): not implemented\n");
242 }
243 
244 void
245 s3c2xx0_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
246 {
247 
248 	panic("s3c2xx0_io_bs_free(): not implemented\n");
249 }
250