OSDN Git Service

Android porting
[android-x86/external-libpciaccess.git] / include / sys / io.h
1 /* Copyright (C) 1996, 2000, 2002, 2009 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, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.  */
18
19 #ifndef _SYS_IO_H
20 #define _SYS_IO_H       1
21
22 __BEGIN_DECLS
23
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.
27
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,
32                    int __turn_on);
33
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
36    privileges. */
37 extern int iopl (int __level);
38
39 #if defined __GNUC__ && __GNUC__ >= 2
40
41 static __inline unsigned char
42 inb (unsigned short int __port)
43 {
44   unsigned char _v;
45
46   __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (__port));
47   return _v;
48 }
49
50 static __inline unsigned char
51 inb_p (unsigned short int __port)
52 {
53   unsigned char _v;
54
55   __asm__ __volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (__port));
56   return _v;
57 }
58
59 static __inline unsigned short int
60 inw (unsigned short int __port)
61 {
62   unsigned short _v;
63
64   __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (__port));
65   return _v;
66 }
67
68 static __inline unsigned short int
69 inw_p (unsigned short int __port)
70 {
71   unsigned short int _v;
72
73   __asm__ __volatile__ ("inw %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (__port));
74   return _v;
75 }
76
77 static __inline unsigned int
78 inl (unsigned short int __port)
79 {
80   unsigned int _v;
81
82   __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (__port));
83   return _v;
84 }
85
86 static __inline unsigned int
87 inl_p (unsigned short int __port)
88 {
89   unsigned int _v;
90   __asm__ __volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (__port));
91   return _v;
92 }
93
94 static __inline void
95 outb (unsigned char __value, unsigned short int __port)
96 {
97   __asm__ __volatile__ ("outb %b0,%w1": :"a" (__value), "Nd" (__port));
98 }
99
100 static __inline void
101 outb_p (unsigned char __value, unsigned short int __port)
102 {
103   __asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (__value),
104                         "Nd" (__port));
105 }
106
107 static __inline void
108 outw (unsigned short int __value, unsigned short int __port)
109 {
110   __asm__ __volatile__ ("outw %w0,%w1": :"a" (__value), "Nd" (__port));
111
112 }
113
114 static __inline void
115 outw_p (unsigned short int __value, unsigned short int __port)
116 {
117   __asm__ __volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (__value),
118                         "Nd" (__port));
119 }
120
121 static __inline void
122 outl (unsigned int __value, unsigned short int __port)
123 {
124   __asm__ __volatile__ ("outl %0,%w1": :"a" (__value), "Nd" (__port));
125 }
126
127 static __inline void
128 outl_p (unsigned int __value, unsigned short int __port)
129 {
130   __asm__ __volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (__value),
131                         "Nd" (__port));
132 }
133
134 static __inline void
135 insb (unsigned short int __port, void *addr, unsigned long int __count)
136 {
137   __asm__ __volatile__ ("cld ; rep ; insb":"=D" (addr), "=c" (__count)
138                         :"d" (__port), "0" (addr), "1" (__count));
139 }
140
141 static __inline void
142 insw (unsigned short int __port, void *addr, unsigned long int __count)
143 {
144   __asm__ __volatile__ ("cld ; rep ; insw":"=D" (addr), "=c" (__count)
145                         :"d" (__port), "0" (addr), "1" (__count));
146 }
147
148 static __inline void
149 insl (unsigned short int __port, void *addr, unsigned long int __count)
150 {
151   __asm__ __volatile__ ("cld ; rep ; insl":"=D" (addr), "=c" (__count)
152                         :"d" (__port), "0" (addr), "1" (__count));
153 }
154
155 static __inline void
156 outsb (unsigned short int __port, const void *addr, unsigned long int __count)
157 {
158   __asm__ __volatile__ ("cld ; rep ; outsb":"=S" (addr), "=c" (__count)
159                         :"d" (__port), "0" (addr), "1" (__count));
160 }
161
162 static __inline void
163 outsw (unsigned short int __port, const void *addr, unsigned long int __count)
164 {
165   __asm__ __volatile__ ("cld ; rep ; outsw":"=S" (addr), "=c" (__count)
166                         :"d" (__port), "0" (addr), "1" (__count));
167 }
168
169 static __inline void
170 outsl (unsigned short int __port, const void *addr, unsigned long int __count)
171 {
172   __asm__ __volatile__ ("cld ; rep ; outsl":"=S" (addr), "=c" (__count)
173                         :"d" (__port), "0" (addr), "1" (__count));
174 }
175
176 #endif  /* GNU C */
177
178 __END_DECLS
179 #endif /* _SYS_IO_H */