]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/IoLibGcc.c
remove unnecessary comments introduced by tools from MdePkg. The regular express...
[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 from Address.
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 The value written to the Mmio. It equals to the input
63 Value instead of the actual value read back from the
64 Mmio.
65 **/
66 UINT8
67 EFIAPI
68 MmioWrite8 (
69 IN UINTN Address,
70 IN UINT8 Value
71 )
72 {
73 return *(volatile UINT8*)Address = Value;
74 }
75
76 /**
77 Reads a 16-bit MMIO register.
78
79 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
80 returned. This function must guarantee that all MMIO read and write
81 operations are serialized.
82
83 If 16-bit MMIO register operations are not supported, then ASSERT().
84
85 @param Address The MMIO register to read.
86
87 @return The value read from Address.
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
109 @param Address The MMIO register to write.
110 @param Value The value to write to the MMIO register.
111
112 @return The value written to the Mmio. It equals to the input
113 Value instead of the actual value read back from the
114 Mmio.
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
136 @param Address The MMIO register to read.
137
138 @return The value read from Address.
139
140 **/
141 UINT32
142 EFIAPI
143 MmioRead32 (
144 IN UINTN Address
145 )
146 {
147 ASSERT ((Address & 3) == 0);
148 return *(volatile UINT32*)Address;
149 }
150
151 /**
152 Writes a 32-bit MMIO register.
153
154 Writes the 32-bit MMIO register specified by Address with the value specified
155 by Value and returns Value. This function must guarantee that all MMIO read
156 and write operations are serialized.
157
158 If 32-bit MMIO register operations are not supported, then ASSERT().
159
160 @param Address The MMIO register to write.
161 @param Value The value to write to the MMIO register.
162
163 @return The value written to the Mmio. It equals to the input
164 Value instead of the actual value read back from the
165 Mmio.
166 **/
167 UINT32
168 EFIAPI
169 MmioWrite32 (
170 IN UINTN Address,
171 IN UINT32 Value
172 )
173 {
174 ASSERT ((Address & 3) == 0);
175 return *(volatile UINT32*)Address = Value;
176 }
177
178 /**
179 Reads a 64-bit MMIO register.
180
181 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
182 returned. This function must guarantee that all MMIO read and write
183 operations are serialized.
184
185 If 64-bit MMIO register operations are not supported, then ASSERT().
186
187 @param Address The MMIO register to read.
188
189 @return The value read from Address.
190
191 **/
192 UINT64
193 EFIAPI
194 MmioRead64 (
195 IN UINTN Address
196 )
197 {
198 ASSERT ((Address & 7) == 0);
199 return *(volatile UINT64*)Address;
200 }
201
202 /**
203 Writes a 64-bit MMIO register.
204
205 Writes the 64-bit MMIO register specified by Address with the value specified
206 by Value and returns Value. This function must guarantee that all MMIO read
207 and write operations are serialized.
208
209 If 64-bit MMIO register operations are not supported, then ASSERT().
210
211 @param Address The MMIO register to write.
212 @param Value The value to write to the MMIO register.
213
214 @return The value written to the Mmio. It equals to the input
215 Value instead of the actual value read back from the
216 Mmio.
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 UINT8
247 EFIAPI
248 IoRead8 (
249 IN UINTN Port
250 )
251 {
252 UINT8 Data;
253
254 __asm__ __volatile__ ("inb %w1,%b0" : "=a" (Data) : "d" ((UINT16)Port));
255 return Data;
256 }
257
258 /**
259 Writes an 8-bit I/O port.
260
261 Writes the 8-bit I/O port specified by Port with the value specified by Value
262 and returns Value. This function must guarantee that all I/O read and write
263 operations are serialized.
264
265 If 8-bit I/O port operations are not supported, then ASSERT().
266
267 @param Port The I/O port to write.
268 @param Value The value to write to the I/O port.
269
270 @return The value written to the I/O port. It equals to the
271 input Value instead of the actual value read back from
272 the I/O port.
273
274 **/
275 __inline__
276 UINT8
277 EFIAPI
278 IoWrite8 (
279 IN UINTN Port,
280 IN UINT8 Value
281 )
282 {
283 __asm__ __volatile__ ("outb %b0,%w1" : : "a" (Value), "d" ((UINT16)Port));
284 return Value;;
285 }
286
287 /**
288 Reads a 16-bit I/O port.
289
290 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
291 This function must guarantee that all I/O read and write operations are
292 serialized.
293
294 If 16-bit I/O port operations are not supported, then ASSERT().
295
296 @param Port The I/O port to read.
297
298 @return The value read from Port.
299
300 **/
301 __inline__
302 UINT16
303 EFIAPI
304 IoRead16 (
305 IN UINTN Port
306 )
307 {
308 UINT16 Data;
309
310 ASSERT ((Port & 1) == 0);
311 __asm__ __volatile__ ("inw %w1,%w0" : "=a" (Data) : "d" ((UINT16)Port));
312 return Data;
313 }
314
315 /**
316 Writes a 16-bit I/O port.
317
318 Writes the 16-bit I/O port specified by Port with the value specified by Value
319 and returns Value. This function must guarantee that all I/O read and write
320 operations are serialized.
321
322 If 16-bit I/O port operations are not supported, then ASSERT().
323
324 @param Port The I/O port to write.
325 @param Value The value to write to the I/O port.
326
327 @return The value written to the I/O port. It equals to the
328 input Value instead of the actual value read back from
329 the I/O port.
330
331 **/
332 __inline__
333 UINT16
334 EFIAPI
335 IoWrite16 (
336 IN UINTN Port,
337 IN UINT16 Value
338 )
339 {
340 ASSERT ((Port & 1) == 0);
341 __asm__ __volatile__ ("outw %w0,%w1" : : "a" (Value), "d" ((UINT16)Port));
342 return Value;;
343 }
344
345 /**
346 Reads a 32-bit I/O port.
347
348 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
349 This function must guarantee that all I/O read and write operations are
350 serialized.
351
352 If 32-bit I/O port operations are not supported, then ASSERT().
353
354 @param Port The I/O port to read.
355
356 @return The value read from Port.
357
358 **/
359 __inline__
360 UINT32
361 EFIAPI
362 IoRead32 (
363 IN UINTN Port
364 )
365 {
366 UINT32 Data;
367
368 ASSERT ((Port & 3) == 0);
369 __asm__ __volatile__ ("inl %w1,%0" : "=a" (Data) : "d" ((UINT16)Port));
370 return Data;
371 }
372
373 /**
374 Writes a 32-bit I/O port.
375
376 Writes the 32-bit I/O port specified by Port with the value specified by Value
377 and returns Value. This function must guarantee that all I/O read and write
378 operations are serialized.
379
380 If 32-bit I/O port operations are not supported, then ASSERT().
381
382 @param Port The I/O port to write.
383 @param Value The value to write to the I/O port.
384
385 @return The value written to the I/O port. It equals to the
386 input Value instead of the actual value read back from
387 the I/O port.
388
389 **/
390 __inline__
391 UINT32
392 EFIAPI
393 IoWrite32 (
394 IN UINTN Port,
395 IN UINT32 Value
396 )
397 {
398 ASSERT ((Port & 3) == 0);
399 __asm__ __volatile__ ("outl %0,%w1" : : "a" (Value), "d" ((UINT16)Port));
400 return Value;
401 }
402