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