TianoCore EDK2 master
Loading...
Searching...
No Matches
IoLib.c
Go to the documentation of this file.
1
12
13//
14// Global variable to cache pointer to CpuIo2 protocol.
15//
17
31EFIAPI
33 IN EFI_HANDLE ImageHandle,
34 IN EFI_SYSTEM_TABLE *SystemTable
35 )
36{
37 EFI_STATUS Status;
38
39 Status = gBS->LocateProtocol (&gEfiCpuIo2ProtocolGuid, NULL, (VOID **)&mCpuIo);
40 ASSERT_EFI_ERROR (Status);
41
42 return Status;
43}
44
61UINT64
62EFIAPI
64 IN UINTN Port,
66 )
67{
68 EFI_STATUS Status;
69 UINT64 Data;
70
71 Status = mCpuIo->Io.Read (mCpuIo, Width, Port, 1, &Data);
72 ASSERT_EFI_ERROR (Status);
73
74 return Data;
75}
76
94UINT64
95EFIAPI
97 IN UINTN Port,
99 IN UINT64 Data
100 )
101{
102 EFI_STATUS Status;
103
104 Status = mCpuIo->Io.Write (mCpuIo, Width, Port, 1, &Data);
105 ASSERT_EFI_ERROR (Status);
106
107 return Data;
108}
109
126VOID
127EFIAPI
129 IN UINTN Port,
131 IN UINTN Count,
132 IN VOID *Buffer
133 )
134{
135 EFI_STATUS Status;
136
137 Status = mCpuIo->Io.Read (mCpuIo, Width, Port, Count, Buffer);
138 ASSERT_EFI_ERROR (Status);
139}
140
157VOID
158EFIAPI
160 IN UINTN Port,
162 IN UINTN Count,
163 IN VOID *Buffer
164 )
165{
166 EFI_STATUS Status;
167
168 Status = mCpuIo->Io.Write (mCpuIo, Width, Port, Count, Buffer);
169 ASSERT_EFI_ERROR (Status);
170}
171
186UINT64
187EFIAPI
189 IN UINTN Address,
191 )
192{
193 EFI_STATUS Status;
194 UINT64 Data;
195
196 Status = mCpuIo->Mem.Read (mCpuIo, Width, Address, 1, &Data);
197 ASSERT_EFI_ERROR (Status);
198
199 return Data;
200}
201
217UINT64
218EFIAPI
220 IN UINTN Address,
222 IN UINT64 Data
223 )
224{
225 EFI_STATUS Status;
226
227 Status = mCpuIo->Mem.Write (mCpuIo, Width, Address, 1, &Data);
228 ASSERT_EFI_ERROR (Status);
229
230 return Data;
231}
232
247UINT8
248EFIAPI
250 IN UINTN Port
251 )
252{
253 return (UINT8)IoReadWorker (Port, EfiCpuIoWidthUint8);
254}
255
271UINT8
272EFIAPI
274 IN UINTN Port,
275 IN UINT8 Value
276 )
277{
278 return (UINT8)IoWriteWorker (Port, EfiCpuIoWidthUint8, Value);
279}
280
297UINT16
298EFIAPI
300 IN UINTN Port
301 )
302{
303 //
304 // Make sure Port is aligned on a 16-bit boundary.
305 //
306 ASSERT ((Port & 1) == 0);
307 return (UINT16)IoReadWorker (Port, EfiCpuIoWidthUint16);
308}
309
327UINT16
328EFIAPI
330 IN UINTN Port,
331 IN UINT16 Value
332 )
333{
334 //
335 // Make sure Port is aligned on a 16-bit boundary.
336 //
337 ASSERT ((Port & 1) == 0);
338 return (UINT16)IoWriteWorker (Port, EfiCpuIoWidthUint16, Value);
339}
340
357UINT32
358EFIAPI
360 IN UINTN Port
361 )
362{
363 //
364 // Make sure Port is aligned on a 32-bit boundary.
365 //
366 ASSERT ((Port & 3) == 0);
367 return (UINT32)IoReadWorker (Port, EfiCpuIoWidthUint32);
368}
369
387UINT32
388EFIAPI
390 IN UINTN Port,
391 IN UINT32 Value
392 )
393{
394 //
395 // Make sure Port is aligned on a 32-bit boundary.
396 //
397 ASSERT ((Port & 3) == 0);
398 return (UINT32)IoWriteWorker (Port, EfiCpuIoWidthUint32, Value);
399}
400
417UINT64
418EFIAPI
420 IN UINTN Port
421 )
422{
423 //
424 // Make sure Port is aligned on a 64-bit boundary.
425 //
426 ASSERT ((Port & 7) == 0);
427 return IoReadWorker (Port, EfiCpuIoWidthUint64);
428}
429
447UINT64
448EFIAPI
450 IN UINTN Port,
451 IN UINT64 Value
452 )
453{
454 //
455 // Make sure Port is aligned on a 64-bit boundary.
456 //
457 ASSERT ((Port & 7) == 0);
458 return IoWriteWorker (Port, EfiCpuIoWidthUint64, Value);
459}
460
478VOID
479EFIAPI
481 IN UINTN Port,
482 IN UINTN Count,
483 OUT VOID *Buffer
484 )
485{
486 IoReadFifoWorker (Port, EfiCpuIoWidthFifoUint8, Count, Buffer);
487}
488
506VOID
507EFIAPI
509 IN UINTN Port,
510 IN UINTN Count,
511 IN VOID *Buffer
512 )
513{
514 IoWriteFifoWorker (Port, EfiCpuIoWidthFifoUint8, Count, Buffer);
515}
516
534VOID
535EFIAPI
537 IN UINTN Port,
538 IN UINTN Count,
539 OUT VOID *Buffer
540 )
541{
542 //
543 // Make sure Port is aligned on a 16-bit boundary.
544 //
545 ASSERT ((Port & 1) == 0);
546 IoReadFifoWorker (Port, EfiCpuIoWidthFifoUint16, Count, Buffer);
547}
548
566VOID
567EFIAPI
569 IN UINTN Port,
570 IN UINTN Count,
571 IN VOID *Buffer
572 )
573{
574 //
575 // Make sure Port is aligned on a 16-bit boundary.
576 //
577 ASSERT ((Port & 1) == 0);
578 IoWriteFifoWorker (Port, EfiCpuIoWidthFifoUint16, Count, Buffer);
579}
580
598VOID
599EFIAPI
601 IN UINTN Port,
602 IN UINTN Count,
603 OUT VOID *Buffer
604 )
605{
606 //
607 // Make sure Port is aligned on a 32-bit boundary.
608 //
609 ASSERT ((Port & 3) == 0);
610 IoReadFifoWorker (Port, EfiCpuIoWidthFifoUint32, Count, Buffer);
611}
612
630VOID
631EFIAPI
633 IN UINTN Port,
634 IN UINTN Count,
635 IN VOID *Buffer
636 )
637{
638 //
639 // Make sure Port is aligned on a 32-bit boundary.
640 //
641 ASSERT ((Port & 3) == 0);
642 IoWriteFifoWorker (Port, EfiCpuIoWidthFifoUint32, Count, Buffer);
643}
644
659UINT8
660EFIAPI
662 IN UINTN Address
663 )
664{
665 return (UINT8)MmioReadWorker (Address, EfiCpuIoWidthUint8);
666}
667
681UINT8
682EFIAPI
684 IN UINTN Address,
685 IN UINT8 Value
686 )
687{
688 return (UINT8)MmioWriteWorker (Address, EfiCpuIoWidthUint8, Value);
689}
690
707UINT16
708EFIAPI
710 IN UINTN Address
711 )
712{
713 //
714 // Make sure Address is aligned on a 16-bit boundary.
715 //
716 ASSERT ((Address & 1) == 0);
717 return (UINT16)MmioReadWorker (Address, EfiCpuIoWidthUint16);
718}
719
735UINT16
736EFIAPI
738 IN UINTN Address,
739 IN UINT16 Value
740 )
741{
742 //
743 // Make sure Address is aligned on a 16-bit boundary.
744 //
745 ASSERT ((Address & 1) == 0);
746 return (UINT16)MmioWriteWorker (Address, EfiCpuIoWidthUint16, Value);
747}
748
765UINT32
766EFIAPI
768 IN UINTN Address
769 )
770{
771 //
772 // Make sure Address is aligned on a 32-bit boundary.
773 //
774 ASSERT ((Address & 3) == 0);
775 return (UINT32)MmioReadWorker (Address, EfiCpuIoWidthUint32);
776}
777
793UINT32
794EFIAPI
796 IN UINTN Address,
797 IN UINT32 Value
798 )
799{
800 //
801 // Make sure Address is aligned on a 32-bit boundary.
802 //
803 ASSERT ((Address & 3) == 0);
804 return (UINT32)MmioWriteWorker (Address, EfiCpuIoWidthUint32, Value);
805}
806
823UINT64
824EFIAPI
826 IN UINTN Address
827 )
828{
829 //
830 // Make sure Address is aligned on a 64-bit boundary.
831 //
832 ASSERT ((Address & 7) == 0);
833 return (UINT64)MmioReadWorker (Address, EfiCpuIoWidthUint64);
834}
835
851UINT64
852EFIAPI
854 IN UINTN Address,
855 IN UINT64 Value
856 )
857{
858 //
859 // Make sure Address is aligned on a 64-bit boundary.
860 //
861 ASSERT ((Address & 7) == 0);
862 return (UINT64)MmioWriteWorker (Address, EfiCpuIoWidthUint64, Value);
863}
UINT64 UINTN
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_CPU_IO_PROTOCOL_WIDTH
Definition: CpuIo2.h:37
UINT8 EFIAPI IoWrite8(IN UINTN Port, IN UINT8 Value)
Definition: IoLib.c:273
EFI_STATUS EFIAPI IoLibConstructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: IoLib.c:32
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
UINT64 EFIAPI IoReadWorker(IN UINTN Port, IN EFI_CPU_IO_PROTOCOL_WIDTH Width)
Definition: IoLib.c:63
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
UINT64 EFIAPI MmioWriteWorker(IN UINTN Address, IN EFI_CPU_IO_PROTOCOL_WIDTH Width, IN UINT64 Data)
Definition: IoLib.c:219
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
UINT64 EFIAPI IoWriteWorker(IN UINTN Port, IN EFI_CPU_IO_PROTOCOL_WIDTH Width, IN UINT64 Data)
Definition: IoLib.c:96
UINT16 EFIAPI IoRead16(IN UINTN Port)
Definition: IoLib.c:299
UINT64 EFIAPI MmioReadWorker(IN UINTN Address, IN EFI_CPU_IO_PROTOCOL_WIDTH Width)
Definition: IoLib.c:188
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 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
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
EFI_BOOT_SERVICES * gBS
EFI_CPU_IO_PROTOCOL_ACCESS Io
Definition: CpuIo2.h:131
EFI_CPU_IO_PROTOCOL_ACCESS Mem
Definition: CpuIo2.h:127
EFI_CPU_IO_PROTOCOL_IO_MEM Read
Definition: CpuIo2.h:112
EFI_CPU_IO_PROTOCOL_IO_MEM Write
Definition: CpuIo2.h:116