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