OSDN Git Service

- adds several config-options to allow for turning off certain features
[uclinux-h8/uClibc.git] / libc / sysdeps / linux / i386 / sys / io.h
1 /* Copyright (C) 1996, 2000 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 defined __UCLIBC_LINUX_SPECIFIC__
27 /* If TURN_ON is TRUE, request for permission to do direct i/o on the
28    port numbers in the range [FROM,FROM+NUM-1].  Otherwise, turn I/O
29    permission off for that range.  This call requires root privileges.
30
31    Portability note: not all Linux platforms support this call.  Most
32    platforms based on the PC I/O architecture probably will, however.
33    E.g., Linux/Alpha for Alpha PCs supports this.  */
34 extern int ioperm (unsigned long int __from, unsigned long int __num,
35                    int __turn_on) __THROW;
36
37 /* Set the I/O privilege level to LEVEL.  If LEVEL>3, permission to
38    access any I/O port is granted.  This call requires root
39    privileges. */
40 extern int iopl (int __level) __THROW;
41 #endif /* __UCLIBC_LINUX_SPECIFIC__ */
42
43 #if defined __GNUC__ && __GNUC__ >= 2
44
45 static __inline unsigned char
46 inb (unsigned short int port)
47 {
48   unsigned char _v;
49
50   __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (port));
51   return _v;
52 }
53
54 static __inline unsigned char
55 inb_p (unsigned short int port)
56 {
57   unsigned char _v;
58
59   __asm__ __volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
60   return _v;
61 }
62
63 static __inline unsigned short int
64 inw (unsigned short int port)
65 {
66   unsigned short _v;
67
68   __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (port));
69   return _v;
70 }
71
72 static __inline unsigned short int
73 inw_p (unsigned short int port)
74 {
75   unsigned short int _v;
76
77   __asm__ __volatile__ ("inw %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
78   return _v;
79 }
80
81 static __inline unsigned int
82 inl (unsigned short int port)
83 {
84   unsigned int _v;
85
86   __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (port));
87   return _v;
88 }
89
90 static __inline unsigned int
91 inl_p (unsigned short int port)
92 {
93   unsigned int _v;
94   __asm__ __volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
95   return _v;
96 }
97
98 static __inline void
99 outb (unsigned char value, unsigned short int port)
100 {
101   __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port));
102 }
103
104 static __inline void
105 outb_p (unsigned char value, unsigned short int port)
106 {
107   __asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (value),
108                         "Nd" (port));
109 }
110
111 static __inline void
112 outw (unsigned short int value, unsigned short int port)
113 {
114   __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (port));
115
116 }
117
118 static __inline void
119 outw_p (unsigned short int value, unsigned short int port)
120 {
121   __asm__ __volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (value),
122                         "Nd" (port));
123 }
124
125 static __inline void
126 outl (unsigned int value, unsigned short int port)
127 {
128   __asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (port));
129 }
130
131 static __inline void
132 outl_p (unsigned int value, unsigned short int port)
133 {
134   __asm__ __volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (value),
135                         "Nd" (port));
136 }
137
138 static __inline void
139 insb (unsigned short int port, void *addr, unsigned long int count)
140 {
141   __asm__ __volatile__ ("cld ; rep ; insb":"=D" (addr),
142                         "=c" (count):"d" (port), "0" (addr), "1" (count));
143 }
144
145 static __inline void
146 insw (unsigned short int port, void *addr, unsigned long int count)
147 {
148   __asm__ __volatile__ ("cld ; rep ; insw":"=D" (addr),
149                         "=c" (count):"d" (port), "0" (addr), "1" (count));
150 }
151
152 static __inline void
153 insl (unsigned short int port, void *addr, unsigned long int count)
154 {
155   __asm__ __volatile__ ("cld ; rep ; insl":"=D" (addr),
156                         "=c" (count):"d" (port), "0" (addr), "1" (count));
157 }
158
159 static __inline void
160 outsb (unsigned short int port, const void *addr, unsigned long int count)
161 {
162   __asm__ __volatile__ ("cld ; rep ; outsb":"=S" (addr),
163                         "=c" (count):"d" (port), "0" (addr), "1" (count));
164 }
165
166 static __inline void
167 outsw (unsigned short int port, const void *addr, unsigned long int count)
168 {
169   __asm__ __volatile__ ("cld ; rep ; outsw":"=S" (addr),
170                         "=c" (count):"d" (port), "0" (addr), "1" (count));
171 }
172
173 static __inline void
174 outsl (unsigned short int port, const void *addr, unsigned long int count)
175 {
176   __asm__ __volatile__ ("cld ; rep ; outsl":"=S" (addr),
177                         "=c" (count):"d" (port), "0" (addr), "1" (count));
178 }
179
180 #endif  /* GNU C */
181
182 __END_DECLS
183 #endif /* _SYS_IO_H */