2 * Copyright (c) 2009 Marcel Moolenaar
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/types.h>
31 #include <machine/bus.h>
35 extern u_long ia64_port_base;
37 #define __PIO_ADDR(port) \
38 (void *)(ia64_port_base | (((port) & 0xfffc) << 10) | ((port) & 0xFFF))
41 bus_space_map(bus_space_tag_t bst, bus_addr_t addr, bus_size_t size,
42 int flags __unused, bus_space_handle_t *bshp)
45 *bshp = (__predict_false(bst == IA64_BUS_SPACE_IO))
46 ? addr : (uintptr_t)pmap_mapdev(addr, size);
52 bus_space_unmap(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
56 pmap_unmapdev(bsh, size);
60 bus_space_read_io_1(u_long port)
65 v = ia64_ld1(__PIO_ADDR(port));
72 bus_space_read_io_2(u_long port)
77 v = ia64_ld2(__PIO_ADDR(port));
84 bus_space_read_io_4(u_long port)
89 v = ia64_ld4(__PIO_ADDR(port));
97 bus_space_read_io_8(u_long port)
103 bus_space_write_io_1(u_long port, uint8_t val)
107 ia64_st1(__PIO_ADDR(port), val);
113 bus_space_write_io_2(u_long port, uint16_t val)
117 ia64_st2(__PIO_ADDR(port), val);
123 bus_space_write_io_4(u_long port, uint32_t val)
127 ia64_st4(__PIO_ADDR(port), val);
134 bus_space_write_io_8(u_long port, uint64_t val)
140 bus_space_read_multi_io_1(u_long port, uint8_t *ptr, size_t count)
144 *ptr++ = bus_space_read_io_1(port);
148 bus_space_read_multi_io_2(u_long port, uint16_t *ptr, size_t count)
152 *ptr++ = bus_space_read_io_2(port);
156 bus_space_read_multi_io_4(u_long port, uint32_t *ptr, size_t count)
160 *ptr++ = bus_space_read_io_4(port);
165 bus_space_read_multi_io_8(u_long port, uint64_t *ptr, size_t count)
171 bus_space_write_multi_io_1(u_long port, const uint8_t *ptr, size_t count)
175 bus_space_write_io_1(port, *ptr++);
179 bus_space_write_multi_io_2(u_long port, const uint16_t *ptr, size_t count)
183 bus_space_write_io_2(port, *ptr++);
187 bus_space_write_multi_io_4(u_long port, const uint32_t *ptr, size_t count)
191 bus_space_write_io_4(port, *ptr++);
196 bus_space_write_multi_io_8(u_long port, const uint64_t *ptr, size_t count)
202 bus_space_read_region_io_1(u_long port, uint8_t *ptr, size_t count)
205 while (count-- > 0) {
206 *ptr++ = bus_space_read_io_1(port);
212 bus_space_read_region_io_2(u_long port, uint16_t *ptr, size_t count)
215 while (count-- > 0) {
216 *ptr++ = bus_space_read_io_2(port);
222 bus_space_read_region_io_4(u_long port, uint32_t *ptr, size_t count)
225 while (count-- > 0) {
226 *ptr++ = bus_space_read_io_4(port);
232 void bus_space_read_region_io_8(u_long, uint64_t *, size_t);
236 bus_space_write_region_io_1(u_long port, const uint8_t *ptr, size_t count)
239 while (count-- > 0) {
240 bus_space_write_io_1(port, *ptr++);
246 bus_space_write_region_io_2(u_long port, const uint16_t *ptr, size_t count)
249 while (count-- > 0) {
250 bus_space_write_io_2(port, *ptr++);
256 bus_space_write_region_io_4(u_long port, const uint32_t *ptr, size_t count)
259 while (count-- > 0) {
260 bus_space_write_io_4(port, *ptr++);
267 bus_space_write_region_io_8(u_long port, const uint64_t *ptr, size_t count)
273 bus_space_set_region_io_1(u_long port, uint8_t val, size_t count)
276 while (count-- > 0) {
277 bus_space_write_io_1(port, val);
283 bus_space_set_region_io_2(u_long port, uint16_t val, size_t count)
286 while (count-- > 0) {
287 bus_space_write_io_2(port, val);
293 bus_space_set_region_io_4(u_long port, uint32_t val, size_t count)
296 while (count-- > 0) {
297 bus_space_write_io_4(port, val);
304 bus_space_set_region_io_8(u_long port, uint64_t val, size_t count)
310 bus_space_copy_region_io_1(u_long src, u_long dst, size_t count)
322 while (count-- > 0) {
323 val = bus_space_read_io_1(src);
324 bus_space_write_io_1(dst, val);
331 bus_space_copy_region_io_2(u_long src, u_long dst, size_t count)
337 src += 2 * (count - 1);
338 dst += 2 * (count - 1);
343 while (count-- > 0) {
344 val = bus_space_read_io_2(src);
345 bus_space_write_io_2(dst, val);
352 bus_space_copy_region_io_4(u_long src, u_long dst, size_t count)
358 src += 4 * (count - 1);
359 dst += 4 * (count - 1);
364 while (count-- > 0) {
365 val = bus_space_read_io_4(src);
366 bus_space_write_io_4(dst, val);
374 bus_space_copy_region_io_8(u_long src, u_long dst, size_t count)