Updated to fedora-glibc-20090218T1534
[glibc/history.git] / sysdeps / unix / sysv / linux / x86_64 / sys / io.h
blob4f8537f428e2dbbc7d15233c4a053c3d5828bd02
1 /* Copyright (C) 1996, 2000, 2002, 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):"Nd" (__port));
93 return _v;
96 static __inline void
97 outb (unsigned char __value, unsigned short int __port)
99 __asm__ __volatile__ ("outb %b0,%w1": :"a" (__value), "Nd" (__port));
102 static __inline void
103 outb_p (unsigned char __value, unsigned short int __port)
105 __asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (__value),
106 "Nd" (__port));
109 static __inline void
110 outw (unsigned short int __value, unsigned short int __port)
112 __asm__ __volatile__ ("outw %w0,%w1": :"a" (__value), "Nd" (__port));
116 static __inline void
117 outw_p (unsigned short int __value, unsigned short int __port)
119 __asm__ __volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (__value),
120 "Nd" (__port));
123 static __inline void
124 outl (unsigned int __value, unsigned short int __port)
126 __asm__ __volatile__ ("outl %0,%w1": :"a" (__value), "Nd" (__port));
129 static __inline void
130 outl_p (unsigned int __value, unsigned short int __port)
132 __asm__ __volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (__value),
133 "Nd" (__port));
136 static __inline void
137 insb (unsigned short int __port, void *addr, unsigned long int __count)
139 __asm__ __volatile__ ("cld ; rep ; insb":"=D" (addr), "=c" (__count)
140 :"d" (__port), "0" (addr), "1" (__count));
143 static __inline void
144 insw (unsigned short int __port, void *addr, unsigned long int __count)
146 __asm__ __volatile__ ("cld ; rep ; insw":"=D" (addr), "=c" (__count)
147 :"d" (__port), "0" (addr), "1" (__count));
150 static __inline void
151 insl (unsigned short int __port, void *addr, unsigned long int __count)
153 __asm__ __volatile__ ("cld ; rep ; insl":"=D" (addr), "=c" (__count)
154 :"d" (__port), "0" (addr), "1" (__count));
157 static __inline void
158 outsb (unsigned short int __port, const void *addr, unsigned long int __count)
160 __asm__ __volatile__ ("cld ; rep ; outsb":"=S" (addr), "=c" (__count)
161 :"d" (__port), "0" (addr), "1" (__count));
164 static __inline void
165 outsw (unsigned short int __port, const void *addr, unsigned long int __count)
167 __asm__ __volatile__ ("cld ; rep ; outsw":"=S" (addr), "=c" (__count)
168 :"d" (__port), "0" (addr), "1" (__count));
171 static __inline void
172 outsl (unsigned short int __port, const void *addr, unsigned long int __count)
174 __asm__ __volatile__ ("cld ; rep ; outsl":"=S" (addr), "=c" (__count)
175 :"d" (__port), "0" (addr), "1" (__count));
178 #endif /* GNU C */
180 __END_DECLS
181 #endif /* _SYS_IO_H */