1 /* Access to hardware i/o ports. GNU/x86 version.
2 Copyright (C) 2002 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
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 extern int ioperm (unsigned long int __from
, unsigned long int __num
,
31 int __turn_on
) __THROW
;
33 /* Set the I/O privilege level to LEVEL. If LEVEL>3, permission to
34 access any I/O port is granted. This call requires root
36 extern int iopl (int __level
) __THROW
;
38 #if defined __GNUC__ && __GNUC__ >= 2
40 static __inline
unsigned char
41 inb (unsigned short int port
)
45 __asm__
__volatile__ ("inb %w1,%0":"=a" (_v
):"Nd" (port
));
49 static __inline
unsigned char
50 inb_p (unsigned short int port
)
54 __asm__
__volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v
):"Nd" (port
));
58 static __inline
unsigned short int
59 inw (unsigned short int port
)
63 __asm__
__volatile__ ("inw %w1,%0":"=a" (_v
):"Nd" (port
));
67 static __inline
unsigned short int
68 inw_p (unsigned short int port
)
70 unsigned short int _v
;
72 __asm__
__volatile__ ("inw %w1,%0\noutb %%al,$0x80":"=a" (_v
):"Nd" (port
));
76 static __inline
unsigned int
77 inl (unsigned short int port
)
81 __asm__
__volatile__ ("inl %w1,%0":"=a" (_v
):"Nd" (port
));
85 static __inline
unsigned int
86 inl_p (unsigned short int port
)
89 __asm__
__volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (_v
):"Nd" (port
));
94 outb (unsigned char value
, unsigned short int port
)
96 __asm__
__volatile__ ("outb %b0,%w1": :"a" (value
), "Nd" (port
));
100 outb_p (unsigned char value
, unsigned short int port
)
102 __asm__
__volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (value
),
107 outw (unsigned short int value
, unsigned short int port
)
109 __asm__
__volatile__ ("outw %w0,%w1": :"a" (value
), "Nd" (port
));
114 outw_p (unsigned short int value
, unsigned short int port
)
116 __asm__
__volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (value
),
121 outl (unsigned int value
, unsigned short int port
)
123 __asm__
__volatile__ ("outl %0,%w1": :"a" (value
), "Nd" (port
));
127 outl_p (unsigned int value
, unsigned short int port
)
129 __asm__
__volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (value
),
134 insb (unsigned short int port
, void *addr
, unsigned long int count
)
136 __asm__
__volatile__ ("cld ; rep ; insb":"=D" (addr
),
137 "=c" (count
):"d" (port
), "0" (addr
), "1" (count
));
141 insw (unsigned short int port
, void *addr
, unsigned long int count
)
143 __asm__
__volatile__ ("cld ; rep ; insw":"=D" (addr
),
144 "=c" (count
):"d" (port
), "0" (addr
), "1" (count
));
148 insl (unsigned short int port
, void *addr
, unsigned long int count
)
150 __asm__
__volatile__ ("cld ; rep ; insl":"=D" (addr
),
151 "=c" (count
):"d" (port
), "0" (addr
), "1" (count
));
155 outsb (unsigned short int port
, const void *addr
, unsigned long int count
)
157 __asm__
__volatile__ ("cld ; rep ; outsb":"=S" (addr
),
158 "=c" (count
):"d" (port
), "0" (addr
), "1" (count
));
162 outsw (unsigned short int port
, const void *addr
, unsigned long int count
)
164 __asm__
__volatile__ ("cld ; rep ; outsw":"=S" (addr
),
165 "=c" (count
):"d" (port
), "0" (addr
), "1" (count
));
169 outsl (unsigned short int port
, const void *addr
, unsigned long int count
)
171 __asm__
__volatile__ ("cld ; rep ; outsl":"=S" (addr
),
172 "=c" (count
):"d" (port
), "0" (addr
), "1" (count
));
178 #endif /* _SYS_IO_H */