Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / unix / sysv / linux / x86 / sys / io.h
blobe30d37fe21518a3b663b857fa8a40580597ed478
1 /* Copyright (C) 1996-2014 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, see
16 <http://www.gnu.org/licenses/>. */
18 #ifndef _SYS_IO_H
19 #define _SYS_IO_H 1
21 #include <features.h>
23 __BEGIN_DECLS
25 /* If TURN_ON is TRUE, request for permission to do direct i/o on the
26 port numbers in the range [FROM,FROM+NUM-1]. Otherwise, turn I/O
27 permission off for that range. This call requires root privileges.
29 Portability note: not all Linux platforms support this call. Most
30 platforms based on the PC I/O architecture probably will, however.
31 E.g., Linux/Alpha for Alpha PCs supports this. */
32 extern int ioperm (unsigned long int __from, unsigned long int __num,
33 int __turn_on) __THROW;
35 /* Set the I/O privilege level to LEVEL. If LEVEL>3, permission to
36 access any I/O port is granted. This call requires root
37 privileges. */
38 extern int iopl (int __level) __THROW;
40 #if defined __GNUC__ && __GNUC__ >= 2
42 static __inline unsigned char
43 inb (unsigned short int __port)
45 unsigned char _v;
47 __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (__port));
48 return _v;
51 static __inline unsigned char
52 inb_p (unsigned short int __port)
54 unsigned char _v;
56 __asm__ __volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (__port));
57 return _v;
60 static __inline unsigned short int
61 inw (unsigned short int __port)
63 unsigned short _v;
65 __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (__port));
66 return _v;
69 static __inline unsigned short int
70 inw_p (unsigned short int __port)
72 unsigned short int _v;
74 __asm__ __volatile__ ("inw %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (__port));
75 return _v;
78 static __inline unsigned int
79 inl (unsigned short int __port)
81 unsigned int _v;
83 __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (__port));
84 return _v;
87 static __inline unsigned int
88 inl_p (unsigned short int __port)
90 unsigned int _v;
91 __asm__ __volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (__port));
92 return _v;
95 static __inline void
96 outb (unsigned char __value, unsigned short int __port)
98 __asm__ __volatile__ ("outb %b0,%w1": :"a" (__value), "Nd" (__port));
101 static __inline void
102 outb_p (unsigned char __value, unsigned short int __port)
104 __asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (__value),
105 "Nd" (__port));
108 static __inline void
109 outw (unsigned short int __value, unsigned short int __port)
111 __asm__ __volatile__ ("outw %w0,%w1": :"a" (__value), "Nd" (__port));
115 static __inline void
116 outw_p (unsigned short int __value, unsigned short int __port)
118 __asm__ __volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (__value),
119 "Nd" (__port));
122 static __inline void
123 outl (unsigned int __value, unsigned short int __port)
125 __asm__ __volatile__ ("outl %0,%w1": :"a" (__value), "Nd" (__port));
128 static __inline void
129 outl_p (unsigned int __value, unsigned short int __port)
131 __asm__ __volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (__value),
132 "Nd" (__port));
135 static __inline void
136 insb (unsigned short int __port, void *__addr, unsigned long int __count)
138 __asm__ __volatile__ ("cld ; rep ; insb":"=D" (__addr), "=c" (__count)
139 :"d" (__port), "0" (__addr), "1" (__count));
142 static __inline void
143 insw (unsigned short int __port, void *__addr, unsigned long int __count)
145 __asm__ __volatile__ ("cld ; rep ; insw":"=D" (__addr), "=c" (__count)
146 :"d" (__port), "0" (__addr), "1" (__count));
149 static __inline void
150 insl (unsigned short int __port, void *__addr, unsigned long int __count)
152 __asm__ __volatile__ ("cld ; rep ; insl":"=D" (__addr), "=c" (__count)
153 :"d" (__port), "0" (__addr), "1" (__count));
156 static __inline void
157 outsb (unsigned short int __port, const void *__addr,
158 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,
166 unsigned long int __count)
168 __asm__ __volatile__ ("cld ; rep ; outsw":"=S" (__addr), "=c" (__count)
169 :"d" (__port), "0" (__addr), "1" (__count));
172 static __inline void
173 outsl (unsigned short int __port, const void *__addr,
174 unsigned long int __count)
176 __asm__ __volatile__ ("cld ; rep ; outsl":"=S" (__addr), "=c" (__count)
177 :"d" (__port), "0" (__addr), "1" (__count));
180 #endif /* GNU C */
182 __END_DECLS
183 #endif /* _SYS_IO_H */