]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/IoLibGcc.c
Import some basic libraries instances for Mde Packages.
[mirror_edk2.git] / MdePkg / Library / BaseIoLibIntrinsic / IoLibGcc.c
1 /** @file
2 I/O Library. This file has compiler specifics for GCC as there is no
3 ANSI C standard for doing IO.
4
5 GCC - uses EFIAPI assembler. __asm__ calls GAS. __volatile__ makes sure the
6 compiler puts the assembler in this exact location. The complex GNUC
7 operations are not optimzed. It would be possible to also write these
8 with EFIAPI assembler.
9
10 We don't advocate putting compiler specifics in libraries or drivers but there
11 is no other way to make this work.
12
13 Copyright (c) 2006 - 2007, Intel Corporation<BR>
14 All rights reserved. This program and the accompanying materials
15 are licensed and made available under the terms and conditions of the BSD License
16 which accompanies this distribution. The full text of the license may be found at
17 http://opensource.org/licenses/bsd-license.php
18
19 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
20 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21
22 Module Name: IoLibGcc.c
23
24 **/
25
26 //
27 // Include common header file for this module.
28 //
29 #include "CommonHeader.h"
30
31 /**
32 Reads an 8-bit MMIO register.
33
34 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
35 returned. This function must guarantee that all MMIO read and write
36 operations are serialized.
37
38 If 8-bit MMIO register operations are not supported, then ASSERT().
39
40 @param Address The MMIO register to read.
41
42 @return The value read.
43
44 **/
45 UINT8
46 EFIAPI
47 MmioRead8 (
48 IN UINTN Address
49 )
50 {
51 return *(volatile UINT8*)Address;
52 }
53
54 /**
55 Writes an 8-bit MMIO register.
56
57 Writes the 8-bit MMIO register specified by Address with the value specified
58 by Value and returns Value. This function must guarantee that all MMIO read
59 and write operations are serialized.
60
61 If 8-bit MMIO register operations are not supported, then ASSERT().
62
63 @param Address The MMIO register to write.
64 @param Value The value to write to the MMIO register.
65
66 **/
67 UINT8
68 EFIAPI
69 MmioWrite8 (
70 IN UINTN Address,
71 IN UINT8 Value
72 )
73 {
74 return *(volatile UINT8*)Address = Value;
75 }
76
77 /**
78 Reads a 16-bit MMIO register.
79
80 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
81 returned. This function must guarantee that all MMIO read and write
82 operations are serialized.
83
84 If 16-bit MMIO register operations are not supported, then ASSERT().
85
86 @param Address The MMIO register to read.
87
88 @return The value read.
89
90 **/
91 UINT16
92 EFIAPI
93 MmioRead16 (
94 IN UINTN Address
95 )
96 {
97 ASSERT ((Address & 1) == 0);
98 return *(volatile UINT16*)Address;
99 }
100
101 /**
102 Writes a 16-bit MMIO register.
103
104 Writes the 16-bit MMIO register specified by Address with the value specified
105 by Value and returns Value. This function must guarantee that all MMIO read
106 and write operations are serialized.
107
108 If 16-bit MMIO register operations are not supported, then ASSERT().
109
110 @param Address The MMIO register to write.
111 @param Value The value to write to the MMIO register.
112
113 **/
114 UINT16
115 EFIAPI
116 MmioWrite16 (
117 IN UINTN Address,
118 IN UINT16 Value
119 )
120 {
121 ASSERT ((Address & 1) == 0);
122 return *(volatile UINT16*)Address = Value;
123 }
124
125 /**
126 Reads a 32-bit MMIO register.
127
128 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
129 returned. This function must guarantee that all MMIO read and write
130 operations are serialized.
131
132 If 32-bit MMIO register operations are not supported, then ASSERT().
133
134 @param Address The MMIO register to read.
135
136 @return The value read.
137
138 **/
139 UINT32
140 EFIAPI
141 MmioRead32 (
142 IN UINTN Address
143 )
144 {
145 ASSERT ((Address & 3) == 0);
146 return *(volatile UINT32*)Address;
147 }
148
149 /**
150 Writes a 32-bit MMIO register.
151
152 Writes the 32-bit MMIO register specified by Address with the value specified
153 by Value and returns Value. This function must guarantee that all MMIO read
154 and write operations are serialized.
155
156 If 32-bit MMIO register operations are not supported, then ASSERT().
157
158 @param Address The MMIO register to write.
159 @param Value The value to write to the MMIO register.
160
161 **/
162 UINT32
163 EFIAPI
164 MmioWrite32 (
165 IN UINTN Address,
166 IN UINT32 Value
167 )
168 {
169 ASSERT ((Address & 3) == 0);
170 return *(volatile UINT32*)Address = Value;
171 }
172
173 /**
174 Reads a 64-bit MMIO register.
175
176 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
177 returned. This function must guarantee that all MMIO read and write
178 operations are serialized.
179
180 If 64-bit MMIO register operations are not supported, then ASSERT().
181
182 @param Address The MMIO register to read.
183
184 @return The value read.
185
186 **/
187 UINT64
188 EFIAPI
189 MmioRead64 (
190 IN UINTN Address
191 )
192 {
193 ASSERT ((Address & 7) == 0);
194 return *(volatile UINT64*)Address;
195 }
196
197 /**
198 Writes a 64-bit MMIO register.
199
200 Writes the 64-bit MMIO register specified by Address with the value specified
201 by Value and returns Value. This function must guarantee that all MMIO read
202 and write operations are serialized.
203
204 If 64-bit MMIO register operations are not supported, then ASSERT().
205
206 @param Address The MMIO register to write.
207 @param Value The value to write to the MMIO register.
208
209 **/
210 UINT64
211 EFIAPI
212 MmioWrite64 (
213 IN UINTN Address,
214 IN UINT64 Value
215 )
216 {
217 ASSERT ((Address & 7) == 0);
218 return *(volatile UINT64*)Address = Value;
219 }
220
221
222
223 /**
224 Reads an 8-bit I/O port.
225
226 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
227 This function must guarantee that all I/O read and write operations are
228 serialized.
229
230 If 8-bit I/O port operations are not supported, then ASSERT().
231
232 @param Port The I/O port to read.
233
234 @return The value read.
235
236 **/
237 __inline__
238 UINT8
239 EFIAPI
240 IoRead8 (
241 IN UINTN Port
242 )
243 {
244 UINT8 Data;
245
246 __asm__ __volatile__ ("inb %w1,%b0" : "=a" (Data) : "d" ((UINT16)Port));
247 return Data;
248 }
249
250 /**
251 Writes an 8-bit I/O port.
252
253 Writes the 8-bit I/O port specified by Port with the value specified by Value
254 and returns Value. This function must guarantee that all I/O read and write
255 operations are serialized.
256
257 If 8-bit I/O port operations are not supported, then ASSERT().
258
259 @param Port The I/O port to write.
260 @param Value The value to write to the I/O port.
261
262 @return The value written the I/O port.
263
264 **/
265 __inline__
266 UINT8
267 EFIAPI
268 IoWrite8 (
269 IN UINTN Port,
270 IN UINT8 Value
271 )
272 {
273 __asm__ __volatile__ ("outb %b0,%w1" : : "a" (Value), "d" ((UINT16)Port));
274 return Value;;
275 }
276
277 /**
278 Reads a 16-bit I/O port.
279
280 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
281 This function must guarantee that all I/O read and write operations are
282 serialized.
283
284 If 16-bit I/O port operations are not supported, then ASSERT().
285
286 @param Port The I/O port to read.
287
288 @return The value read.
289
290 **/
291 __inline__
292 UINT16
293 EFIAPI
294 IoRead16 (
295 IN UINTN Port
296 )
297 {
298 UINT16 Data;
299
300 ASSERT ((Port & 1) == 0);
301 __asm__ __volatile__ ("inw %w1,%w0" : "=a" (Data) : "d" ((UINT16)Port));
302 return Data;
303 }
304
305 /**
306 Writes a 16-bit I/O port.
307
308 Writes the 16-bit I/O port specified by Port with the value specified by Value
309 and returns Value. This function must guarantee that all I/O read and write
310 operations are serialized.
311
312 If 16-bit I/O port operations are not supported, then ASSERT().
313
314 @param Port The I/O port to write.
315 @param Value The value to write to the I/O port.
316
317 @return The value written the I/O port.
318
319 **/
320 __inline__
321 UINT16
322 EFIAPI
323 IoWrite16 (
324 IN UINTN Port,
325 IN UINT16 Value
326 )
327 {
328 ASSERT ((Port & 1) == 0);
329 __asm__ __volatile__ ("outw %w0,%w1" : : "a" (Value), "d" ((UINT16)Port));
330 return Value;;
331 }
332
333 /**
334 Reads a 32-bit I/O port.
335
336 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
337 This function must guarantee that all I/O read and write operations are
338 serialized.
339
340 If 32-bit I/O port operations are not supported, then ASSERT().
341
342 @param Port The I/O port to read.
343
344 @return The value read.
345
346 **/
347 __inline__
348 UINT32
349 EFIAPI
350 IoRead32 (
351 IN UINTN Port
352 )
353 {
354 UINT32 Data;
355
356 ASSERT ((Port & 3) == 0);
357 __asm__ __volatile__ ("inl %w1,%0" : "=a" (Data) : "d" ((UINT16)Port));
358 return Data;
359 }
360
361 /**
362 Writes a 32-bit I/O port.
363
364 Writes the 32-bit I/O port specified by Port with the value specified by Value
365 and returns Value. This function must guarantee that all I/O read and write
366 operations are serialized.
367
368 If 32-bit I/O port operations are not supported, then ASSERT().
369
370 @param Port The I/O port to write.
371 @param Value The value to write to the I/O port.
372
373 @return The value written the I/O port.
374
375 **/
376 __inline__
377 UINT32
378 EFIAPI
379 IoWrite32 (
380 IN UINTN Port,
381 IN UINT32 Value
382 )
383 {
384 ASSERT ((Port & 3) == 0);
385 __asm__ __volatile__ ("outl %0,%w1" : : "a" (Value), "d" ((UINT16)Port));
386 return Value;
387 }
388