3 A UI application to offer a UI interface in device manager to let user configure
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 <Protocol/DevicePathToText.h>
40 #include <Protocol/DevicePath.h>
42 #include <Guid/GlobalVariable.h>
44 #include <Library/BaseLib.h>
45 #include <Library/DebugLib.h>
46 #include <Library/UefiLib.h>
47 #include <Library/UefiApplicationEntryPoint.h>
48 #include <Library/UefiBootServicesTableLib.h>
49 #include <Library/PlatformDriverOverrideLib.h>
50 #include <Library/HiiLib.h>
51 #include <Library/IfrSupportLib.h>
52 #include <Library/ExtendedHiiLib.h>
53 #include <Library/ExtendedIfrSupportLib.h>
54 #include <Library/BaseMemoryLib.h>
55 #include <Library/MemoryAllocationLib.h>
56 #include <Library/UefiRuntimeServicesTableLib.h>
57 #include <Library/DevicePathLib.h>
58 #include "PlatOverMngr.h"
60 #define EFI_CALLBACK_INFO_SIGNATURE SIGNATURE_32 ('C', 'l', 'b', 'k')
61 #define EFI_CALLBACK_INFO_FROM_THIS(a) CR (a, EFI_CALLBACK_INFO, ConfigAccess, EFI_CALLBACK_INFO_SIGNATURE)
65 EFI_HANDLE DriverHandle
;
66 EFI_HII_HANDLE RegisteredHandle
;
67 PLAT_OVER_MNGR_DATA FakeNvData
;
68 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
69 EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess
;
73 // uni string and Vfr Binary data.
75 extern UINT8 VfrBin
[];
76 extern UINT8 PlatOverMngrStrings
[];
81 EFI_GUID mPlatformOverridesManagerGuid
= PLAT_OVER_MNGR_GUID
;
82 LIST_ENTRY mMappingDataBase
= INITIALIZE_LIST_HEAD_VARIABLE (mMappingDataBase
);
84 EFI_HANDLE
*mDevicePathHandleBuffer
;
85 EFI_HANDLE
*mDriverImageHandleBuffer
;
87 INTN mSelectedCtrIndex
;
88 EFI_STRING_ID mControllerToken
[MAX_CHOICE_NUM
];
89 UINTN mDriverImageHandleCount
;
90 EFI_STRING_ID mDriverImageToken
[MAX_CHOICE_NUM
];
91 EFI_STRING_ID mDriverImageFilePathToken
[MAX_CHOICE_NUM
];
92 EFI_LOADED_IMAGE_PROTOCOL
*mDriverImageProtocol
[MAX_CHOICE_NUM
];
93 EFI_DEVICE_PATH_PROTOCOL
*mControllerDevicePathProtocol
[MAX_CHOICE_NUM
];
94 UINTN mSelectedDriverImageNum
;
95 UINTN mLastSavedDriverImageNum
;
96 CHAR8 mLanguage
[RFC_3066_ENTRY_SIZE
];
100 Converting a given device to an unicode string.
102 This function will dependent on gEfiDevicePathToTextProtocolGuid, if protocol
103 does not installed, then return unknown device path L"?" directly.
105 @param DevPath Given device path instance
107 @return Converted string from given device path.
108 @retval L"?" Can not locate gEfiDevicePathToTextProtocolGuid protocol for converting.
112 IN EFI_DEVICE_PATH_PROTOCOL
*DevPath
116 Do string convertion for the ComponentName supported language. It do
117 the convertion just for english language code from RFC 3066 to ISO 639-2.
118 Then it will check whether the converted language is in the supported language list.
119 If not supported, NULL is returned.
120 If Language is not english, NULL is returned.
122 @param SupportedLanguages Pointer to ComponentName supported language string list. ISO 639-2 language
123 @param Language The language string. RFC 3066 language
125 @return English language string (ISO 639-2)
126 @return NULL if the conertion is not successful.
130 ConvertComponentNameSupportLanguage (
131 IN CHAR8
*SupportedLanguages
,
139 // Check the input language is English
141 if (AsciiStrnCmp (Language
, "en-", 3) != 0) {
146 // Check SupportedLanguages format
148 if (AsciiStrStr (SupportedLanguages
, "en-") != NULL
) {
150 // Create RFC 3066 language
152 LangCode
= AllocateZeroPool(AsciiStrSize (Language
));
153 AsciiStrCpy (LangCode
, Language
);
154 } else if (AsciiStrStr (SupportedLanguages
, "en") != NULL
) {
156 // Create ISO 639-2 Language
158 LangCode
= AllocateZeroPool(4);
159 AsciiStrCpy (LangCode
, "eng");
166 Get the driver name by ComponentName or ComponentName2 protocol
167 according to the driver binding handle
169 @param DriverBindingHandle The Handle of DriverBinding.
171 @retval !NULL Pointer into the image name if the image name is found,
172 @retval NULL Pointer to NULL if the image name is not found.
177 IN EFI_HANDLE DriverBindingHandle
181 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
182 EFI_COMPONENT_NAME2_PROTOCOL
*ComponentName2
;
183 CHAR8
*SupportedLanguage
;
186 ComponentName
= NULL
;
187 ComponentName2
= NULL
;
188 Status
= gBS
->OpenProtocol (
190 &gEfiComponentName2ProtocolGuid
,
191 (VOID
**) &ComponentName2
,
194 EFI_OPEN_PROTOCOL_GET_PROTOCOL
196 if (EFI_ERROR(Status
)) {
197 Status
= gBS
->OpenProtocol (
199 &gEfiComponentNameProtocolGuid
,
200 (VOID
**) &ComponentName
,
203 EFI_OPEN_PROTOCOL_GET_PROTOCOL
207 Status
= EFI_SUCCESS
;
209 if (ComponentName
!= NULL
) {
210 if (ComponentName
->GetDriverName
!= NULL
) {
211 SupportedLanguage
= ConvertComponentNameSupportLanguage (ComponentName
->SupportedLanguages
, mLanguage
);
212 if (SupportedLanguage
!= NULL
) {
213 Status
= ComponentName
->GetDriverName (
218 FreePool (SupportedLanguage
);
221 } else if (ComponentName2
!= NULL
) {
222 if (ComponentName2
->GetDriverName
!= NULL
) {
223 Status
= ComponentName2
->GetDriverName (
231 if (EFI_ERROR (Status
)) {
239 Get the image name from EFI UI section.
240 Get FV protocol by its loaded image protoocl to abastract EFI UI section.
242 @param Image Pointer to the loaded image protocol
244 @retval !NULL Pointer to the image name if the image name is found,
245 @retval NULL NULL if the image name is not found.
250 IN EFI_LOADED_IMAGE_PROTOCOL
*Image
254 EFI_DEVICE_PATH_PROTOCOL
*DevPathNode
;
255 EFI_DEVICE_PATH_PROTOCOL
*AlignedDevPathNode
;
256 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*FvFilePath
;
259 UINT32 AuthenticationStatus
;
261 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv2
;
267 if (Image
->FilePath
== NULL
) {
270 DevPathNode
= Image
->FilePath
;
272 while (!IsDevicePathEnd (DevPathNode
)) {
274 // Make sure device path node is aligned when accessing it's FV Name Guid field.
276 AlignedDevPathNode
= AllocateCopyPool (DevicePathNodeLength(DevPathNode
), DevPathNode
);
279 // Find the Fv File path
281 NameGuid
= EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*)AlignedDevPathNode
);
282 if (NameGuid
!= NULL
) {
283 FvFilePath
= (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*) AlignedDevPathNode
;
284 Status
= gBS
->HandleProtocol (
286 &gEfiFirmwareVolume2ProtocolGuid
,
290 // Locate Image EFI UI section to get the image name.
292 if (!EFI_ERROR (Status
)) {
293 Status
= Fv2
->ReadSection (
295 &FvFilePath
->FvFileName
,
296 EFI_SECTION_USER_INTERFACE
,
300 &AuthenticationStatus
302 if (!EFI_ERROR (Status
)) {
303 FreePool (AlignedDevPathNode
);
310 FreePool (AlignedDevPathNode
);
313 // Next device path node
315 DevPathNode
= NextDevicePathNode (DevPathNode
);
322 Prepare the first page to let user select the device controller which need to
323 add mapping drivers if user select 'Refresh' in first page.
324 During first page, user will see all currnet controller device path in system,
325 select any device path will go to second page to select its overrides drivers.
327 @param Private Pointer to EFI_CALLBACK_INFO.
328 @param KeyValue The callback key value of device controller item in first page.
329 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
331 @retval EFI_SUCCESS Always returned.
335 UpdateDeviceSelectPage (
336 IN EFI_CALLBACK_INFO
*Private
,
338 IN PLAT_OVER_MNGR_DATA
*FakeNvData
341 EFI_HII_UPDATE_DATA UpdateData
;
345 UINTN DevicePathHandleCount
;
347 EFI_STRING_ID NewStringToken
;
348 CHAR16
*ControllerName
;
349 EFI_DEVICE_PATH_PROTOCOL
*ControllerDevicePath
;
350 EFI_PCI_IO_PROTOCOL
*PciIo
;
351 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*BusSpecificDriverOverride
;
355 // set current page form ID.
357 mCurrentPage
= FORM_ID_DEVICE
;
360 // Get Platform supported Language (RFC_3066 format)
362 LangSize
= RFC_3066_ENTRY_SIZE
;
363 Status
= gRT
->GetVariable (
365 &gEfiGlobalVariableGuid
,
370 ASSERT_EFI_ERROR (Status
);
373 // Initial the mapping database in memory
375 FreeMappingDatabase (&mMappingDataBase
);
376 Status
= InitOverridesMapping (&mMappingDataBase
);
379 // Clear all the content in the first page
381 UpdateData
.BufferSize
= UPDATE_DATA_SIZE
;
382 UpdateData
.Offset
= 0;
383 UpdateData
.Data
= AllocateZeroPool (UPDATE_DATA_SIZE
);
384 ASSERT (UpdateData
.Data
!= NULL
);
386 // Clear first page form
389 Private
->RegisteredHandle
,
390 &mPlatformOverridesManagerGuid
,
398 // When user enter the page at first time, the 'first refresh' string is given to notify user to refresh all the drivers,
399 // then the 'first refresh' string will be replaced by the 'refresh' string, and the two strings content are same after the replacement
401 NewStringToken
= STRING_TOKEN (STR_FIRST_REFRESH
);
402 HiiLibGetStringFromHandle (Private
->RegisteredHandle
, STRING_TOKEN (STR_REFRESH
), &NewString
);
403 ASSERT (NewString
!= NULL
);
404 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
);
405 ASSERT_EFI_ERROR (Status
);
406 FreePool (NewString
);
408 NewStringToken
= STRING_TOKEN (STR_FIRST_REFRESH_HELP
);
409 HiiLibGetStringFromHandle (Private
->RegisteredHandle
, STRING_TOKEN (STR_REFRESH_HELP
), &NewString
);
410 ASSERT (NewString
!= NULL
);
411 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
);
412 ASSERT_EFI_ERROR (Status
);
413 FreePool (NewString
);
416 // created needed controller device item in first page
418 DevicePathHandleCount
= 0;
419 Status
= gBS
->LocateHandleBuffer (
421 &gEfiDevicePathProtocolGuid
,
423 &DevicePathHandleCount
,
424 &mDevicePathHandleBuffer
426 if (EFI_ERROR (Status
) || (DevicePathHandleCount
== 0)) {
430 for (Index
= 0; Index
< DevicePathHandleCount
; Index
++) {
431 if (FakeNvData
->PciDeviceFilter
== 0x01) {
433 // Only care PCI device which contain efi driver in its option rom.
437 // Check whether it is a pci device
439 ControllerDevicePath
= NULL
;
440 Status
= gBS
->OpenProtocol (
441 mDevicePathHandleBuffer
[Index
],
442 &gEfiPciIoProtocolGuid
,
446 EFI_OPEN_PROTOCOL_GET_PROTOCOL
448 if (EFI_ERROR (Status
)) {
452 // Check whether it contain efi driver in its option rom
454 Status
= gBS
->HandleProtocol(
455 mDevicePathHandleBuffer
[Index
],
456 &gEfiBusSpecificDriverOverrideProtocolGuid
,
457 (VOID
**) &BusSpecificDriverOverride
459 if (EFI_ERROR (Status
) || BusSpecificDriverOverride
== NULL
) {
464 ControllerDevicePath
= NULL
;
465 Status
= gBS
->OpenProtocol (
466 mDevicePathHandleBuffer
[Index
],
467 &gEfiDevicePathProtocolGuid
,
468 (VOID
**) &ControllerDevicePath
,
471 EFI_OPEN_PROTOCOL_GET_PROTOCOL
473 ASSERT_EFI_ERROR (Status
);
475 // Save the device path protocol interface
477 mControllerDevicePathProtocol
[Index
] = ControllerDevicePath
;
480 // Get the driver name
482 ControllerName
= DevicePathToStr (ControllerDevicePath
);
485 // Export the driver name string and create item in set options page
487 Len
= StrSize (ControllerName
);
488 NewString
= AllocateZeroPool (Len
+ StrSize (L
"--"));
489 ASSERT (NewString
!= NULL
);
490 if (EFI_ERROR (CheckMapping (ControllerDevicePath
,NULL
, &mMappingDataBase
, NULL
, NULL
))) {
491 StrCat (NewString
, L
"--");
493 StrCat (NewString
, L
"**");
495 StrCat (NewString
, ControllerName
);
497 NewStringToken
= mControllerToken
[Index
];
498 if (NewStringToken
== 0) {
499 Status
= HiiLibNewString (Private
->RegisteredHandle
, &NewStringToken
, NewString
);
501 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
);
503 ASSERT_EFI_ERROR (Status
);
504 FreePool (NewString
);
506 // Save the device path string toke for next access use
508 mControllerToken
[Index
] = NewStringToken
;
513 STRING_TOKEN (STR_GOTO_HELP_DRIVER
),
514 EFI_IFR_FLAG_CALLBACK
,
515 (UINT16
) (Index
+ KEY_VALUE_DEVICE_OFFSET
),
521 // Update first page form
524 Private
->RegisteredHandle
,
525 &mPlatformOverridesManagerGuid
,
532 FreePool (UpdateData
.Data
);
537 Get the first Driver Binding handle which has the specific image handle.
539 @param ImageHandle The Image handle
541 @return Handle to Driver binding
542 @retval NULL The paramter is not valid or the driver binding handle is not found.
546 GetDriverBindingHandleFromImageHandle (
547 IN EFI_HANDLE ImageHandle
552 UINTN DriverBindingHandleCount
;
553 EFI_HANDLE
*DriverBindingHandleBuffer
;
554 EFI_DRIVER_BINDING_PROTOCOL
*DriverBindingInterface
;
555 EFI_HANDLE DriverBindingHandle
;
557 DriverBindingHandle
= NULL
;
559 if (ImageHandle
== NULL
) {
563 // Get all drivers which support driver binding protocol
565 DriverBindingHandleCount
= 0;
566 Status
= gBS
->LocateHandleBuffer (
568 &gEfiDriverBindingProtocolGuid
,
570 &DriverBindingHandleCount
,
571 &DriverBindingHandleBuffer
573 if (EFI_ERROR (Status
) || (DriverBindingHandleCount
== 0)) {
578 // Get the first Driver Binding handle which has the specific image handle.
580 for (Index
= 0; Index
< DriverBindingHandleCount
; Index
++) {
581 DriverBindingInterface
= NULL
;
582 Status
= gBS
->OpenProtocol (
583 DriverBindingHandleBuffer
[Index
],
584 &gEfiDriverBindingProtocolGuid
,
585 (VOID
**) &DriverBindingInterface
,
588 EFI_OPEN_PROTOCOL_GET_PROTOCOL
590 if (EFI_ERROR (Status
)) {
594 if (DriverBindingInterface
->ImageHandle
== ImageHandle
) {
595 DriverBindingHandle
= DriverBindingHandleBuffer
[Index
];
600 FreePool (DriverBindingHandleBuffer
);
601 return DriverBindingHandle
;
605 Prepare to let user select the drivers which need mapping with the device controller
606 selected in first page.
608 @param Private Pointer to EFI_CALLBACK_INFO.
609 @param KeyValue The callback key value of device controller item in first page.
610 KeyValue is larger than or equal to KEY_VALUE_DEVICE_OFFSET.
611 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
613 @retval EFI_SUCCESS Always returned.
617 UpdateBindingDriverSelectPage (
618 IN EFI_CALLBACK_INFO
*Private
,
620 IN PLAT_OVER_MNGR_DATA
*FakeNvData
623 EFI_HII_UPDATE_DATA UpdateData
;
627 EFI_STRING_ID NewStringToken
;
628 EFI_STRING_ID NewStringHelpToken
;
629 UINTN DriverImageHandleCount
;
630 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
632 BOOLEAN FreeDriverName
;
633 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
634 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*BusSpecificDriverOverride
;
635 EFI_HANDLE DriverBindingHandle
;
638 // If user select a controller item in the first page the following code will be run.
639 // During second page, user will see all currnet driver bind protocol driver, the driver name and its device path will be shown
641 //First acquire the list of Loaded Image Protocols, and then when want the name of the driver, look up all the Driver Binding Protocols
642 // and find the first one whose ImageHandle field matches the image handle of the Loaded Image Protocol.
643 // 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.
646 mCurrentPage
= FORM_ID_DRIVER
;
648 // Switch the item callback key value to its NO. in mDevicePathHandleBuffer
650 mSelectedCtrIndex
= KeyValue
- KEY_VALUE_DEVICE_OFFSET
;
651 ASSERT (mSelectedCtrIndex
> 0 && mSelectedCtrIndex
< MAX_CHOICE_NUM
);
653 mLastSavedDriverImageNum
= 0;
655 // Clear all the content in dynamic page
657 UpdateData
.BufferSize
= UPDATE_DATA_SIZE
;
658 UpdateData
.Offset
= 0;
659 UpdateData
.Data
= AllocateZeroPool (UPDATE_DATA_SIZE
);
660 ASSERT (UpdateData
.Data
!= NULL
);
662 // Clear second page form
665 Private
->RegisteredHandle
,
666 &mPlatformOverridesManagerGuid
,
674 // Show all driver which support loaded image protocol in second page
676 DriverImageHandleCount
= 0;
677 Status
= gBS
->LocateHandleBuffer (
679 &gEfiLoadedImageProtocolGuid
,
681 &DriverImageHandleCount
,
682 &mDriverImageHandleBuffer
684 if (EFI_ERROR (Status
) || (DriverImageHandleCount
== 0)) {
685 return EFI_NOT_FOUND
;
688 mDriverImageHandleCount
= DriverImageHandleCount
;
689 for (Index
= 0; Index
< DriverImageHandleCount
; Index
++) {
691 // Step1: Get the driver image total file path for help string and the driver name.
695 // Find driver's Loaded Image protocol
699 Status
= gBS
->OpenProtocol (
700 mDriverImageHandleBuffer
[Index
],
701 &gEfiLoadedImageProtocolGuid
,
702 (VOID
**) &LoadedImage
,
705 EFI_OPEN_PROTOCOL_GET_PROTOCOL
707 if (EFI_ERROR (Status
)) {
708 FakeNvData
->DriSelection
[Index
] = 0x00;
711 mDriverImageProtocol
[Index
] = LoadedImage
;
713 // Find its related driver binding protocol
715 DriverBindingHandle
= GetDriverBindingHandleFromImageHandle (mDriverImageHandleBuffer
[Index
]);
716 if (DriverBindingHandle
== NULL
) {
717 FakeNvData
->DriSelection
[Index
] = 0x00;
722 // Get the EFI Loaded Image Device Path Protocol
724 LoadedImageDevicePath
= NULL
;
725 Status
= gBS
->HandleProtocol (
726 mDriverImageHandleBuffer
[Index
],
727 &gEfiLoadedImageDevicePathProtocolGuid
,
728 (VOID
**) &LoadedImageDevicePath
730 if (LoadedImageDevicePath
== NULL
) {
731 FakeNvData
->DriSelection
[Index
] = 0x00;
735 if (FakeNvData
->PciDeviceFilter
== 0x01) {
737 // only care the driver which is in a Pci device option rom,
738 // and the driver's LoadedImage->DeviceHandle must point to a pci device which has efi option rom
740 if (!EFI_ERROR (Status
)) {
741 Status
= gBS
->HandleProtocol(
742 LoadedImage
->DeviceHandle
,
743 &gEfiBusSpecificDriverOverrideProtocolGuid
,
744 (VOID
**) &BusSpecificDriverOverride
746 if (EFI_ERROR (Status
) || BusSpecificDriverOverride
== NULL
) {
747 FakeNvData
->DriSelection
[Index
] = 0x00;
751 FakeNvData
->DriSelection
[Index
] = 0x00;
757 // For driver name, try to get its component name, if fail, get its image name,
758 // if also fail, give a default name.
760 FreeDriverName
= FALSE
;
761 DriverName
= GetComponentName (DriverBindingHandle
);
762 if (DriverName
== NULL
) {
764 // get its image name
766 DriverName
= GetImageName (LoadedImage
);
768 if (DriverName
== NULL
) {
770 // give a default name
772 HiiLibGetStringFromHandle (Private
->RegisteredHandle
, STRING_TOKEN (STR_DRIVER_DEFAULT_NAME
), &DriverName
);
773 ASSERT (DriverName
!= NULL
);
774 FreeDriverName
= TRUE
; // the DriverName string need to free pool
779 // Step2 Export the driver name string and create check box item in second page
783 // First create the driver image name
785 NewString
= AllocateZeroPool (StrSize (DriverName
));
786 ASSERT (NewString
!= NULL
);
787 if (EFI_ERROR (CheckMapping (mControllerDevicePathProtocol
[mSelectedCtrIndex
], LoadedImageDevicePath
, &mMappingDataBase
, NULL
, NULL
))) {
788 FakeNvData
->DriSelection
[Index
] = 0x00;
790 FakeNvData
->DriSelection
[Index
] = 0x01;
791 mLastSavedDriverImageNum
++;
793 StrCat (NewString
, DriverName
);
794 NewStringToken
= mDriverImageToken
[Index
];
795 if (NewStringToken
== 0) {
796 Status
= HiiLibNewString (Private
->RegisteredHandle
, &NewStringToken
, NewString
);
798 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
);
800 mDriverImageToken
[Index
] = NewStringToken
;
801 ASSERT_EFI_ERROR (Status
);
802 FreePool (NewString
);
803 if (FreeDriverName
) {
804 FreePool (DriverName
);
808 // Second create the driver image device path as item help string
810 DriverName
= DevicePathToStr (LoadedImageDevicePath
);
812 NewString
= AllocateZeroPool (StrSize (DriverName
));
813 ASSERT (NewString
!= NULL
);
814 StrCat (NewString
, DriverName
);
815 NewStringHelpToken
= mDriverImageFilePathToken
[Index
];
816 if (NewStringHelpToken
== 0) {
817 Status
= HiiLibNewString (Private
->RegisteredHandle
, &NewStringHelpToken
, NewString
);
819 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringHelpToken
, NewString
);
821 mDriverImageFilePathToken
[Index
] = NewStringHelpToken
;
822 ASSERT_EFI_ERROR (Status
);
823 FreePool (NewString
);
824 FreePool (DriverName
);
826 CreateCheckBoxOpCode (
827 (UINT16
) (DRIVER_SELECTION_QUESTION_ID
+ Index
),
828 VARSTORE_ID_PLAT_OVER_MNGR
,
829 (UINT16
) (DRIVER_SELECTION_VAR_OFFSET
+ Index
),
839 // Update second page form
842 Private
->RegisteredHandle
,
843 &mPlatformOverridesManagerGuid
,
850 FreePool (UpdateData
.Data
);
855 Prepare to let user select the priority order of the drivers which are
856 selected in second page.
858 @param Private Pointer to EFI_CALLBACK_INFO.
859 @param KeyValue The callback key value of device controller item in first page.
860 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
862 @retval EFI_SUCCESS Always returned.
866 UpdatePrioritySelectPage (
867 IN EFI_CALLBACK_INFO
*Private
,
869 IN PLAT_OVER_MNGR_DATA
*FakeNvData
872 EFI_HII_UPDATE_DATA UpdateData
;
874 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
875 IFR_OPTION
*IfrOptionList
;
876 UINTN SelectedDriverImageNum
;
877 UINT32 DriverImageNO
;
883 // Following code will be run if user select 'order ... priority' item in second page
884 // Prepare third page. In third page, user will order the drivers priority which are selected in second page
886 mCurrentPage
= FORM_ID_ORDER
;
888 UpdateData
.BufferSize
= UPDATE_DATA_SIZE
;
889 UpdateData
.Offset
= 0;
890 UpdateData
.Data
= AllocateZeroPool (UPDATE_DATA_SIZE
);
891 ASSERT (UpdateData
.Data
!= NULL
);
893 // Clear third page form
896 Private
->RegisteredHandle
,
897 &mPlatformOverridesManagerGuid
,
905 // Check how many drivers have been selected
907 SelectedDriverImageNum
= 0;
908 for (Index
= 0; Index
< mDriverImageHandleCount
; Index
++) {
909 if (FakeNvData
->DriSelection
[Index
] != 0) {
910 SelectedDriverImageNum
++;
914 mSelectedDriverImageNum
= SelectedDriverImageNum
;
915 if (SelectedDriverImageNum
== 0) {
919 IfrOptionList
= AllocateZeroPool (sizeof (IFR_OPTION
) * mSelectedDriverImageNum
);
920 ASSERT (IfrOptionList
!= NULL
);
922 // Create order list for those selected drivers
924 SelectedDriverImageNum
= 0;
925 for (Index
= 0; Index
< mDriverImageHandleCount
; Index
++) {
926 if (FakeNvData
->DriSelection
[Index
] != 0) {
927 IfrOptionList
[SelectedDriverImageNum
].StringToken
= mDriverImageToken
[Index
];
929 // Use the NO. in driver binding buffer as value, will use it later
931 IfrOptionList
[SelectedDriverImageNum
].Value
.u8
= (UINT8
) (Index
+ 1);
932 IfrOptionList
[SelectedDriverImageNum
].Flags
= 0;
935 // Get the EFI Loaded Image Device Path Protocol
937 LoadedImageDevicePath
= NULL
;
938 gBS
->HandleProtocol (
939 mDriverImageHandleBuffer
[Index
],
940 &gEfiLoadedImageDevicePathProtocolGuid
,
941 (VOID
**) &LoadedImageDevicePath
943 ASSERT (LoadedImageDevicePath
!= NULL
);
946 // Check the driver DriverImage's order number in mapping database
950 mControllerDevicePathProtocol
[mSelectedCtrIndex
],
951 LoadedImageDevicePath
,
956 if (DriverImageNO
== 0) {
957 DriverImageNO
= (UINT32
) mLastSavedDriverImageNum
+ 1;
958 mLastSavedDriverImageNum
++;
960 TempNO
[SelectedDriverImageNum
] = DriverImageNO
;
961 SelectedDriverImageNum
++;
965 ASSERT (SelectedDriverImageNum
== mSelectedDriverImageNum
);
967 // NvRamMap Must be clear firstly
969 ZeroMem (FakeNvData
->DriOrder
, sizeof (FakeNvData
->DriOrder
));
972 // Order the selected drivers according to the info already in mapping database
973 // the less order number in mapping database the less order number in NvRamMap
975 for (Index
=0; Index
< SelectedDriverImageNum
; Index
++) {
977 // Find the minimal order number in TempNO array, its index in TempNO is same as IfrOptionList array
980 for (Index1
=0; Index1
< SelectedDriverImageNum
; Index1
++) {
981 if (TempNO
[Index1
] < TempNO
[MinNO
]) {
986 // the IfrOptionList[MinNO].Value = the driver NO. in driver binding buffer
988 FakeNvData
->DriOrder
[Index
] =IfrOptionList
[MinNO
].Value
.u8
;
989 TempNO
[MinNO
] = MAX_CHOICE_NUM
+ 1;
992 CreateOrderedListOpCode (
993 (UINT16
) DRIVER_ORDER_QUESTION_ID
,
994 VARSTORE_ID_PLAT_OVER_MNGR
,
995 (UINT16
) DRIVER_ORDER_VAR_OFFSET
,
996 mControllerToken
[mSelectedCtrIndex
],
997 mControllerToken
[mSelectedCtrIndex
],
998 EFI_IFR_FLAG_RESET_REQUIRED
,
1000 EFI_IFR_NUMERIC_SIZE_1
,
1001 (UINT8
) MAX_CHOICE_NUM
,
1003 SelectedDriverImageNum
,
1008 // Update third page form
1011 Private
->RegisteredHandle
,
1012 &mPlatformOverridesManagerGuid
,
1019 FreePool (IfrOptionList
);
1020 FreePool (UpdateData
.Data
);
1025 Save the save the mapping database to NV variable.
1027 @param Private Pointer to EFI_CALLBACK_INFO.
1028 @param KeyValue The callback key value of device controller item in first page.
1029 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
1031 @retval EFI_SUCCESS Always returned.
1036 IN EFI_CALLBACK_INFO
*Private
,
1038 IN PLAT_OVER_MNGR_DATA
*FakeNvData
1043 UINTN SelectedDriverImageNum
;
1044 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
1046 // Following code will be run if user select 'commint changes' in third page
1047 // user enter 'Commit Changes' to save the mapping database
1049 DeleteDriverImage (mControllerDevicePathProtocol
[mSelectedCtrIndex
], NULL
, &mMappingDataBase
);
1050 for (SelectedDriverImageNum
= 0; SelectedDriverImageNum
< mSelectedDriverImageNum
; SelectedDriverImageNum
++) {
1052 // DriOrder[SelectedDriverImageNum] = the driver NO. in driver binding buffer
1054 Index
= FakeNvData
->DriOrder
[SelectedDriverImageNum
] - 1;
1057 // Get the EFI Loaded Image Device Path Protocol
1059 LoadedImageDevicePath
= NULL
;
1060 Status
= gBS
->HandleProtocol (
1061 mDriverImageHandleBuffer
[Index
],
1062 &gEfiLoadedImageDevicePathProtocolGuid
,
1063 (VOID
**) &LoadedImageDevicePath
1065 ASSERT (LoadedImageDevicePath
!= NULL
);
1068 mControllerDevicePathProtocol
[mSelectedCtrIndex
],
1069 LoadedImageDevicePath
,
1071 (UINT32
)SelectedDriverImageNum
+ 1
1074 Status
= SaveOverridesMapping (&mMappingDataBase
);
1080 This function allows a caller to extract the current configuration for one
1081 or more named elements from the target driver.
1083 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1084 @param Request A null-terminated Unicode string in <ConfigRequest> format.
1085 @param Progress On return, points to a character in the Request string.
1086 Points to the string's null terminator if request was successful.
1087 Points to the most recent '&' before the first failing name/value
1088 pair (or the beginning of the string if the failure is in the
1089 first name/value pair) if the request was not successful.
1090 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
1091 has all values filled in for the names in the Request string.
1092 String to be allocated by the called function.
1094 @retval EFI_SUCCESS The Results is filled with the requested values.
1095 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
1096 @retval EFI_INVALID_PARAMETER Request is NULL, illegal syntax, or unknown name.
1097 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
1102 PlatOverMngrExtractConfig (
1103 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1104 IN CONST EFI_STRING Request
,
1105 OUT EFI_STRING
*Progress
,
1106 OUT EFI_STRING
*Results
1110 EFI_CALLBACK_INFO
*Private
;
1111 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
1113 if (Request
== NULL
) {
1114 return EFI_NOT_FOUND
;
1117 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1118 HiiConfigRouting
= Private
->HiiConfigRouting
;
1121 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
1123 Status
= HiiConfigRouting
->BlockToConfig (
1126 (UINT8
*) &Private
->FakeNvData
,
1127 sizeof (PLAT_OVER_MNGR_DATA
),
1135 This function processes the results of changes in configuration.
1137 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1138 @param Configuration A null-terminated Unicode string in <ConfigRequest> format.
1139 @param Progress A pointer to a string filled in with the offset of the most
1140 recent '&' before the first failing name/value pair (or the
1141 beginning of the string if the failure is in the first
1142 name/value pair) or the terminating NULL if all was successful.
1144 @retval EFI_SUCCESS The Results is processed successfully.
1145 @retval EFI_INVALID_PARAMETER Configuration is NULL.
1146 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
1151 PlatOverMngrRouteConfig (
1152 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1153 IN CONST EFI_STRING Configuration
,
1154 OUT EFI_STRING
*Progress
1157 EFI_CALLBACK_INFO
*Private
;
1161 PLAT_OVER_MNGR_DATA
*FakeNvData
;
1163 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1165 FakeNvData
= &Private
->FakeNvData
;
1166 BufferSize
= sizeof (PLAT_OVER_MNGR_DATA
);
1167 Status
= GetBrowserData (NULL
, NULL
, &BufferSize
, (UINT8
*) FakeNvData
);
1168 if (EFI_ERROR (Status
)) {
1172 if (mCurrentPage
== FORM_ID_DRIVER
) {
1173 KeyValue
= KEY_VALUE_DRIVER_GOTO_ORDER
;
1174 UpdatePrioritySelectPage (Private
, KeyValue
, FakeNvData
);
1175 KeyValue
= KEY_VALUE_ORDER_SAVE_AND_EXIT
;
1176 CommintChanges (Private
, KeyValue
, FakeNvData
);
1178 // Since UpdatePrioritySelectPage will change mCurrentPage,
1179 // should ensure the mCurrentPage still indicate the second page here
1181 mCurrentPage
= FORM_ID_DRIVER
;
1184 if (mCurrentPage
== FORM_ID_ORDER
) {
1185 KeyValue
= KEY_VALUE_ORDER_SAVE_AND_EXIT
;
1186 CommintChanges (Private
, KeyValue
, FakeNvData
);
1192 This is the function that is called to provide results data to the driver. This data
1193 consists of a unique key which is used to identify what data is either being passed back
1196 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1197 @param Action A null-terminated Unicode string in <ConfigRequest> format.
1198 @param KeyValue A unique Goto OpCode callback value which record user's selection.
1199 0x100 <= KeyValue <0x500 : user select a controller item in the first page;
1200 KeyValue == 0x1234 : user select 'Refresh' in first page, or user select 'Go to Previous Menu' in second page
1201 KeyValue == 0x1235 : user select 'Pci device filter' in first page
1202 KeyValue == 0x1500 : user select 'order ... priority' item in second page
1203 KeyValue == 0x1800 : user select 'commint changes' in third page
1204 KeyValue == 0x2000 : user select 'Go to Previous Menu' in third page
1205 @param Type The type of value for the question.
1206 @param Value A pointer to the data being sent to the original exporting driver.
1207 @param ActionRequest On return, points to the action requested by the callback function.
1209 @retval EFI_SUCCESS Always returned.
1214 PlatOverMngrCallback (
1215 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1216 IN EFI_BROWSER_ACTION Action
,
1217 IN EFI_QUESTION_ID KeyValue
,
1219 IN EFI_IFR_TYPE_VALUE
*Value
,
1220 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
1223 EFI_CALLBACK_INFO
*Private
;
1225 EFI_STRING_ID NewStringToken
;
1227 PLAT_OVER_MNGR_DATA
*FakeNvData
;
1230 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1232 FakeNvData
= &Private
->FakeNvData
;
1233 BufferSize
= sizeof (PLAT_OVER_MNGR_DATA
);
1234 Status
= GetBrowserData (NULL
, NULL
, &BufferSize
, (UINT8
*) FakeNvData
);
1235 if (EFI_ERROR (Status
)) {
1239 if (KeyValue
== KEY_VALUE_DEVICE_REFRESH
||
1240 KeyValue
== KEY_VALUE_DEVICE_FILTER
||
1241 KeyValue
== KEY_VALUE_DRIVER_GOTO_PREVIOUS
1243 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1245 // Update page title string
1247 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1248 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, L
"First, Select the controller by device path");
1249 ASSERT_EFI_ERROR (Status
);
1252 if (((KeyValue
>= KEY_VALUE_DEVICE_OFFSET
) && (KeyValue
< KEY_VALUE_DEVICE_MAX
)) || (KeyValue
== KEY_VALUE_ORDER_GOTO_PREVIOUS
)) {
1253 if (KeyValue
== KEY_VALUE_ORDER_GOTO_PREVIOUS
) {
1254 KeyValue
= (EFI_QUESTION_ID
) (mSelectedCtrIndex
+ KEY_VALUE_DEVICE_OFFSET
);
1256 UpdateBindingDriverSelectPage (Private
, KeyValue
, FakeNvData
);
1258 // Update page title string
1260 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1261 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, L
"Second, Select drivers for the previous selected controller");
1262 ASSERT_EFI_ERROR (Status
);
1265 if (KeyValue
== KEY_VALUE_DRIVER_GOTO_ORDER
) {
1266 UpdatePrioritySelectPage (Private
, KeyValue
, FakeNvData
);
1268 // Update page title string
1270 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1271 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, L
"Finally, Set the priority order for the drivers and save them");
1272 ASSERT_EFI_ERROR (Status
);
1275 if (KeyValue
== KEY_VALUE_ORDER_SAVE_AND_EXIT
) {
1276 Status
= CommintChanges (Private
, KeyValue
, FakeNvData
);
1277 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1278 if (EFI_ERROR (Status
)) {
1279 IfrLibCreatePopUp (1, &Key
, L
"Single Override Info too large, Saving Error!");
1280 return EFI_DEVICE_ERROR
;
1284 if (KeyValue
== KEY_VALUE_DEVICE_CLEAR
) {
1286 // Deletes all environment variable(s) that contain the override mappings info
1288 FreeMappingDatabase (&mMappingDataBase
);
1289 Status
= SaveOverridesMapping (&mMappingDataBase
);
1290 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1293 // Pass changed uncommitted data back to Form Browser
1295 BufferSize
= sizeof (PLAT_OVER_MNGR_DATA
);
1296 Status
= SetBrowserData (NULL
, NULL
, BufferSize
, (UINT8
*) FakeNvData
, NULL
);
1302 The driver Entry Point. The funciton will export a disk device class formset and
1303 its callback function to hii database.
1305 @param ImageHandle The firmware allocated handle for the EFI image.
1306 @param SystemTable A pointer to the EFI System Table.
1308 @retval EFI_SUCCESS The entry point is executed successfully.
1309 @retval other Some error occurs when executing this entry point.
1315 IN EFI_HANDLE ImageHandle
,
1316 IN EFI_SYSTEM_TABLE
*SystemTable
1320 EFI_HII_DATABASE_PROTOCOL
*HiiDatabase
;
1321 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
1322 EFI_CALLBACK_INFO
*CallbackInfo
;
1323 EFI_HANDLE DriverHandle
;
1324 EFI_FORM_BROWSER2_PROTOCOL
*FormBrowser2
;
1327 // There should only be one HII protocol
1329 Status
= gBS
->LocateProtocol (
1330 &gEfiHiiDatabaseProtocolGuid
,
1332 (VOID
**) &HiiDatabase
1334 if (EFI_ERROR (Status
)) {
1339 // There should only be one Form Configuration protocol
1341 Status
= gBS
->LocateProtocol (
1342 &gEfiFormBrowser2ProtocolGuid
,
1344 (VOID
**) &FormBrowser2
1346 if (EFI_ERROR (Status
)) {
1350 CallbackInfo
= AllocateZeroPool (sizeof (EFI_CALLBACK_INFO
));
1351 if (CallbackInfo
== NULL
) {
1352 return EFI_BAD_BUFFER_SIZE
;
1355 CallbackInfo
->Signature
= EFI_CALLBACK_INFO_SIGNATURE
;
1356 CallbackInfo
->ConfigAccess
.ExtractConfig
= PlatOverMngrExtractConfig
;
1357 CallbackInfo
->ConfigAccess
.RouteConfig
= PlatOverMngrRouteConfig
;
1358 CallbackInfo
->ConfigAccess
.Callback
= PlatOverMngrCallback
;
1361 // Create driver handle used by HII database
1363 Status
= HiiLibCreateHiiDriverHandle (&DriverHandle
);
1364 if (EFI_ERROR (Status
)) {
1367 CallbackInfo
->DriverHandle
= DriverHandle
;
1370 // Install Config Access protocol to driver handle
1372 Status
= gBS
->InstallProtocolInterface (
1374 &gEfiHiiConfigAccessProtocolGuid
,
1375 EFI_NATIVE_INTERFACE
,
1376 &CallbackInfo
->ConfigAccess
1378 if (EFI_ERROR (Status
)) {
1383 // Publish our HII data
1385 PackageList
= HiiLibPreparePackageList (
1387 &mPlatformOverridesManagerGuid
,
1391 ASSERT (PackageList
!= NULL
);
1393 Status
= HiiDatabase
->NewPackageList (
1397 &CallbackInfo
->RegisteredHandle
1399 FreePool (PackageList
);
1401 if (EFI_ERROR (Status
)) {
1406 // Locate ConfigRouting protocol
1408 Status
= gBS
->LocateProtocol (
1409 &gEfiHiiConfigRoutingProtocolGuid
,
1411 (VOID
**) &CallbackInfo
->HiiConfigRouting
1413 if (EFI_ERROR (Status
)) {
1418 // Clear all the globle variable
1420 mDriverImageHandleCount
= 0;
1422 ZeroMem (mDriverImageToken
, MAX_CHOICE_NUM
* sizeof (EFI_STRING_ID
));
1423 ZeroMem (mDriverImageFilePathToken
, MAX_CHOICE_NUM
* sizeof (EFI_STRING_ID
));
1424 ZeroMem (mControllerToken
, MAX_CHOICE_NUM
* sizeof (EFI_STRING_ID
));
1425 ZeroMem (mDriverImageProtocol
, MAX_CHOICE_NUM
* sizeof (EFI_LOADED_IMAGE_PROTOCOL
*));
1430 Status
= FormBrowser2
->SendForm (
1432 &CallbackInfo
->RegisteredHandle
,
1439 if (EFI_ERROR (Status
)) {
1443 Status
= HiiDatabase
->RemovePackageList (HiiDatabase
, CallbackInfo
->RegisteredHandle
);
1444 if (EFI_ERROR (Status
)) {
1451 if (CallbackInfo
->DriverHandle
!= NULL
) {
1452 HiiLibDestroyHiiDriverHandle (CallbackInfo
->DriverHandle
);
1454 if (CallbackInfo
!= NULL
) {
1455 FreePool (CallbackInfo
);
1462 Converting a given device to an unicode string.
1464 This function will dependent on gEfiDevicePathToTextProtocolGuid, if protocol
1465 does not installed, then return unknown device path L"?" directly.
1467 @param DevPath Given device path instance
1469 @return Converted string from given device path.
1470 @retval L"?" Can not locate gEfiDevicePathToTextProtocolGuid protocol for converting.
1474 IN EFI_DEVICE_PATH_PROTOCOL
*DevPath
1478 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
*DevPathToText
;
1481 if (DevPath
== NULL
) {
1485 Status
= gBS
->LocateProtocol (
1486 &gEfiDevicePathToTextProtocolGuid
,
1488 (VOID
**) &DevPathToText
1490 if (!EFI_ERROR (Status
)) {
1491 ToText
= DevPathToText
->ConvertDevicePathToText (
1496 ASSERT (ToText
!= NULL
);