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 driver 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 driver dynamicly locate all controller device path.
24 2. The UI driver dynamicly locate all drivers which support binding protocol.
25 3. The UI driver export and dynamicly update two menu to let user select the
26 mapping between drivers to controllers.
27 4. The UI driver save all the mapping info in NV variables which will be consumed
28 by platform override protocol driver to publish the platform override protocol.
32 #include "PlatOverMngr.h"
34 EFI_GUID mPlatformOverridesManagerGuid
= PLAT_OVER_MNGR_GUID
;
36 LIST_ENTRY mMappingDataBase
= INITIALIZE_LIST_HEAD_VARIABLE (mMappingDataBase
);
38 EFI_HANDLE
*mDevicePathHandleBuffer
;
39 EFI_HANDLE
*mDriverImageHandleBuffer
;
41 UINTN mSelectedCtrIndex
;
42 EFI_STRING_ID mControllerToken
[MAX_CHOICE_NUM
];
44 UINTN mDriverImageHandleCount
;
45 EFI_STRING_ID mDriverImageToken
[MAX_CHOICE_NUM
];
46 EFI_STRING_ID mDriverImageFilePathToken
[MAX_CHOICE_NUM
];
47 EFI_LOADED_IMAGE_PROTOCOL
*mDriverImageProtocol
[MAX_CHOICE_NUM
];
48 EFI_DEVICE_PATH_PROTOCOL
*mControllerDevicePathProtocol
[MAX_CHOICE_NUM
];
49 UINTN mSelectedDriverImageNum
;
50 UINTN mLastSavedDriverImageNum
;
51 CHAR8 mLanguage
[RFC_3066_ENTRY_SIZE
];
55 The driver Entry Point. The funciton will export a disk device class formset and
56 its callback function to hii database.
58 @param ImageHandle The firmware allocated handle for the EFI image.
59 @param SystemTable A pointer to the EFI System Table.
61 @retval EFI_SUCCESS The entry point is executed successfully.
62 @retval other Some error occurs when executing this entry point.
68 IN EFI_HANDLE ImageHandle
,
69 IN EFI_SYSTEM_TABLE
*SystemTable
73 EFI_HII_DATABASE_PROTOCOL
*HiiDatabase
;
74 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
75 EFI_CALLBACK_INFO
*CallbackInfo
;
76 EFI_HANDLE DriverHandle
;
77 EFI_FORM_BROWSER2_PROTOCOL
*FormBrowser2
;
80 // There should only be one HII protocol
82 Status
= gBS
->LocateProtocol (
83 &gEfiHiiDatabaseProtocolGuid
,
85 (VOID
**) &HiiDatabase
87 if (EFI_ERROR (Status
)) {
93 // There should only be one Form Configuration protocol
95 Status
= gBS
->LocateProtocol (
96 &gEfiFormBrowser2ProtocolGuid
,
98 (VOID
**) &FormBrowser2
100 if (EFI_ERROR (Status
)) {
105 CallbackInfo
= AllocateZeroPool (sizeof (EFI_CALLBACK_INFO
));
106 if (CallbackInfo
== NULL
) {
107 return EFI_BAD_BUFFER_SIZE
;
110 CallbackInfo
->Signature
= EFI_CALLBACK_INFO_SIGNATURE
;
111 CallbackInfo
->ConfigAccess
.ExtractConfig
= PlatOverMngrExtractConfig
;
112 CallbackInfo
->ConfigAccess
.RouteConfig
= PlatOverMngrRouteConfig
;
113 CallbackInfo
->ConfigAccess
.Callback
= PlatOverMngrCallback
;
116 // Create driver handle used by HII database
118 Status
= HiiLibCreateHiiDriverHandle (&DriverHandle
);
119 if (EFI_ERROR (Status
)) {
122 CallbackInfo
->DriverHandle
= DriverHandle
;
125 // Install Config Access protocol to driver handle
127 Status
= gBS
->InstallProtocolInterface (
129 &gEfiHiiConfigAccessProtocolGuid
,
130 EFI_NATIVE_INTERFACE
,
131 &CallbackInfo
->ConfigAccess
133 if (EFI_ERROR (Status
)) {
138 // Publish our HII data
140 PackageList
= HiiLibPreparePackageList (
142 &mPlatformOverridesManagerGuid
,
146 ASSERT (PackageList
!= NULL
);
148 Status
= HiiDatabase
->NewPackageList (
152 &CallbackInfo
->RegisteredHandle
154 gBS
->FreePool (PackageList
);
157 // Locate ConfigRouting protocol
159 Status
= gBS
->LocateProtocol (
160 &gEfiHiiConfigRoutingProtocolGuid
,
162 (VOID
**) &CallbackInfo
->HiiConfigRouting
164 if (EFI_ERROR (Status
)) {
169 // Clear all the globle variable
171 mDriverImageHandleCount
= 0;
173 ZeroMem (mDriverImageToken
, MAX_CHOICE_NUM
* sizeof (EFI_STRING_ID
));
174 ZeroMem (mDriverImageFilePathToken
, MAX_CHOICE_NUM
* sizeof (EFI_STRING_ID
));
175 ZeroMem (mControllerToken
, MAX_CHOICE_NUM
* sizeof (EFI_STRING_ID
));
176 ZeroMem (mDriverImageProtocol
, MAX_CHOICE_NUM
* sizeof (EFI_LOADED_IMAGE_PROTOCOL
*));
181 Status
= FormBrowser2
->SendForm (
183 &CallbackInfo
->RegisteredHandle
,
191 Status
= HiiDatabase
->RemovePackageList (HiiDatabase
, CallbackInfo
->RegisteredHandle
);
192 if (EFI_ERROR (Status
)) {
200 Do some convertion for the ComponentName2 supported language. It do
201 the convertion just for english language code currently.
203 @param ComponentName Pointer to the ComponentName2 protocl pointer.
204 @param Language The language string.
206 @return Return the duplication of Language if it is not english otherwise return
207 the supported english language code.
211 ConvertComponentName2SupportLanguage (
212 IN EFI_COMPONENT_NAME2_PROTOCOL
*ComponentName
,
216 CHAR8
*SupportedLanguages
;
221 SupportedLanguages
= NULL
;
224 // treat all the english language code (en-xx or eng) equally
226 if ((AsciiStrnCmp (Language
, "en-", 3) == 0) || (AsciiStrCmp (Language
, "eng") == 0)) {
227 SupportedLanguages
= AsciiStrStr (ComponentName
->SupportedLanguages
, "en");
228 if (SupportedLanguages
== NULL
) {
229 SupportedLanguages
= AsciiStrStr (ComponentName
->SupportedLanguages
, "eng");
234 // duplicate the Language if it is not english
236 if (SupportedLanguages
== NULL
) {
237 SupportedLanguages
= Language
;
241 // duplicate the returned language code.
243 if (AsciiStrStr (SupportedLanguages
, "-") != NULL
) {
244 LangCode
= AllocateZeroPool(32);
245 for(Index
= 0; (Index
< 31) && (SupportedLanguages
[Index
] != '\0') && (SupportedLanguages
[Index
] != ';'); Index
++) {
246 LangCode
[Index
] = SupportedLanguages
[Index
];
248 LangCode
[Index
] = '\0';
250 LangCode
= AllocateZeroPool(4);
251 for(Index
= 0; (Index
< 3) && (SupportedLanguages
[Index
] != '\0'); Index
++) {
252 LangCode
[Index
] = SupportedLanguages
[Index
];
254 LangCode
[Index
] = '\0';
260 Get the ComponentName or ComponentName2 protocol according to the driver binding handle
262 @param DriverBindingHandle The Handle of DriverBinding.
264 @retval !NULL Pointer into the image name if the image name is found,
265 @retval NULL Pointer to NULL if the image name is not found.
270 IN EFI_HANDLE DriverBindingHandle
274 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
275 EFI_COMPONENT_NAME2_PROTOCOL
*ComponentName2
;
276 CHAR8
*SupportedLanguage
;
279 ComponentName
= NULL
;
280 ComponentName2
= NULL
;
281 Status
= gBS
->OpenProtocol (
283 &gEfiComponentName2ProtocolGuid
,
284 (VOID
**) &ComponentName2
,
287 EFI_OPEN_PROTOCOL_GET_PROTOCOL
289 if (EFI_ERROR(Status
)) {
290 Status
= gBS
->OpenProtocol (
292 &gEfiComponentNameProtocolGuid
,
293 (VOID
**) &ComponentName
,
296 EFI_OPEN_PROTOCOL_GET_PROTOCOL
300 Status
= EFI_SUCCESS
;
302 if (ComponentName
!= NULL
) {
303 if (ComponentName
->GetDriverName
!= NULL
) {
304 Status
= ComponentName
->GetDriverName (
310 } else if (ComponentName2
!= NULL
) {
311 if (ComponentName2
->GetDriverName
!= NULL
) {
312 SupportedLanguage
= ConvertComponentName2SupportLanguage (ComponentName2
, mLanguage
);
313 Status
= ComponentName2
->GetDriverName (
318 gBS
->FreePool (SupportedLanguage
);
321 if (EFI_ERROR (Status
)) {
331 @param Image Image to search.
333 @retval !NULL Pointer into the image name if the image name is found,
334 @retval NULL Pointer to NULL if the image name is not found.
339 IN EFI_LOADED_IMAGE_PROTOCOL
*Image
343 EFI_DEVICE_PATH_PROTOCOL
*DevPathNode
;
344 EFI_DEVICE_PATH_PROTOCOL
*AlignedDevPathNode
;
345 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*FvFilePath
;
348 UINT32 AuthenticationStatus
;
350 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv2
;
356 if (Image
->FilePath
== NULL
) {
360 DevPathNode
= Image
->FilePath
;
362 if (DevPathNode
== NULL
) {
366 while (!IsDevicePathEnd (DevPathNode
)) {
368 // Make sure device path node is aligned when accessing it's FV Name Guid field.
370 AlignedDevPathNode
= AllocateCopyPool (DevicePathNodeLength(DevPathNode
), DevPathNode
);
373 // Find the Fv File path
375 NameGuid
= EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*)AlignedDevPathNode
);
376 if (NameGuid
!= NULL
) {
377 FvFilePath
= (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*) AlignedDevPathNode
;
378 Status
= gBS
->HandleProtocol (
380 &gEfiFirmwareVolume2ProtocolGuid
,
383 if (!EFI_ERROR (Status
)) {
384 Status
= Fv2
->ReadSection (
386 &FvFilePath
->FvFileName
,
387 EFI_SECTION_USER_INTERFACE
,
391 &AuthenticationStatus
393 if (!EFI_ERROR (Status
)) {
394 FreePool (AlignedDevPathNode
);
401 FreePool (AlignedDevPathNode
);
404 // Next device path node
406 DevPathNode
= NextDevicePathNode (DevPathNode
);
413 Prepare the first page to let user select the device controller which need to
416 @param Private Pointer to EFI_CALLBACK_INFO.
417 @param KeyValue The callback key value of device controller item in first page.
418 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
420 @retval EFI_SUCCESS Always returned.
424 UpdateDeviceSelectPage (
425 IN EFI_CALLBACK_INFO
*Private
,
427 IN PLAT_OVER_MNGR_DATA
*FakeNvData
430 EFI_HII_UPDATE_DATA UpdateData
;
434 UINTN DevicePathHandleCount
;
436 EFI_STRING_ID NewStringToken
;
437 CHAR16
*ControllerName
;
438 EFI_DEVICE_PATH_PROTOCOL
*ControllerDevicePath
;
439 EFI_PCI_IO_PROTOCOL
*PciIo
;
440 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*BusSpecificDriverOverride
;
443 mCurrentPage
= FORM_ID_DEVICE
;
445 // Following code will be run if user select 'Refresh' in first page
446 // During first page, user will see all currnet controller device path in system,
447 // select any device path will go to second page to select its overrides drivers
450 LangSize
= RFC_3066_ENTRY_SIZE
;
451 Status
= gRT
->GetVariable (
453 &gEfiGlobalVariableGuid
,
458 ASSERT_EFI_ERROR (Status
);
461 // Initial the mapping database in memory
463 FreeMappingDatabase (&mMappingDataBase
);
464 Status
= InitOverridesMapping (&mMappingDataBase
);
467 // Clear all the content in the first page
469 UpdateData
.BufferSize
= UPDATE_DATA_SIZE
;
470 UpdateData
.Offset
= 0;
471 UpdateData
.Data
= AllocateZeroPool (UPDATE_DATA_SIZE
);
472 ASSERT (UpdateData
.Data
!= NULL
);
474 // Clear first page form
477 Private
->RegisteredHandle
,
478 &mPlatformOverridesManagerGuid
,
486 // When user enter the page at first time, the 'first refresh' string is given to notify user to refresh all the drivers,
487 // then the 'first refresh' string will be replaced by the 'refresh' string, and the two strings content are same after the replacement
489 NewStringToken
= STRING_TOKEN (STR_FIRST_REFRESH
);
490 HiiLibGetStringFromHandle (Private
->RegisteredHandle
, STRING_TOKEN (STR_REFRESH
), &NewString
);
491 ASSERT (NewString
!= NULL
);
492 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
);
493 ASSERT_EFI_ERROR (Status
);
494 gBS
->FreePool (NewString
);
496 NewStringToken
= STRING_TOKEN (STR_FIRST_REFRESH_HELP
);
497 HiiLibGetStringFromHandle (Private
->RegisteredHandle
, STRING_TOKEN (STR_REFRESH_HELP
), &NewString
);
498 ASSERT (NewString
!= NULL
);
499 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
);
500 ASSERT_EFI_ERROR (Status
);
501 gBS
->FreePool (NewString
);
503 // created needed controller device item in first page
505 DevicePathHandleCount
= 0;
506 Status
= gBS
->LocateHandleBuffer (
508 &gEfiDevicePathProtocolGuid
,
510 &DevicePathHandleCount
,
511 &mDevicePathHandleBuffer
513 if (EFI_ERROR (Status
) || (DevicePathHandleCount
== 0)) {
517 for (Index
= 0; Index
< DevicePathHandleCount
; Index
++) {
518 if (FakeNvData
->PciDeviceFilter
== 0x01) {
520 // Only care PCI device which contain efi driver in its option rom.
524 // Check whether it is a pci device
526 ControllerDevicePath
= NULL
;
527 Status
= gBS
->OpenProtocol (
528 mDevicePathHandleBuffer
[Index
],
529 &gEfiPciIoProtocolGuid
,
533 EFI_OPEN_PROTOCOL_GET_PROTOCOL
535 if (EFI_ERROR (Status
)) {
539 // Check whether it contain efi driver in its option rom
541 Status
= gBS
->HandleProtocol(
542 mDevicePathHandleBuffer
[Index
],
543 &gEfiBusSpecificDriverOverrideProtocolGuid
,
544 (VOID
**) &BusSpecificDriverOverride
546 if (EFI_ERROR (Status
) || BusSpecificDriverOverride
== NULL
) {
551 ControllerDevicePath
= NULL
;
552 Status
= gBS
->OpenProtocol (
553 mDevicePathHandleBuffer
[Index
],
554 &gEfiDevicePathProtocolGuid
,
555 (VOID
**) &ControllerDevicePath
,
558 EFI_OPEN_PROTOCOL_GET_PROTOCOL
560 ASSERT_EFI_ERROR (Status
);
562 // Save the device path protocol interface
564 mControllerDevicePathProtocol
[Index
] = ControllerDevicePath
;
567 // Get the driver name
569 ControllerName
= DevicePathToStr (ControllerDevicePath
);
572 // Export the driver name string and create item in set options page
574 Len
= StrSize (ControllerName
);
575 NewString
= AllocateZeroPool (Len
+ StrSize (L
"--"));
576 if (EFI_ERROR (CheckMapping (ControllerDevicePath
,NULL
, &mMappingDataBase
, NULL
, NULL
))) {
577 StrCat (NewString
, L
"--");
579 StrCat (NewString
, L
"**");
581 StrCat (NewString
, ControllerName
);
583 NewStringToken
= mControllerToken
[Index
];
584 if (NewStringToken
== 0) {
585 Status
= HiiLibNewString (Private
->RegisteredHandle
, &NewStringToken
, NewString
);
587 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
);
589 ASSERT_EFI_ERROR (Status
);
590 gBS
->FreePool (NewString
);
592 // Save the device path string toke for next access use
594 mControllerToken
[Index
] = NewStringToken
;
599 STRING_TOKEN (STR_GOTO_HELP_DRIVER
),
600 EFI_IFR_FLAG_CALLBACK
,
601 (UINT16
) (Index
+ KEY_VALUE_DEVICE_OFFSET
),
607 // Update first page form
610 Private
->RegisteredHandle
,
611 &mPlatformOverridesManagerGuid
,
618 gBS
->FreePool (UpdateData
.Data
);
623 Prepare to let user select the drivers which need mapping with the device controller
624 selected in first page.
626 @param Private Pointer to EFI_CALLBACK_INFO.
627 @param KeyValue The callback key value of device controller item in first page.
628 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
630 @retval EFI_SUCCESS Always returned.
634 UpdateBindingDriverSelectPage (
635 IN EFI_CALLBACK_INFO
*Private
,
637 IN PLAT_OVER_MNGR_DATA
*FakeNvData
640 EFI_HII_UPDATE_DATA UpdateData
;
645 EFI_STRING_ID NewStringToken
;
646 EFI_STRING_ID NewStringHelpToken
;
647 UINTN DriverImageHandleCount
;
649 EFI_DRIVER_BINDING_PROTOCOL
*DriverBindingInterface
;
650 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
652 BOOLEAN FreeDriverName
;
654 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
655 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*BusSpecificDriverOverride
;
656 EFI_HANDLE DriverBindingHandle
;
658 // If user select a controller item in the first page the following code will be run.
659 // During second page, user will see all currnet driver bind protocol driver, the driver name and its device path will be shown
661 //First acquire the list of Loaded Image Protocols, and then when want the name of the driver, look up all the Driver Binding Protocols
662 // and find the first one whose ImageHandle field matches the image handle of the Loaded Image Protocol.
663 // 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.
666 mCurrentPage
= FORM_ID_DRIVER
;
668 // Switch the item callback key value to its NO. in mDevicePathHandleBuffer
670 mSelectedCtrIndex
= KeyValue
- 0x100;
671 ASSERT (mSelectedCtrIndex
< MAX_CHOICE_NUM
);
672 mLastSavedDriverImageNum
= 0;
674 // Clear all the content in dynamic page
676 UpdateData
.BufferSize
= UPDATE_DATA_SIZE
;
677 UpdateData
.Offset
= 0;
678 UpdateData
.Data
= AllocateZeroPool (UPDATE_DATA_SIZE
);
679 ASSERT (UpdateData
.Data
!= NULL
);
681 // Clear second page form
684 Private
->RegisteredHandle
,
685 &mPlatformOverridesManagerGuid
,
693 // Show all driver which support loaded image protocol in second page
695 DriverImageHandleCount
= 0;
696 Status
= gBS
->LocateHandleBuffer (
698 &gEfiLoadedImageProtocolGuid
,
700 &DriverImageHandleCount
,
701 &mDriverImageHandleBuffer
703 if (EFI_ERROR (Status
) || (DriverImageHandleCount
== 0)) {
704 return EFI_NOT_FOUND
;
707 mDriverImageHandleCount
= DriverImageHandleCount
;
708 for (Index
= 0; Index
< DriverImageHandleCount
; Index
++) {
710 // Step1: Get the driver image total file path for help string and the driver name.
714 // Find driver's Loaded Image protocol
718 Status
= gBS
->OpenProtocol (
719 mDriverImageHandleBuffer
[Index
],
720 &gEfiLoadedImageProtocolGuid
,
721 (VOID
**) &LoadedImage
,
724 EFI_OPEN_PROTOCOL_GET_PROTOCOL
726 if (EFI_ERROR (Status
)) {
727 FakeNvData
->DriSelection
[Index
] = 0x00;
730 mDriverImageProtocol
[Index
] = LoadedImage
;
732 // Find its related driver binding protocol
734 DriverBindingInterface
= NULL
;
735 DriverBindingHandle
= NULL
;
736 DriverBindingInterface
= GetBindingProtocolFromImageHandle (
737 mDriverImageHandleBuffer
[Index
],
740 if (DriverBindingInterface
== NULL
) {
741 FakeNvData
->DriSelection
[Index
] = 0x00;
746 // Get the EFI Loaded Image Device Path Protocol
748 LoadedImageDevicePath
= NULL
;
749 Status
= gBS
->HandleProtocol (
750 mDriverImageHandleBuffer
[Index
],
751 &gEfiLoadedImageDevicePathProtocolGuid
,
752 (VOID
**) &LoadedImageDevicePath
754 if (LoadedImageDevicePath
== NULL
) {
755 FakeNvData
->DriSelection
[Index
] = 0x00;
759 if (FakeNvData
->PciDeviceFilter
== 0x01) {
761 // only care the driver which is in a Pci device option rom,
762 // and the driver's LoadedImage->DeviceHandle must point to a pci device which has efi option rom
764 if (!EFI_ERROR (Status
)) {
765 Status
= gBS
->HandleProtocol(
766 LoadedImage
->DeviceHandle
,
767 &gEfiBusSpecificDriverOverrideProtocolGuid
,
768 (VOID
**) &BusSpecificDriverOverride
770 if (EFI_ERROR (Status
) || BusSpecificDriverOverride
== NULL
) {
771 FakeNvData
->DriSelection
[Index
] = 0x00;
775 FakeNvData
->DriSelection
[Index
] = 0x00;
781 // For driver name, try to get its component name, if fail, get its image name,
782 // if also fail, give a default name.
784 FreeDriverName
= FALSE
;
785 DriverName
= GetComponentName (DriverBindingHandle
);
786 if (DriverName
== NULL
) {
788 // get its image name
790 DriverName
= GetImageName (LoadedImage
);
792 if (DriverName
== NULL
) {
794 // give a default name
796 HiiLibGetStringFromHandle (Private
->RegisteredHandle
, STRING_TOKEN (STR_DRIVER_DEFAULT_NAME
), &DriverName
);
797 ASSERT (DriverName
!= NULL
);
798 FreeDriverName
= TRUE
; // the DriverName string need to free pool
803 // Step2 Export the driver name string and create check box item in second page
807 // First create the driver image name
809 NewString
= AllocateZeroPool (StrSize (DriverName
));
810 if (EFI_ERROR (CheckMapping (mControllerDevicePathProtocol
[mSelectedCtrIndex
], LoadedImageDevicePath
, &mMappingDataBase
, NULL
, NULL
))) {
811 FakeNvData
->DriSelection
[Index
] = 0x00;
813 FakeNvData
->DriSelection
[Index
] = 0x01;
814 mLastSavedDriverImageNum
++;
816 StrCat (NewString
, DriverName
);
817 NewStringToken
= mDriverImageToken
[Index
];
818 if (NewStringToken
== 0) {
819 Status
= HiiLibNewString (Private
->RegisteredHandle
, &NewStringToken
, NewString
);
821 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
);
823 mDriverImageToken
[Index
] = NewStringToken
;
824 ASSERT_EFI_ERROR (Status
);
825 gBS
->FreePool (NewString
);
826 if (FreeDriverName
) {
827 gBS
->FreePool (DriverName
);
831 // Second create the driver image device path as item help string
833 DriverName
= DevicePathToStr (LoadedImageDevicePath
);
835 NewString
= AllocateZeroPool (StrSize (DriverName
));
836 StrCat (NewString
, DriverName
);
837 NewStringHelpToken
= mDriverImageFilePathToken
[Index
];
838 if (NewStringHelpToken
== 0) {
839 Status
= HiiLibNewString (Private
->RegisteredHandle
, &NewStringHelpToken
, NewString
);
841 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringHelpToken
, NewString
);
843 mDriverImageFilePathToken
[Index
] = NewStringHelpToken
;
844 ASSERT_EFI_ERROR (Status
);
845 gBS
->FreePool (NewString
);
846 gBS
->FreePool (DriverName
);
848 CreateCheckBoxOpCode (
849 (UINT16
) (DRIVER_SELECTION_QUESTION_ID
+ Index
),
850 VARSTORE_ID_PLAT_OVER_MNGR
,
851 (UINT16
) (DRIVER_SELECTION_VAR_OFFSET
+ Index
),
861 // Update second page form
864 Private
->RegisteredHandle
,
865 &mPlatformOverridesManagerGuid
,
872 gBS
->FreePool (UpdateData
.Data
);
877 Prepare to let user select the priority order of the drivers which are
878 selected in second page.
880 @param Private Pointer to EFI_CALLBACK_INFO.
881 @param KeyValue The callback key value of device controller item in first page.
882 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
884 @retval EFI_SUCCESS Always returned.
888 UpdatePrioritySelectPage (
889 IN EFI_CALLBACK_INFO
*Private
,
891 IN PLAT_OVER_MNGR_DATA
*FakeNvData
894 EFI_HII_UPDATE_DATA UpdateData
;
897 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
899 IFR_OPTION
*IfrOptionList
;
900 UINTN SelectedDriverImageNum
;
901 UINT32 DriverImageNO
;
907 // Following code will be run if user select 'order ... priority' item in second page
908 // Prepare third page. In third page, user will order the drivers priority which are selected in second page
910 mCurrentPage
= FORM_ID_ORDER
;
912 UpdateData
.BufferSize
= UPDATE_DATA_SIZE
;
913 UpdateData
.Offset
= 0;
914 UpdateData
.Data
= AllocateZeroPool (UPDATE_DATA_SIZE
);
915 ASSERT (UpdateData
.Data
!= NULL
);
917 // Clear third page form
920 Private
->RegisteredHandle
,
921 &mPlatformOverridesManagerGuid
,
929 // Check how many drivers have been selected
931 SelectedDriverImageNum
= 0;
932 for (Index
= 0; Index
< mDriverImageHandleCount
; Index
++) {
933 if (FakeNvData
->DriSelection
[Index
] != 0) {
934 SelectedDriverImageNum
++;
938 mSelectedDriverImageNum
= SelectedDriverImageNum
;
939 if (SelectedDriverImageNum
== 0) {
943 IfrOptionList
= AllocateZeroPool (0x200);
944 ASSERT_EFI_ERROR (IfrOptionList
!= NULL
);
946 // Create order list for those selected drivers
948 SelectedDriverImageNum
= 0;
949 for (Index
= 0; Index
< mDriverImageHandleCount
; Index
++) {
950 if (FakeNvData
->DriSelection
[Index
] != 0) {
951 IfrOptionList
[SelectedDriverImageNum
].StringToken
= mDriverImageToken
[Index
];
953 // Use the NO. in driver binding buffer as value, will use it later
955 IfrOptionList
[SelectedDriverImageNum
].Value
.u8
= (UINT8
) (Index
+ 1);
956 IfrOptionList
[SelectedDriverImageNum
].Flags
= 0;
959 // Get the EFI Loaded Image Device Path Protocol
961 LoadedImageDevicePath
= NULL
;
962 gBS
->HandleProtocol (
963 mDriverImageHandleBuffer
[Index
],
964 &gEfiLoadedImageDevicePathProtocolGuid
,
965 (VOID
**) &LoadedImageDevicePath
967 ASSERT (LoadedImageDevicePath
!= NULL
);
970 // Check the driver DriverImage's order number in mapping database
974 mControllerDevicePathProtocol
[mSelectedCtrIndex
],
975 LoadedImageDevicePath
,
980 if (DriverImageNO
== 0) {
981 DriverImageNO
= (UINT32
) mLastSavedDriverImageNum
+ 1;
982 mLastSavedDriverImageNum
++;
984 TempNO
[SelectedDriverImageNum
] = DriverImageNO
;
985 SelectedDriverImageNum
++;
989 ASSERT (SelectedDriverImageNum
== mSelectedDriverImageNum
);
991 // NvRamMap Must be clear firstly
993 ZeroMem (FakeNvData
->DriOrder
, 100);
996 // Order the selected drivers according to the info already in mapping database
997 // the less order number in mapping database the less order number in NvRamMap
999 for (Index
=0; Index
< SelectedDriverImageNum
; Index
++) {
1001 // Find the minimal order number in TempNO array, its index in TempNO is same as IfrOptionList array
1004 for (Index1
=0; Index1
< SelectedDriverImageNum
; Index1
++) {
1005 if (TempNO
[Index1
] < TempNO
[MinNO
]) {
1010 // the IfrOptionList[MinNO].Value = the driver NO. in driver binding buffer
1012 FakeNvData
->DriOrder
[Index
] =IfrOptionList
[MinNO
].Value
.u8
;
1013 TempNO
[MinNO
] = 101;
1016 CreateOrderedListOpCode (
1017 (UINT16
) DRIVER_ORDER_QUESTION_ID
,
1018 VARSTORE_ID_PLAT_OVER_MNGR
,
1019 (UINT16
) DRIVER_ORDER_VAR_OFFSET
,
1020 mControllerToken
[mSelectedCtrIndex
],
1021 mControllerToken
[mSelectedCtrIndex
],
1022 EFI_IFR_FLAG_RESET_REQUIRED
,
1024 EFI_IFR_NUMERIC_SIZE_1
,
1027 SelectedDriverImageNum
,
1032 // Update third page form
1035 Private
->RegisteredHandle
,
1036 &mPlatformOverridesManagerGuid
,
1043 gBS
->FreePool (IfrOptionList
);
1044 gBS
->FreePool (UpdateData
.Data
);
1049 Save the save the mapping database to NV variable.
1051 @param Private Pointer to EFI_CALLBACK_INFO.
1052 @param KeyValue The callback key value of device controller item in first page.
1053 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
1055 @retval EFI_SUCCESS Always returned.
1060 IN EFI_CALLBACK_INFO
*Private
,
1062 IN PLAT_OVER_MNGR_DATA
*FakeNvData
1067 UINTN SelectedDriverImageNum
;
1068 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
1070 // Following code will be run if user select 'commint changes' in third page
1071 // user enter 'Commit Changes' to save the mapping database
1073 DeleteDriverImage (mControllerDevicePathProtocol
[mSelectedCtrIndex
], NULL
, &mMappingDataBase
);
1074 for (SelectedDriverImageNum
= 0; SelectedDriverImageNum
< mSelectedDriverImageNum
; SelectedDriverImageNum
++) {
1076 // DriOrder[SelectedDriverImageNum] = the driver NO. in driver binding buffer
1078 Index
= FakeNvData
->DriOrder
[SelectedDriverImageNum
] - 1;
1081 // Get the EFI Loaded Image Device Path Protocol
1083 LoadedImageDevicePath
= NULL
;
1084 Status
= gBS
->HandleProtocol (
1085 mDriverImageHandleBuffer
[Index
],
1086 &gEfiLoadedImageDevicePathProtocolGuid
,
1087 (VOID
**) &LoadedImageDevicePath
1089 ASSERT (LoadedImageDevicePath
!= NULL
);
1092 mControllerDevicePathProtocol
[mSelectedCtrIndex
],
1093 LoadedImageDevicePath
,
1095 (UINT32
)SelectedDriverImageNum
+ 1
1098 Status
= SaveOverridesMapping (&mMappingDataBase
);
1104 This function allows a caller to extract the current configuration for one
1105 or more named elements from the target driver.
1107 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1108 @param Request A null-terminated Unicode string in <ConfigRequest> format.
1109 @param Progress On return, points to a character in the Request string.
1110 Points to the string's null terminator if request was successful.
1111 Points to the most recent '&' before the first failing name/value
1112 pair (or the beginning of the string if the failure is in the
1113 first name/value pair) if the request was not successful.
1114 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
1115 has all values filled in for the names in the Request string.
1116 String to be allocated by the called function.
1118 @retval EFI_SUCCESS The Results is filled with the requested values.
1119 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
1120 @retval EFI_INVALID_PARAMETER Request is NULL, illegal syntax, or unknown name.
1121 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
1126 PlatOverMngrExtractConfig (
1127 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1128 IN CONST EFI_STRING Request
,
1129 OUT EFI_STRING
*Progress
,
1130 OUT EFI_STRING
*Results
1134 EFI_CALLBACK_INFO
*Private
;
1135 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
1137 if (Request
== NULL
) {
1138 return EFI_NOT_FOUND
;
1141 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1142 HiiConfigRouting
= Private
->HiiConfigRouting
;
1145 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
1147 Status
= HiiConfigRouting
->BlockToConfig (
1150 (UINT8
*) &Private
->FakeNvData
,
1151 sizeof (PLAT_OVER_MNGR_DATA
),
1159 This function processes the results of changes in configuration.
1161 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1162 @param Configuration A null-terminated Unicode string in <ConfigRequest> format.
1163 @param Progress A pointer to a string filled in with the offset of the most
1164 recent '&' before the first failing name/value pair (or the
1165 beginning of the string if the failure is in the first
1166 name/value pair) or the terminating NULL if all was successful.
1168 @retval EFI_SUCCESS The Results is processed successfully.
1169 @retval EFI_INVALID_PARAMETER Configuration is NULL.
1170 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
1175 PlatOverMngrRouteConfig (
1176 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1177 IN CONST EFI_STRING Configuration
,
1178 OUT EFI_STRING
*Progress
1181 EFI_CALLBACK_INFO
*Private
;
1185 PLAT_OVER_MNGR_DATA
*FakeNvData
;
1187 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1189 FakeNvData
= &Private
->FakeNvData
;
1190 BufferSize
= sizeof (PLAT_OVER_MNGR_DATA
);
1191 Status
= GetBrowserData (NULL
, NULL
, &BufferSize
, (UINT8
*) FakeNvData
);
1192 if (EFI_ERROR (Status
)) {
1196 if (mCurrentPage
== FORM_ID_DRIVER
) {
1197 KeyValue
= KEY_VALUE_DRIVER_GOTO_ORDER
;
1198 UpdatePrioritySelectPage (Private
, KeyValue
, FakeNvData
);
1199 KeyValue
= KEY_VALUE_ORDER_SAVE_AND_EXIT
;
1200 CommintChanges (Private
, KeyValue
, FakeNvData
);
1202 // Since UpdatePrioritySelectPage will change mCurrentPage,
1203 // should ensure the mCurrentPage still indicate the second page here
1205 mCurrentPage
= FORM_ID_DRIVER
;
1208 if (mCurrentPage
== FORM_ID_ORDER
) {
1209 KeyValue
= KEY_VALUE_ORDER_SAVE_AND_EXIT
;
1210 CommintChanges (Private
, KeyValue
, FakeNvData
);
1216 This is the function that is called to provide results data to the driver. This data
1217 consists of a unique key which is used to identify what data is either being passed back
1220 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1221 @param Action A null-terminated Unicode string in <ConfigRequest> format.
1222 @param KeyValue A unique Goto OpCode callback value which record user's selection.
1223 0x100 <= KeyValue <0x500 : user select a controller item in the first page;
1224 KeyValue == 0x1234 : user select 'Refresh' in first page, or user select 'Go to Previous Menu' in second page
1225 KeyValue == 0x1235 : user select 'Pci device filter' in first page
1226 KeyValue == 0x1500 : user select 'order ... priority' item in second page
1227 KeyValue == 0x1800 : user select 'commint changes' in third page
1228 KeyValue == 0x2000 : user select 'Go to Previous Menu' in third page
1229 @param Type The type of value for the question.
1230 @param Value A pointer to the data being sent to the original exporting driver.
1231 @param ActionRequest On return, points to the action requested by the callback function.
1233 @retval EFI_SUCCESS Always returned.
1238 PlatOverMngrCallback (
1239 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1240 IN EFI_BROWSER_ACTION Action
,
1241 IN EFI_QUESTION_ID KeyValue
,
1243 IN EFI_IFR_TYPE_VALUE
*Value
,
1244 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
1247 EFI_CALLBACK_INFO
*Private
;
1249 EFI_STRING_ID NewStringToken
;
1251 PLAT_OVER_MNGR_DATA
*FakeNvData
;
1254 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1256 FakeNvData
= &Private
->FakeNvData
;
1257 BufferSize
= sizeof (PLAT_OVER_MNGR_DATA
);
1258 Status
= GetBrowserData (NULL
, NULL
, &BufferSize
, (UINT8
*) FakeNvData
);
1259 if (EFI_ERROR (Status
)) {
1263 if (KeyValue
== KEY_VALUE_DEVICE_REFRESH
||
1264 KeyValue
== KEY_VALUE_DEVICE_FILTER
||
1265 KeyValue
== KEY_VALUE_DRIVER_GOTO_PREVIOUS
1267 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1269 // Update page title string
1271 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1272 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, L
"First, Select the controller by device path");
1273 ASSERT_EFI_ERROR (Status
);
1276 if (((KEY_VALUE_DEVICE_OFFSET
<= KeyValue
) && (KeyValue
< KEY_VALUE_DEVICE_MAX
)) || (KeyValue
== KEY_VALUE_ORDER_GOTO_PREVIOUS
)) {
1277 if (KeyValue
== KEY_VALUE_ORDER_GOTO_PREVIOUS
) {
1278 KeyValue
= (EFI_QUESTION_ID
) (mSelectedCtrIndex
+ 0x100);
1280 UpdateBindingDriverSelectPage (Private
, KeyValue
, FakeNvData
);
1282 // Update page title string
1284 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1285 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, L
"Second, Select drivers for the previous selected controller");
1286 ASSERT_EFI_ERROR (Status
);
1289 if (KeyValue
== KEY_VALUE_DRIVER_GOTO_ORDER
) {
1290 UpdatePrioritySelectPage (Private
, KeyValue
, FakeNvData
);
1292 // Update page title string
1294 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1295 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, L
"Finally, Set the priority order for the drivers and save them");
1296 ASSERT_EFI_ERROR (Status
);
1299 if (KeyValue
== KEY_VALUE_ORDER_SAVE_AND_EXIT
) {
1300 Status
= CommintChanges (Private
, KeyValue
, FakeNvData
);
1301 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1302 if (EFI_ERROR (Status
)) {
1303 IfrLibCreatePopUp (1, &Key
, L
"Single Override Info too large, Saving Error!");
1304 return EFI_DEVICE_ERROR
;
1308 if (KeyValue
== KEY_VALUE_DEVICE_CLEAR
) {
1310 // Deletes all environment variable(s) that contain the override mappings info
1312 FreeMappingDatabase (&mMappingDataBase
);
1313 Status
= SaveOverridesMapping (&mMappingDataBase
);
1314 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1317 // Pass changed uncommitted data back to Form Browser
1319 BufferSize
= sizeof (PLAT_OVER_MNGR_DATA
);
1320 Status
= SetBrowserData (NULL
, NULL
, BufferSize
, (UINT8
*) FakeNvData
, NULL
);
1326 Get the description string by device path.
1328 @param DevPath The input device path.
1330 @retval !NULL The description string retured.
1331 @retval NULL The description string cannot be found.
1336 IN EFI_DEVICE_PATH_PROTOCOL
*DevPath
1341 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
*DevPathToText
;
1343 if (DevPath
== NULL
) {
1347 Status
= gBS
->LocateProtocol (
1348 &gEfiDevicePathToTextProtocolGuid
,
1350 (VOID
**) &DevPathToText
1352 if (!EFI_ERROR (Status
)) {
1353 ToText
= DevPathToText
->ConvertDevicePathToText (
1358 ASSERT (ToText
!= NULL
);