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>
40 #include <Library/BaseLib.h>
41 #include <Library/DebugLib.h>
42 #include <Library/UefiLib.h>
43 #include <Library/UefiApplicationEntryPoint.h>
44 #include <Library/UefiBootServicesTableLib.h>
45 #include <Library/PlatDriOverLib.h>
46 #include <Library/HiiLib.h>
47 #include <Library/IfrSupportLib.h>
48 #include <Library/ExtendedHiiLib.h>
49 #include <Library/ExtendedIfrSupportLib.h>
50 #include <Library/BaseMemoryLib.h>
51 #include <Library/MemoryAllocationLib.h>
52 #include <Library/UefiRuntimeServicesTableLib.h>
53 #include <Library/DevicePathLib.h>
54 #include <Library/GenericBdsLib.h>
55 #include "PlatOverMngr.h"
57 #define EFI_CALLBACK_INFO_SIGNATURE SIGNATURE_32 ('C', 'l', 'b', 'k')
58 #define EFI_CALLBACK_INFO_FROM_THIS(a) CR (a, EFI_CALLBACK_INFO, ConfigAccess, EFI_CALLBACK_INFO_SIGNATURE)
62 EFI_HANDLE DriverHandle
;
63 EFI_HII_HANDLE RegisteredHandle
;
64 PLAT_OVER_MNGR_DATA FakeNvData
;
65 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
66 EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess
;
70 // uni string and Vfr Binary data.
72 extern UINT8 VfrBin
[];
73 extern UINT8 PlatOverMngrStrings
[];
78 EFI_GUID mPlatformOverridesManagerGuid
= PLAT_OVER_MNGR_GUID
;
79 LIST_ENTRY mMappingDataBase
= INITIALIZE_LIST_HEAD_VARIABLE (mMappingDataBase
);
81 EFI_HANDLE
*mDevicePathHandleBuffer
;
82 EFI_HANDLE
*mDriverImageHandleBuffer
;
84 UINTN mSelectedCtrIndex
;
85 EFI_STRING_ID mControllerToken
[MAX_CHOICE_NUM
];
86 UINTN mDriverImageHandleCount
;
87 EFI_STRING_ID mDriverImageToken
[MAX_CHOICE_NUM
];
88 EFI_STRING_ID mDriverImageFilePathToken
[MAX_CHOICE_NUM
];
89 EFI_LOADED_IMAGE_PROTOCOL
*mDriverImageProtocol
[MAX_CHOICE_NUM
];
90 EFI_DEVICE_PATH_PROTOCOL
*mControllerDevicePathProtocol
[MAX_CHOICE_NUM
];
91 UINTN mSelectedDriverImageNum
;
92 UINTN mLastSavedDriverImageNum
;
93 CHAR8 mLanguage
[RFC_3066_ENTRY_SIZE
];
97 Do string convertion for the ComponentName supported language. It do
98 the convertion just for english language code from RFC 3066 to ISO 639-2.
99 Then it will check whether the converted language is in the supported language list.
100 If not supported, NULL is returned.
101 If Language is not english, NULL is returned.
103 @param SupportedLanguages Pointer to ComponentName supported language string list. ISO 639-2 language
104 @param Language The language string. RFC 3066 language
106 @return English language string (ISO 639-2)
107 @return NULL if the conertion is not successful.
111 ConvertComponentNameSupportLanguage (
112 IN CHAR8
*SupportedLanguages
,
120 // Check the input language is English
122 if (AsciiStrnCmp (Language
, "en-", 3) != 0) {
127 // Check SupportedLanguages format
129 if (AsciiStrStr (SupportedLanguages
, "en-") != NULL
) {
131 // Create RFC 3066 language
133 LangCode
= AllocateZeroPool(AsciiStrSize (Language
));
134 AsciiStrCpy (LangCode
, Language
);
135 } else if (AsciiStrStr (SupportedLanguages
, "en") != NULL
) {
137 // Create ISO 639-2 Language
139 LangCode
= AllocateZeroPool(4);
140 AsciiStrCpy (LangCode
, "eng");
147 Get the driver name by ComponentName or ComponentName2 protocol
148 according to the driver binding handle
150 @param DriverBindingHandle The Handle of DriverBinding.
152 @retval !NULL Pointer into the image name if the image name is found,
153 @retval NULL Pointer to NULL if the image name is not found.
158 IN EFI_HANDLE DriverBindingHandle
162 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
163 EFI_COMPONENT_NAME2_PROTOCOL
*ComponentName2
;
164 CHAR8
*SupportedLanguage
;
167 ComponentName
= NULL
;
168 ComponentName2
= NULL
;
169 Status
= gBS
->OpenProtocol (
171 &gEfiComponentName2ProtocolGuid
,
172 (VOID
**) &ComponentName2
,
175 EFI_OPEN_PROTOCOL_GET_PROTOCOL
177 if (EFI_ERROR(Status
)) {
178 Status
= gBS
->OpenProtocol (
180 &gEfiComponentNameProtocolGuid
,
181 (VOID
**) &ComponentName
,
184 EFI_OPEN_PROTOCOL_GET_PROTOCOL
188 Status
= EFI_SUCCESS
;
190 if (ComponentName
!= NULL
) {
191 if (ComponentName
->GetDriverName
!= NULL
) {
192 SupportedLanguage
= ConvertComponentNameSupportLanguage (ComponentName
->SupportedLanguages
, mLanguage
);
193 if (SupportedLanguage
!= NULL
) {
194 Status
= ComponentName
->GetDriverName (
199 FreePool (SupportedLanguage
);
202 } else if (ComponentName2
!= NULL
) {
203 if (ComponentName2
->GetDriverName
!= NULL
) {
204 Status
= ComponentName2
->GetDriverName (
212 if (EFI_ERROR (Status
)) {
220 Get the image name from EFI UI section.
221 Get FV protocol by its loaded image protoocl to abastract EFI UI section.
223 @param Image Pointer to the loaded image protocol
225 @retval !NULL Pointer to the image name if the image name is found,
226 @retval NULL NULL if the image name is not found.
231 IN EFI_LOADED_IMAGE_PROTOCOL
*Image
235 EFI_DEVICE_PATH_PROTOCOL
*DevPathNode
;
236 EFI_DEVICE_PATH_PROTOCOL
*AlignedDevPathNode
;
237 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*FvFilePath
;
240 UINT32 AuthenticationStatus
;
242 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv2
;
248 if (Image
->FilePath
== NULL
) {
251 DevPathNode
= Image
->FilePath
;
253 while (!IsDevicePathEnd (DevPathNode
)) {
255 // Make sure device path node is aligned when accessing it's FV Name Guid field.
257 AlignedDevPathNode
= AllocateCopyPool (DevicePathNodeLength(DevPathNode
), DevPathNode
);
260 // Find the Fv File path
262 NameGuid
= EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*)AlignedDevPathNode
);
263 if (NameGuid
!= NULL
) {
264 FvFilePath
= (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*) AlignedDevPathNode
;
265 Status
= gBS
->HandleProtocol (
267 &gEfiFirmwareVolume2ProtocolGuid
,
271 // Locate Image EFI UI section to get the image name.
273 if (!EFI_ERROR (Status
)) {
274 Status
= Fv2
->ReadSection (
276 &FvFilePath
->FvFileName
,
277 EFI_SECTION_USER_INTERFACE
,
281 &AuthenticationStatus
283 if (!EFI_ERROR (Status
)) {
284 FreePool (AlignedDevPathNode
);
291 FreePool (AlignedDevPathNode
);
294 // Next device path node
296 DevPathNode
= NextDevicePathNode (DevPathNode
);
303 Prepare the first page to let user select the device controller which need to
304 add mapping drivers if user select 'Refresh' in first page.
305 During first page, user will see all currnet controller device path in system,
306 select any device path will go to second page to select its overrides drivers.
308 @param Private Pointer to EFI_CALLBACK_INFO.
309 @param KeyValue The callback key value of device controller item in first page.
310 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
312 @retval EFI_SUCCESS Always returned.
316 UpdateDeviceSelectPage (
317 IN EFI_CALLBACK_INFO
*Private
,
319 IN PLAT_OVER_MNGR_DATA
*FakeNvData
322 EFI_HII_UPDATE_DATA UpdateData
;
326 UINTN DevicePathHandleCount
;
328 EFI_STRING_ID NewStringToken
;
329 CHAR16
*ControllerName
;
330 EFI_DEVICE_PATH_PROTOCOL
*ControllerDevicePath
;
331 EFI_PCI_IO_PROTOCOL
*PciIo
;
332 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*BusSpecificDriverOverride
;
336 // set current page form ID.
338 mCurrentPage
= FORM_ID_DEVICE
;
341 // Get Platform supported Language (RFC_3066 format)
343 LangSize
= RFC_3066_ENTRY_SIZE
;
344 Status
= gRT
->GetVariable (
346 &gEfiGlobalVariableGuid
,
351 ASSERT_EFI_ERROR (Status
);
354 // Initial the mapping database in memory
356 FreeMappingDatabase (&mMappingDataBase
);
357 Status
= InitOverridesMapping (&mMappingDataBase
);
360 // Clear all the content in the first page
362 UpdateData
.BufferSize
= UPDATE_DATA_SIZE
;
363 UpdateData
.Offset
= 0;
364 UpdateData
.Data
= AllocateZeroPool (UPDATE_DATA_SIZE
);
365 ASSERT (UpdateData
.Data
!= NULL
);
367 // Clear first page form
370 Private
->RegisteredHandle
,
371 &mPlatformOverridesManagerGuid
,
379 // When user enter the page at first time, the 'first refresh' string is given to notify user to refresh all the drivers,
380 // then the 'first refresh' string will be replaced by the 'refresh' string, and the two strings content are same after the replacement
382 NewStringToken
= STRING_TOKEN (STR_FIRST_REFRESH
);
383 HiiLibGetStringFromHandle (Private
->RegisteredHandle
, STRING_TOKEN (STR_REFRESH
), &NewString
);
384 ASSERT (NewString
!= NULL
);
385 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
);
386 ASSERT_EFI_ERROR (Status
);
387 FreePool (NewString
);
389 NewStringToken
= STRING_TOKEN (STR_FIRST_REFRESH_HELP
);
390 HiiLibGetStringFromHandle (Private
->RegisteredHandle
, STRING_TOKEN (STR_REFRESH_HELP
), &NewString
);
391 ASSERT (NewString
!= NULL
);
392 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
);
393 ASSERT_EFI_ERROR (Status
);
394 FreePool (NewString
);
397 // created needed controller device item in first page
399 DevicePathHandleCount
= 0;
400 Status
= gBS
->LocateHandleBuffer (
402 &gEfiDevicePathProtocolGuid
,
404 &DevicePathHandleCount
,
405 &mDevicePathHandleBuffer
407 if (EFI_ERROR (Status
) || (DevicePathHandleCount
== 0)) {
411 for (Index
= 0; Index
< DevicePathHandleCount
; Index
++) {
412 if (FakeNvData
->PciDeviceFilter
== 0x01) {
414 // Only care PCI device which contain efi driver in its option rom.
418 // Check whether it is a pci device
420 ControllerDevicePath
= NULL
;
421 Status
= gBS
->OpenProtocol (
422 mDevicePathHandleBuffer
[Index
],
423 &gEfiPciIoProtocolGuid
,
427 EFI_OPEN_PROTOCOL_GET_PROTOCOL
429 if (EFI_ERROR (Status
)) {
433 // Check whether it contain efi driver in its option rom
435 Status
= gBS
->HandleProtocol(
436 mDevicePathHandleBuffer
[Index
],
437 &gEfiBusSpecificDriverOverrideProtocolGuid
,
438 (VOID
**) &BusSpecificDriverOverride
440 if (EFI_ERROR (Status
) || BusSpecificDriverOverride
== NULL
) {
445 ControllerDevicePath
= NULL
;
446 Status
= gBS
->OpenProtocol (
447 mDevicePathHandleBuffer
[Index
],
448 &gEfiDevicePathProtocolGuid
,
449 (VOID
**) &ControllerDevicePath
,
452 EFI_OPEN_PROTOCOL_GET_PROTOCOL
454 ASSERT_EFI_ERROR (Status
);
456 // Save the device path protocol interface
458 mControllerDevicePathProtocol
[Index
] = ControllerDevicePath
;
461 // Get the driver name
463 ControllerName
= DevicePathToStr (ControllerDevicePath
);
466 // Export the driver name string and create item in set options page
468 Len
= StrSize (ControllerName
);
469 NewString
= AllocateZeroPool (Len
+ StrSize (L
"--"));
470 ASSERT (NewString
!= NULL
);
471 if (EFI_ERROR (CheckMapping (ControllerDevicePath
,NULL
, &mMappingDataBase
, NULL
, NULL
))) {
472 StrCat (NewString
, L
"--");
474 StrCat (NewString
, L
"**");
476 StrCat (NewString
, ControllerName
);
478 NewStringToken
= mControllerToken
[Index
];
479 if (NewStringToken
== 0) {
480 Status
= HiiLibNewString (Private
->RegisteredHandle
, &NewStringToken
, NewString
);
482 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
);
484 ASSERT_EFI_ERROR (Status
);
485 FreePool (NewString
);
487 // Save the device path string toke for next access use
489 mControllerToken
[Index
] = NewStringToken
;
494 STRING_TOKEN (STR_GOTO_HELP_DRIVER
),
495 EFI_IFR_FLAG_CALLBACK
,
496 (UINT16
) (Index
+ KEY_VALUE_DEVICE_OFFSET
),
502 // Update first page form
505 Private
->RegisteredHandle
,
506 &mPlatformOverridesManagerGuid
,
513 FreePool (UpdateData
.Data
);
518 Get the first Driver Binding handle which has the specific image handle.
520 @param ImageHandle The Image handle
522 @return Handle to Driver binding
523 @retval NULL The paramter is not valid or the driver binding handle is not found.
527 GetDriverBindingHandleFromImageHandle (
528 IN EFI_HANDLE ImageHandle
533 UINTN DriverBindingHandleCount
;
534 EFI_HANDLE
*DriverBindingHandleBuffer
;
535 EFI_DRIVER_BINDING_PROTOCOL
*DriverBindingInterface
;
536 EFI_HANDLE DriverBindingHandle
;
538 DriverBindingHandle
= NULL
;
540 if (ImageHandle
== NULL
) {
544 // Get all drivers which support driver binding protocol
546 DriverBindingHandleCount
= 0;
547 Status
= gBS
->LocateHandleBuffer (
549 &gEfiDriverBindingProtocolGuid
,
551 &DriverBindingHandleCount
,
552 &DriverBindingHandleBuffer
554 if (EFI_ERROR (Status
) || (DriverBindingHandleCount
== 0)) {
559 // Get the first Driver Binding handle which has the specific image handle.
561 for (Index
= 0; Index
< DriverBindingHandleCount
; Index
++) {
562 DriverBindingInterface
= NULL
;
563 Status
= gBS
->OpenProtocol (
564 DriverBindingHandleBuffer
[Index
],
565 &gEfiDriverBindingProtocolGuid
,
566 (VOID
**) &DriverBindingInterface
,
569 EFI_OPEN_PROTOCOL_GET_PROTOCOL
571 if (EFI_ERROR (Status
)) {
575 if (DriverBindingInterface
->ImageHandle
== ImageHandle
) {
576 DriverBindingHandle
= DriverBindingHandleBuffer
[Index
];
581 FreePool (DriverBindingHandleBuffer
);
582 return DriverBindingHandle
;
586 Prepare to let user select the drivers which need mapping with the device controller
587 selected in first page.
589 @param Private Pointer to EFI_CALLBACK_INFO.
590 @param KeyValue The callback key value of device controller item in first page.
591 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
593 @retval EFI_SUCCESS Always returned.
597 UpdateBindingDriverSelectPage (
598 IN EFI_CALLBACK_INFO
*Private
,
600 IN PLAT_OVER_MNGR_DATA
*FakeNvData
603 EFI_HII_UPDATE_DATA UpdateData
;
607 EFI_STRING_ID NewStringToken
;
608 EFI_STRING_ID NewStringHelpToken
;
609 UINTN DriverImageHandleCount
;
610 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
612 BOOLEAN FreeDriverName
;
613 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
614 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*BusSpecificDriverOverride
;
615 EFI_HANDLE DriverBindingHandle
;
618 // If user select a controller item in the first page the following code will be run.
619 // During second page, user will see all currnet driver bind protocol driver, the driver name and its device path will be shown
621 //First acquire the list of Loaded Image Protocols, and then when want the name of the driver, look up all the Driver Binding Protocols
622 // and find the first one whose ImageHandle field matches the image handle of the Loaded Image Protocol.
623 // 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.
626 mCurrentPage
= FORM_ID_DRIVER
;
628 // Switch the item callback key value to its NO. in mDevicePathHandleBuffer
630 mSelectedCtrIndex
= KeyValue
- KEY_VALUE_DEVICE_OFFSET
;
631 ASSERT (mSelectedCtrIndex
< MAX_CHOICE_NUM
);
632 mLastSavedDriverImageNum
= 0;
634 // Clear all the content in dynamic page
636 UpdateData
.BufferSize
= UPDATE_DATA_SIZE
;
637 UpdateData
.Offset
= 0;
638 UpdateData
.Data
= AllocateZeroPool (UPDATE_DATA_SIZE
);
639 ASSERT (UpdateData
.Data
!= NULL
);
641 // Clear second page form
644 Private
->RegisteredHandle
,
645 &mPlatformOverridesManagerGuid
,
653 // Show all driver which support loaded image protocol in second page
655 DriverImageHandleCount
= 0;
656 Status
= gBS
->LocateHandleBuffer (
658 &gEfiLoadedImageProtocolGuid
,
660 &DriverImageHandleCount
,
661 &mDriverImageHandleBuffer
663 if (EFI_ERROR (Status
) || (DriverImageHandleCount
== 0)) {
664 return EFI_NOT_FOUND
;
667 mDriverImageHandleCount
= DriverImageHandleCount
;
668 for (Index
= 0; Index
< DriverImageHandleCount
; Index
++) {
670 // Step1: Get the driver image total file path for help string and the driver name.
674 // Find driver's Loaded Image protocol
678 Status
= gBS
->OpenProtocol (
679 mDriverImageHandleBuffer
[Index
],
680 &gEfiLoadedImageProtocolGuid
,
681 (VOID
**) &LoadedImage
,
684 EFI_OPEN_PROTOCOL_GET_PROTOCOL
686 if (EFI_ERROR (Status
)) {
687 FakeNvData
->DriSelection
[Index
] = 0x00;
690 mDriverImageProtocol
[Index
] = LoadedImage
;
692 // Find its related driver binding protocol
694 DriverBindingHandle
= GetDriverBindingHandleFromImageHandle (mDriverImageHandleBuffer
[Index
]);
695 if (DriverBindingHandle
== NULL
) {
696 FakeNvData
->DriSelection
[Index
] = 0x00;
701 // Get the EFI Loaded Image Device Path Protocol
703 LoadedImageDevicePath
= NULL
;
704 Status
= gBS
->HandleProtocol (
705 mDriverImageHandleBuffer
[Index
],
706 &gEfiLoadedImageDevicePathProtocolGuid
,
707 (VOID
**) &LoadedImageDevicePath
709 if (LoadedImageDevicePath
== NULL
) {
710 FakeNvData
->DriSelection
[Index
] = 0x00;
714 if (FakeNvData
->PciDeviceFilter
== 0x01) {
716 // only care the driver which is in a Pci device option rom,
717 // and the driver's LoadedImage->DeviceHandle must point to a pci device which has efi option rom
719 if (!EFI_ERROR (Status
)) {
720 Status
= gBS
->HandleProtocol(
721 LoadedImage
->DeviceHandle
,
722 &gEfiBusSpecificDriverOverrideProtocolGuid
,
723 (VOID
**) &BusSpecificDriverOverride
725 if (EFI_ERROR (Status
) || BusSpecificDriverOverride
== NULL
) {
726 FakeNvData
->DriSelection
[Index
] = 0x00;
730 FakeNvData
->DriSelection
[Index
] = 0x00;
736 // For driver name, try to get its component name, if fail, get its image name,
737 // if also fail, give a default name.
739 FreeDriverName
= FALSE
;
740 DriverName
= GetComponentName (DriverBindingHandle
);
741 if (DriverName
== NULL
) {
743 // get its image name
745 DriverName
= GetImageName (LoadedImage
);
747 if (DriverName
== NULL
) {
749 // give a default name
751 HiiLibGetStringFromHandle (Private
->RegisteredHandle
, STRING_TOKEN (STR_DRIVER_DEFAULT_NAME
), &DriverName
);
752 ASSERT (DriverName
!= NULL
);
753 FreeDriverName
= TRUE
; // the DriverName string need to free pool
758 // Step2 Export the driver name string and create check box item in second page
762 // First create the driver image name
764 NewString
= AllocateZeroPool (StrSize (DriverName
));
765 ASSERT (NewString
!= NULL
);
766 if (EFI_ERROR (CheckMapping (mControllerDevicePathProtocol
[mSelectedCtrIndex
], LoadedImageDevicePath
, &mMappingDataBase
, NULL
, NULL
))) {
767 FakeNvData
->DriSelection
[Index
] = 0x00;
769 FakeNvData
->DriSelection
[Index
] = 0x01;
770 mLastSavedDriverImageNum
++;
772 StrCat (NewString
, DriverName
);
773 NewStringToken
= mDriverImageToken
[Index
];
774 if (NewStringToken
== 0) {
775 Status
= HiiLibNewString (Private
->RegisteredHandle
, &NewStringToken
, NewString
);
777 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
);
779 mDriverImageToken
[Index
] = NewStringToken
;
780 ASSERT_EFI_ERROR (Status
);
781 FreePool (NewString
);
782 if (FreeDriverName
) {
783 FreePool (DriverName
);
787 // Second create the driver image device path as item help string
789 DriverName
= DevicePathToStr (LoadedImageDevicePath
);
791 NewString
= AllocateZeroPool (StrSize (DriverName
));
792 StrCat (NewString
, DriverName
);
793 NewStringHelpToken
= mDriverImageFilePathToken
[Index
];
794 if (NewStringHelpToken
== 0) {
795 Status
= HiiLibNewString (Private
->RegisteredHandle
, &NewStringHelpToken
, NewString
);
797 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringHelpToken
, NewString
);
799 mDriverImageFilePathToken
[Index
] = NewStringHelpToken
;
800 ASSERT_EFI_ERROR (Status
);
801 FreePool (NewString
);
802 FreePool (DriverName
);
804 CreateCheckBoxOpCode (
805 (UINT16
) (DRIVER_SELECTION_QUESTION_ID
+ Index
),
806 VARSTORE_ID_PLAT_OVER_MNGR
,
807 (UINT16
) (DRIVER_SELECTION_VAR_OFFSET
+ Index
),
817 // Update second page form
820 Private
->RegisteredHandle
,
821 &mPlatformOverridesManagerGuid
,
828 FreePool (UpdateData
.Data
);
833 Prepare to let user select the priority order of the drivers which are
834 selected in second page.
836 @param Private Pointer to EFI_CALLBACK_INFO.
837 @param KeyValue The callback key value of device controller item in first page.
838 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
840 @retval EFI_SUCCESS Always returned.
844 UpdatePrioritySelectPage (
845 IN EFI_CALLBACK_INFO
*Private
,
847 IN PLAT_OVER_MNGR_DATA
*FakeNvData
850 EFI_HII_UPDATE_DATA UpdateData
;
852 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
853 IFR_OPTION
*IfrOptionList
;
854 UINTN SelectedDriverImageNum
;
855 UINT32 DriverImageNO
;
861 // Following code will be run if user select 'order ... priority' item in second page
862 // Prepare third page. In third page, user will order the drivers priority which are selected in second page
864 mCurrentPage
= FORM_ID_ORDER
;
866 UpdateData
.BufferSize
= UPDATE_DATA_SIZE
;
867 UpdateData
.Offset
= 0;
868 UpdateData
.Data
= AllocateZeroPool (UPDATE_DATA_SIZE
);
869 ASSERT (UpdateData
.Data
!= NULL
);
871 // Clear third page form
874 Private
->RegisteredHandle
,
875 &mPlatformOverridesManagerGuid
,
883 // Check how many drivers have been selected
885 SelectedDriverImageNum
= 0;
886 for (Index
= 0; Index
< mDriverImageHandleCount
; Index
++) {
887 if (FakeNvData
->DriSelection
[Index
] != 0) {
888 SelectedDriverImageNum
++;
892 mSelectedDriverImageNum
= SelectedDriverImageNum
;
893 if (SelectedDriverImageNum
== 0) {
897 IfrOptionList
= AllocateZeroPool (sizeof (IFR_OPTION
) * mSelectedDriverImageNum
);
898 ASSERT (IfrOptionList
!= NULL
);
900 // Create order list for those selected drivers
902 SelectedDriverImageNum
= 0;
903 for (Index
= 0; Index
< mDriverImageHandleCount
; Index
++) {
904 if (FakeNvData
->DriSelection
[Index
] != 0) {
905 IfrOptionList
[SelectedDriverImageNum
].StringToken
= mDriverImageToken
[Index
];
907 // Use the NO. in driver binding buffer as value, will use it later
909 IfrOptionList
[SelectedDriverImageNum
].Value
.u8
= (UINT8
) (Index
+ 1);
910 IfrOptionList
[SelectedDriverImageNum
].Flags
= 0;
913 // Get the EFI Loaded Image Device Path Protocol
915 LoadedImageDevicePath
= NULL
;
916 gBS
->HandleProtocol (
917 mDriverImageHandleBuffer
[Index
],
918 &gEfiLoadedImageDevicePathProtocolGuid
,
919 (VOID
**) &LoadedImageDevicePath
921 ASSERT (LoadedImageDevicePath
!= NULL
);
924 // Check the driver DriverImage's order number in mapping database
928 mControllerDevicePathProtocol
[mSelectedCtrIndex
],
929 LoadedImageDevicePath
,
934 if (DriverImageNO
== 0) {
935 DriverImageNO
= (UINT32
) mLastSavedDriverImageNum
+ 1;
936 mLastSavedDriverImageNum
++;
938 TempNO
[SelectedDriverImageNum
] = DriverImageNO
;
939 SelectedDriverImageNum
++;
943 ASSERT (SelectedDriverImageNum
== mSelectedDriverImageNum
);
945 // NvRamMap Must be clear firstly
947 ZeroMem (FakeNvData
->DriOrder
, sizeof (FakeNvData
->DriOrder
));
950 // Order the selected drivers according to the info already in mapping database
951 // the less order number in mapping database the less order number in NvRamMap
953 for (Index
=0; Index
< SelectedDriverImageNum
; Index
++) {
955 // Find the minimal order number in TempNO array, its index in TempNO is same as IfrOptionList array
958 for (Index1
=0; Index1
< SelectedDriverImageNum
; Index1
++) {
959 if (TempNO
[Index1
] < TempNO
[MinNO
]) {
964 // the IfrOptionList[MinNO].Value = the driver NO. in driver binding buffer
966 FakeNvData
->DriOrder
[Index
] =IfrOptionList
[MinNO
].Value
.u8
;
967 TempNO
[MinNO
] = MAX_CHOICE_NUM
+ 1;
970 CreateOrderedListOpCode (
971 (UINT16
) DRIVER_ORDER_QUESTION_ID
,
972 VARSTORE_ID_PLAT_OVER_MNGR
,
973 (UINT16
) DRIVER_ORDER_VAR_OFFSET
,
974 mControllerToken
[mSelectedCtrIndex
],
975 mControllerToken
[mSelectedCtrIndex
],
976 EFI_IFR_FLAG_RESET_REQUIRED
,
978 EFI_IFR_NUMERIC_SIZE_1
,
979 (UINT8
) MAX_CHOICE_NUM
,
981 SelectedDriverImageNum
,
986 // Update third page form
989 Private
->RegisteredHandle
,
990 &mPlatformOverridesManagerGuid
,
997 FreePool (IfrOptionList
);
998 FreePool (UpdateData
.Data
);
1003 Save the save the mapping database to NV variable.
1005 @param Private Pointer to EFI_CALLBACK_INFO.
1006 @param KeyValue The callback key value of device controller item in first page.
1007 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
1009 @retval EFI_SUCCESS Always returned.
1014 IN EFI_CALLBACK_INFO
*Private
,
1016 IN PLAT_OVER_MNGR_DATA
*FakeNvData
1021 UINTN SelectedDriverImageNum
;
1022 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
1024 // Following code will be run if user select 'commint changes' in third page
1025 // user enter 'Commit Changes' to save the mapping database
1027 DeleteDriverImage (mControllerDevicePathProtocol
[mSelectedCtrIndex
], NULL
, &mMappingDataBase
);
1028 for (SelectedDriverImageNum
= 0; SelectedDriverImageNum
< mSelectedDriverImageNum
; SelectedDriverImageNum
++) {
1030 // DriOrder[SelectedDriverImageNum] = the driver NO. in driver binding buffer
1032 Index
= FakeNvData
->DriOrder
[SelectedDriverImageNum
] - 1;
1035 // Get the EFI Loaded Image Device Path Protocol
1037 LoadedImageDevicePath
= NULL
;
1038 Status
= gBS
->HandleProtocol (
1039 mDriverImageHandleBuffer
[Index
],
1040 &gEfiLoadedImageDevicePathProtocolGuid
,
1041 (VOID
**) &LoadedImageDevicePath
1043 ASSERT (LoadedImageDevicePath
!= NULL
);
1046 mControllerDevicePathProtocol
[mSelectedCtrIndex
],
1047 LoadedImageDevicePath
,
1049 (UINT32
)SelectedDriverImageNum
+ 1
1052 Status
= SaveOverridesMapping (&mMappingDataBase
);
1058 This function allows a caller to extract the current configuration for one
1059 or more named elements from the target driver.
1061 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1062 @param Request A null-terminated Unicode string in <ConfigRequest> format.
1063 @param Progress On return, points to a character in the Request string.
1064 Points to the string's null terminator if request was successful.
1065 Points to the most recent '&' before the first failing name/value
1066 pair (or the beginning of the string if the failure is in the
1067 first name/value pair) if the request was not successful.
1068 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
1069 has all values filled in for the names in the Request string.
1070 String to be allocated by the called function.
1072 @retval EFI_SUCCESS The Results is filled with the requested values.
1073 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
1074 @retval EFI_INVALID_PARAMETER Request is NULL, illegal syntax, or unknown name.
1075 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
1080 PlatOverMngrExtractConfig (
1081 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1082 IN CONST EFI_STRING Request
,
1083 OUT EFI_STRING
*Progress
,
1084 OUT EFI_STRING
*Results
1088 EFI_CALLBACK_INFO
*Private
;
1089 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
1091 if (Request
== NULL
) {
1092 return EFI_NOT_FOUND
;
1095 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1096 HiiConfigRouting
= Private
->HiiConfigRouting
;
1099 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
1101 Status
= HiiConfigRouting
->BlockToConfig (
1104 (UINT8
*) &Private
->FakeNvData
,
1105 sizeof (PLAT_OVER_MNGR_DATA
),
1113 This function processes the results of changes in configuration.
1115 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1116 @param Configuration A null-terminated Unicode string in <ConfigRequest> format.
1117 @param Progress A pointer to a string filled in with the offset of the most
1118 recent '&' before the first failing name/value pair (or the
1119 beginning of the string if the failure is in the first
1120 name/value pair) or the terminating NULL if all was successful.
1122 @retval EFI_SUCCESS The Results is processed successfully.
1123 @retval EFI_INVALID_PARAMETER Configuration is NULL.
1124 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
1129 PlatOverMngrRouteConfig (
1130 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1131 IN CONST EFI_STRING Configuration
,
1132 OUT EFI_STRING
*Progress
1135 EFI_CALLBACK_INFO
*Private
;
1139 PLAT_OVER_MNGR_DATA
*FakeNvData
;
1141 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1143 FakeNvData
= &Private
->FakeNvData
;
1144 BufferSize
= sizeof (PLAT_OVER_MNGR_DATA
);
1145 Status
= GetBrowserData (NULL
, NULL
, &BufferSize
, (UINT8
*) FakeNvData
);
1146 if (EFI_ERROR (Status
)) {
1150 if (mCurrentPage
== FORM_ID_DRIVER
) {
1151 KeyValue
= KEY_VALUE_DRIVER_GOTO_ORDER
;
1152 UpdatePrioritySelectPage (Private
, KeyValue
, FakeNvData
);
1153 KeyValue
= KEY_VALUE_ORDER_SAVE_AND_EXIT
;
1154 CommintChanges (Private
, KeyValue
, FakeNvData
);
1156 // Since UpdatePrioritySelectPage will change mCurrentPage,
1157 // should ensure the mCurrentPage still indicate the second page here
1159 mCurrentPage
= FORM_ID_DRIVER
;
1162 if (mCurrentPage
== FORM_ID_ORDER
) {
1163 KeyValue
= KEY_VALUE_ORDER_SAVE_AND_EXIT
;
1164 CommintChanges (Private
, KeyValue
, FakeNvData
);
1170 This is the function that is called to provide results data to the driver. This data
1171 consists of a unique key which is used to identify what data is either being passed back
1174 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1175 @param Action A null-terminated Unicode string in <ConfigRequest> format.
1176 @param KeyValue A unique Goto OpCode callback value which record user's selection.
1177 0x100 <= KeyValue <0x500 : user select a controller item in the first page;
1178 KeyValue == 0x1234 : user select 'Refresh' in first page, or user select 'Go to Previous Menu' in second page
1179 KeyValue == 0x1235 : user select 'Pci device filter' in first page
1180 KeyValue == 0x1500 : user select 'order ... priority' item in second page
1181 KeyValue == 0x1800 : user select 'commint changes' in third page
1182 KeyValue == 0x2000 : user select 'Go to Previous Menu' in third page
1183 @param Type The type of value for the question.
1184 @param Value A pointer to the data being sent to the original exporting driver.
1185 @param ActionRequest On return, points to the action requested by the callback function.
1187 @retval EFI_SUCCESS Always returned.
1192 PlatOverMngrCallback (
1193 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1194 IN EFI_BROWSER_ACTION Action
,
1195 IN EFI_QUESTION_ID KeyValue
,
1197 IN EFI_IFR_TYPE_VALUE
*Value
,
1198 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
1201 EFI_CALLBACK_INFO
*Private
;
1203 EFI_STRING_ID NewStringToken
;
1205 PLAT_OVER_MNGR_DATA
*FakeNvData
;
1208 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1210 FakeNvData
= &Private
->FakeNvData
;
1211 BufferSize
= sizeof (PLAT_OVER_MNGR_DATA
);
1212 Status
= GetBrowserData (NULL
, NULL
, &BufferSize
, (UINT8
*) FakeNvData
);
1213 if (EFI_ERROR (Status
)) {
1217 if (KeyValue
== KEY_VALUE_DEVICE_REFRESH
||
1218 KeyValue
== KEY_VALUE_DEVICE_FILTER
||
1219 KeyValue
== KEY_VALUE_DRIVER_GOTO_PREVIOUS
1221 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1223 // Update page title string
1225 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1226 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, L
"First, Select the controller by device path");
1227 ASSERT_EFI_ERROR (Status
);
1230 if (((KEY_VALUE_DEVICE_OFFSET
<= KeyValue
) && (KeyValue
< KEY_VALUE_DEVICE_MAX
)) || (KeyValue
== KEY_VALUE_ORDER_GOTO_PREVIOUS
)) {
1231 if (KeyValue
== KEY_VALUE_ORDER_GOTO_PREVIOUS
) {
1232 KeyValue
= (EFI_QUESTION_ID
) (mSelectedCtrIndex
+ KEY_VALUE_DEVICE_OFFSET
);
1234 UpdateBindingDriverSelectPage (Private
, KeyValue
, FakeNvData
);
1236 // Update page title string
1238 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1239 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, L
"Second, Select drivers for the previous selected controller");
1240 ASSERT_EFI_ERROR (Status
);
1243 if (KeyValue
== KEY_VALUE_DRIVER_GOTO_ORDER
) {
1244 UpdatePrioritySelectPage (Private
, KeyValue
, FakeNvData
);
1246 // Update page title string
1248 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1249 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, L
"Finally, Set the priority order for the drivers and save them");
1250 ASSERT_EFI_ERROR (Status
);
1253 if (KeyValue
== KEY_VALUE_ORDER_SAVE_AND_EXIT
) {
1254 Status
= CommintChanges (Private
, KeyValue
, FakeNvData
);
1255 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1256 if (EFI_ERROR (Status
)) {
1257 IfrLibCreatePopUp (1, &Key
, L
"Single Override Info too large, Saving Error!");
1258 return EFI_DEVICE_ERROR
;
1262 if (KeyValue
== KEY_VALUE_DEVICE_CLEAR
) {
1264 // Deletes all environment variable(s) that contain the override mappings info
1266 FreeMappingDatabase (&mMappingDataBase
);
1267 Status
= SaveOverridesMapping (&mMappingDataBase
);
1268 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1271 // Pass changed uncommitted data back to Form Browser
1273 BufferSize
= sizeof (PLAT_OVER_MNGR_DATA
);
1274 Status
= SetBrowserData (NULL
, NULL
, BufferSize
, (UINT8
*) FakeNvData
, NULL
);
1280 The driver Entry Point. The funciton will export a disk device class formset and
1281 its callback function to hii database.
1283 @param ImageHandle The firmware allocated handle for the EFI image.
1284 @param SystemTable A pointer to the EFI System Table.
1286 @retval EFI_SUCCESS The entry point is executed successfully.
1287 @retval other Some error occurs when executing this entry point.
1293 IN EFI_HANDLE ImageHandle
,
1294 IN EFI_SYSTEM_TABLE
*SystemTable
1298 EFI_HII_DATABASE_PROTOCOL
*HiiDatabase
;
1299 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
1300 EFI_CALLBACK_INFO
*CallbackInfo
;
1301 EFI_HANDLE DriverHandle
;
1302 EFI_FORM_BROWSER2_PROTOCOL
*FormBrowser2
;
1305 // There should only be one HII protocol
1307 Status
= gBS
->LocateProtocol (
1308 &gEfiHiiDatabaseProtocolGuid
,
1310 (VOID
**) &HiiDatabase
1312 if (EFI_ERROR (Status
)) {
1317 // There should only be one Form Configuration protocol
1319 Status
= gBS
->LocateProtocol (
1320 &gEfiFormBrowser2ProtocolGuid
,
1322 (VOID
**) &FormBrowser2
1324 if (EFI_ERROR (Status
)) {
1328 CallbackInfo
= AllocateZeroPool (sizeof (EFI_CALLBACK_INFO
));
1329 if (CallbackInfo
== NULL
) {
1330 return EFI_BAD_BUFFER_SIZE
;
1333 CallbackInfo
->Signature
= EFI_CALLBACK_INFO_SIGNATURE
;
1334 CallbackInfo
->ConfigAccess
.ExtractConfig
= PlatOverMngrExtractConfig
;
1335 CallbackInfo
->ConfigAccess
.RouteConfig
= PlatOverMngrRouteConfig
;
1336 CallbackInfo
->ConfigAccess
.Callback
= PlatOverMngrCallback
;
1339 // Create driver handle used by HII database
1341 Status
= HiiLibCreateHiiDriverHandle (&DriverHandle
);
1342 if (EFI_ERROR (Status
)) {
1345 CallbackInfo
->DriverHandle
= DriverHandle
;
1348 // Install Config Access protocol to driver handle
1350 Status
= gBS
->InstallProtocolInterface (
1352 &gEfiHiiConfigAccessProtocolGuid
,
1353 EFI_NATIVE_INTERFACE
,
1354 &CallbackInfo
->ConfigAccess
1356 if (EFI_ERROR (Status
)) {
1361 // Publish our HII data
1363 PackageList
= HiiLibPreparePackageList (
1365 &mPlatformOverridesManagerGuid
,
1369 ASSERT (PackageList
!= NULL
);
1371 Status
= HiiDatabase
->NewPackageList (
1375 &CallbackInfo
->RegisteredHandle
1377 FreePool (PackageList
);
1379 if (EFI_ERROR (Status
)) {
1384 // Locate ConfigRouting protocol
1386 Status
= gBS
->LocateProtocol (
1387 &gEfiHiiConfigRoutingProtocolGuid
,
1389 (VOID
**) &CallbackInfo
->HiiConfigRouting
1391 if (EFI_ERROR (Status
)) {
1396 // Clear all the globle variable
1398 mDriverImageHandleCount
= 0;
1400 ZeroMem (mDriverImageToken
, MAX_CHOICE_NUM
* sizeof (EFI_STRING_ID
));
1401 ZeroMem (mDriverImageFilePathToken
, MAX_CHOICE_NUM
* sizeof (EFI_STRING_ID
));
1402 ZeroMem (mControllerToken
, MAX_CHOICE_NUM
* sizeof (EFI_STRING_ID
));
1403 ZeroMem (mDriverImageProtocol
, MAX_CHOICE_NUM
* sizeof (EFI_LOADED_IMAGE_PROTOCOL
*));
1408 Status
= FormBrowser2
->SendForm (
1410 &CallbackInfo
->RegisteredHandle
,
1417 if (EFI_ERROR (Status
)) {
1421 Status
= HiiDatabase
->RemovePackageList (HiiDatabase
, CallbackInfo
->RegisteredHandle
);
1422 if (EFI_ERROR (Status
)) {
1429 if (CallbackInfo
->DriverHandle
!= NULL
) {
1430 HiiLibDestroyHiiDriverHandle (CallbackInfo
->DriverHandle
);
1432 if (CallbackInfo
!= NULL
) {
1433 FreePool (CallbackInfo
);