]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/ia64/include/cpufunc.h
This commit was generated by cvs2svn to compensate for changes in r84685,
[FreeBSD/FreeBSD.git] / sys / ia64 / include / cpufunc.h
1 /*-
2  * Copyright (c) 1998 Doug Rabson
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  * $FreeBSD$
27  */
28
29 #ifndef _MACHINE_CPUFUNC_H_
30 #define _MACHINE_CPUFUNC_H_
31
32 #ifdef _KERNEL
33
34 #include <sys/types.h>
35 #include <machine/ia64_cpu.h>
36
37 #ifdef __GNUC__
38
39 static __inline void
40 breakpoint(void)
41 {
42         __asm __volatile("break 0x80100"); /* XXX use linux value */
43 }
44
45 #endif
46
47 extern u_int64_t        ia64_port_base;
48
49 static __inline volatile void *
50 ia64_port_address(u_int port)
51 {
52     return (volatile void *)(ia64_port_base
53                              | ((port >> 2) << 12)
54                              | (port & ((1 << 12) - 1)));
55 }
56
57 static __inline volatile void *
58 ia64_memory_address(u_int64_t addr)
59 {
60         return (volatile void *) IA64_PHYS_TO_RR6(addr);
61 }
62
63 static __inline u_int8_t
64 inb(u_int port)
65 {
66         volatile u_int8_t *p = ia64_port_address(port);
67         u_int8_t v = *p;
68         ia64_mf_a();
69         ia64_mf();
70         return v;
71 }
72
73 static __inline u_int16_t
74 inw(u_int port)
75 {
76         volatile u_int16_t *p = ia64_port_address(port);
77         u_int16_t v = *p;
78         ia64_mf_a();
79         ia64_mf();
80         return v;
81 }
82
83 static __inline u_int32_t
84 inl(u_int port)
85 {
86         volatile u_int32_t *p = ia64_port_address(port);
87         u_int32_t v = *p;
88         ia64_mf_a();
89         ia64_mf();
90         return v;
91 }
92
93 static __inline void
94 insb(u_int port, void *addr, size_t count)
95 {
96         u_int8_t *p = addr;
97         while (count--)
98                 *p++ = inb(port);
99 }
100
101 static __inline void
102 insw(u_int port, void *addr, size_t count)
103 {
104         u_int16_t *p = addr;
105         while (count--)
106                 *p++ = inw(port);
107 }
108
109 static __inline void
110 insl(u_int port, void *addr, size_t count)
111 {
112         u_int32_t *p = addr;
113         while (count--)
114                 *p++ = inl(port);
115 }
116
117 static __inline void
118 outb(u_int port, u_int8_t data)
119 {
120         volatile u_int8_t *p = ia64_port_address(port);
121         *p = data;
122         ia64_mf_a();
123         ia64_mf();
124 }
125
126 static __inline void
127 outw(u_int port, u_int16_t data)
128 {
129         volatile u_int16_t *p = ia64_port_address(port);
130         *p = data;
131         ia64_mf_a();
132         ia64_mf();
133 }
134
135 static __inline void
136 outl(u_int port, u_int32_t data)
137 {
138         volatile u_int32_t *p = ia64_port_address(port);
139         *p = data;
140         ia64_mf_a();
141         ia64_mf();
142 }
143
144 static __inline void
145 outsb(u_int port, const void *addr, size_t count)
146 {
147         const u_int8_t *p = addr;
148         while (count--)
149                 outb(port, *p++);
150 }
151
152 static __inline void
153 outsw(u_int port, const void *addr, size_t count)
154 {
155         const u_int16_t *p = addr;
156         while (count--)
157                 outw(port, *p++);
158 }
159
160 static __inline void
161 outsl(u_int port, const void *addr, size_t count)
162 {
163         const u_int32_t *p = addr;
164         while (count--)
165                 outl(port, *p++);
166 }
167
168 static __inline u_int8_t
169 readb(u_int addr)
170 {
171         volatile u_int8_t *p = ia64_memory_address(addr);
172         u_int8_t v = *p;
173         ia64_mf_a();
174         ia64_mf();
175         return v;
176 }
177
178 static __inline u_int16_t
179 readw(u_int addr)
180 {
181         volatile u_int16_t *p = ia64_memory_address(addr);
182         u_int16_t v = *p;
183         ia64_mf_a();
184         ia64_mf();
185         return v;
186 }
187
188 static __inline u_int32_t
189 readl(u_int addr)
190 {
191         volatile u_int32_t *p = ia64_memory_address(addr);
192         u_int32_t v = *p;
193         ia64_mf_a();
194         ia64_mf();
195         return v;
196 }
197
198 static __inline void
199 writeb(u_int addr, u_int8_t data)
200 {
201         volatile u_int8_t *p = ia64_memory_address(addr);
202         *p = data;
203         ia64_mf_a();
204         ia64_mf();
205 }
206
207 static __inline void
208 writew(u_int addr, u_int16_t data)
209 {
210         volatile u_int16_t *p = ia64_memory_address(addr);
211         *p = data;
212         ia64_mf_a();
213         ia64_mf();
214 }
215
216 static __inline void
217 writel(u_int addr, u_int32_t data)
218 {
219         volatile u_int32_t *p = ia64_memory_address(addr);
220         *p = data;
221         ia64_mf_a();
222         ia64_mf();
223 }
224
225 static __inline void
226 memcpy_fromio(u_int8_t *addr, size_t ofs, size_t count)
227 {
228         volatile u_int8_t *p = ia64_memory_address(ofs);
229         while (count--)
230                 *addr++ = *p++;
231 }
232
233 static __inline void
234 memcpy_io(size_t dst, size_t src, size_t count)
235 {
236         volatile u_int8_t *dp = ia64_memory_address(dst);
237         volatile u_int8_t *sp = ia64_memory_address(src);
238         while (count--)
239                 *dp++ = *sp++;
240 }
241
242 static __inline void
243 memcpy_toio(size_t ofs, u_int8_t *addr, size_t count)
244 {
245         volatile u_int8_t *p = ia64_memory_address(ofs);
246         while (count--)
247                 *p++ = *addr++;
248 }
249
250 static __inline void
251 memset_io(size_t ofs, u_int8_t value, size_t count)
252 {
253         volatile u_int8_t *p = ia64_memory_address(ofs);
254         while (count--)
255                 *p++ = value;
256 }
257
258 static __inline void
259 memsetw(u_int16_t *addr, int val, size_t size)
260 {
261         while (size--)
262                 *addr++ = val;
263 }
264
265 static __inline void
266 memsetw_io(size_t ofs, u_int16_t value, size_t count)
267 {
268         volatile u_int16_t *p = ia64_memory_address(ofs);
269         while (count--)
270                 *p++ = value;
271 }
272
273 static __inline void
274 disable_intr(void)
275 {
276         __asm __volatile ("rsm psr.i;;");
277 }
278
279 static __inline void
280 enable_intr(void)
281 {
282         __asm __volatile (";; ssm psr.i;; srlz.d");
283 }
284
285 static __inline critical_t
286 critical_enter(void)
287 {
288         critical_t psr;
289
290         __asm __volatile ("mov %0=psr;;" : "=r" (psr));
291         disable_intr();
292         return (psr);
293 }
294
295 static __inline void
296 critical_exit(critical_t psr)
297 {
298         __asm __volatile ("mov psr.l=%0;; srlz.d" :: "r" (psr));
299 }
300
301 #endif /* _KERNEL */
302
303 #endif /* !_MACHINE_CPUFUNC_H_ */