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