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