]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/i386/sys/io.h
128c2caac7b4edfacf1689b2236e2546cce86764
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / i386 / sys / io.h
1 /* Copyright (C) 1996, 2000, 2009 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
18
19 #ifndef _SYS_IO_H
20 #define _SYS_IO_H 1
21
22 #include <features.h>
23
24 __BEGIN_DECLS
25
26 /* If TURN_ON is TRUE, request for permission to do direct i/o on the
27 port numbers in the range [FROM,FROM+NUM-1]. Otherwise, turn I/O
28 permission off for that range. This call requires root privileges.
29
30 Portability note: not all Linux platforms support this call. Most
31 platforms based on the PC I/O architecture probably will, however.
32 E.g., Linux/Alpha for Alpha PCs supports this. */
33 extern int ioperm (unsigned long int __from, unsigned long int __num,
34 int __turn_on) __THROW;
35
36 /* Set the I/O privilege level to LEVEL. If LEVEL>3, permission to
37 access any I/O port is granted. This call requires root
38 privileges. */
39 extern int iopl (int __level) __THROW;
40
41 #if defined __GNUC__ && __GNUC__ >= 2
42
43 static __inline unsigned char
44 inb (unsigned short int __port)
45 {
46 unsigned char _v;
47
48 __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (__port));
49 return _v;
50 }
51
52 static __inline unsigned char
53 inb_p (unsigned short int __port)
54 {
55 unsigned char _v;
56
57 __asm__ __volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (__port));
58 return _v;
59 }
60
61 static __inline unsigned short int
62 inw (unsigned short int __port)
63 {
64 unsigned short _v;
65
66 __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (__port));
67 return _v;
68 }
69
70 static __inline unsigned short int
71 inw_p (unsigned short int __port)
72 {
73 unsigned short int _v;
74
75 __asm__ __volatile__ ("inw %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (__port));
76 return _v;
77 }
78
79 static __inline unsigned int
80 inl (unsigned short int __port)
81 {
82 unsigned int _v;
83
84 __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (__port));
85 return _v;
86 }
87
88 static __inline unsigned int
89 inl_p (unsigned short int __port)
90 {
91 unsigned int _v;
92 __asm__ __volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (_v)
93 :"Nd" (__port));
94 return _v;
95 }
96
97 static __inline void
98 outb (unsigned char value, unsigned short int __port)
99 {
100 __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (__port));
101 }
102
103 static __inline void
104 outb_p (unsigned char value, unsigned short int __port)
105 {
106 __asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (value),
107 "Nd" (__port));
108 }
109
110 static __inline void
111 outw (unsigned short int value, unsigned short int __port)
112 {
113 __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (__port));
114
115 }
116
117 static __inline void
118 outw_p (unsigned short int value, unsigned short int __port)
119 {
120 __asm__ __volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (value),
121 "Nd" (__port));
122 }
123
124 static __inline void
125 outl (unsigned int value, unsigned short int __port)
126 {
127 __asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (__port));
128 }
129
130 static __inline void
131 outl_p (unsigned int value, unsigned short int __port)
132 {
133 __asm__ __volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (value),
134 "Nd" (__port));
135 }
136
137 static __inline void
138 insb (unsigned short int __port, void *__addr, unsigned long int __count)
139 {
140 __asm__ __volatile__ ("cld ; rep ; insb":"=D" (__addr), "=c" (__count)
141 :"d" (__port), "0" (__addr), "1" (__count));
142 }
143
144 static __inline void
145 insw (unsigned short int __port, void *__addr, unsigned long int __count)
146 {
147 __asm__ __volatile__ ("cld ; rep ; insw":"=D" (__addr), "=c" (__count)
148 :"d" (__port), "0" (__addr), "1" (__count));
149 }
150
151 static __inline void
152 insl (unsigned short int __port, void *__addr, unsigned long int __count)
153 {
154 __asm__ __volatile__ ("cld ; rep ; insl":"=D" (__addr), "=c" (__count)
155 :"d" (__port), "0" (__addr), "1" (__count));
156 }
157
158 static __inline void
159 outsb (unsigned short int __port, const void *__addr,
160 unsigned long int __count)
161 {
162 __asm__ __volatile__ ("cld ; rep ; outsb":"=S" (__addr), "=c" (__count)
163 :"d" (__port), "0" (__addr), "1" (__count));
164 }
165
166 static __inline void
167 outsw (unsigned short int __port, const void *__addr,
168 unsigned long int __count)
169 {
170 __asm__ __volatile__ ("cld ; rep ; outsw":"=S" (__addr), "=c" (__count)
171 :"d" (__port), "0" (__addr), "1" (__count));
172 }
173
174 static __inline void
175 outsl (unsigned short int __port, const void *__addr,
176 unsigned long int __count)
177 {
178 __asm__ __volatile__ ("cld ; rep ; outsl":"=S" (__addr), "=c" (__count)
179 :"d" (__port), "0" (__addr), "1" (__count));
180 }
181
182 #endif /* GNU C */
183
184 __END_DECLS
185 #endif /* _SYS_IO_H */