]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/PeiIoLibCpuIo/IoLib.c
2 I/O Library. The implementations are based on EFI_PEI_SERVICE->CpuIo interface.
4 Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
5 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.
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.
18 #include <Library/IoLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/BaseLib.h>
21 #include <Library/PeiServicesTablePointerLib.h>
24 Reads an 8-bit I/O port.
26 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
27 This function must guarantee that all I/O read and write operations are
30 If 8-bit I/O port operations are not supported, then ASSERT().
32 @param Port The I/O port to read.
34 @return The value read.
43 CONST EFI_PEI_SERVICES
**PeiServices
;
44 EFI_PEI_CPU_IO_PPI
*CpuIo
;
46 PeiServices
= GetPeiServicesTablePointer ();
47 CpuIo
= (*PeiServices
)->CpuIo
;
48 ASSERT (CpuIo
!= NULL
);
50 return CpuIo
->IoRead8 (PeiServices
, CpuIo
, (UINT64
) Port
);
54 Writes an 8-bit I/O port.
56 Writes the 8-bit I/O port specified by Port with the value specified by Value
57 and returns Value. This function must guarantee that all I/O read and write
58 operations are serialized.
60 If 8-bit I/O port operations are not supported, then ASSERT().
62 @param Port The I/O port to write.
63 @param Value The value to write to the I/O port.
65 @return The value written the I/O port.
75 CONST EFI_PEI_SERVICES
**PeiServices
;
76 EFI_PEI_CPU_IO_PPI
*CpuIo
;
78 PeiServices
= GetPeiServicesTablePointer ();
79 CpuIo
= (*PeiServices
)->CpuIo
;
80 ASSERT (CpuIo
!= NULL
);
82 CpuIo
->IoWrite8 (PeiServices
, CpuIo
, (UINT64
) Port
, Value
);
87 Reads a 16-bit I/O port.
89 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
90 This function must guarantee that all I/O read and write operations are
93 If 16-bit I/O port operations are not supported, then ASSERT().
94 If Port is not aligned on a 16-bit boundary, then ASSERT().
96 @param Port The I/O port to read.
98 @return The value read.
107 CONST EFI_PEI_SERVICES
**PeiServices
;
108 EFI_PEI_CPU_IO_PPI
*CpuIo
;
110 PeiServices
= GetPeiServicesTablePointer ();
111 CpuIo
= (*PeiServices
)->CpuIo
;
112 ASSERT (CpuIo
!= NULL
);
114 // Make sure Port is aligned on a 16-bit boundary.
116 ASSERT ((Port
& 1) == 0);
117 return CpuIo
->IoRead16 (PeiServices
, CpuIo
, (UINT64
) Port
);
121 Writes a 16-bit I/O port.
123 Writes the 16-bit I/O port specified by Port with the value specified by Value
124 and returns Value. This function must guarantee that all I/O read and write
125 operations are serialized.
127 If 16-bit I/O port operations are not supported, then ASSERT().
128 If Port is not aligned on a 16-bit boundary, then ASSERT().
130 @param Port The I/O port to write.
131 @param Value The value to write to the I/O port.
133 @return The value written the I/O port.
143 CONST EFI_PEI_SERVICES
**PeiServices
;
144 EFI_PEI_CPU_IO_PPI
*CpuIo
;
146 PeiServices
= GetPeiServicesTablePointer ();
147 CpuIo
= (*PeiServices
)->CpuIo
;
148 ASSERT (CpuIo
!= NULL
);
150 // Make sure Port is aligned on a 16-bit boundary.
152 ASSERT ((Port
& 1) == 0);
153 CpuIo
->IoWrite16 (PeiServices
, CpuIo
, (UINT64
) Port
, Value
);
158 Reads a 32-bit I/O port.
160 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
161 This function must guarantee that all I/O read and write operations are
164 If 32-bit I/O port operations are not supported, then ASSERT().
165 If Port is not aligned on a 32-bit boundary, then ASSERT().
167 @param Port The I/O port to read.
169 @return The value read.
178 CONST EFI_PEI_SERVICES
**PeiServices
;
179 EFI_PEI_CPU_IO_PPI
*CpuIo
;
181 PeiServices
= GetPeiServicesTablePointer ();
182 CpuIo
= (*PeiServices
)->CpuIo
;
183 ASSERT (CpuIo
!= NULL
);
185 // Make sure Port is aligned on a 32-bit boundary.
187 ASSERT ((Port
& 3) == 0);
188 return CpuIo
->IoRead32 (PeiServices
, CpuIo
, (UINT64
) Port
);
192 Writes a 32-bit I/O port.
194 Writes the 32-bit I/O port specified by Port with the value specified by Value
195 and returns Value. This function must guarantee that all I/O read and write
196 operations are serialized.
198 If 32-bit I/O port operations are not supported, then ASSERT().
199 If Port is not aligned on a 32-bit boundary, then ASSERT().
201 @param Port The I/O port to write.
202 @param Value The value to write to the I/O port.
204 @return The value written the I/O port.
214 CONST EFI_PEI_SERVICES
**PeiServices
;
215 EFI_PEI_CPU_IO_PPI
*CpuIo
;
217 PeiServices
= GetPeiServicesTablePointer ();
218 CpuIo
= (*PeiServices
)->CpuIo
;
219 ASSERT (CpuIo
!= NULL
);
221 // Make sure Port is aligned on a 32-bit boundary.
223 ASSERT ((Port
& 3) == 0);
224 CpuIo
->IoWrite32 (PeiServices
, CpuIo
, (UINT64
) Port
, Value
);
229 Reads a 64-bit I/O port.
231 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
232 This function must guarantee that all I/O read and write operations are
235 If 64-bit I/O port operations are not supported, then ASSERT().
236 If Port is not aligned on a 64-bit boundary, then ASSERT().
238 @param Port The I/O port to read.
240 @return The value read.
249 CONST EFI_PEI_SERVICES
**PeiServices
;
250 EFI_PEI_CPU_IO_PPI
*CpuIo
;
252 PeiServices
= GetPeiServicesTablePointer ();
253 CpuIo
= (*PeiServices
)->CpuIo
;
254 ASSERT (CpuIo
!= NULL
);
256 // Make sure Port is aligned on a 64-bit boundary.
258 ASSERT ((Port
& 7) == 0);
259 return CpuIo
->IoRead64 (PeiServices
, CpuIo
, (UINT64
) Port
);
263 Writes a 64-bit I/O port.
265 Writes the 64-bit I/O port specified by Port with the value specified by Value
266 and returns Value. This function must guarantee that all I/O read and write
267 operations are serialized.
269 If 64-bit I/O port operations are not supported, then ASSERT().
270 If Port is not aligned on a 64-bit boundary, then ASSERT().
272 @param Port The I/O port to write.
273 @param Value The value to write to the I/O port.
275 @return The value written the I/O port.
285 CONST EFI_PEI_SERVICES
**PeiServices
;
286 EFI_PEI_CPU_IO_PPI
*CpuIo
;
288 PeiServices
= GetPeiServicesTablePointer ();
289 CpuIo
= (*PeiServices
)->CpuIo
;
290 ASSERT (CpuIo
!= NULL
);
292 // Make sure Port is aligned on a 64-bit boundary.
294 ASSERT ((Port
& 7) == 0);
295 CpuIo
->IoWrite64 (PeiServices
, CpuIo
, (UINT64
) Port
, Value
);
300 Reads an 8-bit MMIO register.
302 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
303 returned. This function must guarantee that all MMIO read and write
304 operations are serialized.
306 If 8-bit MMIO register operations are not supported, then ASSERT().
308 @param Address The MMIO register to read.
310 @return The value read.
319 CONST EFI_PEI_SERVICES
**PeiServices
;
320 EFI_PEI_CPU_IO_PPI
*CpuIo
;
322 PeiServices
= GetPeiServicesTablePointer ();
323 CpuIo
= (*PeiServices
)->CpuIo
;
324 ASSERT (CpuIo
!= NULL
);
326 return CpuIo
->MemRead8 (PeiServices
, CpuIo
, (UINT64
) Address
);
330 Writes an 8-bit MMIO register.
332 Writes the 8-bit MMIO register specified by Address with the value specified
333 by Value and returns Value. This function must guarantee that all MMIO read
334 and write operations are serialized.
336 If 8-bit MMIO register operations are not supported, then ASSERT().
338 @param Address The MMIO register to write.
339 @param Value The value to write to the MMIO register.
351 CONST EFI_PEI_SERVICES
**PeiServices
;
352 EFI_PEI_CPU_IO_PPI
*CpuIo
;
354 PeiServices
= GetPeiServicesTablePointer ();
355 CpuIo
= (*PeiServices
)->CpuIo
;
356 ASSERT (CpuIo
!= NULL
);
358 CpuIo
->MemWrite8 (PeiServices
, CpuIo
, (UINT64
) Address
, Value
);
363 Reads a 16-bit MMIO register.
365 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
366 returned. This function must guarantee that all MMIO read and write
367 operations are serialized.
369 If 16-bit MMIO register operations are not supported, then ASSERT().
370 If Address is not aligned on a 16-bit boundary, then ASSERT().
372 @param Address The MMIO register to read.
374 @return The value read.
383 CONST EFI_PEI_SERVICES
**PeiServices
;
384 EFI_PEI_CPU_IO_PPI
*CpuIo
;
386 PeiServices
= GetPeiServicesTablePointer ();
387 CpuIo
= (*PeiServices
)->CpuIo
;
388 ASSERT (CpuIo
!= NULL
);
390 // Make sure Address is aligned on a 16-bit boundary.
392 ASSERT ((Address
& 1) == 0);
393 return CpuIo
->MemRead16 (PeiServices
, CpuIo
, (UINT64
) Address
);
398 Writes a 16-bit MMIO register.
400 Writes the 16-bit MMIO register specified by Address with the value specified
401 by Value and returns Value. This function must guarantee that all MMIO read
402 and write operations are serialized.
404 If 16-bit MMIO register operations are not supported, then ASSERT().
405 If Address is not aligned on a 16-bit boundary, then ASSERT().
407 @param Address The MMIO register to write.
408 @param Value The value to write to the MMIO register.
420 CONST EFI_PEI_SERVICES
**PeiServices
;
421 EFI_PEI_CPU_IO_PPI
*CpuIo
;
423 PeiServices
= GetPeiServicesTablePointer ();
424 CpuIo
= (*PeiServices
)->CpuIo
;
425 ASSERT (CpuIo
!= NULL
);
427 // Make sure Address is aligned on a 16-bit boundary.
429 ASSERT ((Address
& 1) == 0);
430 CpuIo
->MemWrite16 (PeiServices
, CpuIo
, (UINT64
) Address
, Value
);
435 Reads a 32-bit MMIO register.
437 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
438 returned. This function must guarantee that all MMIO read and write
439 operations are serialized.
441 If 32-bit MMIO register operations are not supported, then ASSERT().
442 If Address is not aligned on a 32-bit boundary, then ASSERT().
444 @param Address The MMIO register to read.
446 @return The value read.
455 CONST EFI_PEI_SERVICES
**PeiServices
;
456 EFI_PEI_CPU_IO_PPI
*CpuIo
;
458 PeiServices
= GetPeiServicesTablePointer ();
459 CpuIo
= (*PeiServices
)->CpuIo
;
460 ASSERT (CpuIo
!= NULL
);
462 // Make sure Address is aligned on a 32-bit boundary.
464 ASSERT ((Address
& 3) == 0);
465 return CpuIo
->MemRead32 (PeiServices
, CpuIo
, (UINT64
) Address
);
470 Writes a 32-bit MMIO register.
472 Writes the 32-bit MMIO register specified by Address with the value specified
473 by Value and returns Value. This function must guarantee that all MMIO read
474 and write operations are serialized.
476 If 32-bit MMIO register operations are not supported, then ASSERT().
477 If Address is not aligned on a 32-bit boundary, then ASSERT().
479 @param Address The MMIO register to write.
480 @param Value The value to write to the MMIO register.
492 CONST EFI_PEI_SERVICES
**PeiServices
;
493 EFI_PEI_CPU_IO_PPI
*CpuIo
;
495 PeiServices
= GetPeiServicesTablePointer ();
496 CpuIo
= (*PeiServices
)->CpuIo
;
497 ASSERT (CpuIo
!= NULL
);
499 // Make sure Address is aligned on a 32-bit boundary.
501 ASSERT ((Address
& 3) == 0);
502 CpuIo
->MemWrite32 (PeiServices
, CpuIo
, (UINT64
) Address
, Value
);
507 Reads a 64-bit MMIO register.
509 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
510 returned. This function must guarantee that all MMIO read and write
511 operations are serialized.
513 If 64-bit MMIO register operations are not supported, then ASSERT().
514 If Address is not aligned on a 64-bit boundary, then ASSERT().
516 @param Address The MMIO register to read.
518 @return The value read.
527 CONST EFI_PEI_SERVICES
**PeiServices
;
528 EFI_PEI_CPU_IO_PPI
*CpuIo
;
530 PeiServices
= GetPeiServicesTablePointer ();
531 CpuIo
= (*PeiServices
)->CpuIo
;
532 ASSERT (CpuIo
!= NULL
);
534 // Make sure Address is aligned on a 64-bit boundary.
536 ASSERT ((Address
& (sizeof (UINT64
) - 1)) == 0);
537 return CpuIo
->MemRead64 (PeiServices
, CpuIo
, (UINT64
) Address
);
542 Writes a 64-bit MMIO register.
544 Writes the 64-bit MMIO register specified by Address with the value specified
545 by Value and returns Value. This function must guarantee that all MMIO read
546 and write operations are serialized.
548 If 64-bit MMIO register operations are not supported, then ASSERT().
549 If Address is not aligned on a 64-bit boundary, then ASSERT().
551 @param Address The MMIO register to write.
552 @param Value The value to write to the MMIO register.
562 CONST EFI_PEI_SERVICES
**PeiServices
;
563 EFI_PEI_CPU_IO_PPI
*CpuIo
;
565 PeiServices
= GetPeiServicesTablePointer ();
566 CpuIo
= (*PeiServices
)->CpuIo
;
567 ASSERT (CpuIo
!= NULL
);
569 // Make sure Address is aligned on a 64-bit boundary.
571 ASSERT ((Address
& 7) == 0);
572 CpuIo
->MemWrite64 (PeiServices
, CpuIo
, (UINT64
) Address
, Value
);