Updated to fedora-glibc-20090218T1534
[glibc.git] / sysdeps / unix / sysv / linux / i386 / sys / io.h
blob128c2caac7b4edfacf1689b2236e2546cce86764
1 /* Copyright (C) 1996, 2000, 2009 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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. */
19 #ifndef _SYS_IO_H
20 #define _SYS_IO_H 1
22 #include <features.h>
24 __BEGIN_DECLS
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.
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;
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;
41 #if defined __GNUC__ && __GNUC__ >= 2
43 static __inline unsigned char
44 inb (unsigned short int __port)
46 unsigned char _v;
48 __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (__port));
49 return _v;
52 static __inline unsigned char
53 inb_p (unsigned short int __port)
55 unsigned char _v;
57 __asm__ __volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (__port));
58 return _v;
61 static __inline unsigned short int
62 inw (unsigned short int __port)
64 unsigned short _v;
66 __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (__port));
67 return _v;
70 static __inline unsigned short int
71 inw_p (unsigned short int __port)
73 unsigned short int _v;
75 __asm__ __volatile__ ("inw %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (__port));
76 return _v;
79 static __inline unsigned int
80 inl (unsigned short int __port)
82 unsigned int _v;
84 __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (__port));
85 return _v;
88 static __inline unsigned int
89 inl_p (unsigned short int __port)
91 unsigned int _v;
92 __asm__ __volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (_v)
93 :"Nd" (__port));
94 return _v;
97 static __inline void
98 outb (unsigned char value, unsigned short int __port)
100 __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (__port));
103 static __inline void
104 outb_p (unsigned char value, unsigned short int __port)
106 __asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (value),
107 "Nd" (__port));
110 static __inline void
111 outw (unsigned short int value, unsigned short int __port)
113 __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (__port));
117 static __inline void
118 outw_p (unsigned short int value, unsigned short int __port)
120 __asm__ __volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (value),
121 "Nd" (__port));
124 static __inline void
125 outl (unsigned int value, unsigned short int __port)
127 __asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (__port));
130 static __inline void
131 outl_p (unsigned int value, unsigned short int __port)
133 __asm__ __volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (value),
134 "Nd" (__port));
137 static __inline void
138 insb (unsigned short int __port, void *__addr, unsigned long int __count)
140 __asm__ __volatile__ ("cld ; rep ; insb":"=D" (__addr), "=c" (__count)
141 :"d" (__port), "0" (__addr), "1" (__count));
144 static __inline void
145 insw (unsigned short int __port, void *__addr, unsigned long int __count)
147 __asm__ __volatile__ ("cld ; rep ; insw":"=D" (__addr), "=c" (__count)
148 :"d" (__port), "0" (__addr), "1" (__count));
151 static __inline void
152 insl (unsigned short int __port, void *__addr, unsigned long int __count)
154 __asm__ __volatile__ ("cld ; rep ; insl":"=D" (__addr), "=c" (__count)
155 :"d" (__port), "0" (__addr), "1" (__count));
158 static __inline void
159 outsb (unsigned short int __port, const void *__addr,
160 unsigned long int __count)
162 __asm__ __volatile__ ("cld ; rep ; outsb":"=S" (__addr), "=c" (__count)
163 :"d" (__port), "0" (__addr), "1" (__count));
166 static __inline void
167 outsw (unsigned short int __port, const void *__addr,
168 unsigned long int __count)
170 __asm__ __volatile__ ("cld ; rep ; outsw":"=S" (__addr), "=c" (__count)
171 :"d" (__port), "0" (__addr), "1" (__count));
174 static __inline void
175 outsl (unsigned short int __port, const void *__addr,
176 unsigned long int __count)
178 __asm__ __volatile__ ("cld ; rep ; outsl":"=S" (__addr), "=c" (__count)
179 :"d" (__port), "0" (__addr), "1" (__count));
182 #endif /* GNU C */
184 __END_DECLS
185 #endif /* _SYS_IO_H */