]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/BaseIoLibIntrinsic/IoLibGcc.c
0e22d10d33698b498852e16e96986fc892dba5da
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EdkIIGlueLib / 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. All rights reserved.<BR>
14 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 #include "BaseIoLibIntrinsicInternal.h"
24
25 /**
26 Reads an 8-bit MMIO register.
27
28 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
29 returned. This function must guarantee that all MMIO read and write
30 operations are serialized.
31
32 If 8-bit MMIO register operations are not supported, then ASSERT().
33
34 @param Address The MMIO register to read.
35
36 @return The value read.
37
38 **/
39 UINT8
40 EFIAPI
41 MmioRead8 (
42 IN UINTN Address
43 )
44 {
45 return *(volatile UINT8*)Address;
46 }
47
48 /**
49 Writes an 8-bit MMIO register.
50
51 Writes the 8-bit MMIO register specified by Address with the value specified
52 by Value and returns Value. This function must guarantee that all MMIO read
53 and write operations are serialized.
54
55 If 8-bit MMIO register operations are not supported, then ASSERT().
56
57 @param Address The MMIO register to write.
58 @param Value The value to write to the MMIO register.
59
60 **/
61 UINT8
62 EFIAPI
63 MmioWrite8 (
64 IN UINTN Address,
65 IN UINT8 Value
66 )
67 {
68 return *(volatile UINT8*)Address = Value;
69 }
70
71 /**
72 Reads a 16-bit MMIO register.
73
74 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
75 returned. This function must guarantee that all MMIO read and write
76 operations are serialized.
77
78 If 16-bit MMIO register operations are not supported, then ASSERT().
79
80 @param Address The MMIO register to read.
81
82 @return The value read.
83
84 **/
85 UINT16
86 EFIAPI
87 MmioRead16 (
88 IN UINTN Address
89 )
90 {
91 ASSERT ((Address & 1) == 0);
92 return *(volatile UINT16*)Address;
93 }
94
95 /**
96 Writes a 16-bit MMIO register.
97
98 Writes the 16-bit MMIO register specified by Address with the value specified
99 by Value and returns Value. This function must guarantee that all MMIO read
100 and write operations are serialized.
101
102 If 16-bit MMIO register operations are not supported, then ASSERT().
103
104 @param Address The MMIO register to write.
105 @param Value The value to write to the MMIO register.
106
107 **/
108 UINT16
109 EFIAPI
110 MmioWrite16 (
111 IN UINTN Address,
112 IN UINT16 Value
113 )
114 {
115 ASSERT ((Address & 1) == 0);
116 return *(volatile UINT16*)Address = Value;
117 }
118
119 /**
120 Reads a 32-bit MMIO register.
121
122 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
123 returned. This function must guarantee that all MMIO read and write
124 operations are serialized.
125
126 If 32-bit MMIO register operations are not supported, then ASSERT().
127
128 @param Address The MMIO register to read.
129
130 @return The value read.
131
132 **/
133 UINT32
134 EFIAPI
135 MmioRead32 (
136 IN UINTN Address
137 )
138 {
139 ASSERT ((Address & 3) == 0);
140 return *(volatile UINT32*)Address;
141 }
142
143 /**
144 Writes a 32-bit MMIO register.
145
146 Writes the 32-bit MMIO register specified by Address with the value specified
147 by Value and returns Value. This function must guarantee that all MMIO read
148 and write operations are serialized.
149
150 If 32-bit MMIO register operations are not supported, then ASSERT().
151
152 @param Address The MMIO register to write.
153 @param Value The value to write to the MMIO register.
154
155 **/
156 UINT32
157 EFIAPI
158 MmioWrite32 (
159 IN UINTN Address,
160 IN UINT32 Value
161 )
162 {
163 ASSERT ((Address & 3) == 0);
164 return *(volatile UINT32*)Address = Value;
165 }
166
167 /**
168 Reads a 64-bit MMIO register.
169
170 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
171 returned. This function must guarantee that all MMIO read and write
172 operations are serialized.
173
174 If 64-bit MMIO register operations are not supported, then ASSERT().
175
176 @param Address The MMIO register to read.
177
178 @return The value read.
179
180 **/
181 UINT64
182 EFIAPI
183 MmioRead64 (
184 IN UINTN Address
185 )
186 {
187 ASSERT ((Address & 7) == 0);
188 return *(volatile UINT64*)Address;
189 }
190
191 /**
192 Writes a 64-bit MMIO register.
193
194 Writes the 64-bit MMIO register specified by Address with the value specified
195 by Value and returns Value. This function must guarantee that all MMIO read
196 and write operations are serialized.
197
198 If 64-bit MMIO register operations are not supported, then ASSERT().
199
200 @param Address The MMIO register to write.
201 @param Value The value to write to the MMIO register.
202
203 **/
204 UINT64
205 EFIAPI
206 MmioWrite64 (
207 IN UINTN Address,
208 IN UINT64 Value
209 )
210 {
211 ASSERT ((Address & 7) == 0);
212 return *(volatile UINT64*)Address = Value;
213 }
214
215
216
217 /**
218 Reads an 8-bit I/O port.
219
220 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
221 This function must guarantee that all I/O read and write operations are
222 serialized.
223
224 If 8-bit I/O port operations are not supported, then ASSERT().
225
226 @param Port The I/O port to read.
227
228 @return The value read.
229
230 **/
231 __inline__
232 UINT8
233 EFIAPI
234 IoRead8 (
235 IN UINTN Port
236 )
237 {
238 UINT8 Data;
239
240 __asm__ __volatile__ ("inb %w1,%b0" : "=a" (Data) : "d" ((UINT16)Port));
241 return Data;
242 }
243
244 /**
245 Writes an 8-bit I/O port.
246
247 Writes the 8-bit I/O port specified by Port with the value specified by Value
248 and returns Value. This function must guarantee that all I/O read and write
249 operations are serialized.
250
251 If 8-bit I/O port operations are not supported, then ASSERT().
252
253 @param Port The I/O port to write.
254 @param Value The value to write to the I/O port.
255
256 @return The value written the I/O port.
257
258 **/
259 __inline__
260 UINT8
261 EFIAPI
262 IoWrite8 (
263 IN UINTN Port,
264 IN UINT8 Value
265 )
266 {
267 __asm__ __volatile__ ("outb %b0,%w1" : : "a" (Value), "d" ((UINT16)Port));
268 return Value;;
269 }
270
271 /**
272 Reads a 16-bit I/O port.
273
274 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
275 This function must guarantee that all I/O read and write operations are
276 serialized.
277
278 If 16-bit I/O port operations are not supported, then ASSERT().
279
280 @param Port The I/O port to read.
281
282 @return The value read.
283
284 **/
285 __inline__
286 UINT16
287 EFIAPI
288 IoRead16 (
289 IN UINTN Port
290 )
291 {
292 UINT16 Data;
293
294 ASSERT ((Port & 1) == 0);
295 __asm__ __volatile__ ("inw %w1,%w0" : "=a" (Data) : "d" ((UINT16)Port));
296 return Data;
297 }
298
299 /**
300 Writes a 16-bit I/O port.
301
302 Writes the 16-bit I/O port specified by Port with the value specified by Value
303 and returns Value. This function must guarantee that all I/O read and write
304 operations are serialized.
305
306 If 16-bit I/O port operations are not supported, then ASSERT().
307
308 @param Port The I/O port to write.
309 @param Value The value to write to the I/O port.
310
311 @return The value written the I/O port.
312
313 **/
314 __inline__
315 UINT16
316 EFIAPI
317 IoWrite16 (
318 IN UINTN Port,
319 IN UINT16 Value
320 )
321 {
322 ASSERT ((Port & 1) == 0);
323 __asm__ __volatile__ ("outw %w0,%w1" : : "a" (Value), "d" ((UINT16)Port));
324 return Value;;
325 }
326
327 /**
328 Reads a 32-bit I/O port.
329
330 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
331 This function must guarantee that all I/O read and write operations are
332 serialized.
333
334 If 32-bit I/O port operations are not supported, then ASSERT().
335
336 @param Port The I/O port to read.
337
338 @return The value read.
339
340 **/
341 __inline__
342 UINT32
343 EFIAPI
344 IoRead32 (
345 IN UINTN Port
346 )
347 {
348 UINT32 Data;
349
350 ASSERT ((Port & 3) == 0);
351 __asm__ __volatile__ ("inl %w1,%0" : "=a" (Data) : "d" ((UINT16)Port));
352 return Data;
353 }
354
355 /**
356 Writes a 32-bit I/O port.
357
358 Writes the 32-bit I/O port specified by Port with the value specified by Value
359 and returns Value. This function must guarantee that all I/O read and write
360 operations are serialized.
361
362 If 32-bit I/O port operations are not supported, then ASSERT().
363
364 @param Port The I/O port to write.
365 @param Value The value to write to the I/O port.
366
367 @return The value written the I/O port.
368
369 **/
370 __inline__
371 UINT32
372 EFIAPI
373 IoWrite32 (
374 IN UINTN Port,
375 IN UINT32 Value
376 )
377 {
378 ASSERT ((Port & 3) == 0);
379 __asm__ __volatile__ ("outl %0,%w1" : : "a" (Value), "d" ((UINT16)Port));
380 return Value;
381 }
382