xref: /netbsd-src/sys/arch/arm/imx/imx23_space.c (revision ba65fde2d7fefa7d39838fa5fa855e62bd606b5e)
1 /* $Id: imx23_space.c,v 1.1 2012/11/20 19:06:13 jkunz Exp $ */
2 
3 /*
4  * Copyright (c) 2012 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Petri Laakso.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * bus_space(9) support for Freescale i.MX23 processor.
34  */
35 #include <sys/bus.h>
36 #include <sys/mutex.h>
37 #include <uvm/uvm_prot.h>
38 #include <machine/pcb.h>
39 #include <uvm/uvm_pmap.h>
40 #include <machine/bus_defs.h>
41 #include <machine/pmap.h>
42 
43 int	imx23_bs_map(void *, bus_addr_t, bus_size_t, int, bus_space_handle_t *);
44 void	imx23_bs_unmap(void *, bus_space_handle_t, bus_size_t);
45 int	imx23_bs_subregion(void *, bus_space_handle_t, bus_size_t, bus_size_t,
46 		bus_space_handle_t *);
47 int	imx23_bs_alloc(void *, bus_addr_t, bus_addr_t, bus_size_t, bus_size_t,
48 		bus_size_t, int, bus_addr_t *, bus_space_handle_t *);
49 void	imx23_bs_free(void *, bus_space_handle_t, bus_size_t);
50 void *	imx23_bs_vaddr(void *, bus_space_handle_t);
51 paddr_t	imx23_bs_mmap(void *, bus_addr_t, off_t, int, int);
52 void	imx23_bs_barrier(void *, bus_space_handle_t, bus_size_t,
53 		bus_size_t, int);
54 
55 bs_protos(bs_notimpl);
56 bs_protos(generic);
57 bs_protos(generic_armv4);
58 
59 /* Describes bus space on i.MX23 */
60 struct bus_space imx23_bus_space = {
61 	/* cookie */
62 	(void *) 0,
63 
64 	/* mapping/unmapping */
65 	imx23_bs_map,
66 	imx23_bs_unmap,
67 	imx23_bs_subregion,
68 
69 	/* allocation/deallocation */
70 	imx23_bs_alloc,
71 	imx23_bs_free,
72 
73 	/* get kernel virtual address */
74 	imx23_bs_vaddr,
75 
76 	/* mmap bus space for user */
77 	imx23_bs_mmap,
78 
79 	/* barrier */
80 	imx23_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 	generic_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 	generic_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 	generic_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 
137 int
138 imx23_bs_map(void *space, bus_addr_t address, bus_size_t size,
139 	int flags, bus_space_handle_t *handlep)
140 {
141 	const struct pmap_devmap *pd;
142 
143 	if ((pd = pmap_devmap_find_pa(address, size)) != NULL) {
144 		/* Device was statically mapped. */
145 		*handlep = pd->pd_va + (address - pd->pd_pa);
146 		return 0;
147 	}
148 
149 	return 0;
150 }
151 
152 void
153 imx23_bs_unmap(void *space, bus_space_handle_t handle, bus_size_t size)
154 {
155 	if (pmap_devmap_find_va(handle, size) != NULL) {
156 		/* Device was statically mapped. */
157 		return;
158 	}
159 
160 	return;
161 }
162 
163 int
164 imx23_bs_subregion(void *space, bus_space_handle_t handle,
165 	bus_size_t offset, bus_size_t size, bus_space_handle_t *nhandlep)
166 {
167 	*nhandlep = handle + offset;
168 	return 0;
169 }
170 
171 int
172 imx23_bs_alloc(void *space, bus_addr_t reg_start, bus_addr_t reg_end,
173 	bus_size_t size, bus_size_t alignment,
174 	bus_size_t boundary, int flags, bus_addr_t *addrp,
175 	bus_space_handle_t *handlep)
176 {
177 	return 0;
178 }
179 
180 void
181 imx23_bs_free(void *space, bus_space_handle_t handle, bus_size_t size)
182 {
183 	return;
184 }
185 
186 void *
187 imx23_bs_vaddr(void *space, bus_space_handle_t handle)
188 {
189 	return (void *)0;
190 }
191 
192 paddr_t
193 imx23_bs_mmap(void *space, bus_addr_t addr, off_t off, int prot,
194 	int flags)
195 {
196 	return (paddr_t)0;
197 }
198 
199 void
200 imx23_bs_barrier(void *space, bus_space_handle_t handle,
201 	bus_size_t offset,
202 	bus_size_t length, int flags)
203 {
204 	return;
205 }
206