]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/PeiIoLibCpuIo/IoLib.c
4 Copyright (c) 2006, 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
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 // The package level header files this module uses
22 // The Library classes this module consumes
24 #include <Library/IoLib.h>
25 #include <Library/DebugLib.h>
26 #include <Library/BaseLib.h>
27 #include <Library/PeiServicesTablePointerLib.h>
30 Reads an 8-bit I/O port.
32 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
33 This function must guarantee that all I/O read and write operations are
36 If 8-bit I/O port operations are not supported, then ASSERT().
38 @param Port The I/O port to read.
40 @return The value read.
49 EFI_PEI_SERVICES
**PeiServices
;
50 EFI_PEI_CPU_IO_PPI
*CpuIo
;
52 PeiServices
= GetPeiServicesTablePointer ();
53 CpuIo
= (*PeiServices
)->CpuIo
;
54 ASSERT (CpuIo
!= NULL
);
56 return CpuIo
->IoRead8 (PeiServices
, CpuIo
, (UINT64
) Port
);
60 Writes an 8-bit I/O port.
62 Writes the 8-bit I/O port specified by Port with the value specified by Value
63 and returns Value. This function must guarantee that all I/O read and write
64 operations are serialized.
66 If 8-bit I/O port operations are not supported, then ASSERT().
68 @param Port The I/O port to write.
69 @param Value The value to write to the I/O port.
71 @return The value written the I/O port.
81 EFI_PEI_SERVICES
**PeiServices
;
82 EFI_PEI_CPU_IO_PPI
*CpuIo
;
84 PeiServices
= GetPeiServicesTablePointer ();
85 CpuIo
= (*PeiServices
)->CpuIo
;
86 ASSERT (CpuIo
!= NULL
);
88 CpuIo
->IoWrite8 (PeiServices
, CpuIo
, (UINT64
) Port
, Value
);
93 Reads a 16-bit I/O port.
95 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
96 This function must guarantee that all I/O read and write operations are
99 If 16-bit I/O port operations are not supported, then ASSERT().
101 @param Port The I/O port to read.
103 @return The value read.
112 EFI_PEI_SERVICES
**PeiServices
;
113 EFI_PEI_CPU_IO_PPI
*CpuIo
;
115 PeiServices
= GetPeiServicesTablePointer ();
116 CpuIo
= (*PeiServices
)->CpuIo
;
117 ASSERT (CpuIo
!= NULL
);
119 // Make sure Port is aligned on a 16-bit boundary.
121 ASSERT ((Port
& 1) == 0);
122 return CpuIo
->IoRead16 (PeiServices
, CpuIo
, (UINT64
) Port
);
126 Writes a 16-bit I/O port.
128 Writes the 16-bit I/O port specified by Port with the value specified by Value
129 and returns Value. This function must guarantee that all I/O read and write
130 operations are serialized.
132 If 16-bit I/O port operations are not supported, then ASSERT().
134 @param Port The I/O port to write.
135 @param Value The value to write to the I/O port.
137 @return The value written the I/O port.
147 EFI_PEI_SERVICES
**PeiServices
;
148 EFI_PEI_CPU_IO_PPI
*CpuIo
;
150 PeiServices
= GetPeiServicesTablePointer ();
151 CpuIo
= (*PeiServices
)->CpuIo
;
152 ASSERT (CpuIo
!= NULL
);
154 // Make sure Port is aligned on a 16-bit boundary.
156 ASSERT ((Port
& 1) == 0);
157 CpuIo
->IoWrite16 (PeiServices
, CpuIo
, (UINT64
) Port
, Value
);
162 Reads a 32-bit I/O port.
164 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
165 This function must guarantee that all I/O read and write operations are
168 If 32-bit I/O port operations are not supported, then ASSERT().
170 @param Port The I/O port to read.
172 @return The value read.
181 EFI_PEI_SERVICES
**PeiServices
;
182 EFI_PEI_CPU_IO_PPI
*CpuIo
;
184 PeiServices
= GetPeiServicesTablePointer ();
185 CpuIo
= (*PeiServices
)->CpuIo
;
186 ASSERT (CpuIo
!= NULL
);
188 // Make sure Port is aligned on a 32-bit boundary.
190 ASSERT ((Port
& 3) == 0);
191 return CpuIo
->IoRead32 (PeiServices
, CpuIo
, (UINT64
) Port
);
195 Writes a 32-bit I/O port.
197 Writes the 32-bit I/O port specified by Port with the value specified by Value
198 and returns Value. This function must guarantee that all I/O read and write
199 operations are serialized.
201 If 32-bit I/O port operations are not supported, then ASSERT().
203 @param Port The I/O port to write.
204 @param Value The value to write to the I/O port.
206 @return The value written the I/O port.
216 EFI_PEI_SERVICES
**PeiServices
;
217 EFI_PEI_CPU_IO_PPI
*CpuIo
;
219 PeiServices
= GetPeiServicesTablePointer ();
220 CpuIo
= (*PeiServices
)->CpuIo
;
221 ASSERT (CpuIo
!= NULL
);
223 // Make sure Port is aligned on a 32-bit boundary.
225 ASSERT ((Port
& 3) == 0);
226 CpuIo
->IoWrite32 (PeiServices
, CpuIo
, (UINT64
) Port
, Value
);
231 Reads a 64-bit I/O port.
233 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
234 This function must guarantee that all I/O read and write operations are
237 If 64-bit I/O port operations are not supported, then ASSERT().
239 @param Port The I/O port to read.
241 @return The value read.
250 EFI_PEI_SERVICES
**PeiServices
;
251 EFI_PEI_CPU_IO_PPI
*CpuIo
;
253 PeiServices
= GetPeiServicesTablePointer ();
254 CpuIo
= (*PeiServices
)->CpuIo
;
255 ASSERT (CpuIo
!= NULL
);
257 // Make sure Port is aligned on a 64-bit boundary.
259 ASSERT ((Port
& 7) == 0);
260 return CpuIo
->IoRead64 (PeiServices
, CpuIo
, (UINT64
) Port
);
264 Writes a 64-bit I/O port.
266 Writes the 64-bit I/O port specified by Port with the value specified by Value
267 and returns Value. This function must guarantee that all I/O read and write
268 operations are serialized.
270 If 64-bit I/O port operations are not supported, 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 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 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.
349 EFI_PEI_SERVICES
**PeiServices
;
350 EFI_PEI_CPU_IO_PPI
*CpuIo
;
352 PeiServices
= GetPeiServicesTablePointer ();
353 CpuIo
= (*PeiServices
)->CpuIo
;
354 ASSERT (CpuIo
!= NULL
);
356 CpuIo
->MemWrite8 (PeiServices
, CpuIo
, (UINT64
) Address
, Value
);
361 Reads a 16-bit MMIO register.
363 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
364 returned. This function must guarantee that all MMIO read and write
365 operations are serialized.
367 If 16-bit MMIO register operations are not supported, then ASSERT().
369 @param Address The MMIO register to read.
371 @return The value read.
380 EFI_PEI_SERVICES
**PeiServices
;
381 EFI_PEI_CPU_IO_PPI
*CpuIo
;
383 PeiServices
= GetPeiServicesTablePointer ();
384 CpuIo
= (*PeiServices
)->CpuIo
;
385 ASSERT (CpuIo
!= NULL
);
387 // Make sure Address is aligned on a 16-bit boundary.
389 ASSERT ((Address
& 1) == 0);
390 return CpuIo
->MemRead16 (PeiServices
, CpuIo
, (UINT64
) Address
);
395 Writes a 16-bit MMIO register.
397 Writes the 16-bit MMIO register specified by Address with the value specified
398 by Value and returns Value. This function must guarantee that all MMIO read
399 and write operations are serialized.
401 If 16-bit MMIO register operations are not supported, then ASSERT().
403 @param Address The MMIO register to write.
404 @param Value The value to write to the MMIO register.
414 EFI_PEI_SERVICES
**PeiServices
;
415 EFI_PEI_CPU_IO_PPI
*CpuIo
;
417 PeiServices
= GetPeiServicesTablePointer ();
418 CpuIo
= (*PeiServices
)->CpuIo
;
419 ASSERT (CpuIo
!= NULL
);
421 // Make sure Address is aligned on a 16-bit boundary.
423 ASSERT ((Address
& 1) == 0);
424 CpuIo
->MemWrite16 (PeiServices
, CpuIo
, (UINT64
) Address
, Value
);
429 Reads a 32-bit MMIO register.
431 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
432 returned. This function must guarantee that all MMIO read and write
433 operations are serialized.
435 If 32-bit MMIO register operations are not supported, then ASSERT().
437 @param Address The MMIO register to read.
439 @return The value read.
448 EFI_PEI_SERVICES
**PeiServices
;
449 EFI_PEI_CPU_IO_PPI
*CpuIo
;
451 PeiServices
= GetPeiServicesTablePointer ();
452 CpuIo
= (*PeiServices
)->CpuIo
;
453 ASSERT (CpuIo
!= NULL
);
455 // Make sure Address is aligned on a 32-bit boundary.
457 ASSERT ((Address
& 3) == 0);
458 return CpuIo
->MemRead32 (PeiServices
, CpuIo
, (UINT64
) Address
);
463 Writes a 32-bit MMIO register.
465 Writes the 32-bit MMIO register specified by Address with the value specified
466 by Value and returns Value. This function must guarantee that all MMIO read
467 and write operations are serialized.
469 If 32-bit MMIO register operations are not supported, then ASSERT().
471 @param Address The MMIO register to write.
472 @param Value The value to write to the MMIO register.
482 EFI_PEI_SERVICES
**PeiServices
;
483 EFI_PEI_CPU_IO_PPI
*CpuIo
;
485 PeiServices
= GetPeiServicesTablePointer ();
486 CpuIo
= (*PeiServices
)->CpuIo
;
487 ASSERT (CpuIo
!= NULL
);
489 // Make sure Address is aligned on a 32-bit boundary.
491 ASSERT ((Address
& 3) == 0);
492 CpuIo
->MemWrite32 (PeiServices
, CpuIo
, (UINT64
) Address
, Value
);
497 Reads a 64-bit MMIO register.
499 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
500 returned. This function must guarantee that all MMIO read and write
501 operations are serialized.
503 If 64-bit MMIO register operations are not supported, then ASSERT().
505 @param Address The MMIO register to read.
507 @return The value read.
516 EFI_PEI_SERVICES
**PeiServices
;
517 EFI_PEI_CPU_IO_PPI
*CpuIo
;
519 PeiServices
= GetPeiServicesTablePointer ();
520 CpuIo
= (*PeiServices
)->CpuIo
;
521 ASSERT (CpuIo
!= NULL
);
523 // Make sure Address is aligned on a 64-bit boundary.
525 ASSERT ((Address
& 7) == 0);
526 return CpuIo
->MemRead64 (PeiServices
, CpuIo
, (UINT64
) Address
);
531 Writes a 64-bit MMIO register.
533 Writes the 64-bit MMIO register specified by Address with the value specified
534 by Value and returns Value. This function must guarantee that all MMIO read
535 and write operations are serialized.
537 If 64-bit MMIO register operations are not supported, then ASSERT().
539 @param Address The MMIO register to write.
540 @param Value The value to write to the MMIO register.
550 EFI_PEI_SERVICES
**PeiServices
;
551 EFI_PEI_CPU_IO_PPI
*CpuIo
;
553 PeiServices
= GetPeiServicesTablePointer ();
554 CpuIo
= (*PeiServices
)->CpuIo
;
555 ASSERT (CpuIo
!= NULL
);
557 // Make sure Address is aligned on a 64-bit boundary.
559 ASSERT ((Address
& 7) == 0);
560 CpuIo
->MemWrite64 (PeiServices
, CpuIo
, (UINT64
) Address
, Value
);