TianoCore EDK2 master
Loading...
Searching...
No Matches
PciDriverOverride.c
Go to the documentation of this file.
1
9#include "PciBus.h"
10
17VOID
19 IN OUT PCI_IO_DEVICE *PciIoDevice
20 )
21{
22 PciIoDevice->PciDriverOverride.GetDriver = GetDriver;
23}
24
35 )
36{
37 EFI_STATUS Status;
38 EFI_HANDLE *Handles;
39 UINTN Index;
40 UINTN HandleNum;
41 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
42 UINTN ImagePathSize;
43 EFI_HANDLE ImageHandle;
44
45 Status = gBS->LocateHandleBuffer (
47 &gEfiLoadedImageDevicePathProtocolGuid,
48 NULL,
49 &HandleNum,
50 &Handles
51 );
52 if (EFI_ERROR (Status)) {
53 return NULL;
54 }
55
56 ImageHandle = NULL;
57 ImagePathSize = GetDevicePathSize (ImagePath);
58
59 for (Index = 0; Index < HandleNum; Index++) {
60 Status = gBS->HandleProtocol (Handles[Index], &gEfiLoadedImageDevicePathProtocolGuid, (VOID **)&DevicePath);
61 if (EFI_ERROR (Status)) {
62 continue;
63 }
64
65 if ((ImagePathSize == GetDevicePathSize (DevicePath)) &&
66 (CompareMem (ImagePath, DevicePath, ImagePathSize) == 0)
67 )
68 {
69 ImageHandle = Handles[Index];
70 break;
71 }
72 }
73
74 FreePool (Handles);
75 return ImageHandle;
76}
77
95EFIAPI
98 IN OUT EFI_HANDLE *DriverImageHandle
99 )
100{
101 PCI_IO_DEVICE *PciIoDevice;
102 LIST_ENTRY *Link;
103 PCI_DRIVER_OVERRIDE_LIST *Override;
104 BOOLEAN ReturnNext;
105
106 Override = NULL;
107 PciIoDevice = PCI_IO_DEVICE_FROM_PCI_DRIVER_OVERRIDE_THIS (This);
108 ReturnNext = (BOOLEAN)(*DriverImageHandle == NULL);
109 for ( Link = GetFirstNode (&PciIoDevice->OptionRomDriverList)
110 ; !IsNull (&PciIoDevice->OptionRomDriverList, Link)
111 ; Link = GetNextNode (&PciIoDevice->OptionRomDriverList, Link)
112 )
113 {
114 Override = DRIVER_OVERRIDE_FROM_LINK (Link);
115
116 if (ReturnNext) {
117 if (Override->DriverImageHandle == NULL) {
118 Override->DriverImageHandle = LocateImageHandle (Override->DriverImagePath);
119 }
120
121 if (Override->DriverImageHandle == NULL) {
122 //
123 // The Option ROM identified by Override->DriverImagePath is not loaded.
124 //
125 continue;
126 } else {
127 *DriverImageHandle = Override->DriverImageHandle;
128 return EFI_SUCCESS;
129 }
130 }
131
132 if (*DriverImageHandle == Override->DriverImageHandle) {
133 ReturnNext = TRUE;
134 }
135 }
136
137 ASSERT (IsNull (&PciIoDevice->OptionRomDriverList, Link));
138 //
139 // ReturnNext indicates a handle match happens.
140 // If all nodes are checked without handle match happening,
141 // the DriverImageHandle should be a invalid handle.
142 //
143 if (ReturnNext) {
144 return EFI_NOT_FOUND;
145 } else {
146 return EFI_INVALID_PARAMETER;
147 }
148}
149
164 IN PCI_IO_DEVICE *PciIoDevice,
165 IN EFI_HANDLE DriverImageHandle,
166 IN EFI_DEVICE_PATH_PROTOCOL *DriverImagePath
167 )
168{
170
171 //
172 // Caller should pass in either Image Handle or Image Path, but not both.
173 //
174 ASSERT ((DriverImageHandle == NULL) || (DriverImagePath == NULL));
175
177 if (Node == NULL) {
178 return EFI_OUT_OF_RESOURCES;
179 }
180
181 Node->Signature = DRIVER_OVERRIDE_SIGNATURE;
182 Node->DriverImageHandle = DriverImageHandle;
183 Node->DriverImagePath = DuplicateDevicePath (DriverImagePath);
184
185 InsertTailList (&PciIoDevice->OptionRomDriverList, &Node->Link);
186
187 PciIoDevice->BusOverride = TRUE;
188 return EFI_SUCCESS;
189}
UINT64 UINTN
BOOLEAN EFIAPI IsNull(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
Definition: LinkedList.c:443
LIST_ENTRY *EFIAPI GetNextNode(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
Definition: LinkedList.c:333
LIST_ENTRY *EFIAPI GetFirstNode(IN CONST LIST_ENTRY *List)
Definition: LinkedList.c:298
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
Definition: LinkedList.c:259
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
UINTN EFIAPI GetDevicePathSize(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI DuplicateDevicePath(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
VOID InitializePciDriverOverrideInstance(IN OUT PCI_IO_DEVICE *PciIoDevice)
EFI_STATUS AddDriver(IN PCI_IO_DEVICE *PciIoDevice, IN EFI_HANDLE DriverImageHandle, IN EFI_DEVICE_PATH_PROTOCOL *DriverImagePath)
EFI_STATUS EFIAPI GetDriver(IN EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL *This, IN OUT EFI_HANDLE *DriverImageHandle)
EFI_HANDLE LocateImageHandle(IN EFI_DEVICE_PATH_PROTOCOL *ImagePath)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
@ ByProtocol
Definition: UefiSpec.h:1518