No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / alpha / jensenio / jensenio_bus_intio.c
blob59d64631283b3f52c088c9c52b18c839a8debfe8
1 /* $NetBSD: jensenio_bus_intio.c,v 1.1 2000/07/12 20:36:08 thorpej Exp $ */
3 /*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
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.
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.
32 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
34 __KERNEL_RCSID(0, "$NetBSD: jensenio_bus_intio.c,v 1.1 2000/07/12 20:36:08 thorpej Exp $");
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/malloc.h>
39 #include <sys/device.h>
40 #include <sys/extent.h>
42 #include <machine/bus.h>
44 #include <dev/eisa/eisavar.h>
46 #include <dev/isa/isavar.h>
48 #include <alpha/jensenio/jensenioreg.h>
49 #include <alpha/jensenio/jenseniovar.h>
51 /* mapping/unmapping */
52 int jensenio_intio_map(void *, bus_addr_t, bus_size_t, int,
53 bus_space_handle_t *, int);
54 void jensenio_intio_unmap(void *, bus_space_handle_t,
55 bus_size_t, int);
56 int jensenio_intio_subregion(void *, bus_space_handle_t,
57 bus_size_t, bus_size_t, bus_space_handle_t *);
59 /* allocation/deallocation */
60 /* Not supported for Internal space */
62 /* barrier */
63 inline void jensenio_intio_barrier(void *, bus_space_handle_t,
64 bus_size_t, bus_size_t, int);
66 /* read (single) */
67 inline u_int8_t jensenio_intio_read_1(void *, bus_space_handle_t, bus_size_t);
69 /* read multiple */
70 void jensenio_intio_read_multi_1(void *, bus_space_handle_t,
71 bus_size_t, u_int8_t *, bus_size_t);
73 /* read region */
74 /* Not supported for Internal space */
76 /* write (single) */
77 inline void jensenio_intio_write_1(void *, bus_space_handle_t,
78 bus_size_t, u_int8_t);
80 /* write multiple */
81 void jensenio_intio_write_multi_1(void *, bus_space_handle_t,
82 bus_size_t, const u_int8_t *, bus_size_t);
84 /* write region */
85 /* Not supported for Internal space */
87 /* set multiple */
88 void jensenio_intio_set_multi_1(void *, bus_space_handle_t,
89 bus_size_t, u_int8_t, bus_size_t);
91 /* set region */
92 /* Not supported for Internal space */
94 /* copy */
95 /* Not supported for Internal space */
97 void
98 jensenio_bus_intio_init(bus_space_tag_t t, void *v)
102 * Initialize the bus space tag.
105 memset(t, 0, sizeof(*t));
107 /* cookie */
108 t->abs_cookie = v;
110 /* mapping/unmapping */
111 t->abs_map = jensenio_intio_map;
112 t->abs_unmap = jensenio_intio_unmap;
113 t->abs_subregion = jensenio_intio_subregion;
115 /* barrier */
116 t->abs_barrier = jensenio_intio_barrier;
118 /* read (single) */
119 t->abs_r_1 = jensenio_intio_read_1;
121 /* read multiple */
122 t->abs_rm_1 = jensenio_intio_read_multi_1;
124 /* write (single) */
125 t->abs_w_1 = jensenio_intio_write_1;
127 /* write multiple */
128 t->abs_wm_1 = jensenio_intio_write_multi_1;
130 /* set multiple */
131 t->abs_sm_1 = jensenio_intio_set_multi_1;
134 * Extent map is already set up.
139 jensenio_intio_map(void *v, bus_addr_t ioaddr, bus_size_t iosize, int flags,
140 bus_space_handle_t *iohp, int acct)
142 struct jensenio_config *jcp = v;
143 int linear = flags & BUS_SPACE_MAP_LINEAR;
144 int error;
147 * Can't map i/o space linearly.
149 if (linear)
150 return (EOPNOTSUPP);
152 if (acct) {
153 #ifdef EXTENT_DEBUG
154 printf("intio: allocating 0x%lx to 0x%lx\n", ioaddr,
155 ioaddr + iosize - 1);
156 #endif
157 error = extent_alloc_region(jcp->jc_io_ex, ioaddr, iosize,
158 EX_NOWAIT | (jcp->jc_mallocsafe ? EX_MALLOCOK : 0));
159 if (error) {
160 #ifdef EXTENT_DEBUG
161 printf("intio: allocation failed (%d)\n", error);
162 extent_print(jcp->jc_io_ex);
163 #endif
164 return (error);
168 *iohp = ALPHA_PHYS_TO_K0SEG((ioaddr << 9) + JENSEN_VL82C106);
169 return (0);
172 void
173 jensenio_intio_unmap(void *v, bus_space_handle_t ioh, bus_size_t iosize,
174 int acct)
176 struct jensenio_config *jcp = v;
177 bus_addr_t ioaddr;
178 int error;
180 if (acct == 0)
181 return;
183 #ifdef EXTENT_DEBUG
184 printf("intio: freeing handle 0x%lx for 0x%lx\n", ioh, iosize);
185 #endif
187 ioh = ALPHA_K0SEG_TO_PHYS(ioh);
189 ioaddr = (ioh - JENSEN_VL82C106) >> 9;
191 #ifdef EXTENT_DEBUG
192 printf("intio: freeing 0x%lx to 0x%lx\n", ioaddr, ioaddr + iosize - 1);
193 #endif
194 error = extent_free(jcp->jc_io_ex, ioaddr, iosize,
195 EX_NOWAIT | (jcp->jc_mallocsafe ? EX_MALLOCOK : 0));
196 if (error) {
197 printf("WARNING: could not unmap 0x%lx-0x%lx (error %d)\n",
198 ioaddr, ioaddr + iosize - 1, error);
199 #ifdef EXTENT_DEBUG
200 extent_print(jcp->jc_io_ex);
201 #endif
206 jensenio_intio_subregion(void *v, bus_space_handle_t ioh, bus_size_t offset,
207 bus_size_t size, bus_space_handle_t *nioh)
210 *nioh = ioh + (offset << 9);
211 return (0);
214 inline void
215 jensenio_intio_barrier(void *v, bus_space_handle_t h, bus_size_t o,
216 bus_size_t l, int f)
219 if ((f & BUS_SPACE_BARRIER_READ) != 0)
220 alpha_mb();
221 else if ((f & BUS_SPACE_BARRIER_WRITE) != 0)
222 alpha_wmb();
225 inline u_int8_t
226 jensenio_intio_read_1(void *v, bus_space_handle_t ioh, bus_size_t off)
228 register u_int32_t *port;
230 alpha_mb();
232 port = (u_int32_t *)(ioh + (off << 9));
233 return (*port & 0xff);
236 void
237 jensenio_intio_read_multi_1(void *v, bus_space_handle_t h, bus_size_t o,
238 u_int8_t *a, bus_size_t c)
241 while (c-- > 0) {
242 jensenio_intio_barrier(v, h, o, sizeof *a,
243 BUS_SPACE_BARRIER_READ);
244 *a++ = jensenio_intio_read_1(v, h, o);
248 inline void
249 jensenio_intio_write_1(void *v, bus_space_handle_t ioh, bus_size_t off,
250 u_int8_t val)
252 register u_int32_t *port;
254 port = (u_int32_t *)(ioh + (off << 9));
255 *port = val;
256 alpha_mb();
259 void
260 jensenio_intio_write_multi_1(void *v, bus_space_handle_t h, bus_size_t o,
261 const u_int8_t *a, bus_size_t c)
264 while (c-- > 0) {
265 jensenio_intio_write_1(v, h, o, *a++);
266 jensenio_intio_barrier(v, h, o, sizeof *a,
267 BUS_SPACE_BARRIER_WRITE);
271 void
272 jensenio_intio_set_multi_1(void *v, bus_space_handle_t h, bus_size_t o,
273 u_int8_t val, bus_size_t c)
276 while (c-- > 0) {
277 jensenio_intio_write_1(v, h, o, val);
278 jensenio_intio_barrier(v, h, o, sizeof val,
279 BUS_SPACE_BARRIER_WRITE);