]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/IoLibGcc.c
Synchronize the h files with c files.
[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 **/
23
24
25 #include "BaseIoLibIntrinsicInternal.h"
26
27 /**
28 Reads an 8-bit MMIO register.
29
30 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
31 returned. This function must guarantee that all MMIO read and write
32 operations are serialized.
33
34 If 8-bit MMIO register operations are not supported, then ASSERT().
35
36 @param Address The MMIO register to read.
37
38 @return The value read.
39
40 **/
41 UINT8
42 EFIAPI
43 MmioRead8 (
44 IN UINTN Address
45 )
46 {
47 return *(volatile UINT8*)Address;
48 }
49
50 /**
51 Writes an 8-bit MMIO register.
52
53 Writes the 8-bit MMIO register specified by Address with the value specified
54 by Value and returns Value. This function must guarantee that all MMIO read
55 and write operations are serialized.
56
57 If 8-bit MMIO register operations are not supported, then ASSERT().
58
59 @param Address The MMIO register to write.
60 @param Value The value to write to the MMIO register.
61
62 @return Value.
63
64 **/
65 UINT8
66 EFIAPI
67 MmioWrite8 (
68 IN UINTN Address,
69 IN UINT8 Value
70 )
71 {
72 return *(volatile UINT8*)Address = Value;
73 }
74
75 /**
76 Reads a 16-bit MMIO register.
77
78 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
79 returned. This function must guarantee that all MMIO read and write
80 operations are serialized.
81
82 If 16-bit MMIO register operations are not supported, then ASSERT().
83 If Address is not aligned on a 16-bit boundary, then ASSERT().
84
85 @param Address The MMIO register to read.
86
87 @return The value read.
88
89 **/
90 UINT16
91 EFIAPI
92 MmioRead16 (
93 IN UINTN Address
94 )
95 {
96 ASSERT ((Address & 1) == 0);
97 return *(volatile UINT16*)Address;
98 }
99
100 /**
101 Writes a 16-bit MMIO register.
102
103 Writes the 16-bit MMIO register specified by Address with the value specified
104 by Value and returns Value. This function must guarantee that all MMIO read
105 and write operations are serialized.
106
107 If 16-bit MMIO register operations are not supported, then ASSERT().
108 If Address is not aligned on a 16-bit boundary, then ASSERT().
109
110 @param Address The MMIO register to write.
111 @param Value The value to write to the MMIO register.
112
113 @return Value.
114
115 **/
116 UINT16
117 EFIAPI
118 MmioWrite16 (
119 IN UINTN Address,
120 IN UINT16 Value
121 )
122 {
123 ASSERT ((Address & 1) == 0);
124 return *(volatile UINT16*)Address = Value;
125 }
126
127 /**
128 Reads a 32-bit MMIO register.
129
130 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
131 returned. This function must guarantee that all MMIO read and write
132 operations are serialized.
133
134 If 32-bit MMIO register operations are not supported, then ASSERT().
135 If Address is not aligned on a 32-bit boundary, then ASSERT().
136
137 @param Address The MMIO register to read.
138
139 @return The value read.
140
141 **/
142 UINT32
143 EFIAPI
144 MmioRead32 (
145 IN UINTN Address
146 )
147 {
148 ASSERT ((Address & 3) == 0);
149 return *(volatile UINT32*)Address;
150 }
151
152 /**
153 Writes a 32-bit MMIO register.
154
155 Writes the 32-bit MMIO register specified by Address with the value specified
156 by Value and returns Value. This function must guarantee that all MMIO read
157 and write operations are serialized.
158
159 If 32-bit MMIO register operations are not supported, then ASSERT().
160 If Address is not aligned on a 32-bit boundary, then ASSERT().
161
162 @param Address The MMIO register to write.
163 @param Value The value to write to the MMIO register.
164
165 @return Value.
166
167 **/
168 UINT32
169 EFIAPI
170 MmioWrite32 (
171 IN UINTN Address,
172 IN UINT32 Value
173 )
174 {
175 ASSERT ((Address & 3) == 0);
176 return *(volatile UINT32*)Address = Value;
177 }
178
179 /**
180 Reads a 64-bit MMIO register.
181
182 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
183 returned. This function must guarantee that all MMIO read and write
184 operations are serialized.
185
186 If 64-bit MMIO register operations are not supported, then ASSERT().
187 If Address is not aligned on a 64-bit boundary, then ASSERT().
188
189 @param Address The MMIO register to read.
190
191 @return The value read.
192
193 **/
194 UINT64
195 EFIAPI
196 MmioRead64 (
197 IN UINTN Address
198 )
199 {
200 ASSERT ((Address & 7) == 0);
201 return *(volatile UINT64*)Address;
202 }
203
204 /**
205 Writes a 64-bit MMIO register.
206
207 Writes the 64-bit MMIO register specified by Address with the value specified
208 by Value and returns Value. This function must guarantee that all MMIO read
209 and write operations are serialized.
210
211 If 64-bit MMIO register operations are not supported, then ASSERT().
212 If Address is not aligned on a 64-bit boundary, then ASSERT().
213
214 @param Address The MMIO register to write.
215 @param Value The value to write to the MMIO register.
216
217 **/
218 UINT64
219 EFIAPI
220 MmioWrite64 (
221 IN UINTN Address,
222 IN UINT64 Value
223 )
224 {
225 ASSERT ((Address & 7) == 0);
226 return *(volatile UINT64*)Address = Value;
227 }
228
229
230
231 /**
232 Reads an 8-bit I/O port.
233
234 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
235 This function must guarantee that all I/O read and write operations are
236 serialized.
237
238 If 8-bit I/O port operations are not supported, then ASSERT().
239
240 @param Port The I/O port to read.
241
242 @return The value read from Port.
243
244 **/
245 __inline__
246 /**
247 Reads an 8-bit I/O port.
248
249 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
250 This function must guarantee that all I/O read and write operations are
251 serialized.
252
253 If 8-bit I/O port operations are not supported, then ASSERT().
254
255 @param Port The I/O port to read.
256
257 @return The value read.
258
259 **/
260 UINT8
261 EFIAPI
262 IoRead8 (
263 IN UINTN Port
264 )
265 {
266 UINT8 Data;
267
268 __asm__ __volatile__ ("inb %w1,%b0" : "=a" (Data) : "d" ((UINT16)Port));
269 return Data;
270 }
271
272 /**
273 Writes an 8-bit I/O port.
274
275 Writes the 8-bit I/O port specified by Port with the value specified by Value
276 and returns Value. This function must guarantee that all I/O read and write
277 operations are serialized.
278
279 If 8-bit I/O port operations are not supported, then ASSERT().
280
281 @param Port The I/O port to write.
282 @param Value The value to write to the I/O port.
283
284 @return The value written to the I/O port. It equals to the
285 input Value instead of the actual value read back from
286 the I/O port.
287
288 **/
289 __inline__
290 /**
291 Writes an 8-bit I/O port.
292
293 Writes the 8-bit I/O port specified by Port with the value specified by Value
294 and returns Value. This function must guarantee that all I/O read and write
295 operations are serialized.
296
297 If 8-bit I/O port operations are not supported, then ASSERT().
298
299 @param Port The I/O port to write.
300 @param Value The value to write to the I/O port.
301
302 @return The value written the I/O port.
303
304 **/
305 UINT8
306 EFIAPI
307 IoWrite8 (
308 IN UINTN Port,
309 IN UINT8 Value
310 )
311 {
312 __asm__ __volatile__ ("outb %b0,%w1" : : "a" (Value), "d" ((UINT16)Port));
313 return Value;;
314 }
315
316 /**
317 Reads a 16-bit I/O port.
318
319 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
320 This function must guarantee that all I/O read and write operations are
321 serialized.
322
323 If 16-bit I/O port operations are not supported, then ASSERT().
324
325 @param Port The I/O port to read.
326
327 @return The value read from Port.
328
329 **/
330 __inline__
331 /**
332 Reads a 16-bit I/O port.
333
334 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
335 This function must guarantee that all I/O read and write operations are
336 serialized.
337
338 If 16-bit I/O port operations are not supported, then ASSERT().
339 If Port is not aligned on a 16-bit boundary, then ASSERT().
340
341 @param Port The I/O port to read.
342
343 @return The value read.
344
345 **/
346 UINT16
347 EFIAPI
348 IoRead16 (
349 IN UINTN Port
350 )
351 {
352 UINT16 Data;
353
354 ASSERT ((Port & 1) == 0);
355 __asm__ __volatile__ ("inw %w1,%w0" : "=a" (Data) : "d" ((UINT16)Port));
356 return Data;
357 }
358
359 /**
360 Writes a 16-bit I/O port.
361
362 Writes the 16-bit I/O port specified by Port with the value specified by Value
363 and returns Value. This function must guarantee that all I/O read and write
364 operations are serialized.
365
366 If 16-bit I/O port operations are not supported, then ASSERT().
367
368 @param Port The I/O port to write.
369 @param Value The value to write to the I/O port.
370
371 @return The value written to the I/O port. It equals to the
372 input Value instead of the actual value read back from
373 the I/O port.
374
375 **/
376 __inline__
377 /**
378 Writes a 16-bit I/O port.
379
380 Writes the 16-bit I/O port specified by Port with the value specified by Value
381 and returns Value. This function must guarantee that all I/O read and write
382 operations are serialized.
383
384 If 16-bit I/O port operations are not supported, then ASSERT().
385 If Port is not aligned on a 16-bit boundary, then ASSERT().
386
387 @param Port The I/O port to write.
388 @param Value The value to write to the I/O port.
389
390 @return The value written the I/O port.
391
392 **/
393 UINT16
394 EFIAPI
395 IoWrite16 (
396 IN UINTN Port,
397 IN UINT16 Value
398 )
399 {
400 ASSERT ((Port & 1) == 0);
401 __asm__ __volatile__ ("outw %w0,%w1" : : "a" (Value), "d" ((UINT16)Port));
402 return Value;;
403 }
404
405 /**
406 Reads a 32-bit I/O port.
407
408 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
409 This function must guarantee that all I/O read and write operations are
410 serialized.
411
412 If 32-bit I/O port operations are not supported, then ASSERT().
413
414 @param Port The I/O port to read.
415
416 @return The value read from Port.
417
418 **/
419 __inline__
420 /**
421 Reads a 32-bit I/O port.
422
423 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
424 This function must guarantee that all I/O read and write operations are
425 serialized.
426
427 If 32-bit I/O port operations are not supported, then ASSERT().
428 If Port is not aligned on a 32-bit boundary, then ASSERT().
429
430 @param Port The I/O port to read.
431
432 @return The value read.
433
434 **/
435 UINT32
436 EFIAPI
437 IoRead32 (
438 IN UINTN Port
439 )
440 {
441 UINT32 Data;
442
443 ASSERT ((Port & 3) == 0);
444 __asm__ __volatile__ ("inl %w1,%0" : "=a" (Data) : "d" ((UINT16)Port));
445 return Data;
446 }
447
448 /**
449 Writes a 32-bit I/O port.
450
451 Writes the 32-bit I/O port specified by Port with the value specified by Value
452 and returns Value. This function must guarantee that all I/O read and write
453 operations are serialized.
454
455 If 32-bit I/O port operations are not supported, then ASSERT().
456
457 @param Port The I/O port to write.
458 @param Value The value to write to the I/O port.
459
460 @return The value written to the I/O port. It equals to the
461 input Value instead of the actual value read back from
462 the I/O port.
463
464 **/
465 __inline__
466 /**
467 Writes a 32-bit I/O port.
468
469 Writes the 32-bit I/O port specified by Port with the value specified by Value
470 and returns Value. This function must guarantee that all I/O read and write
471 operations are serialized.
472
473 If 32-bit I/O port operations are not supported, then ASSERT().
474 If Port is not aligned on a 32-bit boundary, then ASSERT().
475
476 @param Port The I/O port to write.
477 @param Value The value to write to the I/O port.
478
479 @return The value written the I/O port.
480
481 **/
482 UINT32
483 EFIAPI
484 IoWrite32 (
485 IN UINTN Port,
486 IN UINT32 Value
487 )
488 {
489 ASSERT ((Port & 3) == 0);
490 __asm__ __volatile__ ("outl %0,%w1" : : "a" (Value), "d" ((UINT16)Port));
491 return Value;
492 }
493