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, see
16 <http://www.gnu.org/licenses/>. */
17
18 #ifndef _SYS_IO_H
19 #define _SYS_IO_H 1
20
21 #include <features.h>
22
23 __BEGIN_DECLS
24
25 #if defined __UCLIBC_LINUX_SPECIFIC__
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
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;
35
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;
40 #endif /* __UCLIBC_LINUX_SPECIFIC__ */
41
42 #if defined __GNUC__ && __GNUC__ >= 2
43
44 static __inline unsigned char
inb(unsigned short int port)45 inb (unsigned short int port)
46 {
47 unsigned char _v;
48
49 __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (port));
50 return _v;
51 }
52
53 static __inline unsigned char
inb_p(unsigned short int port)54 inb_p (unsigned short int port)
55 {
56 unsigned char _v;
57
58 __asm__ __volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
59 return _v;
60 }
61
62 static __inline unsigned short int
inw(unsigned short int port)63 inw (unsigned short int port)
64 {
65 unsigned short _v;
66
67 __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (port));
68 return _v;
69 }
70
71 static __inline unsigned short int
inw_p(unsigned short int port)72 inw_p (unsigned short int port)
73 {
74 unsigned short int _v;
75
76 __asm__ __volatile__ ("inw %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
77 return _v;
78 }
79
80 static __inline unsigned int
inl(unsigned short int port)81 inl (unsigned short int port)
82 {
83 unsigned int _v;
84
85 __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (port));
86 return _v;
87 }
88
89 static __inline unsigned int
inl_p(unsigned short int port)90 inl_p (unsigned short int port)
91 {
92 unsigned int _v;
93 __asm__ __volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
94 return _v;
95 }
96
97 static __inline void
outb(unsigned char value,unsigned short int port)98 outb (unsigned char value, unsigned short int port)
99 {
100 __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port));
101 }
102
103 static __inline void
outb_p(unsigned char value,unsigned short int port)104 outb_p (unsigned char value, unsigned short int port)
105 {
106 __asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (value),
107 "Nd" (port));
108 }
109
110 static __inline void
outw(unsigned short int value,unsigned short int port)111 outw (unsigned short int value, unsigned short int port)
112 {
113 __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (port));
114
115 }
116
117 static __inline void
outw_p(unsigned short int value,unsigned short int port)118 outw_p (unsigned short int value, unsigned short int port)
119 {
120 __asm__ __volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (value),
121 "Nd" (port));
122 }
123
124 static __inline void
outl(unsigned int value,unsigned short int port)125 outl (unsigned int value, unsigned short int port)
126 {
127 __asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (port));
128 }
129
130 static __inline void
outl_p(unsigned int value,unsigned short int port)131 outl_p (unsigned int value, unsigned short int port)
132 {
133 __asm__ __volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (value),
134 "Nd" (port));
135 }
136
137 static __inline void
insb(unsigned short int port,void * addr,unsigned long int count)138 insb (unsigned short int port, void *addr, unsigned long int count)
139 {
140 __asm__ __volatile__ ("cld ; rep ; insb":"=D" (addr),
141 "=c" (count):"d" (port), "0" (addr), "1" (count));
142 }
143
144 static __inline void
insw(unsigned short int port,void * addr,unsigned long int count)145 insw (unsigned short int port, void *addr, unsigned long int count)
146 {
147 __asm__ __volatile__ ("cld ; rep ; insw":"=D" (addr),
148 "=c" (count):"d" (port), "0" (addr), "1" (count));
149 }
150
151 static __inline void
insl(unsigned short int port,void * addr,unsigned long int count)152 insl (unsigned short int port, void *addr, unsigned long int count)
153 {
154 __asm__ __volatile__ ("cld ; rep ; insl":"=D" (addr),
155 "=c" (count):"d" (port), "0" (addr), "1" (count));
156 }
157
158 static __inline void
outsb(unsigned short int port,const void * addr,unsigned long int count)159 outsb (unsigned short int port, const void *addr, unsigned long int count)
160 {
161 __asm__ __volatile__ ("cld ; rep ; outsb":"=S" (addr),
162 "=c" (count):"d" (port), "0" (addr), "1" (count));
163 }
164
165 static __inline void
outsw(unsigned short int port,const void * addr,unsigned long int count)166 outsw (unsigned short int port, const void *addr, unsigned long int count)
167 {
168 __asm__ __volatile__ ("cld ; rep ; outsw":"=S" (addr),
169 "=c" (count):"d" (port), "0" (addr), "1" (count));
170 }
171
172 static __inline void
outsl(unsigned short int port,const void * addr,unsigned long int count)173 outsl (unsigned short int port, const void *addr, unsigned long int count)
174 {
175 __asm__ __volatile__ ("cld ; rep ; outsl":"=S" (addr),
176 "=c" (count):"d" (port), "0" (addr), "1" (count));
177 }
178
179 #endif /* GNU C */
180
181 __END_DECLS
182 #endif /* _SYS_IO_H */
183