| 1 |
/* Access to hardware i/o ports. GNU/x86 version. |
| 2 |
Copyright (C) 2002-2026 Free Software Foundation, Inc. |
| 3 |
This file is part of the GNU C Library. |
| 4 |
|
| 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. |
| 9 |
|
| 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. |
| 14 |
|
| 15 |
You should have received a copy of the GNU Lesser General Public |
| 16 |
License along with the GNU C Library; if not, see |
| 17 |
<https://www.gnu.org/licenses/>. */ |
| 18 |
|
| 19 |
#ifndef _SYS_IO_H |
| 20 |
#define _SYS_IO_H 1 |
| 21 |
|
| 22 |
#include <features.h> |
| 23 |
|
| 24 |
__BEGIN_DECLS |
| 25 |
|
| 26 |
/* If TURN_ON is TRUE, request for permission to do direct i/o on the |
| 27 |
port numbers in the range [FROM,FROM+NUM-1]. Otherwise, turn I/O |
| 28 |
permission off for that range. This call requires root privileges. */ |
| 29 |
extern int ioperm (unsigned long int __from, unsigned long int __num, |
| 30 |
int __turn_on) __THROW; |
| 31 |
|
| 32 |
/* Set the I/O privilege level to LEVEL. If LEVEL>3, permission to |
| 33 |
access any I/O port is granted. This call requires root |
| 34 |
privileges. */ |
| 35 |
extern int iopl (int __level) __THROW; |
| 36 |
|
| 37 |
#if defined __GNUC__ && __GNUC__ >= 2 |
| 38 |
|
| 39 |
static __inline unsigned char |
| 40 |
inb (unsigned short int port) |
| 41 |
{ |
| 42 |
unsigned char _v; |
| 43 |
|
| 44 |
__asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (port)); |
| 45 |
return _v; |
| 46 |
} |
| 47 |
|
| 48 |
static __inline unsigned char |
| 49 |
inb_p (unsigned short int port) |
| 50 |
{ |
| 51 |
unsigned char _v; |
| 52 |
|
| 53 |
__asm__ __volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port)); |
| 54 |
return _v; |
| 55 |
} |
| 56 |
|
| 57 |
static __inline unsigned short int |
| 58 |
inw (unsigned short int port) |
| 59 |
{ |
| 60 |
unsigned short _v; |
| 61 |
|
| 62 |
__asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (port)); |
| 63 |
return _v; |
| 64 |
} |
| 65 |
|
| 66 |
static __inline unsigned short int |
| 67 |
inw_p (unsigned short int port) |
| 68 |
{ |
| 69 |
unsigned short int _v; |
| 70 |
|
| 71 |
__asm__ __volatile__ ("inw %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port)); |
| 72 |
return _v; |
| 73 |
} |
| 74 |
|
| 75 |
static __inline unsigned int |
| 76 |
inl (unsigned short int port) |
| 77 |
{ |
| 78 |
unsigned int _v; |
| 79 |
|
| 80 |
__asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (port)); |
| 81 |
return _v; |
| 82 |
} |
| 83 |
|
| 84 |
static __inline unsigned int |
| 85 |
inl_p (unsigned short int port) |
| 86 |
{ |
| 87 |
unsigned int _v; |
| 88 |
__asm__ __volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port)); |
| 89 |
return _v; |
| 90 |
} |
| 91 |
|
| 92 |
static __inline void |
| 93 |
outb (unsigned char value, unsigned short int port) |
| 94 |
{ |
| 95 |
__asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port)); |
| 96 |
} |
| 97 |
|
| 98 |
static __inline void |
| 99 |
outb_p (unsigned char value, unsigned short int port) |
| 100 |
{ |
| 101 |
__asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (value), |
| 102 |
"Nd" (port)); |
| 103 |
} |
| 104 |
|
| 105 |
static __inline void |
| 106 |
outw (unsigned short int value, unsigned short int port) |
| 107 |
{ |
| 108 |
__asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (port)); |
| 109 |
|
| 110 |
} |
| 111 |
|
| 112 |
static __inline void |
| 113 |
outw_p (unsigned short int value, unsigned short int port) |
| 114 |
{ |
| 115 |
__asm__ __volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (value), |
| 116 |
"Nd" (port)); |
| 117 |
} |
| 118 |
|
| 119 |
static __inline void |
| 120 |
outl (unsigned int value, unsigned short int port) |
| 121 |
{ |
| 122 |
__asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (port)); |
| 123 |
} |
| 124 |
|
| 125 |
static __inline void |
| 126 |
outl_p (unsigned int value, unsigned short int port) |
| 127 |
{ |
| 128 |
__asm__ __volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (value), |
| 129 |
"Nd" (port)); |
| 130 |
} |
| 131 |
|
| 132 |
static __inline void |
| 133 |
insb (unsigned short int port, void *addr, unsigned long int count) |
| 134 |
{ |
| 135 |
__asm__ __volatile__ ("cld ; rep ; insb":"=D" (addr), |
| 136 |
"=c" (count):"d" (port), "0" (addr), "1" (count)); |
| 137 |
} |
| 138 |
|
| 139 |
static __inline void |
| 140 |
insw (unsigned short int port, void *addr, unsigned long int count) |
| 141 |
{ |
| 142 |
__asm__ __volatile__ ("cld ; rep ; insw":"=D" (addr), |
| 143 |
"=c" (count):"d" (port), "0" (addr), "1" (count)); |
| 144 |
} |
| 145 |
|
| 146 |
static __inline void |
| 147 |
insl (unsigned short int port, void *addr, unsigned long int count) |
| 148 |
{ |
| 149 |
__asm__ __volatile__ ("cld ; rep ; insl":"=D" (addr), |
| 150 |
"=c" (count):"d" (port), "0" (addr), "1" (count)); |
| 151 |
} |
| 152 |
|
| 153 |
static __inline void |
| 154 |
outsb (unsigned short int port, const void *addr, unsigned long int count) |
| 155 |
{ |
| 156 |
__asm__ __volatile__ ("cld ; rep ; outsb":"=S" (addr), |
| 157 |
"=c" (count):"d" (port), "0" (addr), "1" (count)); |
| 158 |
} |
| 159 |
|
| 160 |
static __inline void |
| 161 |
outsw (unsigned short int port, const void *addr, unsigned long int count) |
| 162 |
{ |
| 163 |
__asm__ __volatile__ ("cld ; rep ; outsw":"=S" (addr), |
| 164 |
"=c" (count):"d" (port), "0" (addr), "1" (count)); |
| 165 |
} |
| 166 |
|
| 167 |
static __inline void |
| 168 |
outsl (unsigned short int port, const void *addr, unsigned long int count) |
| 169 |
{ |
| 170 |
__asm__ __volatile__ ("cld ; rep ; outsl":"=S" (addr), |
| 171 |
"=c" (count):"d" (port), "0" (addr), "1" (count)); |
| 172 |
} |
| 173 |
|
| 174 |
#endif /* GNU C */ |
| 175 |
|
| 176 |
__END_DECLS |
| 177 |
#endif /* _SYS_IO_H */ |