]>
Commit | Line | Data |
---|---|---|
a6f164a7 | 1 | /** @file\r |
6d8ced29 LG |
2 | This file also installs UEFI PLATFORM_DRIVER_OVERRIDE_PROTOCOL.\r |
3 | \r | |
4 | The main code offers a UI interface in device manager to let user configure\r | |
a6f164a7 | 5 | platform override protocol to override the default algorithm for matching\r |
6 | drivers to controllers.\r | |
7 | \r | |
8 | The main flow:\r | |
6d8ced29 LG |
9 | 1. It dynamicly locate all controller device path.\r |
10 | 2. It dynamicly locate all drivers which support binding protocol.\r | |
11 | 3. It export and dynamicly update two menu to let user select the\r | |
a6f164a7 | 12 | mapping between drivers to controllers.\r |
6d8ced29 | 13 | 4. It save all the mapping info in NV variables which will be consumed\r |
a6f164a7 | 14 | by platform override protocol driver to publish the platform override protocol.\r |
15 | \r | |
9f25f7dd | 16 | Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r |
e5eed7d3 | 17 | This program and the accompanying materials\r |
e5618791 LG |
18 | are licensed and made available under the terms and conditions of the BSD License\r |
19 | which accompanies this distribution. The full text of the license may be found at\r | |
20 | http://opensource.org/licenses/bsd-license.php\r | |
21 | \r | |
22 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
23 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
24 | \r | |
a6f164a7 | 25 | **/\r |
26 | \r | |
6d8ced29 | 27 | #include "InternalPlatDriOverrideDxe.h"\r |
a6f164a7 | 28 | #include "PlatOverMngr.h"\r |
29 | \r | |
68dbca6c LG |
30 | #define EFI_CALLBACK_INFO_SIGNATURE SIGNATURE_32 ('C', 'l', 'b', 'k')\r |
31 | #define EFI_CALLBACK_INFO_FROM_THIS(a) CR (a, EFI_CALLBACK_INFO, ConfigAccess, EFI_CALLBACK_INFO_SIGNATURE)\r | |
32 | \r | |
33 | typedef struct {\r | |
34 | UINTN Signature;\r | |
35 | EFI_HANDLE DriverHandle;\r | |
36 | EFI_HII_HANDLE RegisteredHandle;\r | |
37 | PLAT_OVER_MNGR_DATA FakeNvData;\r | |
38 | EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;\r | |
39 | EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess;\r | |
6d8ced29 | 40 | EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL PlatformDriverOverride;\r |
68dbca6c LG |
41 | } EFI_CALLBACK_INFO;\r |
42 | \r | |
f6f910dd | 43 | #pragma pack(1)\r |
44 | \r | |
45 | ///\r | |
46 | /// HII specific Vendor Device Path definition.\r | |
47 | ///\r | |
48 | typedef struct {\r | |
49 | VENDOR_DEVICE_PATH VendorDevicePath;\r | |
50 | EFI_DEVICE_PATH_PROTOCOL End;\r | |
51 | } HII_VENDOR_DEVICE_PATH;\r | |
52 | \r | |
53 | #pragma pack()\r | |
54 | \r | |
68dbca6c LG |
55 | //\r |
56 | // uni string and Vfr Binary data.\r | |
57 | //\r | |
58 | extern UINT8 VfrBin[];\r | |
6d8ced29 | 59 | extern UINT8 PlatDriOverrideDxeStrings[];\r |
68dbca6c LG |
60 | \r |
61 | //\r | |
62 | // module global data\r | |
63 | //\r | |
7e3bcccb | 64 | CHAR16 mVariableName[] = L"Data";\r |
68dbca6c | 65 | LIST_ENTRY mMappingDataBase = INITIALIZE_LIST_HEAD_VARIABLE (mMappingDataBase);\r |
6d8ced29 LG |
66 | BOOLEAN mEnvironmentVariableRead = FALSE;\r |
67 | EFI_HANDLE mCallerImageHandle = NULL;\r | |
68dbca6c LG |
68 | \r |
69 | EFI_HANDLE *mDevicePathHandleBuffer;\r | |
70 | EFI_HANDLE *mDriverImageHandleBuffer;\r | |
71 | \r | |
db0bd81c | 72 | INTN mSelectedCtrIndex;\r |
68dbca6c | 73 | EFI_STRING_ID mControllerToken[MAX_CHOICE_NUM];\r |
fe1e36e5 | 74 | UINTN mDriverImageHandleCount;\r |
75 | EFI_STRING_ID mDriverImageToken[MAX_CHOICE_NUM];\r | |
76 | EFI_STRING_ID mDriverImageFilePathToken[MAX_CHOICE_NUM];\r | |
77 | EFI_LOADED_IMAGE_PROTOCOL *mDriverImageProtocol[MAX_CHOICE_NUM];\r | |
78 | EFI_DEVICE_PATH_PROTOCOL *mControllerDevicePathProtocol[MAX_CHOICE_NUM];\r | |
79 | UINTN mSelectedDriverImageNum;\r | |
80 | UINTN mLastSavedDriverImageNum;\r | |
fe1e36e5 | 81 | UINT16 mCurrentPage;\r |
7e3bcccb | 82 | EFI_CALLBACK_INFO *mCallbackInfo;\r |
a6f164a7 | 83 | \r |
f6f910dd | 84 | HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath = {\r |
85 | {\r | |
86 | {\r | |
87 | HARDWARE_DEVICE_PATH,\r | |
88 | HW_VENDOR_DP,\r | |
89 | {\r | |
90 | (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r | |
91 | (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r | |
92 | }\r | |
93 | },\r | |
c8ad2d7a | 94 | PLAT_OVER_MNGR_GUID\r |
f6f910dd | 95 | },\r |
96 | {\r | |
97 | END_DEVICE_PATH_TYPE,\r | |
98 | END_ENTIRE_DEVICE_PATH_SUBTYPE,\r | |
99 | { \r | |
100 | (UINT8) (END_DEVICE_PATH_LENGTH),\r | |
101 | (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r | |
102 | }\r | |
103 | }\r | |
104 | };\r | |
105 | \r | |
87fbccbe | 106 | /**\r |
863986b3 RN |
107 | Converting a given device to an unicode string.\r |
108 | \r | |
87fbccbe | 109 | @param DevPath Given device path instance\r |
110 | \r | |
111 | @return Converted string from given device path.\r | |
863986b3 | 112 | @retval L"?" Converting failed.\r |
87fbccbe | 113 | **/\r |
114 | CHAR16 *\r | |
115 | DevicePathToStr (\r | |
116 | IN EFI_DEVICE_PATH_PROTOCOL *DevPath\r | |
6d8ced29 LG |
117 | )\r |
118 | {\r | |
863986b3 RN |
119 | CHAR16 *Text;\r |
120 | Text = ConvertDevicePathToText (\r | |
121 | DevPath,\r | |
122 | FALSE,\r | |
123 | TRUE\r | |
124 | );\r | |
125 | if (Text == NULL) {\r | |
126 | return AllocateCopyPool (sizeof (L"?"), L"?");\r | |
127 | } else {\r | |
128 | return Text;\r | |
6d8ced29 | 129 | }\r |
6d8ced29 | 130 | }\r |
87fbccbe | 131 | \r |
a6f164a7 | 132 | /**\r |
f6a65182 | 133 | Worker function to get the driver name by ComponentName or ComponentName2 protocol \r |
134 | according to the driver binding handle.\r | |
a6f164a7 | 135 | \r |
f6a65182 | 136 | @param DriverBindingHandle The Handle of DriverBinding.\r |
137 | @param ProtocolGuid The pointer to Component Name (2) protocol GUID.\r | |
138 | @param VariableName The name of the RFC 4646 or ISO 639-2 language variable.\r | |
a6f164a7 | 139 | \r |
f6a65182 | 140 | @retval !NULL Pointer into the image name if the image name is found,\r |
141 | @retval NULL Pointer to NULL if the image name is not found.\r | |
a6f164a7 | 142 | \r |
143 | **/\r | |
f6a65182 | 144 | CHAR16 *\r |
145 | GetComponentNameWorker (\r | |
146 | IN EFI_HANDLE DriverBindingHandle,\r | |
147 | IN EFI_GUID *ProtocolGuid,\r | |
148 | IN CONST CHAR16 *VariableName\r | |
a6f164a7 | 149 | )\r |
150 | {\r | |
f6a65182 | 151 | EFI_STATUS Status;\r |
152 | EFI_COMPONENT_NAME_PROTOCOL *ComponentName;\r | |
153 | CHAR16 *DriverName;\r | |
154 | CHAR8 *Language;\r | |
155 | CHAR8 *BestLanguage;\r | |
a6f164a7 | 156 | \r |
f6a65182 | 157 | Status = gBS->OpenProtocol (\r |
158 | DriverBindingHandle,\r | |
159 | ProtocolGuid,\r | |
160 | (VOID *) &ComponentName,\r | |
161 | NULL,\r | |
162 | NULL,\r | |
163 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
164 | );\r | |
165 | if (EFI_ERROR (Status)) {\r | |
68dbca6c | 166 | return NULL;\r |
a6f164a7 | 167 | }\r |
f6a65182 | 168 | \r |
a6f164a7 | 169 | //\r |
f6a65182 | 170 | // Find the best matching language.\r |
a6f164a7 | 171 | //\r |
f01b91ae | 172 | GetEfiGlobalVariable2 (VariableName, (VOID**)&Language, NULL);\r |
f6a65182 | 173 | BestLanguage = GetBestLanguage (\r |
174 | ComponentName->SupportedLanguages,\r | |
175 | (BOOLEAN) (ProtocolGuid == &gEfiComponentNameProtocolGuid),\r | |
176 | Language,\r | |
177 | NULL\r | |
178 | );\r | |
179 | \r | |
180 | DriverName = NULL;\r | |
181 | if (BestLanguage != NULL) {\r | |
182 | ComponentName->GetDriverName (\r | |
183 | ComponentName,\r | |
184 | BestLanguage,\r | |
185 | &DriverName\r | |
186 | );\r | |
187 | FreePool (BestLanguage);\r | |
a6f164a7 | 188 | }\r |
f6a65182 | 189 | \r |
190 | if (Language != NULL) {\r | |
191 | FreePool (Language);\r | |
192 | }\r | |
193 | \r | |
194 | return DriverName;\r | |
a6f164a7 | 195 | }\r |
196 | \r | |
f6a65182 | 197 | \r |
a6f164a7 | 198 | /**\r |
68dbca6c LG |
199 | Get the driver name by ComponentName or ComponentName2 protocol \r |
200 | according to the driver binding handle\r | |
a6f164a7 | 201 | \r |
202 | @param DriverBindingHandle The Handle of DriverBinding.\r | |
203 | \r | |
204 | @retval !NULL Pointer into the image name if the image name is found,\r | |
205 | @retval NULL Pointer to NULL if the image name is not found.\r | |
206 | \r | |
207 | **/\r | |
208 | CHAR16 *\r | |
209 | GetComponentName (\r | |
210 | IN EFI_HANDLE DriverBindingHandle\r | |
211 | )\r | |
212 | {\r | |
f6a65182 | 213 | CHAR16 *DriverName;\r |
68dbca6c | 214 | \r |
f6a65182 | 215 | //\r |
216 | // Try RFC 4646 Component Name 2 protocol first.\r | |
217 | //\r | |
218 | DriverName = GetComponentNameWorker (DriverBindingHandle, &gEfiComponentName2ProtocolGuid, L"PlatformLang");\r | |
219 | if (DriverName == NULL) {\r | |
220 | //\r | |
221 | // If we can not get driver name from Component Name 2 protocol, we can try ISO 639-2 Component Name protocol. \r | |
222 | //\r | |
223 | DriverName = GetComponentNameWorker (DriverBindingHandle, &gEfiComponentNameProtocolGuid, L"Lang");\r | |
a6f164a7 | 224 | }\r |
225 | \r | |
226 | return DriverName;\r | |
227 | }\r | |
228 | \r | |
229 | /**\r | |
68dbca6c | 230 | Get the image name from EFI UI section.\r |
f6a65182 | 231 | Get FV protocol by its loaded image protocol to abstract EFI UI section.\r |
a6f164a7 | 232 | \r |
68dbca6c | 233 | @param Image Pointer to the loaded image protocol\r |
a6f164a7 | 234 | \r |
68dbca6c LG |
235 | @retval !NULL Pointer to the image name if the image name is found,\r |
236 | @retval NULL NULL if the image name is not found.\r | |
a6f164a7 | 237 | \r |
238 | **/\r | |
239 | CHAR16 *\r | |
240 | GetImageName (\r | |
cebc8d48 | 241 | IN EFI_LOADED_IMAGE_PROTOCOL *Image\r |
a6f164a7 | 242 | )\r |
243 | {\r | |
244 | EFI_STATUS Status;\r | |
a6f164a7 | 245 | EFI_DEVICE_PATH_PROTOCOL *DevPathNode;\r |
1232b214 | 246 | EFI_DEVICE_PATH_PROTOCOL *AlignedDevPathNode;\r |
a6f164a7 | 247 | MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFilePath;\r |
248 | VOID *Buffer;\r | |
249 | UINTN BufferSize;\r | |
250 | UINT32 AuthenticationStatus;\r | |
251 | EFI_GUID *NameGuid;\r | |
cebc8d48 | 252 | EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv2;\r |
a6f164a7 | 253 | \r |
cebc8d48 | 254 | Fv2 = NULL;\r |
a6f164a7 | 255 | Buffer = NULL;\r |
256 | BufferSize = 0;\r | |
257 | \r | |
258 | if (Image->FilePath == NULL) {\r | |
259 | return NULL;\r | |
260 | }\r | |
1232b214 | 261 | DevPathNode = Image->FilePath;\r |
a6f164a7 | 262 | \r |
a6f164a7 | 263 | while (!IsDevicePathEnd (DevPathNode)) {\r |
1232b214 | 264 | //\r |
265 | // Make sure device path node is aligned when accessing it's FV Name Guid field.\r | |
266 | //\r | |
267 | AlignedDevPathNode = AllocateCopyPool (DevicePathNodeLength(DevPathNode), DevPathNode);\r | |
268 | \r | |
a6f164a7 | 269 | //\r |
270 | // Find the Fv File path\r | |
271 | //\r | |
1232b214 | 272 | NameGuid = EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)AlignedDevPathNode);\r |
a6f164a7 | 273 | if (NameGuid != NULL) {\r |
1232b214 | 274 | FvFilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) AlignedDevPathNode;\r |
a6f164a7 | 275 | Status = gBS->HandleProtocol (\r |
276 | Image->DeviceHandle,\r | |
277 | &gEfiFirmwareVolume2ProtocolGuid,\r | |
cebc8d48 | 278 | (VOID **) &Fv2\r |
a6f164a7 | 279 | );\r |
68dbca6c LG |
280 | //\r |
281 | // Locate Image EFI UI section to get the image name.\r | |
282 | //\r | |
a6f164a7 | 283 | if (!EFI_ERROR (Status)) {\r |
cebc8d48 LG |
284 | Status = Fv2->ReadSection (\r |
285 | Fv2,\r | |
a6f164a7 | 286 | &FvFilePath->FvFileName,\r |
287 | EFI_SECTION_USER_INTERFACE,\r | |
288 | 0,\r | |
289 | &Buffer,\r | |
290 | &BufferSize,\r | |
291 | &AuthenticationStatus\r | |
292 | );\r | |
293 | if (!EFI_ERROR (Status)) {\r | |
1232b214 | 294 | FreePool (AlignedDevPathNode);\r |
a6f164a7 | 295 | break;\r |
296 | }\r | |
297 | Buffer = NULL;\r | |
298 | }\r | |
299 | }\r | |
1232b214 | 300 | \r |
301 | FreePool (AlignedDevPathNode);\r | |
302 | \r | |
a6f164a7 | 303 | //\r |
304 | // Next device path node\r | |
305 | //\r | |
306 | DevPathNode = NextDevicePathNode (DevPathNode);\r | |
307 | }\r | |
308 | \r | |
a6f164a7 | 309 | return Buffer;\r |
310 | }\r | |
311 | \r | |
312 | /**\r | |
313 | Prepare the first page to let user select the device controller which need to\r | |
68dbca6c LG |
314 | add mapping drivers if user select 'Refresh' in first page.\r |
315 | During first page, user will see all currnet controller device path in system,\r | |
316 | select any device path will go to second page to select its overrides drivers.\r | |
a6f164a7 | 317 | \r |
318 | @param Private Pointer to EFI_CALLBACK_INFO.\r | |
319 | @param KeyValue The callback key value of device controller item in first page.\r | |
320 | @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.\r | |
321 | \r | |
322 | @retval EFI_SUCCESS Always returned.\r | |
323 | \r | |
324 | **/\r | |
325 | EFI_STATUS\r | |
326 | UpdateDeviceSelectPage (\r | |
327 | IN EFI_CALLBACK_INFO *Private,\r | |
328 | IN UINT16 KeyValue,\r | |
329 | IN PLAT_OVER_MNGR_DATA *FakeNvData\r | |
330 | )\r | |
331 | {\r | |
a6f164a7 | 332 | EFI_STATUS Status;\r |
a6f164a7 | 333 | UINTN Index;\r |
334 | UINTN DevicePathHandleCount;\r | |
335 | CHAR16 *NewString;\r | |
336 | EFI_STRING_ID NewStringToken;\r | |
337 | CHAR16 *ControllerName;\r | |
338 | EFI_DEVICE_PATH_PROTOCOL *ControllerDevicePath;\r | |
339 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
340 | EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL *BusSpecificDriverOverride;\r | |
341 | UINTN Len;\r | |
7e3bcccb LG |
342 | VOID *StartOpCodeHandle;\r |
343 | VOID *EndOpCodeHandle;\r | |
344 | EFI_IFR_GUID_LABEL *StartLabel;\r | |
345 | EFI_IFR_GUID_LABEL *EndLabel; \r | |
346 | \r | |
a6f164a7 | 347 | //\r |
7e3bcccb | 348 | // Set current page form ID.\r |
68dbca6c LG |
349 | //\r |
350 | mCurrentPage = FORM_ID_DEVICE; \r | |
351 | \r | |
a6f164a7 | 352 | //\r |
353 | // Initial the mapping database in memory\r | |
354 | //\r | |
355 | FreeMappingDatabase (&mMappingDataBase);\r | |
7e3bcccb LG |
356 | InitOverridesMapping (&mMappingDataBase);\r |
357 | \r | |
358 | //\r | |
359 | // Init OpCode Handle\r | |
360 | //\r | |
361 | StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r | |
362 | ASSERT (StartOpCodeHandle != NULL);\r | |
a6f164a7 | 363 | \r |
7e3bcccb LG |
364 | EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r |
365 | ASSERT (EndOpCodeHandle != NULL);\r | |
366 | \r | |
367 | //\r | |
368 | // Create Hii Extend Label OpCode as the start opcode\r | |
a6f164a7 | 369 | //\r |
7e3bcccb LG |
370 | StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r |
371 | StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r | |
372 | StartLabel->Number = FORM_ID_DEVICE;\r | |
373 | \r | |
a6f164a7 | 374 | //\r |
7e3bcccb LG |
375 | // Create Hii Extend Label OpCode as the end opcode\r |
376 | //\r | |
377 | EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r | |
378 | EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r | |
379 | EndLabel->Number = LABEL_END;\r | |
380 | \r | |
a6f164a7 | 381 | //\r |
382 | // Clear first page form\r | |
383 | //\r | |
7e3bcccb | 384 | HiiUpdateForm (\r |
a6f164a7 | 385 | Private->RegisteredHandle,\r |
c8ad2d7a | 386 | &gPlatformOverridesManagerGuid,\r |
a6f164a7 | 387 | FORM_ID_DEVICE,\r |
7e3bcccb LG |
388 | StartOpCodeHandle, // Label FORM_ID_DEVICE\r |
389 | EndOpCodeHandle // LABEL_END\r | |
a6f164a7 | 390 | );\r |
391 | \r | |
392 | //\r | |
393 | // When user enter the page at first time, the 'first refresh' string is given to notify user to refresh all the drivers,\r | |
68dbca6c | 394 | // then the 'first refresh' string will be replaced by the 'refresh' string, and the two strings content are same after the replacement\r |
a6f164a7 | 395 | //\r |
396 | NewStringToken = STRING_TOKEN (STR_FIRST_REFRESH);\r | |
cb7d01c0 | 397 | NewString = HiiGetString (Private->RegisteredHandle, STRING_TOKEN (STR_REFRESH), NULL);\r |
a6f164a7 | 398 | ASSERT (NewString != NULL);\r |
cb7d01c0 | 399 | if (HiiSetString (Private->RegisteredHandle, NewStringToken, NewString, NULL) == 0) {\r |
400 | ASSERT (FALSE);\r | |
401 | }\r | |
68dbca6c | 402 | FreePool (NewString);\r |
a6f164a7 | 403 | \r |
404 | NewStringToken = STRING_TOKEN (STR_FIRST_REFRESH_HELP);\r | |
cb7d01c0 | 405 | NewString = HiiGetString (Private->RegisteredHandle, STRING_TOKEN (STR_REFRESH_HELP), NULL);\r |
a6f164a7 | 406 | ASSERT (NewString != NULL);\r |
cb7d01c0 | 407 | if (HiiSetString (Private->RegisteredHandle, NewStringToken, NewString, NULL) == 0) {\r |
408 | ASSERT (FALSE);\r | |
409 | }\r | |
68dbca6c LG |
410 | FreePool (NewString);\r |
411 | \r | |
a6f164a7 | 412 | //\r |
413 | // created needed controller device item in first page\r | |
414 | //\r | |
415 | DevicePathHandleCount = 0;\r | |
416 | Status = gBS->LocateHandleBuffer (\r | |
417 | ByProtocol,\r | |
418 | &gEfiDevicePathProtocolGuid,\r | |
419 | NULL,\r | |
420 | &DevicePathHandleCount,\r | |
421 | &mDevicePathHandleBuffer\r | |
422 | );\r | |
423 | if (EFI_ERROR (Status) || (DevicePathHandleCount == 0)) {\r | |
424 | return EFI_SUCCESS;\r | |
425 | }\r | |
426 | \r | |
427 | for (Index = 0; Index < DevicePathHandleCount; Index++) {\r | |
428 | if (FakeNvData->PciDeviceFilter == 0x01) {\r | |
429 | //\r | |
430 | // Only care PCI device which contain efi driver in its option rom.\r | |
431 | //\r | |
432 | \r | |
433 | //\r | |
434 | // Check whether it is a pci device\r | |
435 | //\r | |
436 | ControllerDevicePath = NULL;\r | |
437 | Status = gBS->OpenProtocol (\r | |
438 | mDevicePathHandleBuffer[Index],\r | |
439 | &gEfiPciIoProtocolGuid,\r | |
440 | (VOID **) &PciIo,\r | |
441 | NULL,\r | |
442 | NULL,\r | |
443 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
444 | );\r | |
445 | if (EFI_ERROR (Status)) {\r | |
446 | continue;\r | |
447 | }\r | |
448 | //\r | |
449 | // Check whether it contain efi driver in its option rom\r | |
450 | //\r | |
451 | Status = gBS->HandleProtocol(\r | |
452 | mDevicePathHandleBuffer[Index],\r | |
453 | &gEfiBusSpecificDriverOverrideProtocolGuid,\r | |
454 | (VOID **) &BusSpecificDriverOverride\r | |
455 | );\r | |
456 | if (EFI_ERROR (Status) || BusSpecificDriverOverride == NULL) {\r | |
457 | continue;\r | |
458 | }\r | |
459 | }\r | |
460 | \r | |
461 | ControllerDevicePath = NULL;\r | |
462 | Status = gBS->OpenProtocol (\r | |
463 | mDevicePathHandleBuffer[Index],\r | |
464 | &gEfiDevicePathProtocolGuid,\r | |
465 | (VOID **) &ControllerDevicePath,\r | |
466 | NULL,\r | |
467 | NULL,\r | |
468 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
469 | );\r | |
470 | ASSERT_EFI_ERROR (Status);\r | |
471 | //\r | |
472 | // Save the device path protocol interface\r | |
473 | //\r | |
474 | mControllerDevicePathProtocol[Index] = ControllerDevicePath;\r | |
475 | \r | |
476 | //\r | |
477 | // Get the driver name\r | |
478 | //\r | |
479 | ControllerName = DevicePathToStr (ControllerDevicePath);\r | |
480 | \r | |
481 | //\r | |
482 | // Export the driver name string and create item in set options page\r | |
483 | //\r | |
484 | Len = StrSize (ControllerName);\r | |
485 | NewString = AllocateZeroPool (Len + StrSize (L"--"));\r | |
77980854 | 486 | ASSERT (NewString != NULL);\r |
a6f164a7 | 487 | if (EFI_ERROR (CheckMapping (ControllerDevicePath,NULL, &mMappingDataBase, NULL, NULL))) {\r |
488 | StrCat (NewString, L"--");\r | |
489 | } else {\r | |
490 | StrCat (NewString, L"**");\r | |
491 | }\r | |
492 | StrCat (NewString, ControllerName);\r | |
493 | \r | |
cb7d01c0 | 494 | NewStringToken = HiiSetString (Private->RegisteredHandle, mControllerToken[Index], NewString, NULL);\r |
495 | ASSERT (NewStringToken != 0);\r | |
68dbca6c | 496 | FreePool (NewString);\r |
a6f164a7 | 497 | //\r |
498 | // Save the device path string toke for next access use\r | |
499 | //\r | |
500 | mControllerToken[Index] = NewStringToken;\r | |
7e3bcccb LG |
501 | \r |
502 | HiiCreateGotoOpCode (\r | |
503 | StartOpCodeHandle,\r | |
a6f164a7 | 504 | FORM_ID_DRIVER,\r |
505 | NewStringToken,\r | |
506 | STRING_TOKEN (STR_GOTO_HELP_DRIVER),\r | |
507 | EFI_IFR_FLAG_CALLBACK,\r | |
7e3bcccb | 508 | (UINT16) (Index + KEY_VALUE_DEVICE_OFFSET)\r |
a6f164a7 | 509 | );\r |
510 | }\r | |
511 | \r | |
512 | //\r | |
513 | // Update first page form\r | |
514 | //\r | |
7e3bcccb | 515 | HiiUpdateForm (\r |
a6f164a7 | 516 | Private->RegisteredHandle,\r |
c8ad2d7a | 517 | &gPlatformOverridesManagerGuid,\r |
a6f164a7 | 518 | FORM_ID_DEVICE,\r |
7e3bcccb LG |
519 | StartOpCodeHandle, // Label FORM_ID_DEVICE\r |
520 | EndOpCodeHandle // LABEL_END\r | |
a6f164a7 | 521 | );\r |
522 | \r | |
7e3bcccb LG |
523 | HiiFreeOpCodeHandle (StartOpCodeHandle);\r |
524 | HiiFreeOpCodeHandle (EndOpCodeHandle);\r | |
525 | \r | |
a6f164a7 | 526 | return EFI_SUCCESS;\r |
527 | }\r | |
528 | \r | |
68dbca6c LG |
529 | /**\r |
530 | Get the first Driver Binding handle which has the specific image handle.\r | |
531 | \r | |
532 | @param ImageHandle The Image handle\r | |
533 | \r | |
534 | @return Handle to Driver binding\r | |
535 | @retval NULL The paramter is not valid or the driver binding handle is not found.\r | |
536 | \r | |
537 | **/\r | |
538 | EFI_HANDLE\r | |
539 | GetDriverBindingHandleFromImageHandle (\r | |
540 | IN EFI_HANDLE ImageHandle\r | |
541 | )\r | |
542 | {\r | |
543 | EFI_STATUS Status;\r | |
544 | UINTN Index;\r | |
545 | UINTN DriverBindingHandleCount;\r | |
546 | EFI_HANDLE *DriverBindingHandleBuffer;\r | |
547 | EFI_DRIVER_BINDING_PROTOCOL *DriverBindingInterface;\r | |
548 | EFI_HANDLE DriverBindingHandle;\r | |
549 | \r | |
550 | DriverBindingHandle = NULL;\r | |
551 | \r | |
552 | if (ImageHandle == NULL) {\r | |
553 | return NULL;\r | |
554 | }\r | |
555 | //\r | |
556 | // Get all drivers which support driver binding protocol\r | |
557 | //\r | |
558 | DriverBindingHandleCount = 0;\r | |
559 | Status = gBS->LocateHandleBuffer (\r | |
560 | ByProtocol,\r | |
561 | &gEfiDriverBindingProtocolGuid,\r | |
562 | NULL,\r | |
563 | &DriverBindingHandleCount,\r | |
564 | &DriverBindingHandleBuffer\r | |
565 | );\r | |
566 | if (EFI_ERROR (Status) || (DriverBindingHandleCount == 0)) {\r | |
567 | return NULL;\r | |
568 | }\r | |
e5618791 LG |
569 | \r |
570 | //\r | |
571 | // Get the first Driver Binding handle which has the specific image handle.\r | |
572 | //\r | |
68dbca6c LG |
573 | for (Index = 0; Index < DriverBindingHandleCount; Index++) {\r |
574 | DriverBindingInterface = NULL;\r | |
575 | Status = gBS->OpenProtocol (\r | |
576 | DriverBindingHandleBuffer[Index],\r | |
577 | &gEfiDriverBindingProtocolGuid,\r | |
578 | (VOID **) &DriverBindingInterface,\r | |
579 | NULL,\r | |
580 | NULL,\r | |
581 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
582 | );\r | |
583 | if (EFI_ERROR (Status)) {\r | |
584 | continue;\r | |
585 | }\r | |
586 | \r | |
587 | if (DriverBindingInterface->ImageHandle == ImageHandle) {\r | |
588 | DriverBindingHandle = DriverBindingHandleBuffer[Index];\r | |
589 | break;\r | |
590 | }\r | |
591 | }\r | |
592 | \r | |
68dbca6c LG |
593 | FreePool (DriverBindingHandleBuffer);\r |
594 | return DriverBindingHandle;\r | |
595 | }\r | |
596 | \r | |
a6f164a7 | 597 | /**\r |
598 | Prepare to let user select the drivers which need mapping with the device controller\r | |
599 | selected in first page.\r | |
600 | \r | |
601 | @param Private Pointer to EFI_CALLBACK_INFO.\r | |
602 | @param KeyValue The callback key value of device controller item in first page.\r | |
9872985b | 603 | KeyValue is larger than or equal to KEY_VALUE_DEVICE_OFFSET.\r |
a6f164a7 | 604 | @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.\r |
605 | \r | |
606 | @retval EFI_SUCCESS Always returned.\r | |
607 | \r | |
608 | **/\r | |
609 | EFI_STATUS\r | |
610 | UpdateBindingDriverSelectPage (\r | |
611 | IN EFI_CALLBACK_INFO *Private,\r | |
612 | IN UINT16 KeyValue,\r | |
613 | IN PLAT_OVER_MNGR_DATA *FakeNvData\r | |
614 | )\r | |
615 | {\r | |
a6f164a7 | 616 | EFI_STATUS Status;\r |
617 | UINTN Index;\r | |
a6f164a7 | 618 | CHAR16 *NewString;\r |
619 | EFI_STRING_ID NewStringToken;\r | |
620 | EFI_STRING_ID NewStringHelpToken;\r | |
621 | UINTN DriverImageHandleCount;\r | |
a6f164a7 | 622 | EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r |
623 | CHAR16 *DriverName;\r | |
624 | BOOLEAN FreeDriverName;\r | |
a6f164a7 | 625 | EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath;\r |
626 | EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL *BusSpecificDriverOverride;\r | |
627 | EFI_HANDLE DriverBindingHandle;\r | |
7e3bcccb LG |
628 | VOID *StartOpCodeHandle;\r |
629 | VOID *EndOpCodeHandle;\r | |
630 | EFI_IFR_GUID_LABEL *StartLabel;\r | |
631 | EFI_IFR_GUID_LABEL *EndLabel;\r | |
68dbca6c | 632 | \r |
a6f164a7 | 633 | //\r |
634 | // If user select a controller item in the first page the following code will be run.\r | |
635 | // During second page, user will see all currnet driver bind protocol driver, the driver name and its device path will be shown\r | |
636 | //\r | |
637 | //First acquire the list of Loaded Image Protocols, and then when want the name of the driver, look up all the Driver Binding Protocols\r | |
638 | // and find the first one whose ImageHandle field matches the image handle of the Loaded Image Protocol.\r | |
639 | // then use the Component Name Protocol on the same handle as the first matching Driver Binding Protocol to look up the name of the driver.\r | |
640 | //\r | |
641 | \r | |
642 | mCurrentPage = FORM_ID_DRIVER;\r | |
643 | //\r | |
644 | // Switch the item callback key value to its NO. in mDevicePathHandleBuffer\r | |
645 | //\r | |
68dbca6c | 646 | mSelectedCtrIndex = KeyValue - KEY_VALUE_DEVICE_OFFSET;\r |
e35eb8af | 647 | ASSERT (mSelectedCtrIndex >= 0 && mSelectedCtrIndex < MAX_CHOICE_NUM);\r |
db0bd81c | 648 | \r |
a6f164a7 | 649 | mLastSavedDriverImageNum = 0;\r |
7e3bcccb | 650 | \r |
a6f164a7 | 651 | //\r |
7e3bcccb | 652 | // Init OpCode Handle\r |
a6f164a7 | 653 | //\r |
7e3bcccb LG |
654 | StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r |
655 | ASSERT (StartOpCodeHandle != NULL);\r | |
656 | \r | |
657 | EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r | |
658 | ASSERT (EndOpCodeHandle != NULL);\r | |
659 | \r | |
660 | //\r | |
661 | // Create Hii Extend Label OpCode as the start opcode\r | |
662 | //\r | |
663 | StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r | |
664 | StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r | |
665 | StartLabel->Number = FORM_ID_DRIVER;\r | |
666 | \r | |
667 | //\r | |
668 | // Create Hii Extend Label OpCode as the end opcode\r | |
669 | //\r | |
670 | EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r | |
671 | EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r | |
672 | EndLabel->Number = LABEL_END;\r | |
673 | \r | |
a6f164a7 | 674 | //\r |
675 | // Clear second page form\r | |
676 | //\r | |
7e3bcccb | 677 | HiiUpdateForm (\r |
a6f164a7 | 678 | Private->RegisteredHandle,\r |
c8ad2d7a | 679 | &gPlatformOverridesManagerGuid,\r |
a6f164a7 | 680 | FORM_ID_DRIVER,\r |
7e3bcccb LG |
681 | StartOpCodeHandle,\r |
682 | EndOpCodeHandle\r | |
a6f164a7 | 683 | );\r |
684 | \r | |
685 | //\r | |
686 | // Show all driver which support loaded image protocol in second page\r | |
687 | //\r | |
688 | DriverImageHandleCount = 0;\r | |
689 | Status = gBS->LocateHandleBuffer (\r | |
690 | ByProtocol,\r | |
691 | &gEfiLoadedImageProtocolGuid,\r | |
692 | NULL,\r | |
693 | &DriverImageHandleCount,\r | |
694 | &mDriverImageHandleBuffer\r | |
695 | );\r | |
696 | if (EFI_ERROR (Status) || (DriverImageHandleCount == 0)) {\r | |
697 | return EFI_NOT_FOUND;\r | |
698 | }\r | |
699 | \r | |
700 | mDriverImageHandleCount = DriverImageHandleCount;\r | |
701 | for (Index = 0; Index < DriverImageHandleCount; Index++) {\r | |
702 | //\r | |
703 | // Step1: Get the driver image total file path for help string and the driver name.\r | |
704 | //\r | |
705 | \r | |
706 | //\r | |
707 | // Find driver's Loaded Image protocol\r | |
708 | //\r | |
709 | LoadedImage =NULL;\r | |
710 | \r | |
711 | Status = gBS->OpenProtocol (\r | |
712 | mDriverImageHandleBuffer[Index],\r | |
713 | &gEfiLoadedImageProtocolGuid,\r | |
714 | (VOID **) &LoadedImage,\r | |
715 | NULL,\r | |
716 | NULL,\r | |
717 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
718 | );\r | |
719 | if (EFI_ERROR (Status)) {\r | |
720 | FakeNvData->DriSelection[Index] = 0x00;\r | |
721 | continue;\r | |
722 | }\r | |
723 | mDriverImageProtocol[Index] = LoadedImage;\r | |
724 | //\r | |
725 | // Find its related driver binding protocol\r | |
726 | //\r | |
68dbca6c LG |
727 | DriverBindingHandle = GetDriverBindingHandleFromImageHandle (mDriverImageHandleBuffer[Index]);\r |
728 | if (DriverBindingHandle == NULL) {\r | |
a6f164a7 | 729 | FakeNvData->DriSelection[Index] = 0x00;\r |
730 | continue;\r | |
731 | }\r | |
732 | \r | |
733 | //\r | |
734 | // Get the EFI Loaded Image Device Path Protocol\r | |
735 | //\r | |
736 | LoadedImageDevicePath = NULL;\r | |
737 | Status = gBS->HandleProtocol (\r | |
738 | mDriverImageHandleBuffer[Index],\r | |
739 | &gEfiLoadedImageDevicePathProtocolGuid,\r | |
740 | (VOID **) &LoadedImageDevicePath\r | |
741 | );\r | |
742 | if (LoadedImageDevicePath == NULL) {\r | |
743 | FakeNvData->DriSelection[Index] = 0x00;\r | |
744 | continue;\r | |
745 | }\r | |
746 | \r | |
747 | if (FakeNvData->PciDeviceFilter == 0x01) {\r | |
748 | //\r | |
749 | // only care the driver which is in a Pci device option rom,\r | |
750 | // and the driver's LoadedImage->DeviceHandle must point to a pci device which has efi option rom\r | |
751 | //\r | |
752 | if (!EFI_ERROR (Status)) {\r | |
753 | Status = gBS->HandleProtocol(\r | |
754 | LoadedImage->DeviceHandle,\r | |
755 | &gEfiBusSpecificDriverOverrideProtocolGuid,\r | |
756 | (VOID **) &BusSpecificDriverOverride\r | |
757 | );\r | |
758 | if (EFI_ERROR (Status) || BusSpecificDriverOverride == NULL) {\r | |
759 | FakeNvData->DriSelection[Index] = 0x00;\r | |
760 | continue;\r | |
761 | }\r | |
762 | } else {\r | |
763 | FakeNvData->DriSelection[Index] = 0x00;\r | |
764 | continue;\r | |
765 | }\r | |
766 | }\r | |
767 | \r | |
768 | //\r | |
769 | // For driver name, try to get its component name, if fail, get its image name,\r | |
770 | // if also fail, give a default name.\r | |
771 | //\r | |
772 | FreeDriverName = FALSE;\r | |
773 | DriverName = GetComponentName (DriverBindingHandle);\r | |
774 | if (DriverName == NULL) {\r | |
775 | //\r | |
776 | // get its image name\r | |
777 | //\r | |
778 | DriverName = GetImageName (LoadedImage);\r | |
779 | }\r | |
780 | if (DriverName == NULL) {\r | |
781 | //\r | |
782 | // give a default name\r | |
783 | //\r | |
cb7d01c0 | 784 | DriverName = HiiGetString (Private->RegisteredHandle, STRING_TOKEN (STR_DRIVER_DEFAULT_NAME), NULL);\r |
a6f164a7 | 785 | ASSERT (DriverName != NULL);\r |
786 | FreeDriverName = TRUE; // the DriverName string need to free pool\r | |
787 | }\r | |
788 | \r | |
789 | \r | |
790 | //\r | |
791 | // Step2 Export the driver name string and create check box item in second page\r | |
792 | //\r | |
793 | \r | |
794 | //\r | |
795 | // First create the driver image name\r | |
796 | //\r | |
797 | NewString = AllocateZeroPool (StrSize (DriverName));\r | |
77980854 | 798 | ASSERT (NewString != NULL); \r |
a6f164a7 | 799 | if (EFI_ERROR (CheckMapping (mControllerDevicePathProtocol[mSelectedCtrIndex], LoadedImageDevicePath, &mMappingDataBase, NULL, NULL))) {\r |
800 | FakeNvData->DriSelection[Index] = 0x00;\r | |
801 | } else {\r | |
802 | FakeNvData->DriSelection[Index] = 0x01;\r | |
803 | mLastSavedDriverImageNum++;\r | |
804 | }\r | |
805 | StrCat (NewString, DriverName);\r | |
cb7d01c0 | 806 | NewStringToken = HiiSetString (Private->RegisteredHandle, mDriverImageToken[Index], NewString, NULL);\r |
807 | ASSERT (NewStringToken != 0);\r | |
a6f164a7 | 808 | mDriverImageToken[Index] = NewStringToken;\r |
68dbca6c | 809 | FreePool (NewString);\r |
a6f164a7 | 810 | if (FreeDriverName) {\r |
68dbca6c | 811 | FreePool (DriverName);\r |
a6f164a7 | 812 | }\r |
813 | \r | |
814 | //\r | |
815 | // Second create the driver image device path as item help string\r | |
816 | //\r | |
817 | DriverName = DevicePathToStr (LoadedImageDevicePath);\r | |
818 | \r | |
819 | NewString = AllocateZeroPool (StrSize (DriverName));\r | |
80882266 | 820 | ASSERT (NewString != NULL); \r |
a6f164a7 | 821 | StrCat (NewString, DriverName);\r |
cb7d01c0 | 822 | NewStringHelpToken = HiiSetString (Private->RegisteredHandle, mDriverImageFilePathToken[Index], NewString, NULL);\r |
823 | ASSERT (NewStringHelpToken != 0);\r | |
a6f164a7 | 824 | mDriverImageFilePathToken[Index] = NewStringHelpToken;\r |
68dbca6c LG |
825 | FreePool (NewString);\r |
826 | FreePool (DriverName);\r | |
a6f164a7 | 827 | \r |
7e3bcccb LG |
828 | HiiCreateCheckBoxOpCode (\r |
829 | StartOpCodeHandle,\r | |
a6f164a7 | 830 | (UINT16) (DRIVER_SELECTION_QUESTION_ID + Index),\r |
831 | VARSTORE_ID_PLAT_OVER_MNGR,\r | |
832 | (UINT16) (DRIVER_SELECTION_VAR_OFFSET + Index),\r | |
833 | NewStringToken,\r | |
834 | NewStringHelpToken,\r | |
835 | 0,\r | |
836 | 0,\r | |
7e3bcccb | 837 | NULL\r |
a6f164a7 | 838 | );\r |
839 | }\r | |
840 | \r | |
841 | //\r | |
842 | // Update second page form\r | |
843 | //\r | |
7e3bcccb | 844 | HiiUpdateForm (\r |
a6f164a7 | 845 | Private->RegisteredHandle,\r |
c8ad2d7a | 846 | &gPlatformOverridesManagerGuid,\r |
a6f164a7 | 847 | FORM_ID_DRIVER,\r |
7e3bcccb LG |
848 | StartOpCodeHandle, // Label FORM_ID_DRIVER\r |
849 | EndOpCodeHandle // LABEL_END\r | |
a6f164a7 | 850 | );\r |
851 | \r | |
7e3bcccb LG |
852 | HiiFreeOpCodeHandle (StartOpCodeHandle);\r |
853 | HiiFreeOpCodeHandle (EndOpCodeHandle);\r | |
a6f164a7 | 854 | return EFI_SUCCESS;\r |
855 | }\r | |
856 | \r | |
857 | /**\r | |
858 | Prepare to let user select the priority order of the drivers which are\r | |
859 | selected in second page.\r | |
860 | \r | |
861 | @param Private Pointer to EFI_CALLBACK_INFO.\r | |
862 | @param KeyValue The callback key value of device controller item in first page.\r | |
863 | @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.\r | |
864 | \r | |
865 | @retval EFI_SUCCESS Always returned.\r | |
866 | \r | |
867 | **/\r | |
868 | EFI_STATUS\r | |
869 | UpdatePrioritySelectPage (\r | |
870 | IN EFI_CALLBACK_INFO *Private,\r | |
871 | IN UINT16 KeyValue,\r | |
872 | IN PLAT_OVER_MNGR_DATA *FakeNvData\r | |
873 | )\r | |
874 | {\r | |
a6f164a7 | 875 | UINTN Index;\r |
a6f164a7 | 876 | EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath;\r |
a6f164a7 | 877 | UINTN SelectedDriverImageNum;\r |
878 | UINT32 DriverImageNO;\r | |
879 | UINTN MinNO;\r | |
880 | UINTN Index1;\r | |
881 | UINTN TempNO[100];\r | |
7e3bcccb LG |
882 | UINTN OrderNO[100];\r |
883 | VOID *StartOpCodeHandle;\r | |
884 | VOID *EndOpCodeHandle;\r | |
885 | VOID *OptionsOpCodeHandle;\r | |
886 | EFI_IFR_GUID_LABEL *StartLabel;\r | |
887 | EFI_IFR_GUID_LABEL *EndLabel;\r | |
a6f164a7 | 888 | \r |
889 | //\r | |
890 | // Following code will be run if user select 'order ... priority' item in second page\r | |
891 | // Prepare third page. In third page, user will order the drivers priority which are selected in second page\r | |
892 | //\r | |
893 | mCurrentPage = FORM_ID_ORDER;\r | |
894 | \r | |
7e3bcccb LG |
895 | //\r |
896 | // Init OpCode Handle\r | |
897 | //\r | |
898 | StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r | |
899 | ASSERT (StartOpCodeHandle != NULL);\r | |
900 | \r | |
901 | EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r | |
902 | ASSERT (EndOpCodeHandle != NULL);\r | |
903 | \r | |
904 | //\r | |
905 | // Create Hii Extend Label OpCode as the start opcode\r | |
906 | //\r | |
907 | StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r | |
908 | StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r | |
909 | StartLabel->Number = FORM_ID_ORDER;\r | |
910 | \r | |
911 | //\r | |
912 | // Create Hii Extend Label OpCode as the end opcode\r | |
913 | //\r | |
914 | EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r | |
915 | EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r | |
916 | EndLabel->Number = LABEL_END;\r | |
917 | \r | |
a6f164a7 | 918 | //\r |
919 | // Clear third page form\r | |
920 | //\r | |
7e3bcccb | 921 | HiiUpdateForm (\r |
a6f164a7 | 922 | Private->RegisteredHandle,\r |
c8ad2d7a | 923 | &gPlatformOverridesManagerGuid,\r |
a6f164a7 | 924 | FORM_ID_ORDER,\r |
7e3bcccb LG |
925 | StartOpCodeHandle,\r |
926 | EndOpCodeHandle\r | |
a6f164a7 | 927 | );\r |
928 | \r | |
929 | //\r | |
930 | // Check how many drivers have been selected\r | |
931 | //\r | |
932 | SelectedDriverImageNum = 0;\r | |
933 | for (Index = 0; Index < mDriverImageHandleCount; Index++) {\r | |
934 | if (FakeNvData->DriSelection[Index] != 0) {\r | |
935 | SelectedDriverImageNum ++;\r | |
936 | }\r | |
937 | }\r | |
938 | \r | |
939 | mSelectedDriverImageNum = SelectedDriverImageNum;\r | |
940 | if (SelectedDriverImageNum == 0) {\r | |
941 | return EFI_SUCCESS;\r | |
942 | }\r | |
7e3bcccb LG |
943 | \r |
944 | OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r | |
945 | ASSERT (OptionsOpCodeHandle != NULL);\r | |
946 | \r | |
a6f164a7 | 947 | //\r |
948 | // Create order list for those selected drivers\r | |
949 | //\r | |
950 | SelectedDriverImageNum = 0;\r | |
951 | for (Index = 0; Index < mDriverImageHandleCount; Index++) {\r | |
952 | if (FakeNvData->DriSelection[Index] != 0) {\r | |
a6f164a7 | 953 | //\r |
954 | // Use the NO. in driver binding buffer as value, will use it later\r | |
955 | //\r | |
7e3bcccb LG |
956 | HiiCreateOneOfOptionOpCode (\r |
957 | OptionsOpCodeHandle,\r | |
958 | mDriverImageToken[Index],\r | |
959 | 0,\r | |
960 | EFI_IFR_NUMERIC_SIZE_1,\r | |
961 | Index + 1\r | |
962 | );\r | |
a6f164a7 | 963 | \r |
964 | //\r | |
965 | // Get the EFI Loaded Image Device Path Protocol\r | |
966 | //\r | |
967 | LoadedImageDevicePath = NULL;\r | |
968 | gBS->HandleProtocol (\r | |
969 | mDriverImageHandleBuffer[Index],\r | |
970 | &gEfiLoadedImageDevicePathProtocolGuid,\r | |
971 | (VOID **) &LoadedImageDevicePath\r | |
972 | );\r | |
973 | ASSERT (LoadedImageDevicePath != NULL);\r | |
974 | \r | |
975 | //\r | |
976 | // Check the driver DriverImage's order number in mapping database\r | |
977 | //\r | |
978 | DriverImageNO = 0;\r | |
979 | CheckMapping (\r | |
980 | mControllerDevicePathProtocol[mSelectedCtrIndex],\r | |
981 | LoadedImageDevicePath,\r | |
982 | &mMappingDataBase,\r | |
983 | NULL,\r | |
984 | &DriverImageNO\r | |
985 | );\r | |
986 | if (DriverImageNO == 0) {\r | |
987 | DriverImageNO = (UINT32) mLastSavedDriverImageNum + 1;\r | |
988 | mLastSavedDriverImageNum++;\r | |
989 | }\r | |
990 | TempNO[SelectedDriverImageNum] = DriverImageNO;\r | |
7e3bcccb | 991 | OrderNO[SelectedDriverImageNum] = Index + 1;\r |
a6f164a7 | 992 | SelectedDriverImageNum ++;\r |
993 | }\r | |
994 | }\r | |
995 | \r | |
996 | ASSERT (SelectedDriverImageNum == mSelectedDriverImageNum);\r | |
997 | //\r | |
998 | // NvRamMap Must be clear firstly\r | |
999 | //\r | |
68dbca6c | 1000 | ZeroMem (FakeNvData->DriOrder, sizeof (FakeNvData->DriOrder));\r |
a6f164a7 | 1001 | \r |
1002 | //\r | |
1003 | // Order the selected drivers according to the info already in mapping database\r | |
1004 | // the less order number in mapping database the less order number in NvRamMap\r | |
1005 | //\r | |
1006 | for (Index=0; Index < SelectedDriverImageNum; Index++) {\r | |
1007 | //\r | |
1008 | // Find the minimal order number in TempNO array, its index in TempNO is same as IfrOptionList array\r | |
1009 | //\r | |
1010 | MinNO = 0;\r | |
1011 | for (Index1=0; Index1 < SelectedDriverImageNum; Index1++) {\r | |
1012 | if (TempNO[Index1] < TempNO[MinNO]) {\r | |
1013 | MinNO = Index1;\r | |
1014 | }\r | |
1015 | }\r | |
1016 | //\r | |
1017 | // the IfrOptionList[MinNO].Value = the driver NO. in driver binding buffer\r | |
1018 | //\r | |
7e3bcccb | 1019 | FakeNvData->DriOrder[Index] = (UINT8) OrderNO[MinNO];\r |
68dbca6c | 1020 | TempNO[MinNO] = MAX_CHOICE_NUM + 1;\r |
a6f164a7 | 1021 | }\r |
7e3bcccb LG |
1022 | \r |
1023 | //\r | |
1024 | // Create Order List OpCode\r | |
1025 | //\r | |
1026 | HiiCreateOrderedListOpCode (\r | |
1027 | StartOpCodeHandle,\r | |
a6f164a7 | 1028 | (UINT16) DRIVER_ORDER_QUESTION_ID,\r |
1029 | VARSTORE_ID_PLAT_OVER_MNGR,\r | |
1030 | (UINT16) DRIVER_ORDER_VAR_OFFSET,\r | |
1031 | mControllerToken[mSelectedCtrIndex],\r | |
1032 | mControllerToken[mSelectedCtrIndex],\r | |
1033 | EFI_IFR_FLAG_RESET_REQUIRED,\r | |
1034 | 0,\r | |
1035 | EFI_IFR_NUMERIC_SIZE_1,\r | |
40b96d40 | 1036 | (UINT8) MAX_CHOICE_NUM,\r |
7e3bcccb LG |
1037 | OptionsOpCodeHandle,\r |
1038 | NULL\r | |
a6f164a7 | 1039 | );\r |
1040 | \r | |
1041 | //\r | |
1042 | // Update third page form\r | |
1043 | //\r | |
7e3bcccb | 1044 | HiiUpdateForm (\r |
a6f164a7 | 1045 | Private->RegisteredHandle,\r |
c8ad2d7a | 1046 | &gPlatformOverridesManagerGuid,\r |
a6f164a7 | 1047 | FORM_ID_ORDER,\r |
7e3bcccb LG |
1048 | StartOpCodeHandle, // Label FORM_ID_ORDER\r |
1049 | EndOpCodeHandle // LABEL_END\r | |
a6f164a7 | 1050 | );\r |
1051 | \r | |
7e3bcccb LG |
1052 | HiiFreeOpCodeHandle (StartOpCodeHandle);\r |
1053 | HiiFreeOpCodeHandle (EndOpCodeHandle);\r | |
1054 | HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r | |
1055 | \r | |
a6f164a7 | 1056 | return EFI_SUCCESS;\r |
1057 | }\r | |
1058 | \r | |
1059 | /**\r | |
1060 | Save the save the mapping database to NV variable.\r | |
1061 | \r | |
1062 | @param Private Pointer to EFI_CALLBACK_INFO.\r | |
1063 | @param KeyValue The callback key value of device controller item in first page.\r | |
1064 | @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.\r | |
1065 | \r | |
1066 | @retval EFI_SUCCESS Always returned.\r | |
1067 | \r | |
1068 | **/\r | |
1069 | EFI_STATUS\r | |
1070 | CommintChanges (\r | |
1071 | IN EFI_CALLBACK_INFO *Private,\r | |
1072 | IN UINT16 KeyValue,\r | |
1073 | IN PLAT_OVER_MNGR_DATA *FakeNvData\r | |
1074 | )\r | |
1075 | {\r | |
1076 | EFI_STATUS Status;\r | |
1077 | UINTN Index;\r | |
1078 | UINTN SelectedDriverImageNum;\r | |
1079 | EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath;\r | |
1080 | //\r | |
1081 | // Following code will be run if user select 'commint changes' in third page\r | |
1082 | // user enter 'Commit Changes' to save the mapping database\r | |
1083 | //\r | |
1084 | DeleteDriverImage (mControllerDevicePathProtocol[mSelectedCtrIndex], NULL, &mMappingDataBase);\r | |
1085 | for (SelectedDriverImageNum = 0; SelectedDriverImageNum < mSelectedDriverImageNum; SelectedDriverImageNum++) {\r | |
1086 | //\r | |
1087 | // DriOrder[SelectedDriverImageNum] = the driver NO. in driver binding buffer\r | |
1088 | //\r | |
1089 | Index = FakeNvData->DriOrder[SelectedDriverImageNum] - 1;\r | |
1090 | \r | |
1091 | //\r | |
1092 | // Get the EFI Loaded Image Device Path Protocol\r | |
1093 | //\r | |
1094 | LoadedImageDevicePath = NULL;\r | |
1095 | Status = gBS->HandleProtocol (\r | |
1096 | mDriverImageHandleBuffer[Index],\r | |
1097 | &gEfiLoadedImageDevicePathProtocolGuid,\r | |
1098 | (VOID **) &LoadedImageDevicePath\r | |
1099 | );\r | |
1100 | ASSERT (LoadedImageDevicePath != NULL);\r | |
1101 | \r | |
1102 | InsertDriverImage (\r | |
1103 | mControllerDevicePathProtocol[mSelectedCtrIndex],\r | |
1104 | LoadedImageDevicePath,\r | |
1105 | &mMappingDataBase,\r | |
1106 | (UINT32)SelectedDriverImageNum + 1\r | |
1107 | );\r | |
1108 | }\r | |
1109 | Status = SaveOverridesMapping (&mMappingDataBase);\r | |
1110 | \r | |
1111 | return Status;\r | |
1112 | }\r | |
1113 | \r | |
1114 | /**\r | |
1115 | This function allows a caller to extract the current configuration for one\r | |
1116 | or more named elements from the target driver.\r | |
1117 | \r | |
1118 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
1119 | @param Request A null-terminated Unicode string in <ConfigRequest> format.\r | |
1120 | @param Progress On return, points to a character in the Request string.\r | |
1121 | Points to the string's null terminator if request was successful.\r | |
1122 | Points to the most recent '&' before the first failing name/value\r | |
1123 | pair (or the beginning of the string if the failure is in the\r | |
1124 | first name/value pair) if the request was not successful.\r | |
1125 | @param Results A null-terminated Unicode string in <ConfigAltResp> format which\r | |
1126 | has all values filled in for the names in the Request string.\r | |
1127 | String to be allocated by the called function.\r | |
1128 | \r | |
1129 | @retval EFI_SUCCESS The Results is filled with the requested values.\r | |
1130 | @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.\r | |
e35eb8af | 1131 | @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.\r |
a6f164a7 | 1132 | @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.\r |
1133 | \r | |
1134 | **/\r | |
1135 | EFI_STATUS\r | |
1136 | EFIAPI\r | |
1137 | PlatOverMngrExtractConfig (\r | |
68dbca6c | 1138 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r |
a6f164a7 | 1139 | IN CONST EFI_STRING Request,\r |
1140 | OUT EFI_STRING *Progress,\r | |
1141 | OUT EFI_STRING *Results\r | |
1142 | )\r | |
1143 | {\r | |
1144 | EFI_STATUS Status;\r | |
1145 | EFI_CALLBACK_INFO *Private;\r | |
1146 | EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;\r | |
59aefb7e LG |
1147 | EFI_STRING ConfigRequestHdr;\r |
1148 | EFI_STRING ConfigRequest;\r | |
1149 | BOOLEAN AllocatedRequest;\r | |
1150 | UINTN Size;\r | |
1151 | UINTN BufferSize;\r | |
8d00a0f1 | 1152 | \r |
59aefb7e | 1153 | if (Progress == NULL || Results == NULL) {\r |
ae79d2f9 LG |
1154 | return EFI_INVALID_PARAMETER;\r |
1155 | }\r | |
59aefb7e LG |
1156 | \r |
1157 | *Progress = Request;\r | |
c8ad2d7a | 1158 | if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &gPlatformOverridesManagerGuid, mVariableName)) {\r |
59aefb7e LG |
1159 | return EFI_NOT_FOUND;\r |
1160 | }\r | |
1161 | \r | |
1162 | ConfigRequestHdr = NULL;\r | |
1163 | ConfigRequest = NULL;\r | |
1164 | Size = 0;\r | |
1165 | AllocatedRequest = FALSE;\r | |
1166 | \r | |
ae79d2f9 | 1167 | Private = EFI_CALLBACK_INFO_FROM_THIS (This);\r |
a6f164a7 | 1168 | HiiConfigRouting = Private->HiiConfigRouting;\r |
59aefb7e LG |
1169 | ConfigRequest = Request;\r |
1170 | if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {\r | |
1171 | //\r | |
1172 | // Request has no request element, construct full request string.\r | |
1173 | // Allocate and fill a buffer large enough to hold the <ConfigHdr> template\r | |
1174 | // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator\r | |
1175 | //\r | |
c8ad2d7a | 1176 | ConfigRequestHdr = HiiConstructConfigHdr (&gPlatformOverridesManagerGuid, mVariableName, Private->DriverHandle);\r |
59aefb7e LG |
1177 | Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r |
1178 | ConfigRequest = AllocateZeroPool (Size);\r | |
1179 | ASSERT (ConfigRequest != NULL);\r | |
1180 | AllocatedRequest = TRUE;\r | |
1181 | BufferSize = sizeof (PLAT_OVER_MNGR_DATA);\r | |
1182 | UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);\r | |
1183 | FreePool (ConfigRequestHdr);\r | |
1184 | }\r | |
a6f164a7 | 1185 | \r |
1186 | //\r | |
1187 | // Convert buffer data to <ConfigResp> by helper function BlockToConfig()\r | |
1188 | //\r | |
1189 | Status = HiiConfigRouting->BlockToConfig (\r | |
1190 | HiiConfigRouting,\r | |
59aefb7e | 1191 | ConfigRequest,\r |
a6f164a7 | 1192 | (UINT8 *) &Private->FakeNvData,\r |
1193 | sizeof (PLAT_OVER_MNGR_DATA),\r | |
1194 | Results,\r | |
1195 | Progress\r | |
1196 | );\r | |
59aefb7e LG |
1197 | \r |
1198 | //\r | |
1199 | // Free the allocated config request string.\r | |
1200 | //\r | |
1201 | if (AllocatedRequest) {\r | |
1202 | FreePool (ConfigRequest);\r | |
1203 | ConfigRequest = NULL;\r | |
1204 | }\r | |
1205 | //\r | |
1206 | // Set Progress string to the original request string.\r | |
1207 | //\r | |
1208 | if (Request == NULL) {\r | |
1209 | *Progress = NULL;\r | |
1210 | } else if (StrStr (Request, L"OFFSET") == NULL) {\r | |
1211 | *Progress = Request + StrLen (Request);\r | |
1212 | }\r | |
1213 | \r | |
a6f164a7 | 1214 | return Status;\r |
1215 | }\r | |
1216 | \r | |
1217 | /**\r | |
1218 | This function processes the results of changes in configuration.\r | |
1219 | \r | |
cebc8d48 LG |
1220 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r |
1221 | @param Configuration A null-terminated Unicode string in <ConfigRequest> format.\r | |
1222 | @param Progress A pointer to a string filled in with the offset of the most\r | |
1223 | recent '&' before the first failing name/value pair (or the\r | |
1224 | beginning of the string if the failure is in the first\r | |
1225 | name/value pair) or the terminating NULL if all was successful.\r | |
a6f164a7 | 1226 | \r |
1227 | @retval EFI_SUCCESS The Results is processed successfully.\r | |
1228 | @retval EFI_INVALID_PARAMETER Configuration is NULL.\r | |
1229 | @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.\r | |
1230 | \r | |
1231 | **/\r | |
1232 | EFI_STATUS\r | |
1233 | EFIAPI\r | |
1234 | PlatOverMngrRouteConfig (\r | |
1235 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
1236 | IN CONST EFI_STRING Configuration,\r | |
1237 | OUT EFI_STRING *Progress\r | |
1238 | )\r | |
1239 | {\r | |
1240 | EFI_CALLBACK_INFO *Private;\r | |
a6f164a7 | 1241 | UINT16 KeyValue;\r |
a6f164a7 | 1242 | PLAT_OVER_MNGR_DATA *FakeNvData;\r |
9f25f7dd | 1243 | EFI_STATUS Status;\r |
a6f164a7 | 1244 | \r |
ae79d2f9 LG |
1245 | if (Configuration == NULL || Progress == NULL) {\r |
1246 | return EFI_INVALID_PARAMETER;\r | |
1247 | }\r | |
1248 | *Progress = Configuration;\r | |
1249 | \r | |
c8ad2d7a | 1250 | if (!HiiIsConfigHdrMatch (Configuration, &gPlatformOverridesManagerGuid, mVariableName)) {\r |
ae79d2f9 LG |
1251 | return EFI_NOT_FOUND;\r |
1252 | }\r | |
de482998 LG |
1253 | \r |
1254 | *Progress = Configuration + StrLen (Configuration);\r | |
7e3bcccb | 1255 | Private = EFI_CALLBACK_INFO_FROM_THIS (This);\r |
1d451ff9 | 1256 | FakeNvData = &Private->FakeNvData;\r |
c8ad2d7a | 1257 | if (!HiiGetBrowserData (&gPlatformOverridesManagerGuid, mVariableName, sizeof (PLAT_OVER_MNGR_DATA), (UINT8 *) FakeNvData)) {\r |
de482998 LG |
1258 | //\r |
1259 | // FakeNvData can't be got from SetupBrowser, which doesn't need to be set.\r | |
1260 | //\r | |
1261 | return EFI_SUCCESS;\r | |
a6f164a7 | 1262 | }\r |
1263 | \r | |
9f25f7dd | 1264 | Status = EFI_SUCCESS;\r |
a6f164a7 | 1265 | if (mCurrentPage == FORM_ID_DRIVER) {\r |
1266 | KeyValue = KEY_VALUE_DRIVER_GOTO_ORDER;\r | |
1267 | UpdatePrioritySelectPage (Private, KeyValue, FakeNvData);\r | |
1268 | KeyValue = KEY_VALUE_ORDER_SAVE_AND_EXIT;\r | |
9f25f7dd | 1269 | Status = CommintChanges (Private, KeyValue, FakeNvData);\r |
a6f164a7 | 1270 | //\r |
1271 | // Since UpdatePrioritySelectPage will change mCurrentPage,\r | |
1272 | // should ensure the mCurrentPage still indicate the second page here\r | |
1273 | //\r | |
1274 | mCurrentPage = FORM_ID_DRIVER;\r | |
1275 | }\r | |
1276 | \r | |
1277 | if (mCurrentPage == FORM_ID_ORDER) {\r | |
1278 | KeyValue = KEY_VALUE_ORDER_SAVE_AND_EXIT;\r | |
9f25f7dd | 1279 | Status = CommintChanges (Private, KeyValue, FakeNvData);\r |
a6f164a7 | 1280 | }\r |
7e3bcccb | 1281 | \r |
9f25f7dd | 1282 | return Status;\r |
a6f164a7 | 1283 | }\r |
1284 | \r | |
1285 | /**\r | |
1286 | This is the function that is called to provide results data to the driver. This data\r | |
1287 | consists of a unique key which is used to identify what data is either being passed back\r | |
1288 | or being asked for.\r | |
1289 | \r | |
1290 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
1291 | @param Action A null-terminated Unicode string in <ConfigRequest> format.\r | |
1292 | @param KeyValue A unique Goto OpCode callback value which record user's selection.\r | |
1293 | 0x100 <= KeyValue <0x500 : user select a controller item in the first page;\r | |
1294 | KeyValue == 0x1234 : user select 'Refresh' in first page, or user select 'Go to Previous Menu' in second page\r | |
1295 | KeyValue == 0x1235 : user select 'Pci device filter' in first page\r | |
1296 | KeyValue == 0x1500 : user select 'order ... priority' item in second page\r | |
1297 | KeyValue == 0x1800 : user select 'commint changes' in third page\r | |
1298 | KeyValue == 0x2000 : user select 'Go to Previous Menu' in third page\r | |
1299 | @param Type The type of value for the question.\r | |
1300 | @param Value A pointer to the data being sent to the original exporting driver.\r | |
1301 | @param ActionRequest On return, points to the action requested by the callback function.\r | |
1302 | \r | |
1303 | @retval EFI_SUCCESS Always returned.\r | |
1304 | \r | |
1305 | **/\r | |
1306 | EFI_STATUS\r | |
1307 | EFIAPI\r | |
1308 | PlatOverMngrCallback (\r | |
1309 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
1310 | IN EFI_BROWSER_ACTION Action,\r | |
1311 | IN EFI_QUESTION_ID KeyValue,\r | |
1312 | IN UINT8 Type,\r | |
1313 | IN EFI_IFR_TYPE_VALUE *Value,\r | |
1314 | OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r | |
1315 | )\r | |
1316 | {\r | |
1317 | EFI_CALLBACK_INFO *Private;\r | |
1318 | EFI_STATUS Status;\r | |
1319 | EFI_STRING_ID NewStringToken;\r | |
a6f164a7 | 1320 | EFI_INPUT_KEY Key;\r |
7e3bcccb | 1321 | PLAT_OVER_MNGR_DATA *FakeNvData;\r |
5adb8db7 | 1322 | \r |
3a4e7a3e ED |
1323 | if ((Action != EFI_BROWSER_ACTION_CHANGING) && (Action != EFI_BROWSER_ACTION_CHANGED)) {\r |
1324 | //\r | |
1325 | // All other action return unsupported.\r | |
1326 | //\r | |
1327 | return EFI_UNSUPPORTED;\r | |
1328 | }\r | |
1329 | \r | |
1330 | Private = EFI_CALLBACK_INFO_FROM_THIS (This);\r | |
1331 | FakeNvData = &Private->FakeNvData;\r | |
1332 | if (!HiiGetBrowserData (&gPlatformOverridesManagerGuid, mVariableName, sizeof (PLAT_OVER_MNGR_DATA), (UINT8 *) FakeNvData)) {\r | |
1333 | return EFI_NOT_FOUND;\r | |
1334 | }\r | |
1335 | \r | |
083f7c69 | 1336 | if (Action == EFI_BROWSER_ACTION_CHANGING) {\r |
3a4e7a3e ED |
1337 | if (Value == NULL) {\r |
1338 | return EFI_INVALID_PARAMETER;\r | |
cb7d01c0 | 1339 | }\r |
3a4e7a3e ED |
1340 | \r |
1341 | if (KeyValue == KEY_VALUE_DRIVER_GOTO_PREVIOUS) {\r | |
083f7c69 ED |
1342 | UpdateDeviceSelectPage (Private, KeyValue, FakeNvData);\r |
1343 | //\r | |
1344 | // Update page title string\r | |
1345 | //\r | |
1346 | NewStringToken = STRING_TOKEN (STR_TITLE);\r | |
1347 | if (HiiSetString (Private->RegisteredHandle, NewStringToken, L"First, Select the controller by device path", NULL) == 0) {\r | |
1348 | ASSERT (FALSE);\r | |
1349 | }\r | |
a6f164a7 | 1350 | }\r |
083f7c69 ED |
1351 | \r |
1352 | if (((KeyValue >= KEY_VALUE_DEVICE_OFFSET) && (KeyValue < KEY_VALUE_DEVICE_MAX)) || (KeyValue == KEY_VALUE_ORDER_GOTO_PREVIOUS)) {\r | |
1353 | if (KeyValue == KEY_VALUE_ORDER_GOTO_PREVIOUS) {\r | |
1354 | KeyValue = (EFI_QUESTION_ID) (mSelectedCtrIndex + KEY_VALUE_DEVICE_OFFSET);\r | |
1355 | }\r | |
1356 | UpdateBindingDriverSelectPage (Private, KeyValue, FakeNvData);\r | |
1357 | //\r | |
1358 | // Update page title string\r | |
1359 | //\r | |
1360 | NewStringToken = STRING_TOKEN (STR_TITLE);\r | |
1361 | if (HiiSetString (Private->RegisteredHandle, NewStringToken, L"Second, Select drivers for the previous selected controller", NULL) == 0) {\r | |
1362 | ASSERT (FALSE);\r | |
1363 | }\r | |
cb7d01c0 | 1364 | }\r |
a6f164a7 | 1365 | \r |
083f7c69 ED |
1366 | if (KeyValue == KEY_VALUE_DRIVER_GOTO_ORDER) {\r |
1367 | UpdatePrioritySelectPage (Private, KeyValue, FakeNvData);\r | |
1368 | //\r | |
1369 | // Update page title string\r | |
1370 | //\r | |
1371 | NewStringToken = STRING_TOKEN (STR_TITLE);\r | |
1372 | if (HiiSetString (Private->RegisteredHandle, NewStringToken, L"Finally, Set the priority order for the drivers and save them", NULL) == 0) {\r | |
1373 | ASSERT (FALSE);\r | |
1374 | }\r | |
cb7d01c0 | 1375 | }\r |
a6f164a7 | 1376 | \r |
083f7c69 ED |
1377 | if (KeyValue == KEY_VALUE_DEVICE_CLEAR) {\r |
1378 | //\r | |
1379 | // Deletes all environment variable(s) that contain the override mappings info\r | |
1380 | //\r | |
1381 | FreeMappingDatabase (&mMappingDataBase);\r | |
1382 | Status = SaveOverridesMapping (&mMappingDataBase);\r | |
1383 | UpdateDeviceSelectPage (Private, KeyValue, FakeNvData);\r | |
1384 | }\r | |
3a4e7a3e ED |
1385 | } else if (Action == EFI_BROWSER_ACTION_CHANGED) {\r |
1386 | switch (KeyValue) {\r | |
1387 | case KEY_VALUE_DEVICE_REFRESH:\r | |
1388 | case KEY_VALUE_DEVICE_FILTER:\r | |
1389 | UpdateDeviceSelectPage (Private, KeyValue, FakeNvData);\r | |
1390 | //\r | |
1391 | // Update page title string\r | |
1392 | //\r | |
1393 | NewStringToken = STRING_TOKEN (STR_TITLE);\r | |
1394 | if (HiiSetString (Private->RegisteredHandle, NewStringToken, L"First, Select the controller by device path", NULL) == 0) {\r | |
1395 | ASSERT (FALSE);\r | |
1396 | }\r | |
1397 | break;\r | |
1398 | \r | |
1399 | case KEY_VALUE_ORDER_SAVE_AND_EXIT:\r | |
1400 | Status = CommintChanges (Private, KeyValue, FakeNvData);\r | |
1401 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;\r | |
1402 | if (EFI_ERROR (Status)) {\r | |
1403 | CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Single Override Info too large, Saving Error!", NULL);\r | |
1404 | return EFI_DEVICE_ERROR;\r | |
1405 | }\r | |
1406 | break;\r | |
083f7c69 | 1407 | \r |
3a4e7a3e ED |
1408 | default:\r |
1409 | break;\r | |
1410 | }\r | |
1411 | }\r | |
083f7c69 | 1412 | \r |
a6f164a7 | 1413 | //\r |
3a4e7a3e | 1414 | // Pass changed uncommitted data back to Form Browser\r |
a6f164a7 | 1415 | //\r |
3a4e7a3e ED |
1416 | HiiSetBrowserData (&gPlatformOverridesManagerGuid, mVariableName, sizeof (PLAT_OVER_MNGR_DATA), (UINT8 *) FakeNvData, NULL);\r |
1417 | \r | |
1418 | return EFI_SUCCESS;\r | |
a6f164a7 | 1419 | }\r |
1420 | \r | |
6d8ced29 LG |
1421 | /**\r |
1422 | Retrieves the image handle of the platform override driver for a controller in the system.\r | |
1423 | \r | |
1424 | @param This A pointer to the\r | |
1425 | EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL instance.\r | |
1426 | @param ControllerHandle The device handle of the controller to check if a\r | |
1427 | driver override exists.\r | |
1428 | @param DriverImageHandle On input, a pointer to the previous driver image\r | |
1429 | handle returned by GetDriver(). On output, a\r | |
1430 | pointer to the next driver image handle. Passing\r | |
1431 | in a NULL, will return the first driver image\r | |
1432 | handle for ControllerHandle.\r | |
1433 | \r | |
1434 | @retval EFI_SUCCESS The driver override for ControllerHandle was\r | |
1435 | returned in DriverImageHandle.\r | |
1436 | @retval EFI_NOT_FOUND A driver override for ControllerHandle was not\r | |
1437 | found.\r | |
284ee2e8 RN |
1438 | @retval EFI_INVALID_PARAMETER The handle specified by ControllerHandle is NULL.\r |
1439 | DriverImageHandle is not a handle that was returned\r | |
1440 | on a previous call to GetDriver().\r | |
6d8ced29 LG |
1441 | \r |
1442 | **/\r | |
1443 | EFI_STATUS\r | |
1444 | EFIAPI\r | |
1445 | GetDriver (\r | |
1446 | IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL *This,\r | |
1447 | IN EFI_HANDLE ControllerHandle,\r | |
1448 | IN OUT EFI_HANDLE *DriverImageHandle\r | |
1449 | )\r | |
1450 | {\r | |
1451 | EFI_STATUS Status;\r | |
1452 | \r | |
1453 | //\r | |
1454 | // Check that ControllerHandle is a valid handle\r | |
1455 | //\r | |
1456 | if (ControllerHandle == NULL) {\r | |
1457 | return EFI_INVALID_PARAMETER;\r | |
1458 | }\r | |
1459 | \r | |
1460 | //\r | |
1461 | // Read the environment variable(s) that contain the override mappings from Controller Device Path to\r | |
1462 | // a set of Driver Device Paths, and initialize in memory database of the overrides that map Controller\r | |
1463 | // Device Paths to an ordered set of Driver Device Paths and Driver Handles. This action is only performed\r | |
1464 | // once and finished in first call.\r | |
1465 | //\r | |
1466 | if (!mEnvironmentVariableRead) {\r | |
1467 | mEnvironmentVariableRead = TRUE;\r | |
1468 | \r | |
1469 | Status = InitOverridesMapping (&mMappingDataBase);\r | |
1470 | if (EFI_ERROR (Status)){\r | |
1471 | DEBUG ((DEBUG_ERROR, "The status to Get Platform Driver Override Variable is %r\n", Status));\r | |
1472 | InitializeListHead (&mMappingDataBase);\r | |
1473 | return EFI_NOT_FOUND;\r | |
1474 | }\r | |
1475 | }\r | |
1476 | \r | |
1477 | //\r | |
1478 | // if the environment variable does not exist, just return not found\r | |
1479 | //\r | |
1480 | if (IsListEmpty (&mMappingDataBase)) {\r | |
1481 | return EFI_NOT_FOUND;\r | |
1482 | }\r | |
1483 | \r | |
1484 | return GetDriverFromMapping (\r | |
1485 | ControllerHandle,\r | |
1486 | DriverImageHandle,\r | |
1487 | &mMappingDataBase,\r | |
1488 | mCallerImageHandle\r | |
1489 | );\r | |
1490 | }\r | |
1491 | \r | |
1492 | /**\r | |
1493 | Retrieves the device path of the platform override driver for a controller in the system.\r | |
1494 | This driver doesn't support this API.\r | |
1495 | \r | |
1496 | @param This A pointer to the EFI_PLATFORM_DRIVER_OVERRIDE_\r | |
1497 | PROTOCOL instance. \r | |
1498 | @param ControllerHandle The device handle of the controller to check if a driver override\r | |
1499 | exists. \r | |
1500 | @param DriverImagePath On input, a pointer to the previous driver device path returned by\r | |
1501 | GetDriverPath(). On output, a pointer to the next driver\r | |
1502 | device path. Passing in a pointer to NULL, will return the first\r | |
1503 | driver device path for ControllerHandle.\r | |
1504 | \r | |
1505 | @retval EFI_UNSUPPORTED\r | |
1506 | **/\r | |
1507 | EFI_STATUS\r | |
1508 | EFIAPI\r | |
1509 | GetDriverPath (\r | |
1510 | IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL *This,\r | |
1511 | IN EFI_HANDLE ControllerHandle,\r | |
1512 | IN OUT EFI_DEVICE_PATH_PROTOCOL **DriverImagePath\r | |
1513 | )\r | |
1514 | {\r | |
1515 | return EFI_UNSUPPORTED;\r | |
1516 | }\r | |
1517 | \r | |
1518 | \r | |
1519 | /**\r | |
1520 | Used to associate a driver image handle with a device path that was returned on a prior call to the\r | |
1521 | GetDriverPath() service. This driver image handle will then be available through the \r | |
1522 | GetDriver() service. This driver doesn't support this API.\r | |
1523 | \r | |
1524 | @param This A pointer to the EFI_PLATFORM_DRIVER_OVERRIDE_\r | |
1525 | PROTOCOL instance. \r | |
1526 | @param ControllerHandle The device handle of the controller. \r | |
1527 | @param DriverImagePath A pointer to the driver device path that was returned in a prior\r | |
1528 | call to GetDriverPath(). \r | |
1529 | @param DriverImageHandle The driver image handle that was returned by LoadImage()\r | |
1530 | when the driver specified by DriverImagePath was loaded \r | |
1531 | into memory. \r | |
1532 | \r | |
1533 | @retval EFI_UNSUPPORTED\r | |
1534 | **/\r | |
1535 | EFI_STATUS\r | |
1536 | EFIAPI\r | |
1537 | DriverLoaded (\r | |
1538 | IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL *This,\r | |
1539 | IN EFI_HANDLE ControllerHandle,\r | |
1540 | IN EFI_DEVICE_PATH_PROTOCOL *DriverImagePath,\r | |
1541 | IN EFI_HANDLE DriverImageHandle\r | |
1542 | )\r | |
1543 | {\r | |
1544 | return EFI_UNSUPPORTED;\r | |
1545 | }\r | |
1546 | \r | |
a6f164a7 | 1547 | /**\r |
68dbca6c LG |
1548 | The driver Entry Point. The funciton will export a disk device class formset and\r |
1549 | its callback function to hii database.\r | |
a6f164a7 | 1550 | \r |
68dbca6c LG |
1551 | @param ImageHandle The firmware allocated handle for the EFI image.\r |
1552 | @param SystemTable A pointer to the EFI System Table.\r | |
a6f164a7 | 1553 | \r |
68dbca6c LG |
1554 | @retval EFI_SUCCESS The entry point is executed successfully.\r |
1555 | @retval other Some error occurs when executing this entry point.\r | |
a6f164a7 | 1556 | \r |
1557 | **/\r | |
68dbca6c LG |
1558 | EFI_STATUS\r |
1559 | EFIAPI\r | |
6d8ced29 | 1560 | PlatDriOverrideDxeInit (\r |
68dbca6c LG |
1561 | IN EFI_HANDLE ImageHandle,\r |
1562 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
a6f164a7 | 1563 | )\r |
1564 | {\r | |
68dbca6c | 1565 | EFI_STATUS Status;\r |
f6f910dd | 1566 | EFI_FORM_BROWSER2_PROTOCOL *FormBrowser2;\r |
6d8ced29 | 1567 | VOID *Instance;\r |
e5618791 | 1568 | \r |
68dbca6c LG |
1569 | //\r |
1570 | // There should only be one Form Configuration protocol\r | |
1571 | //\r | |
a6f164a7 | 1572 | Status = gBS->LocateProtocol (\r |
68dbca6c LG |
1573 | &gEfiFormBrowser2ProtocolGuid,\r |
1574 | NULL,\r | |
1575 | (VOID **) &FormBrowser2\r | |
1576 | );\r | |
1577 | if (EFI_ERROR (Status)) {\r | |
1578 | return Status;\r | |
1579 | }\r | |
1580 | \r | |
6d8ced29 LG |
1581 | //\r |
1582 | // According to UEFI spec, there can be at most a single instance\r | |
1583 | // in the system of the EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL.\r | |
1584 | // So here we check the existence.\r | |
1585 | //\r | |
1586 | Status = gBS->LocateProtocol (\r | |
1587 | &gEfiPlatformDriverOverrideProtocolGuid,\r | |
1588 | NULL,\r | |
1589 | &Instance\r | |
1590 | );\r | |
1591 | //\r | |
1592 | // If there was no error, assume there is an installation and return error\r | |
1593 | //\r | |
1594 | if (!EFI_ERROR (Status)) {\r | |
1595 | return EFI_ALREADY_STARTED;\r | |
1596 | }\r | |
1597 | \r | |
1598 | mCallerImageHandle = ImageHandle;\r | |
7e3bcccb LG |
1599 | mCallbackInfo = AllocateZeroPool (sizeof (EFI_CALLBACK_INFO));\r |
1600 | if (mCallbackInfo == NULL) {\r | |
68dbca6c LG |
1601 | return EFI_BAD_BUFFER_SIZE;\r |
1602 | }\r | |
1603 | \r | |
7e3bcccb LG |
1604 | mCallbackInfo->Signature = EFI_CALLBACK_INFO_SIGNATURE;\r |
1605 | mCallbackInfo->ConfigAccess.ExtractConfig = PlatOverMngrExtractConfig;\r | |
1606 | mCallbackInfo->ConfigAccess.RouteConfig = PlatOverMngrRouteConfig;\r | |
1607 | mCallbackInfo->ConfigAccess.Callback = PlatOverMngrCallback;\r | |
6d8ced29 LG |
1608 | mCallbackInfo->PlatformDriverOverride.GetDriver = GetDriver;\r |
1609 | mCallbackInfo->PlatformDriverOverride.GetDriverPath = GetDriverPath;\r | |
1610 | mCallbackInfo->PlatformDriverOverride.DriverLoaded = DriverLoaded;\r | |
68dbca6c | 1611 | //\r |
f6f910dd | 1612 | // Install Device Path Protocol and Config Access protocol to driver handle\r |
6d8ced29 | 1613 | // Install Platform Driver Override Protocol to driver handle\r |
68dbca6c | 1614 | //\r |
f6f910dd | 1615 | Status = gBS->InstallMultipleProtocolInterfaces (\r |
7e3bcccb | 1616 | &mCallbackInfo->DriverHandle,\r |
f6f910dd | 1617 | &gEfiDevicePathProtocolGuid,\r |
1618 | &mHiiVendorDevicePath,\r | |
68dbca6c | 1619 | &gEfiHiiConfigAccessProtocolGuid,\r |
7e3bcccb | 1620 | &mCallbackInfo->ConfigAccess,\r |
6d8ced29 LG |
1621 | &gEfiPlatformDriverOverrideProtocolGuid,\r |
1622 | &mCallbackInfo->PlatformDriverOverride,\r | |
f6f910dd | 1623 | NULL\r |
68dbca6c LG |
1624 | );\r |
1625 | if (EFI_ERROR (Status)) {\r | |
e5618791 | 1626 | goto Finish;\r |
68dbca6c LG |
1627 | }\r |
1628 | \r | |
1629 | //\r | |
1630 | // Publish our HII data\r | |
1631 | //\r | |
cb7d01c0 | 1632 | mCallbackInfo->RegisteredHandle = HiiAddPackages (\r |
c8ad2d7a | 1633 | &gPlatformOverridesManagerGuid,\r |
cb7d01c0 | 1634 | mCallbackInfo->DriverHandle,\r |
1635 | VfrBin,\r | |
6d8ced29 | 1636 | PlatDriOverrideDxeStrings,\r |
cb7d01c0 | 1637 | NULL\r |
1638 | );\r | |
1639 | if (mCallbackInfo->RegisteredHandle == NULL) {\r | |
1640 | Status = EFI_OUT_OF_RESOURCES;\r | |
e5618791 LG |
1641 | goto Finish;\r |
1642 | }\r | |
1643 | \r | |
68dbca6c LG |
1644 | //\r |
1645 | // Locate ConfigRouting protocol\r | |
1646 | //\r | |
1647 | Status = gBS->LocateProtocol (\r | |
1648 | &gEfiHiiConfigRoutingProtocolGuid,\r | |
a6f164a7 | 1649 | NULL,\r |
7e3bcccb | 1650 | (VOID **) &mCallbackInfo->HiiConfigRouting\r |
a6f164a7 | 1651 | );\r |
68dbca6c | 1652 | if (EFI_ERROR (Status)) {\r |
e5618791 | 1653 | goto Finish;\r |
68dbca6c LG |
1654 | }\r |
1655 | \r | |
1656 | //\r | |
1657 | // Clear all the globle variable\r | |
1658 | //\r | |
1659 | mDriverImageHandleCount = 0;\r | |
1660 | mCurrentPage = 0;\r | |
1661 | ZeroMem (mDriverImageToken, MAX_CHOICE_NUM * sizeof (EFI_STRING_ID));\r | |
1662 | ZeroMem (mDriverImageFilePathToken, MAX_CHOICE_NUM * sizeof (EFI_STRING_ID));\r | |
1663 | ZeroMem (mControllerToken, MAX_CHOICE_NUM * sizeof (EFI_STRING_ID));\r | |
1664 | ZeroMem (mDriverImageProtocol, MAX_CHOICE_NUM * sizeof (EFI_LOADED_IMAGE_PROTOCOL *));\r | |
6d8ced29 LG |
1665 | \r |
1666 | return EFI_SUCCESS;\r | |
e5618791 LG |
1667 | \r |
1668 | Finish:\r | |
f0c855b2 | 1669 | PlatDriOverrideDxeUnload (ImageHandle);\r |
e5618791 LG |
1670 | \r |
1671 | return Status;\r | |
a6f164a7 | 1672 | }\r |
87fbccbe | 1673 | \r |
1674 | /**\r | |
6d8ced29 LG |
1675 | Unload its installed protocol.\r |
1676 | \r | |
1677 | @param[in] ImageHandle Handle that identifies the image to be unloaded.\r | |
1678 | \r | |
1679 | @retval EFI_SUCCESS The image has been unloaded.\r | |
87fbccbe | 1680 | **/\r |
6d8ced29 LG |
1681 | EFI_STATUS\r |
1682 | EFIAPI\r | |
1683 | PlatDriOverrideDxeUnload (\r | |
1684 | IN EFI_HANDLE ImageHandle\r | |
87fbccbe | 1685 | )\r |
1686 | {\r | |
f0c855b2 | 1687 | ASSERT (mCallbackInfo != NULL);\r |
1688 | \r | |
6d8ced29 LG |
1689 | if (mCallbackInfo->DriverHandle != NULL) {\r |
1690 | gBS->UninstallMultipleProtocolInterfaces (\r | |
1691 | mCallbackInfo->DriverHandle,\r | |
1692 | &gEfiDevicePathProtocolGuid,\r | |
1693 | &mHiiVendorDevicePath,\r | |
1694 | &gEfiHiiConfigAccessProtocolGuid,\r | |
1695 | &mCallbackInfo->ConfigAccess,\r | |
1696 | &gEfiPlatformDriverOverrideProtocolGuid,\r | |
1697 | &mCallbackInfo->PlatformDriverOverride,\r | |
1698 | NULL\r | |
1699 | );\r | |
87fbccbe | 1700 | }\r |
6d8ced29 LG |
1701 | \r |
1702 | if (mCallbackInfo->RegisteredHandle != NULL) {\r | |
1703 | HiiRemovePackages (mCallbackInfo->RegisteredHandle);\r | |
87fbccbe | 1704 | }\r |
1705 | \r | |
f0c855b2 | 1706 | FreePool (mCallbackInfo);\r |
6d8ced29 LG |
1707 | \r |
1708 | return EFI_SUCCESS;\r | |
87fbccbe | 1709 | }\r |