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

source code of glibc/sysdeps/unix/sysv/linux/x86/sys/io.h