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 - 2013, 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
[MAX_CHOICE_NUM
];
74 UINTN mDriverImageHandleCount
;
75 EFI_STRING_ID mDriverImageToken
[MAX_CHOICE_NUM
];
76 EFI_STRING_ID mDriverImageFilePathToken
[MAX_CHOICE_NUM
];
77 EFI_LOADED_IMAGE_PROTOCOL
*mDriverImageProtocol
[MAX_CHOICE_NUM
];
78 EFI_DEVICE_PATH_PROTOCOL
*mControllerDevicePathProtocol
[MAX_CHOICE_NUM
];
79 UINTN mSelectedDriverImageNum
;
80 UINTN mLastSavedDriverImageNum
;
82 EFI_CALLBACK_INFO
*mCallbackInfo
;
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 return AllocateCopyPool (sizeof (L
"?"), L
"?");
133 Worker function to get the driver name by ComponentName or ComponentName2 protocol
134 according to the driver binding handle.
136 @param DriverBindingHandle The Handle of DriverBinding.
137 @param ProtocolGuid The pointer to Component Name (2) protocol GUID.
138 @param VariableName The name of the RFC 4646 or ISO 639-2 language variable.
140 @retval !NULL Pointer into the image name if the image name is found,
141 @retval NULL Pointer to NULL if the image name is not found.
145 GetComponentNameWorker (
146 IN EFI_HANDLE DriverBindingHandle
,
147 IN EFI_GUID
*ProtocolGuid
,
148 IN CONST CHAR16
*VariableName
152 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
157 Status
= gBS
->OpenProtocol (
160 (VOID
*) &ComponentName
,
163 EFI_OPEN_PROTOCOL_GET_PROTOCOL
165 if (EFI_ERROR (Status
)) {
170 // Find the best matching language.
172 GetEfiGlobalVariable2 (VariableName
, (VOID
**)&Language
, NULL
);
173 BestLanguage
= GetBestLanguage (
174 ComponentName
->SupportedLanguages
,
175 (BOOLEAN
) (ProtocolGuid
== &gEfiComponentNameProtocolGuid
),
181 if (BestLanguage
!= NULL
) {
182 ComponentName
->GetDriverName (
187 FreePool (BestLanguage
);
190 if (Language
!= NULL
) {
199 Get the driver name by ComponentName or ComponentName2 protocol
200 according to the driver binding handle
202 @param DriverBindingHandle The Handle of DriverBinding.
204 @retval !NULL Pointer into the image name if the image name is found,
205 @retval NULL Pointer to NULL if the image name is not found.
210 IN EFI_HANDLE DriverBindingHandle
216 // Try RFC 4646 Component Name 2 protocol first.
218 DriverName
= GetComponentNameWorker (DriverBindingHandle
, &gEfiComponentName2ProtocolGuid
, L
"PlatformLang");
219 if (DriverName
== NULL
) {
221 // If we can not get driver name from Component Name 2 protocol, we can try ISO 639-2 Component Name protocol.
223 DriverName
= GetComponentNameWorker (DriverBindingHandle
, &gEfiComponentNameProtocolGuid
, L
"Lang");
230 Get the image name from EFI UI section.
231 Get FV protocol by its loaded image protocol to abstract EFI UI section.
233 @param Image Pointer to the loaded image protocol
235 @retval !NULL Pointer to the image name if the image name is found,
236 @retval NULL NULL if the image name is not found.
241 IN EFI_LOADED_IMAGE_PROTOCOL
*Image
245 EFI_DEVICE_PATH_PROTOCOL
*DevPathNode
;
246 EFI_DEVICE_PATH_PROTOCOL
*AlignedDevPathNode
;
247 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*FvFilePath
;
250 UINT32 AuthenticationStatus
;
252 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv2
;
258 if (Image
->FilePath
== NULL
) {
261 DevPathNode
= Image
->FilePath
;
263 while (!IsDevicePathEnd (DevPathNode
)) {
265 // Make sure device path node is aligned when accessing it's FV Name Guid field.
267 AlignedDevPathNode
= AllocateCopyPool (DevicePathNodeLength(DevPathNode
), DevPathNode
);
270 // Find the Fv File path
272 NameGuid
= EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*)AlignedDevPathNode
);
273 if (NameGuid
!= NULL
) {
274 FvFilePath
= (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*) AlignedDevPathNode
;
275 Status
= gBS
->HandleProtocol (
277 &gEfiFirmwareVolume2ProtocolGuid
,
281 // Locate Image EFI UI section to get the image name.
283 if (!EFI_ERROR (Status
)) {
284 Status
= Fv2
->ReadSection (
286 &FvFilePath
->FvFileName
,
287 EFI_SECTION_USER_INTERFACE
,
291 &AuthenticationStatus
293 if (!EFI_ERROR (Status
)) {
294 FreePool (AlignedDevPathNode
);
301 FreePool (AlignedDevPathNode
);
304 // Next device path node
306 DevPathNode
= NextDevicePathNode (DevPathNode
);
313 Prepare the first page to let user select the device controller which need to
314 add mapping drivers if user select 'Refresh' in first page.
315 During first page, user will see all currnet controller device path in system,
316 select any device path will go to second page to select its overrides drivers.
318 @param Private Pointer to EFI_CALLBACK_INFO.
319 @param KeyValue The callback key value of device controller item in first page.
320 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
322 @retval EFI_SUCCESS Always returned.
326 UpdateDeviceSelectPage (
327 IN EFI_CALLBACK_INFO
*Private
,
329 IN PLAT_OVER_MNGR_DATA
*FakeNvData
334 UINTN DevicePathHandleCount
;
336 EFI_STRING_ID NewStringToken
;
337 CHAR16
*ControllerName
;
338 EFI_DEVICE_PATH_PROTOCOL
*ControllerDevicePath
;
339 EFI_PCI_IO_PROTOCOL
*PciIo
;
340 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*BusSpecificDriverOverride
;
342 VOID
*StartOpCodeHandle
;
343 VOID
*EndOpCodeHandle
;
344 EFI_IFR_GUID_LABEL
*StartLabel
;
345 EFI_IFR_GUID_LABEL
*EndLabel
;
348 // Set current page form ID.
350 mCurrentPage
= FORM_ID_DEVICE
;
353 // Initial the mapping database in memory
355 FreeMappingDatabase (&mMappingDataBase
);
356 InitOverridesMapping (&mMappingDataBase
);
359 // Init OpCode Handle
361 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
362 ASSERT (StartOpCodeHandle
!= NULL
);
364 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
365 ASSERT (EndOpCodeHandle
!= NULL
);
368 // Create Hii Extend Label OpCode as the start opcode
370 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
371 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
372 StartLabel
->Number
= FORM_ID_DEVICE
;
375 // Create Hii Extend Label OpCode as the end opcode
377 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
378 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
379 EndLabel
->Number
= LABEL_END
;
382 // Clear first page form
385 Private
->RegisteredHandle
,
386 &gPlatformOverridesManagerGuid
,
388 StartOpCodeHandle
, // Label FORM_ID_DEVICE
389 EndOpCodeHandle
// LABEL_END
393 // When user enter the page at first time, the 'first refresh' string is given to notify user to refresh all the drivers,
394 // then the 'first refresh' string will be replaced by the 'refresh' string, and the two strings content are same after the replacement
396 NewStringToken
= STRING_TOKEN (STR_FIRST_REFRESH
);
397 NewString
= HiiGetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_REFRESH
), NULL
);
398 ASSERT (NewString
!= NULL
);
399 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
, NULL
) == 0) {
402 FreePool (NewString
);
404 NewStringToken
= STRING_TOKEN (STR_FIRST_REFRESH_HELP
);
405 NewString
= HiiGetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_REFRESH_HELP
), NULL
);
406 ASSERT (NewString
!= NULL
);
407 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
, NULL
) == 0) {
410 FreePool (NewString
);
413 // created needed controller device item in first page
415 DevicePathHandleCount
= 0;
416 Status
= gBS
->LocateHandleBuffer (
418 &gEfiDevicePathProtocolGuid
,
420 &DevicePathHandleCount
,
421 &mDevicePathHandleBuffer
423 if (EFI_ERROR (Status
) || (DevicePathHandleCount
== 0)) {
427 for (Index
= 0; Index
< DevicePathHandleCount
; Index
++) {
428 if (FakeNvData
->PciDeviceFilter
== 0x01) {
430 // Only care PCI device which contain efi driver in its option rom.
434 // Check whether it is a pci device
436 ControllerDevicePath
= NULL
;
437 Status
= gBS
->OpenProtocol (
438 mDevicePathHandleBuffer
[Index
],
439 &gEfiPciIoProtocolGuid
,
443 EFI_OPEN_PROTOCOL_GET_PROTOCOL
445 if (EFI_ERROR (Status
)) {
449 // Check whether it contain efi driver in its option rom
451 Status
= gBS
->HandleProtocol(
452 mDevicePathHandleBuffer
[Index
],
453 &gEfiBusSpecificDriverOverrideProtocolGuid
,
454 (VOID
**) &BusSpecificDriverOverride
456 if (EFI_ERROR (Status
) || BusSpecificDriverOverride
== NULL
) {
461 ControllerDevicePath
= NULL
;
462 Status
= gBS
->OpenProtocol (
463 mDevicePathHandleBuffer
[Index
],
464 &gEfiDevicePathProtocolGuid
,
465 (VOID
**) &ControllerDevicePath
,
468 EFI_OPEN_PROTOCOL_GET_PROTOCOL
470 ASSERT_EFI_ERROR (Status
);
472 // Save the device path protocol interface
474 mControllerDevicePathProtocol
[Index
] = ControllerDevicePath
;
477 // Get the driver name
479 ControllerName
= DevicePathToStr (ControllerDevicePath
);
482 // Export the driver name string and create item in set options page
484 Len
= StrSize (ControllerName
);
485 NewString
= AllocateZeroPool (Len
+ StrSize (L
"--"));
486 ASSERT (NewString
!= NULL
);
487 if (EFI_ERROR (CheckMapping (ControllerDevicePath
,NULL
, &mMappingDataBase
, NULL
, NULL
))) {
488 StrCat (NewString
, L
"--");
490 StrCat (NewString
, L
"**");
492 StrCat (NewString
, ControllerName
);
494 NewStringToken
= HiiSetString (Private
->RegisteredHandle
, mControllerToken
[Index
], NewString
, NULL
);
495 ASSERT (NewStringToken
!= 0);
496 FreePool (NewString
);
498 // Save the device path string toke for next access use
500 mControllerToken
[Index
] = NewStringToken
;
502 HiiCreateGotoOpCode (
506 STRING_TOKEN (STR_GOTO_HELP_DRIVER
),
507 EFI_IFR_FLAG_CALLBACK
,
508 (UINT16
) (Index
+ KEY_VALUE_DEVICE_OFFSET
)
513 // Update first page form
516 Private
->RegisteredHandle
,
517 &gPlatformOverridesManagerGuid
,
519 StartOpCodeHandle
, // Label FORM_ID_DEVICE
520 EndOpCodeHandle
// LABEL_END
523 HiiFreeOpCodeHandle (StartOpCodeHandle
);
524 HiiFreeOpCodeHandle (EndOpCodeHandle
);
530 Get the first Driver Binding handle which has the specific image handle.
532 @param ImageHandle The Image handle
534 @return Handle to Driver binding
535 @retval NULL The paramter is not valid or the driver binding handle is not found.
539 GetDriverBindingHandleFromImageHandle (
540 IN EFI_HANDLE ImageHandle
545 UINTN DriverBindingHandleCount
;
546 EFI_HANDLE
*DriverBindingHandleBuffer
;
547 EFI_DRIVER_BINDING_PROTOCOL
*DriverBindingInterface
;
548 EFI_HANDLE DriverBindingHandle
;
550 DriverBindingHandle
= NULL
;
552 if (ImageHandle
== NULL
) {
556 // Get all drivers which support driver binding protocol
558 DriverBindingHandleCount
= 0;
559 Status
= gBS
->LocateHandleBuffer (
561 &gEfiDriverBindingProtocolGuid
,
563 &DriverBindingHandleCount
,
564 &DriverBindingHandleBuffer
566 if (EFI_ERROR (Status
) || (DriverBindingHandleCount
== 0)) {
571 // Get the first Driver Binding handle which has the specific image handle.
573 for (Index
= 0; Index
< DriverBindingHandleCount
; Index
++) {
574 DriverBindingInterface
= NULL
;
575 Status
= gBS
->OpenProtocol (
576 DriverBindingHandleBuffer
[Index
],
577 &gEfiDriverBindingProtocolGuid
,
578 (VOID
**) &DriverBindingInterface
,
581 EFI_OPEN_PROTOCOL_GET_PROTOCOL
583 if (EFI_ERROR (Status
)) {
587 if (DriverBindingInterface
->ImageHandle
== ImageHandle
) {
588 DriverBindingHandle
= DriverBindingHandleBuffer
[Index
];
593 FreePool (DriverBindingHandleBuffer
);
594 return DriverBindingHandle
;
598 Prepare to let user select the drivers which need mapping with the device controller
599 selected in first page.
601 @param Private Pointer to EFI_CALLBACK_INFO.
602 @param KeyValue The callback key value of device controller item in first page.
603 KeyValue is larger than or equal to KEY_VALUE_DEVICE_OFFSET.
604 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
606 @retval EFI_SUCCESS Always returned.
610 UpdateBindingDriverSelectPage (
611 IN EFI_CALLBACK_INFO
*Private
,
613 IN PLAT_OVER_MNGR_DATA
*FakeNvData
619 EFI_STRING_ID NewStringToken
;
620 EFI_STRING_ID NewStringHelpToken
;
621 UINTN DriverImageHandleCount
;
622 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
624 BOOLEAN FreeDriverName
;
625 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
626 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*BusSpecificDriverOverride
;
627 EFI_HANDLE DriverBindingHandle
;
628 VOID
*StartOpCodeHandle
;
629 VOID
*EndOpCodeHandle
;
630 EFI_IFR_GUID_LABEL
*StartLabel
;
631 EFI_IFR_GUID_LABEL
*EndLabel
;
634 // If user select a controller item in the first page the following code will be run.
635 // During second page, user will see all currnet driver bind protocol driver, the driver name and its device path will be shown
637 //First acquire the list of Loaded Image Protocols, and then when want the name of the driver, look up all the Driver Binding Protocols
638 // and find the first one whose ImageHandle field matches the image handle of the Loaded Image Protocol.
639 // 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.
642 mCurrentPage
= FORM_ID_DRIVER
;
644 // Switch the item callback key value to its NO. in mDevicePathHandleBuffer
646 mSelectedCtrIndex
= KeyValue
- KEY_VALUE_DEVICE_OFFSET
;
647 ASSERT (mSelectedCtrIndex
>= 0 && mSelectedCtrIndex
< MAX_CHOICE_NUM
);
649 mLastSavedDriverImageNum
= 0;
652 // Init OpCode Handle
654 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
655 ASSERT (StartOpCodeHandle
!= NULL
);
657 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
658 ASSERT (EndOpCodeHandle
!= NULL
);
661 // Create Hii Extend Label OpCode as the start opcode
663 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
664 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
665 StartLabel
->Number
= FORM_ID_DRIVER
;
668 // Create Hii Extend Label OpCode as the end opcode
670 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
671 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
672 EndLabel
->Number
= LABEL_END
;
675 // Clear second page form
678 Private
->RegisteredHandle
,
679 &gPlatformOverridesManagerGuid
,
686 // Show all driver which support loaded image protocol in second page
688 DriverImageHandleCount
= 0;
689 Status
= gBS
->LocateHandleBuffer (
691 &gEfiLoadedImageProtocolGuid
,
693 &DriverImageHandleCount
,
694 &mDriverImageHandleBuffer
696 if (EFI_ERROR (Status
) || (DriverImageHandleCount
== 0)) {
697 return EFI_NOT_FOUND
;
700 mDriverImageHandleCount
= DriverImageHandleCount
;
701 for (Index
= 0; Index
< DriverImageHandleCount
; Index
++) {
703 // Step1: Get the driver image total file path for help string and the driver name.
707 // Find driver's Loaded Image protocol
711 Status
= gBS
->OpenProtocol (
712 mDriverImageHandleBuffer
[Index
],
713 &gEfiLoadedImageProtocolGuid
,
714 (VOID
**) &LoadedImage
,
717 EFI_OPEN_PROTOCOL_GET_PROTOCOL
719 if (EFI_ERROR (Status
)) {
720 FakeNvData
->DriSelection
[Index
] = 0x00;
723 mDriverImageProtocol
[Index
] = LoadedImage
;
725 // Find its related driver binding protocol
727 DriverBindingHandle
= GetDriverBindingHandleFromImageHandle (mDriverImageHandleBuffer
[Index
]);
728 if (DriverBindingHandle
== NULL
) {
729 FakeNvData
->DriSelection
[Index
] = 0x00;
734 // Get the EFI Loaded Image Device Path Protocol
736 LoadedImageDevicePath
= NULL
;
737 Status
= gBS
->HandleProtocol (
738 mDriverImageHandleBuffer
[Index
],
739 &gEfiLoadedImageDevicePathProtocolGuid
,
740 (VOID
**) &LoadedImageDevicePath
742 if (LoadedImageDevicePath
== NULL
) {
743 FakeNvData
->DriSelection
[Index
] = 0x00;
747 if (FakeNvData
->PciDeviceFilter
== 0x01) {
749 // only care the driver which is in a Pci device option rom,
750 // and the driver's LoadedImage->DeviceHandle must point to a pci device which has efi option rom
752 if (!EFI_ERROR (Status
)) {
753 Status
= gBS
->HandleProtocol(
754 LoadedImage
->DeviceHandle
,
755 &gEfiBusSpecificDriverOverrideProtocolGuid
,
756 (VOID
**) &BusSpecificDriverOverride
758 if (EFI_ERROR (Status
) || BusSpecificDriverOverride
== NULL
) {
759 FakeNvData
->DriSelection
[Index
] = 0x00;
763 FakeNvData
->DriSelection
[Index
] = 0x00;
769 // For driver name, try to get its component name, if fail, get its image name,
770 // if also fail, give a default name.
772 FreeDriverName
= FALSE
;
773 DriverName
= GetComponentName (DriverBindingHandle
);
774 if (DriverName
== NULL
) {
776 // get its image name
778 DriverName
= GetImageName (LoadedImage
);
780 if (DriverName
== NULL
) {
782 // give a default name
784 DriverName
= HiiGetString (Private
->RegisteredHandle
, STRING_TOKEN (STR_DRIVER_DEFAULT_NAME
), NULL
);
785 ASSERT (DriverName
!= NULL
);
786 FreeDriverName
= TRUE
; // the DriverName string need to free pool
791 // Step2 Export the driver name string and create check box item in second page
795 // First create the driver image name
797 NewString
= AllocateZeroPool (StrSize (DriverName
));
798 ASSERT (NewString
!= NULL
);
799 if (EFI_ERROR (CheckMapping (mControllerDevicePathProtocol
[mSelectedCtrIndex
], LoadedImageDevicePath
, &mMappingDataBase
, NULL
, NULL
))) {
800 FakeNvData
->DriSelection
[Index
] = 0x00;
802 FakeNvData
->DriSelection
[Index
] = 0x01;
803 mLastSavedDriverImageNum
++;
805 StrCat (NewString
, DriverName
);
806 NewStringToken
= HiiSetString (Private
->RegisteredHandle
, mDriverImageToken
[Index
], NewString
, NULL
);
807 ASSERT (NewStringToken
!= 0);
808 mDriverImageToken
[Index
] = NewStringToken
;
809 FreePool (NewString
);
810 if (FreeDriverName
) {
811 FreePool (DriverName
);
815 // Second create the driver image device path as item help string
817 DriverName
= DevicePathToStr (LoadedImageDevicePath
);
819 NewString
= AllocateZeroPool (StrSize (DriverName
));
820 ASSERT (NewString
!= NULL
);
821 StrCat (NewString
, DriverName
);
822 NewStringHelpToken
= HiiSetString (Private
->RegisteredHandle
, mDriverImageFilePathToken
[Index
], NewString
, NULL
);
823 ASSERT (NewStringHelpToken
!= 0);
824 mDriverImageFilePathToken
[Index
] = NewStringHelpToken
;
825 FreePool (NewString
);
826 FreePool (DriverName
);
828 HiiCreateCheckBoxOpCode (
830 (UINT16
) (DRIVER_SELECTION_QUESTION_ID
+ Index
),
831 VARSTORE_ID_PLAT_OVER_MNGR
,
832 (UINT16
) (DRIVER_SELECTION_VAR_OFFSET
+ Index
),
842 // Update second page form
845 Private
->RegisteredHandle
,
846 &gPlatformOverridesManagerGuid
,
848 StartOpCodeHandle
, // Label FORM_ID_DRIVER
849 EndOpCodeHandle
// LABEL_END
852 HiiFreeOpCodeHandle (StartOpCodeHandle
);
853 HiiFreeOpCodeHandle (EndOpCodeHandle
);
858 Prepare to let user select the priority order of the drivers which are
859 selected in second page.
861 @param Private Pointer to EFI_CALLBACK_INFO.
862 @param KeyValue The callback key value of device controller item in first page.
863 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
865 @retval EFI_SUCCESS Always returned.
869 UpdatePrioritySelectPage (
870 IN EFI_CALLBACK_INFO
*Private
,
872 IN PLAT_OVER_MNGR_DATA
*FakeNvData
876 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
877 UINTN SelectedDriverImageNum
;
878 UINT32 DriverImageNO
;
883 VOID
*StartOpCodeHandle
;
884 VOID
*EndOpCodeHandle
;
885 VOID
*OptionsOpCodeHandle
;
886 EFI_IFR_GUID_LABEL
*StartLabel
;
887 EFI_IFR_GUID_LABEL
*EndLabel
;
890 // Following code will be run if user select 'order ... priority' item in second page
891 // Prepare third page. In third page, user will order the drivers priority which are selected in second page
893 mCurrentPage
= FORM_ID_ORDER
;
896 // Init OpCode Handle
898 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
899 ASSERT (StartOpCodeHandle
!= NULL
);
901 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
902 ASSERT (EndOpCodeHandle
!= NULL
);
905 // Create Hii Extend Label OpCode as the start opcode
907 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
908 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
909 StartLabel
->Number
= FORM_ID_ORDER
;
912 // Create Hii Extend Label OpCode as the end opcode
914 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
915 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
916 EndLabel
->Number
= LABEL_END
;
919 // Clear third page form
922 Private
->RegisteredHandle
,
923 &gPlatformOverridesManagerGuid
,
930 // Check how many drivers have been selected
932 SelectedDriverImageNum
= 0;
933 for (Index
= 0; Index
< mDriverImageHandleCount
; Index
++) {
934 if (FakeNvData
->DriSelection
[Index
] != 0) {
935 SelectedDriverImageNum
++;
939 mSelectedDriverImageNum
= SelectedDriverImageNum
;
940 if (SelectedDriverImageNum
== 0) {
944 OptionsOpCodeHandle
= HiiAllocateOpCodeHandle ();
945 ASSERT (OptionsOpCodeHandle
!= NULL
);
948 // Create order list for those selected drivers
950 SelectedDriverImageNum
= 0;
951 for (Index
= 0; Index
< mDriverImageHandleCount
; Index
++) {
952 if (FakeNvData
->DriSelection
[Index
] != 0) {
954 // Use the NO. in driver binding buffer as value, will use it later
956 HiiCreateOneOfOptionOpCode (
958 mDriverImageToken
[Index
],
960 EFI_IFR_NUMERIC_SIZE_1
,
965 // Get the EFI Loaded Image Device Path Protocol
967 LoadedImageDevicePath
= NULL
;
968 gBS
->HandleProtocol (
969 mDriverImageHandleBuffer
[Index
],
970 &gEfiLoadedImageDevicePathProtocolGuid
,
971 (VOID
**) &LoadedImageDevicePath
973 ASSERT (LoadedImageDevicePath
!= NULL
);
976 // Check the driver DriverImage's order number in mapping database
980 mControllerDevicePathProtocol
[mSelectedCtrIndex
],
981 LoadedImageDevicePath
,
986 if (DriverImageNO
== 0) {
987 DriverImageNO
= (UINT32
) mLastSavedDriverImageNum
+ 1;
988 mLastSavedDriverImageNum
++;
990 TempNO
[SelectedDriverImageNum
] = DriverImageNO
;
991 OrderNO
[SelectedDriverImageNum
] = Index
+ 1;
992 SelectedDriverImageNum
++;
996 ASSERT (SelectedDriverImageNum
== mSelectedDriverImageNum
);
998 // NvRamMap Must be clear firstly
1000 ZeroMem (FakeNvData
->DriOrder
, sizeof (FakeNvData
->DriOrder
));
1003 // Order the selected drivers according to the info already in mapping database
1004 // the less order number in mapping database the less order number in NvRamMap
1006 for (Index
=0; Index
< SelectedDriverImageNum
; Index
++) {
1008 // Find the minimal order number in TempNO array, its index in TempNO is same as IfrOptionList array
1011 for (Index1
=0; Index1
< SelectedDriverImageNum
; Index1
++) {
1012 if (TempNO
[Index1
] < TempNO
[MinNO
]) {
1017 // the IfrOptionList[MinNO].Value = the driver NO. in driver binding buffer
1019 FakeNvData
->DriOrder
[Index
] = (UINT8
) OrderNO
[MinNO
];
1020 TempNO
[MinNO
] = MAX_CHOICE_NUM
+ 1;
1024 // Create Order List OpCode
1026 HiiCreateOrderedListOpCode (
1028 (UINT16
) DRIVER_ORDER_QUESTION_ID
,
1029 VARSTORE_ID_PLAT_OVER_MNGR
,
1030 (UINT16
) DRIVER_ORDER_VAR_OFFSET
,
1031 mControllerToken
[mSelectedCtrIndex
],
1032 mControllerToken
[mSelectedCtrIndex
],
1033 EFI_IFR_FLAG_RESET_REQUIRED
,
1035 EFI_IFR_NUMERIC_SIZE_1
,
1036 (UINT8
) MAX_CHOICE_NUM
,
1037 OptionsOpCodeHandle
,
1042 // Update third page form
1045 Private
->RegisteredHandle
,
1046 &gPlatformOverridesManagerGuid
,
1048 StartOpCodeHandle
, // Label FORM_ID_ORDER
1049 EndOpCodeHandle
// LABEL_END
1052 HiiFreeOpCodeHandle (StartOpCodeHandle
);
1053 HiiFreeOpCodeHandle (EndOpCodeHandle
);
1054 HiiFreeOpCodeHandle (OptionsOpCodeHandle
);
1060 Save the save the mapping database to NV variable.
1062 @param Private Pointer to EFI_CALLBACK_INFO.
1063 @param KeyValue The callback key value of device controller item in first page.
1064 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
1066 @retval EFI_SUCCESS Always returned.
1071 IN EFI_CALLBACK_INFO
*Private
,
1073 IN PLAT_OVER_MNGR_DATA
*FakeNvData
1078 UINTN SelectedDriverImageNum
;
1079 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
1081 // Following code will be run if user select 'commint changes' in third page
1082 // user enter 'Commit Changes' to save the mapping database
1084 DeleteDriverImage (mControllerDevicePathProtocol
[mSelectedCtrIndex
], NULL
, &mMappingDataBase
);
1085 for (SelectedDriverImageNum
= 0; SelectedDriverImageNum
< mSelectedDriverImageNum
; SelectedDriverImageNum
++) {
1087 // DriOrder[SelectedDriverImageNum] = the driver NO. in driver binding buffer
1089 Index
= FakeNvData
->DriOrder
[SelectedDriverImageNum
] - 1;
1092 // Get the EFI Loaded Image Device Path Protocol
1094 LoadedImageDevicePath
= NULL
;
1095 Status
= gBS
->HandleProtocol (
1096 mDriverImageHandleBuffer
[Index
],
1097 &gEfiLoadedImageDevicePathProtocolGuid
,
1098 (VOID
**) &LoadedImageDevicePath
1100 ASSERT (LoadedImageDevicePath
!= NULL
);
1103 mControllerDevicePathProtocol
[mSelectedCtrIndex
],
1104 LoadedImageDevicePath
,
1106 (UINT32
)SelectedDriverImageNum
+ 1
1109 Status
= SaveOverridesMapping (&mMappingDataBase
);
1115 This function allows a caller to extract the current configuration for one
1116 or more named elements from the target driver.
1118 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1119 @param Request A null-terminated Unicode string in <ConfigRequest> format.
1120 @param Progress On return, points to a character in the Request string.
1121 Points to the string's null terminator if request was successful.
1122 Points to the most recent '&' before the first failing name/value
1123 pair (or the beginning of the string if the failure is in the
1124 first name/value pair) if the request was not successful.
1125 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
1126 has all values filled in for the names in the Request string.
1127 String to be allocated by the called function.
1129 @retval EFI_SUCCESS The Results is filled with the requested values.
1130 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
1131 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
1132 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
1137 PlatOverMngrExtractConfig (
1138 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1139 IN CONST EFI_STRING Request
,
1140 OUT EFI_STRING
*Progress
,
1141 OUT EFI_STRING
*Results
1145 EFI_CALLBACK_INFO
*Private
;
1146 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
1147 EFI_STRING ConfigRequestHdr
;
1148 EFI_STRING ConfigRequest
;
1149 BOOLEAN AllocatedRequest
;
1153 if (Progress
== NULL
|| Results
== NULL
) {
1154 return EFI_INVALID_PARAMETER
;
1157 *Progress
= Request
;
1158 if ((Request
!= NULL
) && !HiiIsConfigHdrMatch (Request
, &gPlatformOverridesManagerGuid
, mVariableName
)) {
1159 return EFI_NOT_FOUND
;
1162 ConfigRequestHdr
= NULL
;
1163 ConfigRequest
= NULL
;
1165 AllocatedRequest
= FALSE
;
1167 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1168 HiiConfigRouting
= Private
->HiiConfigRouting
;
1169 ConfigRequest
= Request
;
1170 if ((Request
== NULL
) || (StrStr (Request
, L
"OFFSET") == NULL
)) {
1172 // Request has no request element, construct full request string.
1173 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
1174 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
1176 ConfigRequestHdr
= HiiConstructConfigHdr (&gPlatformOverridesManagerGuid
, mVariableName
, Private
->DriverHandle
);
1177 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
1178 ConfigRequest
= AllocateZeroPool (Size
);
1179 ASSERT (ConfigRequest
!= NULL
);
1180 AllocatedRequest
= TRUE
;
1181 BufferSize
= sizeof (PLAT_OVER_MNGR_DATA
);
1182 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr
, (UINT64
)BufferSize
);
1183 FreePool (ConfigRequestHdr
);
1187 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
1189 Status
= HiiConfigRouting
->BlockToConfig (
1192 (UINT8
*) &Private
->FakeNvData
,
1193 sizeof (PLAT_OVER_MNGR_DATA
),
1199 // Free the allocated config request string.
1201 if (AllocatedRequest
) {
1202 FreePool (ConfigRequest
);
1203 ConfigRequest
= NULL
;
1206 // Set Progress string to the original request string.
1208 if (Request
== NULL
) {
1210 } else if (StrStr (Request
, L
"OFFSET") == NULL
) {
1211 *Progress
= Request
+ StrLen (Request
);
1218 This function processes the results of changes in configuration.
1220 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1221 @param Configuration A null-terminated Unicode string in <ConfigRequest> format.
1222 @param Progress A pointer to a string filled in with the offset of the most
1223 recent '&' before the first failing name/value pair (or the
1224 beginning of the string if the failure is in the first
1225 name/value pair) or the terminating NULL if all was successful.
1227 @retval EFI_SUCCESS The Results is processed successfully.
1228 @retval EFI_INVALID_PARAMETER Configuration is NULL.
1229 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
1234 PlatOverMngrRouteConfig (
1235 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1236 IN CONST EFI_STRING Configuration
,
1237 OUT EFI_STRING
*Progress
1240 EFI_CALLBACK_INFO
*Private
;
1242 PLAT_OVER_MNGR_DATA
*FakeNvData
;
1244 if (Configuration
== NULL
|| Progress
== NULL
) {
1245 return EFI_INVALID_PARAMETER
;
1247 *Progress
= Configuration
;
1249 if (!HiiIsConfigHdrMatch (Configuration
, &gPlatformOverridesManagerGuid
, mVariableName
)) {
1250 return EFI_NOT_FOUND
;
1253 *Progress
= Configuration
+ StrLen (Configuration
);
1254 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1255 FakeNvData
= &Private
->FakeNvData
;
1256 if (!HiiGetBrowserData (&gPlatformOverridesManagerGuid
, mVariableName
, sizeof (PLAT_OVER_MNGR_DATA
), (UINT8
*) FakeNvData
)) {
1258 // FakeNvData can't be got from SetupBrowser, which doesn't need to be set.
1263 if (mCurrentPage
== FORM_ID_DRIVER
) {
1264 KeyValue
= KEY_VALUE_DRIVER_GOTO_ORDER
;
1265 UpdatePrioritySelectPage (Private
, KeyValue
, FakeNvData
);
1266 KeyValue
= KEY_VALUE_ORDER_SAVE_AND_EXIT
;
1267 CommintChanges (Private
, KeyValue
, FakeNvData
);
1269 // Since UpdatePrioritySelectPage will change mCurrentPage,
1270 // should ensure the mCurrentPage still indicate the second page here
1272 mCurrentPage
= FORM_ID_DRIVER
;
1275 if (mCurrentPage
== FORM_ID_ORDER
) {
1276 KeyValue
= KEY_VALUE_ORDER_SAVE_AND_EXIT
;
1277 CommintChanges (Private
, KeyValue
, FakeNvData
);
1284 This is the function that is called to provide results data to the driver. This data
1285 consists of a unique key which is used to identify what data is either being passed back
1288 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1289 @param Action A null-terminated Unicode string in <ConfigRequest> format.
1290 @param KeyValue A unique Goto OpCode callback value which record user's selection.
1291 0x100 <= KeyValue <0x500 : user select a controller item in the first page;
1292 KeyValue == 0x1234 : user select 'Refresh' in first page, or user select 'Go to Previous Menu' in second page
1293 KeyValue == 0x1235 : user select 'Pci device filter' in first page
1294 KeyValue == 0x1500 : user select 'order ... priority' item in second page
1295 KeyValue == 0x1800 : user select 'commint changes' in third page
1296 KeyValue == 0x2000 : user select 'Go to Previous Menu' in third page
1297 @param Type The type of value for the question.
1298 @param Value A pointer to the data being sent to the original exporting driver.
1299 @param ActionRequest On return, points to the action requested by the callback function.
1301 @retval EFI_SUCCESS Always returned.
1306 PlatOverMngrCallback (
1307 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1308 IN EFI_BROWSER_ACTION Action
,
1309 IN EFI_QUESTION_ID KeyValue
,
1311 IN EFI_IFR_TYPE_VALUE
*Value
,
1312 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
1315 EFI_CALLBACK_INFO
*Private
;
1317 EFI_STRING_ID NewStringToken
;
1319 PLAT_OVER_MNGR_DATA
*FakeNvData
;
1321 if ((Action
!= EFI_BROWSER_ACTION_CHANGING
) && (Action
!= EFI_BROWSER_ACTION_CHANGED
)) {
1323 // All other action return unsupported.
1325 return EFI_UNSUPPORTED
;
1328 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1329 FakeNvData
= &Private
->FakeNvData
;
1330 if (!HiiGetBrowserData (&gPlatformOverridesManagerGuid
, mVariableName
, sizeof (PLAT_OVER_MNGR_DATA
), (UINT8
*) FakeNvData
)) {
1331 return EFI_NOT_FOUND
;
1334 if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
1335 if (Value
== NULL
) {
1336 return EFI_INVALID_PARAMETER
;
1339 if (KeyValue
== KEY_VALUE_DRIVER_GOTO_PREVIOUS
) {
1340 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1342 // Update page title string
1344 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1345 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, L
"First, Select the controller by device path", NULL
) == 0) {
1350 if (((KeyValue
>= KEY_VALUE_DEVICE_OFFSET
) && (KeyValue
< KEY_VALUE_DEVICE_MAX
)) || (KeyValue
== KEY_VALUE_ORDER_GOTO_PREVIOUS
)) {
1351 if (KeyValue
== KEY_VALUE_ORDER_GOTO_PREVIOUS
) {
1352 KeyValue
= (EFI_QUESTION_ID
) (mSelectedCtrIndex
+ KEY_VALUE_DEVICE_OFFSET
);
1354 UpdateBindingDriverSelectPage (Private
, KeyValue
, FakeNvData
);
1356 // Update page title string
1358 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1359 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, L
"Second, Select drivers for the previous selected controller", NULL
) == 0) {
1364 if (KeyValue
== KEY_VALUE_DRIVER_GOTO_ORDER
) {
1365 UpdatePrioritySelectPage (Private
, KeyValue
, FakeNvData
);
1367 // Update page title string
1369 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1370 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, L
"Finally, Set the priority order for the drivers and save them", NULL
) == 0) {
1375 if (KeyValue
== KEY_VALUE_DEVICE_CLEAR
) {
1377 // Deletes all environment variable(s) that contain the override mappings info
1379 FreeMappingDatabase (&mMappingDataBase
);
1380 Status
= SaveOverridesMapping (&mMappingDataBase
);
1381 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1383 } else if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
1385 case KEY_VALUE_DEVICE_REFRESH
:
1386 case KEY_VALUE_DEVICE_FILTER
:
1387 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1389 // Update page title string
1391 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1392 if (HiiSetString (Private
->RegisteredHandle
, NewStringToken
, L
"First, Select the controller by device path", NULL
) == 0) {
1397 case KEY_VALUE_ORDER_SAVE_AND_EXIT
:
1398 Status
= CommintChanges (Private
, KeyValue
, FakeNvData
);
1399 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1400 if (EFI_ERROR (Status
)) {
1401 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Single Override Info too large, Saving Error!", NULL
);
1402 return EFI_DEVICE_ERROR
;
1412 // Pass changed uncommitted data back to Form Browser
1414 HiiSetBrowserData (&gPlatformOverridesManagerGuid
, mVariableName
, sizeof (PLAT_OVER_MNGR_DATA
), (UINT8
*) FakeNvData
, NULL
);
1420 Retrieves the image handle of the platform override driver for a controller in the system.
1422 @param This A pointer to the
1423 EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL instance.
1424 @param ControllerHandle The device handle of the controller to check if a
1425 driver override exists.
1426 @param DriverImageHandle On input, a pointer to the previous driver image
1427 handle returned by GetDriver(). On output, a
1428 pointer to the next driver image handle. Passing
1429 in a NULL, will return the first driver image
1430 handle for ControllerHandle.
1432 @retval EFI_SUCCESS The driver override for ControllerHandle was
1433 returned in DriverImageHandle.
1434 @retval EFI_NOT_FOUND A driver override for ControllerHandle was not
1436 @retval EFI_INVALID_PARAMETER The handle specified by ControllerHandle is NULL.
1437 DriverImageHandle is not a handle that was returned
1438 on a previous call to GetDriver().
1444 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL
*This
,
1445 IN EFI_HANDLE ControllerHandle
,
1446 IN OUT EFI_HANDLE
*DriverImageHandle
1452 // Check that ControllerHandle is a valid handle
1454 if (ControllerHandle
== NULL
) {
1455 return EFI_INVALID_PARAMETER
;
1459 // Read the environment variable(s) that contain the override mappings from Controller Device Path to
1460 // a set of Driver Device Paths, and initialize in memory database of the overrides that map Controller
1461 // Device Paths to an ordered set of Driver Device Paths and Driver Handles. This action is only performed
1462 // once and finished in first call.
1464 if (!mEnvironmentVariableRead
) {
1465 mEnvironmentVariableRead
= TRUE
;
1467 Status
= InitOverridesMapping (&mMappingDataBase
);
1468 if (EFI_ERROR (Status
)){
1469 DEBUG ((DEBUG_ERROR
, "The status to Get Platform Driver Override Variable is %r\n", Status
));
1470 InitializeListHead (&mMappingDataBase
);
1471 return EFI_NOT_FOUND
;
1476 // if the environment variable does not exist, just return not found
1478 if (IsListEmpty (&mMappingDataBase
)) {
1479 return EFI_NOT_FOUND
;
1482 return GetDriverFromMapping (
1491 Retrieves the device path of the platform override driver for a controller in the system.
1492 This driver doesn't support this API.
1494 @param This A pointer to the EFI_PLATFORM_DRIVER_OVERRIDE_
1496 @param ControllerHandle The device handle of the controller to check if a driver override
1498 @param DriverImagePath On input, a pointer to the previous driver device path returned by
1499 GetDriverPath(). On output, a pointer to the next driver
1500 device path. Passing in a pointer to NULL, will return the first
1501 driver device path for ControllerHandle.
1503 @retval EFI_UNSUPPORTED
1508 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL
*This
,
1509 IN EFI_HANDLE ControllerHandle
,
1510 IN OUT EFI_DEVICE_PATH_PROTOCOL
**DriverImagePath
1513 return EFI_UNSUPPORTED
;
1518 Used to associate a driver image handle with a device path that was returned on a prior call to the
1519 GetDriverPath() service. This driver image handle will then be available through the
1520 GetDriver() service. This driver doesn't support this API.
1522 @param This A pointer to the EFI_PLATFORM_DRIVER_OVERRIDE_
1524 @param ControllerHandle The device handle of the controller.
1525 @param DriverImagePath A pointer to the driver device path that was returned in a prior
1526 call to GetDriverPath().
1527 @param DriverImageHandle The driver image handle that was returned by LoadImage()
1528 when the driver specified by DriverImagePath was loaded
1531 @retval EFI_UNSUPPORTED
1536 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL
*This
,
1537 IN EFI_HANDLE ControllerHandle
,
1538 IN EFI_DEVICE_PATH_PROTOCOL
*DriverImagePath
,
1539 IN EFI_HANDLE DriverImageHandle
1542 return EFI_UNSUPPORTED
;
1546 The driver Entry Point. The funciton will export a disk device class formset and
1547 its callback function to hii database.
1549 @param ImageHandle The firmware allocated handle for the EFI image.
1550 @param SystemTable A pointer to the EFI System Table.
1552 @retval EFI_SUCCESS The entry point is executed successfully.
1553 @retval other Some error occurs when executing this entry point.
1558 PlatDriOverrideDxeInit (
1559 IN EFI_HANDLE ImageHandle
,
1560 IN EFI_SYSTEM_TABLE
*SystemTable
1564 EFI_FORM_BROWSER2_PROTOCOL
*FormBrowser2
;
1568 // There should only be one Form Configuration protocol
1570 Status
= gBS
->LocateProtocol (
1571 &gEfiFormBrowser2ProtocolGuid
,
1573 (VOID
**) &FormBrowser2
1575 if (EFI_ERROR (Status
)) {
1580 // According to UEFI spec, there can be at most a single instance
1581 // in the system of the EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL.
1582 // So here we check the existence.
1584 Status
= gBS
->LocateProtocol (
1585 &gEfiPlatformDriverOverrideProtocolGuid
,
1590 // If there was no error, assume there is an installation and return error
1592 if (!EFI_ERROR (Status
)) {
1593 return EFI_ALREADY_STARTED
;
1596 mCallerImageHandle
= ImageHandle
;
1597 mCallbackInfo
= AllocateZeroPool (sizeof (EFI_CALLBACK_INFO
));
1598 if (mCallbackInfo
== NULL
) {
1599 return EFI_BAD_BUFFER_SIZE
;
1602 mCallbackInfo
->Signature
= EFI_CALLBACK_INFO_SIGNATURE
;
1603 mCallbackInfo
->ConfigAccess
.ExtractConfig
= PlatOverMngrExtractConfig
;
1604 mCallbackInfo
->ConfigAccess
.RouteConfig
= PlatOverMngrRouteConfig
;
1605 mCallbackInfo
->ConfigAccess
.Callback
= PlatOverMngrCallback
;
1606 mCallbackInfo
->PlatformDriverOverride
.GetDriver
= GetDriver
;
1607 mCallbackInfo
->PlatformDriverOverride
.GetDriverPath
= GetDriverPath
;
1608 mCallbackInfo
->PlatformDriverOverride
.DriverLoaded
= DriverLoaded
;
1610 // Install Device Path Protocol and Config Access protocol to driver handle
1611 // Install Platform Driver Override Protocol to driver handle
1613 Status
= gBS
->InstallMultipleProtocolInterfaces (
1614 &mCallbackInfo
->DriverHandle
,
1615 &gEfiDevicePathProtocolGuid
,
1616 &mHiiVendorDevicePath
,
1617 &gEfiHiiConfigAccessProtocolGuid
,
1618 &mCallbackInfo
->ConfigAccess
,
1619 &gEfiPlatformDriverOverrideProtocolGuid
,
1620 &mCallbackInfo
->PlatformDriverOverride
,
1623 if (EFI_ERROR (Status
)) {
1628 // Publish our HII data
1630 mCallbackInfo
->RegisteredHandle
= HiiAddPackages (
1631 &gPlatformOverridesManagerGuid
,
1632 mCallbackInfo
->DriverHandle
,
1634 PlatDriOverrideDxeStrings
,
1637 if (mCallbackInfo
->RegisteredHandle
== NULL
) {
1638 Status
= EFI_OUT_OF_RESOURCES
;
1643 // Locate ConfigRouting protocol
1645 Status
= gBS
->LocateProtocol (
1646 &gEfiHiiConfigRoutingProtocolGuid
,
1648 (VOID
**) &mCallbackInfo
->HiiConfigRouting
1650 if (EFI_ERROR (Status
)) {
1655 // Clear all the globle variable
1657 mDriverImageHandleCount
= 0;
1659 ZeroMem (mDriverImageToken
, MAX_CHOICE_NUM
* sizeof (EFI_STRING_ID
));
1660 ZeroMem (mDriverImageFilePathToken
, MAX_CHOICE_NUM
* sizeof (EFI_STRING_ID
));
1661 ZeroMem (mControllerToken
, MAX_CHOICE_NUM
* sizeof (EFI_STRING_ID
));
1662 ZeroMem (mDriverImageProtocol
, MAX_CHOICE_NUM
* sizeof (EFI_LOADED_IMAGE_PROTOCOL
*));
1667 PlatDriOverrideDxeUnload (ImageHandle
);
1673 Unload its installed protocol.
1675 @param[in] ImageHandle Handle that identifies the image to be unloaded.
1677 @retval EFI_SUCCESS The image has been unloaded.
1681 PlatDriOverrideDxeUnload (
1682 IN EFI_HANDLE ImageHandle
1685 ASSERT (mCallbackInfo
!= NULL
);
1687 if (mCallbackInfo
->DriverHandle
!= NULL
) {
1688 gBS
->UninstallMultipleProtocolInterfaces (
1689 mCallbackInfo
->DriverHandle
,
1690 &gEfiDevicePathProtocolGuid
,
1691 &mHiiVendorDevicePath
,
1692 &gEfiHiiConfigAccessProtocolGuid
,
1693 &mCallbackInfo
->ConfigAccess
,
1694 &gEfiPlatformDriverOverrideProtocolGuid
,
1695 &mCallbackInfo
->PlatformDriverOverride
,
1700 if (mCallbackInfo
->RegisteredHandle
!= NULL
) {
1701 HiiRemovePackages (mCallbackInfo
->RegisteredHandle
);
1704 FreePool (mCallbackInfo
);