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