TianoCore EDK2 master
Loading...
Searching...
No Matches
BasePciCapPciSegmentLib.c
Go to the documentation of this file.
1
10
11#include <Library/BaseLib.h>
14
16
43RETURN_STATUS
44EFIAPI
46 IN PCI_CAP_DEV *PciDevice,
47 IN UINT16 SourceOffset,
48 OUT VOID *DestinationBuffer,
49 IN UINT16 Size
50 )
51{
52 SEGMENT_DEV *SegmentDev;
53 UINT16 ConfigSpaceSize;
54 UINT64 SourceAddress;
55
56 SegmentDev = SEGMENT_DEV_FROM_PCI_CAP_DEV (PciDevice);
57 ConfigSpaceSize = (SegmentDev->MaxDomain == PciCapNormal ?
58 PCI_MAX_CONFIG_OFFSET : PCI_EXP_MAX_CONFIG_OFFSET);
59 //
60 // Note that all UINT16 variables below are promoted to INT32, and the
61 // addition and the comparison is carried out in INT32.
62 //
63 if (SourceOffset + Size > ConfigSpaceSize) {
64 return RETURN_UNSUPPORTED;
65 }
66
67 SourceAddress = PCI_SEGMENT_LIB_ADDRESS (
68 SegmentDev->SegmentNr,
69 SegmentDev->BusNr,
70 SegmentDev->DeviceNr,
71 SegmentDev->FunctionNr,
72 SourceOffset
73 );
74 PciSegmentReadBuffer (SourceAddress, Size, DestinationBuffer);
75 return RETURN_SUCCESS;
76}
77
103STATIC
104RETURN_STATUS
105EFIAPI
107 IN PCI_CAP_DEV *PciDevice,
108 IN UINT16 DestinationOffset,
109 IN VOID *SourceBuffer,
110 IN UINT16 Size
111 )
112{
113 SEGMENT_DEV *SegmentDev;
114 UINT16 ConfigSpaceSize;
115 UINT64 DestinationAddress;
116
117 SegmentDev = SEGMENT_DEV_FROM_PCI_CAP_DEV (PciDevice);
118 ConfigSpaceSize = (SegmentDev->MaxDomain == PciCapNormal ?
119 PCI_MAX_CONFIG_OFFSET : PCI_EXP_MAX_CONFIG_OFFSET);
120 //
121 // Note that all UINT16 variables below are promoted to INT32, and the
122 // addition and the comparison is carried out in INT32.
123 //
124 if (DestinationOffset + Size > ConfigSpaceSize) {
125 return RETURN_UNSUPPORTED;
126 }
127
128 DestinationAddress = PCI_SEGMENT_LIB_ADDRESS (
129 SegmentDev->SegmentNr,
130 SegmentDev->BusNr,
131 SegmentDev->DeviceNr,
132 SegmentDev->FunctionNr,
133 DestinationOffset
134 );
135 PciSegmentWriteBuffer (DestinationAddress, Size, SourceBuffer);
136 return RETURN_SUCCESS;
137}
138
175RETURN_STATUS
176EFIAPI
178 IN PCI_CAP_DOMAIN MaxDomain,
179 IN UINT16 Segment,
180 IN UINT8 Bus,
181 IN UINT8 Device,
182 IN UINT8 Function,
183 OUT PCI_CAP_DEV **PciDevice
184 )
185{
186 SEGMENT_DEV *SegmentDev;
187
188 if ((Device > PCI_MAX_DEVICE) || (Function > PCI_MAX_FUNC)) {
190 }
191
192 SegmentDev = AllocatePool (sizeof *SegmentDev);
193 if (SegmentDev == NULL) {
195 }
196
197 SegmentDev->Signature = SEGMENT_DEV_SIG;
198 SegmentDev->MaxDomain = MaxDomain;
199 SegmentDev->SegmentNr = Segment;
200 SegmentDev->BusNr = Bus;
201 SegmentDev->DeviceNr = Device;
202 SegmentDev->FunctionNr = Function;
203 SegmentDev->BaseDevice.ReadConfig = SegmentDevReadConfig;
204 SegmentDev->BaseDevice.WriteConfig = SegmentDevWriteConfig;
205
206 *PciDevice = &SegmentDev->BaseDevice;
207 return RETURN_SUCCESS;
208}
209
216VOID
217EFIAPI
219 IN PCI_CAP_DEV *PciDevice
220 )
221{
222 SEGMENT_DEV *SegmentDev;
223
224 SegmentDev = SEGMENT_DEV_FROM_PCI_CAP_DEV (PciDevice);
225 FreePool (SegmentDev);
226}
VOID EFIAPI PciCapPciSegmentDeviceUninit(IN PCI_CAP_DEV *PciDevice)
STATIC RETURN_STATUS EFIAPI SegmentDevWriteConfig(IN PCI_CAP_DEV *PciDevice, IN UINT16 DestinationOffset, IN VOID *SourceBuffer, IN UINT16 Size)
RETURN_STATUS EFIAPI PciCapPciSegmentDeviceInit(IN PCI_CAP_DOMAIN MaxDomain, IN UINT16 Segment, IN UINT8 Bus, IN UINT8 Device, IN UINT8 Function, OUT PCI_CAP_DEV **PciDevice)
STATIC RETURN_STATUS EFIAPI SegmentDevReadConfig(IN PCI_CAP_DEV *PciDevice, IN UINT16 SourceOffset, OUT VOID *DestinationBuffer, IN UINT16 Size)
VOID EFIAPI FreePool(IN VOID *Buffer)
UINTN EFIAPI PciSegmentReadBuffer(IN UINT64 StartAddress, IN UINTN Size, OUT VOID *Buffer)
#define PCI_SEGMENT_LIB_ADDRESS(Segment, Bus, Device, Function, Register)
Definition: PciSegmentLib.h:51
UINTN EFIAPI PciSegmentWriteBuffer(IN UINT64 StartAddress, IN UINTN Size, IN VOID *Buffer)
#define NULL
Definition: Base.h:319
#define STATIC
Definition: Base.h:264
#define RETURN_UNSUPPORTED
Definition: Base.h:1081
#define RETURN_OUT_OF_RESOURCES
Definition: Base.h:1114
#define RETURN_SUCCESS
Definition: Base.h:1066
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define RETURN_INVALID_PARAMETER
Definition: Base.h:1076
#define PCI_EXP_MAX_CONFIG_OFFSET
Definition: Pci23.h:83
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)