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