3 Copyright (c) 2007 - 2008, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 A UI application to offer a UI interface in device manager to let user configue
19 platform override protocol to override the default algorithm for matching
20 drivers to controllers.
23 1. The UI application dynamicly locate all controller device path.
24 2. The UI application dynamicly locate all drivers which support binding protocol.
25 3. The UI application export and dynamicly update two menu to let user select the
26 mapping between drivers to controllers.
27 4. The UI application save all the mapping info in NV variables which will be consumed
28 by platform override protocol driver to publish the platform override protocol.
34 #include <Protocol/HiiConfigAccess.h>
35 #include <Protocol/HiiConfigRouting.h>
36 #include <Protocol/HiiDatabase.h>
37 #include <Protocol/FormBrowser2.h>
38 #include <Protocol/LoadedImage.h>
39 #include <Protocol/FirmwareVolume2.h>
40 #include <Protocol/PciIo.h>
41 #include <Protocol/BusSpecificDriverOverride.h>
42 #include <Protocol/ComponentName2.h>
43 #include <Protocol/ComponentName.h>
44 #include <Protocol/DriverBinding.h>
46 #include <Library/BaseLib.h>
47 #include <Library/DebugLib.h>
48 #include <Library/UefiLib.h>
49 #include <Library/UefiApplicationEntryPoint.h>
50 #include <Library/UefiBootServicesTableLib.h>
51 #include <Library/PlatDriOverLib.h>
52 #include <Library/HiiLib.h>
53 #include <Library/IfrSupportLib.h>
54 #include <Library/ExtendedHiiLib.h>
55 #include <Library/ExtendedIfrSupportLib.h>
56 #include <Library/BaseMemoryLib.h>
57 #include <Library/MemoryAllocationLib.h>
58 #include <Library/UefiRuntimeServicesTableLib.h>
59 #include <Library/DevicePathLib.h>
60 #include <Library/GenericBdsLib.h>
61 #include "PlatOverMngr.h"
63 #define EFI_CALLBACK_INFO_SIGNATURE SIGNATURE_32 ('C', 'l', 'b', 'k')
64 #define EFI_CALLBACK_INFO_FROM_THIS(a) CR (a, EFI_CALLBACK_INFO, ConfigAccess, EFI_CALLBACK_INFO_SIGNATURE)
68 EFI_HANDLE DriverHandle
;
69 EFI_HII_HANDLE RegisteredHandle
;
70 PLAT_OVER_MNGR_DATA FakeNvData
;
71 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
72 EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess
;
76 // uni string and Vfr Binary data.
78 extern UINT8 VfrBin
[];
79 extern UINT8 PlatOverMngrStrings
[];
84 EFI_GUID mPlatformOverridesManagerGuid
= PLAT_OVER_MNGR_GUID
;
85 LIST_ENTRY mMappingDataBase
= INITIALIZE_LIST_HEAD_VARIABLE (mMappingDataBase
);
87 EFI_HANDLE
*mDevicePathHandleBuffer
;
88 EFI_HANDLE
*mDriverImageHandleBuffer
;
90 UINTN mSelectedCtrIndex
;
91 EFI_STRING_ID mControllerToken
[MAX_CHOICE_NUM
];
92 UINTN mDriverImageHandleCount
;
93 EFI_STRING_ID mDriverImageToken
[MAX_CHOICE_NUM
];
94 EFI_STRING_ID mDriverImageFilePathToken
[MAX_CHOICE_NUM
];
95 EFI_LOADED_IMAGE_PROTOCOL
*mDriverImageProtocol
[MAX_CHOICE_NUM
];
96 EFI_DEVICE_PATH_PROTOCOL
*mControllerDevicePathProtocol
[MAX_CHOICE_NUM
];
97 UINTN mSelectedDriverImageNum
;
98 UINTN mLastSavedDriverImageNum
;
99 CHAR8 mLanguage
[RFC_3066_ENTRY_SIZE
];
103 Do string convertion for the ComponentName supported language. It do
104 the convertion just for english language code from RFC 3066 to ISO 639-2.
105 Then it will check whether the converted language is in the supported language list.
106 If not supported, NULL is returned.
107 If Language is not english, NULL is returned.
109 @param SupportedLanguages Pointer to ComponentName supported language string list. ISO 639-2 language
110 @param Language The language string. RFC 3066 language
112 @return English language string (ISO 639-2)
113 @return NULL if the conertion is not successful.
117 ConvertComponentNameSupportLanguage (
118 IN CHAR8
*SupportedLanguages
,
126 // check the input language is English
128 if (AsciiStrnCmp (Language
, "en-", 3) != 0) {
133 // Convert Language string from RFC 3066 to ISO 639-2
135 LangCode
= AllocateZeroPool(4);
136 AsciiStrCpy (LangCode
, "eng");
139 // Check whether the converted language is supported in the SupportedLanguages list.
141 if (AsciiStrStr (SupportedLanguages
, LangCode
) == NULL
) {
150 Get the driver name by ComponentName or ComponentName2 protocol
151 according to the driver binding handle
153 @param DriverBindingHandle The Handle of DriverBinding.
155 @retval !NULL Pointer into the image name if the image name is found,
156 @retval NULL Pointer to NULL if the image name is not found.
161 IN EFI_HANDLE DriverBindingHandle
165 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
166 EFI_COMPONENT_NAME2_PROTOCOL
*ComponentName2
;
167 CHAR8
*SupportedLanguage
;
170 ComponentName
= NULL
;
171 ComponentName2
= NULL
;
172 Status
= gBS
->OpenProtocol (
174 &gEfiComponentName2ProtocolGuid
,
175 (VOID
**) &ComponentName2
,
178 EFI_OPEN_PROTOCOL_GET_PROTOCOL
180 if (EFI_ERROR(Status
)) {
181 Status
= gBS
->OpenProtocol (
183 &gEfiComponentNameProtocolGuid
,
184 (VOID
**) &ComponentName
,
187 EFI_OPEN_PROTOCOL_GET_PROTOCOL
191 Status
= EFI_SUCCESS
;
193 if (ComponentName
!= NULL
) {
194 if (ComponentName
->GetDriverName
!= NULL
) {
195 SupportedLanguage
= ConvertComponentNameSupportLanguage (ComponentName
->SupportedLanguages
, mLanguage
);
196 Status
= ComponentName
->GetDriverName (
201 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)) {
559 for (Index
= 0; Index
< DriverBindingHandleCount
; Index
++) {
560 DriverBindingInterface
= NULL
;
561 Status
= gBS
->OpenProtocol (
562 DriverBindingHandleBuffer
[Index
],
563 &gEfiDriverBindingProtocolGuid
,
564 (VOID
**) &DriverBindingInterface
,
567 EFI_OPEN_PROTOCOL_GET_PROTOCOL
569 if (EFI_ERROR (Status
)) {
573 if (DriverBindingInterface
->ImageHandle
== ImageHandle
) {
574 DriverBindingHandle
= DriverBindingHandleBuffer
[Index
];
580 // If no Driver Binding Protocol instance is found
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 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
594 @retval EFI_SUCCESS Always returned.
598 UpdateBindingDriverSelectPage (
599 IN EFI_CALLBACK_INFO
*Private
,
601 IN PLAT_OVER_MNGR_DATA
*FakeNvData
604 EFI_HII_UPDATE_DATA UpdateData
;
608 EFI_STRING_ID NewStringToken
;
609 EFI_STRING_ID NewStringHelpToken
;
610 UINTN DriverImageHandleCount
;
611 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
613 BOOLEAN FreeDriverName
;
614 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
615 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*BusSpecificDriverOverride
;
616 EFI_HANDLE DriverBindingHandle
;
619 // If user select a controller item in the first page the following code will be run.
620 // During second page, user will see all currnet driver bind protocol driver, the driver name and its device path will be shown
622 //First acquire the list of Loaded Image Protocols, and then when want the name of the driver, look up all the Driver Binding Protocols
623 // and find the first one whose ImageHandle field matches the image handle of the Loaded Image Protocol.
624 // 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.
627 mCurrentPage
= FORM_ID_DRIVER
;
629 // Switch the item callback key value to its NO. in mDevicePathHandleBuffer
631 mSelectedCtrIndex
= KeyValue
- KEY_VALUE_DEVICE_OFFSET
;
632 ASSERT (mSelectedCtrIndex
< MAX_CHOICE_NUM
);
633 mLastSavedDriverImageNum
= 0;
635 // Clear all the content in dynamic page
637 UpdateData
.BufferSize
= UPDATE_DATA_SIZE
;
638 UpdateData
.Offset
= 0;
639 UpdateData
.Data
= AllocateZeroPool (UPDATE_DATA_SIZE
);
640 ASSERT (UpdateData
.Data
!= NULL
);
642 // Clear second page form
645 Private
->RegisteredHandle
,
646 &mPlatformOverridesManagerGuid
,
654 // Show all driver which support loaded image protocol in second page
656 DriverImageHandleCount
= 0;
657 Status
= gBS
->LocateHandleBuffer (
659 &gEfiLoadedImageProtocolGuid
,
661 &DriverImageHandleCount
,
662 &mDriverImageHandleBuffer
664 if (EFI_ERROR (Status
) || (DriverImageHandleCount
== 0)) {
665 return EFI_NOT_FOUND
;
668 mDriverImageHandleCount
= DriverImageHandleCount
;
669 for (Index
= 0; Index
< DriverImageHandleCount
; Index
++) {
671 // Step1: Get the driver image total file path for help string and the driver name.
675 // Find driver's Loaded Image protocol
679 Status
= gBS
->OpenProtocol (
680 mDriverImageHandleBuffer
[Index
],
681 &gEfiLoadedImageProtocolGuid
,
682 (VOID
**) &LoadedImage
,
685 EFI_OPEN_PROTOCOL_GET_PROTOCOL
687 if (EFI_ERROR (Status
)) {
688 FakeNvData
->DriSelection
[Index
] = 0x00;
691 mDriverImageProtocol
[Index
] = LoadedImage
;
693 // Find its related driver binding protocol
695 DriverBindingHandle
= GetDriverBindingHandleFromImageHandle (mDriverImageHandleBuffer
[Index
]);
696 if (DriverBindingHandle
== NULL
) {
697 FakeNvData
->DriSelection
[Index
] = 0x00;
702 // Get the EFI Loaded Image Device Path Protocol
704 LoadedImageDevicePath
= NULL
;
705 Status
= gBS
->HandleProtocol (
706 mDriverImageHandleBuffer
[Index
],
707 &gEfiLoadedImageDevicePathProtocolGuid
,
708 (VOID
**) &LoadedImageDevicePath
710 if (LoadedImageDevicePath
== NULL
) {
711 FakeNvData
->DriSelection
[Index
] = 0x00;
715 if (FakeNvData
->PciDeviceFilter
== 0x01) {
717 // only care the driver which is in a Pci device option rom,
718 // and the driver's LoadedImage->DeviceHandle must point to a pci device which has efi option rom
720 if (!EFI_ERROR (Status
)) {
721 Status
= gBS
->HandleProtocol(
722 LoadedImage
->DeviceHandle
,
723 &gEfiBusSpecificDriverOverrideProtocolGuid
,
724 (VOID
**) &BusSpecificDriverOverride
726 if (EFI_ERROR (Status
) || BusSpecificDriverOverride
== NULL
) {
727 FakeNvData
->DriSelection
[Index
] = 0x00;
731 FakeNvData
->DriSelection
[Index
] = 0x00;
737 // For driver name, try to get its component name, if fail, get its image name,
738 // if also fail, give a default name.
740 FreeDriverName
= FALSE
;
741 DriverName
= GetComponentName (DriverBindingHandle
);
742 if (DriverName
== NULL
) {
744 // get its image name
746 DriverName
= GetImageName (LoadedImage
);
748 if (DriverName
== NULL
) {
750 // give a default name
752 HiiLibGetStringFromHandle (Private
->RegisteredHandle
, STRING_TOKEN (STR_DRIVER_DEFAULT_NAME
), &DriverName
);
753 ASSERT (DriverName
!= NULL
);
754 FreeDriverName
= TRUE
; // the DriverName string need to free pool
759 // Step2 Export the driver name string and create check box item in second page
763 // First create the driver image name
765 NewString
= AllocateZeroPool (StrSize (DriverName
));
766 ASSERT (NewString
!= NULL
);
767 if (EFI_ERROR (CheckMapping (mControllerDevicePathProtocol
[mSelectedCtrIndex
], LoadedImageDevicePath
, &mMappingDataBase
, NULL
, NULL
))) {
768 FakeNvData
->DriSelection
[Index
] = 0x00;
770 FakeNvData
->DriSelection
[Index
] = 0x01;
771 mLastSavedDriverImageNum
++;
773 StrCat (NewString
, DriverName
);
774 NewStringToken
= mDriverImageToken
[Index
];
775 if (NewStringToken
== 0) {
776 Status
= HiiLibNewString (Private
->RegisteredHandle
, &NewStringToken
, NewString
);
778 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
);
780 mDriverImageToken
[Index
] = NewStringToken
;
781 ASSERT_EFI_ERROR (Status
);
782 FreePool (NewString
);
783 if (FreeDriverName
) {
784 FreePool (DriverName
);
788 // Second create the driver image device path as item help string
790 DriverName
= DevicePathToStr (LoadedImageDevicePath
);
792 NewString
= AllocateZeroPool (StrSize (DriverName
));
793 StrCat (NewString
, DriverName
);
794 NewStringHelpToken
= mDriverImageFilePathToken
[Index
];
795 if (NewStringHelpToken
== 0) {
796 Status
= HiiLibNewString (Private
->RegisteredHandle
, &NewStringHelpToken
, NewString
);
798 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringHelpToken
, NewString
);
800 mDriverImageFilePathToken
[Index
] = NewStringHelpToken
;
801 ASSERT_EFI_ERROR (Status
);
802 FreePool (NewString
);
803 FreePool (DriverName
);
805 CreateCheckBoxOpCode (
806 (UINT16
) (DRIVER_SELECTION_QUESTION_ID
+ Index
),
807 VARSTORE_ID_PLAT_OVER_MNGR
,
808 (UINT16
) (DRIVER_SELECTION_VAR_OFFSET
+ Index
),
818 // Update second page form
821 Private
->RegisteredHandle
,
822 &mPlatformOverridesManagerGuid
,
829 FreePool (UpdateData
.Data
);
834 Prepare to let user select the priority order of the drivers which are
835 selected in second page.
837 @param Private Pointer to EFI_CALLBACK_INFO.
838 @param KeyValue The callback key value of device controller item in first page.
839 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
841 @retval EFI_SUCCESS Always returned.
845 UpdatePrioritySelectPage (
846 IN EFI_CALLBACK_INFO
*Private
,
848 IN PLAT_OVER_MNGR_DATA
*FakeNvData
851 EFI_HII_UPDATE_DATA UpdateData
;
853 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
854 IFR_OPTION
*IfrOptionList
;
855 UINTN SelectedDriverImageNum
;
856 UINT32 DriverImageNO
;
862 // Following code will be run if user select 'order ... priority' item in second page
863 // Prepare third page. In third page, user will order the drivers priority which are selected in second page
865 mCurrentPage
= FORM_ID_ORDER
;
867 UpdateData
.BufferSize
= UPDATE_DATA_SIZE
;
868 UpdateData
.Offset
= 0;
869 UpdateData
.Data
= AllocateZeroPool (UPDATE_DATA_SIZE
);
870 ASSERT (UpdateData
.Data
!= NULL
);
872 // Clear third page form
875 Private
->RegisteredHandle
,
876 &mPlatformOverridesManagerGuid
,
884 // Check how many drivers have been selected
886 SelectedDriverImageNum
= 0;
887 for (Index
= 0; Index
< mDriverImageHandleCount
; Index
++) {
888 if (FakeNvData
->DriSelection
[Index
] != 0) {
889 SelectedDriverImageNum
++;
893 mSelectedDriverImageNum
= SelectedDriverImageNum
;
894 if (SelectedDriverImageNum
== 0) {
898 IfrOptionList
= AllocateZeroPool (sizeof (IFR_OPTION
) * mSelectedDriverImageNum
);
899 ASSERT (IfrOptionList
!= NULL
);
901 // Create order list for those selected drivers
903 SelectedDriverImageNum
= 0;
904 for (Index
= 0; Index
< mDriverImageHandleCount
; Index
++) {
905 if (FakeNvData
->DriSelection
[Index
] != 0) {
906 IfrOptionList
[SelectedDriverImageNum
].StringToken
= mDriverImageToken
[Index
];
908 // Use the NO. in driver binding buffer as value, will use it later
910 IfrOptionList
[SelectedDriverImageNum
].Value
.u8
= (UINT8
) (Index
+ 1);
911 IfrOptionList
[SelectedDriverImageNum
].Flags
= 0;
914 // Get the EFI Loaded Image Device Path Protocol
916 LoadedImageDevicePath
= NULL
;
917 gBS
->HandleProtocol (
918 mDriverImageHandleBuffer
[Index
],
919 &gEfiLoadedImageDevicePathProtocolGuid
,
920 (VOID
**) &LoadedImageDevicePath
922 ASSERT (LoadedImageDevicePath
!= NULL
);
925 // Check the driver DriverImage's order number in mapping database
929 mControllerDevicePathProtocol
[mSelectedCtrIndex
],
930 LoadedImageDevicePath
,
935 if (DriverImageNO
== 0) {
936 DriverImageNO
= (UINT32
) mLastSavedDriverImageNum
+ 1;
937 mLastSavedDriverImageNum
++;
939 TempNO
[SelectedDriverImageNum
] = DriverImageNO
;
940 SelectedDriverImageNum
++;
944 ASSERT (SelectedDriverImageNum
== mSelectedDriverImageNum
);
946 // NvRamMap Must be clear firstly
948 ZeroMem (FakeNvData
->DriOrder
, sizeof (FakeNvData
->DriOrder
));
951 // Order the selected drivers according to the info already in mapping database
952 // the less order number in mapping database the less order number in NvRamMap
954 for (Index
=0; Index
< SelectedDriverImageNum
; Index
++) {
956 // Find the minimal order number in TempNO array, its index in TempNO is same as IfrOptionList array
959 for (Index1
=0; Index1
< SelectedDriverImageNum
; Index1
++) {
960 if (TempNO
[Index1
] < TempNO
[MinNO
]) {
965 // the IfrOptionList[MinNO].Value = the driver NO. in driver binding buffer
967 FakeNvData
->DriOrder
[Index
] =IfrOptionList
[MinNO
].Value
.u8
;
968 TempNO
[MinNO
] = MAX_CHOICE_NUM
+ 1;
971 CreateOrderedListOpCode (
972 (UINT16
) DRIVER_ORDER_QUESTION_ID
,
973 VARSTORE_ID_PLAT_OVER_MNGR
,
974 (UINT16
) DRIVER_ORDER_VAR_OFFSET
,
975 mControllerToken
[mSelectedCtrIndex
],
976 mControllerToken
[mSelectedCtrIndex
],
977 EFI_IFR_FLAG_RESET_REQUIRED
,
979 EFI_IFR_NUMERIC_SIZE_1
,
980 (UINT8
) MAX_CHOICE_NUM
,
982 SelectedDriverImageNum
,
987 // Update third page form
990 Private
->RegisteredHandle
,
991 &mPlatformOverridesManagerGuid
,
998 FreePool (IfrOptionList
);
999 FreePool (UpdateData
.Data
);
1004 Save the save the mapping database to NV variable.
1006 @param Private Pointer to EFI_CALLBACK_INFO.
1007 @param KeyValue The callback key value of device controller item in first page.
1008 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
1010 @retval EFI_SUCCESS Always returned.
1015 IN EFI_CALLBACK_INFO
*Private
,
1017 IN PLAT_OVER_MNGR_DATA
*FakeNvData
1022 UINTN SelectedDriverImageNum
;
1023 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
1025 // Following code will be run if user select 'commint changes' in third page
1026 // user enter 'Commit Changes' to save the mapping database
1028 DeleteDriverImage (mControllerDevicePathProtocol
[mSelectedCtrIndex
], NULL
, &mMappingDataBase
);
1029 for (SelectedDriverImageNum
= 0; SelectedDriverImageNum
< mSelectedDriverImageNum
; SelectedDriverImageNum
++) {
1031 // DriOrder[SelectedDriverImageNum] = the driver NO. in driver binding buffer
1033 Index
= FakeNvData
->DriOrder
[SelectedDriverImageNum
] - 1;
1036 // Get the EFI Loaded Image Device Path Protocol
1038 LoadedImageDevicePath
= NULL
;
1039 Status
= gBS
->HandleProtocol (
1040 mDriverImageHandleBuffer
[Index
],
1041 &gEfiLoadedImageDevicePathProtocolGuid
,
1042 (VOID
**) &LoadedImageDevicePath
1044 ASSERT (LoadedImageDevicePath
!= NULL
);
1047 mControllerDevicePathProtocol
[mSelectedCtrIndex
],
1048 LoadedImageDevicePath
,
1050 (UINT32
)SelectedDriverImageNum
+ 1
1053 Status
= SaveOverridesMapping (&mMappingDataBase
);
1059 This function allows a caller to extract the current configuration for one
1060 or more named elements from the target driver.
1062 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1063 @param Request A null-terminated Unicode string in <ConfigRequest> format.
1064 @param Progress On return, points to a character in the Request string.
1065 Points to the string's null terminator if request was successful.
1066 Points to the most recent '&' before the first failing name/value
1067 pair (or the beginning of the string if the failure is in the
1068 first name/value pair) if the request was not successful.
1069 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
1070 has all values filled in for the names in the Request string.
1071 String to be allocated by the called function.
1073 @retval EFI_SUCCESS The Results is filled with the requested values.
1074 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
1075 @retval EFI_INVALID_PARAMETER Request is NULL, illegal syntax, or unknown name.
1076 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
1081 PlatOverMngrExtractConfig (
1082 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1083 IN CONST EFI_STRING Request
,
1084 OUT EFI_STRING
*Progress
,
1085 OUT EFI_STRING
*Results
1089 EFI_CALLBACK_INFO
*Private
;
1090 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
1092 if (Request
== NULL
) {
1093 return EFI_NOT_FOUND
;
1096 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1097 HiiConfigRouting
= Private
->HiiConfigRouting
;
1100 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
1102 Status
= HiiConfigRouting
->BlockToConfig (
1105 (UINT8
*) &Private
->FakeNvData
,
1106 sizeof (PLAT_OVER_MNGR_DATA
),
1114 This function processes the results of changes in configuration.
1116 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1117 @param Configuration A null-terminated Unicode string in <ConfigRequest> format.
1118 @param Progress A pointer to a string filled in with the offset of the most
1119 recent '&' before the first failing name/value pair (or the
1120 beginning of the string if the failure is in the first
1121 name/value pair) or the terminating NULL if all was successful.
1123 @retval EFI_SUCCESS The Results is processed successfully.
1124 @retval EFI_INVALID_PARAMETER Configuration is NULL.
1125 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
1130 PlatOverMngrRouteConfig (
1131 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1132 IN CONST EFI_STRING Configuration
,
1133 OUT EFI_STRING
*Progress
1136 EFI_CALLBACK_INFO
*Private
;
1140 PLAT_OVER_MNGR_DATA
*FakeNvData
;
1142 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1144 FakeNvData
= &Private
->FakeNvData
;
1145 BufferSize
= sizeof (PLAT_OVER_MNGR_DATA
);
1146 Status
= GetBrowserData (NULL
, NULL
, &BufferSize
, (UINT8
*) FakeNvData
);
1147 if (EFI_ERROR (Status
)) {
1151 if (mCurrentPage
== FORM_ID_DRIVER
) {
1152 KeyValue
= KEY_VALUE_DRIVER_GOTO_ORDER
;
1153 UpdatePrioritySelectPage (Private
, KeyValue
, FakeNvData
);
1154 KeyValue
= KEY_VALUE_ORDER_SAVE_AND_EXIT
;
1155 CommintChanges (Private
, KeyValue
, FakeNvData
);
1157 // Since UpdatePrioritySelectPage will change mCurrentPage,
1158 // should ensure the mCurrentPage still indicate the second page here
1160 mCurrentPage
= FORM_ID_DRIVER
;
1163 if (mCurrentPage
== FORM_ID_ORDER
) {
1164 KeyValue
= KEY_VALUE_ORDER_SAVE_AND_EXIT
;
1165 CommintChanges (Private
, KeyValue
, FakeNvData
);
1171 This is the function that is called to provide results data to the driver. This data
1172 consists of a unique key which is used to identify what data is either being passed back
1175 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1176 @param Action A null-terminated Unicode string in <ConfigRequest> format.
1177 @param KeyValue A unique Goto OpCode callback value which record user's selection.
1178 0x100 <= KeyValue <0x500 : user select a controller item in the first page;
1179 KeyValue == 0x1234 : user select 'Refresh' in first page, or user select 'Go to Previous Menu' in second page
1180 KeyValue == 0x1235 : user select 'Pci device filter' in first page
1181 KeyValue == 0x1500 : user select 'order ... priority' item in second page
1182 KeyValue == 0x1800 : user select 'commint changes' in third page
1183 KeyValue == 0x2000 : user select 'Go to Previous Menu' in third page
1184 @param Type The type of value for the question.
1185 @param Value A pointer to the data being sent to the original exporting driver.
1186 @param ActionRequest On return, points to the action requested by the callback function.
1188 @retval EFI_SUCCESS Always returned.
1193 PlatOverMngrCallback (
1194 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1195 IN EFI_BROWSER_ACTION Action
,
1196 IN EFI_QUESTION_ID KeyValue
,
1198 IN EFI_IFR_TYPE_VALUE
*Value
,
1199 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
1202 EFI_CALLBACK_INFO
*Private
;
1204 EFI_STRING_ID NewStringToken
;
1206 PLAT_OVER_MNGR_DATA
*FakeNvData
;
1209 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1211 FakeNvData
= &Private
->FakeNvData
;
1212 BufferSize
= sizeof (PLAT_OVER_MNGR_DATA
);
1213 Status
= GetBrowserData (NULL
, NULL
, &BufferSize
, (UINT8
*) FakeNvData
);
1214 if (EFI_ERROR (Status
)) {
1218 if (KeyValue
== KEY_VALUE_DEVICE_REFRESH
||
1219 KeyValue
== KEY_VALUE_DEVICE_FILTER
||
1220 KeyValue
== KEY_VALUE_DRIVER_GOTO_PREVIOUS
1222 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1224 // Update page title string
1226 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1227 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, L
"First, Select the controller by device path");
1228 ASSERT_EFI_ERROR (Status
);
1231 if (((KEY_VALUE_DEVICE_OFFSET
<= KeyValue
) && (KeyValue
< KEY_VALUE_DEVICE_MAX
)) || (KeyValue
== KEY_VALUE_ORDER_GOTO_PREVIOUS
)) {
1232 if (KeyValue
== KEY_VALUE_ORDER_GOTO_PREVIOUS
) {
1233 KeyValue
= (EFI_QUESTION_ID
) (mSelectedCtrIndex
+ KEY_VALUE_DEVICE_OFFSET
);
1235 UpdateBindingDriverSelectPage (Private
, KeyValue
, FakeNvData
);
1237 // Update page title string
1239 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1240 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, L
"Second, Select drivers for the previous selected controller");
1241 ASSERT_EFI_ERROR (Status
);
1244 if (KeyValue
== KEY_VALUE_DRIVER_GOTO_ORDER
) {
1245 UpdatePrioritySelectPage (Private
, KeyValue
, FakeNvData
);
1247 // Update page title string
1249 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1250 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, L
"Finally, Set the priority order for the drivers and save them");
1251 ASSERT_EFI_ERROR (Status
);
1254 if (KeyValue
== KEY_VALUE_ORDER_SAVE_AND_EXIT
) {
1255 Status
= CommintChanges (Private
, KeyValue
, FakeNvData
);
1256 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1257 if (EFI_ERROR (Status
)) {
1258 IfrLibCreatePopUp (1, &Key
, L
"Single Override Info too large, Saving Error!");
1259 return EFI_DEVICE_ERROR
;
1263 if (KeyValue
== KEY_VALUE_DEVICE_CLEAR
) {
1265 // Deletes all environment variable(s) that contain the override mappings info
1267 FreeMappingDatabase (&mMappingDataBase
);
1268 Status
= SaveOverridesMapping (&mMappingDataBase
);
1269 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1272 // Pass changed uncommitted data back to Form Browser
1274 BufferSize
= sizeof (PLAT_OVER_MNGR_DATA
);
1275 Status
= SetBrowserData (NULL
, NULL
, BufferSize
, (UINT8
*) FakeNvData
, NULL
);
1281 The driver Entry Point. The funciton will export a disk device class formset and
1282 its callback function to hii database.
1284 @param ImageHandle The firmware allocated handle for the EFI image.
1285 @param SystemTable A pointer to the EFI System Table.
1287 @retval EFI_SUCCESS The entry point is executed successfully.
1288 @retval other Some error occurs when executing this entry point.
1294 IN EFI_HANDLE ImageHandle
,
1295 IN EFI_SYSTEM_TABLE
*SystemTable
1299 EFI_HII_DATABASE_PROTOCOL
*HiiDatabase
;
1300 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
1301 EFI_CALLBACK_INFO
*CallbackInfo
;
1302 EFI_HANDLE DriverHandle
;
1303 EFI_FORM_BROWSER2_PROTOCOL
*FormBrowser2
;
1306 // There should only be one HII protocol
1308 Status
= gBS
->LocateProtocol (
1309 &gEfiHiiDatabaseProtocolGuid
,
1311 (VOID
**) &HiiDatabase
1313 if (EFI_ERROR (Status
)) {
1318 // There should only be one Form Configuration protocol
1320 Status
= gBS
->LocateProtocol (
1321 &gEfiFormBrowser2ProtocolGuid
,
1323 (VOID
**) &FormBrowser2
1325 if (EFI_ERROR (Status
)) {
1329 CallbackInfo
= AllocateZeroPool (sizeof (EFI_CALLBACK_INFO
));
1330 if (CallbackInfo
== NULL
) {
1331 return EFI_BAD_BUFFER_SIZE
;
1334 CallbackInfo
->Signature
= EFI_CALLBACK_INFO_SIGNATURE
;
1335 CallbackInfo
->ConfigAccess
.ExtractConfig
= PlatOverMngrExtractConfig
;
1336 CallbackInfo
->ConfigAccess
.RouteConfig
= PlatOverMngrRouteConfig
;
1337 CallbackInfo
->ConfigAccess
.Callback
= PlatOverMngrCallback
;
1340 // Create driver handle used by HII database
1342 Status
= HiiLibCreateHiiDriverHandle (&DriverHandle
);
1343 if (EFI_ERROR (Status
)) {
1346 CallbackInfo
->DriverHandle
= DriverHandle
;
1349 // Install Config Access protocol to driver handle
1351 Status
= gBS
->InstallProtocolInterface (
1353 &gEfiHiiConfigAccessProtocolGuid
,
1354 EFI_NATIVE_INTERFACE
,
1355 &CallbackInfo
->ConfigAccess
1357 if (EFI_ERROR (Status
)) {
1362 // Publish our HII data
1364 PackageList
= HiiLibPreparePackageList (
1366 &mPlatformOverridesManagerGuid
,
1370 ASSERT (PackageList
!= NULL
);
1372 Status
= HiiDatabase
->NewPackageList (
1376 &CallbackInfo
->RegisteredHandle
1378 FreePool (PackageList
);
1381 // Locate ConfigRouting protocol
1383 Status
= gBS
->LocateProtocol (
1384 &gEfiHiiConfigRoutingProtocolGuid
,
1386 (VOID
**) &CallbackInfo
->HiiConfigRouting
1388 if (EFI_ERROR (Status
)) {
1393 // Clear all the globle variable
1395 mDriverImageHandleCount
= 0;
1397 ZeroMem (mDriverImageToken
, MAX_CHOICE_NUM
* sizeof (EFI_STRING_ID
));
1398 ZeroMem (mDriverImageFilePathToken
, MAX_CHOICE_NUM
* sizeof (EFI_STRING_ID
));
1399 ZeroMem (mControllerToken
, MAX_CHOICE_NUM
* sizeof (EFI_STRING_ID
));
1400 ZeroMem (mDriverImageProtocol
, MAX_CHOICE_NUM
* sizeof (EFI_LOADED_IMAGE_PROTOCOL
*));
1405 Status
= FormBrowser2
->SendForm (
1407 &CallbackInfo
->RegisteredHandle
,
1415 Status
= HiiDatabase
->RemovePackageList (HiiDatabase
, CallbackInfo
->RegisteredHandle
);
1416 if (EFI_ERROR (Status
)) {