Back to index

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