1 /* $NetBSD: jensenio_bus_intio.c,v 1.1 2000/07/12 20:36:08 thorpej Exp $ */
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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
,
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 */
63 inline void jensenio_intio_barrier(void *, bus_space_handle_t
,
64 bus_size_t
, bus_size_t
, int);
67 inline u_int8_t
jensenio_intio_read_1(void *, bus_space_handle_t
, bus_size_t
);
70 void jensenio_intio_read_multi_1(void *, bus_space_handle_t
,
71 bus_size_t
, u_int8_t
*, bus_size_t
);
74 /* Not supported for Internal space */
77 inline void jensenio_intio_write_1(void *, bus_space_handle_t
,
78 bus_size_t
, u_int8_t
);
81 void jensenio_intio_write_multi_1(void *, bus_space_handle_t
,
82 bus_size_t
, const u_int8_t
*, bus_size_t
);
85 /* Not supported for Internal space */
88 void jensenio_intio_set_multi_1(void *, bus_space_handle_t
,
89 bus_size_t
, u_int8_t
, bus_size_t
);
92 /* Not supported for Internal space */
95 /* Not supported for Internal space */
98 jensenio_bus_intio_init(bus_space_tag_t t
, void *v
)
102 * Initialize the bus space tag.
105 memset(t
, 0, sizeof(*t
));
110 /* mapping/unmapping */
111 t
->abs_map
= jensenio_intio_map
;
112 t
->abs_unmap
= jensenio_intio_unmap
;
113 t
->abs_subregion
= jensenio_intio_subregion
;
116 t
->abs_barrier
= jensenio_intio_barrier
;
119 t
->abs_r_1
= jensenio_intio_read_1
;
122 t
->abs_rm_1
= jensenio_intio_read_multi_1
;
125 t
->abs_w_1
= jensenio_intio_write_1
;
128 t
->abs_wm_1
= jensenio_intio_write_multi_1
;
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
;
147 * Can't map i/o space linearly.
154 printf("intio: allocating 0x%lx to 0x%lx\n", ioaddr
,
155 ioaddr
+ iosize
- 1);
157 error
= extent_alloc_region(jcp
->jc_io_ex
, ioaddr
, iosize
,
158 EX_NOWAIT
| (jcp
->jc_mallocsafe
? EX_MALLOCOK
: 0));
161 printf("intio: allocation failed (%d)\n", error
);
162 extent_print(jcp
->jc_io_ex
);
168 *iohp
= ALPHA_PHYS_TO_K0SEG((ioaddr
<< 9) + JENSEN_VL82C106
);
173 jensenio_intio_unmap(void *v
, bus_space_handle_t ioh
, bus_size_t iosize
,
176 struct jensenio_config
*jcp
= v
;
184 printf("intio: freeing handle 0x%lx for 0x%lx\n", ioh
, iosize
);
187 ioh
= ALPHA_K0SEG_TO_PHYS(ioh
);
189 ioaddr
= (ioh
- JENSEN_VL82C106
) >> 9;
192 printf("intio: freeing 0x%lx to 0x%lx\n", ioaddr
, ioaddr
+ iosize
- 1);
194 error
= extent_free(jcp
->jc_io_ex
, ioaddr
, iosize
,
195 EX_NOWAIT
| (jcp
->jc_mallocsafe
? EX_MALLOCOK
: 0));
197 printf("WARNING: could not unmap 0x%lx-0x%lx (error %d)\n",
198 ioaddr
, ioaddr
+ iosize
- 1, error
);
200 extent_print(jcp
->jc_io_ex
);
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);
215 jensenio_intio_barrier(void *v
, bus_space_handle_t h
, bus_size_t o
,
219 if ((f
& BUS_SPACE_BARRIER_READ
) != 0)
221 else if ((f
& BUS_SPACE_BARRIER_WRITE
) != 0)
226 jensenio_intio_read_1(void *v
, bus_space_handle_t ioh
, bus_size_t off
)
228 register u_int32_t
*port
;
232 port
= (u_int32_t
*)(ioh
+ (off
<< 9));
233 return (*port
& 0xff);
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
)
242 jensenio_intio_barrier(v
, h
, o
, sizeof *a
,
243 BUS_SPACE_BARRIER_READ
);
244 *a
++ = jensenio_intio_read_1(v
, h
, o
);
249 jensenio_intio_write_1(void *v
, bus_space_handle_t ioh
, bus_size_t off
,
252 register u_int32_t
*port
;
254 port
= (u_int32_t
*)(ioh
+ (off
<< 9));
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
)
265 jensenio_intio_write_1(v
, h
, o
, *a
++);
266 jensenio_intio_barrier(v
, h
, o
, sizeof *a
,
267 BUS_SPACE_BARRIER_WRITE
);
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
)
277 jensenio_intio_write_1(v
, h
, o
, val
);
278 jensenio_intio_barrier(v
, h
, o
, sizeof val
,
279 BUS_SPACE_BARRIER_WRITE
);