]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/PeiIoLibCpuIo/IoLib.c
e2d6ea631daf059b954b72cdb271e40ba5de99c9
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.
16 // The package level header files this module uses
20 // The Library classes this module consumes
22 #include <Library/IoLib.h>
23 #include <Library/DebugLib.h>
24 #include <Library/BaseLib.h>
25 #include <Library/PeiServicesTablePointerLib.h>
28 Reads an 8-bit I/O port.
30 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
31 This function must guarantee that all I/O read and write operations are
34 If 8-bit I/O port operations are not supported, then ASSERT().
36 @param Port The I/O port to read.
38 @return The value read.
47 EFI_PEI_SERVICES
**PeiServices
;
48 EFI_PEI_CPU_IO_PPI
*CpuIo
;
50 PeiServices
= GetPeiServicesTablePointer ();
51 CpuIo
= (*PeiServices
)->CpuIo
;
52 ASSERT (CpuIo
!= NULL
);
54 return CpuIo
->IoRead8 (PeiServices
, CpuIo
, (UINT64
) Port
);
58 Writes an 8-bit I/O port.
60 Writes the 8-bit I/O port specified by Port with the value specified by Value
61 and returns Value. This function must guarantee that all I/O read and write
62 operations are serialized.
64 If 8-bit I/O port operations are not supported, then ASSERT().
66 @param Port The I/O port to write.
67 @param Value The value to write to the I/O port.
69 @return The value written the I/O port.
79 EFI_PEI_SERVICES
**PeiServices
;
80 EFI_PEI_CPU_IO_PPI
*CpuIo
;
82 PeiServices
= GetPeiServicesTablePointer ();
83 CpuIo
= (*PeiServices
)->CpuIo
;
84 ASSERT (CpuIo
!= NULL
);
86 CpuIo
->IoWrite8 (PeiServices
, CpuIo
, (UINT64
) Port
, Value
);
91 Reads a 16-bit I/O port.
93 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
94 This function must guarantee that all I/O read and write operations are
97 If 16-bit I/O port operations are not supported, then ASSERT().
99 @param Port The I/O port to read.
101 @return The value read.
110 EFI_PEI_SERVICES
**PeiServices
;
111 EFI_PEI_CPU_IO_PPI
*CpuIo
;
113 PeiServices
= GetPeiServicesTablePointer ();
114 CpuIo
= (*PeiServices
)->CpuIo
;
115 ASSERT (CpuIo
!= NULL
);
117 // Make sure Port is aligned on a 16-bit boundary.
119 ASSERT ((Port
& 1) == 0);
120 return CpuIo
->IoRead16 (PeiServices
, CpuIo
, (UINT64
) Port
);
124 Writes a 16-bit I/O port.
126 Writes the 16-bit I/O port specified by Port with the value specified by Value
127 and returns Value. This function must guarantee that all I/O read and write
128 operations are serialized.
130 If 16-bit I/O port operations are not supported, then ASSERT().
132 @param Port The I/O port to write.
133 @param Value The value to write to the I/O port.
135 @return The value written the I/O port.
145 EFI_PEI_SERVICES
**PeiServices
;
146 EFI_PEI_CPU_IO_PPI
*CpuIo
;
148 PeiServices
= GetPeiServicesTablePointer ();
149 CpuIo
= (*PeiServices
)->CpuIo
;
150 ASSERT (CpuIo
!= NULL
);
152 // Make sure Port is aligned on a 16-bit boundary.
154 ASSERT ((Port
& 1) == 0);
155 CpuIo
->IoWrite16 (PeiServices
, CpuIo
, (UINT64
) Port
, Value
);
160 Reads a 32-bit I/O port.
162 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
163 This function must guarantee that all I/O read and write operations are
166 If 32-bit I/O port operations are not supported, then ASSERT().
168 @param Port The I/O port to read.
170 @return The value read.
179 EFI_PEI_SERVICES
**PeiServices
;
180 EFI_PEI_CPU_IO_PPI
*CpuIo
;
182 PeiServices
= GetPeiServicesTablePointer ();
183 CpuIo
= (*PeiServices
)->CpuIo
;
184 ASSERT (CpuIo
!= NULL
);
186 // Make sure Port is aligned on a 32-bit boundary.
188 ASSERT ((Port
& 3) == 0);
189 return CpuIo
->IoRead32 (PeiServices
, CpuIo
, (UINT64
) Port
);
193 Writes a 32-bit I/O port.
195 Writes the 32-bit I/O port specified by Port with the value specified by Value
196 and returns Value. This function must guarantee that all I/O read and write
197 operations are serialized.
199 If 32-bit I/O port operations are not supported, 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 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().
237 @param Port The I/O port to read.
239 @return The value read.
248 EFI_PEI_SERVICES
**PeiServices
;
249 EFI_PEI_CPU_IO_PPI
*CpuIo
;
251 PeiServices
= GetPeiServicesTablePointer ();
252 CpuIo
= (*PeiServices
)->CpuIo
;
253 ASSERT (CpuIo
!= NULL
);
255 // Make sure Port is aligned on a 64-bit boundary.
257 ASSERT ((Port
& 7) == 0);
258 return CpuIo
->IoRead64 (PeiServices
, CpuIo
, (UINT64
) Port
);
262 Writes a 64-bit I/O port.
264 Writes the 64-bit I/O port specified by Port with the value specified by Value
265 and returns Value. This function must guarantee that all I/O read and write
266 operations are serialized.
268 If 64-bit I/O port operations are not supported, then ASSERT().
270 @param Port The I/O port to write.
271 @param Value The value to write to the I/O port.
273 @return The value written the I/O port.
283 EFI_PEI_SERVICES
**PeiServices
;
284 EFI_PEI_CPU_IO_PPI
*CpuIo
;
286 PeiServices
= GetPeiServicesTablePointer ();
287 CpuIo
= (*PeiServices
)->CpuIo
;
288 ASSERT (CpuIo
!= NULL
);
290 // Make sure Port is aligned on a 64-bit boundary.
292 ASSERT ((Port
& 7) == 0);
293 CpuIo
->IoWrite64 (PeiServices
, CpuIo
, (UINT64
) Port
, Value
);
298 Reads an 8-bit MMIO register.
300 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
301 returned. This function must guarantee that all MMIO read and write
302 operations are serialized.
304 If 8-bit MMIO register operations are not supported, then ASSERT().
306 @param Address The MMIO register to read.
308 @return The value read.
317 EFI_PEI_SERVICES
**PeiServices
;
318 EFI_PEI_CPU_IO_PPI
*CpuIo
;
320 PeiServices
= GetPeiServicesTablePointer ();
321 CpuIo
= (*PeiServices
)->CpuIo
;
322 ASSERT (CpuIo
!= NULL
);
324 return CpuIo
->MemRead8 (PeiServices
, CpuIo
, (UINT64
) Address
);
328 Writes an 8-bit MMIO register.
330 Writes the 8-bit MMIO register specified by Address with the value specified
331 by Value and returns Value. This function must guarantee that all MMIO read
332 and write operations are serialized.
334 If 8-bit MMIO register operations are not supported, then ASSERT().
336 @param Address The MMIO register to write.
337 @param Value The value to write to the MMIO register.
347 EFI_PEI_SERVICES
**PeiServices
;
348 EFI_PEI_CPU_IO_PPI
*CpuIo
;
350 PeiServices
= GetPeiServicesTablePointer ();
351 CpuIo
= (*PeiServices
)->CpuIo
;
352 ASSERT (CpuIo
!= NULL
);
354 CpuIo
->MemWrite8 (PeiServices
, CpuIo
, (UINT64
) Address
, Value
);
359 Reads a 16-bit MMIO register.
361 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
362 returned. This function must guarantee that all MMIO read and write
363 operations are serialized.
365 If 16-bit MMIO register operations are not supported, then ASSERT().
367 @param Address The MMIO register to read.
369 @return The value read.
378 EFI_PEI_SERVICES
**PeiServices
;
379 EFI_PEI_CPU_IO_PPI
*CpuIo
;
381 PeiServices
= GetPeiServicesTablePointer ();
382 CpuIo
= (*PeiServices
)->CpuIo
;
383 ASSERT (CpuIo
!= NULL
);
385 // Make sure Address is aligned on a 16-bit boundary.
387 ASSERT ((Address
& 1) == 0);
388 return CpuIo
->MemRead16 (PeiServices
, CpuIo
, (UINT64
) Address
);
393 Writes a 16-bit MMIO register.
395 Writes the 16-bit MMIO register specified by Address with the value specified
396 by Value and returns Value. This function must guarantee that all MMIO read
397 and write operations are serialized.
399 If 16-bit MMIO register operations are not supported, then ASSERT().
401 @param Address The MMIO register to write.
402 @param Value The value to write to the MMIO register.
412 EFI_PEI_SERVICES
**PeiServices
;
413 EFI_PEI_CPU_IO_PPI
*CpuIo
;
415 PeiServices
= GetPeiServicesTablePointer ();
416 CpuIo
= (*PeiServices
)->CpuIo
;
417 ASSERT (CpuIo
!= NULL
);
419 // Make sure Address is aligned on a 16-bit boundary.
421 ASSERT ((Address
& 1) == 0);
422 CpuIo
->MemWrite16 (PeiServices
, CpuIo
, (UINT64
) Address
, Value
);
427 Reads a 32-bit MMIO register.
429 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
430 returned. This function must guarantee that all MMIO read and write
431 operations are serialized.
433 If 32-bit MMIO register operations are not supported, then ASSERT().
435 @param Address The MMIO register to read.
437 @return The value read.
446 EFI_PEI_SERVICES
**PeiServices
;
447 EFI_PEI_CPU_IO_PPI
*CpuIo
;
449 PeiServices
= GetPeiServicesTablePointer ();
450 CpuIo
= (*PeiServices
)->CpuIo
;
451 ASSERT (CpuIo
!= NULL
);
453 // Make sure Address is aligned on a 32-bit boundary.
455 ASSERT ((Address
& 3) == 0);
456 return CpuIo
->MemRead32 (PeiServices
, CpuIo
, (UINT64
) Address
);
461 Writes a 32-bit MMIO register.
463 Writes the 32-bit MMIO register specified by Address with the value specified
464 by Value and returns Value. This function must guarantee that all MMIO read
465 and write operations are serialized.
467 If 32-bit MMIO register operations are not supported, then ASSERT().
469 @param Address The MMIO register to write.
470 @param Value The value to write to the MMIO register.
480 EFI_PEI_SERVICES
**PeiServices
;
481 EFI_PEI_CPU_IO_PPI
*CpuIo
;
483 PeiServices
= GetPeiServicesTablePointer ();
484 CpuIo
= (*PeiServices
)->CpuIo
;
485 ASSERT (CpuIo
!= NULL
);
487 // Make sure Address is aligned on a 32-bit boundary.
489 ASSERT ((Address
& 3) == 0);
490 CpuIo
->MemWrite32 (PeiServices
, CpuIo
, (UINT64
) Address
, Value
);
495 Reads a 64-bit MMIO register.
497 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
498 returned. This function must guarantee that all MMIO read and write
499 operations are serialized.
501 If 64-bit MMIO register operations are not supported, then ASSERT().
503 @param Address The MMIO register to read.
505 @return The value read.
514 EFI_PEI_SERVICES
**PeiServices
;
515 EFI_PEI_CPU_IO_PPI
*CpuIo
;
517 PeiServices
= GetPeiServicesTablePointer ();
518 CpuIo
= (*PeiServices
)->CpuIo
;
519 ASSERT (CpuIo
!= NULL
);
521 // Make sure Address is aligned on a 64-bit boundary.
523 ASSERT ((Address
& 7) == 0);
524 return CpuIo
->MemRead64 (PeiServices
, CpuIo
, (UINT64
) Address
);
529 Writes a 64-bit MMIO register.
531 Writes the 64-bit MMIO register specified by Address with the value specified
532 by Value and returns Value. This function must guarantee that all MMIO read
533 and write operations are serialized.
535 If 64-bit MMIO register operations are not supported, then ASSERT().
537 @param Address The MMIO register to write.
538 @param Value The value to write to the MMIO register.
548 EFI_PEI_SERVICES
**PeiServices
;
549 EFI_PEI_CPU_IO_PPI
*CpuIo
;
551 PeiServices
= GetPeiServicesTablePointer ();
552 CpuIo
= (*PeiServices
)->CpuIo
;
553 ASSERT (CpuIo
!= NULL
);
555 // Make sure Address is aligned on a 64-bit boundary.
557 ASSERT ((Address
& 7) == 0);
558 CpuIo
->MemWrite64 (PeiServices
, CpuIo
, (UINT64
) Address
, Value
);