TianoCore EDK2 master
Loading...
Searching...
No Matches
UefiPciCapPciIoLib.c
Go to the documentation of this file.
1
10
11#include "UefiPciCapPciIoLib.h"
12
49 IN EFI_PCI_IO_PROTOCOL_CONFIG TransferFunction,
50 IN UINT16 ConfigOffset,
51 IN OUT UINT8 *Buffer,
52 IN UINT16 Size
53 )
54{
55 while (Size > 0) {
57 UINT16 Count;
58 EFI_STATUS Status;
59 UINT16 Progress;
60
61 //
62 // Pick the largest access size that is allowed by the remaining transfer
63 // Size and by the alignment of ConfigOffset.
64 //
65 // When the largest access size is available, transfer as many bytes as
66 // possible in one iteration of the loop. Otherwise, transfer only one
67 // unit, to improve the alignment.
68 //
69 if ((Size >= 4) && ((ConfigOffset & 3) == 0)) {
70 Width = EfiPciIoWidthUint32;
71 Count = Size >> Width;
72 } else if ((Size >= 2) && ((ConfigOffset & 1) == 0)) {
73 Width = EfiPciIoWidthUint16;
74 Count = 1;
75 } else {
76 Width = EfiPciIoWidthUint8;
77 Count = 1;
78 }
79
80 Status = TransferFunction (PciIo, Width, ConfigOffset, Count, Buffer);
81 if (EFI_ERROR (Status)) {
82 return Status;
83 }
84
85 Progress = Count << Width;
86 ConfigOffset += Progress;
87 Buffer += Progress;
88 Size -= Progress;
89 }
90
91 return EFI_SUCCESS;
92}
93
121STATIC
122RETURN_STATUS
123EFIAPI
125 IN PCI_CAP_DEV *PciDevice,
126 IN UINT16 SourceOffset,
127 OUT VOID *DestinationBuffer,
128 IN UINT16 Size
129 )
130{
131 PROTO_DEV *ProtoDev;
132
133 ProtoDev = PROTO_DEV_FROM_PCI_CAP_DEV (PciDevice);
135 ProtoDev->PciIo,
136 ProtoDev->PciIo->Pci.Read,
137 SourceOffset,
138 DestinationBuffer,
139 Size
140 );
141}
142
170STATIC
171RETURN_STATUS
172EFIAPI
174 IN PCI_CAP_DEV *PciDevice,
175 IN UINT16 DestinationOffset,
176 IN VOID *SourceBuffer,
177 IN UINT16 Size
178 )
179{
180 PROTO_DEV *ProtoDev;
181
182 ProtoDev = PROTO_DEV_FROM_PCI_CAP_DEV (PciDevice);
184 ProtoDev->PciIo,
185 ProtoDev->PciIo->Pci.Write,
186 DestinationOffset,
187 SourceBuffer,
188 Size
189 );
190}
191
207EFIAPI
209 IN EFI_PCI_IO_PROTOCOL *PciIo,
210 OUT PCI_CAP_DEV **PciDevice
211 )
212{
213 PROTO_DEV *ProtoDev;
214
215 ProtoDev = AllocatePool (sizeof *ProtoDev);
216 if (ProtoDev == NULL) {
217 return EFI_OUT_OF_RESOURCES;
218 }
219
220 ProtoDev->Signature = PROTO_DEV_SIG;
221 ProtoDev->PciIo = PciIo;
222 ProtoDev->BaseDevice.ReadConfig = ProtoDevReadConfig;
223 ProtoDev->BaseDevice.WriteConfig = ProtoDevWriteConfig;
224
225 *PciDevice = &ProtoDev->BaseDevice;
226 return EFI_SUCCESS;
227}
228
235VOID
236EFIAPI
238 IN PCI_CAP_DEV *PciDevice
239 )
240{
241 PROTO_DEV *ProtoDev;
242
243 ProtoDev = PROTO_DEV_FROM_PCI_CAP_DEV (PciDevice);
244 FreePool (ProtoDev);
245}
VOID EFIAPI FreePool(IN VOID *Buffer)
#define NULL
Definition: Base.h:319
#define STATIC
Definition: Base.h:264
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
EFI_STATUS(EFIAPI * EFI_PCI_IO_PROTOCOL_CONFIG)(IN EFI_PCI_IO_PROTOCOL *This, IN EFI_PCI_IO_PROTOCOL_WIDTH Width, IN UINT32 Offset, IN UINTN Count, IN OUT VOID *Buffer)
Definition: PciIo.h:220
EFI_PCI_IO_PROTOCOL_WIDTH
Definition: PciIo.h:28
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
VOID EFIAPI PciCapPciIoDeviceUninit(IN PCI_CAP_DEV *PciDevice)
STATIC RETURN_STATUS EFIAPI ProtoDevReadConfig(IN PCI_CAP_DEV *PciDevice, IN UINT16 SourceOffset, OUT VOID *DestinationBuffer, IN UINT16 Size)
STATIC EFI_STATUS ProtoDevTransferConfig(IN EFI_PCI_IO_PROTOCOL *PciIo, IN EFI_PCI_IO_PROTOCOL_CONFIG TransferFunction, IN UINT16 ConfigOffset, IN OUT UINT8 *Buffer, IN UINT16 Size)
EFI_STATUS EFIAPI PciCapPciIoDeviceInit(IN EFI_PCI_IO_PROTOCOL *PciIo, OUT PCI_CAP_DEV **PciDevice)
STATIC RETURN_STATUS EFIAPI ProtoDevWriteConfig(IN PCI_CAP_DEV *PciDevice, IN UINT16 DestinationOffset, IN VOID *SourceBuffer, IN UINT16 Size)
EFI_PCI_IO_PROTOCOL_CONFIG Read
Definition: PciIo.h:232
EFI_PCI_IO_PROTOCOL_CONFIG Write
Definition: PciIo.h:236