]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4util/include/ARCH-x86/port_io.h
d41ccb46a43e22e756317de55ebfdb92ec03da0d
[l4.git] / l4 / pkg / l4util / include / ARCH-x86 / port_io.h
1 /*****************************************************************************/
2 /**
3  * \file
4  * \brief  x86 port I/O
5  *
6  * \date   06/2003
7  * \author Frank Mehnert <fm3@os.inf.tu-dresden.de>
8  */
9 /*****************************************************************************/
10
11 /*
12  * (c) 2003-2009 Technische Universität Dresden
13  * This file is part of TUD:OS and distributed under the terms of the
14  * GNU Lesser General Public License 2.1.
15  * Please see the COPYING-LGPL-2.1 file for details.
16  */
17
18 #ifndef _L4UTIL_PORT_IO_H
19 #define _L4UTIL_PORT_IO_H
20
21 /**
22  * \defgroup l4util_portio IA32 Port I/O API
23  * \ingroup l4util_api
24  */
25
26 /* L4 includes */
27 #include <l4/sys/l4int.h>
28 #include <l4/sys/compiler.h>
29 #include <l4/sys/types.h>
30
31 /*****************************************************************************
32  *** Prototypes
33  *****************************************************************************/
34
35 EXTERN_C_BEGIN
36 /**
37  * \addtogroup l4util_portio
38  */
39 /*@{*/
40 /**
41  * \brief Read byte from I/O port
42  *
43  * \param  port    I/O port address
44  * \return value
45  */
46 L4_INLINE l4_uint8_t
47 l4util_in8(l4_uint16_t port);
48
49 /**
50  * \brief Read 16-bit-value from I/O port
51  *
52  * \param  port    I/O port address
53  * \return value
54  */
55 L4_INLINE l4_uint16_t
56 l4util_in16(l4_uint16_t port);
57
58 /**
59  * \brief Read 32-bit-value from I/O port
60  *
61  * \param  port    I/O port address
62  * \return value
63  */
64 L4_INLINE l4_uint32_t
65 l4util_in32(l4_uint16_t port);
66
67 /**
68  * \brief Read a block of 8-bit-value from I/O ports
69  *
70  * \param  port    I/O port address
71  * \param  addr    address of buffer
72  * \param  count   number of I/O operations
73  * \return value
74  */
75 L4_INLINE void
76 l4util_ins8(l4_uint16_t port, l4_umword_t addr, l4_umword_t count);
77
78 /**
79  * \brief Read a block of 16-bit-value from I/O ports
80  *
81  * \param  port    I/O port address
82  * \param  addr    address of buffer
83  * \param  count   number of I/O operations
84  * \return value
85  */
86 L4_INLINE void
87 l4util_ins16(l4_uint16_t port, l4_umword_t addr, l4_umword_t count);
88
89 /**
90  * \brief Read a block of 32-bit-value from I/O ports
91  *
92  * \param  port    I/O port address
93  * \param  addr    address of buffer
94  * \param  count   number of I/O operations
95  * \return value
96  */
97 L4_INLINE void
98 l4util_ins32(l4_uint16_t port, l4_umword_t addr, l4_umword_t count);
99
100 /**
101  * \brief Write byte to I/O port
102  *
103  * \param  port    I/O port address
104  * \param  value   value to write
105  */
106 L4_INLINE void
107 l4util_out8(l4_uint8_t value, l4_uint16_t port);
108
109 /**
110  * \brief Write 16-bit-value to I/O port
111  * \ingroup port_io
112  *
113  * \param  port    I/O port address
114  * \param  value   value to write
115  */
116 L4_INLINE void
117 l4util_out16(l4_uint16_t value, l4_uint16_t port);
118
119 /**
120  * \brief Write 32-bit-value to I/O port
121  *
122  * \param  port    I/O port address
123  * \param  value   value to write
124  */
125 L4_INLINE void
126 l4util_out32(l4_uint32_t value, l4_uint16_t port);
127
128 /**
129  * \brief delay I/O port access by writing to port 0x80
130  */
131 L4_INLINE void
132 l4util_iodelay(void);
133
134 /*@}*/
135
136 EXTERN_C_END
137
138
139 /*****************************************************************************
140  *** Implementation
141  *****************************************************************************/
142
143 L4_INLINE l4_uint8_t
144 l4util_in8(l4_uint16_t port)
145 {
146   l4_uint8_t value;
147   asm volatile ("inb %w1, %b0" : "=a" (value) : "Nd" (port));
148   return value;
149 }
150
151 L4_INLINE l4_uint16_t
152 l4util_in16(l4_uint16_t port)
153 {
154   l4_uint16_t value;
155   asm volatile ("inw %w1, %w0" : "=a" (value) : "Nd" (port));
156   return value;
157 }
158
159 L4_INLINE l4_uint32_t
160 l4util_in32(l4_uint16_t port)
161 {
162   l4_uint32_t value;
163   asm volatile ("inl %w1, %0" : "=a" (value) : "Nd" (port));
164   return value;
165 }
166
167 L4_INLINE void
168 l4util_ins8(l4_uint16_t port, l4_umword_t addr, l4_umword_t count)
169 {
170   l4_umword_t dummy1, dummy2;
171   asm volatile ("rep insb" : "=D"(dummy1), "=c"(dummy2)
172                            : "d" (port), "D" (addr), "c"(count)
173                            : "memory");
174 }
175
176 L4_INLINE void
177 l4util_ins16(l4_uint16_t port, l4_umword_t addr, l4_umword_t count)
178 {
179   l4_umword_t dummy1, dummy2;
180   asm volatile ("rep insw" : "=D"(dummy1), "=c"(dummy2)
181                            : "d" (port), "D" (addr), "c"(count)
182                            : "memory");
183 }
184
185 L4_INLINE void
186 l4util_ins32(l4_uint16_t port, l4_umword_t addr, l4_umword_t count)
187 {
188   l4_umword_t dummy1, dummy2;
189   asm volatile ("rep insl" : "=D"(dummy1), "=c"(dummy2)
190                            : "d" (port), "D" (addr), "c"(count)
191                            : "memory");
192 }
193
194 L4_INLINE void
195 l4util_out8(l4_uint8_t value, l4_uint16_t port)
196 {
197   asm volatile ("outb %b0, %w1" : : "a" (value), "Nd" (port));
198 }
199
200 L4_INLINE void
201 l4util_out16(l4_uint16_t value, l4_uint16_t port)
202 {
203   asm volatile ("outw %w0, %w1" : : "a" (value), "Nd" (port));
204 }
205
206 L4_INLINE void
207 l4util_out32(l4_uint32_t value, l4_uint16_t port)
208 {
209   asm volatile ("outl %0, %w1" : : "a" (value), "Nd" (port));
210 }
211
212 L4_INLINE void
213 l4util_iodelay(void)
214 {
215   asm volatile ("outb %al,$0x80");
216 }
217
218 #endif