]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Pci/PciBusDxe/PciDriverOverride.c
MdeModulePkg/PciBus: Correct typos
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / PciBusDxe / PciDriverOverride.c
CommitLineData
9060e3ec 1/** @file\r
fcdfcdbf 2 Functions implementation for Bus Specific Driver Override protocol.\r
9060e3ec 3\r
fcdfcdbf 4Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
cd5ebaa0 5This program and the accompanying materials\r
9060e3ec 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "PciBus.h"\r
16\r
17/**\r
18 Initializes a PCI Driver Override Instance.\r
19\r
20 @param PciIoDevice PCI Device instance.\r
21\r
22**/\r
23VOID\r
24InitializePciDriverOverrideInstance (\r
25 IN OUT PCI_IO_DEVICE *PciIoDevice\r
26 )\r
27{\r
28 PciIoDevice->PciDriverOverride.GetDriver = GetDriver;\r
29}\r
30\r
b5cbef4e
RN
31/**\r
32 Find the image handle whose path equals to ImagePath.\r
33\r
34 @param ImagePath Image path.\r
35\r
36 @return Image handle.\r
37**/\r
38EFI_HANDLE\r
39LocateImageHandle (\r
40 IN EFI_DEVICE_PATH_PROTOCOL *ImagePath\r
41 )\r
42{\r
43 EFI_STATUS Status;\r
44 EFI_HANDLE *Handles;\r
45 UINTN Index;\r
46 UINTN HandleNum;\r
47 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
48 UINTN ImagePathSize;\r
49 EFI_HANDLE ImageHandle;\r
50\r
51 Status = gBS->LocateHandleBuffer (\r
52 ByProtocol,\r
53 &gEfiLoadedImageDevicePathProtocolGuid,\r
54 NULL,\r
55 &HandleNum,\r
56 &Handles\r
57 );\r
58 if (EFI_ERROR (Status)) {\r
59 return NULL;\r
60 }\r
61\r
62 ImageHandle = NULL;\r
63 ImagePathSize = GetDevicePathSize (ImagePath);\r
64\r
65 for (Index = 0; Index < HandleNum; Index++) {\r
66 Status = gBS->HandleProtocol (Handles[Index], &gEfiLoadedImageDevicePathProtocolGuid, (VOID **) &DevicePath);\r
67 if (EFI_ERROR (Status)) {\r
68 continue;\r
69 }\r
70 if ((ImagePathSize == GetDevicePathSize (DevicePath)) &&\r
71 (CompareMem (ImagePath, DevicePath, ImagePathSize) == 0)\r
72 ) {\r
73 ImageHandle = Handles[Index];\r
74 break;\r
75 }\r
76 }\r
77\r
78 FreePool (Handles);\r
79 return ImageHandle;\r
80}\r
9060e3ec 81\r
82/**\r
83 Uses a bus specific algorithm to retrieve a driver image handle for a controller.\r
84\r
85 @param This A pointer to the EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL instance.\r
86 @param DriverImageHandle On input, a pointer to the previous driver image handle returned\r
87 by GetDriver(). On output, a pointer to the next driver\r
88 image handle. Passing in a NULL, will return the first driver\r
89 image handle.\r
90\r
91 @retval EFI_SUCCESS A bus specific override driver is returned in DriverImageHandle.\r
92 @retval EFI_NOT_FOUND The end of the list of override drivers was reached.\r
93 A bus specific override driver is not returned in DriverImageHandle.\r
94 @retval EFI_INVALID_PARAMETER DriverImageHandle is not a handle that was returned on a\r
95 previous call to GetDriver().\r
96\r
97**/\r
98EFI_STATUS\r
99EFIAPI\r
100GetDriver (\r
101 IN EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL *This,\r
102 IN OUT EFI_HANDLE *DriverImageHandle\r
103 )\r
104{\r
105 PCI_IO_DEVICE *PciIoDevice;\r
b5cbef4e
RN
106 LIST_ENTRY *Link;\r
107 PCI_DRIVER_OVERRIDE_LIST *Override;\r
108 BOOLEAN ReturnNext;\r
9060e3ec 109\r
b5cbef4e 110 Override = NULL;\r
9060e3ec 111 PciIoDevice = PCI_IO_DEVICE_FROM_PCI_DRIVER_OVERRIDE_THIS (This);\r
b5cbef4e
RN
112 ReturnNext = (BOOLEAN) (*DriverImageHandle == NULL);\r
113 for ( Link = GetFirstNode (&PciIoDevice->OptionRomDriverList)\r
114 ; !IsNull (&PciIoDevice->OptionRomDriverList, Link)\r
115 ; Link = GetNextNode (&PciIoDevice->OptionRomDriverList, Link)\r
116 ) {\r
9060e3ec 117\r
b5cbef4e 118 Override = DRIVER_OVERRIDE_FROM_LINK (Link);\r
9060e3ec 119\r
b5cbef4e
RN
120 if (ReturnNext) {\r
121 if (Override->DriverImageHandle == NULL) {\r
122 Override->DriverImageHandle = LocateImageHandle (Override->DriverImagePath);\r
9060e3ec 123 }\r
124\r
b5cbef4e
RN
125 if (Override->DriverImageHandle == NULL) {\r
126 //\r
127 // The Option ROM identified by Override->DriverImagePath is not loaded.\r
128 //\r
129 continue;\r
130 } else {\r
131 *DriverImageHandle = Override->DriverImageHandle;\r
132 return EFI_SUCCESS;\r
133 }\r
9060e3ec 134 }\r
135\r
b5cbef4e
RN
136 if (*DriverImageHandle == Override->DriverImageHandle) {\r
137 ReturnNext = TRUE;\r
138 }\r
9060e3ec 139 }\r
140\r
b5cbef4e
RN
141 ASSERT (IsNull (&PciIoDevice->OptionRomDriverList, Link));\r
142 //\r
143 // ReturnNext indicates a handle match happens.\r
144 // If all nodes are checked without handle match happening,\r
145 // the DriverImageHandle should be a invalid handle.\r
146 //\r
147 if (ReturnNext) {\r
148 return EFI_NOT_FOUND;\r
149 } else {\r
150 return EFI_INVALID_PARAMETER;\r
151 }\r
9060e3ec 152}\r
153\r
154/**\r
155 Add an overriding driver image.\r
156\r
157 @param PciIoDevice Instance of PciIo device.\r
b5cbef4e
RN
158 @param DriverImageHandle Image handle of newly added driver image.\r
159 @param DriverImagePath Device path of newly added driver image.\r
9060e3ec 160\r
161 @retval EFI_SUCCESS Successfully added driver.\r
162 @retval EFI_OUT_OF_RESOURCES No memory resource for new driver instance.\r
163 @retval other Some error occurred when locating gEfiLoadedImageProtocolGuid.\r
164\r
165**/\r
166EFI_STATUS\r
167AddDriver (\r
b5cbef4e
RN
168 IN PCI_IO_DEVICE *PciIoDevice,\r
169 IN EFI_HANDLE DriverImageHandle,\r
170 IN EFI_DEVICE_PATH_PROTOCOL *DriverImagePath\r
9060e3ec 171 )\r
172{\r
9060e3ec 173 PCI_DRIVER_OVERRIDE_LIST *Node;\r
174\r
b5cbef4e
RN
175 //\r
176 // Caller should pass in either Image Handle or Image Path, but not both.\r
177 //\r
178 ASSERT ((DriverImageHandle == NULL) || (DriverImagePath == NULL));\r
9060e3ec 179\r
b5cbef4e 180 Node = AllocateZeroPool (sizeof (PCI_DRIVER_OVERRIDE_LIST));\r
9060e3ec 181 if (Node == NULL) {\r
182 return EFI_OUT_OF_RESOURCES;\r
183 }\r
184\r
185 Node->Signature = DRIVER_OVERRIDE_SIGNATURE;\r
186 Node->DriverImageHandle = DriverImageHandle;\r
b5cbef4e 187 Node->DriverImagePath = DuplicateDevicePath (DriverImagePath);\r
9060e3ec 188\r
b5cbef4e 189 InsertTailList (&PciIoDevice->OptionRomDriverList, &Node->Link);\r
9060e3ec 190\r
191 PciIoDevice->BusOverride = TRUE;\r
9060e3ec 192 return EFI_SUCCESS;\r
193}\r
194\r