obio_space.c revision 1.5
1/*	$NetBSD: obio_space.c,v 1.5 2003/06/15 18:43:50 thorpej Exp $	*/
2
3/*
4 * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
5 * All rights reserved.
6 *
7 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in the
16 *    documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 *    must display the following acknowledgement:
19 *	This product includes software developed for the NetBSD Project by
20 *	Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 *    or promote products derived from this software without specific prior
23 *    written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38/*
39 * bus_space functions for IQ80321 on-board devices
40 */
41
42#include <sys/param.h>
43#include <sys/systm.h>
44
45#include <uvm/uvm_extern.h>
46
47#include <machine/bus.h>
48
49/* Prototypes for all the bus_space structure functions */
50bs_protos(obio);
51bs_protos(generic);
52bs_protos(generic_armv4);
53bs_protos(bs_notimpl);
54
55/*
56 * The obio bus space tag.  This is constant for all instances, so
57 * we never have to explicitly "create" it.
58 */
59struct bus_space obio_bs_tag = {
60	/* cookie */
61	(void *) 0,
62
63	/* mapping/unmapping */
64	obio_bs_map,
65	obio_bs_unmap,
66	obio_bs_subregion,
67
68	/* allocation/deallocation */
69	obio_bs_alloc,
70	obio_bs_free,
71
72	/* get kernel virtual address */
73	obio_bs_vaddr,
74
75	/* mmap */
76	bs_notimpl_bs_mmap,
77
78	/* barrier */
79	obio_bs_barrier,
80
81	/* read (single) */
82	generic_bs_r_1,
83	generic_armv4_bs_r_2,
84	generic_bs_r_4,
85	bs_notimpl_bs_r_8,
86
87	/* read multiple */
88	generic_bs_rm_1,
89	bs_notimpl_bs_rm_2,
90	bs_notimpl_bs_rm_4,
91	bs_notimpl_bs_rm_8,
92
93	/* read region */
94	generic_bs_rr_1,
95	bs_notimpl_bs_rr_2,
96	bs_notimpl_bs_rr_4,
97	bs_notimpl_bs_rr_8,
98
99	/* write (single) */
100	generic_bs_w_1,
101	generic_armv4_bs_w_2,
102	generic_bs_w_4,
103	bs_notimpl_bs_w_8,
104
105	/* write multiple */
106	generic_bs_wm_1,
107	bs_notimpl_bs_wm_2,
108	bs_notimpl_bs_wm_4,
109	bs_notimpl_bs_wm_8,
110
111	/* write region */
112	bs_notimpl_bs_wr_1,
113	bs_notimpl_bs_wr_2,
114	bs_notimpl_bs_wr_4,
115	bs_notimpl_bs_wr_8,
116
117	/* set multiple */
118	bs_notimpl_bs_sm_1,
119	bs_notimpl_bs_sm_2,
120	bs_notimpl_bs_sm_4,
121	bs_notimpl_bs_sm_8,
122
123	/* set region */
124	bs_notimpl_bs_sr_1,
125	bs_notimpl_bs_sr_2,
126	bs_notimpl_bs_sr_4,
127	bs_notimpl_bs_sr_8,
128
129	/* copy */
130	bs_notimpl_bs_c_1,
131	bs_notimpl_bs_c_2,
132	bs_notimpl_bs_c_4,
133	bs_notimpl_bs_c_8,
134};
135
136int
137obio_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags,
138    bus_space_handle_t *bshp)
139{
140	const struct pmap_devmap *pd;
141	paddr_t startpa, endpa, pa, offset;
142	vaddr_t va;
143	pt_entry_t *pte;
144
145	if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) {
146		/* Device was statically mapped. */
147		*bshp = pd->pd_va + (bpa - pd->pd_pa);
148		return (0);
149	}
150
151	endpa = round_page(bpa + size);
152	offset = bpa & PAGE_MASK;
153	startpa = trunc_page(bpa);
154
155	va = uvm_km_valloc(kernel_map, endpa - startpa);
156	if (va == 0)
157		return (ENOMEM);
158
159	*bshp = va + offset;
160
161	for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
162		pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE);
163		pte = vtopte(va);
164		*pte &= ~L2_S_CACHE_MASK;
165		PTE_SYNC(pte);
166	}
167	pmap_update(pmap_kernel());
168
169	return (0);
170}
171
172int
173obio_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend, bus_size_t size,
174    bus_size_t alignment, bus_size_t boundary, int flags, bus_addr_t *bpap,
175    bus_space_handle_t *bshp)
176{
177
178	panic("obio_bs_alloc(): not implemented");
179}
180
181
182void
183obio_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
184{
185	vaddr_t va, endva;
186
187	if (pmap_devmap_find_va(bsh, size) != NULL) {
188		/* Device was statically mapped; nothing to do. */
189		return;
190	}
191
192	endva = round_page(bsh + size);
193	va = trunc_page(bsh);
194
195	pmap_kremove(va, endva - va);
196	uvm_km_free(kernel_map, va, endva - va);
197}
198
199void
200obio_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
201{
202
203	panic("obio_bs_free(): not implemented");
204}
205
206int
207obio_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset,
208    bus_size_t size, bus_space_handle_t *nbshp)
209{
210
211	*nbshp = bsh + offset;
212	return (0);
213}
214
215void *
216obio_bs_vaddr(void *t, bus_space_handle_t bsh)
217{
218
219	return ((void *)bsh);
220}
221
222void
223obio_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset,
224    bus_size_t len, int flags)
225{
226
227	/* Nothing to do. */
228}
229