]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/IoLibIpf.c
Removed CommonHeader.h generated file from the MdePkg.
[mirror_edk2.git] / MdePkg / Library / BaseIoLibIntrinsic / IoLibIpf.c
1 /** @file
2 Common I/O Library routines.
3
4 Copyright (c) 2006 - 2007, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 Module Name: IoLibIpf.c
14
15 **/
16
17 //
18 // Include common header file for this module.
19 //
20 #include "BaseIoLibIntrinsicInternal.h"
21
22 #define MAP_PORT_BASE_TO_MEM(_Port) \
23 ((((_Port) & 0xfffc) << 10) | ((_Port) & 0x0fff))
24
25 /**
26 Reads a 8-bit I/O port.
27
28 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
29 This function must guarantee that all I/O read and write operations are
30 serialized.
31
32 @param Port The I/O port to read.
33
34 @return The value read.
35
36 **/
37 UINT8
38 EFIAPI
39 IoRead8 (
40 IN UINT64 Port
41 )
42 {
43 UINT64 Address;
44
45 //
46 // Add the 64MB aligned IO Port space to the IO address
47 //
48 Address = MAP_PORT_BASE_TO_MEM (Port);
49 Address += PcdGet64(PcdIoBlockBaseAddressForIpf);
50
51 return MmioRead8 (Address);
52 }
53
54 /**
55 Reads a 16-bit I/O port.
56
57 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
58 This function must guarantee that all I/O read and write operations are
59 serialized.
60
61 @param Port The I/O port to read.
62
63 @return The value read.
64
65 **/
66 UINT16
67 EFIAPI
68 IoRead16 (
69 IN UINT64 Port
70 )
71 {
72 UINT64 Address;
73
74 //
75 // Add the 64MB aligned IO Port space to the IO address
76 //
77 Address = MAP_PORT_BASE_TO_MEM (Port);
78 Address += PcdGet64(PcdIoBlockBaseAddressForIpf);
79
80 return MmioRead16 (Address);
81 }
82
83 /**
84 Reads a 32-bit I/O port.
85
86 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
87 This function must guarantee that all I/O read and write operations are
88 serialized.
89
90 @param Port The I/O port to read.
91
92 @return The value read.
93
94 **/
95 UINT32
96 EFIAPI
97 IoRead32 (
98 IN UINT64 Port
99 )
100 {
101 UINT64 Address;
102
103 //
104 // Add the 64MB aligned IO Port space to the IO address
105 //
106 Address = MAP_PORT_BASE_TO_MEM (Port);
107 Address += PcdGet64(PcdIoBlockBaseAddressForIpf);
108
109 return MmioRead32 (Address);
110 }
111
112 /**
113 Reads a 64-bit I/O port.
114
115 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
116 This function must guarantee that all I/O read and write operations are
117 serialized.
118
119 If 64-bit I/O port operations are not supported, then ASSERT().
120
121 @param Port The I/O port to read.
122
123 @return The value read.
124
125 **/
126 UINT64
127 EFIAPI
128 IoRead64 (
129 IN UINTN Port
130 )
131 {
132 ASSERT (FALSE);
133 return 0;
134 }
135
136 /**
137 Writes a 8-bit I/O port.
138
139 Writes the 8-bit I/O port specified by Port with the value specified by Value
140 and returns Value. This function must guarantee that all I/O read and write
141 operations are serialized.
142
143 @param Port The I/O port to write.
144 @param Value The value to write to the I/O port.
145
146 @return The value written the I/O port.
147
148 **/
149 UINT8
150 EFIAPI
151 IoWrite8 (
152 IN UINT64 Port,
153 IN UINT8 Data
154 )
155 {
156 UINT64 Address;
157
158 //
159 // Add the 64MB aligned IO Port space to the IO address
160 //
161 Address = MAP_PORT_BASE_TO_MEM (Port);
162 Address += PcdGet64(PcdIoBlockBaseAddressForIpf);
163
164 return MmioWrite8 (Address, Data);
165 }
166
167 /**
168 Writes a 16-bit I/O port.
169
170 Writes the 16-bit I/O port specified by Port with the value specified by Value
171 and returns Value. This function must guarantee that all I/O read and write
172 operations are serialized.
173
174 @param Port The I/O port to write.
175 @param Value The value to write to the I/O port.
176
177 @return The value written the I/O port.
178
179 **/
180 UINT16
181 EFIAPI
182 IoWrite16 (
183 IN UINT64 Port,
184 IN UINT16 Data
185 )
186 {
187 UINT64 Address;
188
189 //
190 // Add the 64MB aligned IO Port space to the IO address
191 //
192 Address = MAP_PORT_BASE_TO_MEM (Port);
193 Address += PcdGet64(PcdIoBlockBaseAddressForIpf);
194
195 return MmioWrite16 (Address, Data);
196 }
197
198 /**
199 Writes a 32-bit I/O port.
200
201 Writes the 32-bit I/O port specified by Port with the value specified by Value
202 and returns Value. This function must guarantee that all I/O read and write
203 operations are serialized.
204
205 @param Port The I/O port to write.
206 @param Value The value to write to the I/O port.
207
208 @return The value written the I/O port.
209
210 **/
211 UINT32
212 EFIAPI
213 IoWrite32 (
214 IN UINT64 Port,
215 IN UINT32 Data
216 )
217 {
218 UINT64 Address;
219
220 //
221 // Add the 64MB aligned IO Port space to the IO address
222 //
223 Address = MAP_PORT_BASE_TO_MEM (Port);
224 Address += PcdGet64(PcdIoBlockBaseAddressForIpf);
225
226 return MmioWrite32 (Address, Data);
227 }
228
229 /**
230 Writes a 64-bit I/O port.
231
232 Writes the 64-bit I/O port specified by Port with the value specified by Value
233 and returns Value. This function must guarantee that all I/O read and write
234 operations are serialized.
235
236 If 64-bit I/O port operations are not supported, then ASSERT().
237
238 @param Port The I/O port to write.
239 @param Value The value to write to the I/O port.
240
241 @return The value written the I/O port.
242
243 **/
244 UINT64
245 EFIAPI
246 IoWrite64 (
247 IN UINTN Port,
248 IN UINT64 Value
249 )
250 {
251 ASSERT (FALSE);
252 return 0;
253 }
254
255 /**
256 Reads a 8-bit MMIO register.
257
258 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
259 returned. This function must guarantee that all MMIO read and write
260 operations are serialized.
261
262 @param Address The MMIO register to read.
263
264 @return The value read.
265
266 **/
267 UINT8
268 EFIAPI
269 MmioRead8 (
270 IN UINT64 Address
271 )
272 {
273 UINT8 Data;
274
275 Address |= BIT63;
276
277 MemoryFence ();
278 Data = *((volatile UINT8 *) Address);
279 MemoryFence ();
280
281 return Data;
282 }
283
284 /**
285 Reads a 16-bit MMIO register.
286
287 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
288 returned. This function must guarantee that all MMIO read and write
289 operations are serialized.
290
291 @param Address The MMIO register to read.
292
293 @return The value read.
294
295 **/
296 UINT16
297 EFIAPI
298 MmioRead16 (
299 IN UINT64 Address
300 )
301 {
302 UINT16 Data;
303
304 Address |= BIT63;
305
306 MemoryFence ();
307 Data = *((volatile UINT16 *) Address);
308 MemoryFence ();
309
310 return Data;
311 }
312
313 /**
314 Reads a 32-bit MMIO register.
315
316 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
317 returned. This function must guarantee that all MMIO read and write
318 operations are serialized.
319
320 @param Address The MMIO register to read.
321
322 @return The value read.
323
324 **/
325 UINT32
326 EFIAPI
327 MmioRead32 (
328 IN UINT64 Address
329 )
330 {
331 UINT32 Data;
332
333 Address |= BIT63;
334
335 MemoryFence ();
336 Data = *((volatile UINT32 *) Address);
337 MemoryFence ();
338
339 return Data;
340 }
341
342 /**
343 Reads a 64-bit MMIO register.
344
345 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
346 returned. This function must guarantee that all MMIO read and write
347 operations are serialized.
348
349 @param Address The MMIO register to read.
350
351 @return The value read.
352
353 **/
354 UINT64
355 EFIAPI
356 MmioRead64 (
357 IN UINT64 Address
358 )
359 {
360 UINT64 Data;
361
362 Address |= BIT63;
363
364 MemoryFence ();
365 Data = *((volatile UINT64 *) Address);
366 MemoryFence ();
367
368 return Data;
369
370 }
371
372 /**
373 Writes a 8-bit MMIO register.
374
375 Writes the 8-bit MMIO register specified by Address with the value specified
376 by Value and returns Value. This function must guarantee that all MMIO read
377 and write operations are serialized.
378
379 @param Address The MMIO register to write.
380 @param Data The value to write to the MMIO register.
381
382 @return The value written the memory address.
383
384 **/
385 UINT8
386 EFIAPI
387 MmioWrite8 (
388 IN UINT64 Address,
389 IN UINT8 Data
390 )
391 {
392 Address |= BIT63;
393
394 MemoryFence ();
395 *((volatile UINT8 *) Address) = Data;
396 MemoryFence ();
397
398 return Data;
399 }
400
401 /**
402 Writes a 16-bit MMIO register.
403
404 Writes the 16-bit MMIO register specified by Address with the value specified
405 by Value and returns Value. This function must guarantee that all MMIO read
406 and write operations are serialized.
407
408 @param Address The MMIO register to write.
409 @param Data The value to write to the MMIO register.
410
411 @return The value written the memory address.
412
413 **/
414 UINT16
415 EFIAPI
416 MmioWrite16 (
417 IN UINT64 Address,
418 IN UINT16 Data
419 )
420 {
421 Address |= BIT63;
422
423 MemoryFence ();
424 *((volatile UINT16 *) Address) = Data;
425 MemoryFence ();
426
427 return Data;
428 }
429
430 /**
431 Writes a 32-bit MMIO register.
432
433 Writes the 32-bit MMIO register specified by Address with the value specified
434 by Value and returns Value. This function must guarantee that all MMIO read
435 and write operations are serialized.
436
437 @param Address The MMIO register to write.
438 @param Data The value to write to the MMIO register.
439
440 @return The value written the memory address.
441
442 **/
443 UINT32
444 EFIAPI
445 MmioWrite32 (
446 IN UINT64 Address,
447 IN UINT32 Data
448 )
449 {
450 Address |= BIT63;
451
452 MemoryFence ();
453 *((volatile UINT32 *) Address) = Data;
454 MemoryFence ();
455
456 return Data;
457 }
458
459 /**
460 Writes a 64-bit MMIO register.
461
462 Writes the 64-bit MMIO register specified by Address with the value specified
463 by Value and returns Value. This function must guarantee that all MMIO read
464 and write operations are serialized.
465
466 @param Address The MMIO register to write.
467 @param Data The value to write to the MMIO register.
468
469 @return The value written the memory address.
470
471 **/
472 UINT64
473 EFIAPI
474 MmioWrite64 (
475 IN UINT64 Address,
476 IN UINT64 Data
477 )
478 {
479 Address |= BIT63;
480
481 MemoryFence ();
482 *((volatile UINT64 *) Address) = Data;
483 MemoryFence ();
484
485 return Data;
486 }