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
;
337 EFI_STRING_ID NewStringToken
;
338 CHAR16
*ControllerName
;
339 EFI_DEVICE_PATH_PROTOCOL
*ControllerDevicePath
;
340 EFI_PCI_IO_PROTOCOL
*PciIo
;
341 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*BusSpecificDriverOverride
;
343 VOID
*StartOpCodeHandle
;
344 VOID
*EndOpCodeHandle
;
345 EFI_IFR_GUID_LABEL
*StartLabel
;
346 EFI_IFR_GUID_LABEL
*EndLabel
;
349 // Set current page form ID.
351 mCurrentPage
= FORM_ID_DEVICE
;
354 // Initial the mapping database in memory
356 FreeMappingDatabase (&mMappingDataBase
);
357 InitOverridesMapping (&mMappingDataBase
);
360 // Init OpCode Handle
362 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
363 ASSERT (StartOpCodeHandle
!= NULL
);
365 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
366 ASSERT (EndOpCodeHandle
!= NULL
);
369 // Create Hii Extend Label OpCode as the start opcode
371 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
372 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
373 StartLabel
->Number
= FORM_ID_DEVICE
;
376 // Create Hii Extend Label OpCode as the end opcode
378 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
379 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
380 EndLabel
->Number
= LABEL_END
;
383 // Clear first page form
386 Private
->RegisteredHandle
,
387 &gPlatformOverridesManagerGuid
,
389 StartOpCodeHandle
, // Label FORM_ID_DEVICE
390 EndOpCodeHandle
// LABEL_END
394 // When user enter the page at first time, the 'first refresh' string is given to notify user to refresh all the drivers,
395 // then the 'first refresh' string will be replaced by the 'refresh' string, and the two strings content are same after the replacement
397 NewStringToken
= STRING_TOKEN (STR_FIRST_REFRESH
);
398 NewString
= HiiGetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_REFRESH
), NULL
);
399 ASSERT (NewString
!= NULL
);
400 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
, NULL
) == 0) {
403 FreePool (NewString
);
405 NewStringToken
= STRING_TOKEN (STR_FIRST_REFRESH_HELP
);
406 NewString
= HiiGetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_REFRESH_HELP
), NULL
);
407 ASSERT (NewString
!= NULL
);
408 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
, NULL
) == 0) {
411 FreePool (NewString
);
414 // created needed controller device item in first page
416 DevicePathHandleCount
= 0;
417 Status
= gBS
->LocateHandleBuffer (
419 &gEfiDevicePathProtocolGuid
,
421 &DevicePathHandleCount
,
422 &mDevicePathHandleBuffer
424 if (EFI_ERROR (Status
) || (DevicePathHandleCount
== 0)) {
428 mMaxDeviceCount
= DevicePathHandleCount
;
429 mControllerDevicePathProtocol
= AllocateZeroPool (DevicePathHandleCount
* sizeof (EFI_DEVICE_PATH_PROTOCOL
*));
430 ASSERT (mControllerDevicePathProtocol
!= NULL
);
431 mControllerToken
= AllocateZeroPool (DevicePathHandleCount
* sizeof (EFI_STRING_ID
));
432 ASSERT (mControllerToken
!= NULL
);
434 for (Index
= 0; Index
< DevicePathHandleCount
; Index
++) {
435 if (FakeNvData
->PciDeviceFilter
== 0x01) {
437 // Only care PCI device which contain efi driver in its option rom.
441 // Check whether it is a pci device
443 ControllerDevicePath
= NULL
;
444 Status
= gBS
->OpenProtocol (
445 mDevicePathHandleBuffer
[Index
],
446 &gEfiPciIoProtocolGuid
,
450 EFI_OPEN_PROTOCOL_GET_PROTOCOL
452 if (EFI_ERROR (Status
)) {
456 // Check whether it contain efi driver in its option rom
458 Status
= gBS
->HandleProtocol(
459 mDevicePathHandleBuffer
[Index
],
460 &gEfiBusSpecificDriverOverrideProtocolGuid
,
461 (VOID
**) &BusSpecificDriverOverride
463 if (EFI_ERROR (Status
) || BusSpecificDriverOverride
== NULL
) {
468 ControllerDevicePath
= NULL
;
469 Status
= gBS
->OpenProtocol (
470 mDevicePathHandleBuffer
[Index
],
471 &gEfiDevicePathProtocolGuid
,
472 (VOID
**) &ControllerDevicePath
,
475 EFI_OPEN_PROTOCOL_GET_PROTOCOL
477 ASSERT_EFI_ERROR (Status
);
479 // Save the device path protocol interface
481 mControllerDevicePathProtocol
[Index
] = ControllerDevicePath
;
484 // Get the driver name
486 ControllerName
= DevicePathToStr (ControllerDevicePath
);
489 // Export the driver name string and create item in set options page
491 Len
= StrSize (ControllerName
);
492 NewString
= AllocateZeroPool (Len
+ StrSize (L
"--"));
493 ASSERT (NewString
!= NULL
);
494 if (EFI_ERROR (CheckMapping (ControllerDevicePath
,NULL
, &mMappingDataBase
, NULL
, NULL
))) {
495 StrCat (NewString
, L
"--");
497 StrCat (NewString
, L
"**");
499 StrCat (NewString
, ControllerName
);
501 NewStringToken
= HiiSetString (Private
->RegisteredHandle
, mControllerToken
[Index
], NewString
, NULL
);
502 ASSERT (NewStringToken
!= 0);
503 FreePool (NewString
);
505 // Save the device path string toke for next access use
507 mControllerToken
[Index
] = NewStringToken
;
509 HiiCreateGotoOpCode (
513 STRING_TOKEN (STR_GOTO_HELP_DRIVER
),
514 EFI_IFR_FLAG_CALLBACK
,
515 (UINT16
) (Index
+ KEY_VALUE_DEVICE_OFFSET
)
520 // Update first page form
523 Private
->RegisteredHandle
,
524 &gPlatformOverridesManagerGuid
,
526 StartOpCodeHandle
, // Label FORM_ID_DEVICE
527 EndOpCodeHandle
// LABEL_END
530 HiiFreeOpCodeHandle (StartOpCodeHandle
);
531 HiiFreeOpCodeHandle (EndOpCodeHandle
);
537 Get the first Driver Binding handle which has the specific image handle.
539 @param ImageHandle The Image handle
541 @return Handle to Driver binding
542 @retval NULL The paramter is not valid or the driver binding handle is not found.
546 GetDriverBindingHandleFromImageHandle (
547 IN EFI_HANDLE ImageHandle
552 UINTN DriverBindingHandleCount
;
553 EFI_HANDLE
*DriverBindingHandleBuffer
;
554 EFI_DRIVER_BINDING_PROTOCOL
*DriverBindingInterface
;
555 EFI_HANDLE DriverBindingHandle
;
557 DriverBindingHandle
= NULL
;
559 if (ImageHandle
== NULL
) {
563 // Get all drivers which support driver binding protocol
565 DriverBindingHandleCount
= 0;
566 Status
= gBS
->LocateHandleBuffer (
568 &gEfiDriverBindingProtocolGuid
,
570 &DriverBindingHandleCount
,
571 &DriverBindingHandleBuffer
573 if (EFI_ERROR (Status
) || (DriverBindingHandleCount
== 0)) {
578 // Get the first Driver Binding handle which has the specific image handle.
580 for (Index
= 0; Index
< DriverBindingHandleCount
; Index
++) {
581 DriverBindingInterface
= NULL
;
582 Status
= gBS
->OpenProtocol (
583 DriverBindingHandleBuffer
[Index
],
584 &gEfiDriverBindingProtocolGuid
,
585 (VOID
**) &DriverBindingInterface
,
588 EFI_OPEN_PROTOCOL_GET_PROTOCOL
590 if (EFI_ERROR (Status
)) {
594 if (DriverBindingInterface
->ImageHandle
== ImageHandle
) {
595 DriverBindingHandle
= DriverBindingHandleBuffer
[Index
];
600 FreePool (DriverBindingHandleBuffer
);
601 return DriverBindingHandle
;
605 Prepare to let user select the drivers which need mapping with the device controller
606 selected in first page.
608 @param Private Pointer to EFI_CALLBACK_INFO.
609 @param KeyValue The callback key value of device controller item in first page.
610 KeyValue is larger than or equal to KEY_VALUE_DEVICE_OFFSET.
611 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
613 @retval EFI_SUCCESS Always returned.
617 UpdateBindingDriverSelectPage (
618 IN EFI_CALLBACK_INFO
*Private
,
620 IN PLAT_OVER_MNGR_DATA
*FakeNvData
626 EFI_STRING_ID NewStringToken
;
627 EFI_STRING_ID NewStringHelpToken
;
628 UINTN DriverImageHandleCount
;
629 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
631 BOOLEAN FreeDriverName
;
632 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
633 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*BusSpecificDriverOverride
;
634 EFI_HANDLE DriverBindingHandle
;
635 VOID
*StartOpCodeHandle
;
636 VOID
*EndOpCodeHandle
;
637 EFI_IFR_GUID_LABEL
*StartLabel
;
638 EFI_IFR_GUID_LABEL
*EndLabel
;
639 EFI_LOADED_IMAGE_PROTOCOL
**DriverImageProtocol
;
640 EFI_STRING_ID
*DriverImageFilePathToken
;
644 // If user select a controller item in the first page the following code will be run.
645 // During second page, user will see all currnet driver bind protocol driver, the driver name and its device path will be shown
647 //First acquire the list of Loaded Image Protocols, and then when want the name of the driver, look up all the Driver Binding Protocols
648 // and find the first one whose ImageHandle field matches the image handle of the Loaded Image Protocol.
649 // 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.
652 mCurrentPage
= FORM_ID_DRIVER
;
654 // Switch the item callback key value to its NO. in mDevicePathHandleBuffer
656 mSelectedCtrIndex
= KeyValue
- KEY_VALUE_DEVICE_OFFSET
;
657 ASSERT (mSelectedCtrIndex
>= 0 && mSelectedCtrIndex
< MAX_CHOICE_NUM
);
659 mLastSavedDriverImageNum
= 0;
662 // Init OpCode Handle
664 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
665 ASSERT (StartOpCodeHandle
!= NULL
);
667 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
668 ASSERT (EndOpCodeHandle
!= NULL
);
671 // Create Hii Extend Label OpCode as the start opcode
673 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
674 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
675 StartLabel
->Number
= FORM_ID_DRIVER
;
678 // Create Hii Extend Label OpCode as the end opcode
680 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
681 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
682 EndLabel
->Number
= LABEL_END
;
685 // Clear second page form
688 Private
->RegisteredHandle
,
689 &gPlatformOverridesManagerGuid
,
696 // Show all driver which support loaded image protocol in second page
698 DriverImageHandleCount
= 0;
699 Status
= gBS
->LocateHandleBuffer (
701 &gEfiLoadedImageProtocolGuid
,
703 &DriverImageHandleCount
,
704 &mDriverImageHandleBuffer
706 if (EFI_ERROR (Status
) || (DriverImageHandleCount
== 0)) {
707 return EFI_NOT_FOUND
;
710 mDriverImageToken
= AllocateZeroPool (DriverImageHandleCount
* sizeof (EFI_STRING_ID
));
711 ASSERT (mDriverImageToken
!= NULL
);
712 mDriSelection
= AllocateZeroPool (DriverImageHandleCount
* sizeof (BOOLEAN
));
713 ASSERT (mDriSelection
!= NULL
);
715 DriverImageProtocol
= AllocateZeroPool (DriverImageHandleCount
* sizeof (EFI_LOADED_IMAGE_PROTOCOL
*));
716 ASSERT (DriverImageProtocol
!= NULL
);
717 DriverImageFilePathToken
= AllocateZeroPool (DriverImageHandleCount
* sizeof (EFI_STRING_ID
));
718 ASSERT (DriverImageFilePathToken
!= NULL
);
720 mDriverImageHandleCount
= DriverImageHandleCount
;
721 for (Index
= 0; Index
< DriverImageHandleCount
; Index
++) {
723 // Step1: Get the driver image total file path for help string and the driver name.
727 // Find driver's Loaded Image protocol
731 Status
= gBS
->OpenProtocol (
732 mDriverImageHandleBuffer
[Index
],
733 &gEfiLoadedImageProtocolGuid
,
734 (VOID
**) &LoadedImage
,
737 EFI_OPEN_PROTOCOL_GET_PROTOCOL
739 if (EFI_ERROR (Status
)) {
740 mDriSelection
[Index
] = FALSE
;
743 DriverImageProtocol
[Index
] = LoadedImage
;
745 // Find its related driver binding protocol
747 DriverBindingHandle
= GetDriverBindingHandleFromImageHandle (mDriverImageHandleBuffer
[Index
]);
748 if (DriverBindingHandle
== NULL
) {
749 mDriSelection
[Index
] = FALSE
;
754 // Get the EFI Loaded Image Device Path Protocol
756 LoadedImageDevicePath
= NULL
;
757 Status
= gBS
->HandleProtocol (
758 mDriverImageHandleBuffer
[Index
],
759 &gEfiLoadedImageDevicePathProtocolGuid
,
760 (VOID
**) &LoadedImageDevicePath
762 if (LoadedImageDevicePath
== NULL
) {
763 mDriSelection
[Index
] = FALSE
;
767 if (FakeNvData
->PciDeviceFilter
== 0x01) {
769 // only care the driver which is in a Pci device option rom,
770 // and the driver's LoadedImage->DeviceHandle must point to a pci device which has efi option rom
772 if (!EFI_ERROR (Status
)) {
773 Status
= gBS
->HandleProtocol(
774 LoadedImage
->DeviceHandle
,
775 &gEfiBusSpecificDriverOverrideProtocolGuid
,
776 (VOID
**) &BusSpecificDriverOverride
778 if (EFI_ERROR (Status
) || BusSpecificDriverOverride
== NULL
) {
779 mDriSelection
[Index
] = FALSE
;
783 mDriSelection
[Index
] = FALSE
;
789 // For driver name, try to get its component name, if fail, get its image name,
790 // if also fail, give a default name.
792 FreeDriverName
= FALSE
;
793 DriverName
= GetComponentName (DriverBindingHandle
);
794 if (DriverName
== NULL
) {
796 // get its image name
798 DriverName
= GetImageName (LoadedImage
);
800 if (DriverName
== NULL
) {
802 // give a default name
804 DriverName
= HiiGetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_DRIVER_DEFAULT_NAME
), NULL
);
805 ASSERT (DriverName
!= NULL
);
806 FreeDriverName
= TRUE
; // the DriverName string need to free pool
811 // Step2 Export the driver name string and create check box item in second page
815 // First create the driver image name
817 NewString
= AllocateZeroPool (StrSize (DriverName
));
818 ASSERT (NewString
!= NULL
);
819 if (EFI_ERROR (CheckMapping (mControllerDevicePathProtocol
[mSelectedCtrIndex
], LoadedImageDevicePath
, &mMappingDataBase
, NULL
, NULL
))) {
820 mDriSelection
[Index
] = FALSE
;
822 mDriSelection
[Index
] = TRUE
;
823 mLastSavedDriverImageNum
++;
825 StrCat (NewString
, DriverName
);
826 NewStringToken
= HiiSetString (Private
->RegisteredHandle
, mDriverImageToken
[Index
], NewString
, NULL
);
827 ASSERT (NewStringToken
!= 0);
828 mDriverImageToken
[Index
] = NewStringToken
;
829 FreePool (NewString
);
830 if (FreeDriverName
) {
831 FreePool (DriverName
);
835 // Second create the driver image device path as item help string
837 DriverName
= DevicePathToStr (LoadedImageDevicePath
);
839 NewString
= AllocateZeroPool (StrSize (DriverName
));
840 ASSERT (NewString
!= NULL
);
841 StrCat (NewString
, DriverName
);
842 NewStringHelpToken
= HiiSetString (Private
->RegisteredHandle
, DriverImageFilePathToken
[Index
], NewString
, NULL
);
843 ASSERT (NewStringHelpToken
!= 0);
844 DriverImageFilePathToken
[Index
] = NewStringHelpToken
;
845 FreePool (NewString
);
846 FreePool (DriverName
);
849 if (mDriSelection
[Index
]) {
850 CheckFlags
|= EFI_IFR_CHECKBOX_DEFAULT
;
853 HiiCreateCheckBoxOpCode (
855 (UINT16
) (KEY_VALUE_DRIVER_OFFSET
+ Index
),
860 EFI_IFR_FLAG_CALLBACK
,
867 // Update second page form
870 Private
->RegisteredHandle
,
871 &gPlatformOverridesManagerGuid
,
873 StartOpCodeHandle
, // Label FORM_ID_DRIVER
874 EndOpCodeHandle
// LABEL_END
877 HiiFreeOpCodeHandle (StartOpCodeHandle
);
878 HiiFreeOpCodeHandle (EndOpCodeHandle
);
880 if (DriverImageProtocol
!= NULL
) {
881 FreePool (DriverImageProtocol
);
884 if (DriverImageFilePathToken
!= NULL
) {
885 FreePool (DriverImageFilePathToken
);
892 Prepare to let user select the priority order of the drivers which are
893 selected in second page.
895 @param Private Pointer to EFI_CALLBACK_INFO.
896 @param KeyValue The callback key value of device controller item in first page.
897 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
899 @retval EFI_SUCCESS Always returned.
903 UpdatePrioritySelectPage (
904 IN EFI_CALLBACK_INFO
*Private
,
906 IN PLAT_OVER_MNGR_DATA
*FakeNvData
910 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
911 UINTN SelectedDriverImageNum
;
912 UINT32 DriverImageNO
;
917 VOID
*StartOpCodeHandle
;
918 VOID
*EndOpCodeHandle
;
919 VOID
*OptionsOpCodeHandle
;
920 EFI_IFR_GUID_LABEL
*StartLabel
;
921 EFI_IFR_GUID_LABEL
*EndLabel
;
924 // Following code will be run if user select 'order ... priority' item in second page
925 // Prepare third page. In third page, user will order the drivers priority which are selected in second page
927 mCurrentPage
= FORM_ID_ORDER
;
930 // Init OpCode Handle
932 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
933 ASSERT (StartOpCodeHandle
!= NULL
);
935 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
936 ASSERT (EndOpCodeHandle
!= NULL
);
939 // Create Hii Extend Label OpCode as the start opcode
941 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
942 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
943 StartLabel
->Number
= FORM_ID_ORDER
;
946 // Create Hii Extend Label OpCode as the end opcode
948 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
949 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
950 EndLabel
->Number
= LABEL_END
;
953 // Clear third page form
956 Private
->RegisteredHandle
,
957 &gPlatformOverridesManagerGuid
,
964 // Check how many drivers have been selected
966 SelectedDriverImageNum
= 0;
967 for (Index
= 0; Index
< mDriverImageHandleCount
; Index
++) {
968 if (mDriSelection
[Index
]) {
969 SelectedDriverImageNum
++;
973 mSelectedDriverImageNum
= SelectedDriverImageNum
;
974 if (SelectedDriverImageNum
== 0) {
978 OptionsOpCodeHandle
= HiiAllocateOpCodeHandle ();
979 ASSERT (OptionsOpCodeHandle
!= NULL
);
982 // Create order list for those selected drivers
984 SelectedDriverImageNum
= 0;
985 for (Index
= 0; Index
< mDriverImageHandleCount
; Index
++) {
986 if (mDriSelection
[Index
]) {
988 // Use the NO. in driver binding buffer as value, will use it later
990 HiiCreateOneOfOptionOpCode (
992 mDriverImageToken
[Index
],
994 EFI_IFR_NUMERIC_SIZE_1
,
999 // Get the EFI Loaded Image Device Path Protocol
1001 LoadedImageDevicePath
= NULL
;
1002 gBS
->HandleProtocol (
1003 mDriverImageHandleBuffer
[Index
],
1004 &gEfiLoadedImageDevicePathProtocolGuid
,
1005 (VOID
**) &LoadedImageDevicePath
1007 ASSERT (LoadedImageDevicePath
!= NULL
);
1010 // Check the driver DriverImage's order number in mapping database
1014 mControllerDevicePathProtocol
[mSelectedCtrIndex
],
1015 LoadedImageDevicePath
,
1020 if (DriverImageNO
== 0) {
1021 DriverImageNO
= (UINT32
) mLastSavedDriverImageNum
+ 1;
1022 mLastSavedDriverImageNum
++;
1024 TempNO
[SelectedDriverImageNum
] = DriverImageNO
;
1025 OrderNO
[SelectedDriverImageNum
] = Index
+ 1;
1026 SelectedDriverImageNum
++;
1030 ASSERT (SelectedDriverImageNum
== mSelectedDriverImageNum
);
1032 // NvRamMap Must be clear firstly
1034 ZeroMem (FakeNvData
->DriOrder
, sizeof (FakeNvData
->DriOrder
));
1037 // Order the selected drivers according to the info already in mapping database
1038 // the less order number in mapping database the less order number in NvRamMap
1040 for (Index
=0; Index
< SelectedDriverImageNum
; Index
++) {
1042 // Find the minimal order number in TempNO array, its index in TempNO is same as IfrOptionList array
1045 for (Index1
=0; Index1
< SelectedDriverImageNum
; Index1
++) {
1046 if (TempNO
[Index1
] < TempNO
[MinNO
]) {
1051 // the IfrOptionList[MinNO].Value = the driver NO. in driver binding buffer
1053 FakeNvData
->DriOrder
[Index
] = (UINT8
) OrderNO
[MinNO
];
1054 TempNO
[MinNO
] = MAX_CHOICE_NUM
+ 1;
1058 // Create Order List OpCode
1060 HiiCreateOrderedListOpCode (
1062 (UINT16
) DRIVER_ORDER_QUESTION_ID
,
1063 VARSTORE_ID_PLAT_OVER_MNGR
,
1064 (UINT16
) DRIVER_ORDER_VAR_OFFSET
,
1065 mControllerToken
[mSelectedCtrIndex
],
1066 mControllerToken
[mSelectedCtrIndex
],
1067 EFI_IFR_FLAG_RESET_REQUIRED
,
1069 EFI_IFR_NUMERIC_SIZE_1
,
1070 (UINT8
) MAX_CHOICE_NUM
,
1071 OptionsOpCodeHandle
,
1076 // Update third page form
1079 Private
->RegisteredHandle
,
1080 &gPlatformOverridesManagerGuid
,
1082 StartOpCodeHandle
, // Label FORM_ID_ORDER
1083 EndOpCodeHandle
// LABEL_END
1086 HiiFreeOpCodeHandle (StartOpCodeHandle
);
1087 HiiFreeOpCodeHandle (EndOpCodeHandle
);
1088 HiiFreeOpCodeHandle (OptionsOpCodeHandle
);
1094 Save the save the mapping database to NV variable.
1096 @param Private Pointer to EFI_CALLBACK_INFO.
1097 @param KeyValue The callback key value of device controller item in first page.
1098 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
1100 @retval EFI_SUCCESS Always returned.
1105 IN EFI_CALLBACK_INFO
*Private
,
1107 IN PLAT_OVER_MNGR_DATA
*FakeNvData
1112 UINTN SelectedDriverImageNum
;
1113 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
1115 // Following code will be run if user select 'commint changes' in third page
1116 // user enter 'Commit Changes' to save the mapping database
1118 DeleteDriverImage (mControllerDevicePathProtocol
[mSelectedCtrIndex
], NULL
, &mMappingDataBase
);
1119 for (SelectedDriverImageNum
= 0; SelectedDriverImageNum
< mSelectedDriverImageNum
; SelectedDriverImageNum
++) {
1121 // DriOrder[SelectedDriverImageNum] = the driver NO. in driver binding buffer
1123 Index
= FakeNvData
->DriOrder
[SelectedDriverImageNum
] - 1;
1126 // Get the EFI Loaded Image Device Path Protocol
1128 LoadedImageDevicePath
= NULL
;
1129 Status
= gBS
->HandleProtocol (
1130 mDriverImageHandleBuffer
[Index
],
1131 &gEfiLoadedImageDevicePathProtocolGuid
,
1132 (VOID
**) &LoadedImageDevicePath
1134 ASSERT (LoadedImageDevicePath
!= NULL
);
1137 mControllerDevicePathProtocol
[mSelectedCtrIndex
],
1138 LoadedImageDevicePath
,
1140 (UINT32
)SelectedDriverImageNum
+ 1
1143 Status
= SaveOverridesMapping (&mMappingDataBase
);
1149 This function allows a caller to extract the current configuration for one
1150 or more named elements from the target driver.
1152 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1153 @param Request A null-terminated Unicode string in <ConfigRequest> format.
1154 @param Progress On return, points to a character in the Request string.
1155 Points to the string's null terminator if request was successful.
1156 Points to the most recent '&' before the first failing name/value
1157 pair (or the beginning of the string if the failure is in the
1158 first name/value pair) if the request was not successful.
1159 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
1160 has all values filled in for the names in the Request string.
1161 String to be allocated by the called function.
1163 @retval EFI_SUCCESS The Results is filled with the requested values.
1164 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
1165 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
1166 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
1171 PlatOverMngrExtractConfig (
1172 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1173 IN CONST EFI_STRING Request
,
1174 OUT EFI_STRING
*Progress
,
1175 OUT EFI_STRING
*Results
1179 EFI_CALLBACK_INFO
*Private
;
1180 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
1181 EFI_STRING ConfigRequestHdr
;
1182 EFI_STRING ConfigRequest
;
1183 BOOLEAN AllocatedRequest
;
1187 if (Progress
== NULL
|| Results
== NULL
) {
1188 return EFI_INVALID_PARAMETER
;
1191 *Progress
= Request
;
1192 if ((Request
!= NULL
) && !HiiIsConfigHdrMatch (Request
, &gPlatformOverridesManagerGuid
, mVariableName
)) {
1193 return EFI_NOT_FOUND
;
1196 ConfigRequestHdr
= NULL
;
1197 ConfigRequest
= NULL
;
1199 AllocatedRequest
= FALSE
;
1201 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1202 HiiConfigRouting
= Private
->HiiConfigRouting
;
1203 ConfigRequest
= Request
;
1204 if ((Request
== NULL
) || (StrStr (Request
, L
"OFFSET") == NULL
)) {
1206 // Request has no request element, construct full request string.
1207 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
1208 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
1210 ConfigRequestHdr
= HiiConstructConfigHdr (&gPlatformOverridesManagerGuid
, mVariableName
, Private
->DriverHandle
);
1211 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
1212 ConfigRequest
= AllocateZeroPool (Size
);
1213 ASSERT (ConfigRequest
!= NULL
);
1214 AllocatedRequest
= TRUE
;
1215 BufferSize
= sizeof (PLAT_OVER_MNGR_DATA
);
1216 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr
, (UINT64
)BufferSize
);
1217 FreePool (ConfigRequestHdr
);
1221 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
1223 Status
= HiiConfigRouting
->BlockToConfig (
1226 (UINT8
*) &Private
->FakeNvData
,
1227 sizeof (PLAT_OVER_MNGR_DATA
),
1233 // Free the allocated config request string.
1235 if (AllocatedRequest
) {
1236 FreePool (ConfigRequest
);
1237 ConfigRequest
= NULL
;
1240 // Set Progress string to the original request string.
1242 if (Request
== NULL
) {
1244 } else if (StrStr (Request
, L
"OFFSET") == NULL
) {
1245 *Progress
= Request
+ StrLen (Request
);
1252 This function processes the results of changes in configuration.
1254 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1255 @param Configuration A null-terminated Unicode string in <ConfigRequest> format.
1256 @param Progress A pointer to a string filled in with the offset of the most
1257 recent '&' before the first failing name/value pair (or the
1258 beginning of the string if the failure is in the first
1259 name/value pair) or the terminating NULL if all was successful.
1261 @retval EFI_SUCCESS The Results is processed successfully.
1262 @retval EFI_INVALID_PARAMETER Configuration is NULL.
1263 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
1268 PlatOverMngrRouteConfig (
1269 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1270 IN CONST EFI_STRING Configuration
,
1271 OUT EFI_STRING
*Progress
1274 EFI_CALLBACK_INFO
*Private
;
1276 PLAT_OVER_MNGR_DATA
*FakeNvData
;
1279 if (Configuration
== NULL
|| Progress
== NULL
) {
1280 return EFI_INVALID_PARAMETER
;
1282 *Progress
= Configuration
;
1284 if (!HiiIsConfigHdrMatch (Configuration
, &gPlatformOverridesManagerGuid
, mVariableName
)) {
1285 return EFI_NOT_FOUND
;
1288 *Progress
= Configuration
+ StrLen (Configuration
);
1289 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1290 FakeNvData
= &Private
->FakeNvData
;
1291 if (!HiiGetBrowserData (&gPlatformOverridesManagerGuid
, mVariableName
, sizeof (PLAT_OVER_MNGR_DATA
), (UINT8
*) FakeNvData
)) {
1293 // FakeNvData can't be got from SetupBrowser, which doesn't need to be set.
1298 Status
= EFI_SUCCESS
;
1300 if (mCurrentPage
== FORM_ID_ORDER
) {
1301 KeyValue
= KEY_VALUE_ORDER_SAVE_AND_EXIT
;
1302 Status
= CommitChanges (Private
, KeyValue
, FakeNvData
);
1309 This is the function that is called to provide results data to the driver. This data
1310 consists of a unique key which is used to identify what data is either being passed back
1313 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1314 @param Action A null-terminated Unicode string in <ConfigRequest> format.
1315 @param KeyValue A unique Goto OpCode callback value which record user's selection.
1316 0x100 <= KeyValue <0x500 : user select a controller item in the first page;
1317 KeyValue == 0x1234 : user select 'Refresh' in first page, or user select 'Go to Previous Menu' in second page
1318 KeyValue == 0x1235 : user select 'Pci device filter' in first page
1319 KeyValue == 0x1500 : user select 'order ... priority' item in second page
1320 KeyValue == 0x1800 : user select 'commint changes' in third page
1321 KeyValue == 0x2000 : user select 'Go to Previous Menu' in third page
1322 @param Type The type of value for the question.
1323 @param Value A pointer to the data being sent to the original exporting driver.
1324 @param ActionRequest On return, points to the action requested by the callback function.
1326 @retval EFI_SUCCESS Always returned.
1331 PlatOverMngrCallback (
1332 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1333 IN EFI_BROWSER_ACTION Action
,
1334 IN EFI_QUESTION_ID KeyValue
,
1336 IN EFI_IFR_TYPE_VALUE
*Value
,
1337 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
1340 EFI_CALLBACK_INFO
*Private
;
1342 EFI_STRING_ID NewStringToken
;
1344 PLAT_OVER_MNGR_DATA
*FakeNvData
;
1346 if ((Action
!= EFI_BROWSER_ACTION_CHANGING
) && (Action
!= EFI_BROWSER_ACTION_CHANGED
)) {
1348 // All other action return unsupported.
1350 return EFI_UNSUPPORTED
;
1353 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1354 FakeNvData
= &Private
->FakeNvData
;
1355 if (!HiiGetBrowserData (&gPlatformOverridesManagerGuid
, mVariableName
, sizeof (PLAT_OVER_MNGR_DATA
), (UINT8
*) FakeNvData
)) {
1356 return EFI_NOT_FOUND
;
1359 if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
1360 if (Value
== NULL
) {
1361 return EFI_INVALID_PARAMETER
;
1364 if (KeyValue
== KEY_VALUE_DRIVER_GOTO_PREVIOUS
) {
1365 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1367 // Update page title string
1369 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1370 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, L
"First, Select the controller by device path", NULL
) == 0) {
1375 if (((KeyValue
>= KEY_VALUE_DEVICE_OFFSET
) && (KeyValue
< KEY_VALUE_DEVICE_OFFSET
+ mMaxDeviceCount
)) || (KeyValue
== KEY_VALUE_ORDER_GOTO_PREVIOUS
)) {
1376 if (KeyValue
== KEY_VALUE_ORDER_GOTO_PREVIOUS
) {
1377 KeyValue
= (EFI_QUESTION_ID
) (mSelectedCtrIndex
+ KEY_VALUE_DEVICE_OFFSET
);
1379 UpdateBindingDriverSelectPage (Private
, KeyValue
, FakeNvData
);
1381 // Update page title string
1383 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1384 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, L
"Second, Select drivers for the previous selected controller", NULL
) == 0) {
1389 if (KeyValue
== KEY_VALUE_DRIVER_GOTO_ORDER
) {
1390 UpdatePrioritySelectPage (Private
, KeyValue
, FakeNvData
);
1392 // Update page title string
1394 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1395 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, L
"Finally, Set the priority order for the drivers and save them", NULL
) == 0) {
1400 if (KeyValue
== KEY_VALUE_DEVICE_CLEAR
) {
1402 // Deletes all environment variable(s) that contain the override mappings info
1404 FreeMappingDatabase (&mMappingDataBase
);
1405 Status
= SaveOverridesMapping (&mMappingDataBase
);
1406 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1408 } else if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
1409 if ((KeyValue
>= KEY_VALUE_DRIVER_OFFSET
) && (KeyValue
< KEY_VALUE_DRIVER_OFFSET
+ mDriverImageHandleCount
)) {
1410 mDriSelection
[KeyValue
- KEY_VALUE_DRIVER_OFFSET
] = Value
->b
;
1413 case KEY_VALUE_DEVICE_REFRESH
:
1414 case KEY_VALUE_DEVICE_FILTER
:
1415 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1417 // Update page title string
1419 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1420 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, L
"First, Select the controller by device path", NULL
) == 0) {
1425 case KEY_VALUE_ORDER_SAVE_AND_EXIT
:
1426 Status
= CommitChanges (Private
, KeyValue
, FakeNvData
);
1427 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1428 if (EFI_ERROR (Status
)) {
1429 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Single Override Info too large, Saving Error!", NULL
);
1430 return EFI_DEVICE_ERROR
;
1441 // Pass changed uncommitted data back to Form Browser
1443 HiiSetBrowserData (&gPlatformOverridesManagerGuid
, mVariableName
, sizeof (PLAT_OVER_MNGR_DATA
), (UINT8
*) FakeNvData
, NULL
);
1449 Retrieves the image handle of the platform override driver for a controller in the system.
1451 @param This A pointer to the
1452 EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL instance.
1453 @param ControllerHandle The device handle of the controller to check if a
1454 driver override exists.
1455 @param DriverImageHandle On input, a pointer to the previous driver image
1456 handle returned by GetDriver(). On output, a
1457 pointer to the next driver image handle. Passing
1458 in a NULL, will return the first driver image
1459 handle for ControllerHandle.
1461 @retval EFI_SUCCESS The driver override for ControllerHandle was
1462 returned in DriverImageHandle.
1463 @retval EFI_NOT_FOUND A driver override for ControllerHandle was not
1465 @retval EFI_INVALID_PARAMETER The handle specified by ControllerHandle is NULL.
1466 DriverImageHandle is not a handle that was returned
1467 on a previous call to GetDriver().
1473 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL
*This
,
1474 IN EFI_HANDLE ControllerHandle
,
1475 IN OUT EFI_HANDLE
*DriverImageHandle
1481 // Check that ControllerHandle is a valid handle
1483 if (ControllerHandle
== NULL
) {
1484 return EFI_INVALID_PARAMETER
;
1488 // Read the environment variable(s) that contain the override mappings from Controller Device Path to
1489 // a set of Driver Device Paths, and initialize in memory database of the overrides that map Controller
1490 // Device Paths to an ordered set of Driver Device Paths and Driver Handles. This action is only performed
1491 // once and finished in first call.
1493 if (!mEnvironmentVariableRead
) {
1494 mEnvironmentVariableRead
= TRUE
;
1496 Status
= InitOverridesMapping (&mMappingDataBase
);
1497 if (EFI_ERROR (Status
)){
1498 DEBUG ((DEBUG_ERROR
, "The status to Get Platform Driver Override Variable is %r\n", Status
));
1499 InitializeListHead (&mMappingDataBase
);
1500 return EFI_NOT_FOUND
;
1505 // if the environment variable does not exist, just return not found
1507 if (IsListEmpty (&mMappingDataBase
)) {
1508 return EFI_NOT_FOUND
;
1511 return GetDriverFromMapping (
1520 Retrieves the device path of the platform override driver for a controller in the system.
1521 This driver doesn't support this API.
1523 @param This A pointer to the EFI_PLATFORM_DRIVER_OVERRIDE_
1525 @param ControllerHandle The device handle of the controller to check if a driver override
1527 @param DriverImagePath On input, a pointer to the previous driver device path returned by
1528 GetDriverPath(). On output, a pointer to the next driver
1529 device path. Passing in a pointer to NULL, will return the first
1530 driver device path for ControllerHandle.
1532 @retval EFI_UNSUPPORTED
1537 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL
*This
,
1538 IN EFI_HANDLE ControllerHandle
,
1539 IN OUT EFI_DEVICE_PATH_PROTOCOL
**DriverImagePath
1542 return EFI_UNSUPPORTED
;
1547 Used to associate a driver image handle with a device path that was returned on a prior call to the
1548 GetDriverPath() service. This driver image handle will then be available through the
1549 GetDriver() service. This driver doesn't support this API.
1551 @param This A pointer to the EFI_PLATFORM_DRIVER_OVERRIDE_
1553 @param ControllerHandle The device handle of the controller.
1554 @param DriverImagePath A pointer to the driver device path that was returned in a prior
1555 call to GetDriverPath().
1556 @param DriverImageHandle The driver image handle that was returned by LoadImage()
1557 when the driver specified by DriverImagePath was loaded
1560 @retval EFI_UNSUPPORTED
1565 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL
*This
,
1566 IN EFI_HANDLE ControllerHandle
,
1567 IN EFI_DEVICE_PATH_PROTOCOL
*DriverImagePath
,
1568 IN EFI_HANDLE DriverImageHandle
1571 return EFI_UNSUPPORTED
;
1575 The driver Entry Point. The funciton will export a disk device class formset and
1576 its callback function to hii database.
1578 @param ImageHandle The firmware allocated handle for the EFI image.
1579 @param SystemTable A pointer to the EFI System Table.
1581 @retval EFI_SUCCESS The entry point is executed successfully.
1582 @retval other Some error occurs when executing this entry point.
1587 PlatDriOverrideDxeInit (
1588 IN EFI_HANDLE ImageHandle
,
1589 IN EFI_SYSTEM_TABLE
*SystemTable
1593 EFI_FORM_BROWSER2_PROTOCOL
*FormBrowser2
;
1597 // There should only be one Form Configuration protocol
1599 Status
= gBS
->LocateProtocol (
1600 &gEfiFormBrowser2ProtocolGuid
,
1602 (VOID
**) &FormBrowser2
1604 if (EFI_ERROR (Status
)) {
1609 // According to UEFI spec, there can be at most a single instance
1610 // in the system of the EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL.
1611 // So here we check the existence.
1613 Status
= gBS
->LocateProtocol (
1614 &gEfiPlatformDriverOverrideProtocolGuid
,
1619 // If there was no error, assume there is an installation and return error
1621 if (!EFI_ERROR (Status
)) {
1622 return EFI_ALREADY_STARTED
;
1625 mCallerImageHandle
= ImageHandle
;
1626 mCallbackInfo
= AllocateZeroPool (sizeof (EFI_CALLBACK_INFO
));
1627 if (mCallbackInfo
== NULL
) {
1628 return EFI_BAD_BUFFER_SIZE
;
1631 mCallbackInfo
->Signature
= EFI_CALLBACK_INFO_SIGNATURE
;
1632 mCallbackInfo
->ConfigAccess
.ExtractConfig
= PlatOverMngrExtractConfig
;
1633 mCallbackInfo
->ConfigAccess
.RouteConfig
= PlatOverMngrRouteConfig
;
1634 mCallbackInfo
->ConfigAccess
.Callback
= PlatOverMngrCallback
;
1635 mCallbackInfo
->PlatformDriverOverride
.GetDriver
= GetDriver
;
1636 mCallbackInfo
->PlatformDriverOverride
.GetDriverPath
= GetDriverPath
;
1637 mCallbackInfo
->PlatformDriverOverride
.DriverLoaded
= DriverLoaded
;
1640 // Locate ConfigRouting protocol
1642 Status
= gBS
->LocateProtocol (
1643 &gEfiHiiConfigRoutingProtocolGuid
,
1645 (VOID
**) &mCallbackInfo
->HiiConfigRouting
1647 if (EFI_ERROR (Status
)) {
1652 // Install Device Path Protocol and Config Access protocol to driver handle
1653 // Install Platform Driver Override Protocol to driver handle
1655 Status
= gBS
->InstallMultipleProtocolInterfaces (
1656 &mCallbackInfo
->DriverHandle
,
1657 &gEfiDevicePathProtocolGuid
,
1658 &mHiiVendorDevicePath
,
1659 &gEfiHiiConfigAccessProtocolGuid
,
1660 &mCallbackInfo
->ConfigAccess
,
1661 &gEfiPlatformDriverOverrideProtocolGuid
,
1662 &mCallbackInfo
->PlatformDriverOverride
,
1665 if (EFI_ERROR (Status
)) {
1670 // Publish our HII data
1672 mCallbackInfo
->RegisteredHandle
= HiiAddPackages (
1673 &gPlatformOverridesManagerGuid
,
1674 mCallbackInfo
->DriverHandle
,
1676 PlatDriOverrideDxeStrings
,
1679 if (mCallbackInfo
->RegisteredHandle
== NULL
) {
1680 Status
= EFI_OUT_OF_RESOURCES
;
1685 // Clear all the globle variable
1687 mDriverImageHandleCount
= 0;
1693 PlatDriOverrideDxeUnload (ImageHandle
);
1699 Unload its installed protocol.
1701 @param[in] ImageHandle Handle that identifies the image to be unloaded.
1703 @retval EFI_SUCCESS The image has been unloaded.
1707 PlatDriOverrideDxeUnload (
1708 IN EFI_HANDLE ImageHandle
1711 ASSERT (mCallbackInfo
!= NULL
);
1713 if (mCallbackInfo
->DriverHandle
!= NULL
) {
1714 gBS
->UninstallMultipleProtocolInterfaces (
1715 mCallbackInfo
->DriverHandle
,
1716 &gEfiDevicePathProtocolGuid
,
1717 &mHiiVendorDevicePath
,
1718 &gEfiHiiConfigAccessProtocolGuid
,
1719 &mCallbackInfo
->ConfigAccess
,
1720 &gEfiPlatformDriverOverrideProtocolGuid
,
1721 &mCallbackInfo
->PlatformDriverOverride
,
1726 if (mCallbackInfo
->RegisteredHandle
!= NULL
) {
1727 HiiRemovePackages (mCallbackInfo
->RegisteredHandle
);
1730 FreePool (mCallbackInfo
);
1732 if (mControllerToken
!= NULL
) {
1733 FreePool (mControllerToken
);
1736 if (mControllerDevicePathProtocol
!= NULL
) {
1737 FreePool (mControllerDevicePathProtocol
);
1740 if (mDriverImageToken
!= NULL
) {
1741 FreePool (mDriverImageToken
);