TianoCore EDK2 master
Loading...
Searching...
No Matches
IoLib.c
Go to the documentation of this file.
1
11#include <PiPei.h>
12
13#include <Library/IoLib.h>
14#include <Library/DebugLib.h>
15#include <Library/BaseLib.h>
17
34VOID
35EFIAPI
37 IN UINTN Port,
39 IN UINTN Count,
40 IN VOID *Buffer
41 )
42{
43 CONST EFI_PEI_SERVICES **PeiServices;
44 EFI_PEI_CPU_IO_PPI *CpuIo;
45 EFI_STATUS Status;
46
47 PeiServices = GetPeiServicesTablePointer ();
48 CpuIo = (*PeiServices)->CpuIo;
49 ASSERT (CpuIo != NULL);
50
51 Status = CpuIo->Io.Read (PeiServices, CpuIo, Width, Port, Count, Buffer);
52 ASSERT_EFI_ERROR (Status);
53}
54
71VOID
72EFIAPI
74 IN UINTN Port,
76 IN UINTN Count,
77 IN VOID *Buffer
78 )
79{
80 CONST EFI_PEI_SERVICES **PeiServices;
81 EFI_PEI_CPU_IO_PPI *CpuIo;
82 EFI_STATUS Status;
83
84 PeiServices = GetPeiServicesTablePointer ();
85 CpuIo = (*PeiServices)->CpuIo;
86 ASSERT (CpuIo != NULL);
87
88 Status = CpuIo->Io.Write (PeiServices, CpuIo, Width, Port, Count, Buffer);
89 ASSERT_EFI_ERROR (Status);
90}
91
106UINT8
107EFIAPI
109 IN UINTN Port
110 )
111{
112 CONST EFI_PEI_SERVICES **PeiServices;
113 EFI_PEI_CPU_IO_PPI *CpuIo;
114
115 PeiServices = GetPeiServicesTablePointer ();
116 CpuIo = (*PeiServices)->CpuIo;
117 ASSERT (CpuIo != NULL);
118
119 return CpuIo->IoRead8 (PeiServices, CpuIo, (UINT64)Port);
120}
121
137UINT8
138EFIAPI
140 IN UINTN Port,
141 IN UINT8 Value
142 )
143{
144 CONST EFI_PEI_SERVICES **PeiServices;
145 EFI_PEI_CPU_IO_PPI *CpuIo;
146
147 PeiServices = GetPeiServicesTablePointer ();
148 CpuIo = (*PeiServices)->CpuIo;
149 ASSERT (CpuIo != NULL);
150
151 CpuIo->IoWrite8 (PeiServices, CpuIo, (UINT64)Port, Value);
152 return Value;
153}
154
170UINT16
171EFIAPI
173 IN UINTN Port
174 )
175{
176 CONST EFI_PEI_SERVICES **PeiServices;
177 EFI_PEI_CPU_IO_PPI *CpuIo;
178
179 PeiServices = GetPeiServicesTablePointer ();
180 CpuIo = (*PeiServices)->CpuIo;
181 ASSERT (CpuIo != NULL);
182 //
183 // Make sure Port is aligned on a 16-bit boundary.
184 //
185 ASSERT ((Port & 1) == 0);
186 return CpuIo->IoRead16 (PeiServices, CpuIo, (UINT64)Port);
187}
188
205UINT16
206EFIAPI
208 IN UINTN Port,
209 IN UINT16 Value
210 )
211{
212 CONST EFI_PEI_SERVICES **PeiServices;
213 EFI_PEI_CPU_IO_PPI *CpuIo;
214
215 PeiServices = GetPeiServicesTablePointer ();
216 CpuIo = (*PeiServices)->CpuIo;
217 ASSERT (CpuIo != NULL);
218 //
219 // Make sure Port is aligned on a 16-bit boundary.
220 //
221 ASSERT ((Port & 1) == 0);
222 CpuIo->IoWrite16 (PeiServices, CpuIo, (UINT64)Port, Value);
223 return Value;
224}
225
241UINT32
242EFIAPI
244 IN UINTN Port
245 )
246{
247 CONST EFI_PEI_SERVICES **PeiServices;
248 EFI_PEI_CPU_IO_PPI *CpuIo;
249
250 PeiServices = GetPeiServicesTablePointer ();
251 CpuIo = (*PeiServices)->CpuIo;
252 ASSERT (CpuIo != NULL);
253 //
254 // Make sure Port is aligned on a 32-bit boundary.
255 //
256 ASSERT ((Port & 3) == 0);
257 return CpuIo->IoRead32 (PeiServices, CpuIo, (UINT64)Port);
258}
259
276UINT32
277EFIAPI
279 IN UINTN Port,
280 IN UINT32 Value
281 )
282{
283 CONST EFI_PEI_SERVICES **PeiServices;
284 EFI_PEI_CPU_IO_PPI *CpuIo;
285
286 PeiServices = GetPeiServicesTablePointer ();
287 CpuIo = (*PeiServices)->CpuIo;
288 ASSERT (CpuIo != NULL);
289 //
290 // Make sure Port is aligned on a 32-bit boundary.
291 //
292 ASSERT ((Port & 3) == 0);
293 CpuIo->IoWrite32 (PeiServices, CpuIo, (UINT64)Port, Value);
294 return Value;
295}
296
312UINT64
313EFIAPI
315 IN UINTN Port
316 )
317{
318 CONST EFI_PEI_SERVICES **PeiServices;
319 EFI_PEI_CPU_IO_PPI *CpuIo;
320
321 PeiServices = GetPeiServicesTablePointer ();
322 CpuIo = (*PeiServices)->CpuIo;
323 ASSERT (CpuIo != NULL);
324 //
325 // Make sure Port is aligned on a 64-bit boundary.
326 //
327 ASSERT ((Port & 7) == 0);
328 return CpuIo->IoRead64 (PeiServices, CpuIo, (UINT64)Port);
329}
330
347UINT64
348EFIAPI
350 IN UINTN Port,
351 IN UINT64 Value
352 )
353{
354 CONST EFI_PEI_SERVICES **PeiServices;
355 EFI_PEI_CPU_IO_PPI *CpuIo;
356
357 PeiServices = GetPeiServicesTablePointer ();
358 CpuIo = (*PeiServices)->CpuIo;
359 ASSERT (CpuIo != NULL);
360 //
361 // Make sure Port is aligned on a 64-bit boundary.
362 //
363 ASSERT ((Port & 7) == 0);
364 CpuIo->IoWrite64 (PeiServices, CpuIo, (UINT64)Port, Value);
365 return Value;
366}
367
385VOID
386EFIAPI
388 IN UINTN Port,
389 IN UINTN Count,
390 OUT VOID *Buffer
391 )
392{
393 IoReadFifoWorker (Port, EfiPeiCpuIoWidthFifoUint8, Count, Buffer);
394}
395
413VOID
414EFIAPI
416 IN UINTN Port,
417 IN UINTN Count,
418 IN VOID *Buffer
419 )
420{
421 IoWriteFifoWorker (Port, EfiPeiCpuIoWidthFifoUint8, Count, Buffer);
422}
423
441VOID
442EFIAPI
444 IN UINTN Port,
445 IN UINTN Count,
446 OUT VOID *Buffer
447 )
448{
449 //
450 // Make sure Port is aligned on a 16-bit boundary.
451 //
452 ASSERT ((Port & 1) == 0);
453 IoReadFifoWorker (Port, EfiPeiCpuIoWidthFifoUint16, Count, Buffer);
454}
455
473VOID
474EFIAPI
476 IN UINTN Port,
477 IN UINTN Count,
478 IN VOID *Buffer
479 )
480{
481 //
482 // Make sure Port is aligned on a 16-bit boundary.
483 //
484 ASSERT ((Port & 1) == 0);
485 IoWriteFifoWorker (Port, EfiPeiCpuIoWidthFifoUint16, Count, Buffer);
486}
487
505VOID
506EFIAPI
508 IN UINTN Port,
509 IN UINTN Count,
510 OUT VOID *Buffer
511 )
512{
513 //
514 // Make sure Port is aligned on a 32-bit boundary.
515 //
516 ASSERT ((Port & 3) == 0);
517 IoReadFifoWorker (Port, EfiPeiCpuIoWidthFifoUint32, Count, Buffer);
518}
519
537VOID
538EFIAPI
540 IN UINTN Port,
541 IN UINTN Count,
542 IN VOID *Buffer
543 )
544{
545 //
546 // Make sure Port is aligned on a 32-bit boundary.
547 //
548 ASSERT ((Port & 3) == 0);
549 IoWriteFifoWorker (Port, EfiPeiCpuIoWidthFifoUint32, Count, Buffer);
550}
551
566UINT8
567EFIAPI
569 IN UINTN Address
570 )
571{
572 CONST EFI_PEI_SERVICES **PeiServices;
573 EFI_PEI_CPU_IO_PPI *CpuIo;
574
575 PeiServices = GetPeiServicesTablePointer ();
576 CpuIo = (*PeiServices)->CpuIo;
577 ASSERT (CpuIo != NULL);
578
579 return CpuIo->MemRead8 (PeiServices, CpuIo, (UINT64)Address);
580}
581
597UINT8
598EFIAPI
600 IN UINTN Address,
601 IN UINT8 Value
602 )
603{
604 CONST EFI_PEI_SERVICES **PeiServices;
605 EFI_PEI_CPU_IO_PPI *CpuIo;
606
607 PeiServices = GetPeiServicesTablePointer ();
608 CpuIo = (*PeiServices)->CpuIo;
609 ASSERT (CpuIo != NULL);
610
611 CpuIo->MemWrite8 (PeiServices, CpuIo, (UINT64)Address, Value);
612 return Value;
613}
614
630UINT16
631EFIAPI
633 IN UINTN Address
634 )
635{
636 CONST EFI_PEI_SERVICES **PeiServices;
637 EFI_PEI_CPU_IO_PPI *CpuIo;
638
639 PeiServices = GetPeiServicesTablePointer ();
640 CpuIo = (*PeiServices)->CpuIo;
641 ASSERT (CpuIo != NULL);
642 //
643 // Make sure Address is aligned on a 16-bit boundary.
644 //
645 ASSERT ((Address & 1) == 0);
646 return CpuIo->MemRead16 (PeiServices, CpuIo, (UINT64)Address);
647}
648
665UINT16
666EFIAPI
668 IN UINTN Address,
669 IN UINT16 Value
670 )
671{
672 CONST EFI_PEI_SERVICES **PeiServices;
673 EFI_PEI_CPU_IO_PPI *CpuIo;
674
675 PeiServices = GetPeiServicesTablePointer ();
676 CpuIo = (*PeiServices)->CpuIo;
677 ASSERT (CpuIo != NULL);
678 //
679 // Make sure Address is aligned on a 16-bit boundary.
680 //
681 ASSERT ((Address & 1) == 0);
682 CpuIo->MemWrite16 (PeiServices, CpuIo, (UINT64)Address, Value);
683 return Value;
684}
685
701UINT32
702EFIAPI
704 IN UINTN Address
705 )
706{
707 CONST EFI_PEI_SERVICES **PeiServices;
708 EFI_PEI_CPU_IO_PPI *CpuIo;
709
710 PeiServices = GetPeiServicesTablePointer ();
711 CpuIo = (*PeiServices)->CpuIo;
712 ASSERT (CpuIo != NULL);
713 //
714 // Make sure Address is aligned on a 32-bit boundary.
715 //
716 ASSERT ((Address & 3) == 0);
717 return CpuIo->MemRead32 (PeiServices, CpuIo, (UINT64)Address);
718}
719
736UINT32
737EFIAPI
739 IN UINTN Address,
740 IN UINT32 Value
741 )
742{
743 CONST EFI_PEI_SERVICES **PeiServices;
744 EFI_PEI_CPU_IO_PPI *CpuIo;
745
746 PeiServices = GetPeiServicesTablePointer ();
747 CpuIo = (*PeiServices)->CpuIo;
748 ASSERT (CpuIo != NULL);
749 //
750 // Make sure Address is aligned on a 32-bit boundary.
751 //
752 ASSERT ((Address & 3) == 0);
753 CpuIo->MemWrite32 (PeiServices, CpuIo, (UINT64)Address, Value);
754 return Value;
755}
756
772UINT64
773EFIAPI
775 IN UINTN Address
776 )
777{
778 CONST EFI_PEI_SERVICES **PeiServices;
779 EFI_PEI_CPU_IO_PPI *CpuIo;
780
781 PeiServices = GetPeiServicesTablePointer ();
782 CpuIo = (*PeiServices)->CpuIo;
783 ASSERT (CpuIo != NULL);
784 //
785 // Make sure Address is aligned on a 64-bit boundary.
786 //
787 ASSERT ((Address & (sizeof (UINT64) - 1)) == 0);
788 return CpuIo->MemRead64 (PeiServices, CpuIo, (UINT64)Address);
789}
790
805UINT64
806EFIAPI
808 IN UINTN Address,
809 IN UINT64 Value
810 )
811{
812 CONST EFI_PEI_SERVICES **PeiServices;
813 EFI_PEI_CPU_IO_PPI *CpuIo;
814
815 PeiServices = GetPeiServicesTablePointer ();
816 CpuIo = (*PeiServices)->CpuIo;
817 ASSERT (CpuIo != NULL);
818 //
819 // Make sure Address is aligned on a 64-bit boundary.
820 //
821 ASSERT ((Address & 7) == 0);
822 CpuIo->MemWrite64 (PeiServices, CpuIo, (UINT64)Address, Value);
823 return Value;
824}
UINT64 UINTN
CONST EFI_PEI_SERVICES **EFIAPI GetPeiServicesTablePointer(VOID)
UINT64 EFIAPI MmioWrite64(IN UINTN Address, IN UINT64 Value)
Definition: IoLib.c:400
UINT64 EFIAPI IoRead64(IN UINTN Port)
Definition: IoLib.c:29
UINT64 EFIAPI IoWrite64(IN UINTN Port, IN UINT64 Value)
Definition: IoLib.c:55
UINT64 EFIAPI MmioRead64(IN UINTN Address)
Definition: IoLib.c:355
UINT16 EFIAPI MmioRead16(IN UINTN Address)
Definition: IoLib.c:170
UINT8 EFIAPI MmioRead8(IN UINTN Address)
Definition: IoLib.c:82
UINT8 EFIAPI MmioWrite8(IN UINTN Address, IN UINT8 Value)
Definition: IoLib.c:126
UINT32 EFIAPI MmioRead32(IN UINTN Address)
Definition: IoLib.c:262
UINT16 EFIAPI MmioWrite16(IN UINTN Address, IN UINT16 Value)
Definition: IoLib.c:216
UINT32 EFIAPI MmioWrite32(IN UINTN Address, IN UINT32 Value)
Definition: IoLib.c:309
EFI_PEI_CPU_IO_PPI_WIDTH
Definition: CpuIo.h:24
UINT8 EFIAPI IoWrite8(IN UINTN Port, IN UINT8 Value)
Definition: IoLib.c:273
VOID EFIAPI IoWriteFifo32(IN UINTN Port, IN UINTN Count, IN VOID *Buffer)
Definition: IoLib.c:632
VOID EFIAPI IoReadFifo8(IN UINTN Port, IN UINTN Count, OUT VOID *Buffer)
Definition: IoLib.c:480
VOID EFIAPI IoReadFifo16(IN UINTN Port, IN UINTN Count, OUT VOID *Buffer)
Definition: IoLib.c:536
VOID EFIAPI IoReadFifoWorker(IN UINTN Port, IN EFI_CPU_IO_PROTOCOL_WIDTH Width, IN UINTN Count, IN VOID *Buffer)
Definition: IoLib.c:128
VOID EFIAPI IoWriteFifo16(IN UINTN Port, IN UINTN Count, IN VOID *Buffer)
Definition: IoLib.c:568
VOID EFIAPI IoReadFifo32(IN UINTN Port, IN UINTN Count, OUT VOID *Buffer)
Definition: IoLib.c:600
UINT8 EFIAPI IoRead8(IN UINTN Port)
Definition: IoLib.c:249
VOID EFIAPI IoWriteFifoWorker(IN UINTN Port, IN EFI_CPU_IO_PROTOCOL_WIDTH Width, IN UINTN Count, IN VOID *Buffer)
Definition: IoLib.c:159
VOID EFIAPI IoWriteFifo8(IN UINTN Port, IN UINTN Count, IN VOID *Buffer)
Definition: IoLib.c:508
UINT16 EFIAPI IoRead16(IN UINTN Port)
Definition: IoLib.c:299
UINT32 EFIAPI IoRead32(IN UINTN Port)
Definition: IoLib.c:359
UINT32 EFIAPI IoWrite32(IN UINTN Port, IN UINT32 Value)
Definition: IoLib.c:389
UINT16 EFIAPI IoWrite16(IN UINTN Port, IN UINT16 Value)
Definition: IoLib.c:329
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
EFI_PEI_CPU_IO_PPI_ACCESS Io
Definition: CpuIo.h:397
EFI_PEI_CPU_IO_PPI_IO_MEM Write
Definition: CpuIo.h:77
EFI_PEI_CPU_IO_PPI_IO_MEM Read
Definition: CpuIo.h:73