1 /* Copyright (C) 1996, 2000, 2009 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, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
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.
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
;
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
39 extern int iopl (int __level
) __THROW
;
41 #if defined __GNUC__ && __GNUC__ >= 2
43 static __inline
unsigned char
44 inb (unsigned short int __port
)
48 __asm__
__volatile__ ("inb %w1,%0":"=a" (_v
):"Nd" (__port
));
52 static __inline
unsigned char
53 inb_p (unsigned short int __port
)
57 __asm__
__volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v
):"Nd" (__port
));
61 static __inline
unsigned short int
62 inw (unsigned short int __port
)
66 __asm__
__volatile__ ("inw %w1,%0":"=a" (_v
):"Nd" (__port
));
70 static __inline
unsigned short int
71 inw_p (unsigned short int __port
)
73 unsigned short int _v
;
75 __asm__
__volatile__ ("inw %w1,%0\noutb %%al,$0x80":"=a" (_v
):"Nd" (__port
));
79 static __inline
unsigned int
80 inl (unsigned short int __port
)
84 __asm__
__volatile__ ("inl %w1,%0":"=a" (_v
):"Nd" (__port
));
88 static __inline
unsigned int
89 inl_p (unsigned short int __port
)
92 __asm__
__volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (_v
)
98 outb (unsigned char value
, unsigned short int __port
)
100 __asm__
__volatile__ ("outb %b0,%w1": :"a" (value
), "Nd" (__port
));
104 outb_p (unsigned char value
, unsigned short int __port
)
106 __asm__
__volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (value
),
111 outw (unsigned short int value
, unsigned short int __port
)
113 __asm__
__volatile__ ("outw %w0,%w1": :"a" (value
), "Nd" (__port
));
118 outw_p (unsigned short int value
, unsigned short int __port
)
120 __asm__
__volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (value
),
125 outl (unsigned int value
, unsigned short int __port
)
127 __asm__
__volatile__ ("outl %0,%w1": :"a" (value
), "Nd" (__port
));
131 outl_p (unsigned int value
, unsigned short int __port
)
133 __asm__
__volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (value
),
138 insb (unsigned short int __port
, void *__addr
, unsigned long int __count
)
140 __asm__
__volatile__ ("cld ; rep ; insb":"=D" (__addr
), "=c" (__count
)
141 :"d" (__port
), "0" (__addr
), "1" (__count
));
145 insw (unsigned short int __port
, void *__addr
, unsigned long int __count
)
147 __asm__
__volatile__ ("cld ; rep ; insw":"=D" (__addr
), "=c" (__count
)
148 :"d" (__port
), "0" (__addr
), "1" (__count
));
152 insl (unsigned short int __port
, void *__addr
, unsigned long int __count
)
154 __asm__
__volatile__ ("cld ; rep ; insl":"=D" (__addr
), "=c" (__count
)
155 :"d" (__port
), "0" (__addr
), "1" (__count
));
159 outsb (unsigned short int __port
, const void *__addr
,
160 unsigned long int __count
)
162 __asm__
__volatile__ ("cld ; rep ; outsb":"=S" (__addr
), "=c" (__count
)
163 :"d" (__port
), "0" (__addr
), "1" (__count
));
167 outsw (unsigned short int __port
, const void *__addr
,
168 unsigned long int __count
)
170 __asm__
__volatile__ ("cld ; rep ; outsw":"=S" (__addr
), "=c" (__count
)
171 :"d" (__port
), "0" (__addr
), "1" (__count
));
175 outsl (unsigned short int __port
, const void *__addr
,
176 unsigned long int __count
)
178 __asm__
__volatile__ ("cld ; rep ; outsl":"=S" (__addr
), "=c" (__count
)
179 :"d" (__port
), "0" (__addr
), "1" (__count
));
185 #endif /* _SYS_IO_H */