]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseIoLibIntrinsic/IoLibGcc.c
Code scrub:
[mirror_edk2.git] / MdePkg / Library / BaseIoLibIntrinsic / IoLibGcc.c
CommitLineData
e1f414b6 1/** @file\r
2 I/O Library. This file has compiler specifics for GCC as there is no\r
3 ANSI C standard for doing IO.\r
4\r
5 GCC - uses EFIAPI assembler. __asm__ calls GAS. __volatile__ makes sure the\r
6 compiler puts the assembler in this exact location. The complex GNUC\r
7 operations are not optimzed. It would be possible to also write these\r
8 with EFIAPI assembler.\r
9\r
10 We don't advocate putting compiler specifics in libraries or drivers but there\r
11 is no other way to make this work.\r
12\r
13 Copyright (c) 2006 - 2007, Intel Corporation<BR>\r
14 All rights reserved. This program and the accompanying materials\r
15 are licensed and made available under the terms and conditions of the BSD License\r
16 which accompanies this distribution. The full text of the license may be found at\r
17 http://opensource.org/licenses/bsd-license.php\r
18\r
19 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
20 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
21\r
e1f414b6 22**/\r
23\r
24//\r
25// Include common header file for this module.\r
26//\r
f734a10a 27#include "BaseIoLibIntrinsicInternal.h"\r
e1f414b6 28\r
29/**\r
30 Reads an 8-bit MMIO register.\r
31\r
32 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is\r
33 returned. This function must guarantee that all MMIO read and write\r
34 operations are serialized.\r
35\r
36 If 8-bit MMIO register operations are not supported, then ASSERT().\r
37\r
38 @param Address The MMIO register to read.\r
39\r
38bbd3d9 40 @return The value read from Address.\r
e1f414b6 41\r
42**/\r
43UINT8\r
44EFIAPI\r
45MmioRead8 (\r
46 IN UINTN Address\r
47 )\r
48{\r
49 return *(volatile UINT8*)Address;\r
50}\r
51\r
52/**\r
53 Writes an 8-bit MMIO register.\r
54\r
55 Writes the 8-bit MMIO register specified by Address with the value specified\r
56 by Value and returns Value. This function must guarantee that all MMIO read\r
57 and write operations are serialized.\r
58\r
59 If 8-bit MMIO register operations are not supported, then ASSERT().\r
60\r
61 @param Address The MMIO register to write.\r
62 @param Value The value to write to the MMIO register.\r
63\r
38bbd3d9 64 @return The value written to the Mmio. It equals to the input\r
65 Value instead of the actual value read back from the\r
66 Mmio.\r
e1f414b6 67**/\r
68UINT8\r
69EFIAPI\r
70MmioWrite8 (\r
71 IN UINTN Address,\r
72 IN UINT8 Value\r
73 )\r
74{\r
75 return *(volatile UINT8*)Address = Value;\r
76}\r
77\r
78/**\r
79 Reads a 16-bit MMIO register.\r
80\r
81 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is\r
82 returned. This function must guarantee that all MMIO read and write\r
83 operations are serialized.\r
84\r
85 If 16-bit MMIO register operations are not supported, then ASSERT().\r
86\r
87 @param Address The MMIO register to read.\r
88\r
38bbd3d9 89 @return The value read from Address.\r
e1f414b6 90\r
91**/\r
92UINT16\r
93EFIAPI\r
94MmioRead16 (\r
95 IN UINTN Address\r
96 )\r
97{\r
98 ASSERT ((Address & 1) == 0);\r
99 return *(volatile UINT16*)Address;\r
100}\r
101\r
102/**\r
103 Writes a 16-bit MMIO register.\r
104\r
105 Writes the 16-bit MMIO register specified by Address with the value specified\r
106 by Value and returns Value. This function must guarantee that all MMIO read\r
107 and write operations are serialized.\r
108\r
109 If 16-bit MMIO register operations are not supported, then ASSERT().\r
110\r
111 @param Address The MMIO register to write.\r
112 @param Value The value to write to the MMIO register.\r
113\r
38bbd3d9 114 @return The value written to the Mmio. It equals to the input\r
115 Value instead of the actual value read back from the\r
116 Mmio.\r
e1f414b6 117**/\r
118UINT16\r
119EFIAPI\r
120MmioWrite16 (\r
121 IN UINTN Address,\r
122 IN UINT16 Value\r
123 )\r
124{\r
125 ASSERT ((Address & 1) == 0);\r
126 return *(volatile UINT16*)Address = Value;\r
127}\r
128\r
129/**\r
130 Reads a 32-bit MMIO register.\r
131\r
132 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is\r
133 returned. This function must guarantee that all MMIO read and write\r
134 operations are serialized.\r
135\r
136 If 32-bit MMIO register operations are not supported, then ASSERT().\r
137\r
138 @param Address The MMIO register to read.\r
139\r
38bbd3d9 140 @return The value read from Address.\r
e1f414b6 141\r
142**/\r
143UINT32\r
144EFIAPI\r
145MmioRead32 (\r
146 IN UINTN Address\r
147 )\r
148{\r
149 ASSERT ((Address & 3) == 0);\r
150 return *(volatile UINT32*)Address;\r
151}\r
152\r
153/**\r
154 Writes a 32-bit MMIO register.\r
155\r
156 Writes the 32-bit MMIO register specified by Address with the value specified\r
157 by Value and returns Value. This function must guarantee that all MMIO read\r
158 and write operations are serialized.\r
159\r
160 If 32-bit MMIO register operations are not supported, then ASSERT().\r
161\r
162 @param Address The MMIO register to write.\r
163 @param Value The value to write to the MMIO register.\r
164\r
38bbd3d9 165 @return The value written to the Mmio. It equals to the input\r
166 Value instead of the actual value read back from the\r
167 Mmio.\r
e1f414b6 168**/\r
169UINT32\r
170EFIAPI\r
171MmioWrite32 (\r
172 IN UINTN Address,\r
173 IN UINT32 Value\r
174 )\r
175{\r
176 ASSERT ((Address & 3) == 0);\r
177 return *(volatile UINT32*)Address = Value;\r
178}\r
179\r
180/**\r
181 Reads a 64-bit MMIO register.\r
182\r
183 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is\r
184 returned. This function must guarantee that all MMIO read and write\r
185 operations are serialized.\r
186\r
187 If 64-bit MMIO register operations are not supported, then ASSERT().\r
188\r
189 @param Address The MMIO register to read.\r
190\r
38bbd3d9 191 @return The value read from Address.\r
e1f414b6 192\r
193**/\r
194UINT64\r
195EFIAPI\r
196MmioRead64 (\r
197 IN UINTN Address\r
198 )\r
199{\r
200 ASSERT ((Address & 7) == 0);\r
201 return *(volatile UINT64*)Address;\r
202}\r
203\r
204/**\r
205 Writes a 64-bit MMIO register.\r
206\r
207 Writes the 64-bit MMIO register specified by Address with the value specified\r
208 by Value and returns Value. This function must guarantee that all MMIO read\r
209 and write operations are serialized.\r
210\r
211 If 64-bit MMIO register operations are not supported, then ASSERT().\r
212\r
213 @param Address The MMIO register to write.\r
214 @param Value The value to write to the MMIO register.\r
215\r
38bbd3d9 216 @return The value written to the Mmio. It equals to the input\r
217 Value instead of the actual value read back from the\r
218 Mmio.\r
e1f414b6 219**/\r
220UINT64\r
221EFIAPI\r
222MmioWrite64 (\r
223 IN UINTN Address,\r
224 IN UINT64 Value\r
225 )\r
226{\r
227 ASSERT ((Address & 7) == 0);\r
228 return *(volatile UINT64*)Address = Value;\r
229}\r
230\r
231\r
232\r
233/**\r
234 Reads an 8-bit I/O port.\r
235\r
236 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.\r
237 This function must guarantee that all I/O read and write operations are\r
238 serialized.\r
239\r
240 If 8-bit I/O port operations are not supported, then ASSERT().\r
241\r
242 @param Port The I/O port to read.\r
243\r
38bbd3d9 244 @return The value read from Port.\r
e1f414b6 245\r
246**/\r
247__inline__\r
248UINT8\r
249EFIAPI\r
250IoRead8 (\r
251 IN UINTN Port\r
252 )\r
253{\r
254 UINT8 Data;\r
255\r
256 __asm__ __volatile__ ("inb %w1,%b0" : "=a" (Data) : "d" ((UINT16)Port));\r
257 return Data;\r
258}\r
259\r
260/**\r
261 Writes an 8-bit I/O port.\r
262\r
263 Writes the 8-bit I/O port specified by Port with the value specified by Value\r
264 and returns Value. This function must guarantee that all I/O read and write\r
265 operations are serialized.\r
266\r
267 If 8-bit I/O port operations are not supported, then ASSERT().\r
268\r
269 @param Port The I/O port to write.\r
270 @param Value The value to write to the I/O port.\r
271\r
38bbd3d9 272 @return The value written to the I/O port. It equals to the\r
273 input Value instead of the actual value read back from\r
274 the I/O port.\r
e1f414b6 275\r
276**/\r
277__inline__\r
278UINT8\r
279EFIAPI\r
280IoWrite8 (\r
281 IN UINTN Port,\r
282 IN UINT8 Value\r
283 )\r
284{\r
285 __asm__ __volatile__ ("outb %b0,%w1" : : "a" (Value), "d" ((UINT16)Port));\r
286 return Value;;\r
287}\r
288\r
289/**\r
290 Reads a 16-bit I/O port.\r
291\r
292 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.\r
293 This function must guarantee that all I/O read and write operations are\r
294 serialized.\r
295\r
296 If 16-bit I/O port operations are not supported, then ASSERT().\r
297\r
298 @param Port The I/O port to read.\r
299\r
38bbd3d9 300 @return The value read from Port.\r
e1f414b6 301\r
302**/\r
303__inline__\r
304UINT16\r
305EFIAPI\r
306IoRead16 (\r
307 IN UINTN Port\r
308 )\r
309{\r
310 UINT16 Data;\r
311\r
312 ASSERT ((Port & 1) == 0);\r
313 __asm__ __volatile__ ("inw %w1,%w0" : "=a" (Data) : "d" ((UINT16)Port));\r
314 return Data;\r
315}\r
316\r
317/**\r
318 Writes a 16-bit I/O port.\r
319\r
320 Writes the 16-bit I/O port specified by Port with the value specified by Value\r
321 and returns Value. This function must guarantee that all I/O read and write\r
322 operations are serialized.\r
323\r
324 If 16-bit I/O port operations are not supported, then ASSERT().\r
325\r
326 @param Port The I/O port to write.\r
327 @param Value The value to write to the I/O port.\r
328\r
38bbd3d9 329 @return The value written to the I/O port. It equals to the\r
330 input Value instead of the actual value read back from\r
331 the I/O port.\r
e1f414b6 332\r
333**/\r
334__inline__\r
335UINT16\r
336EFIAPI\r
337IoWrite16 (\r
338 IN UINTN Port,\r
339 IN UINT16 Value\r
340 )\r
341{\r
342 ASSERT ((Port & 1) == 0);\r
343 __asm__ __volatile__ ("outw %w0,%w1" : : "a" (Value), "d" ((UINT16)Port));\r
344 return Value;;\r
345}\r
346\r
347/**\r
348 Reads a 32-bit I/O port.\r
349\r
350 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.\r
351 This function must guarantee that all I/O read and write operations are\r
352 serialized.\r
353\r
354 If 32-bit I/O port operations are not supported, then ASSERT().\r
355\r
356 @param Port The I/O port to read.\r
357\r
38bbd3d9 358 @return The value read from Port.\r
e1f414b6 359\r
360**/\r
361__inline__\r
362UINT32\r
363EFIAPI\r
364IoRead32 (\r
365 IN UINTN Port\r
366 )\r
367{\r
368 UINT32 Data;\r
369\r
370 ASSERT ((Port & 3) == 0);\r
371 __asm__ __volatile__ ("inl %w1,%0" : "=a" (Data) : "d" ((UINT16)Port));\r
372 return Data;\r
373}\r
374\r
375/**\r
376 Writes a 32-bit I/O port.\r
377\r
378 Writes the 32-bit I/O port specified by Port with the value specified by Value\r
379 and returns Value. This function must guarantee that all I/O read and write\r
380 operations are serialized.\r
381\r
382 If 32-bit I/O port operations are not supported, then ASSERT().\r
383\r
384 @param Port The I/O port to write.\r
385 @param Value The value to write to the I/O port.\r
386\r
38bbd3d9 387 @return The value written to the I/O port. It equals to the\r
388 input Value instead of the actual value read back from\r
389 the I/O port.\r
e1f414b6 390\r
391**/\r
392__inline__\r
393UINT32\r
394EFIAPI\r
395IoWrite32 (\r
396 IN UINTN Port,\r
397 IN UINT32 Value\r
398 )\r
399{\r
400 ASSERT ((Port & 3) == 0);\r
401 __asm__ __volatile__ ("outl %0,%w1" : : "a" (Value), "d" ((UINT16)Port));\r
402 return Value;\r
403}\r
404\r