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 - 2015, Intel Corporation. All rights reserved.<BR>
17 This program and the accompanying materials
18 are licensed and made available under the terms and conditions of the BSD License
19 which accompanies this distribution. The full text of the license may be found at
20 http://opensource.org/licenses/bsd-license.php
22 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
23 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
27 #include "InternalPlatDriOverrideDxe.h"
28 #include "PlatOverMngr.h"
30 #define EFI_CALLBACK_INFO_SIGNATURE SIGNATURE_32 ('C', 'l', 'b', 'k')
31 #define EFI_CALLBACK_INFO_FROM_THIS(a) CR (a, EFI_CALLBACK_INFO, ConfigAccess, EFI_CALLBACK_INFO_SIGNATURE)
35 EFI_HANDLE DriverHandle
;
36 EFI_HII_HANDLE RegisteredHandle
;
37 PLAT_OVER_MNGR_DATA FakeNvData
;
38 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
39 EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess
;
40 EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL PlatformDriverOverride
;
46 /// HII specific Vendor Device Path definition.
49 VENDOR_DEVICE_PATH VendorDevicePath
;
50 EFI_DEVICE_PATH_PROTOCOL End
;
51 } HII_VENDOR_DEVICE_PATH
;
56 // uni string and Vfr Binary data.
58 extern UINT8 VfrBin
[];
59 extern UINT8 PlatDriOverrideDxeStrings
[];
64 CHAR16 mVariableName
[] = L
"Data";
65 LIST_ENTRY mMappingDataBase
= INITIALIZE_LIST_HEAD_VARIABLE (mMappingDataBase
);
66 BOOLEAN mEnvironmentVariableRead
= FALSE
;
67 EFI_HANDLE mCallerImageHandle
= NULL
;
69 EFI_HANDLE
*mDevicePathHandleBuffer
;
70 EFI_HANDLE
*mDriverImageHandleBuffer
;
72 INTN mSelectedCtrIndex
;
73 EFI_STRING_ID
*mControllerToken
;
74 UINTN mDriverImageHandleCount
;
75 EFI_STRING_ID
*mDriverImageToken
;
76 EFI_DEVICE_PATH_PROTOCOL
**mControllerDevicePathProtocol
;
77 UINTN mSelectedDriverImageNum
;
78 UINTN mLastSavedDriverImageNum
;
80 EFI_CALLBACK_INFO
*mCallbackInfo
;
81 BOOLEAN
*mDriSelection
;
82 UINTN mMaxDeviceCount
;
84 HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath
= {
90 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
91 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
98 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
100 (UINT8
) (END_DEVICE_PATH_LENGTH
),
101 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
107 Converting a given device to an unicode string.
109 @param DevPath Given device path instance
111 @return Converted string from given device path.
112 @retval L"?" Converting failed.
116 IN EFI_DEVICE_PATH_PROTOCOL
*DevPath
120 Text
= ConvertDevicePathToText (
126 Text
= AllocateCopyPool (sizeof (L
"?"), L
"?");
127 ASSERT (Text
!= NULL
);
134 Worker function to get the driver name by ComponentName or ComponentName2 protocol
135 according to the driver binding handle.
137 @param DriverBindingHandle The Handle of DriverBinding.
138 @param ProtocolGuid The pointer to Component Name (2) protocol GUID.
139 @param VariableName The name of the RFC 4646 or ISO 639-2 language variable.
141 @retval !NULL Pointer into the image name if the image name is found,
142 @retval NULL Pointer to NULL if the image name is not found.
146 GetComponentNameWorker (
147 IN EFI_HANDLE DriverBindingHandle
,
148 IN EFI_GUID
*ProtocolGuid
,
149 IN CONST CHAR16
*VariableName
153 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
158 Status
= gBS
->OpenProtocol (
161 (VOID
*) &ComponentName
,
164 EFI_OPEN_PROTOCOL_GET_PROTOCOL
166 if (EFI_ERROR (Status
)) {
171 // Find the best matching language.
173 GetEfiGlobalVariable2 (VariableName
, (VOID
**)&Language
, NULL
);
174 BestLanguage
= GetBestLanguage (
175 ComponentName
->SupportedLanguages
,
176 (BOOLEAN
) (ProtocolGuid
== &gEfiComponentNameProtocolGuid
),
182 if (BestLanguage
!= NULL
) {
183 ComponentName
->GetDriverName (
188 FreePool (BestLanguage
);
191 if (Language
!= NULL
) {
200 Get the driver name by ComponentName or ComponentName2 protocol
201 according to the driver binding handle
203 @param DriverBindingHandle The Handle of DriverBinding.
205 @retval !NULL Pointer into the image name if the image name is found,
206 @retval NULL Pointer to NULL if the image name is not found.
211 IN EFI_HANDLE DriverBindingHandle
217 // Try RFC 4646 Component Name 2 protocol first.
219 DriverName
= GetComponentNameWorker (DriverBindingHandle
, &gEfiComponentName2ProtocolGuid
, L
"PlatformLang");
220 if (DriverName
== NULL
) {
222 // If we can not get driver name from Component Name 2 protocol, we can try ISO 639-2 Component Name protocol.
224 DriverName
= GetComponentNameWorker (DriverBindingHandle
, &gEfiComponentNameProtocolGuid
, L
"Lang");
231 Get the image name from EFI UI section.
232 Get FV protocol by its loaded image protocol to abstract EFI UI section.
234 @param Image Pointer to the loaded image protocol
236 @retval !NULL Pointer to the image name if the image name is found,
237 @retval NULL NULL if the image name is not found.
242 IN EFI_LOADED_IMAGE_PROTOCOL
*Image
246 EFI_DEVICE_PATH_PROTOCOL
*DevPathNode
;
247 EFI_DEVICE_PATH_PROTOCOL
*AlignedDevPathNode
;
248 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*FvFilePath
;
251 UINT32 AuthenticationStatus
;
253 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv2
;
259 if (Image
->FilePath
== NULL
) {
262 DevPathNode
= Image
->FilePath
;
264 while (!IsDevicePathEnd (DevPathNode
)) {
266 // Make sure device path node is aligned when accessing it's FV Name Guid field.
268 AlignedDevPathNode
= AllocateCopyPool (DevicePathNodeLength(DevPathNode
), DevPathNode
);
271 // Find the Fv File path
273 NameGuid
= EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*)AlignedDevPathNode
);
274 if (NameGuid
!= NULL
) {
275 FvFilePath
= (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*) AlignedDevPathNode
;
276 Status
= gBS
->HandleProtocol (
278 &gEfiFirmwareVolume2ProtocolGuid
,
282 // Locate Image EFI UI section to get the image name.
284 if (!EFI_ERROR (Status
)) {
285 Status
= Fv2
->ReadSection (
287 &FvFilePath
->FvFileName
,
288 EFI_SECTION_USER_INTERFACE
,
292 &AuthenticationStatus
294 if (!EFI_ERROR (Status
)) {
295 FreePool (AlignedDevPathNode
);
302 FreePool (AlignedDevPathNode
);
305 // Next device path node
307 DevPathNode
= NextDevicePathNode (DevPathNode
);
314 Prepare the first page to let user select the device controller which need to
315 add mapping drivers if user select 'Refresh' in first page.
316 During first page, user will see all currnet controller device path in system,
317 select any device path will go to second page to select its overrides drivers.
319 @param Private Pointer to EFI_CALLBACK_INFO.
320 @param KeyValue The callback key value of device controller item in first page.
321 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
323 @retval EFI_SUCCESS Always returned.
327 UpdateDeviceSelectPage (
328 IN EFI_CALLBACK_INFO
*Private
,
330 IN PLAT_OVER_MNGR_DATA
*FakeNvData
335 UINTN DevicePathHandleCount
;
338 EFI_STRING_ID NewStringToken
;
339 CHAR16
*ControllerName
;
340 EFI_DEVICE_PATH_PROTOCOL
*ControllerDevicePath
;
341 EFI_PCI_IO_PROTOCOL
*PciIo
;
342 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*BusSpecificDriverOverride
;
344 VOID
*StartOpCodeHandle
;
345 VOID
*EndOpCodeHandle
;
346 EFI_IFR_GUID_LABEL
*StartLabel
;
347 EFI_IFR_GUID_LABEL
*EndLabel
;
350 // Set current page form ID.
352 mCurrentPage
= FORM_ID_DEVICE
;
355 // Initial the mapping database in memory
357 FreeMappingDatabase (&mMappingDataBase
);
358 InitOverridesMapping (&mMappingDataBase
);
361 // Init OpCode Handle
363 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
364 ASSERT (StartOpCodeHandle
!= NULL
);
366 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
367 ASSERT (EndOpCodeHandle
!= NULL
);
370 // Create Hii Extend Label OpCode as the start opcode
372 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
373 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
374 StartLabel
->Number
= FORM_ID_DEVICE
;
377 // Create Hii Extend Label OpCode as the end opcode
379 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
380 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
381 EndLabel
->Number
= LABEL_END
;
384 // Clear first page form
387 Private
->RegisteredHandle
,
388 &gPlatformOverridesManagerGuid
,
390 StartOpCodeHandle
, // Label FORM_ID_DEVICE
391 EndOpCodeHandle
// LABEL_END
395 // When user enter the page at first time, the 'first refresh' string is given to notify user to refresh all the drivers,
396 // then the 'first refresh' string will be replaced by the 'refresh' string, and the two strings content are same after the replacement
398 NewStringToken
= STRING_TOKEN (STR_FIRST_REFRESH
);
399 NewString
= HiiGetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_REFRESH
), NULL
);
400 ASSERT (NewString
!= NULL
);
401 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
, NULL
) == 0) {
404 FreePool (NewString
);
406 NewStringToken
= STRING_TOKEN (STR_FIRST_REFRESH_HELP
);
407 NewString
= HiiGetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_REFRESH_HELP
), NULL
);
408 ASSERT (NewString
!= NULL
);
409 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
, NULL
) == 0) {
412 FreePool (NewString
);
415 // created needed controller device item in first page
417 DevicePathHandleCount
= 0;
418 Status
= gBS
->LocateHandleBuffer (
420 &gEfiDevicePathProtocolGuid
,
422 &DevicePathHandleCount
,
423 &mDevicePathHandleBuffer
425 if (EFI_ERROR (Status
) || (DevicePathHandleCount
== 0)) {
429 mMaxDeviceCount
= DevicePathHandleCount
;
430 mControllerDevicePathProtocol
= AllocateZeroPool (DevicePathHandleCount
* sizeof (EFI_DEVICE_PATH_PROTOCOL
*));
431 ASSERT (mControllerDevicePathProtocol
!= NULL
);
432 mControllerToken
= AllocateZeroPool (DevicePathHandleCount
* sizeof (EFI_STRING_ID
));
433 ASSERT (mControllerToken
!= NULL
);
435 for (Index
= 0; Index
< DevicePathHandleCount
; Index
++) {
436 if (FakeNvData
->PciDeviceFilter
== 0x01) {
438 // Only care PCI device which contain efi driver in its option rom.
442 // Check whether it is a pci device
444 ControllerDevicePath
= NULL
;
445 Status
= gBS
->OpenProtocol (
446 mDevicePathHandleBuffer
[Index
],
447 &gEfiPciIoProtocolGuid
,
451 EFI_OPEN_PROTOCOL_GET_PROTOCOL
453 if (EFI_ERROR (Status
)) {
457 // Check whether it contain efi driver in its option rom
459 Status
= gBS
->HandleProtocol(
460 mDevicePathHandleBuffer
[Index
],
461 &gEfiBusSpecificDriverOverrideProtocolGuid
,
462 (VOID
**) &BusSpecificDriverOverride
464 if (EFI_ERROR (Status
) || BusSpecificDriverOverride
== NULL
) {
469 ControllerDevicePath
= NULL
;
470 Status
= gBS
->OpenProtocol (
471 mDevicePathHandleBuffer
[Index
],
472 &gEfiDevicePathProtocolGuid
,
473 (VOID
**) &ControllerDevicePath
,
476 EFI_OPEN_PROTOCOL_GET_PROTOCOL
478 ASSERT_EFI_ERROR (Status
);
480 // Save the device path protocol interface
482 mControllerDevicePathProtocol
[Index
] = ControllerDevicePath
;
485 // Get the driver name
487 ControllerName
= DevicePathToStr (ControllerDevicePath
);
490 // Export the driver name string and create item in set options page
492 Len
= StrSize (ControllerName
);
493 NewStrSize
= Len
+ StrSize (L
"--");
494 NewString
= AllocateZeroPool (NewStrSize
);
495 ASSERT (NewString
!= NULL
);
496 if (EFI_ERROR (CheckMapping (ControllerDevicePath
,NULL
, &mMappingDataBase
, NULL
, NULL
))) {
497 StrCatS (NewString
, NewStrSize
/sizeof(CHAR16
), L
"--");
499 StrCatS (NewString
, NewStrSize
/sizeof(CHAR16
), L
"**");
501 StrCatS (NewString
, NewStrSize
/sizeof(CHAR16
), ControllerName
);
503 NewStringToken
= HiiSetString (Private
->RegisteredHandle
, mControllerToken
[Index
], NewString
, NULL
);
504 ASSERT (NewStringToken
!= 0);
505 FreePool (NewString
);
507 // Save the device path string toke for next access use
509 mControllerToken
[Index
] = NewStringToken
;
511 HiiCreateGotoOpCode (
515 STRING_TOKEN (STR_GOTO_HELP_DRIVER
),
516 EFI_IFR_FLAG_CALLBACK
,
517 (UINT16
) (Index
+ KEY_VALUE_DEVICE_OFFSET
)
522 // Update first page form
525 Private
->RegisteredHandle
,
526 &gPlatformOverridesManagerGuid
,
528 StartOpCodeHandle
, // Label FORM_ID_DEVICE
529 EndOpCodeHandle
// LABEL_END
532 HiiFreeOpCodeHandle (StartOpCodeHandle
);
533 HiiFreeOpCodeHandle (EndOpCodeHandle
);
539 Get the first Driver Binding handle which has the specific image handle.
541 @param ImageHandle The Image handle
543 @return Handle to Driver binding
544 @retval NULL The paramter is not valid or the driver binding handle is not found.
548 GetDriverBindingHandleFromImageHandle (
549 IN EFI_HANDLE ImageHandle
554 UINTN DriverBindingHandleCount
;
555 EFI_HANDLE
*DriverBindingHandleBuffer
;
556 EFI_DRIVER_BINDING_PROTOCOL
*DriverBindingInterface
;
557 EFI_HANDLE DriverBindingHandle
;
559 DriverBindingHandle
= NULL
;
561 if (ImageHandle
== NULL
) {
565 // Get all drivers which support driver binding protocol
567 DriverBindingHandleCount
= 0;
568 Status
= gBS
->LocateHandleBuffer (
570 &gEfiDriverBindingProtocolGuid
,
572 &DriverBindingHandleCount
,
573 &DriverBindingHandleBuffer
575 if (EFI_ERROR (Status
) || (DriverBindingHandleCount
== 0)) {
580 // Get the first Driver Binding handle which has the specific image handle.
582 for (Index
= 0; Index
< DriverBindingHandleCount
; Index
++) {
583 DriverBindingInterface
= NULL
;
584 Status
= gBS
->OpenProtocol (
585 DriverBindingHandleBuffer
[Index
],
586 &gEfiDriverBindingProtocolGuid
,
587 (VOID
**) &DriverBindingInterface
,
590 EFI_OPEN_PROTOCOL_GET_PROTOCOL
592 if (EFI_ERROR (Status
)) {
596 if (DriverBindingInterface
->ImageHandle
== ImageHandle
) {
597 DriverBindingHandle
= DriverBindingHandleBuffer
[Index
];
602 FreePool (DriverBindingHandleBuffer
);
603 return DriverBindingHandle
;
607 Prepare to let user select the drivers which need mapping with the device controller
608 selected in first page.
610 @param Private Pointer to EFI_CALLBACK_INFO.
611 @param KeyValue The callback key value of device controller item in first page.
612 KeyValue is larger than or equal to KEY_VALUE_DEVICE_OFFSET.
613 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
615 @retval EFI_SUCCESS Always returned.
619 UpdateBindingDriverSelectPage (
620 IN EFI_CALLBACK_INFO
*Private
,
622 IN PLAT_OVER_MNGR_DATA
*FakeNvData
629 EFI_STRING_ID NewStringToken
;
630 EFI_STRING_ID NewStringHelpToken
;
631 UINTN DriverImageHandleCount
;
632 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
634 BOOLEAN FreeDriverName
;
635 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
636 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*BusSpecificDriverOverride
;
637 EFI_HANDLE DriverBindingHandle
;
638 VOID
*StartOpCodeHandle
;
639 VOID
*EndOpCodeHandle
;
640 EFI_IFR_GUID_LABEL
*StartLabel
;
641 EFI_IFR_GUID_LABEL
*EndLabel
;
642 EFI_LOADED_IMAGE_PROTOCOL
**DriverImageProtocol
;
643 EFI_STRING_ID
*DriverImageFilePathToken
;
647 // If user select a controller item in the first page the following code will be run.
648 // During second page, user will see all currnet driver bind protocol driver, the driver name and its device path will be shown
650 //First acquire the list of Loaded Image Protocols, and then when want the name of the driver, look up all the Driver Binding Protocols
651 // and find the first one whose ImageHandle field matches the image handle of the Loaded Image Protocol.
652 // 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.
655 mCurrentPage
= FORM_ID_DRIVER
;
657 // Switch the item callback key value to its NO. in mDevicePathHandleBuffer
659 mSelectedCtrIndex
= KeyValue
- KEY_VALUE_DEVICE_OFFSET
;
660 ASSERT (mSelectedCtrIndex
>= 0 && mSelectedCtrIndex
< MAX_CHOICE_NUM
);
662 mLastSavedDriverImageNum
= 0;
665 // Init OpCode Handle
667 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
668 ASSERT (StartOpCodeHandle
!= NULL
);
670 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
671 ASSERT (EndOpCodeHandle
!= NULL
);
674 // Create Hii Extend Label OpCode as the start opcode
676 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
677 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
678 StartLabel
->Number
= FORM_ID_DRIVER
;
681 // Create Hii Extend Label OpCode as the end opcode
683 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
684 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
685 EndLabel
->Number
= LABEL_END
;
688 // Clear second page form
691 Private
->RegisteredHandle
,
692 &gPlatformOverridesManagerGuid
,
699 // Show all driver which support loaded image protocol in second page
701 DriverImageHandleCount
= 0;
702 Status
= gBS
->LocateHandleBuffer (
704 &gEfiLoadedImageProtocolGuid
,
706 &DriverImageHandleCount
,
707 &mDriverImageHandleBuffer
709 if (EFI_ERROR (Status
) || (DriverImageHandleCount
== 0)) {
710 return EFI_NOT_FOUND
;
713 mDriverImageToken
= AllocateZeroPool (DriverImageHandleCount
* sizeof (EFI_STRING_ID
));
714 ASSERT (mDriverImageToken
!= NULL
);
715 mDriSelection
= AllocateZeroPool (DriverImageHandleCount
* sizeof (BOOLEAN
));
716 ASSERT (mDriSelection
!= NULL
);
718 DriverImageProtocol
= AllocateZeroPool (DriverImageHandleCount
* sizeof (EFI_LOADED_IMAGE_PROTOCOL
*));
719 ASSERT (DriverImageProtocol
!= NULL
);
720 DriverImageFilePathToken
= AllocateZeroPool (DriverImageHandleCount
* sizeof (EFI_STRING_ID
));
721 ASSERT (DriverImageFilePathToken
!= NULL
);
723 mDriverImageHandleCount
= DriverImageHandleCount
;
724 for (Index
= 0; Index
< DriverImageHandleCount
; Index
++) {
726 // Step1: Get the driver image total file path for help string and the driver name.
730 // Find driver's Loaded Image protocol
734 Status
= gBS
->OpenProtocol (
735 mDriverImageHandleBuffer
[Index
],
736 &gEfiLoadedImageProtocolGuid
,
737 (VOID
**) &LoadedImage
,
740 EFI_OPEN_PROTOCOL_GET_PROTOCOL
742 if (EFI_ERROR (Status
)) {
743 mDriSelection
[Index
] = FALSE
;
746 DriverImageProtocol
[Index
] = LoadedImage
;
748 // Find its related driver binding protocol
750 DriverBindingHandle
= GetDriverBindingHandleFromImageHandle (mDriverImageHandleBuffer
[Index
]);
751 if (DriverBindingHandle
== NULL
) {
752 mDriSelection
[Index
] = FALSE
;
757 // Get the EFI Loaded Image Device Path Protocol
759 LoadedImageDevicePath
= NULL
;
760 Status
= gBS
->HandleProtocol (
761 mDriverImageHandleBuffer
[Index
],
762 &gEfiLoadedImageDevicePathProtocolGuid
,
763 (VOID
**) &LoadedImageDevicePath
765 if (LoadedImageDevicePath
== NULL
) {
766 mDriSelection
[Index
] = FALSE
;
770 if (FakeNvData
->PciDeviceFilter
== 0x01) {
772 // only care the driver which is in a Pci device option rom,
773 // and the driver's LoadedImage->DeviceHandle must point to a pci device which has efi option rom
775 if (!EFI_ERROR (Status
)) {
776 Status
= gBS
->HandleProtocol(
777 LoadedImage
->DeviceHandle
,
778 &gEfiBusSpecificDriverOverrideProtocolGuid
,
779 (VOID
**) &BusSpecificDriverOverride
781 if (EFI_ERROR (Status
) || BusSpecificDriverOverride
== NULL
) {
782 mDriSelection
[Index
] = FALSE
;
786 mDriSelection
[Index
] = FALSE
;
792 // For driver name, try to get its component name, if fail, get its image name,
793 // if also fail, give a default name.
795 FreeDriverName
= FALSE
;
796 DriverName
= GetComponentName (DriverBindingHandle
);
797 if (DriverName
== NULL
) {
799 // get its image name
801 DriverName
= GetImageName (LoadedImage
);
803 if (DriverName
== NULL
) {
805 // give a default name
807 DriverName
= HiiGetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_DRIVER_DEFAULT_NAME
), NULL
);
808 ASSERT (DriverName
!= NULL
);
809 FreeDriverName
= TRUE
; // the DriverName string need to free pool
814 // Step2 Export the driver name string and create check box item in second page
818 // First create the driver image name
820 NewStrSize
= StrSize (DriverName
);
821 NewString
= AllocateZeroPool (NewStrSize
);
822 ASSERT (NewString
!= NULL
);
823 if (EFI_ERROR (CheckMapping (mControllerDevicePathProtocol
[mSelectedCtrIndex
], LoadedImageDevicePath
, &mMappingDataBase
, NULL
, NULL
))) {
824 mDriSelection
[Index
] = FALSE
;
826 mDriSelection
[Index
] = TRUE
;
827 mLastSavedDriverImageNum
++;
829 StrCatS (NewString
, NewStrSize
/sizeof(CHAR16
), DriverName
);
830 NewStringToken
= HiiSetString (Private
->RegisteredHandle
, mDriverImageToken
[Index
], NewString
, NULL
);
831 ASSERT (NewStringToken
!= 0);
832 mDriverImageToken
[Index
] = NewStringToken
;
833 FreePool (NewString
);
834 if (FreeDriverName
) {
835 FreePool (DriverName
);
839 // Second create the driver image device path as item help string
841 DriverName
= DevicePathToStr (LoadedImageDevicePath
);
843 NewStrSize
= StrSize (DriverName
);
844 NewString
= AllocateZeroPool (NewStrSize
);
845 ASSERT (NewString
!= NULL
);
846 StrCatS (NewString
, NewStrSize
/sizeof(CHAR16
), DriverName
);
847 NewStringHelpToken
= HiiSetString (Private
->RegisteredHandle
, DriverImageFilePathToken
[Index
], NewString
, NULL
);
848 ASSERT (NewStringHelpToken
!= 0);
849 DriverImageFilePathToken
[Index
] = NewStringHelpToken
;
850 FreePool (NewString
);
851 FreePool (DriverName
);
854 if (mDriSelection
[Index
]) {
855 CheckFlags
|= EFI_IFR_CHECKBOX_DEFAULT
;
858 HiiCreateCheckBoxOpCode (
860 (UINT16
) (KEY_VALUE_DRIVER_OFFSET
+ Index
),
865 EFI_IFR_FLAG_CALLBACK
,
872 // Update second page form
875 Private
->RegisteredHandle
,
876 &gPlatformOverridesManagerGuid
,
878 StartOpCodeHandle
, // Label FORM_ID_DRIVER
879 EndOpCodeHandle
// LABEL_END
882 HiiFreeOpCodeHandle (StartOpCodeHandle
);
883 HiiFreeOpCodeHandle (EndOpCodeHandle
);
885 if (DriverImageProtocol
!= NULL
) {
886 FreePool (DriverImageProtocol
);
889 if (DriverImageFilePathToken
!= NULL
) {
890 FreePool (DriverImageFilePathToken
);
897 Prepare to let user select the priority order of the drivers which are
898 selected in second page.
900 @param Private Pointer to EFI_CALLBACK_INFO.
901 @param KeyValue The callback key value of device controller item in first page.
902 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
904 @retval EFI_SUCCESS Always returned.
908 UpdatePrioritySelectPage (
909 IN EFI_CALLBACK_INFO
*Private
,
911 IN PLAT_OVER_MNGR_DATA
*FakeNvData
915 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
916 UINTN SelectedDriverImageNum
;
917 UINT32 DriverImageNO
;
922 VOID
*StartOpCodeHandle
;
923 VOID
*EndOpCodeHandle
;
924 VOID
*OptionsOpCodeHandle
;
925 EFI_IFR_GUID_LABEL
*StartLabel
;
926 EFI_IFR_GUID_LABEL
*EndLabel
;
929 // Following code will be run if user select 'order ... priority' item in second page
930 // Prepare third page. In third page, user will order the drivers priority which are selected in second page
932 mCurrentPage
= FORM_ID_ORDER
;
935 // Init OpCode Handle
937 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
938 ASSERT (StartOpCodeHandle
!= NULL
);
940 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
941 ASSERT (EndOpCodeHandle
!= NULL
);
944 // Create Hii Extend Label OpCode as the start opcode
946 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
947 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
948 StartLabel
->Number
= FORM_ID_ORDER
;
951 // Create Hii Extend Label OpCode as the end opcode
953 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
954 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
955 EndLabel
->Number
= LABEL_END
;
958 // Clear third page form
961 Private
->RegisteredHandle
,
962 &gPlatformOverridesManagerGuid
,
969 // Check how many drivers have been selected
971 SelectedDriverImageNum
= 0;
972 for (Index
= 0; Index
< mDriverImageHandleCount
; Index
++) {
973 if (mDriSelection
[Index
]) {
974 SelectedDriverImageNum
++;
978 mSelectedDriverImageNum
= SelectedDriverImageNum
;
979 if (SelectedDriverImageNum
== 0) {
983 OptionsOpCodeHandle
= HiiAllocateOpCodeHandle ();
984 ASSERT (OptionsOpCodeHandle
!= NULL
);
987 // Create order list for those selected drivers
989 SelectedDriverImageNum
= 0;
990 for (Index
= 0; Index
< mDriverImageHandleCount
; Index
++) {
991 if (mDriSelection
[Index
]) {
993 // Use the NO. in driver binding buffer as value, will use it later
995 HiiCreateOneOfOptionOpCode (
997 mDriverImageToken
[Index
],
999 EFI_IFR_NUMERIC_SIZE_1
,
1004 // Get the EFI Loaded Image Device Path Protocol
1006 LoadedImageDevicePath
= NULL
;
1007 gBS
->HandleProtocol (
1008 mDriverImageHandleBuffer
[Index
],
1009 &gEfiLoadedImageDevicePathProtocolGuid
,
1010 (VOID
**) &LoadedImageDevicePath
1012 ASSERT (LoadedImageDevicePath
!= NULL
);
1015 // Check the driver DriverImage's order number in mapping database
1019 mControllerDevicePathProtocol
[mSelectedCtrIndex
],
1020 LoadedImageDevicePath
,
1025 if (DriverImageNO
== 0) {
1026 DriverImageNO
= (UINT32
) mLastSavedDriverImageNum
+ 1;
1027 mLastSavedDriverImageNum
++;
1029 TempNO
[SelectedDriverImageNum
] = DriverImageNO
;
1030 OrderNO
[SelectedDriverImageNum
] = Index
+ 1;
1031 SelectedDriverImageNum
++;
1035 ASSERT (SelectedDriverImageNum
== mSelectedDriverImageNum
);
1037 // NvRamMap Must be clear firstly
1039 ZeroMem (FakeNvData
->DriOrder
, sizeof (FakeNvData
->DriOrder
));
1042 // Order the selected drivers according to the info already in mapping database
1043 // the less order number in mapping database the less order number in NvRamMap
1045 for (Index
=0; Index
< SelectedDriverImageNum
; Index
++) {
1047 // Find the minimal order number in TempNO array, its index in TempNO is same as IfrOptionList array
1050 for (Index1
=0; Index1
< SelectedDriverImageNum
; Index1
++) {
1051 if (TempNO
[Index1
] < TempNO
[MinNO
]) {
1056 // the IfrOptionList[MinNO].Value = the driver NO. in driver binding buffer
1058 FakeNvData
->DriOrder
[Index
] = (UINT8
) OrderNO
[MinNO
];
1059 TempNO
[MinNO
] = MAX_CHOICE_NUM
+ 1;
1063 // Create Order List OpCode
1065 HiiCreateOrderedListOpCode (
1067 (UINT16
) DRIVER_ORDER_QUESTION_ID
,
1068 VARSTORE_ID_PLAT_OVER_MNGR
,
1069 (UINT16
) DRIVER_ORDER_VAR_OFFSET
,
1070 mControllerToken
[mSelectedCtrIndex
],
1071 mControllerToken
[mSelectedCtrIndex
],
1072 EFI_IFR_FLAG_RESET_REQUIRED
,
1074 EFI_IFR_NUMERIC_SIZE_1
,
1075 (UINT8
) MAX_CHOICE_NUM
,
1076 OptionsOpCodeHandle
,
1081 // Update third page form
1084 Private
->RegisteredHandle
,
1085 &gPlatformOverridesManagerGuid
,
1087 StartOpCodeHandle
, // Label FORM_ID_ORDER
1088 EndOpCodeHandle
// LABEL_END
1091 HiiFreeOpCodeHandle (StartOpCodeHandle
);
1092 HiiFreeOpCodeHandle (EndOpCodeHandle
);
1093 HiiFreeOpCodeHandle (OptionsOpCodeHandle
);
1099 Save the save the mapping database to NV variable.
1101 @param Private Pointer to EFI_CALLBACK_INFO.
1102 @param KeyValue The callback key value of device controller item in first page.
1103 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
1105 @retval EFI_SUCCESS Always returned.
1110 IN EFI_CALLBACK_INFO
*Private
,
1112 IN PLAT_OVER_MNGR_DATA
*FakeNvData
1117 UINTN SelectedDriverImageNum
;
1118 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
1120 // Following code will be run if user select 'commint changes' in third page
1121 // user enter 'Commit Changes' to save the mapping database
1123 DeleteDriverImage (mControllerDevicePathProtocol
[mSelectedCtrIndex
], NULL
, &mMappingDataBase
);
1124 for (SelectedDriverImageNum
= 0; SelectedDriverImageNum
< mSelectedDriverImageNum
; SelectedDriverImageNum
++) {
1126 // DriOrder[SelectedDriverImageNum] = the driver NO. in driver binding buffer
1128 Index
= FakeNvData
->DriOrder
[SelectedDriverImageNum
] - 1;
1131 // Get the EFI Loaded Image Device Path Protocol
1133 LoadedImageDevicePath
= NULL
;
1134 Status
= gBS
->HandleProtocol (
1135 mDriverImageHandleBuffer
[Index
],
1136 &gEfiLoadedImageDevicePathProtocolGuid
,
1137 (VOID
**) &LoadedImageDevicePath
1139 ASSERT (LoadedImageDevicePath
!= NULL
);
1142 mControllerDevicePathProtocol
[mSelectedCtrIndex
],
1143 LoadedImageDevicePath
,
1145 (UINT32
)SelectedDriverImageNum
+ 1
1148 Status
= SaveOverridesMapping (&mMappingDataBase
);
1154 This function allows a caller to extract the current configuration for one
1155 or more named elements from the target driver.
1157 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1158 @param Request A null-terminated Unicode string in <ConfigRequest> format.
1159 @param Progress On return, points to a character in the Request string.
1160 Points to the string's null terminator if request was successful.
1161 Points to the most recent '&' before the first failing name/value
1162 pair (or the beginning of the string if the failure is in the
1163 first name/value pair) if the request was not successful.
1164 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
1165 has all values filled in for the names in the Request string.
1166 String to be allocated by the called function.
1168 @retval EFI_SUCCESS The Results is filled with the requested values.
1169 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
1170 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
1171 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
1176 PlatOverMngrExtractConfig (
1177 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1178 IN CONST EFI_STRING Request
,
1179 OUT EFI_STRING
*Progress
,
1180 OUT EFI_STRING
*Results
1184 EFI_CALLBACK_INFO
*Private
;
1185 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
1186 EFI_STRING ConfigRequestHdr
;
1187 EFI_STRING ConfigRequest
;
1188 BOOLEAN AllocatedRequest
;
1192 if (Progress
== NULL
|| Results
== NULL
) {
1193 return EFI_INVALID_PARAMETER
;
1196 *Progress
= Request
;
1197 if ((Request
!= NULL
) && !HiiIsConfigHdrMatch (Request
, &gPlatformOverridesManagerGuid
, mVariableName
)) {
1198 return EFI_NOT_FOUND
;
1201 ConfigRequestHdr
= NULL
;
1202 ConfigRequest
= NULL
;
1204 AllocatedRequest
= FALSE
;
1206 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1207 HiiConfigRouting
= Private
->HiiConfigRouting
;
1208 ConfigRequest
= Request
;
1209 if ((Request
== NULL
) || (StrStr (Request
, L
"OFFSET") == NULL
)) {
1211 // Request has no request element, construct full request string.
1212 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
1213 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
1215 ConfigRequestHdr
= HiiConstructConfigHdr (&gPlatformOverridesManagerGuid
, mVariableName
, Private
->DriverHandle
);
1216 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
1217 ConfigRequest
= AllocateZeroPool (Size
);
1218 ASSERT (ConfigRequest
!= NULL
);
1219 AllocatedRequest
= TRUE
;
1220 BufferSize
= sizeof (PLAT_OVER_MNGR_DATA
);
1221 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr
, (UINT64
)BufferSize
);
1222 FreePool (ConfigRequestHdr
);
1226 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
1228 Status
= HiiConfigRouting
->BlockToConfig (
1231 (UINT8
*) &Private
->FakeNvData
,
1232 sizeof (PLAT_OVER_MNGR_DATA
),
1238 // Free the allocated config request string.
1240 if (AllocatedRequest
) {
1241 FreePool (ConfigRequest
);
1242 ConfigRequest
= NULL
;
1245 // Set Progress string to the original request string.
1247 if (Request
== NULL
) {
1249 } else if (StrStr (Request
, L
"OFFSET") == NULL
) {
1250 *Progress
= Request
+ StrLen (Request
);
1257 This function processes the results of changes in configuration.
1259 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1260 @param Configuration A null-terminated Unicode string in <ConfigRequest> format.
1261 @param Progress A pointer to a string filled in with the offset of the most
1262 recent '&' before the first failing name/value pair (or the
1263 beginning of the string if the failure is in the first
1264 name/value pair) or the terminating NULL if all was successful.
1266 @retval EFI_SUCCESS The Results is processed successfully.
1267 @retval EFI_INVALID_PARAMETER Configuration is NULL.
1268 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
1273 PlatOverMngrRouteConfig (
1274 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1275 IN CONST EFI_STRING Configuration
,
1276 OUT EFI_STRING
*Progress
1279 EFI_CALLBACK_INFO
*Private
;
1281 PLAT_OVER_MNGR_DATA
*FakeNvData
;
1284 if (Configuration
== NULL
|| Progress
== NULL
) {
1285 return EFI_INVALID_PARAMETER
;
1287 *Progress
= Configuration
;
1289 if (!HiiIsConfigHdrMatch (Configuration
, &gPlatformOverridesManagerGuid
, mVariableName
)) {
1290 return EFI_NOT_FOUND
;
1293 *Progress
= Configuration
+ StrLen (Configuration
);
1294 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1295 FakeNvData
= &Private
->FakeNvData
;
1296 if (!HiiGetBrowserData (&gPlatformOverridesManagerGuid
, mVariableName
, sizeof (PLAT_OVER_MNGR_DATA
), (UINT8
*) FakeNvData
)) {
1298 // FakeNvData can't be got from SetupBrowser, which doesn't need to be set.
1303 Status
= EFI_SUCCESS
;
1305 if (mCurrentPage
== FORM_ID_ORDER
) {
1306 KeyValue
= KEY_VALUE_ORDER_SAVE_AND_EXIT
;
1307 Status
= CommitChanges (Private
, KeyValue
, FakeNvData
);
1314 This is the function that is called to provide results data to the driver. This data
1315 consists of a unique key which is used to identify what data is either being passed back
1318 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1319 @param Action A null-terminated Unicode string in <ConfigRequest> format.
1320 @param KeyValue A unique Goto OpCode callback value which record user's selection.
1321 0x100 <= KeyValue <0x500 : user select a controller item in the first page;
1322 KeyValue == 0x1234 : user select 'Refresh' in first page, or user select 'Go to Previous Menu' in second page
1323 KeyValue == 0x1235 : user select 'Pci device filter' in first page
1324 KeyValue == 0x1500 : user select 'order ... priority' item in second page
1325 KeyValue == 0x1800 : user select 'commint changes' in third page
1326 KeyValue == 0x2000 : user select 'Go to Previous Menu' in third page
1327 @param Type The type of value for the question.
1328 @param Value A pointer to the data being sent to the original exporting driver.
1329 @param ActionRequest On return, points to the action requested by the callback function.
1331 @retval EFI_SUCCESS Always returned.
1336 PlatOverMngrCallback (
1337 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1338 IN EFI_BROWSER_ACTION Action
,
1339 IN EFI_QUESTION_ID KeyValue
,
1341 IN EFI_IFR_TYPE_VALUE
*Value
,
1342 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
1345 EFI_CALLBACK_INFO
*Private
;
1347 EFI_STRING_ID NewStringToken
;
1349 PLAT_OVER_MNGR_DATA
*FakeNvData
;
1351 if ((Action
!= EFI_BROWSER_ACTION_CHANGING
) && (Action
!= EFI_BROWSER_ACTION_CHANGED
)) {
1353 // All other action return unsupported.
1355 return EFI_UNSUPPORTED
;
1358 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1359 FakeNvData
= &Private
->FakeNvData
;
1360 if (!HiiGetBrowserData (&gPlatformOverridesManagerGuid
, mVariableName
, sizeof (PLAT_OVER_MNGR_DATA
), (UINT8
*) FakeNvData
)) {
1361 return EFI_NOT_FOUND
;
1364 if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
1365 if (Value
== NULL
) {
1366 return EFI_INVALID_PARAMETER
;
1369 if (KeyValue
== KEY_VALUE_DRIVER_GOTO_PREVIOUS
) {
1370 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1372 // Update page title string
1374 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1375 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, L
"First, Select the controller by device path", NULL
) == 0) {
1380 if (((KeyValue
>= KEY_VALUE_DEVICE_OFFSET
) && (KeyValue
< KEY_VALUE_DEVICE_OFFSET
+ mMaxDeviceCount
)) || (KeyValue
== KEY_VALUE_ORDER_GOTO_PREVIOUS
)) {
1381 if (KeyValue
== KEY_VALUE_ORDER_GOTO_PREVIOUS
) {
1382 KeyValue
= (EFI_QUESTION_ID
) (mSelectedCtrIndex
+ KEY_VALUE_DEVICE_OFFSET
);
1384 UpdateBindingDriverSelectPage (Private
, KeyValue
, FakeNvData
);
1386 // Update page title string
1388 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1389 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, L
"Second, Select drivers for the previous selected controller", NULL
) == 0) {
1394 if (KeyValue
== KEY_VALUE_DRIVER_GOTO_ORDER
) {
1395 UpdatePrioritySelectPage (Private
, KeyValue
, FakeNvData
);
1397 // Update page title string
1399 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1400 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, L
"Finally, Set the priority order for the drivers and save them", NULL
) == 0) {
1405 if (KeyValue
== KEY_VALUE_DEVICE_CLEAR
) {
1407 // Deletes all environment variable(s) that contain the override mappings info
1409 FreeMappingDatabase (&mMappingDataBase
);
1410 Status
= SaveOverridesMapping (&mMappingDataBase
);
1411 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1413 } else if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
1414 if ((KeyValue
>= KEY_VALUE_DRIVER_OFFSET
) && (KeyValue
< KEY_VALUE_DRIVER_OFFSET
+ mDriverImageHandleCount
)) {
1415 mDriSelection
[KeyValue
- KEY_VALUE_DRIVER_OFFSET
] = Value
->b
;
1418 case KEY_VALUE_DEVICE_REFRESH
:
1419 case KEY_VALUE_DEVICE_FILTER
:
1420 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1422 // Update page title string
1424 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1425 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, L
"First, Select the controller by device path", NULL
) == 0) {
1430 case KEY_VALUE_ORDER_SAVE_AND_EXIT
:
1431 Status
= CommitChanges (Private
, KeyValue
, FakeNvData
);
1432 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1433 if (EFI_ERROR (Status
)) {
1434 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Single Override Info too large, Saving Error!", NULL
);
1435 return EFI_DEVICE_ERROR
;
1446 // Pass changed uncommitted data back to Form Browser
1448 HiiSetBrowserData (&gPlatformOverridesManagerGuid
, mVariableName
, sizeof (PLAT_OVER_MNGR_DATA
), (UINT8
*) FakeNvData
, NULL
);
1454 Retrieves the image handle of the platform override driver for a controller in the system.
1456 @param This A pointer to the
1457 EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL instance.
1458 @param ControllerHandle The device handle of the controller to check if a
1459 driver override exists.
1460 @param DriverImageHandle On input, a pointer to the previous driver image
1461 handle returned by GetDriver(). On output, a
1462 pointer to the next driver image handle. Passing
1463 in a NULL, will return the first driver image
1464 handle for ControllerHandle.
1466 @retval EFI_SUCCESS The driver override for ControllerHandle was
1467 returned in DriverImageHandle.
1468 @retval EFI_NOT_FOUND A driver override for ControllerHandle was not
1470 @retval EFI_INVALID_PARAMETER The handle specified by ControllerHandle is NULL.
1471 DriverImageHandle is not a handle that was returned
1472 on a previous call to GetDriver().
1478 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL
*This
,
1479 IN EFI_HANDLE ControllerHandle
,
1480 IN OUT EFI_HANDLE
*DriverImageHandle
1486 // Check that ControllerHandle is a valid handle
1488 if (ControllerHandle
== NULL
) {
1489 return EFI_INVALID_PARAMETER
;
1493 // Read the environment variable(s) that contain the override mappings from Controller Device Path to
1494 // a set of Driver Device Paths, and initialize in memory database of the overrides that map Controller
1495 // Device Paths to an ordered set of Driver Device Paths and Driver Handles. This action is only performed
1496 // once and finished in first call.
1498 if (!mEnvironmentVariableRead
) {
1499 mEnvironmentVariableRead
= TRUE
;
1501 Status
= InitOverridesMapping (&mMappingDataBase
);
1502 if (EFI_ERROR (Status
)){
1503 DEBUG ((DEBUG_ERROR
, "The status to Get Platform Driver Override Variable is %r\n", Status
));
1504 InitializeListHead (&mMappingDataBase
);
1505 return EFI_NOT_FOUND
;
1510 // if the environment variable does not exist, just return not found
1512 if (IsListEmpty (&mMappingDataBase
)) {
1513 return EFI_NOT_FOUND
;
1516 return GetDriverFromMapping (
1525 Retrieves the device path of the platform override driver for a controller in the system.
1526 This driver doesn't support this API.
1528 @param This A pointer to the EFI_PLATFORM_DRIVER_OVERRIDE_
1530 @param ControllerHandle The device handle of the controller to check if a driver override
1532 @param DriverImagePath On input, a pointer to the previous driver device path returned by
1533 GetDriverPath(). On output, a pointer to the next driver
1534 device path. Passing in a pointer to NULL, will return the first
1535 driver device path for ControllerHandle.
1537 @retval EFI_UNSUPPORTED
1542 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL
*This
,
1543 IN EFI_HANDLE ControllerHandle
,
1544 IN OUT EFI_DEVICE_PATH_PROTOCOL
**DriverImagePath
1547 return EFI_UNSUPPORTED
;
1552 Used to associate a driver image handle with a device path that was returned on a prior call to the
1553 GetDriverPath() service. This driver image handle will then be available through the
1554 GetDriver() service. This driver doesn't support this API.
1556 @param This A pointer to the EFI_PLATFORM_DRIVER_OVERRIDE_
1558 @param ControllerHandle The device handle of the controller.
1559 @param DriverImagePath A pointer to the driver device path that was returned in a prior
1560 call to GetDriverPath().
1561 @param DriverImageHandle The driver image handle that was returned by LoadImage()
1562 when the driver specified by DriverImagePath was loaded
1565 @retval EFI_UNSUPPORTED
1570 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL
*This
,
1571 IN EFI_HANDLE ControllerHandle
,
1572 IN EFI_DEVICE_PATH_PROTOCOL
*DriverImagePath
,
1573 IN EFI_HANDLE DriverImageHandle
1576 return EFI_UNSUPPORTED
;
1580 The driver Entry Point. The funciton will export a disk device class formset and
1581 its callback function to hii database.
1583 @param ImageHandle The firmware allocated handle for the EFI image.
1584 @param SystemTable A pointer to the EFI System Table.
1586 @retval EFI_SUCCESS The entry point is executed successfully.
1587 @retval other Some error occurs when executing this entry point.
1592 PlatDriOverrideDxeInit (
1593 IN EFI_HANDLE ImageHandle
,
1594 IN EFI_SYSTEM_TABLE
*SystemTable
1598 EFI_FORM_BROWSER2_PROTOCOL
*FormBrowser2
;
1602 // There should only be one Form Configuration protocol
1604 Status
= gBS
->LocateProtocol (
1605 &gEfiFormBrowser2ProtocolGuid
,
1607 (VOID
**) &FormBrowser2
1609 if (EFI_ERROR (Status
)) {
1614 // According to UEFI spec, there can be at most a single instance
1615 // in the system of the EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL.
1616 // So here we check the existence.
1618 Status
= gBS
->LocateProtocol (
1619 &gEfiPlatformDriverOverrideProtocolGuid
,
1624 // If there was no error, assume there is an installation and return error
1626 if (!EFI_ERROR (Status
)) {
1627 return EFI_ALREADY_STARTED
;
1630 mCallerImageHandle
= ImageHandle
;
1631 mCallbackInfo
= AllocateZeroPool (sizeof (EFI_CALLBACK_INFO
));
1632 if (mCallbackInfo
== NULL
) {
1633 return EFI_BAD_BUFFER_SIZE
;
1636 mCallbackInfo
->Signature
= EFI_CALLBACK_INFO_SIGNATURE
;
1637 mCallbackInfo
->ConfigAccess
.ExtractConfig
= PlatOverMngrExtractConfig
;
1638 mCallbackInfo
->ConfigAccess
.RouteConfig
= PlatOverMngrRouteConfig
;
1639 mCallbackInfo
->ConfigAccess
.Callback
= PlatOverMngrCallback
;
1640 mCallbackInfo
->PlatformDriverOverride
.GetDriver
= GetDriver
;
1641 mCallbackInfo
->PlatformDriverOverride
.GetDriverPath
= GetDriverPath
;
1642 mCallbackInfo
->PlatformDriverOverride
.DriverLoaded
= DriverLoaded
;
1645 // Locate ConfigRouting protocol
1647 Status
= gBS
->LocateProtocol (
1648 &gEfiHiiConfigRoutingProtocolGuid
,
1650 (VOID
**) &mCallbackInfo
->HiiConfigRouting
1652 if (EFI_ERROR (Status
)) {
1657 // Install Device Path Protocol and Config Access protocol to driver handle
1658 // Install Platform Driver Override Protocol to driver handle
1660 Status
= gBS
->InstallMultipleProtocolInterfaces (
1661 &mCallbackInfo
->DriverHandle
,
1662 &gEfiDevicePathProtocolGuid
,
1663 &mHiiVendorDevicePath
,
1664 &gEfiHiiConfigAccessProtocolGuid
,
1665 &mCallbackInfo
->ConfigAccess
,
1666 &gEfiPlatformDriverOverrideProtocolGuid
,
1667 &mCallbackInfo
->PlatformDriverOverride
,
1670 if (EFI_ERROR (Status
)) {
1675 // Publish our HII data
1677 mCallbackInfo
->RegisteredHandle
= HiiAddPackages (
1678 &gPlatformOverridesManagerGuid
,
1679 mCallbackInfo
->DriverHandle
,
1681 PlatDriOverrideDxeStrings
,
1684 if (mCallbackInfo
->RegisteredHandle
== NULL
) {
1685 Status
= EFI_OUT_OF_RESOURCES
;
1690 // Clear all the globle variable
1692 mDriverImageHandleCount
= 0;
1698 PlatDriOverrideDxeUnload (ImageHandle
);
1704 Unload its installed protocol.
1706 @param[in] ImageHandle Handle that identifies the image to be unloaded.
1708 @retval EFI_SUCCESS The image has been unloaded.
1712 PlatDriOverrideDxeUnload (
1713 IN EFI_HANDLE ImageHandle
1716 ASSERT (mCallbackInfo
!= NULL
);
1718 if (mCallbackInfo
->DriverHandle
!= NULL
) {
1719 gBS
->UninstallMultipleProtocolInterfaces (
1720 mCallbackInfo
->DriverHandle
,
1721 &gEfiDevicePathProtocolGuid
,
1722 &mHiiVendorDevicePath
,
1723 &gEfiHiiConfigAccessProtocolGuid
,
1724 &mCallbackInfo
->ConfigAccess
,
1725 &gEfiPlatformDriverOverrideProtocolGuid
,
1726 &mCallbackInfo
->PlatformDriverOverride
,
1731 if (mCallbackInfo
->RegisteredHandle
!= NULL
) {
1732 HiiRemovePackages (mCallbackInfo
->RegisteredHandle
);
1735 FreePool (mCallbackInfo
);
1737 if (mControllerToken
!= NULL
) {
1738 FreePool (mControllerToken
);
1741 if (mControllerDevicePathProtocol
!= NULL
) {
1742 FreePool (mControllerDevicePathProtocol
);
1745 if (mDriverImageToken
!= NULL
) {
1746 FreePool (mDriverImageToken
);