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