1 /* Copyright (C) 1996, 2000, 2002, 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
24 /* If TURN_ON is TRUE, request for permission to do direct i/o on the
25 port numbers in the range [FROM,FROM+NUM-1]. Otherwise, turn I/O
26 permission off for that range. This call requires root privileges.
28 Portability note: not all Linux platforms support this call. Most
29 platforms based on the PC I/O architecture probably will, however.
30 E.g., Linux/Alpha for Alpha PCs supports this. */
31 extern int ioperm (unsigned long int __from, unsigned long int __num,
34 /* Set the I/O privilege level to LEVEL. If LEVEL>3, permission to
35 access any I/O port is granted. This call requires root
37 extern int iopl (int __level);
39 #if defined __GNUC__ && __GNUC__ >= 2
41 static __inline unsigned char
42 inb (unsigned short int __port)
46 __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (__port));
50 static __inline unsigned char
51 inb_p (unsigned short int __port)
55 __asm__ __volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (__port));
59 static __inline unsigned short int
60 inw (unsigned short int __port)
64 __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (__port));
68 static __inline unsigned short int
69 inw_p (unsigned short int __port)
71 unsigned short int _v;
73 __asm__ __volatile__ ("inw %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (__port));
77 static __inline unsigned int
78 inl (unsigned short int __port)
82 __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (__port));
86 static __inline unsigned int
87 inl_p (unsigned short int __port)
90 __asm__ __volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (__port));
95 outb (unsigned char __value, unsigned short int __port)
97 __asm__ __volatile__ ("outb %b0,%w1": :"a" (__value), "Nd" (__port));
101 outb_p (unsigned char __value, unsigned short int __port)
103 __asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (__value),
108 outw (unsigned short int __value, unsigned short int __port)
110 __asm__ __volatile__ ("outw %w0,%w1": :"a" (__value), "Nd" (__port));
115 outw_p (unsigned short int __value, unsigned short int __port)
117 __asm__ __volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (__value),
122 outl (unsigned int __value, unsigned short int __port)
124 __asm__ __volatile__ ("outl %0,%w1": :"a" (__value), "Nd" (__port));
128 outl_p (unsigned int __value, unsigned short int __port)
130 __asm__ __volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (__value),
135 insb (unsigned short int __port, void *addr, unsigned long int __count)
137 __asm__ __volatile__ ("cld ; rep ; insb":"=D" (addr), "=c" (__count)
138 :"d" (__port), "0" (addr), "1" (__count));
142 insw (unsigned short int __port, void *addr, unsigned long int __count)
144 __asm__ __volatile__ ("cld ; rep ; insw":"=D" (addr), "=c" (__count)
145 :"d" (__port), "0" (addr), "1" (__count));
149 insl (unsigned short int __port, void *addr, unsigned long int __count)
151 __asm__ __volatile__ ("cld ; rep ; insl":"=D" (addr), "=c" (__count)
152 :"d" (__port), "0" (addr), "1" (__count));
156 outsb (unsigned short int __port, const void *addr, unsigned long int __count)
158 __asm__ __volatile__ ("cld ; rep ; outsb":"=S" (addr), "=c" (__count)
159 :"d" (__port), "0" (addr), "1" (__count));
163 outsw (unsigned short int __port, const void *addr, unsigned long int __count)
165 __asm__ __volatile__ ("cld ; rep ; outsw":"=S" (addr), "=c" (__count)
166 :"d" (__port), "0" (addr), "1" (__count));
170 outsl (unsigned short int __port, const void *addr, unsigned long int __count)
172 __asm__ __volatile__ ("cld ; rep ; outsl":"=S" (addr), "=c" (__count)
173 :"d" (__port), "0" (addr), "1" (__count));
179 #endif /* _SYS_IO_H */