]>
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<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 #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 from Port.
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().
95 @param Port The I/O port to read.
97 @return The value read from Port.
106 CONST EFI_PEI_SERVICES
**PeiServices
;
107 EFI_PEI_CPU_IO_PPI
*CpuIo
;
109 PeiServices
= GetPeiServicesTablePointer ();
110 CpuIo
= (*PeiServices
)->CpuIo
;
111 ASSERT (CpuIo
!= NULL
);
113 // Make sure Port is aligned on a 16-bit boundary.
115 ASSERT ((Port
& 1) == 0);
116 return CpuIo
->IoRead16 (PeiServices
, CpuIo
, (UINT64
) Port
);
120 Writes a 16-bit I/O port.
122 Writes the 16-bit I/O port specified by Port with the value specified by Value
123 and returns Value. This function must guarantee that all I/O read and write
124 operations are serialized.
126 If 16-bit I/O port operations are not supported, then ASSERT().
128 @param Port The I/O port to write.
129 @param Value The value to write to the I/O port.
131 @return The value written the I/O port.
141 CONST EFI_PEI_SERVICES
**PeiServices
;
142 EFI_PEI_CPU_IO_PPI
*CpuIo
;
144 PeiServices
= GetPeiServicesTablePointer ();
145 CpuIo
= (*PeiServices
)->CpuIo
;
146 ASSERT (CpuIo
!= NULL
);
148 // Make sure Port is aligned on a 16-bit boundary.
150 ASSERT ((Port
& 1) == 0);
151 CpuIo
->IoWrite16 (PeiServices
, CpuIo
, (UINT64
) Port
, Value
);
156 Reads a 32-bit I/O port.
158 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
159 This function must guarantee that all I/O read and write operations are
162 If 32-bit I/O port operations are not supported, then ASSERT().
164 @param Port The I/O port to read.
166 @return The value read from Port.
175 CONST EFI_PEI_SERVICES
**PeiServices
;
176 EFI_PEI_CPU_IO_PPI
*CpuIo
;
178 PeiServices
= GetPeiServicesTablePointer ();
179 CpuIo
= (*PeiServices
)->CpuIo
;
180 ASSERT (CpuIo
!= NULL
);
182 // Make sure Port is aligned on a 32-bit boundary.
184 ASSERT ((Port
& 3) == 0);
185 return CpuIo
->IoRead32 (PeiServices
, CpuIo
, (UINT64
) Port
);
189 Writes a 32-bit I/O port.
191 Writes the 32-bit I/O port specified by Port with the value specified by Value
192 and returns Value. This function must guarantee that all I/O read and write
193 operations are serialized.
195 If 32-bit I/O port operations are not supported, then ASSERT().
197 @param Port The I/O port to write.
198 @param Value The value to write to the I/O port.
200 @return The value written the I/O port.
210 CONST EFI_PEI_SERVICES
**PeiServices
;
211 EFI_PEI_CPU_IO_PPI
*CpuIo
;
213 PeiServices
= GetPeiServicesTablePointer ();
214 CpuIo
= (*PeiServices
)->CpuIo
;
215 ASSERT (CpuIo
!= NULL
);
217 // Make sure Port is aligned on a 32-bit boundary.
219 ASSERT ((Port
& 3) == 0);
220 CpuIo
->IoWrite32 (PeiServices
, CpuIo
, (UINT64
) Port
, Value
);
225 Reads a 64-bit I/O port.
227 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
228 This function must guarantee that all I/O read and write operations are
231 If 64-bit I/O port operations are not supported, then ASSERT().
233 @param Port The I/O port to read.
235 @return The value read from Port.
244 CONST EFI_PEI_SERVICES
**PeiServices
;
245 EFI_PEI_CPU_IO_PPI
*CpuIo
;
247 PeiServices
= GetPeiServicesTablePointer ();
248 CpuIo
= (*PeiServices
)->CpuIo
;
249 ASSERT (CpuIo
!= NULL
);
251 // Make sure Port is aligned on a 64-bit boundary.
253 ASSERT ((Port
& 7) == 0);
254 return CpuIo
->IoRead64 (PeiServices
, CpuIo
, (UINT64
) Port
);
258 Writes a 64-bit I/O port.
260 Writes the 64-bit I/O port specified by Port with the value specified by Value
261 and returns Value. This function must guarantee that all I/O read and write
262 operations are serialized.
264 If 64-bit I/O port operations are not supported, then ASSERT().
266 @param Port The I/O port to write.
267 @param Value The value to write to the I/O port.
269 @return The value written the I/O port.
279 CONST EFI_PEI_SERVICES
**PeiServices
;
280 EFI_PEI_CPU_IO_PPI
*CpuIo
;
282 PeiServices
= GetPeiServicesTablePointer ();
283 CpuIo
= (*PeiServices
)->CpuIo
;
284 ASSERT (CpuIo
!= NULL
);
286 // Make sure Port is aligned on a 64-bit boundary.
288 ASSERT ((Port
& 7) == 0);
289 CpuIo
->IoWrite64 (PeiServices
, CpuIo
, (UINT64
) Port
, Value
);
294 Reads an 8-bit MMIO register.
296 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
297 returned. This function must guarantee that all MMIO read and write
298 operations are serialized.
300 If 8-bit MMIO register operations are not supported, then ASSERT().
302 @param Address The MMIO register to read.
304 @return The value read from Port.
313 CONST EFI_PEI_SERVICES
**PeiServices
;
314 EFI_PEI_CPU_IO_PPI
*CpuIo
;
316 PeiServices
= GetPeiServicesTablePointer ();
317 CpuIo
= (*PeiServices
)->CpuIo
;
318 ASSERT (CpuIo
!= NULL
);
320 return CpuIo
->MemRead8 (PeiServices
, CpuIo
, (UINT64
) Address
);
324 Writes an 8-bit MMIO register.
326 Writes the 8-bit MMIO register specified by Address with the value specified
327 by Value and returns Value. This function must guarantee that all MMIO read
328 and write operations are serialized.
330 If 8-bit MMIO register operations are not supported, then ASSERT().
332 @param Address The MMIO register to write.
333 @param Value The value to write to the MMIO register.
335 @return The Value written back to Mmio register.
344 CONST EFI_PEI_SERVICES
**PeiServices
;
345 EFI_PEI_CPU_IO_PPI
*CpuIo
;
347 PeiServices
= GetPeiServicesTablePointer ();
348 CpuIo
= (*PeiServices
)->CpuIo
;
349 ASSERT (CpuIo
!= NULL
);
351 CpuIo
->MemWrite8 (PeiServices
, CpuIo
, (UINT64
) Address
, Value
);
356 Reads a 16-bit MMIO register.
358 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
359 returned. This function must guarantee that all MMIO read and write
360 operations are serialized.
362 If 16-bit MMIO register operations are not supported, then ASSERT().
364 @param Address The MMIO register to read.
366 @return The value read from Address.
375 CONST EFI_PEI_SERVICES
**PeiServices
;
376 EFI_PEI_CPU_IO_PPI
*CpuIo
;
378 PeiServices
= GetPeiServicesTablePointer ();
379 CpuIo
= (*PeiServices
)->CpuIo
;
380 ASSERT (CpuIo
!= NULL
);
382 // Make sure Address is aligned on a 16-bit boundary.
384 ASSERT ((Address
& 1) == 0);
385 return CpuIo
->MemRead16 (PeiServices
, CpuIo
, (UINT64
) Address
);
390 Writes a 16-bit MMIO register.
392 Writes the 16-bit MMIO register specified by Address with the value specified
393 by Value and returns Value. This function must guarantee that all MMIO read
394 and write operations are serialized.
396 If 16-bit MMIO register operations are not supported, then ASSERT().
398 @param Address The MMIO register to write.
399 @param Value The value to write to the MMIO register.
401 @return The Value written back to Mmio register
411 CONST EFI_PEI_SERVICES
**PeiServices
;
412 EFI_PEI_CPU_IO_PPI
*CpuIo
;
414 PeiServices
= GetPeiServicesTablePointer ();
415 CpuIo
= (*PeiServices
)->CpuIo
;
416 ASSERT (CpuIo
!= NULL
);
418 // Make sure Address is aligned on a 16-bit boundary.
420 ASSERT ((Address
& 1) == 0);
421 CpuIo
->MemWrite16 (PeiServices
, CpuIo
, (UINT64
) Address
, Value
);
426 Reads a 32-bit MMIO register.
428 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
429 returned. This function must guarantee that all MMIO read and write
430 operations are serialized.
432 If 32-bit MMIO register operations are not supported, then ASSERT().
434 @param Address The MMIO register to read.
436 @return The value read from Address.
445 CONST EFI_PEI_SERVICES
**PeiServices
;
446 EFI_PEI_CPU_IO_PPI
*CpuIo
;
448 PeiServices
= GetPeiServicesTablePointer ();
449 CpuIo
= (*PeiServices
)->CpuIo
;
450 ASSERT (CpuIo
!= NULL
);
452 // Make sure Address is aligned on a 32-bit boundary.
454 ASSERT ((Address
& 3) == 0);
455 return CpuIo
->MemRead32 (PeiServices
, CpuIo
, (UINT64
) Address
);
460 Writes a 32-bit MMIO register.
462 Writes the 32-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.
466 If 32-bit MMIO register operations are not supported, then ASSERT().
468 @param Address The MMIO register to write.
469 @param Value The value to write to the MMIO register.
471 @return The Value written back to Mmio register
481 CONST EFI_PEI_SERVICES
**PeiServices
;
482 EFI_PEI_CPU_IO_PPI
*CpuIo
;
484 PeiServices
= GetPeiServicesTablePointer ();
485 CpuIo
= (*PeiServices
)->CpuIo
;
486 ASSERT (CpuIo
!= NULL
);
488 // Make sure Address is aligned on a 32-bit boundary.
490 ASSERT ((Address
& 3) == 0);
491 CpuIo
->MemWrite32 (PeiServices
, CpuIo
, (UINT64
) Address
, Value
);
496 Reads a 64-bit MMIO register.
498 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
499 returned. This function must guarantee that all MMIO read and write
500 operations are serialized.
502 If 64-bit MMIO register operations are not supported, then ASSERT().
504 @param Address The MMIO register to read.
506 @return The value read from Address.
515 CONST EFI_PEI_SERVICES
**PeiServices
;
516 EFI_PEI_CPU_IO_PPI
*CpuIo
;
518 PeiServices
= GetPeiServicesTablePointer ();
519 CpuIo
= (*PeiServices
)->CpuIo
;
520 ASSERT (CpuIo
!= NULL
);
522 // Make sure Address is aligned on a 64-bit boundary.
524 ASSERT ((Address
& (sizeof (UINT64
) - 1)) == 0);
525 return CpuIo
->MemRead64 (PeiServices
, CpuIo
, (UINT64
) Address
);
530 Writes a 64-bit MMIO register.
532 Writes the 64-bit MMIO register specified by Address with the value specified
533 by Value and returns Value. This function must guarantee that all MMIO read
534 and write operations are serialized.
536 If 64-bit MMIO register operations are not supported, then ASSERT().
538 @param Address The MMIO register to write.
539 @param Value The value to write to the MMIO register.
541 @return The Value written back to Mmio register
550 CONST 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
);