3 * Copyright (c) 2013 Hans Petter Selasky. All rights reserved.
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 <bsd_kernel.h>
41 bus_space_read_multi_1(bus_space_tag_t t, bus_space_handle_t h,
42 bus_size_t offset, uint8_t *datap, bus_size_t count)
45 *datap++ = bus_space_read_1(t, h, offset);
50 bus_space_read_multi_2(bus_space_tag_t t, bus_space_handle_t h,
51 bus_size_t offset, uint16_t *datap, bus_size_t count)
54 *datap++ = bus_space_read_2(t, h, offset);
59 bus_space_read_multi_4(bus_space_tag_t t, bus_space_handle_t h,
60 bus_size_t offset, uint32_t *datap, bus_size_t count)
65 *datap++ = *((volatile uint32_t *)h);
70 bus_space_write_multi_1(bus_space_tag_t t, bus_space_handle_t h,
71 bus_size_t offset, uint8_t *datap, bus_size_t count)
74 uint8_t temp = *datap++;
76 bus_space_write_1(t, h, offset, temp);
81 bus_space_write_multi_2(bus_space_tag_t t, bus_space_handle_t h,
82 bus_size_t offset, uint16_t *datap, bus_size_t count)
85 uint16_t temp = *datap++;
87 bus_space_write_2(t, h, offset, temp);
92 bus_space_write_multi_4(bus_space_tag_t t, bus_space_handle_t h,
93 bus_size_t offset, uint32_t *datap, bus_size_t count)
98 *((volatile uint32_t *)h) = *datap++;
103 bus_space_write_1(bus_space_tag_t t, bus_space_handle_t h,
104 bus_size_t offset, uint8_t data)
106 *((volatile uint8_t *)(h + offset)) = data;
110 bus_space_write_2(bus_space_tag_t t, bus_space_handle_t h,
111 bus_size_t offset, uint16_t data)
113 *((volatile uint16_t *)(h + offset)) = data;
117 bus_space_write_4(bus_space_tag_t t, bus_space_handle_t h,
118 bus_size_t offset, uint32_t data)
120 *((volatile uint32_t *)(h + offset)) = data;
124 bus_space_read_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset)
126 return (*((volatile uint8_t *)(h + offset)));
130 bus_space_read_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset)
132 return (*((volatile uint16_t *)(h + offset)));
136 bus_space_read_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset)
138 return (*((volatile uint32_t *)(h + offset)));
142 bus_space_read_region_1(bus_space_tag_t t, bus_space_handle_t h,
143 bus_size_t offset, uint8_t *datap, bus_size_t count)
148 *datap++ = *((volatile uint8_t *)h);
154 bus_space_write_region_1(bus_space_tag_t t, bus_space_handle_t h,
155 bus_size_t offset, uint8_t *datap, bus_size_t count)
160 *((volatile uint8_t *)h) = *datap++;
166 bus_space_read_region_4(bus_space_tag_t t, bus_space_handle_t h,
167 bus_size_t offset, uint32_t *datap, bus_size_t count)
169 enum { BURST = sizeof(struct burst) / 4 };
173 while (count >= BURST) {
174 *(struct burst *)datap = *((/* volatile */ struct burst *)h);
182 *datap++ = *((volatile uint32_t *)h);
188 bus_space_write_region_4(bus_space_tag_t t, bus_space_handle_t h,
189 bus_size_t offset, uint32_t *datap, bus_size_t count)
191 enum { BURST = sizeof(struct burst) / 4 };
195 while (count >= BURST) {
196 *((/* volatile */ struct burst *)h) = *(struct burst *)datap;
204 *((volatile uint32_t *)h) = *datap++;