1 /* Copyright (C) 1996-2017 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/>. */
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
38 extern int iopl (int __level
) __THROW
;
40 #if defined __GNUC__ && __GNUC__ >= 2
42 static __inline
unsigned char
43 inb (unsigned short int __port
)
47 __asm__
__volatile__ ("inb %w1,%0":"=a" (_v
):"Nd" (__port
));
51 static __inline
unsigned char
52 inb_p (unsigned short int __port
)
56 __asm__
__volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v
):"Nd" (__port
));
60 static __inline
unsigned short int
61 inw (unsigned short int __port
)
65 __asm__
__volatile__ ("inw %w1,%0":"=a" (_v
):"Nd" (__port
));
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
));
78 static __inline
unsigned int
79 inl (unsigned short int __port
)
83 __asm__
__volatile__ ("inl %w1,%0":"=a" (_v
):"Nd" (__port
));
87 static __inline
unsigned int
88 inl_p (unsigned short int __port
)
91 __asm__
__volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (_v
):"Nd" (__port
));
96 outb (unsigned char __value
, unsigned short int __port
)
98 __asm__
__volatile__ ("outb %b0,%w1": :"a" (__value
), "Nd" (__port
));
102 outb_p (unsigned char __value
, unsigned short int __port
)
104 __asm__
__volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (__value
),
109 outw (unsigned short int __value
, unsigned short int __port
)
111 __asm__
__volatile__ ("outw %w0,%w1": :"a" (__value
), "Nd" (__port
));
116 outw_p (unsigned short int __value
, unsigned short int __port
)
118 __asm__
__volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (__value
),
123 outl (unsigned int __value
, unsigned short int __port
)
125 __asm__
__volatile__ ("outl %0,%w1": :"a" (__value
), "Nd" (__port
));
129 outl_p (unsigned int __value
, unsigned short int __port
)
131 __asm__
__volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (__value
),
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
));
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
));
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
));
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
));
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
));
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
));
183 #endif /* _SYS_IO_H */