ixp425_space.c revision 1.1
1/*	$NetBSD: ixp425_space.c,v 1.1 2003/09/25 14:11:18 ichiro 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__KERNEL_RCSID(0, "$NetBSD: ixp425_space.c,v 1.1 2003/09/25 14:11:18 ichiro Exp $");
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/queue.h>
46
47#include <uvm/uvm.h>
48
49#include <machine/bus.h>
50
51#include <arm/xscale/ixp425reg.h>
52#include <arm/xscale/ixp425var.h>
53
54/* Proto types for all the bus_space structure functions */
55bs_protos(ixp425);
56bs_protos(generic);
57bs_protos(generic_armv4);
58bs_protos(bs_notimpl);
59
60struct bus_space ixp425_bs_tag = {
61	/* cookie */
62	(void *) 0,
63
64	/* mapping/unmapping */
65	ixp425_bs_map,
66	ixp425_bs_unmap,
67	ixp425_bs_subregion,
68
69	/* allocation/deallocation */
70	ixp425_bs_alloc,
71	ixp425_bs_free,
72
73	/* get kernel virtual address */
74	ixp425_bs_vaddr,
75
76	/* mmap bus space for userland */
77	ixp425_bs_mmap,
78
79	/* barrier */
80	ixp425_bs_barrier,
81
82	/* read (single) */
83        generic_bs_r_1,
84        generic_armv4_bs_r_2,
85        generic_bs_r_4,
86        bs_notimpl_bs_r_8,
87
88        /* read multiple */
89        generic_bs_rm_1,
90        generic_armv4_bs_rm_2,
91        generic_bs_rm_4,
92        bs_notimpl_bs_rm_8,
93
94        /* read region */
95        bs_notimpl_bs_rr_1,
96        generic_armv4_bs_rr_2,
97        generic_bs_rr_4,
98        bs_notimpl_bs_rr_8,
99
100        /* write (single) */
101        generic_bs_w_1,
102        generic_armv4_bs_w_2,
103        generic_bs_w_4,
104        bs_notimpl_bs_w_8,
105
106        /* write multiple */
107        generic_bs_wm_1,
108        generic_armv4_bs_wm_2,
109        generic_bs_wm_4,
110        bs_notimpl_bs_wm_8,
111
112        /* write region */
113        bs_notimpl_bs_wr_1,
114        generic_armv4_bs_wr_2,
115        generic_bs_wr_4,
116        bs_notimpl_bs_wr_8,
117
118        /* set multiple */
119        bs_notimpl_bs_sm_1,
120        bs_notimpl_bs_sm_2,
121        bs_notimpl_bs_sm_4,
122        bs_notimpl_bs_sm_8,
123
124        /* set region */
125        bs_notimpl_bs_sr_1,
126        generic_armv4_bs_sr_2,
127        generic_bs_sr_4,
128        bs_notimpl_bs_sr_8,
129
130        /* copy */
131        bs_notimpl_bs_c_1,
132        generic_armv4_bs_c_2,
133        bs_notimpl_bs_c_4,
134        bs_notimpl_bs_c_8,
135};
136
137int
138ixp425_bs_map(void *t, bus_addr_t bpa, bus_size_t size,
139	      int cacheable, bus_space_handle_t *bshp)
140{
141	const struct pmap_devmap	*pd;
142
143	paddr_t		startpa;
144        paddr_t		endpa;
145        paddr_t		pa;
146        paddr_t		offset;
147        vaddr_t		va;
148        pt_entry_t	*pte;
149
150	if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) {
151		/* Device was statically mapped. */
152		*bshp = pd->pd_va + (bpa - pd->pd_pa);
153		return 0;
154	}
155
156	endpa = round_page(bpa + size);
157	offset = bpa & PAGE_MASK;
158	startpa = trunc_page(bpa);
159
160	/* Get some VM.  */
161	if ((va = uvm_km_valloc(kernel_map, endpa - startpa)) == 0)
162		return ENOMEM;
163
164	/* Store the bus space handle */
165	*bshp = va + offset;
166
167	/* Now map the pages */
168	for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
169		pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE);
170		pte = vtopte(va);
171		*pte &= ~L2_S_CACHE_MASK;
172		PTE_SYNC(pte);
173	}
174	pmap_update(pmap_kernel());
175
176	return(0);
177}
178
179void
180ixp425_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
181{
182	vaddr_t	va;
183	vaddr_t	endva;
184
185	if (pmap_devmap_find_va(bsh, size) != NULL) {
186		/* Device was statically mapped; nothing to do. */
187		return;
188	}
189
190	endva = round_page(bsh + size);
191	va = trunc_page(bsh);
192
193	pmap_kremove(va, endva - va);
194	uvm_km_free(kernel_map, va, endva - va);
195}
196
197int
198ixp425_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend,
199	bus_size_t size, bus_size_t alignment, bus_size_t boundary, int cacheable,
200	bus_addr_t *bpap, bus_space_handle_t *bshp)
201{
202	panic("ixp425_bs_alloc(): not implemented\n");
203}
204
205void
206ixp425_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
207{
208	panic("ixp425_bs_free(): not implemented\n");
209}
210
211int
212ixp425_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset,
213	bus_size_t size, bus_space_handle_t *nbshp)
214{
215	*nbshp = bsh + offset;
216	return (0);
217}
218
219void *
220ixp425_bs_vaddr(void *t, bus_space_handle_t bsh)
221{
222	return ((void *)bsh);
223}
224
225paddr_t
226ixp425_bs_mmap(void *t, bus_addr_t addr, off_t off, int prot, int flags)
227{
228	/* Not supported. */
229	return (-1);
230}
231
232void
233ixp425_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset,
234    bus_size_t len, int flags)
235{
236/* NULL */
237}
238/* End of ixp425_space.c */
239