2 This file also installs UEFI PLATFORM_DRIVER_OVERRIDE_PROTOCOL.
4 The main code offers a UI interface in device manager to let user configure
5 platform override protocol to override the default algorithm for matching
6 drivers to controllers.
9 1. It dynamicly locate all controller device path.
10 2. It dynamicly locate all drivers which support binding protocol.
11 3. It export and dynamicly update two menu to let user select the
12 mapping between drivers to controllers.
13 4. It save all the mapping info in NV variables which will be consumed
14 by platform override protocol driver to publish the platform override protocol.
16 Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
17 SPDX-License-Identifier: BSD-2-Clause-Patent
21 #include "InternalPlatDriOverrideDxe.h"
22 #include "PlatOverMngr.h"
24 #define EFI_CALLBACK_INFO_SIGNATURE SIGNATURE_32 ('C', 'l', 'b', 'k')
25 #define EFI_CALLBACK_INFO_FROM_THIS(a) CR (a, EFI_CALLBACK_INFO, ConfigAccess, EFI_CALLBACK_INFO_SIGNATURE)
29 EFI_HANDLE DriverHandle
;
30 EFI_HII_HANDLE RegisteredHandle
;
31 PLAT_OVER_MNGR_DATA FakeNvData
;
32 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
33 EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess
;
34 EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL PlatformDriverOverride
;
40 /// HII specific Vendor Device Path definition.
43 VENDOR_DEVICE_PATH VendorDevicePath
;
44 EFI_DEVICE_PATH_PROTOCOL End
;
45 } HII_VENDOR_DEVICE_PATH
;
50 // uni string and Vfr Binary data.
52 extern UINT8 VfrBin
[];
53 extern UINT8 PlatDriOverrideDxeStrings
[];
58 CHAR16 mVariableName
[] = L
"Data";
59 LIST_ENTRY mMappingDataBase
= INITIALIZE_LIST_HEAD_VARIABLE (mMappingDataBase
);
60 BOOLEAN mEnvironmentVariableRead
= FALSE
;
61 EFI_HANDLE mCallerImageHandle
= NULL
;
63 EFI_HANDLE
*mDevicePathHandleBuffer
;
64 EFI_HANDLE
*mDriverImageHandleBuffer
;
66 INTN mSelectedCtrIndex
;
67 EFI_STRING_ID
*mControllerToken
;
68 UINTN mDriverImageHandleCount
;
69 EFI_STRING_ID
*mDriverImageToken
;
70 EFI_DEVICE_PATH_PROTOCOL
**mControllerDevicePathProtocol
;
71 UINTN mSelectedDriverImageNum
;
72 UINTN mLastSavedDriverImageNum
;
74 EFI_CALLBACK_INFO
*mCallbackInfo
;
75 BOOLEAN
*mDriSelection
;
76 UINTN mMaxDeviceCount
;
78 HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath
= {
84 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
85 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
92 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
94 (UINT8
) (END_DEVICE_PATH_LENGTH
),
95 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
101 Converting a given device to an unicode string.
103 @param DevPath Given device path instance
105 @return Converted string from given device path.
106 @retval L"?" Converting failed.
110 IN EFI_DEVICE_PATH_PROTOCOL
*DevPath
114 Text
= ConvertDevicePathToText (
120 Text
= AllocateCopyPool (sizeof (L
"?"), L
"?");
121 ASSERT (Text
!= NULL
);
128 Worker function to get the driver name by ComponentName or ComponentName2 protocol
129 according to the driver binding handle.
131 @param DriverBindingHandle The Handle of DriverBinding.
132 @param ProtocolGuid The pointer to Component Name (2) protocol GUID.
133 @param VariableName The name of the RFC 4646 or ISO 639-2 language variable.
135 @retval !NULL Pointer into the image name if the image name is found,
136 @retval NULL Pointer to NULL if the image name is not found.
140 GetComponentNameWorker (
141 IN EFI_HANDLE DriverBindingHandle
,
142 IN EFI_GUID
*ProtocolGuid
,
143 IN CONST CHAR16
*VariableName
147 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
152 Status
= gBS
->OpenProtocol (
155 (VOID
*) &ComponentName
,
158 EFI_OPEN_PROTOCOL_GET_PROTOCOL
160 if (EFI_ERROR (Status
)) {
165 // Find the best matching language.
167 GetEfiGlobalVariable2 (VariableName
, (VOID
**)&Language
, NULL
);
168 BestLanguage
= GetBestLanguage (
169 ComponentName
->SupportedLanguages
,
170 (BOOLEAN
) (ProtocolGuid
== &gEfiComponentNameProtocolGuid
),
176 if (BestLanguage
!= NULL
) {
177 ComponentName
->GetDriverName (
182 FreePool (BestLanguage
);
185 if (Language
!= NULL
) {
194 Get the driver name by ComponentName or ComponentName2 protocol
195 according to the driver binding handle
197 @param DriverBindingHandle The Handle of DriverBinding.
199 @retval !NULL Pointer into the image name if the image name is found,
200 @retval NULL Pointer to NULL if the image name is not found.
205 IN EFI_HANDLE DriverBindingHandle
211 // Try RFC 4646 Component Name 2 protocol first.
213 DriverName
= GetComponentNameWorker (DriverBindingHandle
, &gEfiComponentName2ProtocolGuid
, L
"PlatformLang");
214 if (DriverName
== NULL
) {
216 // If we can not get driver name from Component Name 2 protocol, we can try ISO 639-2 Component Name protocol.
218 DriverName
= GetComponentNameWorker (DriverBindingHandle
, &gEfiComponentNameProtocolGuid
, L
"Lang");
225 Get the image name from EFI UI section.
226 Get FV protocol by its loaded image protocol to abstract EFI UI section.
228 @param Image Pointer to the loaded image protocol
230 @retval !NULL Pointer to the image name if the image name is found,
231 @retval NULL NULL if the image name is not found.
236 IN EFI_LOADED_IMAGE_PROTOCOL
*Image
240 EFI_DEVICE_PATH_PROTOCOL
*DevPathNode
;
241 EFI_DEVICE_PATH_PROTOCOL
*AlignedDevPathNode
;
242 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*FvFilePath
;
245 UINT32 AuthenticationStatus
;
247 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv2
;
253 if (Image
->FilePath
== NULL
) {
256 DevPathNode
= Image
->FilePath
;
258 while (!IsDevicePathEnd (DevPathNode
)) {
260 // Make sure device path node is aligned when accessing it's FV Name Guid field.
262 AlignedDevPathNode
= AllocateCopyPool (DevicePathNodeLength(DevPathNode
), DevPathNode
);
265 // Find the Fv File path
267 NameGuid
= EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*)AlignedDevPathNode
);
268 if (NameGuid
!= NULL
) {
269 FvFilePath
= (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*) AlignedDevPathNode
;
270 Status
= gBS
->HandleProtocol (
272 &gEfiFirmwareVolume2ProtocolGuid
,
276 // Locate Image EFI UI section to get the image name.
278 if (!EFI_ERROR (Status
)) {
279 Status
= Fv2
->ReadSection (
281 &FvFilePath
->FvFileName
,
282 EFI_SECTION_USER_INTERFACE
,
286 &AuthenticationStatus
288 if (!EFI_ERROR (Status
)) {
289 FreePool (AlignedDevPathNode
);
296 FreePool (AlignedDevPathNode
);
299 // Next device path node
301 DevPathNode
= NextDevicePathNode (DevPathNode
);
308 Prepare the first page to let user select the device controller which need to
309 add mapping drivers if user select 'Refresh' in first page.
310 During first page, user will see all currnet controller device path in system,
311 select any device path will go to second page to select its overrides drivers.
313 @param Private Pointer to EFI_CALLBACK_INFO.
314 @param KeyValue The callback key value of device controller item in first page.
315 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
317 @retval EFI_SUCCESS Always returned.
321 UpdateDeviceSelectPage (
322 IN EFI_CALLBACK_INFO
*Private
,
324 IN PLAT_OVER_MNGR_DATA
*FakeNvData
329 UINTN DevicePathHandleCount
;
332 EFI_STRING_ID NewStringToken
;
333 CHAR16
*ControllerName
;
334 EFI_DEVICE_PATH_PROTOCOL
*ControllerDevicePath
;
335 EFI_PCI_IO_PROTOCOL
*PciIo
;
336 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*BusSpecificDriverOverride
;
338 VOID
*StartOpCodeHandle
;
339 VOID
*EndOpCodeHandle
;
340 EFI_IFR_GUID_LABEL
*StartLabel
;
341 EFI_IFR_GUID_LABEL
*EndLabel
;
344 // Set current page form ID.
346 mCurrentPage
= FORM_ID_DEVICE
;
349 // Initial the mapping database in memory
351 FreeMappingDatabase (&mMappingDataBase
);
352 InitOverridesMapping (&mMappingDataBase
);
355 // Init OpCode Handle
357 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
358 ASSERT (StartOpCodeHandle
!= NULL
);
360 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
361 ASSERT (EndOpCodeHandle
!= NULL
);
364 // Create Hii Extend Label OpCode as the start opcode
366 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
367 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
368 StartLabel
->Number
= FORM_ID_DEVICE
;
371 // Create Hii Extend Label OpCode as the end opcode
373 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
374 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
375 EndLabel
->Number
= LABEL_END
;
378 // Clear first page form
381 Private
->RegisteredHandle
,
382 &gPlatformOverridesManagerGuid
,
384 StartOpCodeHandle
, // Label FORM_ID_DEVICE
385 EndOpCodeHandle
// LABEL_END
389 // When user enter the page at first time, the 'first refresh' string is given to notify user to refresh all the drivers,
390 // then the 'first refresh' string will be replaced by the 'refresh' string, and the two strings content are same after the replacement
392 NewStringToken
= STRING_TOKEN (STR_FIRST_REFRESH
);
393 NewString
= HiiGetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_REFRESH
), NULL
);
394 ASSERT (NewString
!= NULL
);
395 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
, NULL
) == 0) {
398 FreePool (NewString
);
400 NewStringToken
= STRING_TOKEN (STR_FIRST_REFRESH_HELP
);
401 NewString
= HiiGetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_REFRESH_HELP
), NULL
);
402 ASSERT (NewString
!= NULL
);
403 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
, NULL
) == 0) {
406 FreePool (NewString
);
409 // created needed controller device item in first page
411 DevicePathHandleCount
= 0;
412 Status
= gBS
->LocateHandleBuffer (
414 &gEfiDevicePathProtocolGuid
,
416 &DevicePathHandleCount
,
417 &mDevicePathHandleBuffer
419 if (EFI_ERROR (Status
) || (DevicePathHandleCount
== 0)) {
423 mMaxDeviceCount
= DevicePathHandleCount
;
424 mControllerDevicePathProtocol
= AllocateZeroPool (DevicePathHandleCount
* sizeof (EFI_DEVICE_PATH_PROTOCOL
*));
425 ASSERT (mControllerDevicePathProtocol
!= NULL
);
426 mControllerToken
= AllocateZeroPool (DevicePathHandleCount
* sizeof (EFI_STRING_ID
));
427 ASSERT (mControllerToken
!= NULL
);
429 for (Index
= 0; Index
< DevicePathHandleCount
; Index
++) {
430 if (FakeNvData
->PciDeviceFilter
== 0x01) {
432 // Only care PCI device which contain efi driver in its option rom.
436 // Check whether it is a pci device
438 ControllerDevicePath
= NULL
;
439 Status
= gBS
->OpenProtocol (
440 mDevicePathHandleBuffer
[Index
],
441 &gEfiPciIoProtocolGuid
,
445 EFI_OPEN_PROTOCOL_GET_PROTOCOL
447 if (EFI_ERROR (Status
)) {
451 // Check whether it contain efi driver in its option rom
453 Status
= gBS
->HandleProtocol(
454 mDevicePathHandleBuffer
[Index
],
455 &gEfiBusSpecificDriverOverrideProtocolGuid
,
456 (VOID
**) &BusSpecificDriverOverride
458 if (EFI_ERROR (Status
) || BusSpecificDriverOverride
== NULL
) {
463 ControllerDevicePath
= NULL
;
464 Status
= gBS
->OpenProtocol (
465 mDevicePathHandleBuffer
[Index
],
466 &gEfiDevicePathProtocolGuid
,
467 (VOID
**) &ControllerDevicePath
,
470 EFI_OPEN_PROTOCOL_GET_PROTOCOL
472 ASSERT_EFI_ERROR (Status
);
474 // Save the device path protocol interface
476 mControllerDevicePathProtocol
[Index
] = ControllerDevicePath
;
479 // Get the driver name
481 ControllerName
= DevicePathToStr (ControllerDevicePath
);
484 // Export the driver name string and create item in set options page
486 Len
= StrSize (ControllerName
);
487 NewStrSize
= Len
+ StrSize (L
"--");
488 NewString
= AllocateZeroPool (NewStrSize
);
489 ASSERT (NewString
!= NULL
);
490 if (EFI_ERROR (CheckMapping (ControllerDevicePath
,NULL
, &mMappingDataBase
, NULL
, NULL
))) {
491 StrCatS (NewString
, NewStrSize
/sizeof(CHAR16
), L
"--");
493 StrCatS (NewString
, NewStrSize
/sizeof(CHAR16
), L
"**");
495 StrCatS (NewString
, NewStrSize
/sizeof(CHAR16
), ControllerName
);
497 NewStringToken
= HiiSetString (Private
->RegisteredHandle
, mControllerToken
[Index
], NewString
, NULL
);
498 ASSERT (NewStringToken
!= 0);
499 FreePool (NewString
);
501 // Save the device path string toke for next access use
503 mControllerToken
[Index
] = NewStringToken
;
505 HiiCreateGotoOpCode (
509 STRING_TOKEN (STR_GOTO_HELP_DRIVER
),
510 EFI_IFR_FLAG_CALLBACK
,
511 (UINT16
) (Index
+ KEY_VALUE_DEVICE_OFFSET
)
516 // Update first page form
519 Private
->RegisteredHandle
,
520 &gPlatformOverridesManagerGuid
,
522 StartOpCodeHandle
, // Label FORM_ID_DEVICE
523 EndOpCodeHandle
// LABEL_END
526 HiiFreeOpCodeHandle (StartOpCodeHandle
);
527 HiiFreeOpCodeHandle (EndOpCodeHandle
);
533 Get the first Driver Binding handle which has the specific image handle.
535 @param ImageHandle The Image handle
537 @return Handle to Driver binding
538 @retval NULL The parameter is not valid or the driver binding handle is not found.
542 GetDriverBindingHandleFromImageHandle (
543 IN EFI_HANDLE ImageHandle
548 UINTN DriverBindingHandleCount
;
549 EFI_HANDLE
*DriverBindingHandleBuffer
;
550 EFI_DRIVER_BINDING_PROTOCOL
*DriverBindingInterface
;
551 EFI_HANDLE DriverBindingHandle
;
553 DriverBindingHandle
= NULL
;
555 if (ImageHandle
== NULL
) {
559 // Get all drivers which support driver binding protocol
561 DriverBindingHandleCount
= 0;
562 Status
= gBS
->LocateHandleBuffer (
564 &gEfiDriverBindingProtocolGuid
,
566 &DriverBindingHandleCount
,
567 &DriverBindingHandleBuffer
569 if (EFI_ERROR (Status
) || (DriverBindingHandleCount
== 0)) {
574 // Get the first Driver Binding handle which has the specific image handle.
576 for (Index
= 0; Index
< DriverBindingHandleCount
; Index
++) {
577 DriverBindingInterface
= NULL
;
578 Status
= gBS
->OpenProtocol (
579 DriverBindingHandleBuffer
[Index
],
580 &gEfiDriverBindingProtocolGuid
,
581 (VOID
**) &DriverBindingInterface
,
584 EFI_OPEN_PROTOCOL_GET_PROTOCOL
586 if (EFI_ERROR (Status
)) {
590 if (DriverBindingInterface
->ImageHandle
== ImageHandle
) {
591 DriverBindingHandle
= DriverBindingHandleBuffer
[Index
];
596 FreePool (DriverBindingHandleBuffer
);
597 return DriverBindingHandle
;
601 Prepare to let user select the drivers which need mapping with the device controller
602 selected in first page.
604 @param Private Pointer to EFI_CALLBACK_INFO.
605 @param KeyValue The callback key value of device controller item in first page.
606 KeyValue is larger than or equal to KEY_VALUE_DEVICE_OFFSET.
607 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
609 @retval EFI_SUCCESS Always returned.
613 UpdateBindingDriverSelectPage (
614 IN EFI_CALLBACK_INFO
*Private
,
616 IN PLAT_OVER_MNGR_DATA
*FakeNvData
623 EFI_STRING_ID NewStringToken
;
624 EFI_STRING_ID NewStringHelpToken
;
625 UINTN DriverImageHandleCount
;
626 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
628 BOOLEAN FreeDriverName
;
629 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
630 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*BusSpecificDriverOverride
;
631 EFI_HANDLE DriverBindingHandle
;
632 VOID
*StartOpCodeHandle
;
633 VOID
*EndOpCodeHandle
;
634 EFI_IFR_GUID_LABEL
*StartLabel
;
635 EFI_IFR_GUID_LABEL
*EndLabel
;
636 EFI_LOADED_IMAGE_PROTOCOL
**DriverImageProtocol
;
637 EFI_STRING_ID
*DriverImageFilePathToken
;
641 // If user select a controller item in the first page the following code will be run.
642 // During second page, user will see all currnet driver bind protocol driver, the driver name and its device path will be shown
644 //First acquire the list of Loaded Image Protocols, and then when want the name of the driver, look up all the Driver Binding Protocols
645 // and find the first one whose ImageHandle field matches the image handle of the Loaded Image Protocol.
646 // 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.
649 mCurrentPage
= FORM_ID_DRIVER
;
651 // Switch the item callback key value to its NO. in mDevicePathHandleBuffer
653 mSelectedCtrIndex
= KeyValue
- KEY_VALUE_DEVICE_OFFSET
;
654 ASSERT (mSelectedCtrIndex
>= 0 && mSelectedCtrIndex
< MAX_CHOICE_NUM
);
656 mLastSavedDriverImageNum
= 0;
659 // Init OpCode Handle
661 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
662 ASSERT (StartOpCodeHandle
!= NULL
);
664 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
665 ASSERT (EndOpCodeHandle
!= NULL
);
668 // Create Hii Extend Label OpCode as the start opcode
670 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
671 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
672 StartLabel
->Number
= FORM_ID_DRIVER
;
675 // Create Hii Extend Label OpCode as the end opcode
677 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
678 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
679 EndLabel
->Number
= LABEL_END
;
682 // Clear second page form
685 Private
->RegisteredHandle
,
686 &gPlatformOverridesManagerGuid
,
693 // Show all driver which support loaded image protocol in second page
695 DriverImageHandleCount
= 0;
696 Status
= gBS
->LocateHandleBuffer (
698 &gEfiLoadedImageProtocolGuid
,
700 &DriverImageHandleCount
,
701 &mDriverImageHandleBuffer
703 if (EFI_ERROR (Status
) || (DriverImageHandleCount
== 0)) {
704 return EFI_NOT_FOUND
;
707 mDriverImageToken
= AllocateZeroPool (DriverImageHandleCount
* sizeof (EFI_STRING_ID
));
708 ASSERT (mDriverImageToken
!= NULL
);
709 mDriSelection
= AllocateZeroPool (DriverImageHandleCount
* sizeof (BOOLEAN
));
710 ASSERT (mDriSelection
!= NULL
);
712 DriverImageProtocol
= AllocateZeroPool (DriverImageHandleCount
* sizeof (EFI_LOADED_IMAGE_PROTOCOL
*));
713 ASSERT (DriverImageProtocol
!= NULL
);
714 DriverImageFilePathToken
= AllocateZeroPool (DriverImageHandleCount
* sizeof (EFI_STRING_ID
));
715 ASSERT (DriverImageFilePathToken
!= NULL
);
717 mDriverImageHandleCount
= DriverImageHandleCount
;
718 for (Index
= 0; Index
< DriverImageHandleCount
; Index
++) {
720 // Step1: Get the driver image total file path for help string and the driver name.
724 // Find driver's Loaded Image protocol
728 Status
= gBS
->OpenProtocol (
729 mDriverImageHandleBuffer
[Index
],
730 &gEfiLoadedImageProtocolGuid
,
731 (VOID
**) &LoadedImage
,
734 EFI_OPEN_PROTOCOL_GET_PROTOCOL
736 if (EFI_ERROR (Status
)) {
737 mDriSelection
[Index
] = FALSE
;
740 DriverImageProtocol
[Index
] = LoadedImage
;
742 // Find its related driver binding protocol
744 DriverBindingHandle
= GetDriverBindingHandleFromImageHandle (mDriverImageHandleBuffer
[Index
]);
745 if (DriverBindingHandle
== NULL
) {
746 mDriSelection
[Index
] = FALSE
;
751 // Get the EFI Loaded Image Device Path Protocol
753 LoadedImageDevicePath
= NULL
;
754 Status
= gBS
->HandleProtocol (
755 mDriverImageHandleBuffer
[Index
],
756 &gEfiLoadedImageDevicePathProtocolGuid
,
757 (VOID
**) &LoadedImageDevicePath
759 if (LoadedImageDevicePath
== NULL
) {
760 mDriSelection
[Index
] = FALSE
;
764 if (FakeNvData
->PciDeviceFilter
== 0x01) {
766 // only care the driver which is in a Pci device option rom,
767 // and the driver's LoadedImage->DeviceHandle must point to a pci device which has efi option rom
769 if (!EFI_ERROR (Status
)) {
770 Status
= gBS
->HandleProtocol(
771 LoadedImage
->DeviceHandle
,
772 &gEfiBusSpecificDriverOverrideProtocolGuid
,
773 (VOID
**) &BusSpecificDriverOverride
775 if (EFI_ERROR (Status
) || BusSpecificDriverOverride
== NULL
) {
776 mDriSelection
[Index
] = FALSE
;
780 mDriSelection
[Index
] = FALSE
;
786 // For driver name, try to get its component name, if fail, get its image name,
787 // if also fail, give a default name.
789 FreeDriverName
= FALSE
;
790 DriverName
= GetComponentName (DriverBindingHandle
);
791 if (DriverName
== NULL
) {
793 // get its image name
795 DriverName
= GetImageName (LoadedImage
);
797 if (DriverName
== NULL
) {
799 // give a default name
801 DriverName
= HiiGetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_DRIVER_DEFAULT_NAME
), NULL
);
802 ASSERT (DriverName
!= NULL
);
803 FreeDriverName
= TRUE
; // the DriverName string need to free pool
808 // Step2 Export the driver name string and create check box item in second page
812 // First create the driver image name
814 NewStrSize
= StrSize (DriverName
);
815 NewString
= AllocateZeroPool (NewStrSize
);
816 ASSERT (NewString
!= NULL
);
817 if (EFI_ERROR (CheckMapping (mControllerDevicePathProtocol
[mSelectedCtrIndex
], LoadedImageDevicePath
, &mMappingDataBase
, NULL
, NULL
))) {
818 mDriSelection
[Index
] = FALSE
;
820 mDriSelection
[Index
] = TRUE
;
821 mLastSavedDriverImageNum
++;
823 StrCatS (NewString
, NewStrSize
/sizeof(CHAR16
), DriverName
);
824 NewStringToken
= HiiSetString (Private
->RegisteredHandle
, mDriverImageToken
[Index
], NewString
, NULL
);
825 ASSERT (NewStringToken
!= 0);
826 mDriverImageToken
[Index
] = NewStringToken
;
827 FreePool (NewString
);
828 if (FreeDriverName
) {
829 FreePool (DriverName
);
833 // Second create the driver image device path as item help string
835 DriverName
= DevicePathToStr (LoadedImageDevicePath
);
837 NewStrSize
= StrSize (DriverName
);
838 NewString
= AllocateZeroPool (NewStrSize
);
839 ASSERT (NewString
!= NULL
);
840 StrCatS (NewString
, NewStrSize
/sizeof(CHAR16
), DriverName
);
841 NewStringHelpToken
= HiiSetString (Private
->RegisteredHandle
, DriverImageFilePathToken
[Index
], NewString
, NULL
);
842 ASSERT (NewStringHelpToken
!= 0);
843 DriverImageFilePathToken
[Index
] = NewStringHelpToken
;
844 FreePool (NewString
);
845 FreePool (DriverName
);
848 if (mDriSelection
[Index
]) {
849 CheckFlags
|= EFI_IFR_CHECKBOX_DEFAULT
;
852 HiiCreateCheckBoxOpCode (
854 (UINT16
) (KEY_VALUE_DRIVER_OFFSET
+ Index
),
859 EFI_IFR_FLAG_CALLBACK
,
866 // Update second page form
869 Private
->RegisteredHandle
,
870 &gPlatformOverridesManagerGuid
,
872 StartOpCodeHandle
, // Label FORM_ID_DRIVER
873 EndOpCodeHandle
// LABEL_END
876 HiiFreeOpCodeHandle (StartOpCodeHandle
);
877 HiiFreeOpCodeHandle (EndOpCodeHandle
);
879 if (DriverImageProtocol
!= NULL
) {
880 FreePool (DriverImageProtocol
);
883 if (DriverImageFilePathToken
!= NULL
) {
884 FreePool (DriverImageFilePathToken
);
891 Prepare to let user select the priority order of the drivers which are
892 selected in second page.
894 @param Private Pointer to EFI_CALLBACK_INFO.
895 @param KeyValue The callback key value of device controller item in first page.
896 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
898 @retval EFI_SUCCESS Always returned.
902 UpdatePrioritySelectPage (
903 IN EFI_CALLBACK_INFO
*Private
,
905 IN PLAT_OVER_MNGR_DATA
*FakeNvData
909 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
910 UINTN SelectedDriverImageNum
;
911 UINT32 DriverImageNO
;
916 VOID
*StartOpCodeHandle
;
917 VOID
*EndOpCodeHandle
;
918 VOID
*OptionsOpCodeHandle
;
919 EFI_IFR_GUID_LABEL
*StartLabel
;
920 EFI_IFR_GUID_LABEL
*EndLabel
;
923 // Following code will be run if user select 'order ... priority' item in second page
924 // Prepare third page. In third page, user will order the drivers priority which are selected in second page
926 mCurrentPage
= FORM_ID_ORDER
;
929 // Init OpCode Handle
931 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
932 ASSERT (StartOpCodeHandle
!= NULL
);
934 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
935 ASSERT (EndOpCodeHandle
!= NULL
);
938 // Create Hii Extend Label OpCode as the start opcode
940 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
941 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
942 StartLabel
->Number
= FORM_ID_ORDER
;
945 // Create Hii Extend Label OpCode as the end opcode
947 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
948 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
949 EndLabel
->Number
= LABEL_END
;
952 // Clear third page form
955 Private
->RegisteredHandle
,
956 &gPlatformOverridesManagerGuid
,
963 // Check how many drivers have been selected
965 SelectedDriverImageNum
= 0;
966 for (Index
= 0; Index
< mDriverImageHandleCount
; Index
++) {
967 if (mDriSelection
[Index
]) {
968 SelectedDriverImageNum
++;
972 mSelectedDriverImageNum
= SelectedDriverImageNum
;
973 if (SelectedDriverImageNum
== 0) {
977 OptionsOpCodeHandle
= HiiAllocateOpCodeHandle ();
978 ASSERT (OptionsOpCodeHandle
!= NULL
);
981 // Create order list for those selected drivers
983 SelectedDriverImageNum
= 0;
984 for (Index
= 0; Index
< mDriverImageHandleCount
; Index
++) {
985 if (mDriSelection
[Index
]) {
987 // Use the NO. in driver binding buffer as value, will use it later
989 HiiCreateOneOfOptionOpCode (
991 mDriverImageToken
[Index
],
993 EFI_IFR_NUMERIC_SIZE_1
,
998 // Get the EFI Loaded Image Device Path Protocol
1000 LoadedImageDevicePath
= NULL
;
1001 gBS
->HandleProtocol (
1002 mDriverImageHandleBuffer
[Index
],
1003 &gEfiLoadedImageDevicePathProtocolGuid
,
1004 (VOID
**) &LoadedImageDevicePath
1006 ASSERT (LoadedImageDevicePath
!= NULL
);
1009 // Check the driver DriverImage's order number in mapping database
1013 mControllerDevicePathProtocol
[mSelectedCtrIndex
],
1014 LoadedImageDevicePath
,
1019 if (DriverImageNO
== 0) {
1020 DriverImageNO
= (UINT32
) mLastSavedDriverImageNum
+ 1;
1021 mLastSavedDriverImageNum
++;
1023 TempNO
[SelectedDriverImageNum
] = DriverImageNO
;
1024 OrderNO
[SelectedDriverImageNum
] = Index
+ 1;
1025 SelectedDriverImageNum
++;
1029 ASSERT (SelectedDriverImageNum
== mSelectedDriverImageNum
);
1031 // NvRamMap Must be clear firstly
1033 ZeroMem (FakeNvData
->DriOrder
, sizeof (FakeNvData
->DriOrder
));
1036 // Order the selected drivers according to the info already in mapping database
1037 // the less order number in mapping database the less order number in NvRamMap
1039 for (Index
=0; Index
< SelectedDriverImageNum
; Index
++) {
1041 // Find the minimal order number in TempNO array, its index in TempNO is same as IfrOptionList array
1044 for (Index1
=0; Index1
< SelectedDriverImageNum
; Index1
++) {
1045 if (TempNO
[Index1
] < TempNO
[MinNO
]) {
1050 // the IfrOptionList[MinNO].Value = the driver NO. in driver binding buffer
1052 FakeNvData
->DriOrder
[Index
] = (UINT8
) OrderNO
[MinNO
];
1053 TempNO
[MinNO
] = MAX_CHOICE_NUM
+ 1;
1057 // Create Order List OpCode
1059 HiiCreateOrderedListOpCode (
1061 (UINT16
) DRIVER_ORDER_QUESTION_ID
,
1062 VARSTORE_ID_PLAT_OVER_MNGR
,
1063 (UINT16
) DRIVER_ORDER_VAR_OFFSET
,
1064 mControllerToken
[mSelectedCtrIndex
],
1065 mControllerToken
[mSelectedCtrIndex
],
1066 EFI_IFR_FLAG_RESET_REQUIRED
,
1068 EFI_IFR_NUMERIC_SIZE_1
,
1069 (UINT8
) MAX_CHOICE_NUM
,
1070 OptionsOpCodeHandle
,
1075 // Update third page form
1078 Private
->RegisteredHandle
,
1079 &gPlatformOverridesManagerGuid
,
1081 StartOpCodeHandle
, // Label FORM_ID_ORDER
1082 EndOpCodeHandle
// LABEL_END
1085 HiiFreeOpCodeHandle (StartOpCodeHandle
);
1086 HiiFreeOpCodeHandle (EndOpCodeHandle
);
1087 HiiFreeOpCodeHandle (OptionsOpCodeHandle
);
1093 Save the save the mapping database to NV variable.
1095 @param Private Pointer to EFI_CALLBACK_INFO.
1096 @param KeyValue The callback key value of device controller item in first page.
1097 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
1099 @retval EFI_SUCCESS Always returned.
1104 IN EFI_CALLBACK_INFO
*Private
,
1106 IN PLAT_OVER_MNGR_DATA
*FakeNvData
1111 UINTN SelectedDriverImageNum
;
1112 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
1114 // Following code will be run if user select 'commint changes' in third page
1115 // user enter 'Commit Changes' to save the mapping database
1117 DeleteDriverImage (mControllerDevicePathProtocol
[mSelectedCtrIndex
], NULL
, &mMappingDataBase
);
1118 for (SelectedDriverImageNum
= 0; SelectedDriverImageNum
< mSelectedDriverImageNum
; SelectedDriverImageNum
++) {
1120 // DriOrder[SelectedDriverImageNum] = the driver NO. in driver binding buffer
1122 Index
= FakeNvData
->DriOrder
[SelectedDriverImageNum
] - 1;
1125 // Get the EFI Loaded Image Device Path Protocol
1127 LoadedImageDevicePath
= NULL
;
1128 Status
= gBS
->HandleProtocol (
1129 mDriverImageHandleBuffer
[Index
],
1130 &gEfiLoadedImageDevicePathProtocolGuid
,
1131 (VOID
**) &LoadedImageDevicePath
1133 ASSERT (LoadedImageDevicePath
!= NULL
);
1136 mControllerDevicePathProtocol
[mSelectedCtrIndex
],
1137 LoadedImageDevicePath
,
1139 (UINT32
)SelectedDriverImageNum
+ 1
1142 Status
= SaveOverridesMapping (&mMappingDataBase
);
1148 This function allows a caller to extract the current configuration for one
1149 or more named elements from the target driver.
1151 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1152 @param Request A null-terminated Unicode string in <ConfigRequest> format.
1153 @param Progress On return, points to a character in the Request string.
1154 Points to the string's null terminator if request was successful.
1155 Points to the most recent '&' before the first failing name/value
1156 pair (or the beginning of the string if the failure is in the
1157 first name/value pair) if the request was not successful.
1158 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
1159 has all values filled in for the names in the Request string.
1160 String to be allocated by the called function.
1162 @retval EFI_SUCCESS The Results is filled with the requested values.
1163 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
1164 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
1165 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
1170 PlatOverMngrExtractConfig (
1171 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1172 IN CONST EFI_STRING Request
,
1173 OUT EFI_STRING
*Progress
,
1174 OUT EFI_STRING
*Results
1178 EFI_CALLBACK_INFO
*Private
;
1179 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
1180 EFI_STRING ConfigRequestHdr
;
1181 EFI_STRING ConfigRequest
;
1182 BOOLEAN AllocatedRequest
;
1186 if (Progress
== NULL
|| Results
== NULL
) {
1187 return EFI_INVALID_PARAMETER
;
1190 *Progress
= Request
;
1191 if ((Request
!= NULL
) && !HiiIsConfigHdrMatch (Request
, &gPlatformOverridesManagerGuid
, mVariableName
)) {
1192 return EFI_NOT_FOUND
;
1195 ConfigRequestHdr
= NULL
;
1196 ConfigRequest
= NULL
;
1198 AllocatedRequest
= FALSE
;
1200 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1201 HiiConfigRouting
= Private
->HiiConfigRouting
;
1202 ConfigRequest
= Request
;
1203 if ((Request
== NULL
) || (StrStr (Request
, L
"OFFSET") == NULL
)) {
1205 // Request has no request element, construct full request string.
1206 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
1207 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
1209 ConfigRequestHdr
= HiiConstructConfigHdr (&gPlatformOverridesManagerGuid
, mVariableName
, Private
->DriverHandle
);
1210 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
1211 ConfigRequest
= AllocateZeroPool (Size
);
1212 ASSERT (ConfigRequest
!= NULL
);
1213 AllocatedRequest
= TRUE
;
1214 BufferSize
= sizeof (PLAT_OVER_MNGR_DATA
);
1215 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr
, (UINT64
)BufferSize
);
1216 FreePool (ConfigRequestHdr
);
1220 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
1222 Status
= HiiConfigRouting
->BlockToConfig (
1225 (UINT8
*) &Private
->FakeNvData
,
1226 sizeof (PLAT_OVER_MNGR_DATA
),
1232 // Free the allocated config request string.
1234 if (AllocatedRequest
) {
1235 FreePool (ConfigRequest
);
1236 ConfigRequest
= NULL
;
1239 // Set Progress string to the original request string.
1241 if (Request
== NULL
) {
1243 } else if (StrStr (Request
, L
"OFFSET") == NULL
) {
1244 *Progress
= Request
+ StrLen (Request
);
1251 This function processes the results of changes in configuration.
1253 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1254 @param Configuration A null-terminated Unicode string in <ConfigRequest> format.
1255 @param Progress A pointer to a string filled in with the offset of the most
1256 recent '&' before the first failing name/value pair (or the
1257 beginning of the string if the failure is in the first
1258 name/value pair) or the terminating NULL if all was successful.
1260 @retval EFI_SUCCESS The Results is processed successfully.
1261 @retval EFI_INVALID_PARAMETER Configuration is NULL.
1262 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
1267 PlatOverMngrRouteConfig (
1268 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1269 IN CONST EFI_STRING Configuration
,
1270 OUT EFI_STRING
*Progress
1273 EFI_CALLBACK_INFO
*Private
;
1275 PLAT_OVER_MNGR_DATA
*FakeNvData
;
1278 if (Configuration
== NULL
|| Progress
== NULL
) {
1279 return EFI_INVALID_PARAMETER
;
1281 *Progress
= Configuration
;
1283 if (!HiiIsConfigHdrMatch (Configuration
, &gPlatformOverridesManagerGuid
, mVariableName
)) {
1284 return EFI_NOT_FOUND
;
1287 *Progress
= Configuration
+ StrLen (Configuration
);
1288 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1289 FakeNvData
= &Private
->FakeNvData
;
1290 if (!HiiGetBrowserData (&gPlatformOverridesManagerGuid
, mVariableName
, sizeof (PLAT_OVER_MNGR_DATA
), (UINT8
*) FakeNvData
)) {
1292 // FakeNvData can't be got from SetupBrowser, which doesn't need to be set.
1297 Status
= EFI_SUCCESS
;
1299 if (mCurrentPage
== FORM_ID_ORDER
) {
1300 KeyValue
= KEY_VALUE_ORDER_SAVE_AND_EXIT
;
1301 Status
= CommitChanges (Private
, KeyValue
, FakeNvData
);
1308 This is the function that is called to provide results data to the driver. This data
1309 consists of a unique key which is used to identify what data is either being passed back
1312 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1313 @param Action A null-terminated Unicode string in <ConfigRequest> format.
1314 @param KeyValue A unique Goto OpCode callback value which record user's selection.
1315 0x100 <= KeyValue <0x500 : user select a controller item in the first page;
1316 KeyValue == 0x1234 : user select 'Refresh' in first page, or user select 'Go to Previous Menu' in second page
1317 KeyValue == 0x1235 : user select 'Pci device filter' in first page
1318 KeyValue == 0x1500 : user select 'order ... priority' item in second page
1319 KeyValue == 0x1800 : user select 'commint changes' in third page
1320 KeyValue == 0x2000 : user select 'Go to Previous Menu' in third page
1321 @param Type The type of value for the question.
1322 @param Value A pointer to the data being sent to the original exporting driver.
1323 @param ActionRequest On return, points to the action requested by the callback function.
1325 @retval EFI_SUCCESS Always returned.
1330 PlatOverMngrCallback (
1331 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1332 IN EFI_BROWSER_ACTION Action
,
1333 IN EFI_QUESTION_ID KeyValue
,
1335 IN EFI_IFR_TYPE_VALUE
*Value
,
1336 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
1339 EFI_CALLBACK_INFO
*Private
;
1341 EFI_STRING_ID NewStringToken
;
1343 PLAT_OVER_MNGR_DATA
*FakeNvData
;
1345 if ((Action
!= EFI_BROWSER_ACTION_CHANGING
) && (Action
!= EFI_BROWSER_ACTION_CHANGED
)) {
1347 // All other action return unsupported.
1349 return EFI_UNSUPPORTED
;
1352 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1353 FakeNvData
= &Private
->FakeNvData
;
1354 if (!HiiGetBrowserData (&gPlatformOverridesManagerGuid
, mVariableName
, sizeof (PLAT_OVER_MNGR_DATA
), (UINT8
*) FakeNvData
)) {
1355 return EFI_NOT_FOUND
;
1358 if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
1359 if (Value
== NULL
) {
1360 return EFI_INVALID_PARAMETER
;
1363 if (KeyValue
== KEY_VALUE_DRIVER_GOTO_PREVIOUS
) {
1364 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1366 // Update page title string
1368 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1369 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, L
"First, Select the controller by device path", NULL
) == 0) {
1374 if (((KeyValue
>= KEY_VALUE_DEVICE_OFFSET
) && (KeyValue
< KEY_VALUE_DEVICE_OFFSET
+ mMaxDeviceCount
)) || (KeyValue
== KEY_VALUE_ORDER_GOTO_PREVIOUS
)) {
1375 if (KeyValue
== KEY_VALUE_ORDER_GOTO_PREVIOUS
) {
1376 KeyValue
= (EFI_QUESTION_ID
) (mSelectedCtrIndex
+ KEY_VALUE_DEVICE_OFFSET
);
1378 UpdateBindingDriverSelectPage (Private
, KeyValue
, FakeNvData
);
1380 // Update page title string
1382 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1383 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, L
"Second, Select drivers for the previous selected controller", NULL
) == 0) {
1388 if (KeyValue
== KEY_VALUE_DRIVER_GOTO_ORDER
) {
1389 UpdatePrioritySelectPage (Private
, KeyValue
, FakeNvData
);
1391 // Update page title string
1393 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1394 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, L
"Finally, Set the priority order for the drivers and save them", NULL
) == 0) {
1399 if (KeyValue
== KEY_VALUE_DEVICE_CLEAR
) {
1401 // Deletes all environment variable(s) that contain the override mappings info
1403 FreeMappingDatabase (&mMappingDataBase
);
1404 Status
= SaveOverridesMapping (&mMappingDataBase
);
1405 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1407 } else if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
1408 if ((KeyValue
>= KEY_VALUE_DRIVER_OFFSET
) && (KeyValue
< KEY_VALUE_DRIVER_OFFSET
+ mDriverImageHandleCount
)) {
1409 mDriSelection
[KeyValue
- KEY_VALUE_DRIVER_OFFSET
] = Value
->b
;
1412 case KEY_VALUE_DEVICE_REFRESH
:
1413 case KEY_VALUE_DEVICE_FILTER
:
1414 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1416 // Update page title string
1418 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1419 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, L
"First, Select the controller by device path", NULL
) == 0) {
1424 case KEY_VALUE_ORDER_SAVE_AND_EXIT
:
1425 Status
= CommitChanges (Private
, KeyValue
, FakeNvData
);
1426 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1427 if (EFI_ERROR (Status
)) {
1428 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Single Override Info too large, Saving Error!", NULL
);
1429 return EFI_DEVICE_ERROR
;
1440 // Pass changed uncommitted data back to Form Browser
1442 HiiSetBrowserData (&gPlatformOverridesManagerGuid
, mVariableName
, sizeof (PLAT_OVER_MNGR_DATA
), (UINT8
*) FakeNvData
, NULL
);
1448 Retrieves the image handle of the platform override driver for a controller in the system.
1450 @param This A pointer to the
1451 EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL instance.
1452 @param ControllerHandle The device handle of the controller to check if a
1453 driver override exists.
1454 @param DriverImageHandle On input, a pointer to the previous driver image
1455 handle returned by GetDriver(). On output, a
1456 pointer to the next driver image handle. Passing
1457 in a NULL, will return the first driver image
1458 handle for ControllerHandle.
1460 @retval EFI_SUCCESS The driver override for ControllerHandle was
1461 returned in DriverImageHandle.
1462 @retval EFI_NOT_FOUND A driver override for ControllerHandle was not
1464 @retval EFI_INVALID_PARAMETER The handle specified by ControllerHandle is NULL.
1465 DriverImageHandle is not a handle that was returned
1466 on a previous call to GetDriver().
1472 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL
*This
,
1473 IN EFI_HANDLE ControllerHandle
,
1474 IN OUT EFI_HANDLE
*DriverImageHandle
1480 // Check that ControllerHandle is a valid handle
1482 if (ControllerHandle
== NULL
) {
1483 return EFI_INVALID_PARAMETER
;
1487 // Read the environment variable(s) that contain the override mappings from Controller Device Path to
1488 // a set of Driver Device Paths, and initialize in memory database of the overrides that map Controller
1489 // Device Paths to an ordered set of Driver Device Paths and Driver Handles. This action is only performed
1490 // once and finished in first call.
1492 if (!mEnvironmentVariableRead
) {
1493 mEnvironmentVariableRead
= TRUE
;
1495 Status
= InitOverridesMapping (&mMappingDataBase
);
1496 if (EFI_ERROR (Status
)){
1497 DEBUG ((DEBUG_INFO
, "The status to Get Platform Driver Override Variable is %r\n", Status
));
1498 InitializeListHead (&mMappingDataBase
);
1499 return EFI_NOT_FOUND
;
1504 // if the environment variable does not exist, just return not found
1506 if (IsListEmpty (&mMappingDataBase
)) {
1507 return EFI_NOT_FOUND
;
1510 return GetDriverFromMapping (
1519 Retrieves the device path of the platform override driver for a controller in the system.
1520 This driver doesn't support this API.
1522 @param This A pointer to the EFI_PLATFORM_DRIVER_OVERRIDE_
1524 @param ControllerHandle The device handle of the controller to check if a driver override
1526 @param DriverImagePath On input, a pointer to the previous driver device path returned by
1527 GetDriverPath(). On output, a pointer to the next driver
1528 device path. Passing in a pointer to NULL, will return the first
1529 driver device path for ControllerHandle.
1531 @retval EFI_UNSUPPORTED
1536 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL
*This
,
1537 IN EFI_HANDLE ControllerHandle
,
1538 IN OUT EFI_DEVICE_PATH_PROTOCOL
**DriverImagePath
1541 return EFI_UNSUPPORTED
;
1546 Used to associate a driver image handle with a device path that was returned on a prior call to the
1547 GetDriverPath() service. This driver image handle will then be available through the
1548 GetDriver() service. This driver doesn't support this API.
1550 @param This A pointer to the EFI_PLATFORM_DRIVER_OVERRIDE_
1552 @param ControllerHandle The device handle of the controller.
1553 @param DriverImagePath A pointer to the driver device path that was returned in a prior
1554 call to GetDriverPath().
1555 @param DriverImageHandle The driver image handle that was returned by LoadImage()
1556 when the driver specified by DriverImagePath was loaded
1559 @retval EFI_UNSUPPORTED
1564 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL
*This
,
1565 IN EFI_HANDLE ControllerHandle
,
1566 IN EFI_DEVICE_PATH_PROTOCOL
*DriverImagePath
,
1567 IN EFI_HANDLE DriverImageHandle
1570 return EFI_UNSUPPORTED
;
1574 The driver Entry Point. The function will export a disk device class formset and
1575 its callback function to hii database.
1577 @param ImageHandle The firmware allocated handle for the EFI image.
1578 @param SystemTable A pointer to the EFI System Table.
1580 @retval EFI_SUCCESS The entry point is executed successfully.
1581 @retval other Some error occurs when executing this entry point.
1586 PlatDriOverrideDxeInit (
1587 IN EFI_HANDLE ImageHandle
,
1588 IN EFI_SYSTEM_TABLE
*SystemTable
1592 EFI_FORM_BROWSER2_PROTOCOL
*FormBrowser2
;
1596 // There should only be one Form Configuration protocol
1598 Status
= gBS
->LocateProtocol (
1599 &gEfiFormBrowser2ProtocolGuid
,
1601 (VOID
**) &FormBrowser2
1603 if (EFI_ERROR (Status
)) {
1608 // According to UEFI spec, there can be at most a single instance
1609 // in the system of the EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL.
1610 // So here we check the existence.
1612 Status
= gBS
->LocateProtocol (
1613 &gEfiPlatformDriverOverrideProtocolGuid
,
1618 // If there was no error, assume there is an installation and return error
1620 if (!EFI_ERROR (Status
)) {
1621 return EFI_ALREADY_STARTED
;
1624 mCallerImageHandle
= ImageHandle
;
1625 mCallbackInfo
= AllocateZeroPool (sizeof (EFI_CALLBACK_INFO
));
1626 if (mCallbackInfo
== NULL
) {
1627 return EFI_BAD_BUFFER_SIZE
;
1630 mCallbackInfo
->Signature
= EFI_CALLBACK_INFO_SIGNATURE
;
1631 mCallbackInfo
->ConfigAccess
.ExtractConfig
= PlatOverMngrExtractConfig
;
1632 mCallbackInfo
->ConfigAccess
.RouteConfig
= PlatOverMngrRouteConfig
;
1633 mCallbackInfo
->ConfigAccess
.Callback
= PlatOverMngrCallback
;
1634 mCallbackInfo
->PlatformDriverOverride
.GetDriver
= GetDriver
;
1635 mCallbackInfo
->PlatformDriverOverride
.GetDriverPath
= GetDriverPath
;
1636 mCallbackInfo
->PlatformDriverOverride
.DriverLoaded
= DriverLoaded
;
1639 // Locate ConfigRouting protocol
1641 Status
= gBS
->LocateProtocol (
1642 &gEfiHiiConfigRoutingProtocolGuid
,
1644 (VOID
**) &mCallbackInfo
->HiiConfigRouting
1646 if (EFI_ERROR (Status
)) {
1651 // Install Device Path Protocol and Config Access protocol to driver handle
1652 // Install Platform Driver Override Protocol to driver handle
1654 Status
= gBS
->InstallMultipleProtocolInterfaces (
1655 &mCallbackInfo
->DriverHandle
,
1656 &gEfiDevicePathProtocolGuid
,
1657 &mHiiVendorDevicePath
,
1658 &gEfiHiiConfigAccessProtocolGuid
,
1659 &mCallbackInfo
->ConfigAccess
,
1660 &gEfiPlatformDriverOverrideProtocolGuid
,
1661 &mCallbackInfo
->PlatformDriverOverride
,
1664 if (EFI_ERROR (Status
)) {
1669 // Publish our HII data
1671 mCallbackInfo
->RegisteredHandle
= HiiAddPackages (
1672 &gPlatformOverridesManagerGuid
,
1673 mCallbackInfo
->DriverHandle
,
1675 PlatDriOverrideDxeStrings
,
1678 if (mCallbackInfo
->RegisteredHandle
== NULL
) {
1679 Status
= EFI_OUT_OF_RESOURCES
;
1684 // Clear all the globle variable
1686 mDriverImageHandleCount
= 0;
1692 PlatDriOverrideDxeUnload (ImageHandle
);
1698 Unload its installed protocol.
1700 @param[in] ImageHandle Handle that identifies the image to be unloaded.
1702 @retval EFI_SUCCESS The image has been unloaded.
1706 PlatDriOverrideDxeUnload (
1707 IN EFI_HANDLE ImageHandle
1710 ASSERT (mCallbackInfo
!= NULL
);
1712 if (mCallbackInfo
->DriverHandle
!= NULL
) {
1713 gBS
->UninstallMultipleProtocolInterfaces (
1714 mCallbackInfo
->DriverHandle
,
1715 &gEfiDevicePathProtocolGuid
,
1716 &mHiiVendorDevicePath
,
1717 &gEfiHiiConfigAccessProtocolGuid
,
1718 &mCallbackInfo
->ConfigAccess
,
1719 &gEfiPlatformDriverOverrideProtocolGuid
,
1720 &mCallbackInfo
->PlatformDriverOverride
,
1725 if (mCallbackInfo
->RegisteredHandle
!= NULL
) {
1726 HiiRemovePackages (mCallbackInfo
->RegisteredHandle
);
1729 FreePool (mCallbackInfo
);
1731 if (mControllerToken
!= NULL
) {
1732 FreePool (mControllerToken
);
1735 if (mControllerDevicePathProtocol
!= NULL
) {
1736 FreePool (mControllerDevicePathProtocol
);
1739 if (mDriverImageToken
!= NULL
) {
1740 FreePool (mDriverImageToken
);