Back to index

glibc  2.9
io.h
Go to the documentation of this file.
00001 /* Copyright (C) 1996, 2000, 2002 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #ifndef       _SYS_IO_H
00020 #define       _SYS_IO_H     1
00021 
00022 #include <features.h>
00023 
00024 __BEGIN_DECLS
00025 
00026 /* If TURN_ON is TRUE, request for permission to do direct i/o on the
00027    port numbers in the range [FROM,FROM+NUM-1].  Otherwise, turn I/O
00028    permission off for that range.  This call requires root privileges.
00029 
00030    Portability note: not all Linux platforms support this call.  Most
00031    platforms based on the PC I/O architecture probably will, however.
00032    E.g., Linux/Alpha for Alpha PCs supports this.  */
00033 extern int ioperm (unsigned long int __from, unsigned long int __num,
00034                    int __turn_on) __THROW;
00035 
00036 /* Set the I/O privilege level to LEVEL.  If LEVEL>3, permission to
00037    access any I/O port is granted.  This call requires root
00038    privileges. */
00039 extern int iopl (int __level) __THROW;
00040 
00041 #if defined __GNUC__ && __GNUC__ >= 2
00042 
00043 static __inline unsigned char
00044 inb (unsigned short int port)
00045 {
00046   unsigned char _v;
00047 
00048   __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (port));
00049   return _v;
00050 }
00051 
00052 static __inline unsigned char
00053 inb_p (unsigned short int port)
00054 {
00055   unsigned char _v;
00056 
00057   __asm__ __volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
00058   return _v;
00059 }
00060 
00061 static __inline unsigned short int
00062 inw (unsigned short int port)
00063 {
00064   unsigned short _v;
00065 
00066   __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (port));
00067   return _v;
00068 }
00069 
00070 static __inline unsigned short int
00071 inw_p (unsigned short int port)
00072 {
00073   unsigned short int _v;
00074 
00075   __asm__ __volatile__ ("inw %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
00076   return _v;
00077 }
00078 
00079 static __inline unsigned int
00080 inl (unsigned short int port)
00081 {
00082   unsigned int _v;
00083 
00084   __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (port));
00085   return _v;
00086 }
00087 
00088 static __inline unsigned int
00089 inl_p (unsigned short int port)
00090 {
00091   unsigned int _v;
00092   __asm__ __volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
00093   return _v;
00094 }
00095 
00096 static __inline void
00097 outb (unsigned char value, unsigned short int port)
00098 {
00099   __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port));
00100 }
00101 
00102 static __inline void
00103 outb_p (unsigned char value, unsigned short int port)
00104 {
00105   __asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (value),
00106                      "Nd" (port));
00107 }
00108 
00109 static __inline void
00110 outw (unsigned short int value, unsigned short int port)
00111 {
00112   __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (port));
00113 
00114 }
00115 
00116 static __inline void
00117 outw_p (unsigned short int value, unsigned short int port)
00118 {
00119   __asm__ __volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (value),
00120                      "Nd" (port));
00121 }
00122 
00123 static __inline void
00124 outl (unsigned int value, unsigned short int port)
00125 {
00126   __asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (port));
00127 }
00128 
00129 static __inline void
00130 outl_p (unsigned int value, unsigned short int port)
00131 {
00132   __asm__ __volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (value),
00133                      "Nd" (port));
00134 }
00135 
00136 static __inline void
00137 insb (unsigned short int port, void *addr, unsigned long int count)
00138 {
00139   __asm__ __volatile__ ("cld ; rep ; insb":"=D" (addr),
00140                      "=c" (count):"d" (port), "0" (addr), "1" (count));
00141 }
00142 
00143 static __inline void
00144 insw (unsigned short int port, void *addr, unsigned long int count)
00145 {
00146   __asm__ __volatile__ ("cld ; rep ; insw":"=D" (addr),
00147                      "=c" (count):"d" (port), "0" (addr), "1" (count));
00148 }
00149 
00150 static __inline void
00151 insl (unsigned short int port, void *addr, unsigned long int count)
00152 {
00153   __asm__ __volatile__ ("cld ; rep ; insl":"=D" (addr),
00154                      "=c" (count):"d" (port), "0" (addr), "1" (count));
00155 }
00156 
00157 static __inline void
00158 outsb (unsigned short int port, const void *addr, unsigned long int count)
00159 {
00160   __asm__ __volatile__ ("cld ; rep ; outsb":"=S" (addr),
00161                      "=c" (count):"d" (port), "0" (addr), "1" (count));
00162 }
00163 
00164 static __inline void
00165 outsw (unsigned short int port, const void *addr, unsigned long int count)
00166 {
00167   __asm__ __volatile__ ("cld ; rep ; outsw":"=S" (addr),
00168                      "=c" (count):"d" (port), "0" (addr), "1" (count));
00169 }
00170 
00171 static __inline void
00172 outsl (unsigned short int port, const void *addr, unsigned long int count)
00173 {
00174   __asm__ __volatile__ ("cld ; rep ; outsl":"=S" (addr),
00175                      "=c" (count):"d" (port), "0" (addr), "1" (count));
00176 }
00177 
00178 #endif /* GNU C */
00179 
00180 __END_DECLS
00181 #endif /* _SYS_IO_H */