xref: /netbsd-src/sys/arch/arm/mainbus/mainbus_io.c (revision 3b01aba77a7a698587faaae455bbfe740923c1f5)
1 /*	$NetBSD: mainbus_io.c,v 1.3 2001/07/28 18:12:44 chris 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 #include <machine/pte.h>
48 
49 pt_entry_t *pmap_pte(pmap_t, vm_offset_t);
50 
51 /* Proto types for all the bus_space structure functions */
52 
53 bs_protos(mainbus);
54 bs_protos(bs_notimpl);
55 
56 /* Declare the mainbus bus space tag */
57 
58 struct bus_space mainbus_bs_tag = {
59 	/* cookie */
60 	NULL,
61 
62 	/* mapping/unmapping */
63 	mainbus_bs_map,
64 	mainbus_bs_unmap,
65 	mainbus_bs_subregion,
66 
67 	/* allocation/deallocation */
68 	mainbus_bs_alloc,
69 	mainbus_bs_free,
70 
71 	/* get kernel virtual address */
72 	0, /* there is no linear mapping */
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_SPACE_START) {
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 = pmap_pte(pmap_kernel(), va);
165 		if (cacheable)
166 			*pte |= PT_CACHEABLE;
167 		else
168 			*pte &= ~PT_CACHEABLE;
169 	}
170 	pmap_update();
171 
172 	return(0);
173 }
174 
175 int
176 mainbus_bs_alloc(t, rstart, rend, size, alignment, boundary, cacheable,
177     bpap, bshp)
178 	void *t;
179 	bus_addr_t rstart, rend;
180 	bus_size_t size, alignment, boundary;
181 	int cacheable;
182 	bus_addr_t *bpap;
183 	bus_space_handle_t *bshp;
184 {
185 	panic("mainbus_bs_alloc(): Help!\n");
186 }
187 
188 
189 void
190 mainbus_bs_unmap(t, bsh, size)
191 	void *t;
192 	bus_space_handle_t bsh;
193 	bus_size_t size;
194 {
195 	/*
196 	 * Temporary implementation
197 	 */
198 }
199 
200 void
201 mainbus_bs_free(t, bsh, size)
202 	void *t;
203 	bus_space_handle_t bsh;
204 	bus_size_t size;
205 {
206 
207 	panic("mainbus_bs_free(): Help!\n");
208 	/* mainbus_bs_unmap() does all that we need to do. */
209 /*	mainbus_bs_unmap(t, bsh, size);*/
210 }
211 
212 int
213 mainbus_bs_subregion(t, bsh, offset, size, nbshp)
214 	void *t;
215 	bus_space_handle_t bsh;
216 	bus_size_t offset, size;
217 	bus_space_handle_t *nbshp;
218 {
219 
220 	*nbshp = bsh + offset;
221 	return (0);
222 }
223 
224 void
225 mainbus_bs_barrier(t, bsh, offset, len, flags)
226 	void *t;
227 	bus_space_handle_t bsh;
228 	bus_size_t offset, len;
229 	int flags;
230 {
231 }
232 
233 /* End of mainbus_io.c */
234