3 A UI application to offer a UI interface in device manager to let user configue
4 platform override protocol to override the default algorithm for matching
5 drivers to controllers.
8 1. The UI application dynamicly locate all controller device path.
9 2. The UI application dynamicly locate all drivers which support binding protocol.
10 3. The UI application export and dynamicly update two menu to let user select the
11 mapping between drivers to controllers.
12 4. The UI application save all the mapping info in NV variables which will be consumed
13 by platform override protocol driver to publish the platform override protocol.
15 Copyright (c) 2007 - 2008, Intel Corporation
16 All rights reserved. This program and the accompanying materials
17 are licensed and made available under the terms and conditions of the BSD License
18 which accompanies this distribution. The full text of the license may be found at
19 http://opensource.org/licenses/bsd-license.php
21 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
22 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
28 #include <Protocol/HiiConfigAccess.h>
29 #include <Protocol/HiiConfigRouting.h>
30 #include <Protocol/HiiDatabase.h>
31 #include <Protocol/FormBrowser2.h>
32 #include <Protocol/LoadedImage.h>
33 #include <Protocol/FirmwareVolume2.h>
34 #include <Protocol/PciIo.h>
35 #include <Protocol/BusSpecificDriverOverride.h>
36 #include <Protocol/ComponentName2.h>
37 #include <Protocol/ComponentName.h>
38 #include <Protocol/DriverBinding.h>
39 #include <Guid/GlobalVariable.h>
41 #include <Library/BaseLib.h>
42 #include <Library/DebugLib.h>
43 #include <Library/UefiLib.h>
44 #include <Library/UefiApplicationEntryPoint.h>
45 #include <Library/UefiBootServicesTableLib.h>
46 #include <Library/PlatDriOverLib.h>
47 #include <Library/HiiLib.h>
48 #include <Library/IfrSupportLib.h>
49 #include <Library/ExtendedHiiLib.h>
50 #include <Library/ExtendedIfrSupportLib.h>
51 #include <Library/BaseMemoryLib.h>
52 #include <Library/MemoryAllocationLib.h>
53 #include <Library/UefiRuntimeServicesTableLib.h>
54 #include <Library/DevicePathLib.h>
55 #include <Library/GenericBdsLib.h>
56 #include "PlatOverMngr.h"
58 #define EFI_CALLBACK_INFO_SIGNATURE SIGNATURE_32 ('C', 'l', 'b', 'k')
59 #define EFI_CALLBACK_INFO_FROM_THIS(a) CR (a, EFI_CALLBACK_INFO, ConfigAccess, EFI_CALLBACK_INFO_SIGNATURE)
63 EFI_HANDLE DriverHandle
;
64 EFI_HII_HANDLE RegisteredHandle
;
65 PLAT_OVER_MNGR_DATA FakeNvData
;
66 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
67 EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess
;
71 // uni string and Vfr Binary data.
73 extern UINT8 VfrBin
[];
74 extern UINT8 PlatOverMngrStrings
[];
79 EFI_GUID mPlatformOverridesManagerGuid
= PLAT_OVER_MNGR_GUID
;
80 LIST_ENTRY mMappingDataBase
= INITIALIZE_LIST_HEAD_VARIABLE (mMappingDataBase
);
82 EFI_HANDLE
*mDevicePathHandleBuffer
;
83 EFI_HANDLE
*mDriverImageHandleBuffer
;
85 INTN mSelectedCtrIndex
;
86 EFI_STRING_ID mControllerToken
[MAX_CHOICE_NUM
];
87 UINTN mDriverImageHandleCount
;
88 EFI_STRING_ID mDriverImageToken
[MAX_CHOICE_NUM
];
89 EFI_STRING_ID mDriverImageFilePathToken
[MAX_CHOICE_NUM
];
90 EFI_LOADED_IMAGE_PROTOCOL
*mDriverImageProtocol
[MAX_CHOICE_NUM
];
91 EFI_DEVICE_PATH_PROTOCOL
*mControllerDevicePathProtocol
[MAX_CHOICE_NUM
];
92 UINTN mSelectedDriverImageNum
;
93 UINTN mLastSavedDriverImageNum
;
94 CHAR8 mLanguage
[RFC_3066_ENTRY_SIZE
];
98 Do string convertion for the ComponentName supported language. It do
99 the convertion just for english language code from RFC 3066 to ISO 639-2.
100 Then it will check whether the converted language is in the supported language list.
101 If not supported, NULL is returned.
102 If Language is not english, NULL is returned.
104 @param SupportedLanguages Pointer to ComponentName supported language string list. ISO 639-2 language
105 @param Language The language string. RFC 3066 language
107 @return English language string (ISO 639-2)
108 @return NULL if the conertion is not successful.
112 ConvertComponentNameSupportLanguage (
113 IN CHAR8
*SupportedLanguages
,
121 // Check the input language is English
123 if (AsciiStrnCmp (Language
, "en-", 3) != 0) {
128 // Check SupportedLanguages format
130 if (AsciiStrStr (SupportedLanguages
, "en-") != NULL
) {
132 // Create RFC 3066 language
134 LangCode
= AllocateZeroPool(AsciiStrSize (Language
));
135 AsciiStrCpy (LangCode
, Language
);
136 } else if (AsciiStrStr (SupportedLanguages
, "en") != NULL
) {
138 // Create ISO 639-2 Language
140 LangCode
= AllocateZeroPool(4);
141 AsciiStrCpy (LangCode
, "eng");
148 Get the driver name by ComponentName or ComponentName2 protocol
149 according to the driver binding handle
151 @param DriverBindingHandle The Handle of DriverBinding.
153 @retval !NULL Pointer into the image name if the image name is found,
154 @retval NULL Pointer to NULL if the image name is not found.
159 IN EFI_HANDLE DriverBindingHandle
163 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
164 EFI_COMPONENT_NAME2_PROTOCOL
*ComponentName2
;
165 CHAR8
*SupportedLanguage
;
168 ComponentName
= NULL
;
169 ComponentName2
= NULL
;
170 Status
= gBS
->OpenProtocol (
172 &gEfiComponentName2ProtocolGuid
,
173 (VOID
**) &ComponentName2
,
176 EFI_OPEN_PROTOCOL_GET_PROTOCOL
178 if (EFI_ERROR(Status
)) {
179 Status
= gBS
->OpenProtocol (
181 &gEfiComponentNameProtocolGuid
,
182 (VOID
**) &ComponentName
,
185 EFI_OPEN_PROTOCOL_GET_PROTOCOL
189 Status
= EFI_SUCCESS
;
191 if (ComponentName
!= NULL
) {
192 if (ComponentName
->GetDriverName
!= NULL
) {
193 SupportedLanguage
= ConvertComponentNameSupportLanguage (ComponentName
->SupportedLanguages
, mLanguage
);
194 if (SupportedLanguage
!= NULL
) {
195 Status
= ComponentName
->GetDriverName (
200 FreePool (SupportedLanguage
);
203 } else if (ComponentName2
!= NULL
) {
204 if (ComponentName2
->GetDriverName
!= NULL
) {
205 Status
= ComponentName2
->GetDriverName (
213 if (EFI_ERROR (Status
)) {
221 Get the image name from EFI UI section.
222 Get FV protocol by its loaded image protoocl to abastract EFI UI section.
224 @param Image Pointer to the loaded image protocol
226 @retval !NULL Pointer to the image name if the image name is found,
227 @retval NULL NULL if the image name is not found.
232 IN EFI_LOADED_IMAGE_PROTOCOL
*Image
236 EFI_DEVICE_PATH_PROTOCOL
*DevPathNode
;
237 EFI_DEVICE_PATH_PROTOCOL
*AlignedDevPathNode
;
238 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*FvFilePath
;
241 UINT32 AuthenticationStatus
;
243 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv2
;
249 if (Image
->FilePath
== NULL
) {
252 DevPathNode
= Image
->FilePath
;
254 while (!IsDevicePathEnd (DevPathNode
)) {
256 // Make sure device path node is aligned when accessing it's FV Name Guid field.
258 AlignedDevPathNode
= AllocateCopyPool (DevicePathNodeLength(DevPathNode
), DevPathNode
);
261 // Find the Fv File path
263 NameGuid
= EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*)AlignedDevPathNode
);
264 if (NameGuid
!= NULL
) {
265 FvFilePath
= (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*) AlignedDevPathNode
;
266 Status
= gBS
->HandleProtocol (
268 &gEfiFirmwareVolume2ProtocolGuid
,
272 // Locate Image EFI UI section to get the image name.
274 if (!EFI_ERROR (Status
)) {
275 Status
= Fv2
->ReadSection (
277 &FvFilePath
->FvFileName
,
278 EFI_SECTION_USER_INTERFACE
,
282 &AuthenticationStatus
284 if (!EFI_ERROR (Status
)) {
285 FreePool (AlignedDevPathNode
);
292 FreePool (AlignedDevPathNode
);
295 // Next device path node
297 DevPathNode
= NextDevicePathNode (DevPathNode
);
304 Prepare the first page to let user select the device controller which need to
305 add mapping drivers if user select 'Refresh' in first page.
306 During first page, user will see all currnet controller device path in system,
307 select any device path will go to second page to select its overrides drivers.
309 @param Private Pointer to EFI_CALLBACK_INFO.
310 @param KeyValue The callback key value of device controller item in first page.
311 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
313 @retval EFI_SUCCESS Always returned.
317 UpdateDeviceSelectPage (
318 IN EFI_CALLBACK_INFO
*Private
,
320 IN PLAT_OVER_MNGR_DATA
*FakeNvData
323 EFI_HII_UPDATE_DATA UpdateData
;
327 UINTN DevicePathHandleCount
;
329 EFI_STRING_ID NewStringToken
;
330 CHAR16
*ControllerName
;
331 EFI_DEVICE_PATH_PROTOCOL
*ControllerDevicePath
;
332 EFI_PCI_IO_PROTOCOL
*PciIo
;
333 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*BusSpecificDriverOverride
;
337 // set current page form ID.
339 mCurrentPage
= FORM_ID_DEVICE
;
342 // Get Platform supported Language (RFC_3066 format)
344 LangSize
= RFC_3066_ENTRY_SIZE
;
345 Status
= gRT
->GetVariable (
347 &gEfiGlobalVariableGuid
,
352 ASSERT_EFI_ERROR (Status
);
355 // Initial the mapping database in memory
357 FreeMappingDatabase (&mMappingDataBase
);
358 Status
= InitOverridesMapping (&mMappingDataBase
);
361 // Clear all the content in the first page
363 UpdateData
.BufferSize
= UPDATE_DATA_SIZE
;
364 UpdateData
.Offset
= 0;
365 UpdateData
.Data
= AllocateZeroPool (UPDATE_DATA_SIZE
);
366 ASSERT (UpdateData
.Data
!= NULL
);
368 // Clear first page form
371 Private
->RegisteredHandle
,
372 &mPlatformOverridesManagerGuid
,
380 // When user enter the page at first time, the 'first refresh' string is given to notify user to refresh all the drivers,
381 // then the 'first refresh' string will be replaced by the 'refresh' string, and the two strings content are same after the replacement
383 NewStringToken
= STRING_TOKEN (STR_FIRST_REFRESH
);
384 HiiLibGetStringFromHandle (Private
->RegisteredHandle
, STRING_TOKEN (STR_REFRESH
), &NewString
);
385 ASSERT (NewString
!= NULL
);
386 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
);
387 ASSERT_EFI_ERROR (Status
);
388 FreePool (NewString
);
390 NewStringToken
= STRING_TOKEN (STR_FIRST_REFRESH_HELP
);
391 HiiLibGetStringFromHandle (Private
->RegisteredHandle
, STRING_TOKEN (STR_REFRESH_HELP
), &NewString
);
392 ASSERT (NewString
!= NULL
);
393 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
);
394 ASSERT_EFI_ERROR (Status
);
395 FreePool (NewString
);
398 // created needed controller device item in first page
400 DevicePathHandleCount
= 0;
401 Status
= gBS
->LocateHandleBuffer (
403 &gEfiDevicePathProtocolGuid
,
405 &DevicePathHandleCount
,
406 &mDevicePathHandleBuffer
408 if (EFI_ERROR (Status
) || (DevicePathHandleCount
== 0)) {
412 for (Index
= 0; Index
< DevicePathHandleCount
; Index
++) {
413 if (FakeNvData
->PciDeviceFilter
== 0x01) {
415 // Only care PCI device which contain efi driver in its option rom.
419 // Check whether it is a pci device
421 ControllerDevicePath
= NULL
;
422 Status
= gBS
->OpenProtocol (
423 mDevicePathHandleBuffer
[Index
],
424 &gEfiPciIoProtocolGuid
,
428 EFI_OPEN_PROTOCOL_GET_PROTOCOL
430 if (EFI_ERROR (Status
)) {
434 // Check whether it contain efi driver in its option rom
436 Status
= gBS
->HandleProtocol(
437 mDevicePathHandleBuffer
[Index
],
438 &gEfiBusSpecificDriverOverrideProtocolGuid
,
439 (VOID
**) &BusSpecificDriverOverride
441 if (EFI_ERROR (Status
) || BusSpecificDriverOverride
== NULL
) {
446 ControllerDevicePath
= NULL
;
447 Status
= gBS
->OpenProtocol (
448 mDevicePathHandleBuffer
[Index
],
449 &gEfiDevicePathProtocolGuid
,
450 (VOID
**) &ControllerDevicePath
,
453 EFI_OPEN_PROTOCOL_GET_PROTOCOL
455 ASSERT_EFI_ERROR (Status
);
457 // Save the device path protocol interface
459 mControllerDevicePathProtocol
[Index
] = ControllerDevicePath
;
462 // Get the driver name
464 ControllerName
= DevicePathToStr (ControllerDevicePath
);
467 // Export the driver name string and create item in set options page
469 Len
= StrSize (ControllerName
);
470 NewString
= AllocateZeroPool (Len
+ StrSize (L
"--"));
471 ASSERT (NewString
!= NULL
);
472 if (EFI_ERROR (CheckMapping (ControllerDevicePath
,NULL
, &mMappingDataBase
, NULL
, NULL
))) {
473 StrCat (NewString
, L
"--");
475 StrCat (NewString
, L
"**");
477 StrCat (NewString
, ControllerName
);
479 NewStringToken
= mControllerToken
[Index
];
480 if (NewStringToken
== 0) {
481 Status
= HiiLibNewString (Private
->RegisteredHandle
, &NewStringToken
, NewString
);
483 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
);
485 ASSERT_EFI_ERROR (Status
);
486 FreePool (NewString
);
488 // Save the device path string toke for next access use
490 mControllerToken
[Index
] = NewStringToken
;
495 STRING_TOKEN (STR_GOTO_HELP_DRIVER
),
496 EFI_IFR_FLAG_CALLBACK
,
497 (UINT16
) (Index
+ KEY_VALUE_DEVICE_OFFSET
),
503 // Update first page form
506 Private
->RegisteredHandle
,
507 &mPlatformOverridesManagerGuid
,
514 FreePool (UpdateData
.Data
);
519 Get the first Driver Binding handle which has the specific image handle.
521 @param ImageHandle The Image handle
523 @return Handle to Driver binding
524 @retval NULL The paramter is not valid or the driver binding handle is not found.
528 GetDriverBindingHandleFromImageHandle (
529 IN EFI_HANDLE ImageHandle
534 UINTN DriverBindingHandleCount
;
535 EFI_HANDLE
*DriverBindingHandleBuffer
;
536 EFI_DRIVER_BINDING_PROTOCOL
*DriverBindingInterface
;
537 EFI_HANDLE DriverBindingHandle
;
539 DriverBindingHandle
= NULL
;
541 if (ImageHandle
== NULL
) {
545 // Get all drivers which support driver binding protocol
547 DriverBindingHandleCount
= 0;
548 Status
= gBS
->LocateHandleBuffer (
550 &gEfiDriverBindingProtocolGuid
,
552 &DriverBindingHandleCount
,
553 &DriverBindingHandleBuffer
555 if (EFI_ERROR (Status
) || (DriverBindingHandleCount
== 0)) {
560 // Get the first Driver Binding handle which has the specific image handle.
562 for (Index
= 0; Index
< DriverBindingHandleCount
; Index
++) {
563 DriverBindingInterface
= NULL
;
564 Status
= gBS
->OpenProtocol (
565 DriverBindingHandleBuffer
[Index
],
566 &gEfiDriverBindingProtocolGuid
,
567 (VOID
**) &DriverBindingInterface
,
570 EFI_OPEN_PROTOCOL_GET_PROTOCOL
572 if (EFI_ERROR (Status
)) {
576 if (DriverBindingInterface
->ImageHandle
== ImageHandle
) {
577 DriverBindingHandle
= DriverBindingHandleBuffer
[Index
];
582 FreePool (DriverBindingHandleBuffer
);
583 return DriverBindingHandle
;
587 Prepare to let user select the drivers which need mapping with the device controller
588 selected in first page.
590 @param Private Pointer to EFI_CALLBACK_INFO.
591 @param KeyValue The callback key value of device controller item in first page.
592 KeyValue is larger than or equal to KEY_VALUE_DEVICE_OFFSET.
593 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
595 @retval EFI_SUCCESS Always returned.
599 UpdateBindingDriverSelectPage (
600 IN EFI_CALLBACK_INFO
*Private
,
602 IN PLAT_OVER_MNGR_DATA
*FakeNvData
605 EFI_HII_UPDATE_DATA UpdateData
;
609 EFI_STRING_ID NewStringToken
;
610 EFI_STRING_ID NewStringHelpToken
;
611 UINTN DriverImageHandleCount
;
612 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
614 BOOLEAN FreeDriverName
;
615 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
616 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*BusSpecificDriverOverride
;
617 EFI_HANDLE DriverBindingHandle
;
620 // If user select a controller item in the first page the following code will be run.
621 // During second page, user will see all currnet driver bind protocol driver, the driver name and its device path will be shown
623 //First acquire the list of Loaded Image Protocols, and then when want the name of the driver, look up all the Driver Binding Protocols
624 // and find the first one whose ImageHandle field matches the image handle of the Loaded Image Protocol.
625 // 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.
628 mCurrentPage
= FORM_ID_DRIVER
;
630 // Switch the item callback key value to its NO. in mDevicePathHandleBuffer
632 mSelectedCtrIndex
= KeyValue
- KEY_VALUE_DEVICE_OFFSET
;
633 ASSERT (mSelectedCtrIndex
> 0 && mSelectedCtrIndex
< MAX_CHOICE_NUM
);
635 mLastSavedDriverImageNum
= 0;
637 // Clear all the content in dynamic page
639 UpdateData
.BufferSize
= UPDATE_DATA_SIZE
;
640 UpdateData
.Offset
= 0;
641 UpdateData
.Data
= AllocateZeroPool (UPDATE_DATA_SIZE
);
642 ASSERT (UpdateData
.Data
!= NULL
);
644 // Clear second page form
647 Private
->RegisteredHandle
,
648 &mPlatformOverridesManagerGuid
,
656 // Show all driver which support loaded image protocol in second page
658 DriverImageHandleCount
= 0;
659 Status
= gBS
->LocateHandleBuffer (
661 &gEfiLoadedImageProtocolGuid
,
663 &DriverImageHandleCount
,
664 &mDriverImageHandleBuffer
666 if (EFI_ERROR (Status
) || (DriverImageHandleCount
== 0)) {
667 return EFI_NOT_FOUND
;
670 mDriverImageHandleCount
= DriverImageHandleCount
;
671 for (Index
= 0; Index
< DriverImageHandleCount
; Index
++) {
673 // Step1: Get the driver image total file path for help string and the driver name.
677 // Find driver's Loaded Image protocol
681 Status
= gBS
->OpenProtocol (
682 mDriverImageHandleBuffer
[Index
],
683 &gEfiLoadedImageProtocolGuid
,
684 (VOID
**) &LoadedImage
,
687 EFI_OPEN_PROTOCOL_GET_PROTOCOL
689 if (EFI_ERROR (Status
)) {
690 FakeNvData
->DriSelection
[Index
] = 0x00;
693 mDriverImageProtocol
[Index
] = LoadedImage
;
695 // Find its related driver binding protocol
697 DriverBindingHandle
= GetDriverBindingHandleFromImageHandle (mDriverImageHandleBuffer
[Index
]);
698 if (DriverBindingHandle
== NULL
) {
699 FakeNvData
->DriSelection
[Index
] = 0x00;
704 // Get the EFI Loaded Image Device Path Protocol
706 LoadedImageDevicePath
= NULL
;
707 Status
= gBS
->HandleProtocol (
708 mDriverImageHandleBuffer
[Index
],
709 &gEfiLoadedImageDevicePathProtocolGuid
,
710 (VOID
**) &LoadedImageDevicePath
712 if (LoadedImageDevicePath
== NULL
) {
713 FakeNvData
->DriSelection
[Index
] = 0x00;
717 if (FakeNvData
->PciDeviceFilter
== 0x01) {
719 // only care the driver which is in a Pci device option rom,
720 // and the driver's LoadedImage->DeviceHandle must point to a pci device which has efi option rom
722 if (!EFI_ERROR (Status
)) {
723 Status
= gBS
->HandleProtocol(
724 LoadedImage
->DeviceHandle
,
725 &gEfiBusSpecificDriverOverrideProtocolGuid
,
726 (VOID
**) &BusSpecificDriverOverride
728 if (EFI_ERROR (Status
) || BusSpecificDriverOverride
== NULL
) {
729 FakeNvData
->DriSelection
[Index
] = 0x00;
733 FakeNvData
->DriSelection
[Index
] = 0x00;
739 // For driver name, try to get its component name, if fail, get its image name,
740 // if also fail, give a default name.
742 FreeDriverName
= FALSE
;
743 DriverName
= GetComponentName (DriverBindingHandle
);
744 if (DriverName
== NULL
) {
746 // get its image name
748 DriverName
= GetImageName (LoadedImage
);
750 if (DriverName
== NULL
) {
752 // give a default name
754 HiiLibGetStringFromHandle (Private
->RegisteredHandle
, STRING_TOKEN (STR_DRIVER_DEFAULT_NAME
), &DriverName
);
755 ASSERT (DriverName
!= NULL
);
756 FreeDriverName
= TRUE
; // the DriverName string need to free pool
761 // Step2 Export the driver name string and create check box item in second page
765 // First create the driver image name
767 NewString
= AllocateZeroPool (StrSize (DriverName
));
768 ASSERT (NewString
!= NULL
);
769 if (EFI_ERROR (CheckMapping (mControllerDevicePathProtocol
[mSelectedCtrIndex
], LoadedImageDevicePath
, &mMappingDataBase
, NULL
, NULL
))) {
770 FakeNvData
->DriSelection
[Index
] = 0x00;
772 FakeNvData
->DriSelection
[Index
] = 0x01;
773 mLastSavedDriverImageNum
++;
775 StrCat (NewString
, DriverName
);
776 NewStringToken
= mDriverImageToken
[Index
];
777 if (NewStringToken
== 0) {
778 Status
= HiiLibNewString (Private
->RegisteredHandle
, &NewStringToken
, NewString
);
780 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
);
782 mDriverImageToken
[Index
] = NewStringToken
;
783 ASSERT_EFI_ERROR (Status
);
784 FreePool (NewString
);
785 if (FreeDriverName
) {
786 FreePool (DriverName
);
790 // Second create the driver image device path as item help string
792 DriverName
= DevicePathToStr (LoadedImageDevicePath
);
794 NewString
= AllocateZeroPool (StrSize (DriverName
));
795 ASSERT (NewString
!= NULL
);
796 StrCat (NewString
, DriverName
);
797 NewStringHelpToken
= mDriverImageFilePathToken
[Index
];
798 if (NewStringHelpToken
== 0) {
799 Status
= HiiLibNewString (Private
->RegisteredHandle
, &NewStringHelpToken
, NewString
);
801 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringHelpToken
, NewString
);
803 mDriverImageFilePathToken
[Index
] = NewStringHelpToken
;
804 ASSERT_EFI_ERROR (Status
);
805 FreePool (NewString
);
806 FreePool (DriverName
);
808 CreateCheckBoxOpCode (
809 (UINT16
) (DRIVER_SELECTION_QUESTION_ID
+ Index
),
810 VARSTORE_ID_PLAT_OVER_MNGR
,
811 (UINT16
) (DRIVER_SELECTION_VAR_OFFSET
+ Index
),
821 // Update second page form
824 Private
->RegisteredHandle
,
825 &mPlatformOverridesManagerGuid
,
832 FreePool (UpdateData
.Data
);
837 Prepare to let user select the priority order of the drivers which are
838 selected in second page.
840 @param Private Pointer to EFI_CALLBACK_INFO.
841 @param KeyValue The callback key value of device controller item in first page.
842 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
844 @retval EFI_SUCCESS Always returned.
848 UpdatePrioritySelectPage (
849 IN EFI_CALLBACK_INFO
*Private
,
851 IN PLAT_OVER_MNGR_DATA
*FakeNvData
854 EFI_HII_UPDATE_DATA UpdateData
;
856 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
857 IFR_OPTION
*IfrOptionList
;
858 UINTN SelectedDriverImageNum
;
859 UINT32 DriverImageNO
;
865 // Following code will be run if user select 'order ... priority' item in second page
866 // Prepare third page. In third page, user will order the drivers priority which are selected in second page
868 mCurrentPage
= FORM_ID_ORDER
;
870 UpdateData
.BufferSize
= UPDATE_DATA_SIZE
;
871 UpdateData
.Offset
= 0;
872 UpdateData
.Data
= AllocateZeroPool (UPDATE_DATA_SIZE
);
873 ASSERT (UpdateData
.Data
!= NULL
);
875 // Clear third page form
878 Private
->RegisteredHandle
,
879 &mPlatformOverridesManagerGuid
,
887 // Check how many drivers have been selected
889 SelectedDriverImageNum
= 0;
890 for (Index
= 0; Index
< mDriverImageHandleCount
; Index
++) {
891 if (FakeNvData
->DriSelection
[Index
] != 0) {
892 SelectedDriverImageNum
++;
896 mSelectedDriverImageNum
= SelectedDriverImageNum
;
897 if (SelectedDriverImageNum
== 0) {
901 IfrOptionList
= AllocateZeroPool (sizeof (IFR_OPTION
) * mSelectedDriverImageNum
);
902 ASSERT (IfrOptionList
!= NULL
);
904 // Create order list for those selected drivers
906 SelectedDriverImageNum
= 0;
907 for (Index
= 0; Index
< mDriverImageHandleCount
; Index
++) {
908 if (FakeNvData
->DriSelection
[Index
] != 0) {
909 IfrOptionList
[SelectedDriverImageNum
].StringToken
= mDriverImageToken
[Index
];
911 // Use the NO. in driver binding buffer as value, will use it later
913 IfrOptionList
[SelectedDriverImageNum
].Value
.u8
= (UINT8
) (Index
+ 1);
914 IfrOptionList
[SelectedDriverImageNum
].Flags
= 0;
917 // Get the EFI Loaded Image Device Path Protocol
919 LoadedImageDevicePath
= NULL
;
920 gBS
->HandleProtocol (
921 mDriverImageHandleBuffer
[Index
],
922 &gEfiLoadedImageDevicePathProtocolGuid
,
923 (VOID
**) &LoadedImageDevicePath
925 ASSERT (LoadedImageDevicePath
!= NULL
);
928 // Check the driver DriverImage's order number in mapping database
931 ASSERT (mSelectedCtrIndex
< MAX_CHOICE_NUM
);
933 mControllerDevicePathProtocol
[mSelectedCtrIndex
],
934 LoadedImageDevicePath
,
939 if (DriverImageNO
== 0) {
940 DriverImageNO
= (UINT32
) mLastSavedDriverImageNum
+ 1;
941 mLastSavedDriverImageNum
++;
943 TempNO
[SelectedDriverImageNum
] = DriverImageNO
;
944 SelectedDriverImageNum
++;
948 ASSERT (SelectedDriverImageNum
== mSelectedDriverImageNum
);
950 // NvRamMap Must be clear firstly
952 ZeroMem (FakeNvData
->DriOrder
, sizeof (FakeNvData
->DriOrder
));
955 // Order the selected drivers according to the info already in mapping database
956 // the less order number in mapping database the less order number in NvRamMap
958 for (Index
=0; Index
< SelectedDriverImageNum
; Index
++) {
960 // Find the minimal order number in TempNO array, its index in TempNO is same as IfrOptionList array
963 for (Index1
=0; Index1
< SelectedDriverImageNum
; Index1
++) {
964 if (TempNO
[Index1
] < TempNO
[MinNO
]) {
969 // the IfrOptionList[MinNO].Value = the driver NO. in driver binding buffer
971 FakeNvData
->DriOrder
[Index
] =IfrOptionList
[MinNO
].Value
.u8
;
972 TempNO
[MinNO
] = MAX_CHOICE_NUM
+ 1;
975 CreateOrderedListOpCode (
976 (UINT16
) DRIVER_ORDER_QUESTION_ID
,
977 VARSTORE_ID_PLAT_OVER_MNGR
,
978 (UINT16
) DRIVER_ORDER_VAR_OFFSET
,
979 mControllerToken
[mSelectedCtrIndex
],
980 mControllerToken
[mSelectedCtrIndex
],
981 EFI_IFR_FLAG_RESET_REQUIRED
,
983 EFI_IFR_NUMERIC_SIZE_1
,
984 (UINT8
) MAX_CHOICE_NUM
,
986 SelectedDriverImageNum
,
991 // Update third page form
994 Private
->RegisteredHandle
,
995 &mPlatformOverridesManagerGuid
,
1002 FreePool (IfrOptionList
);
1003 FreePool (UpdateData
.Data
);
1008 Save the save the mapping database to NV variable.
1010 @param Private Pointer to EFI_CALLBACK_INFO.
1011 @param KeyValue The callback key value of device controller item in first page.
1012 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
1014 @retval EFI_SUCCESS Always returned.
1019 IN EFI_CALLBACK_INFO
*Private
,
1021 IN PLAT_OVER_MNGR_DATA
*FakeNvData
1026 UINTN SelectedDriverImageNum
;
1027 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
1029 // Following code will be run if user select 'commint changes' in third page
1030 // user enter 'Commit Changes' to save the mapping database
1032 ASSERT (mSelectedCtrIndex
< MAX_CHOICE_NUM
);
1033 DeleteDriverImage (mControllerDevicePathProtocol
[mSelectedCtrIndex
], NULL
, &mMappingDataBase
);
1034 for (SelectedDriverImageNum
= 0; SelectedDriverImageNum
< mSelectedDriverImageNum
; SelectedDriverImageNum
++) {
1036 // DriOrder[SelectedDriverImageNum] = the driver NO. in driver binding buffer
1038 Index
= FakeNvData
->DriOrder
[SelectedDriverImageNum
] - 1;
1041 // Get the EFI Loaded Image Device Path Protocol
1043 LoadedImageDevicePath
= NULL
;
1044 Status
= gBS
->HandleProtocol (
1045 mDriverImageHandleBuffer
[Index
],
1046 &gEfiLoadedImageDevicePathProtocolGuid
,
1047 (VOID
**) &LoadedImageDevicePath
1049 ASSERT (LoadedImageDevicePath
!= NULL
);
1052 mControllerDevicePathProtocol
[mSelectedCtrIndex
],
1053 LoadedImageDevicePath
,
1055 (UINT32
)SelectedDriverImageNum
+ 1
1058 Status
= SaveOverridesMapping (&mMappingDataBase
);
1064 This function allows a caller to extract the current configuration for one
1065 or more named elements from the target driver.
1067 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1068 @param Request A null-terminated Unicode string in <ConfigRequest> format.
1069 @param Progress On return, points to a character in the Request string.
1070 Points to the string's null terminator if request was successful.
1071 Points to the most recent '&' before the first failing name/value
1072 pair (or the beginning of the string if the failure is in the
1073 first name/value pair) if the request was not successful.
1074 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
1075 has all values filled in for the names in the Request string.
1076 String to be allocated by the called function.
1078 @retval EFI_SUCCESS The Results is filled with the requested values.
1079 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
1080 @retval EFI_INVALID_PARAMETER Request is NULL, illegal syntax, or unknown name.
1081 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
1086 PlatOverMngrExtractConfig (
1087 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1088 IN CONST EFI_STRING Request
,
1089 OUT EFI_STRING
*Progress
,
1090 OUT EFI_STRING
*Results
1094 EFI_CALLBACK_INFO
*Private
;
1095 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
1097 if (Request
== NULL
) {
1098 return EFI_NOT_FOUND
;
1101 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1102 HiiConfigRouting
= Private
->HiiConfigRouting
;
1105 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
1107 Status
= HiiConfigRouting
->BlockToConfig (
1110 (UINT8
*) &Private
->FakeNvData
,
1111 sizeof (PLAT_OVER_MNGR_DATA
),
1119 This function processes the results of changes in configuration.
1121 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1122 @param Configuration A null-terminated Unicode string in <ConfigRequest> format.
1123 @param Progress A pointer to a string filled in with the offset of the most
1124 recent '&' before the first failing name/value pair (or the
1125 beginning of the string if the failure is in the first
1126 name/value pair) or the terminating NULL if all was successful.
1128 @retval EFI_SUCCESS The Results is processed successfully.
1129 @retval EFI_INVALID_PARAMETER Configuration is NULL.
1130 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
1135 PlatOverMngrRouteConfig (
1136 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1137 IN CONST EFI_STRING Configuration
,
1138 OUT EFI_STRING
*Progress
1141 EFI_CALLBACK_INFO
*Private
;
1145 PLAT_OVER_MNGR_DATA
*FakeNvData
;
1147 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1149 FakeNvData
= &Private
->FakeNvData
;
1150 BufferSize
= sizeof (PLAT_OVER_MNGR_DATA
);
1151 Status
= GetBrowserData (NULL
, NULL
, &BufferSize
, (UINT8
*) FakeNvData
);
1152 if (EFI_ERROR (Status
)) {
1156 if (mCurrentPage
== FORM_ID_DRIVER
) {
1157 KeyValue
= KEY_VALUE_DRIVER_GOTO_ORDER
;
1158 UpdatePrioritySelectPage (Private
, KeyValue
, FakeNvData
);
1159 KeyValue
= KEY_VALUE_ORDER_SAVE_AND_EXIT
;
1160 CommintChanges (Private
, KeyValue
, FakeNvData
);
1162 // Since UpdatePrioritySelectPage will change mCurrentPage,
1163 // should ensure the mCurrentPage still indicate the second page here
1165 mCurrentPage
= FORM_ID_DRIVER
;
1168 if (mCurrentPage
== FORM_ID_ORDER
) {
1169 KeyValue
= KEY_VALUE_ORDER_SAVE_AND_EXIT
;
1170 CommintChanges (Private
, KeyValue
, FakeNvData
);
1176 This is the function that is called to provide results data to the driver. This data
1177 consists of a unique key which is used to identify what data is either being passed back
1180 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1181 @param Action A null-terminated Unicode string in <ConfigRequest> format.
1182 @param KeyValue A unique Goto OpCode callback value which record user's selection.
1183 0x100 <= KeyValue <0x500 : user select a controller item in the first page;
1184 KeyValue == 0x1234 : user select 'Refresh' in first page, or user select 'Go to Previous Menu' in second page
1185 KeyValue == 0x1235 : user select 'Pci device filter' in first page
1186 KeyValue == 0x1500 : user select 'order ... priority' item in second page
1187 KeyValue == 0x1800 : user select 'commint changes' in third page
1188 KeyValue == 0x2000 : user select 'Go to Previous Menu' in third page
1189 @param Type The type of value for the question.
1190 @param Value A pointer to the data being sent to the original exporting driver.
1191 @param ActionRequest On return, points to the action requested by the callback function.
1193 @retval EFI_SUCCESS Always returned.
1198 PlatOverMngrCallback (
1199 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1200 IN EFI_BROWSER_ACTION Action
,
1201 IN EFI_QUESTION_ID KeyValue
,
1203 IN EFI_IFR_TYPE_VALUE
*Value
,
1204 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
1207 EFI_CALLBACK_INFO
*Private
;
1209 EFI_STRING_ID NewStringToken
;
1211 PLAT_OVER_MNGR_DATA
*FakeNvData
;
1214 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1216 FakeNvData
= &Private
->FakeNvData
;
1217 BufferSize
= sizeof (PLAT_OVER_MNGR_DATA
);
1218 Status
= GetBrowserData (NULL
, NULL
, &BufferSize
, (UINT8
*) FakeNvData
);
1219 if (EFI_ERROR (Status
)) {
1223 if (KeyValue
== KEY_VALUE_DEVICE_REFRESH
||
1224 KeyValue
== KEY_VALUE_DEVICE_FILTER
||
1225 KeyValue
== KEY_VALUE_DRIVER_GOTO_PREVIOUS
1227 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1229 // Update page title string
1231 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1232 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, L
"First, Select the controller by device path");
1233 ASSERT_EFI_ERROR (Status
);
1236 if (((KeyValue
>= KEY_VALUE_DEVICE_OFFSET
) && (KeyValue
< KEY_VALUE_DEVICE_MAX
)) || (KeyValue
== KEY_VALUE_ORDER_GOTO_PREVIOUS
)) {
1237 if (KeyValue
== KEY_VALUE_ORDER_GOTO_PREVIOUS
) {
1238 KeyValue
= (EFI_QUESTION_ID
) (mSelectedCtrIndex
+ KEY_VALUE_DEVICE_OFFSET
);
1240 UpdateBindingDriverSelectPage (Private
, KeyValue
, FakeNvData
);
1242 // Update page title string
1244 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1245 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, L
"Second, Select drivers for the previous selected controller");
1246 ASSERT_EFI_ERROR (Status
);
1249 if (KeyValue
== KEY_VALUE_DRIVER_GOTO_ORDER
) {
1250 UpdatePrioritySelectPage (Private
, KeyValue
, FakeNvData
);
1252 // Update page title string
1254 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1255 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, L
"Finally, Set the priority order for the drivers and save them");
1256 ASSERT_EFI_ERROR (Status
);
1259 if (KeyValue
== KEY_VALUE_ORDER_SAVE_AND_EXIT
) {
1260 Status
= CommintChanges (Private
, KeyValue
, FakeNvData
);
1261 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1262 if (EFI_ERROR (Status
)) {
1263 IfrLibCreatePopUp (1, &Key
, L
"Single Override Info too large, Saving Error!");
1264 return EFI_DEVICE_ERROR
;
1268 if (KeyValue
== KEY_VALUE_DEVICE_CLEAR
) {
1270 // Deletes all environment variable(s) that contain the override mappings info
1272 FreeMappingDatabase (&mMappingDataBase
);
1273 Status
= SaveOverridesMapping (&mMappingDataBase
);
1274 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1277 // Pass changed uncommitted data back to Form Browser
1279 BufferSize
= sizeof (PLAT_OVER_MNGR_DATA
);
1280 Status
= SetBrowserData (NULL
, NULL
, BufferSize
, (UINT8
*) FakeNvData
, NULL
);
1286 The driver Entry Point. The funciton will export a disk device class formset and
1287 its callback function to hii database.
1289 @param ImageHandle The firmware allocated handle for the EFI image.
1290 @param SystemTable A pointer to the EFI System Table.
1292 @retval EFI_SUCCESS The entry point is executed successfully.
1293 @retval other Some error occurs when executing this entry point.
1299 IN EFI_HANDLE ImageHandle
,
1300 IN EFI_SYSTEM_TABLE
*SystemTable
1304 EFI_HII_DATABASE_PROTOCOL
*HiiDatabase
;
1305 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
1306 EFI_CALLBACK_INFO
*CallbackInfo
;
1307 EFI_HANDLE DriverHandle
;
1308 EFI_FORM_BROWSER2_PROTOCOL
*FormBrowser2
;
1311 // There should only be one HII protocol
1313 Status
= gBS
->LocateProtocol (
1314 &gEfiHiiDatabaseProtocolGuid
,
1316 (VOID
**) &HiiDatabase
1318 if (EFI_ERROR (Status
)) {
1323 // There should only be one Form Configuration protocol
1325 Status
= gBS
->LocateProtocol (
1326 &gEfiFormBrowser2ProtocolGuid
,
1328 (VOID
**) &FormBrowser2
1330 if (EFI_ERROR (Status
)) {
1334 CallbackInfo
= AllocateZeroPool (sizeof (EFI_CALLBACK_INFO
));
1335 if (CallbackInfo
== NULL
) {
1336 return EFI_BAD_BUFFER_SIZE
;
1339 CallbackInfo
->Signature
= EFI_CALLBACK_INFO_SIGNATURE
;
1340 CallbackInfo
->ConfigAccess
.ExtractConfig
= PlatOverMngrExtractConfig
;
1341 CallbackInfo
->ConfigAccess
.RouteConfig
= PlatOverMngrRouteConfig
;
1342 CallbackInfo
->ConfigAccess
.Callback
= PlatOverMngrCallback
;
1345 // Create driver handle used by HII database
1347 Status
= HiiLibCreateHiiDriverHandle (&DriverHandle
);
1348 if (EFI_ERROR (Status
)) {
1351 CallbackInfo
->DriverHandle
= DriverHandle
;
1354 // Install Config Access protocol to driver handle
1356 Status
= gBS
->InstallProtocolInterface (
1358 &gEfiHiiConfigAccessProtocolGuid
,
1359 EFI_NATIVE_INTERFACE
,
1360 &CallbackInfo
->ConfigAccess
1362 if (EFI_ERROR (Status
)) {
1367 // Publish our HII data
1369 PackageList
= HiiLibPreparePackageList (
1371 &mPlatformOverridesManagerGuid
,
1375 ASSERT (PackageList
!= NULL
);
1377 Status
= HiiDatabase
->NewPackageList (
1381 &CallbackInfo
->RegisteredHandle
1383 FreePool (PackageList
);
1385 if (EFI_ERROR (Status
)) {
1390 // Locate ConfigRouting protocol
1392 Status
= gBS
->LocateProtocol (
1393 &gEfiHiiConfigRoutingProtocolGuid
,
1395 (VOID
**) &CallbackInfo
->HiiConfigRouting
1397 if (EFI_ERROR (Status
)) {
1402 // Clear all the globle variable
1404 mDriverImageHandleCount
= 0;
1406 ZeroMem (mDriverImageToken
, MAX_CHOICE_NUM
* sizeof (EFI_STRING_ID
));
1407 ZeroMem (mDriverImageFilePathToken
, MAX_CHOICE_NUM
* sizeof (EFI_STRING_ID
));
1408 ZeroMem (mControllerToken
, MAX_CHOICE_NUM
* sizeof (EFI_STRING_ID
));
1409 ZeroMem (mDriverImageProtocol
, MAX_CHOICE_NUM
* sizeof (EFI_LOADED_IMAGE_PROTOCOL
*));
1414 Status
= FormBrowser2
->SendForm (
1416 &CallbackInfo
->RegisteredHandle
,
1423 if (EFI_ERROR (Status
)) {
1427 Status
= HiiDatabase
->RemovePackageList (HiiDatabase
, CallbackInfo
->RegisteredHandle
);
1428 if (EFI_ERROR (Status
)) {
1435 if (CallbackInfo
->DriverHandle
!= NULL
) {
1436 HiiLibDestroyHiiDriverHandle (CallbackInfo
->DriverHandle
);
1438 if (CallbackInfo
!= NULL
) {
1439 FreePool (CallbackInfo
);