Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / mach / hurd / i386 / sys / io.h
blob6ad2d94dedf169f2feb3edc2778caebb32919629
1 /* Access to hardware i/o ports. GNU/x86 version.
2 Copyright (C) 2002-2014 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
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. */
29 extern int ioperm (unsigned long int __from, unsigned long int __num,
30 int __turn_on) __THROW;
32 /* Set the I/O privilege level to LEVEL. If LEVEL>3, permission to
33 access any I/O port is granted. This call requires root
34 privileges. */
35 extern int iopl (int __level) __THROW;
37 #if defined __GNUC__ && __GNUC__ >= 2
39 static __inline unsigned char
40 inb (unsigned short int port)
42 unsigned char _v;
44 __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (port));
45 return _v;
48 static __inline unsigned char
49 inb_p (unsigned short int port)
51 unsigned char _v;
53 __asm__ __volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
54 return _v;
57 static __inline unsigned short int
58 inw (unsigned short int port)
60 unsigned short _v;
62 __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (port));
63 return _v;
66 static __inline unsigned short int
67 inw_p (unsigned short int port)
69 unsigned short int _v;
71 __asm__ __volatile__ ("inw %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
72 return _v;
75 static __inline unsigned int
76 inl (unsigned short int port)
78 unsigned int _v;
80 __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (port));
81 return _v;
84 static __inline unsigned int
85 inl_p (unsigned short int port)
87 unsigned int _v;
88 __asm__ __volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
89 return _v;
92 static __inline void
93 outb (unsigned char value, unsigned short int port)
95 __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port));
98 static __inline void
99 outb_p (unsigned char value, unsigned short int port)
101 __asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (value),
102 "Nd" (port));
105 static __inline void
106 outw (unsigned short int value, unsigned short int port)
108 __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (port));
112 static __inline void
113 outw_p (unsigned short int value, unsigned short int port)
115 __asm__ __volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (value),
116 "Nd" (port));
119 static __inline void
120 outl (unsigned int value, unsigned short int port)
122 __asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (port));
125 static __inline void
126 outl_p (unsigned int value, unsigned short int port)
128 __asm__ __volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (value),
129 "Nd" (port));
132 static __inline void
133 insb (unsigned short int port, void *addr, unsigned long int count)
135 __asm__ __volatile__ ("cld ; rep ; insb":"=D" (addr),
136 "=c" (count):"d" (port), "0" (addr), "1" (count));
139 static __inline void
140 insw (unsigned short int port, void *addr, unsigned long int count)
142 __asm__ __volatile__ ("cld ; rep ; insw":"=D" (addr),
143 "=c" (count):"d" (port), "0" (addr), "1" (count));
146 static __inline void
147 insl (unsigned short int port, void *addr, unsigned long int count)
149 __asm__ __volatile__ ("cld ; rep ; insl":"=D" (addr),
150 "=c" (count):"d" (port), "0" (addr), "1" (count));
153 static __inline void
154 outsb (unsigned short int port, const void *addr, unsigned long int count)
156 __asm__ __volatile__ ("cld ; rep ; outsb":"=S" (addr),
157 "=c" (count):"d" (port), "0" (addr), "1" (count));
160 static __inline void
161 outsw (unsigned short int port, const void *addr, unsigned long int count)
163 __asm__ __volatile__ ("cld ; rep ; outsw":"=S" (addr),
164 "=c" (count):"d" (port), "0" (addr), "1" (count));
167 static __inline void
168 outsl (unsigned short int port, const void *addr, unsigned long int count)
170 __asm__ __volatile__ ("cld ; rep ; outsl":"=S" (addr),
171 "=c" (count):"d" (port), "0" (addr), "1" (count));
174 #endif /* GNU C */
176 __END_DECLS
177 #endif /* _SYS_IO_H */