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 - 2010, 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 EFI_GUID mPlatformOverridesManagerGuid
= PLAT_OVER_MNGR_GUID
;
65 CHAR16 mVariableName
[] = L
"Data";
66 LIST_ENTRY mMappingDataBase
= INITIALIZE_LIST_HEAD_VARIABLE (mMappingDataBase
);
67 BOOLEAN mEnvironmentVariableRead
= FALSE
;
68 EFI_HANDLE mCallerImageHandle
= NULL
;
70 EFI_HANDLE
*mDevicePathHandleBuffer
;
71 EFI_HANDLE
*mDriverImageHandleBuffer
;
73 INTN mSelectedCtrIndex
;
74 EFI_STRING_ID mControllerToken
[MAX_CHOICE_NUM
];
75 UINTN mDriverImageHandleCount
;
76 EFI_STRING_ID mDriverImageToken
[MAX_CHOICE_NUM
];
77 EFI_STRING_ID mDriverImageFilePathToken
[MAX_CHOICE_NUM
];
78 EFI_LOADED_IMAGE_PROTOCOL
*mDriverImageProtocol
[MAX_CHOICE_NUM
];
79 EFI_DEVICE_PATH_PROTOCOL
*mControllerDevicePathProtocol
[MAX_CHOICE_NUM
];
80 UINTN mSelectedDriverImageNum
;
81 UINTN mLastSavedDriverImageNum
;
83 EFI_CALLBACK_INFO
*mCallbackInfo
;
85 HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath
= {
91 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
92 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
99 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
101 (UINT8
) (END_DEVICE_PATH_LENGTH
),
102 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
108 Converting a given device to an unicode string.
110 This function will dependent on gEfiDevicePathToTextProtocolGuid, if protocol
111 does not installed, then return unknown device path L"?" directly.
113 @param DevPath Given device path instance
115 @return Converted string from given device path.
116 @retval L"?" Can not locate gEfiDevicePathToTextProtocolGuid protocol for converting.
120 IN EFI_DEVICE_PATH_PROTOCOL
*DevPath
124 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
*DevPathToText
;
127 if (DevPath
== NULL
) {
131 Status
= gBS
->LocateProtocol (
132 &gEfiDevicePathToTextProtocolGuid
,
134 (VOID
**) &DevPathToText
136 if (!EFI_ERROR (Status
)) {
137 ToText
= DevPathToText
->ConvertDevicePathToText (
142 ASSERT (ToText
!= NULL
);
150 Worker function to get the driver name by ComponentName or ComponentName2 protocol
151 according to the driver binding handle.
153 @param DriverBindingHandle The Handle of DriverBinding.
154 @param ProtocolGuid The pointer to Component Name (2) protocol GUID.
155 @param VariableName The name of the RFC 4646 or ISO 639-2 language variable.
157 @retval !NULL Pointer into the image name if the image name is found,
158 @retval NULL Pointer to NULL if the image name is not found.
162 GetComponentNameWorker (
163 IN EFI_HANDLE DriverBindingHandle
,
164 IN EFI_GUID
*ProtocolGuid
,
165 IN CONST CHAR16
*VariableName
169 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
174 Status
= gBS
->OpenProtocol (
177 (VOID
*) &ComponentName
,
180 EFI_OPEN_PROTOCOL_GET_PROTOCOL
182 if (EFI_ERROR (Status
)) {
187 // Find the best matching language.
189 Language
= GetEfiGlobalVariable (VariableName
);
190 BestLanguage
= GetBestLanguage (
191 ComponentName
->SupportedLanguages
,
192 (BOOLEAN
) (ProtocolGuid
== &gEfiComponentNameProtocolGuid
),
198 if (BestLanguage
!= NULL
) {
199 ComponentName
->GetDriverName (
204 FreePool (BestLanguage
);
207 if (Language
!= NULL
) {
216 Get the driver name by ComponentName or ComponentName2 protocol
217 according to the driver binding handle
219 @param DriverBindingHandle The Handle of DriverBinding.
221 @retval !NULL Pointer into the image name if the image name is found,
222 @retval NULL Pointer to NULL if the image name is not found.
227 IN EFI_HANDLE DriverBindingHandle
233 // Try RFC 4646 Component Name 2 protocol first.
235 DriverName
= GetComponentNameWorker (DriverBindingHandle
, &gEfiComponentName2ProtocolGuid
, L
"PlatformLang");
236 if (DriverName
== NULL
) {
238 // If we can not get driver name from Component Name 2 protocol, we can try ISO 639-2 Component Name protocol.
240 DriverName
= GetComponentNameWorker (DriverBindingHandle
, &gEfiComponentNameProtocolGuid
, L
"Lang");
247 Get the image name from EFI UI section.
248 Get FV protocol by its loaded image protocol to abstract EFI UI section.
250 @param Image Pointer to the loaded image protocol
252 @retval !NULL Pointer to the image name if the image name is found,
253 @retval NULL NULL if the image name is not found.
258 IN EFI_LOADED_IMAGE_PROTOCOL
*Image
262 EFI_DEVICE_PATH_PROTOCOL
*DevPathNode
;
263 EFI_DEVICE_PATH_PROTOCOL
*AlignedDevPathNode
;
264 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*FvFilePath
;
267 UINT32 AuthenticationStatus
;
269 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv2
;
275 if (Image
->FilePath
== NULL
) {
278 DevPathNode
= Image
->FilePath
;
280 while (!IsDevicePathEnd (DevPathNode
)) {
282 // Make sure device path node is aligned when accessing it's FV Name Guid field.
284 AlignedDevPathNode
= AllocateCopyPool (DevicePathNodeLength(DevPathNode
), DevPathNode
);
287 // Find the Fv File path
289 NameGuid
= EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*)AlignedDevPathNode
);
290 if (NameGuid
!= NULL
) {
291 FvFilePath
= (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*) AlignedDevPathNode
;
292 Status
= gBS
->HandleProtocol (
294 &gEfiFirmwareVolume2ProtocolGuid
,
298 // Locate Image EFI UI section to get the image name.
300 if (!EFI_ERROR (Status
)) {
301 Status
= Fv2
->ReadSection (
303 &FvFilePath
->FvFileName
,
304 EFI_SECTION_USER_INTERFACE
,
308 &AuthenticationStatus
310 if (!EFI_ERROR (Status
)) {
311 FreePool (AlignedDevPathNode
);
318 FreePool (AlignedDevPathNode
);
321 // Next device path node
323 DevPathNode
= NextDevicePathNode (DevPathNode
);
330 Prepare the first page to let user select the device controller which need to
331 add mapping drivers if user select 'Refresh' in first page.
332 During first page, user will see all currnet controller device path in system,
333 select any device path will go to second page to select its overrides drivers.
335 @param Private Pointer to EFI_CALLBACK_INFO.
336 @param KeyValue The callback key value of device controller item in first page.
337 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
339 @retval EFI_SUCCESS Always returned.
343 UpdateDeviceSelectPage (
344 IN EFI_CALLBACK_INFO
*Private
,
346 IN PLAT_OVER_MNGR_DATA
*FakeNvData
351 UINTN DevicePathHandleCount
;
353 EFI_STRING_ID NewStringToken
;
354 CHAR16
*ControllerName
;
355 EFI_DEVICE_PATH_PROTOCOL
*ControllerDevicePath
;
356 EFI_PCI_IO_PROTOCOL
*PciIo
;
357 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*BusSpecificDriverOverride
;
359 VOID
*StartOpCodeHandle
;
360 VOID
*EndOpCodeHandle
;
361 EFI_IFR_GUID_LABEL
*StartLabel
;
362 EFI_IFR_GUID_LABEL
*EndLabel
;
365 // Set current page form ID.
367 mCurrentPage
= FORM_ID_DEVICE
;
370 // Initial the mapping database in memory
372 FreeMappingDatabase (&mMappingDataBase
);
373 InitOverridesMapping (&mMappingDataBase
);
376 // Init OpCode Handle
378 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
379 ASSERT (StartOpCodeHandle
!= NULL
);
381 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
382 ASSERT (EndOpCodeHandle
!= NULL
);
385 // Create Hii Extend Label OpCode as the start opcode
387 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
388 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
389 StartLabel
->Number
= FORM_ID_DEVICE
;
392 // Create Hii Extend Label OpCode as the end opcode
394 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
395 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
396 EndLabel
->Number
= LABEL_END
;
399 // Clear first page form
402 Private
->RegisteredHandle
,
403 &mPlatformOverridesManagerGuid
,
405 StartOpCodeHandle
, // Label FORM_ID_DEVICE
406 EndOpCodeHandle
// LABEL_END
410 // When user enter the page at first time, the 'first refresh' string is given to notify user to refresh all the drivers,
411 // then the 'first refresh' string will be replaced by the 'refresh' string, and the two strings content are same after the replacement
413 NewStringToken
= STRING_TOKEN (STR_FIRST_REFRESH
);
414 NewString
= HiiGetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_REFRESH
), NULL
);
415 ASSERT (NewString
!= NULL
);
416 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
, NULL
) == 0) {
419 FreePool (NewString
);
421 NewStringToken
= STRING_TOKEN (STR_FIRST_REFRESH_HELP
);
422 NewString
= HiiGetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_REFRESH_HELP
), NULL
);
423 ASSERT (NewString
!= NULL
);
424 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
, NULL
) == 0) {
427 FreePool (NewString
);
430 // created needed controller device item in first page
432 DevicePathHandleCount
= 0;
433 Status
= gBS
->LocateHandleBuffer (
435 &gEfiDevicePathProtocolGuid
,
437 &DevicePathHandleCount
,
438 &mDevicePathHandleBuffer
440 if (EFI_ERROR (Status
) || (DevicePathHandleCount
== 0)) {
444 for (Index
= 0; Index
< DevicePathHandleCount
; Index
++) {
445 if (FakeNvData
->PciDeviceFilter
== 0x01) {
447 // Only care PCI device which contain efi driver in its option rom.
451 // Check whether it is a pci device
453 ControllerDevicePath
= NULL
;
454 Status
= gBS
->OpenProtocol (
455 mDevicePathHandleBuffer
[Index
],
456 &gEfiPciIoProtocolGuid
,
460 EFI_OPEN_PROTOCOL_GET_PROTOCOL
462 if (EFI_ERROR (Status
)) {
466 // Check whether it contain efi driver in its option rom
468 Status
= gBS
->HandleProtocol(
469 mDevicePathHandleBuffer
[Index
],
470 &gEfiBusSpecificDriverOverrideProtocolGuid
,
471 (VOID
**) &BusSpecificDriverOverride
473 if (EFI_ERROR (Status
) || BusSpecificDriverOverride
== NULL
) {
478 ControllerDevicePath
= NULL
;
479 Status
= gBS
->OpenProtocol (
480 mDevicePathHandleBuffer
[Index
],
481 &gEfiDevicePathProtocolGuid
,
482 (VOID
**) &ControllerDevicePath
,
485 EFI_OPEN_PROTOCOL_GET_PROTOCOL
487 ASSERT_EFI_ERROR (Status
);
489 // Save the device path protocol interface
491 mControllerDevicePathProtocol
[Index
] = ControllerDevicePath
;
494 // Get the driver name
496 ControllerName
= DevicePathToStr (ControllerDevicePath
);
499 // Export the driver name string and create item in set options page
501 Len
= StrSize (ControllerName
);
502 NewString
= AllocateZeroPool (Len
+ StrSize (L
"--"));
503 ASSERT (NewString
!= NULL
);
504 if (EFI_ERROR (CheckMapping (ControllerDevicePath
,NULL
, &mMappingDataBase
, NULL
, NULL
))) {
505 StrCat (NewString
, L
"--");
507 StrCat (NewString
, L
"**");
509 StrCat (NewString
, ControllerName
);
511 NewStringToken
= HiiSetString (Private
->RegisteredHandle
, mControllerToken
[Index
], NewString
, NULL
);
512 ASSERT (NewStringToken
!= 0);
513 FreePool (NewString
);
515 // Save the device path string toke for next access use
517 mControllerToken
[Index
] = NewStringToken
;
519 HiiCreateGotoOpCode (
523 STRING_TOKEN (STR_GOTO_HELP_DRIVER
),
524 EFI_IFR_FLAG_CALLBACK
,
525 (UINT16
) (Index
+ KEY_VALUE_DEVICE_OFFSET
)
530 // Update first page form
533 Private
->RegisteredHandle
,
534 &mPlatformOverridesManagerGuid
,
536 StartOpCodeHandle
, // Label FORM_ID_DEVICE
537 EndOpCodeHandle
// LABEL_END
540 HiiFreeOpCodeHandle (StartOpCodeHandle
);
541 HiiFreeOpCodeHandle (EndOpCodeHandle
);
547 Get the first Driver Binding handle which has the specific image handle.
549 @param ImageHandle The Image handle
551 @return Handle to Driver binding
552 @retval NULL The paramter is not valid or the driver binding handle is not found.
556 GetDriverBindingHandleFromImageHandle (
557 IN EFI_HANDLE ImageHandle
562 UINTN DriverBindingHandleCount
;
563 EFI_HANDLE
*DriverBindingHandleBuffer
;
564 EFI_DRIVER_BINDING_PROTOCOL
*DriverBindingInterface
;
565 EFI_HANDLE DriverBindingHandle
;
567 DriverBindingHandle
= NULL
;
569 if (ImageHandle
== NULL
) {
573 // Get all drivers which support driver binding protocol
575 DriverBindingHandleCount
= 0;
576 Status
= gBS
->LocateHandleBuffer (
578 &gEfiDriverBindingProtocolGuid
,
580 &DriverBindingHandleCount
,
581 &DriverBindingHandleBuffer
583 if (EFI_ERROR (Status
) || (DriverBindingHandleCount
== 0)) {
588 // Get the first Driver Binding handle which has the specific image handle.
590 for (Index
= 0; Index
< DriverBindingHandleCount
; Index
++) {
591 DriverBindingInterface
= NULL
;
592 Status
= gBS
->OpenProtocol (
593 DriverBindingHandleBuffer
[Index
],
594 &gEfiDriverBindingProtocolGuid
,
595 (VOID
**) &DriverBindingInterface
,
598 EFI_OPEN_PROTOCOL_GET_PROTOCOL
600 if (EFI_ERROR (Status
)) {
604 if (DriverBindingInterface
->ImageHandle
== ImageHandle
) {
605 DriverBindingHandle
= DriverBindingHandleBuffer
[Index
];
610 FreePool (DriverBindingHandleBuffer
);
611 return DriverBindingHandle
;
615 Prepare to let user select the drivers which need mapping with the device controller
616 selected in first page.
618 @param Private Pointer to EFI_CALLBACK_INFO.
619 @param KeyValue The callback key value of device controller item in first page.
620 KeyValue is larger than or equal to KEY_VALUE_DEVICE_OFFSET.
621 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
623 @retval EFI_SUCCESS Always returned.
627 UpdateBindingDriverSelectPage (
628 IN EFI_CALLBACK_INFO
*Private
,
630 IN PLAT_OVER_MNGR_DATA
*FakeNvData
636 EFI_STRING_ID NewStringToken
;
637 EFI_STRING_ID NewStringHelpToken
;
638 UINTN DriverImageHandleCount
;
639 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
641 BOOLEAN FreeDriverName
;
642 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
643 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*BusSpecificDriverOverride
;
644 EFI_HANDLE DriverBindingHandle
;
645 VOID
*StartOpCodeHandle
;
646 VOID
*EndOpCodeHandle
;
647 EFI_IFR_GUID_LABEL
*StartLabel
;
648 EFI_IFR_GUID_LABEL
*EndLabel
;
651 // If user select a controller item in the first page the following code will be run.
652 // During second page, user will see all currnet driver bind protocol driver, the driver name and its device path will be shown
654 //First acquire the list of Loaded Image Protocols, and then when want the name of the driver, look up all the Driver Binding Protocols
655 // and find the first one whose ImageHandle field matches the image handle of the Loaded Image Protocol.
656 // 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.
659 mCurrentPage
= FORM_ID_DRIVER
;
661 // Switch the item callback key value to its NO. in mDevicePathHandleBuffer
663 mSelectedCtrIndex
= KeyValue
- KEY_VALUE_DEVICE_OFFSET
;
664 ASSERT (mSelectedCtrIndex
< MAX_CHOICE_NUM
);
666 mLastSavedDriverImageNum
= 0;
669 // Init OpCode Handle
671 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
672 ASSERT (StartOpCodeHandle
!= NULL
);
674 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
675 ASSERT (EndOpCodeHandle
!= NULL
);
678 // Create Hii Extend Label OpCode as the start opcode
680 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
681 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
682 StartLabel
->Number
= FORM_ID_DRIVER
;
685 // Create Hii Extend Label OpCode as the end opcode
687 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
688 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
689 EndLabel
->Number
= LABEL_END
;
692 // Clear second page form
695 Private
->RegisteredHandle
,
696 &mPlatformOverridesManagerGuid
,
703 // Show all driver which support loaded image protocol in second page
705 DriverImageHandleCount
= 0;
706 Status
= gBS
->LocateHandleBuffer (
708 &gEfiLoadedImageProtocolGuid
,
710 &DriverImageHandleCount
,
711 &mDriverImageHandleBuffer
713 if (EFI_ERROR (Status
) || (DriverImageHandleCount
== 0)) {
714 return EFI_NOT_FOUND
;
717 mDriverImageHandleCount
= DriverImageHandleCount
;
718 for (Index
= 0; Index
< DriverImageHandleCount
; Index
++) {
720 // Step1: Get the driver image total file path for help string and the driver name.
724 // Find driver's Loaded Image protocol
728 Status
= gBS
->OpenProtocol (
729 mDriverImageHandleBuffer
[Index
],
730 &gEfiLoadedImageProtocolGuid
,
731 (VOID
**) &LoadedImage
,
734 EFI_OPEN_PROTOCOL_GET_PROTOCOL
736 if (EFI_ERROR (Status
)) {
737 FakeNvData
->DriSelection
[Index
] = 0x00;
740 mDriverImageProtocol
[Index
] = LoadedImage
;
742 // Find its related driver binding protocol
744 DriverBindingHandle
= GetDriverBindingHandleFromImageHandle (mDriverImageHandleBuffer
[Index
]);
745 if (DriverBindingHandle
== NULL
) {
746 FakeNvData
->DriSelection
[Index
] = 0x00;
751 // Get the EFI Loaded Image Device Path Protocol
753 LoadedImageDevicePath
= NULL
;
754 Status
= gBS
->HandleProtocol (
755 mDriverImageHandleBuffer
[Index
],
756 &gEfiLoadedImageDevicePathProtocolGuid
,
757 (VOID
**) &LoadedImageDevicePath
759 if (LoadedImageDevicePath
== NULL
) {
760 FakeNvData
->DriSelection
[Index
] = 0x00;
764 if (FakeNvData
->PciDeviceFilter
== 0x01) {
766 // only care the driver which is in a Pci device option rom,
767 // and the driver's LoadedImage->DeviceHandle must point to a pci device which has efi option rom
769 if (!EFI_ERROR (Status
)) {
770 Status
= gBS
->HandleProtocol(
771 LoadedImage
->DeviceHandle
,
772 &gEfiBusSpecificDriverOverrideProtocolGuid
,
773 (VOID
**) &BusSpecificDriverOverride
775 if (EFI_ERROR (Status
) || BusSpecificDriverOverride
== NULL
) {
776 FakeNvData
->DriSelection
[Index
] = 0x00;
780 FakeNvData
->DriSelection
[Index
] = 0x00;
786 // For driver name, try to get its component name, if fail, get its image name,
787 // if also fail, give a default name.
789 FreeDriverName
= FALSE
;
790 DriverName
= GetComponentName (DriverBindingHandle
);
791 if (DriverName
== NULL
) {
793 // get its image name
795 DriverName
= GetImageName (LoadedImage
);
797 if (DriverName
== NULL
) {
799 // give a default name
801 DriverName
= HiiGetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_DRIVER_DEFAULT_NAME
), NULL
);
802 ASSERT (DriverName
!= NULL
);
803 FreeDriverName
= TRUE
; // the DriverName string need to free pool
808 // Step2 Export the driver name string and create check box item in second page
812 // First create the driver image name
814 NewString
= AllocateZeroPool (StrSize (DriverName
));
815 ASSERT (NewString
!= NULL
);
816 if (EFI_ERROR (CheckMapping (mControllerDevicePathProtocol
[mSelectedCtrIndex
], LoadedImageDevicePath
, &mMappingDataBase
, NULL
, NULL
))) {
817 FakeNvData
->DriSelection
[Index
] = 0x00;
819 FakeNvData
->DriSelection
[Index
] = 0x01;
820 mLastSavedDriverImageNum
++;
822 StrCat (NewString
, DriverName
);
823 NewStringToken
= HiiSetString (Private
->RegisteredHandle
, mDriverImageToken
[Index
], NewString
, NULL
);
824 ASSERT (NewStringToken
!= 0);
825 mDriverImageToken
[Index
] = NewStringToken
;
826 FreePool (NewString
);
827 if (FreeDriverName
) {
828 FreePool (DriverName
);
832 // Second create the driver image device path as item help string
834 DriverName
= DevicePathToStr (LoadedImageDevicePath
);
836 NewString
= AllocateZeroPool (StrSize (DriverName
));
837 ASSERT (NewString
!= NULL
);
838 StrCat (NewString
, DriverName
);
839 NewStringHelpToken
= HiiSetString (Private
->RegisteredHandle
, mDriverImageFilePathToken
[Index
], NewString
, NULL
);
840 ASSERT (NewStringHelpToken
!= 0);
841 mDriverImageFilePathToken
[Index
] = NewStringHelpToken
;
842 FreePool (NewString
);
843 FreePool (DriverName
);
845 HiiCreateCheckBoxOpCode (
847 (UINT16
) (DRIVER_SELECTION_QUESTION_ID
+ Index
),
848 VARSTORE_ID_PLAT_OVER_MNGR
,
849 (UINT16
) (DRIVER_SELECTION_VAR_OFFSET
+ Index
),
859 // Update second page form
862 Private
->RegisteredHandle
,
863 &mPlatformOverridesManagerGuid
,
865 StartOpCodeHandle
, // Label FORM_ID_DRIVER
866 EndOpCodeHandle
// LABEL_END
869 HiiFreeOpCodeHandle (StartOpCodeHandle
);
870 HiiFreeOpCodeHandle (EndOpCodeHandle
);
875 Prepare to let user select the priority order of the drivers which are
876 selected in second page.
878 @param Private Pointer to EFI_CALLBACK_INFO.
879 @param KeyValue The callback key value of device controller item in first page.
880 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
882 @retval EFI_SUCCESS Always returned.
886 UpdatePrioritySelectPage (
887 IN EFI_CALLBACK_INFO
*Private
,
889 IN PLAT_OVER_MNGR_DATA
*FakeNvData
893 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
894 UINTN SelectedDriverImageNum
;
895 UINT32 DriverImageNO
;
900 VOID
*StartOpCodeHandle
;
901 VOID
*EndOpCodeHandle
;
902 VOID
*OptionsOpCodeHandle
;
903 EFI_IFR_GUID_LABEL
*StartLabel
;
904 EFI_IFR_GUID_LABEL
*EndLabel
;
907 // Following code will be run if user select 'order ... priority' item in second page
908 // Prepare third page. In third page, user will order the drivers priority which are selected in second page
910 mCurrentPage
= FORM_ID_ORDER
;
913 // Init OpCode Handle
915 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
916 ASSERT (StartOpCodeHandle
!= NULL
);
918 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
919 ASSERT (EndOpCodeHandle
!= NULL
);
922 // Create Hii Extend Label OpCode as the start opcode
924 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
925 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
926 StartLabel
->Number
= FORM_ID_ORDER
;
929 // Create Hii Extend Label OpCode as the end opcode
931 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
932 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
933 EndLabel
->Number
= LABEL_END
;
936 // Clear third page form
939 Private
->RegisteredHandle
,
940 &mPlatformOverridesManagerGuid
,
947 // Check how many drivers have been selected
949 SelectedDriverImageNum
= 0;
950 for (Index
= 0; Index
< mDriverImageHandleCount
; Index
++) {
951 if (FakeNvData
->DriSelection
[Index
] != 0) {
952 SelectedDriverImageNum
++;
956 mSelectedDriverImageNum
= SelectedDriverImageNum
;
957 if (SelectedDriverImageNum
== 0) {
961 OptionsOpCodeHandle
= HiiAllocateOpCodeHandle ();
962 ASSERT (OptionsOpCodeHandle
!= NULL
);
965 // Create order list for those selected drivers
967 SelectedDriverImageNum
= 0;
968 for (Index
= 0; Index
< mDriverImageHandleCount
; Index
++) {
969 if (FakeNvData
->DriSelection
[Index
] != 0) {
971 // Use the NO. in driver binding buffer as value, will use it later
973 HiiCreateOneOfOptionOpCode (
975 mDriverImageToken
[Index
],
977 EFI_IFR_NUMERIC_SIZE_1
,
982 // Get the EFI Loaded Image Device Path Protocol
984 LoadedImageDevicePath
= NULL
;
985 gBS
->HandleProtocol (
986 mDriverImageHandleBuffer
[Index
],
987 &gEfiLoadedImageDevicePathProtocolGuid
,
988 (VOID
**) &LoadedImageDevicePath
990 ASSERT (LoadedImageDevicePath
!= NULL
);
993 // Check the driver DriverImage's order number in mapping database
997 mControllerDevicePathProtocol
[mSelectedCtrIndex
],
998 LoadedImageDevicePath
,
1003 if (DriverImageNO
== 0) {
1004 DriverImageNO
= (UINT32
) mLastSavedDriverImageNum
+ 1;
1005 mLastSavedDriverImageNum
++;
1007 TempNO
[SelectedDriverImageNum
] = DriverImageNO
;
1008 OrderNO
[SelectedDriverImageNum
] = Index
+ 1;
1009 SelectedDriverImageNum
++;
1013 ASSERT (SelectedDriverImageNum
== mSelectedDriverImageNum
);
1015 // NvRamMap Must be clear firstly
1017 ZeroMem (FakeNvData
->DriOrder
, sizeof (FakeNvData
->DriOrder
));
1020 // Order the selected drivers according to the info already in mapping database
1021 // the less order number in mapping database the less order number in NvRamMap
1023 for (Index
=0; Index
< SelectedDriverImageNum
; Index
++) {
1025 // Find the minimal order number in TempNO array, its index in TempNO is same as IfrOptionList array
1028 for (Index1
=0; Index1
< SelectedDriverImageNum
; Index1
++) {
1029 if (TempNO
[Index1
] < TempNO
[MinNO
]) {
1034 // the IfrOptionList[MinNO].Value = the driver NO. in driver binding buffer
1036 FakeNvData
->DriOrder
[Index
] = (UINT8
) OrderNO
[MinNO
];
1037 TempNO
[MinNO
] = MAX_CHOICE_NUM
+ 1;
1041 // Create Order List OpCode
1043 HiiCreateOrderedListOpCode (
1045 (UINT16
) DRIVER_ORDER_QUESTION_ID
,
1046 VARSTORE_ID_PLAT_OVER_MNGR
,
1047 (UINT16
) DRIVER_ORDER_VAR_OFFSET
,
1048 mControllerToken
[mSelectedCtrIndex
],
1049 mControllerToken
[mSelectedCtrIndex
],
1050 EFI_IFR_FLAG_RESET_REQUIRED
,
1052 EFI_IFR_NUMERIC_SIZE_1
,
1053 (UINT8
) MAX_CHOICE_NUM
,
1054 OptionsOpCodeHandle
,
1059 // Update third page form
1062 Private
->RegisteredHandle
,
1063 &mPlatformOverridesManagerGuid
,
1065 StartOpCodeHandle
, // Label FORM_ID_ORDER
1066 EndOpCodeHandle
// LABEL_END
1069 HiiFreeOpCodeHandle (StartOpCodeHandle
);
1070 HiiFreeOpCodeHandle (EndOpCodeHandle
);
1071 HiiFreeOpCodeHandle (OptionsOpCodeHandle
);
1077 Save the save the mapping database to NV variable.
1079 @param Private Pointer to EFI_CALLBACK_INFO.
1080 @param KeyValue The callback key value of device controller item in first page.
1081 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
1083 @retval EFI_SUCCESS Always returned.
1088 IN EFI_CALLBACK_INFO
*Private
,
1090 IN PLAT_OVER_MNGR_DATA
*FakeNvData
1095 UINTN SelectedDriverImageNum
;
1096 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
1098 // Following code will be run if user select 'commint changes' in third page
1099 // user enter 'Commit Changes' to save the mapping database
1101 DeleteDriverImage (mControllerDevicePathProtocol
[mSelectedCtrIndex
], NULL
, &mMappingDataBase
);
1102 for (SelectedDriverImageNum
= 0; SelectedDriverImageNum
< mSelectedDriverImageNum
; SelectedDriverImageNum
++) {
1104 // DriOrder[SelectedDriverImageNum] = the driver NO. in driver binding buffer
1106 Index
= FakeNvData
->DriOrder
[SelectedDriverImageNum
] - 1;
1109 // Get the EFI Loaded Image Device Path Protocol
1111 LoadedImageDevicePath
= NULL
;
1112 Status
= gBS
->HandleProtocol (
1113 mDriverImageHandleBuffer
[Index
],
1114 &gEfiLoadedImageDevicePathProtocolGuid
,
1115 (VOID
**) &LoadedImageDevicePath
1117 ASSERT (LoadedImageDevicePath
!= NULL
);
1120 mControllerDevicePathProtocol
[mSelectedCtrIndex
],
1121 LoadedImageDevicePath
,
1123 (UINT32
)SelectedDriverImageNum
+ 1
1126 Status
= SaveOverridesMapping (&mMappingDataBase
);
1132 This function allows a caller to extract the current configuration for one
1133 or more named elements from the target driver.
1135 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1136 @param Request A null-terminated Unicode string in <ConfigRequest> format.
1137 @param Progress On return, points to a character in the Request string.
1138 Points to the string's null terminator if request was successful.
1139 Points to the most recent '&' before the first failing name/value
1140 pair (or the beginning of the string if the failure is in the
1141 first name/value pair) if the request was not successful.
1142 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
1143 has all values filled in for the names in the Request string.
1144 String to be allocated by the called function.
1146 @retval EFI_SUCCESS The Results is filled with the requested values.
1147 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
1148 @retval EFI_INVALID_PARAMETER Request is NULL, illegal syntax, or unknown name.
1149 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
1154 PlatOverMngrExtractConfig (
1155 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1156 IN CONST EFI_STRING Request
,
1157 OUT EFI_STRING
*Progress
,
1158 OUT EFI_STRING
*Results
1162 EFI_CALLBACK_INFO
*Private
;
1163 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
1164 EFI_STRING ConfigRequestHdr
;
1165 EFI_STRING ConfigRequest
;
1166 BOOLEAN AllocatedRequest
;
1170 if (Progress
== NULL
|| Results
== NULL
) {
1171 return EFI_INVALID_PARAMETER
;
1174 *Progress
= Request
;
1175 if ((Request
!= NULL
) && !HiiIsConfigHdrMatch (Request
, &mPlatformOverridesManagerGuid
, mVariableName
)) {
1176 return EFI_NOT_FOUND
;
1179 ConfigRequestHdr
= NULL
;
1180 ConfigRequest
= NULL
;
1182 AllocatedRequest
= FALSE
;
1184 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1185 HiiConfigRouting
= Private
->HiiConfigRouting
;
1186 ConfigRequest
= Request
;
1187 if ((Request
== NULL
) || (StrStr (Request
, L
"OFFSET") == NULL
)) {
1189 // Request has no request element, construct full request string.
1190 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
1191 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
1193 ConfigRequestHdr
= HiiConstructConfigHdr (&mPlatformOverridesManagerGuid
, mVariableName
, Private
->DriverHandle
);
1194 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
1195 ConfigRequest
= AllocateZeroPool (Size
);
1196 ASSERT (ConfigRequest
!= NULL
);
1197 AllocatedRequest
= TRUE
;
1198 BufferSize
= sizeof (PLAT_OVER_MNGR_DATA
);
1199 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr
, (UINT64
)BufferSize
);
1200 FreePool (ConfigRequestHdr
);
1204 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
1206 Status
= HiiConfigRouting
->BlockToConfig (
1209 (UINT8
*) &Private
->FakeNvData
,
1210 sizeof (PLAT_OVER_MNGR_DATA
),
1216 // Free the allocated config request string.
1218 if (AllocatedRequest
) {
1219 FreePool (ConfigRequest
);
1220 ConfigRequest
= NULL
;
1223 // Set Progress string to the original request string.
1225 if (Request
== NULL
) {
1227 } else if (StrStr (Request
, L
"OFFSET") == NULL
) {
1228 *Progress
= Request
+ StrLen (Request
);
1235 This function processes the results of changes in configuration.
1237 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1238 @param Configuration A null-terminated Unicode string in <ConfigRequest> format.
1239 @param Progress A pointer to a string filled in with the offset of the most
1240 recent '&' before the first failing name/value pair (or the
1241 beginning of the string if the failure is in the first
1242 name/value pair) or the terminating NULL if all was successful.
1244 @retval EFI_SUCCESS The Results is processed successfully.
1245 @retval EFI_INVALID_PARAMETER Configuration is NULL.
1246 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
1251 PlatOverMngrRouteConfig (
1252 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1253 IN CONST EFI_STRING Configuration
,
1254 OUT EFI_STRING
*Progress
1257 EFI_CALLBACK_INFO
*Private
;
1259 PLAT_OVER_MNGR_DATA
*FakeNvData
;
1261 if (Configuration
== NULL
|| Progress
== NULL
) {
1262 return EFI_INVALID_PARAMETER
;
1264 *Progress
= Configuration
;
1266 if (!HiiIsConfigHdrMatch (Configuration
, &mPlatformOverridesManagerGuid
, mVariableName
)) {
1267 return EFI_NOT_FOUND
;
1270 *Progress
= Configuration
+ StrLen (Configuration
);
1271 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1272 FakeNvData
= &Private
->FakeNvData
;
1273 if (!HiiGetBrowserData (&mPlatformOverridesManagerGuid
, mVariableName
, sizeof (PLAT_OVER_MNGR_DATA
), (UINT8
*) FakeNvData
)) {
1275 // FakeNvData can't be got from SetupBrowser, which doesn't need to be set.
1280 if (mCurrentPage
== FORM_ID_DRIVER
) {
1281 KeyValue
= KEY_VALUE_DRIVER_GOTO_ORDER
;
1282 UpdatePrioritySelectPage (Private
, KeyValue
, FakeNvData
);
1283 KeyValue
= KEY_VALUE_ORDER_SAVE_AND_EXIT
;
1284 CommintChanges (Private
, KeyValue
, FakeNvData
);
1286 // Since UpdatePrioritySelectPage will change mCurrentPage,
1287 // should ensure the mCurrentPage still indicate the second page here
1289 mCurrentPage
= FORM_ID_DRIVER
;
1292 if (mCurrentPage
== FORM_ID_ORDER
) {
1293 KeyValue
= KEY_VALUE_ORDER_SAVE_AND_EXIT
;
1294 CommintChanges (Private
, KeyValue
, FakeNvData
);
1301 This is the function that is called to provide results data to the driver. This data
1302 consists of a unique key which is used to identify what data is either being passed back
1305 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1306 @param Action A null-terminated Unicode string in <ConfigRequest> format.
1307 @param KeyValue A unique Goto OpCode callback value which record user's selection.
1308 0x100 <= KeyValue <0x500 : user select a controller item in the first page;
1309 KeyValue == 0x1234 : user select 'Refresh' in first page, or user select 'Go to Previous Menu' in second page
1310 KeyValue == 0x1235 : user select 'Pci device filter' in first page
1311 KeyValue == 0x1500 : user select 'order ... priority' item in second page
1312 KeyValue == 0x1800 : user select 'commint changes' in third page
1313 KeyValue == 0x2000 : user select 'Go to Previous Menu' in third page
1314 @param Type The type of value for the question.
1315 @param Value A pointer to the data being sent to the original exporting driver.
1316 @param ActionRequest On return, points to the action requested by the callback function.
1318 @retval EFI_SUCCESS Always returned.
1323 PlatOverMngrCallback (
1324 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1325 IN EFI_BROWSER_ACTION Action
,
1326 IN EFI_QUESTION_ID KeyValue
,
1328 IN EFI_IFR_TYPE_VALUE
*Value
,
1329 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
1332 EFI_CALLBACK_INFO
*Private
;
1334 EFI_STRING_ID NewStringToken
;
1336 PLAT_OVER_MNGR_DATA
*FakeNvData
;
1338 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1339 FakeNvData
= &Private
->FakeNvData
;
1340 if (!HiiGetBrowserData (&mPlatformOverridesManagerGuid
, mVariableName
, sizeof (PLAT_OVER_MNGR_DATA
), (UINT8
*) FakeNvData
)) {
1341 return EFI_NOT_FOUND
;
1344 if (KeyValue
== KEY_VALUE_DEVICE_REFRESH
||
1345 KeyValue
== KEY_VALUE_DEVICE_FILTER
||
1346 KeyValue
== KEY_VALUE_DRIVER_GOTO_PREVIOUS
1348 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1350 // Update page title string
1352 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1353 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, L
"First, Select the controller by device path", NULL
) == 0) {
1358 if (((KeyValue
>= KEY_VALUE_DEVICE_OFFSET
) && (KeyValue
< KEY_VALUE_DEVICE_MAX
)) || (KeyValue
== KEY_VALUE_ORDER_GOTO_PREVIOUS
)) {
1359 if (KeyValue
== KEY_VALUE_ORDER_GOTO_PREVIOUS
) {
1360 KeyValue
= (EFI_QUESTION_ID
) (mSelectedCtrIndex
+ KEY_VALUE_DEVICE_OFFSET
);
1362 UpdateBindingDriverSelectPage (Private
, KeyValue
, FakeNvData
);
1364 // Update page title string
1366 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1367 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, L
"Second, Select drivers for the previous selected controller", NULL
) == 0) {
1372 if (KeyValue
== KEY_VALUE_DRIVER_GOTO_ORDER
) {
1373 UpdatePrioritySelectPage (Private
, KeyValue
, FakeNvData
);
1375 // Update page title string
1377 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1378 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, L
"Finally, Set the priority order for the drivers and save them", NULL
) == 0) {
1383 if (KeyValue
== KEY_VALUE_ORDER_SAVE_AND_EXIT
) {
1384 Status
= CommintChanges (Private
, KeyValue
, FakeNvData
);
1385 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1386 if (EFI_ERROR (Status
)) {
1387 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Single Override Info too large, Saving Error!", NULL
);
1388 return EFI_DEVICE_ERROR
;
1392 if (KeyValue
== KEY_VALUE_DEVICE_CLEAR
) {
1394 // Deletes all environment variable(s) that contain the override mappings info
1396 FreeMappingDatabase (&mMappingDataBase
);
1397 Status
= SaveOverridesMapping (&mMappingDataBase
);
1398 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1401 // Pass changed uncommitted data back to Form Browser
1403 HiiSetBrowserData (&mPlatformOverridesManagerGuid
, mVariableName
, sizeof (PLAT_OVER_MNGR_DATA
), (UINT8
*) FakeNvData
, NULL
);
1409 Retrieves the image handle of the platform override driver for a controller in the system.
1411 @param This A pointer to the
1412 EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL instance.
1413 @param ControllerHandle The device handle of the controller to check if a
1414 driver override exists.
1415 @param DriverImageHandle On input, a pointer to the previous driver image
1416 handle returned by GetDriver(). On output, a
1417 pointer to the next driver image handle. Passing
1418 in a NULL, will return the first driver image
1419 handle for ControllerHandle.
1421 @retval EFI_SUCCESS The driver override for ControllerHandle was
1422 returned in DriverImageHandle.
1423 @retval EFI_NOT_FOUND A driver override for ControllerHandle was not
1425 @retval EFI_INVALID_PARAMETER The handle specified by ControllerHandle is not a
1426 valid handle. DriverImageHandle is not a handle
1427 that was returned on a previous call to
1434 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL
*This
,
1435 IN EFI_HANDLE ControllerHandle
,
1436 IN OUT EFI_HANDLE
*DriverImageHandle
1442 // Check that ControllerHandle is a valid handle
1444 if (ControllerHandle
== NULL
) {
1445 return EFI_INVALID_PARAMETER
;
1449 // Read the environment variable(s) that contain the override mappings from Controller Device Path to
1450 // a set of Driver Device Paths, and initialize in memory database of the overrides that map Controller
1451 // Device Paths to an ordered set of Driver Device Paths and Driver Handles. This action is only performed
1452 // once and finished in first call.
1454 if (!mEnvironmentVariableRead
) {
1455 mEnvironmentVariableRead
= TRUE
;
1457 Status
= InitOverridesMapping (&mMappingDataBase
);
1458 if (EFI_ERROR (Status
)){
1459 DEBUG ((DEBUG_ERROR
, "The status to Get Platform Driver Override Variable is %r\n", Status
));
1460 InitializeListHead (&mMappingDataBase
);
1461 return EFI_NOT_FOUND
;
1466 // if the environment variable does not exist, just return not found
1468 if (IsListEmpty (&mMappingDataBase
)) {
1469 return EFI_NOT_FOUND
;
1472 return GetDriverFromMapping (
1481 Retrieves the device path of the platform override driver for a controller in the system.
1482 This driver doesn't support this API.
1484 @param This A pointer to the EFI_PLATFORM_DRIVER_OVERRIDE_
1486 @param ControllerHandle The device handle of the controller to check if a driver override
1488 @param DriverImagePath On input, a pointer to the previous driver device path returned by
1489 GetDriverPath(). On output, a pointer to the next driver
1490 device path. Passing in a pointer to NULL, will return the first
1491 driver device path for ControllerHandle.
1493 @retval EFI_UNSUPPORTED
1498 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL
*This
,
1499 IN EFI_HANDLE ControllerHandle
,
1500 IN OUT EFI_DEVICE_PATH_PROTOCOL
**DriverImagePath
1503 return EFI_UNSUPPORTED
;
1508 Used to associate a driver image handle with a device path that was returned on a prior call to the
1509 GetDriverPath() service. This driver image handle will then be available through the
1510 GetDriver() service. This driver doesn't support this API.
1512 @param This A pointer to the EFI_PLATFORM_DRIVER_OVERRIDE_
1514 @param ControllerHandle The device handle of the controller.
1515 @param DriverImagePath A pointer to the driver device path that was returned in a prior
1516 call to GetDriverPath().
1517 @param DriverImageHandle The driver image handle that was returned by LoadImage()
1518 when the driver specified by DriverImagePath was loaded
1521 @retval EFI_UNSUPPORTED
1526 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL
*This
,
1527 IN EFI_HANDLE ControllerHandle
,
1528 IN EFI_DEVICE_PATH_PROTOCOL
*DriverImagePath
,
1529 IN EFI_HANDLE DriverImageHandle
1532 return EFI_UNSUPPORTED
;
1536 The driver Entry Point. The funciton will export a disk device class formset and
1537 its callback function to hii database.
1539 @param ImageHandle The firmware allocated handle for the EFI image.
1540 @param SystemTable A pointer to the EFI System Table.
1542 @retval EFI_SUCCESS The entry point is executed successfully.
1543 @retval other Some error occurs when executing this entry point.
1548 PlatDriOverrideDxeInit (
1549 IN EFI_HANDLE ImageHandle
,
1550 IN EFI_SYSTEM_TABLE
*SystemTable
1554 EFI_FORM_BROWSER2_PROTOCOL
*FormBrowser2
;
1558 // There should only be one Form Configuration protocol
1560 Status
= gBS
->LocateProtocol (
1561 &gEfiFormBrowser2ProtocolGuid
,
1563 (VOID
**) &FormBrowser2
1565 if (EFI_ERROR (Status
)) {
1570 // According to UEFI spec, there can be at most a single instance
1571 // in the system of the EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL.
1572 // So here we check the existence.
1574 Status
= gBS
->LocateProtocol (
1575 &gEfiPlatformDriverOverrideProtocolGuid
,
1580 // If there was no error, assume there is an installation and return error
1582 if (!EFI_ERROR (Status
)) {
1583 return EFI_ALREADY_STARTED
;
1586 mCallerImageHandle
= ImageHandle
;
1587 mCallbackInfo
= AllocateZeroPool (sizeof (EFI_CALLBACK_INFO
));
1588 if (mCallbackInfo
== NULL
) {
1589 return EFI_BAD_BUFFER_SIZE
;
1592 mCallbackInfo
->Signature
= EFI_CALLBACK_INFO_SIGNATURE
;
1593 mCallbackInfo
->ConfigAccess
.ExtractConfig
= PlatOverMngrExtractConfig
;
1594 mCallbackInfo
->ConfigAccess
.RouteConfig
= PlatOverMngrRouteConfig
;
1595 mCallbackInfo
->ConfigAccess
.Callback
= PlatOverMngrCallback
;
1596 mCallbackInfo
->PlatformDriverOverride
.GetDriver
= GetDriver
;
1597 mCallbackInfo
->PlatformDriverOverride
.GetDriverPath
= GetDriverPath
;
1598 mCallbackInfo
->PlatformDriverOverride
.DriverLoaded
= DriverLoaded
;
1600 // Install Device Path Protocol and Config Access protocol to driver handle
1601 // Install Platform Driver Override Protocol to driver handle
1603 Status
= gBS
->InstallMultipleProtocolInterfaces (
1604 &mCallbackInfo
->DriverHandle
,
1605 &gEfiDevicePathProtocolGuid
,
1606 &mHiiVendorDevicePath
,
1607 &gEfiHiiConfigAccessProtocolGuid
,
1608 &mCallbackInfo
->ConfigAccess
,
1609 &gEfiPlatformDriverOverrideProtocolGuid
,
1610 &mCallbackInfo
->PlatformDriverOverride
,
1613 if (EFI_ERROR (Status
)) {
1618 // Publish our HII data
1620 mCallbackInfo
->RegisteredHandle
= HiiAddPackages (
1621 &mPlatformOverridesManagerGuid
,
1622 mCallbackInfo
->DriverHandle
,
1624 PlatDriOverrideDxeStrings
,
1627 if (mCallbackInfo
->RegisteredHandle
== NULL
) {
1628 Status
= EFI_OUT_OF_RESOURCES
;
1633 // Locate ConfigRouting protocol
1635 Status
= gBS
->LocateProtocol (
1636 &gEfiHiiConfigRoutingProtocolGuid
,
1638 (VOID
**) &mCallbackInfo
->HiiConfigRouting
1640 if (EFI_ERROR (Status
)) {
1645 // Clear all the globle variable
1647 mDriverImageHandleCount
= 0;
1649 ZeroMem (mDriverImageToken
, MAX_CHOICE_NUM
* sizeof (EFI_STRING_ID
));
1650 ZeroMem (mDriverImageFilePathToken
, MAX_CHOICE_NUM
* sizeof (EFI_STRING_ID
));
1651 ZeroMem (mControllerToken
, MAX_CHOICE_NUM
* sizeof (EFI_STRING_ID
));
1652 ZeroMem (mDriverImageProtocol
, MAX_CHOICE_NUM
* sizeof (EFI_LOADED_IMAGE_PROTOCOL
*));
1657 if (mCallbackInfo
->DriverHandle
!= NULL
) {
1658 gBS
->UninstallMultipleProtocolInterfaces (
1659 mCallbackInfo
->DriverHandle
,
1660 &gEfiDevicePathProtocolGuid
,
1661 &mHiiVendorDevicePath
,
1662 &gEfiHiiConfigAccessProtocolGuid
,
1663 &mCallbackInfo
->ConfigAccess
,
1664 &gEfiPlatformDriverOverrideProtocolGuid
,
1665 &mCallbackInfo
->PlatformDriverOverride
,
1670 if (mCallbackInfo
->RegisteredHandle
!= NULL
) {
1671 HiiRemovePackages (mCallbackInfo
->RegisteredHandle
);
1674 if (mCallbackInfo
!= NULL
) {
1675 FreePool (mCallbackInfo
);
1682 Unload its installed protocol.
1684 @param[in] ImageHandle Handle that identifies the image to be unloaded.
1686 @retval EFI_SUCCESS The image has been unloaded.
1690 PlatDriOverrideDxeUnload (
1691 IN EFI_HANDLE ImageHandle
1694 if (mCallbackInfo
->DriverHandle
!= NULL
) {
1695 gBS
->UninstallMultipleProtocolInterfaces (
1696 mCallbackInfo
->DriverHandle
,
1697 &gEfiDevicePathProtocolGuid
,
1698 &mHiiVendorDevicePath
,
1699 &gEfiHiiConfigAccessProtocolGuid
,
1700 &mCallbackInfo
->ConfigAccess
,
1701 &gEfiPlatformDriverOverrideProtocolGuid
,
1702 &mCallbackInfo
->PlatformDriverOverride
,
1707 if (mCallbackInfo
->RegisteredHandle
!= NULL
) {
1708 HiiRemovePackages (mCallbackInfo
->RegisteredHandle
);
1711 if (mCallbackInfo
!= NULL
) {
1712 FreePool (mCallbackInfo
);