]> CyberLeo.Net >> Repos - FreeBSD/stable/8.git/blob - sys/ia64/ia64/bus_machdep.c
MFC rev 201269, 201373:
[FreeBSD/stable/8.git] / sys / ia64 / ia64 / bus_machdep.c
1 /*-
2  * Copyright (c) 2009 Marcel Moolenaar
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
13  *
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
24  * SUCH DAMAGE.
25  */
26
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29
30 #include <sys/types.h>
31 #include <machine/bus.h>
32
33 extern u_long ia64_port_base;
34
35 #define __PIO_ADDR(port)        \
36         (void *)(ia64_port_base | (((port) & 0xfffc) << 10) | ((port) & 0xFFF))
37
38 uint8_t
39 bus_space_read_io_1(u_long port)
40 {
41         uint8_t v;
42
43         ia64_mf();
44         v = ia64_ld1(__PIO_ADDR(port));
45         ia64_mf_a();
46         ia64_mf();
47         return (v);
48 }
49
50 uint16_t
51 bus_space_read_io_2(u_long port)
52 {
53         uint16_t v;
54
55         ia64_mf();
56         v = ia64_ld2(__PIO_ADDR(port));
57         ia64_mf_a();
58         ia64_mf();
59         return (v);
60 }
61
62 uint32_t
63 bus_space_read_io_4(u_long port)
64 {
65         uint32_t v;
66
67         ia64_mf();
68         v = ia64_ld4(__PIO_ADDR(port));
69         ia64_mf_a();
70         ia64_mf();
71         return (v);
72 }
73
74 #if 0
75 uint64_t
76 bus_space_read_io_8(u_long port)
77 {
78 }
79 #endif
80
81 void
82 bus_space_write_io_1(u_long port, uint8_t val)
83 {
84
85         ia64_mf();
86         ia64_st1(__PIO_ADDR(port), val);
87         ia64_mf_a();
88         ia64_mf();
89 }
90
91 void
92 bus_space_write_io_2(u_long port, uint16_t val)
93 {
94
95         ia64_mf();
96         ia64_st2(__PIO_ADDR(port), val);
97         ia64_mf_a();
98         ia64_mf();
99 }
100
101 void
102 bus_space_write_io_4(u_long port, uint32_t val)
103 {
104
105         ia64_mf();
106         ia64_st4(__PIO_ADDR(port), val);
107         ia64_mf_a();
108         ia64_mf();
109 }
110
111 #if 0
112 void
113 bus_space_write_io_8(u_long port, uint64_t val)
114 {
115 }
116 #endif
117
118 void
119 bus_space_read_multi_io_1(u_long port, uint8_t *ptr, size_t count)
120 {
121
122         while (count-- > 0)
123                 *ptr++ = bus_space_read_io_1(port);
124 }
125
126 void
127 bus_space_read_multi_io_2(u_long port, uint16_t *ptr, size_t count)
128 {
129
130         while (count-- > 0)
131                 *ptr++ = bus_space_read_io_2(port);
132 }
133
134 void
135 bus_space_read_multi_io_4(u_long port, uint32_t *ptr, size_t count)
136 {
137
138         while (count-- > 0)
139                 *ptr++ = bus_space_read_io_4(port);
140 }
141
142 #if 0
143 void
144 bus_space_read_multi_io_8(u_long port, uint64_t *ptr, size_t count)
145 {
146 }
147 #endif
148
149 void
150 bus_space_write_multi_io_1(u_long port, const uint8_t *ptr, size_t count)
151 {
152
153         while (count-- > 0)
154                 bus_space_write_io_1(port, *ptr++);
155 }
156
157 void
158 bus_space_write_multi_io_2(u_long port, const uint16_t *ptr, size_t count)
159 {
160
161         while (count-- > 0)
162                 bus_space_write_io_2(port, *ptr++);
163 }
164
165 void
166 bus_space_write_multi_io_4(u_long port, const uint32_t *ptr, size_t count)
167 {
168
169         while (count-- > 0)
170                 bus_space_write_io_4(port, *ptr++);
171 }
172
173 #if 0
174 void
175 bus_space_write_multi_io_8(u_long port, const uint64_t *ptr, size_t count)
176 {
177 }
178 #endif
179
180 void
181 bus_space_read_region_io_1(u_long port, uint8_t *ptr, size_t count)
182 {
183
184         while (count-- > 0) {
185                 *ptr++ = bus_space_read_io_1(port);
186                 port += 1;
187         }
188 }
189
190 void
191 bus_space_read_region_io_2(u_long port, uint16_t *ptr, size_t count) 
192 {
193
194         while (count-- > 0) {
195                 *ptr++ = bus_space_read_io_2(port);
196                 port += 2;
197         }
198 }
199
200 void
201 bus_space_read_region_io_4(u_long port, uint32_t *ptr, size_t count) 
202 {
203
204         while (count-- > 0) {
205                 *ptr++ = bus_space_read_io_4(port);
206                 port += 4;
207         }
208 }
209
210 #if 0
211 void bus_space_read_region_io_8(u_long, uint64_t *, size_t);
212 #endif
213
214 void
215 bus_space_write_region_io_1(u_long port, const uint8_t *ptr, size_t count)
216 {
217
218         while (count-- > 0) {
219                 bus_space_write_io_1(port, *ptr++);
220                 port += 1;
221         }
222 }
223
224 void
225 bus_space_write_region_io_2(u_long port, const uint16_t *ptr, size_t count)
226 {
227
228         while (count-- > 0) {
229                 bus_space_write_io_2(port, *ptr++);
230                 port += 2;
231         }
232 }
233
234 void
235 bus_space_write_region_io_4(u_long port, const uint32_t *ptr, size_t count)
236 {
237
238         while (count-- > 0) {
239                 bus_space_write_io_4(port, *ptr++);
240                 port += 4;
241         }
242 }
243
244 #if 0
245 void
246 bus_space_write_region_io_8(u_long port, const uint64_t *ptr, size_t count)
247 {
248 }
249 #endif
250
251 void
252 bus_space_set_region_io_1(u_long port, uint8_t val, size_t count)
253 {
254
255         while (count-- > 0) {
256                 bus_space_write_io_1(port, val);
257                 port += 1;
258         }
259 }
260
261 void
262 bus_space_set_region_io_2(u_long port, uint16_t val, size_t count)
263 {
264
265         while (count-- > 0) {
266                 bus_space_write_io_2(port, val);
267                 port += 2;
268         }
269 }
270
271 void
272 bus_space_set_region_io_4(u_long port, uint32_t val, size_t count)
273 {
274
275         while (count-- > 0) {
276                 bus_space_write_io_4(port, val);
277                 port += 4;
278         }
279 }
280
281 #if 0
282 void
283 bus_space_set_region_io_8(u_long port, uint64_t val, size_t count)
284 {
285 }
286 #endif
287
288 void 
289 bus_space_copy_region_io_1(u_long src, u_long dst, size_t count) 
290 {
291         long delta;
292         uint8_t val;
293
294         if (src < dst) {
295                 src += count - 1;
296                 dst += count - 1;
297                 delta = -1;
298         } else
299                 delta = 1;
300
301         while (count-- > 0) {
302                 val = bus_space_read_io_1(src);
303                 bus_space_write_io_1(dst, val);
304                 src += delta;
305                 dst += delta;
306         }
307 }
308
309 void 
310 bus_space_copy_region_io_2(u_long src, u_long dst, size_t count) 
311 {
312         long delta;
313         uint16_t val;
314
315         if (src < dst) {
316                 src += 2 * (count - 1);
317                 dst += 2 * (count - 1);
318                 delta = -2;
319         } else
320                 delta = 2;
321
322         while (count-- > 0) {
323                 val = bus_space_read_io_2(src);
324                 bus_space_write_io_2(dst, val);
325                 src += delta;
326                 dst += delta;
327         }
328 }
329
330 void 
331 bus_space_copy_region_io_4(u_long src, u_long dst, size_t count) 
332 {
333         long delta;
334         uint32_t val;
335
336         if (src < dst) {
337                 src += 4 * (count - 1);
338                 dst += 4 * (count - 1);
339                 delta = -4;
340         } else
341                 delta = 4;
342
343         while (count-- > 0) {
344                 val = bus_space_read_io_4(src);
345                 bus_space_write_io_4(dst, val);
346                 src += delta;
347                 dst += delta;
348         }
349 }
350
351 #if 0
352 void
353 bus_space_copy_region_io_8(u_long src, u_long dst, size_t count)
354 {
355 }
356 #endif