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 <Library/BaseLib.h>
43 #include <Library/DebugLib.h>
44 #include <Library/UefiLib.h>
45 #include <Library/UefiApplicationEntryPoint.h>
46 #include <Library/UefiBootServicesTableLib.h>
47 #include <Library/PlatformDriverOverrideLib.h>
48 #include <Library/HiiLib.h>
49 #include <Library/IfrSupportLib.h>
50 #include <Library/ExtendedHiiLib.h>
51 #include <Library/ExtendedIfrSupportLib.h>
52 #include <Library/BaseMemoryLib.h>
53 #include <Library/MemoryAllocationLib.h>
54 #include <Library/DevicePathLib.h>
55 #include "PlatOverMngr.h"
57 #define EFI_CALLBACK_INFO_SIGNATURE SIGNATURE_32 ('C', 'l', 'b', 'k')
58 #define EFI_CALLBACK_INFO_FROM_THIS(a) CR (a, EFI_CALLBACK_INFO, ConfigAccess, EFI_CALLBACK_INFO_SIGNATURE)
62 EFI_HANDLE DriverHandle
;
63 EFI_HII_HANDLE RegisteredHandle
;
64 PLAT_OVER_MNGR_DATA FakeNvData
;
65 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
66 EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess
;
70 // uni string and Vfr Binary data.
72 extern UINT8 VfrBin
[];
73 extern UINT8 PlatOverMngrStrings
[];
78 EFI_GUID mPlatformOverridesManagerGuid
= PLAT_OVER_MNGR_GUID
;
79 LIST_ENTRY mMappingDataBase
= INITIALIZE_LIST_HEAD_VARIABLE (mMappingDataBase
);
81 EFI_HANDLE
*mDevicePathHandleBuffer
;
82 EFI_HANDLE
*mDriverImageHandleBuffer
;
84 INTN mSelectedCtrIndex
;
85 EFI_STRING_ID mControllerToken
[MAX_CHOICE_NUM
];
86 UINTN mDriverImageHandleCount
;
87 EFI_STRING_ID mDriverImageToken
[MAX_CHOICE_NUM
];
88 EFI_STRING_ID mDriverImageFilePathToken
[MAX_CHOICE_NUM
];
89 EFI_LOADED_IMAGE_PROTOCOL
*mDriverImageProtocol
[MAX_CHOICE_NUM
];
90 EFI_DEVICE_PATH_PROTOCOL
*mControllerDevicePathProtocol
[MAX_CHOICE_NUM
];
91 UINTN mSelectedDriverImageNum
;
92 UINTN mLastSavedDriverImageNum
;
96 Converting a given device to an unicode string.
98 This function will dependent on gEfiDevicePathToTextProtocolGuid, if protocol
99 does not installed, then return unknown device path L"?" directly.
101 @param DevPath Given device path instance
103 @return Converted string from given device path.
104 @retval L"?" Can not locate gEfiDevicePathToTextProtocolGuid protocol for converting.
108 IN EFI_DEVICE_PATH_PROTOCOL
*DevPath
112 Worker function to get the driver name by ComponentName or ComponentName2 protocol
113 according to the driver binding handle.
115 @param DriverBindingHandle The Handle of DriverBinding.
116 @param ProtocolGuid The pointer to Component Name (2) protocol GUID.
117 @param VariableName The name of the RFC 4646 or ISO 639-2 language variable.
119 @retval !NULL Pointer into the image name if the image name is found,
120 @retval NULL Pointer to NULL if the image name is not found.
124 GetComponentNameWorker (
125 IN EFI_HANDLE DriverBindingHandle
,
126 IN EFI_GUID
*ProtocolGuid
,
127 IN CONST CHAR16
*VariableName
131 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
136 Status
= gBS
->OpenProtocol (
139 (VOID
*) &ComponentName
,
142 EFI_OPEN_PROTOCOL_GET_PROTOCOL
144 if (EFI_ERROR (Status
)) {
149 // Find the best matching language.
151 Language
= GetEfiGlobalVariable (VariableName
);
152 BestLanguage
= GetBestLanguage (
153 ComponentName
->SupportedLanguages
,
154 (BOOLEAN
) (ProtocolGuid
== &gEfiComponentNameProtocolGuid
),
160 if (BestLanguage
!= NULL
) {
161 ComponentName
->GetDriverName (
166 FreePool (BestLanguage
);
169 if (Language
!= NULL
) {
178 Get the driver name by ComponentName or ComponentName2 protocol
179 according to the driver binding handle
181 @param DriverBindingHandle The Handle of DriverBinding.
183 @retval !NULL Pointer into the image name if the image name is found,
184 @retval NULL Pointer to NULL if the image name is not found.
189 IN EFI_HANDLE DriverBindingHandle
195 // Try RFC 4646 Component Name 2 protocol first.
197 DriverName
= GetComponentNameWorker (DriverBindingHandle
, &gEfiComponentName2ProtocolGuid
, L
"PlatformLang");
198 if (DriverName
== NULL
) {
200 // If we can not get driver name from Component Name 2 protocol, we can try ISO 639-2 Component Name protocol.
202 DriverName
= GetComponentNameWorker (DriverBindingHandle
, &gEfiComponentNameProtocolGuid
, L
"Lang");
209 Get the image name from EFI UI section.
210 Get FV protocol by its loaded image protocol to abstract EFI UI section.
212 @param Image Pointer to the loaded image protocol
214 @retval !NULL Pointer to the image name if the image name is found,
215 @retval NULL NULL if the image name is not found.
220 IN EFI_LOADED_IMAGE_PROTOCOL
*Image
224 EFI_DEVICE_PATH_PROTOCOL
*DevPathNode
;
225 EFI_DEVICE_PATH_PROTOCOL
*AlignedDevPathNode
;
226 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*FvFilePath
;
229 UINT32 AuthenticationStatus
;
231 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv2
;
237 if (Image
->FilePath
== NULL
) {
240 DevPathNode
= Image
->FilePath
;
242 while (!IsDevicePathEnd (DevPathNode
)) {
244 // Make sure device path node is aligned when accessing it's FV Name Guid field.
246 AlignedDevPathNode
= AllocateCopyPool (DevicePathNodeLength(DevPathNode
), DevPathNode
);
249 // Find the Fv File path
251 NameGuid
= EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*)AlignedDevPathNode
);
252 if (NameGuid
!= NULL
) {
253 FvFilePath
= (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*) AlignedDevPathNode
;
254 Status
= gBS
->HandleProtocol (
256 &gEfiFirmwareVolume2ProtocolGuid
,
260 // Locate Image EFI UI section to get the image name.
262 if (!EFI_ERROR (Status
)) {
263 Status
= Fv2
->ReadSection (
265 &FvFilePath
->FvFileName
,
266 EFI_SECTION_USER_INTERFACE
,
270 &AuthenticationStatus
272 if (!EFI_ERROR (Status
)) {
273 FreePool (AlignedDevPathNode
);
280 FreePool (AlignedDevPathNode
);
283 // Next device path node
285 DevPathNode
= NextDevicePathNode (DevPathNode
);
292 Prepare the first page to let user select the device controller which need to
293 add mapping drivers if user select 'Refresh' in first page.
294 During first page, user will see all currnet controller device path in system,
295 select any device path will go to second page to select its overrides drivers.
297 @param Private Pointer to EFI_CALLBACK_INFO.
298 @param KeyValue The callback key value of device controller item in first page.
299 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
301 @retval EFI_SUCCESS Always returned.
305 UpdateDeviceSelectPage (
306 IN EFI_CALLBACK_INFO
*Private
,
308 IN PLAT_OVER_MNGR_DATA
*FakeNvData
311 EFI_HII_UPDATE_DATA UpdateData
;
314 UINTN DevicePathHandleCount
;
316 EFI_STRING_ID NewStringToken
;
317 CHAR16
*ControllerName
;
318 EFI_DEVICE_PATH_PROTOCOL
*ControllerDevicePath
;
319 EFI_PCI_IO_PROTOCOL
*PciIo
;
320 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*BusSpecificDriverOverride
;
324 // set current page form ID.
326 mCurrentPage
= FORM_ID_DEVICE
;
329 // Initial the mapping database in memory
331 FreeMappingDatabase (&mMappingDataBase
);
332 Status
= InitOverridesMapping (&mMappingDataBase
);
335 // Clear all the content in the first page
337 UpdateData
.BufferSize
= UPDATE_DATA_SIZE
;
338 UpdateData
.Offset
= 0;
339 UpdateData
.Data
= AllocateZeroPool (UPDATE_DATA_SIZE
);
340 ASSERT (UpdateData
.Data
!= NULL
);
342 // Clear first page form
345 Private
->RegisteredHandle
,
346 &mPlatformOverridesManagerGuid
,
354 // When user enter the page at first time, the 'first refresh' string is given to notify user to refresh all the drivers,
355 // then the 'first refresh' string will be replaced by the 'refresh' string, and the two strings content are same after the replacement
357 NewStringToken
= STRING_TOKEN (STR_FIRST_REFRESH
);
358 HiiLibGetStringFromHandle (Private
->RegisteredHandle
, STRING_TOKEN (STR_REFRESH
), &NewString
);
359 ASSERT (NewString
!= NULL
);
360 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
);
361 ASSERT_EFI_ERROR (Status
);
362 FreePool (NewString
);
364 NewStringToken
= STRING_TOKEN (STR_FIRST_REFRESH_HELP
);
365 HiiLibGetStringFromHandle (Private
->RegisteredHandle
, STRING_TOKEN (STR_REFRESH_HELP
), &NewString
);
366 ASSERT (NewString
!= NULL
);
367 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
);
368 ASSERT_EFI_ERROR (Status
);
369 FreePool (NewString
);
372 // created needed controller device item in first page
374 DevicePathHandleCount
= 0;
375 Status
= gBS
->LocateHandleBuffer (
377 &gEfiDevicePathProtocolGuid
,
379 &DevicePathHandleCount
,
380 &mDevicePathHandleBuffer
382 if (EFI_ERROR (Status
) || (DevicePathHandleCount
== 0)) {
386 for (Index
= 0; Index
< DevicePathHandleCount
; Index
++) {
387 if (FakeNvData
->PciDeviceFilter
== 0x01) {
389 // Only care PCI device which contain efi driver in its option rom.
393 // Check whether it is a pci device
395 ControllerDevicePath
= NULL
;
396 Status
= gBS
->OpenProtocol (
397 mDevicePathHandleBuffer
[Index
],
398 &gEfiPciIoProtocolGuid
,
402 EFI_OPEN_PROTOCOL_GET_PROTOCOL
404 if (EFI_ERROR (Status
)) {
408 // Check whether it contain efi driver in its option rom
410 Status
= gBS
->HandleProtocol(
411 mDevicePathHandleBuffer
[Index
],
412 &gEfiBusSpecificDriverOverrideProtocolGuid
,
413 (VOID
**) &BusSpecificDriverOverride
415 if (EFI_ERROR (Status
) || BusSpecificDriverOverride
== NULL
) {
420 ControllerDevicePath
= NULL
;
421 Status
= gBS
->OpenProtocol (
422 mDevicePathHandleBuffer
[Index
],
423 &gEfiDevicePathProtocolGuid
,
424 (VOID
**) &ControllerDevicePath
,
427 EFI_OPEN_PROTOCOL_GET_PROTOCOL
429 ASSERT_EFI_ERROR (Status
);
431 // Save the device path protocol interface
433 mControllerDevicePathProtocol
[Index
] = ControllerDevicePath
;
436 // Get the driver name
438 ControllerName
= DevicePathToStr (ControllerDevicePath
);
441 // Export the driver name string and create item in set options page
443 Len
= StrSize (ControllerName
);
444 NewString
= AllocateZeroPool (Len
+ StrSize (L
"--"));
445 ASSERT (NewString
!= NULL
);
446 if (EFI_ERROR (CheckMapping (ControllerDevicePath
,NULL
, &mMappingDataBase
, NULL
, NULL
))) {
447 StrCat (NewString
, L
"--");
449 StrCat (NewString
, L
"**");
451 StrCat (NewString
, ControllerName
);
453 NewStringToken
= mControllerToken
[Index
];
454 if (NewStringToken
== 0) {
455 Status
= HiiLibNewString (Private
->RegisteredHandle
, &NewStringToken
, NewString
);
457 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
);
459 ASSERT_EFI_ERROR (Status
);
460 FreePool (NewString
);
462 // Save the device path string toke for next access use
464 mControllerToken
[Index
] = NewStringToken
;
469 STRING_TOKEN (STR_GOTO_HELP_DRIVER
),
470 EFI_IFR_FLAG_CALLBACK
,
471 (UINT16
) (Index
+ KEY_VALUE_DEVICE_OFFSET
),
477 // Update first page form
480 Private
->RegisteredHandle
,
481 &mPlatformOverridesManagerGuid
,
488 FreePool (UpdateData
.Data
);
493 Get the first Driver Binding handle which has the specific image handle.
495 @param ImageHandle The Image handle
497 @return Handle to Driver binding
498 @retval NULL The paramter is not valid or the driver binding handle is not found.
502 GetDriverBindingHandleFromImageHandle (
503 IN EFI_HANDLE ImageHandle
508 UINTN DriverBindingHandleCount
;
509 EFI_HANDLE
*DriverBindingHandleBuffer
;
510 EFI_DRIVER_BINDING_PROTOCOL
*DriverBindingInterface
;
511 EFI_HANDLE DriverBindingHandle
;
513 DriverBindingHandle
= NULL
;
515 if (ImageHandle
== NULL
) {
519 // Get all drivers which support driver binding protocol
521 DriverBindingHandleCount
= 0;
522 Status
= gBS
->LocateHandleBuffer (
524 &gEfiDriverBindingProtocolGuid
,
526 &DriverBindingHandleCount
,
527 &DriverBindingHandleBuffer
529 if (EFI_ERROR (Status
) || (DriverBindingHandleCount
== 0)) {
534 // Get the first Driver Binding handle which has the specific image handle.
536 for (Index
= 0; Index
< DriverBindingHandleCount
; Index
++) {
537 DriverBindingInterface
= NULL
;
538 Status
= gBS
->OpenProtocol (
539 DriverBindingHandleBuffer
[Index
],
540 &gEfiDriverBindingProtocolGuid
,
541 (VOID
**) &DriverBindingInterface
,
544 EFI_OPEN_PROTOCOL_GET_PROTOCOL
546 if (EFI_ERROR (Status
)) {
550 if (DriverBindingInterface
->ImageHandle
== ImageHandle
) {
551 DriverBindingHandle
= DriverBindingHandleBuffer
[Index
];
556 FreePool (DriverBindingHandleBuffer
);
557 return DriverBindingHandle
;
561 Prepare to let user select the drivers which need mapping with the device controller
562 selected in first page.
564 @param Private Pointer to EFI_CALLBACK_INFO.
565 @param KeyValue The callback key value of device controller item in first page.
566 KeyValue is larger than or equal to KEY_VALUE_DEVICE_OFFSET.
567 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
569 @retval EFI_SUCCESS Always returned.
573 UpdateBindingDriverSelectPage (
574 IN EFI_CALLBACK_INFO
*Private
,
576 IN PLAT_OVER_MNGR_DATA
*FakeNvData
579 EFI_HII_UPDATE_DATA UpdateData
;
583 EFI_STRING_ID NewStringToken
;
584 EFI_STRING_ID NewStringHelpToken
;
585 UINTN DriverImageHandleCount
;
586 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
588 BOOLEAN FreeDriverName
;
589 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
590 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*BusSpecificDriverOverride
;
591 EFI_HANDLE DriverBindingHandle
;
594 // If user select a controller item in the first page the following code will be run.
595 // During second page, user will see all currnet driver bind protocol driver, the driver name and its device path will be shown
597 //First acquire the list of Loaded Image Protocols, and then when want the name of the driver, look up all the Driver Binding Protocols
598 // and find the first one whose ImageHandle field matches the image handle of the Loaded Image Protocol.
599 // 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.
602 mCurrentPage
= FORM_ID_DRIVER
;
604 // Switch the item callback key value to its NO. in mDevicePathHandleBuffer
606 mSelectedCtrIndex
= KeyValue
- KEY_VALUE_DEVICE_OFFSET
;
607 ASSERT (mSelectedCtrIndex
> 0 && mSelectedCtrIndex
< MAX_CHOICE_NUM
);
609 mLastSavedDriverImageNum
= 0;
611 // Clear all the content in dynamic page
613 UpdateData
.BufferSize
= UPDATE_DATA_SIZE
;
614 UpdateData
.Offset
= 0;
615 UpdateData
.Data
= AllocateZeroPool (UPDATE_DATA_SIZE
);
616 ASSERT (UpdateData
.Data
!= NULL
);
618 // Clear second page form
621 Private
->RegisteredHandle
,
622 &mPlatformOverridesManagerGuid
,
630 // Show all driver which support loaded image protocol in second page
632 DriverImageHandleCount
= 0;
633 Status
= gBS
->LocateHandleBuffer (
635 &gEfiLoadedImageProtocolGuid
,
637 &DriverImageHandleCount
,
638 &mDriverImageHandleBuffer
640 if (EFI_ERROR (Status
) || (DriverImageHandleCount
== 0)) {
641 return EFI_NOT_FOUND
;
644 mDriverImageHandleCount
= DriverImageHandleCount
;
645 for (Index
= 0; Index
< DriverImageHandleCount
; Index
++) {
647 // Step1: Get the driver image total file path for help string and the driver name.
651 // Find driver's Loaded Image protocol
655 Status
= gBS
->OpenProtocol (
656 mDriverImageHandleBuffer
[Index
],
657 &gEfiLoadedImageProtocolGuid
,
658 (VOID
**) &LoadedImage
,
661 EFI_OPEN_PROTOCOL_GET_PROTOCOL
663 if (EFI_ERROR (Status
)) {
664 FakeNvData
->DriSelection
[Index
] = 0x00;
667 mDriverImageProtocol
[Index
] = LoadedImage
;
669 // Find its related driver binding protocol
671 DriverBindingHandle
= GetDriverBindingHandleFromImageHandle (mDriverImageHandleBuffer
[Index
]);
672 if (DriverBindingHandle
== NULL
) {
673 FakeNvData
->DriSelection
[Index
] = 0x00;
678 // Get the EFI Loaded Image Device Path Protocol
680 LoadedImageDevicePath
= NULL
;
681 Status
= gBS
->HandleProtocol (
682 mDriverImageHandleBuffer
[Index
],
683 &gEfiLoadedImageDevicePathProtocolGuid
,
684 (VOID
**) &LoadedImageDevicePath
686 if (LoadedImageDevicePath
== NULL
) {
687 FakeNvData
->DriSelection
[Index
] = 0x00;
691 if (FakeNvData
->PciDeviceFilter
== 0x01) {
693 // only care the driver which is in a Pci device option rom,
694 // and the driver's LoadedImage->DeviceHandle must point to a pci device which has efi option rom
696 if (!EFI_ERROR (Status
)) {
697 Status
= gBS
->HandleProtocol(
698 LoadedImage
->DeviceHandle
,
699 &gEfiBusSpecificDriverOverrideProtocolGuid
,
700 (VOID
**) &BusSpecificDriverOverride
702 if (EFI_ERROR (Status
) || BusSpecificDriverOverride
== NULL
) {
703 FakeNvData
->DriSelection
[Index
] = 0x00;
707 FakeNvData
->DriSelection
[Index
] = 0x00;
713 // For driver name, try to get its component name, if fail, get its image name,
714 // if also fail, give a default name.
716 FreeDriverName
= FALSE
;
717 DriverName
= GetComponentName (DriverBindingHandle
);
718 if (DriverName
== NULL
) {
720 // get its image name
722 DriverName
= GetImageName (LoadedImage
);
724 if (DriverName
== NULL
) {
726 // give a default name
728 HiiLibGetStringFromHandle (Private
->RegisteredHandle
, STRING_TOKEN (STR_DRIVER_DEFAULT_NAME
), &DriverName
);
729 ASSERT (DriverName
!= NULL
);
730 FreeDriverName
= TRUE
; // the DriverName string need to free pool
735 // Step2 Export the driver name string and create check box item in second page
739 // First create the driver image name
741 NewString
= AllocateZeroPool (StrSize (DriverName
));
742 ASSERT (NewString
!= NULL
);
743 if (EFI_ERROR (CheckMapping (mControllerDevicePathProtocol
[mSelectedCtrIndex
], LoadedImageDevicePath
, &mMappingDataBase
, NULL
, NULL
))) {
744 FakeNvData
->DriSelection
[Index
] = 0x00;
746 FakeNvData
->DriSelection
[Index
] = 0x01;
747 mLastSavedDriverImageNum
++;
749 StrCat (NewString
, DriverName
);
750 NewStringToken
= mDriverImageToken
[Index
];
751 if (NewStringToken
== 0) {
752 Status
= HiiLibNewString (Private
->RegisteredHandle
, &NewStringToken
, NewString
);
754 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
);
756 mDriverImageToken
[Index
] = NewStringToken
;
757 ASSERT_EFI_ERROR (Status
);
758 FreePool (NewString
);
759 if (FreeDriverName
) {
760 FreePool (DriverName
);
764 // Second create the driver image device path as item help string
766 DriverName
= DevicePathToStr (LoadedImageDevicePath
);
768 NewString
= AllocateZeroPool (StrSize (DriverName
));
769 ASSERT (NewString
!= NULL
);
770 StrCat (NewString
, DriverName
);
771 NewStringHelpToken
= mDriverImageFilePathToken
[Index
];
772 if (NewStringHelpToken
== 0) {
773 Status
= HiiLibNewString (Private
->RegisteredHandle
, &NewStringHelpToken
, NewString
);
775 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringHelpToken
, NewString
);
777 mDriverImageFilePathToken
[Index
] = NewStringHelpToken
;
778 ASSERT_EFI_ERROR (Status
);
779 FreePool (NewString
);
780 FreePool (DriverName
);
782 CreateCheckBoxOpCode (
783 (UINT16
) (DRIVER_SELECTION_QUESTION_ID
+ Index
),
784 VARSTORE_ID_PLAT_OVER_MNGR
,
785 (UINT16
) (DRIVER_SELECTION_VAR_OFFSET
+ Index
),
795 // Update second page form
798 Private
->RegisteredHandle
,
799 &mPlatformOverridesManagerGuid
,
806 FreePool (UpdateData
.Data
);
811 Prepare to let user select the priority order of the drivers which are
812 selected in second page.
814 @param Private Pointer to EFI_CALLBACK_INFO.
815 @param KeyValue The callback key value of device controller item in first page.
816 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
818 @retval EFI_SUCCESS Always returned.
822 UpdatePrioritySelectPage (
823 IN EFI_CALLBACK_INFO
*Private
,
825 IN PLAT_OVER_MNGR_DATA
*FakeNvData
828 EFI_HII_UPDATE_DATA UpdateData
;
830 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
831 IFR_OPTION
*IfrOptionList
;
832 UINTN SelectedDriverImageNum
;
833 UINT32 DriverImageNO
;
839 // Following code will be run if user select 'order ... priority' item in second page
840 // Prepare third page. In third page, user will order the drivers priority which are selected in second page
842 mCurrentPage
= FORM_ID_ORDER
;
844 UpdateData
.BufferSize
= UPDATE_DATA_SIZE
;
845 UpdateData
.Offset
= 0;
846 UpdateData
.Data
= AllocateZeroPool (UPDATE_DATA_SIZE
);
847 ASSERT (UpdateData
.Data
!= NULL
);
849 // Clear third page form
852 Private
->RegisteredHandle
,
853 &mPlatformOverridesManagerGuid
,
861 // Check how many drivers have been selected
863 SelectedDriverImageNum
= 0;
864 for (Index
= 0; Index
< mDriverImageHandleCount
; Index
++) {
865 if (FakeNvData
->DriSelection
[Index
] != 0) {
866 SelectedDriverImageNum
++;
870 mSelectedDriverImageNum
= SelectedDriverImageNum
;
871 if (SelectedDriverImageNum
== 0) {
875 IfrOptionList
= AllocateZeroPool (sizeof (IFR_OPTION
) * mSelectedDriverImageNum
);
876 ASSERT (IfrOptionList
!= NULL
);
878 // Create order list for those selected drivers
880 SelectedDriverImageNum
= 0;
881 for (Index
= 0; Index
< mDriverImageHandleCount
; Index
++) {
882 if (FakeNvData
->DriSelection
[Index
] != 0) {
883 IfrOptionList
[SelectedDriverImageNum
].StringToken
= mDriverImageToken
[Index
];
885 // Use the NO. in driver binding buffer as value, will use it later
887 IfrOptionList
[SelectedDriverImageNum
].Value
.u8
= (UINT8
) (Index
+ 1);
888 IfrOptionList
[SelectedDriverImageNum
].Flags
= 0;
891 // Get the EFI Loaded Image Device Path Protocol
893 LoadedImageDevicePath
= NULL
;
894 gBS
->HandleProtocol (
895 mDriverImageHandleBuffer
[Index
],
896 &gEfiLoadedImageDevicePathProtocolGuid
,
897 (VOID
**) &LoadedImageDevicePath
899 ASSERT (LoadedImageDevicePath
!= NULL
);
902 // Check the driver DriverImage's order number in mapping database
906 mControllerDevicePathProtocol
[mSelectedCtrIndex
],
907 LoadedImageDevicePath
,
912 if (DriverImageNO
== 0) {
913 DriverImageNO
= (UINT32
) mLastSavedDriverImageNum
+ 1;
914 mLastSavedDriverImageNum
++;
916 TempNO
[SelectedDriverImageNum
] = DriverImageNO
;
917 SelectedDriverImageNum
++;
921 ASSERT (SelectedDriverImageNum
== mSelectedDriverImageNum
);
923 // NvRamMap Must be clear firstly
925 ZeroMem (FakeNvData
->DriOrder
, sizeof (FakeNvData
->DriOrder
));
928 // Order the selected drivers according to the info already in mapping database
929 // the less order number in mapping database the less order number in NvRamMap
931 for (Index
=0; Index
< SelectedDriverImageNum
; Index
++) {
933 // Find the minimal order number in TempNO array, its index in TempNO is same as IfrOptionList array
936 for (Index1
=0; Index1
< SelectedDriverImageNum
; Index1
++) {
937 if (TempNO
[Index1
] < TempNO
[MinNO
]) {
942 // the IfrOptionList[MinNO].Value = the driver NO. in driver binding buffer
944 FakeNvData
->DriOrder
[Index
] =IfrOptionList
[MinNO
].Value
.u8
;
945 TempNO
[MinNO
] = MAX_CHOICE_NUM
+ 1;
948 CreateOrderedListOpCode (
949 (UINT16
) DRIVER_ORDER_QUESTION_ID
,
950 VARSTORE_ID_PLAT_OVER_MNGR
,
951 (UINT16
) DRIVER_ORDER_VAR_OFFSET
,
952 mControllerToken
[mSelectedCtrIndex
],
953 mControllerToken
[mSelectedCtrIndex
],
954 EFI_IFR_FLAG_RESET_REQUIRED
,
956 EFI_IFR_NUMERIC_SIZE_1
,
957 (UINT8
) MAX_CHOICE_NUM
,
959 SelectedDriverImageNum
,
964 // Update third page form
967 Private
->RegisteredHandle
,
968 &mPlatformOverridesManagerGuid
,
975 FreePool (IfrOptionList
);
976 FreePool (UpdateData
.Data
);
981 Save the save the mapping database to NV variable.
983 @param Private Pointer to EFI_CALLBACK_INFO.
984 @param KeyValue The callback key value of device controller item in first page.
985 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
987 @retval EFI_SUCCESS Always returned.
992 IN EFI_CALLBACK_INFO
*Private
,
994 IN PLAT_OVER_MNGR_DATA
*FakeNvData
999 UINTN SelectedDriverImageNum
;
1000 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
1002 // Following code will be run if user select 'commint changes' in third page
1003 // user enter 'Commit Changes' to save the mapping database
1005 DeleteDriverImage (mControllerDevicePathProtocol
[mSelectedCtrIndex
], NULL
, &mMappingDataBase
);
1006 for (SelectedDriverImageNum
= 0; SelectedDriverImageNum
< mSelectedDriverImageNum
; SelectedDriverImageNum
++) {
1008 // DriOrder[SelectedDriverImageNum] = the driver NO. in driver binding buffer
1010 Index
= FakeNvData
->DriOrder
[SelectedDriverImageNum
] - 1;
1013 // Get the EFI Loaded Image Device Path Protocol
1015 LoadedImageDevicePath
= NULL
;
1016 Status
= gBS
->HandleProtocol (
1017 mDriverImageHandleBuffer
[Index
],
1018 &gEfiLoadedImageDevicePathProtocolGuid
,
1019 (VOID
**) &LoadedImageDevicePath
1021 ASSERT (LoadedImageDevicePath
!= NULL
);
1024 mControllerDevicePathProtocol
[mSelectedCtrIndex
],
1025 LoadedImageDevicePath
,
1027 (UINT32
)SelectedDriverImageNum
+ 1
1030 Status
= SaveOverridesMapping (&mMappingDataBase
);
1036 This function allows a caller to extract the current configuration for one
1037 or more named elements from the target driver.
1039 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1040 @param Request A null-terminated Unicode string in <ConfigRequest> format.
1041 @param Progress On return, points to a character in the Request string.
1042 Points to the string's null terminator if request was successful.
1043 Points to the most recent '&' before the first failing name/value
1044 pair (or the beginning of the string if the failure is in the
1045 first name/value pair) if the request was not successful.
1046 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
1047 has all values filled in for the names in the Request string.
1048 String to be allocated by the called function.
1050 @retval EFI_SUCCESS The Results is filled with the requested values.
1051 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
1052 @retval EFI_INVALID_PARAMETER Request is NULL, illegal syntax, or unknown name.
1053 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
1058 PlatOverMngrExtractConfig (
1059 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1060 IN CONST EFI_STRING Request
,
1061 OUT EFI_STRING
*Progress
,
1062 OUT EFI_STRING
*Results
1066 EFI_CALLBACK_INFO
*Private
;
1067 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
1069 if (Request
== NULL
) {
1070 return EFI_NOT_FOUND
;
1073 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1074 HiiConfigRouting
= Private
->HiiConfigRouting
;
1077 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
1079 Status
= HiiConfigRouting
->BlockToConfig (
1082 (UINT8
*) &Private
->FakeNvData
,
1083 sizeof (PLAT_OVER_MNGR_DATA
),
1091 This function processes the results of changes in configuration.
1093 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1094 @param Configuration A null-terminated Unicode string in <ConfigRequest> format.
1095 @param Progress A pointer to a string filled in with the offset of the most
1096 recent '&' before the first failing name/value pair (or the
1097 beginning of the string if the failure is in the first
1098 name/value pair) or the terminating NULL if all was successful.
1100 @retval EFI_SUCCESS The Results is processed successfully.
1101 @retval EFI_INVALID_PARAMETER Configuration is NULL.
1102 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
1107 PlatOverMngrRouteConfig (
1108 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1109 IN CONST EFI_STRING Configuration
,
1110 OUT EFI_STRING
*Progress
1113 EFI_CALLBACK_INFO
*Private
;
1117 PLAT_OVER_MNGR_DATA
*FakeNvData
;
1119 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1121 FakeNvData
= &Private
->FakeNvData
;
1122 BufferSize
= sizeof (PLAT_OVER_MNGR_DATA
);
1123 Status
= GetBrowserData (NULL
, NULL
, &BufferSize
, (UINT8
*) FakeNvData
);
1124 if (EFI_ERROR (Status
)) {
1128 if (mCurrentPage
== FORM_ID_DRIVER
) {
1129 KeyValue
= KEY_VALUE_DRIVER_GOTO_ORDER
;
1130 UpdatePrioritySelectPage (Private
, KeyValue
, FakeNvData
);
1131 KeyValue
= KEY_VALUE_ORDER_SAVE_AND_EXIT
;
1132 CommintChanges (Private
, KeyValue
, FakeNvData
);
1134 // Since UpdatePrioritySelectPage will change mCurrentPage,
1135 // should ensure the mCurrentPage still indicate the second page here
1137 mCurrentPage
= FORM_ID_DRIVER
;
1140 if (mCurrentPage
== FORM_ID_ORDER
) {
1141 KeyValue
= KEY_VALUE_ORDER_SAVE_AND_EXIT
;
1142 CommintChanges (Private
, KeyValue
, FakeNvData
);
1148 This is the function that is called to provide results data to the driver. This data
1149 consists of a unique key which is used to identify what data is either being passed back
1152 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1153 @param Action A null-terminated Unicode string in <ConfigRequest> format.
1154 @param KeyValue A unique Goto OpCode callback value which record user's selection.
1155 0x100 <= KeyValue <0x500 : user select a controller item in the first page;
1156 KeyValue == 0x1234 : user select 'Refresh' in first page, or user select 'Go to Previous Menu' in second page
1157 KeyValue == 0x1235 : user select 'Pci device filter' in first page
1158 KeyValue == 0x1500 : user select 'order ... priority' item in second page
1159 KeyValue == 0x1800 : user select 'commint changes' in third page
1160 KeyValue == 0x2000 : user select 'Go to Previous Menu' in third page
1161 @param Type The type of value for the question.
1162 @param Value A pointer to the data being sent to the original exporting driver.
1163 @param ActionRequest On return, points to the action requested by the callback function.
1165 @retval EFI_SUCCESS Always returned.
1170 PlatOverMngrCallback (
1171 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1172 IN EFI_BROWSER_ACTION Action
,
1173 IN EFI_QUESTION_ID KeyValue
,
1175 IN EFI_IFR_TYPE_VALUE
*Value
,
1176 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
1179 EFI_CALLBACK_INFO
*Private
;
1181 EFI_STRING_ID NewStringToken
;
1183 PLAT_OVER_MNGR_DATA
*FakeNvData
;
1186 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1188 FakeNvData
= &Private
->FakeNvData
;
1189 BufferSize
= sizeof (PLAT_OVER_MNGR_DATA
);
1190 Status
= GetBrowserData (NULL
, NULL
, &BufferSize
, (UINT8
*) FakeNvData
);
1191 if (EFI_ERROR (Status
)) {
1195 if (KeyValue
== KEY_VALUE_DEVICE_REFRESH
||
1196 KeyValue
== KEY_VALUE_DEVICE_FILTER
||
1197 KeyValue
== KEY_VALUE_DRIVER_GOTO_PREVIOUS
1199 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1201 // Update page title string
1203 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1204 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, L
"First, Select the controller by device path");
1205 ASSERT_EFI_ERROR (Status
);
1208 if (((KeyValue
>= KEY_VALUE_DEVICE_OFFSET
) && (KeyValue
< KEY_VALUE_DEVICE_MAX
)) || (KeyValue
== KEY_VALUE_ORDER_GOTO_PREVIOUS
)) {
1209 if (KeyValue
== KEY_VALUE_ORDER_GOTO_PREVIOUS
) {
1210 KeyValue
= (EFI_QUESTION_ID
) (mSelectedCtrIndex
+ KEY_VALUE_DEVICE_OFFSET
);
1212 UpdateBindingDriverSelectPage (Private
, KeyValue
, FakeNvData
);
1214 // Update page title string
1216 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1217 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, L
"Second, Select drivers for the previous selected controller");
1218 ASSERT_EFI_ERROR (Status
);
1221 if (KeyValue
== KEY_VALUE_DRIVER_GOTO_ORDER
) {
1222 UpdatePrioritySelectPage (Private
, KeyValue
, FakeNvData
);
1224 // Update page title string
1226 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1227 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, L
"Finally, Set the priority order for the drivers and save them");
1228 ASSERT_EFI_ERROR (Status
);
1231 if (KeyValue
== KEY_VALUE_ORDER_SAVE_AND_EXIT
) {
1232 Status
= CommintChanges (Private
, KeyValue
, FakeNvData
);
1233 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1234 if (EFI_ERROR (Status
)) {
1235 IfrLibCreatePopUp (1, &Key
, L
"Single Override Info too large, Saving Error!");
1236 return EFI_DEVICE_ERROR
;
1240 if (KeyValue
== KEY_VALUE_DEVICE_CLEAR
) {
1242 // Deletes all environment variable(s) that contain the override mappings info
1244 FreeMappingDatabase (&mMappingDataBase
);
1245 Status
= SaveOverridesMapping (&mMappingDataBase
);
1246 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1249 // Pass changed uncommitted data back to Form Browser
1251 BufferSize
= sizeof (PLAT_OVER_MNGR_DATA
);
1252 Status
= SetBrowserData (NULL
, NULL
, BufferSize
, (UINT8
*) FakeNvData
, NULL
);
1258 The driver Entry Point. The funciton will export a disk device class formset and
1259 its callback function to hii database.
1261 @param ImageHandle The firmware allocated handle for the EFI image.
1262 @param SystemTable A pointer to the EFI System Table.
1264 @retval EFI_SUCCESS The entry point is executed successfully.
1265 @retval other Some error occurs when executing this entry point.
1271 IN EFI_HANDLE ImageHandle
,
1272 IN EFI_SYSTEM_TABLE
*SystemTable
1276 EFI_HII_DATABASE_PROTOCOL
*HiiDatabase
;
1277 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
1278 EFI_CALLBACK_INFO
*CallbackInfo
;
1279 EFI_HANDLE DriverHandle
;
1280 EFI_FORM_BROWSER2_PROTOCOL
*FormBrowser2
;
1283 // There should only be one HII protocol
1285 Status
= gBS
->LocateProtocol (
1286 &gEfiHiiDatabaseProtocolGuid
,
1288 (VOID
**) &HiiDatabase
1290 if (EFI_ERROR (Status
)) {
1295 // There should only be one Form Configuration protocol
1297 Status
= gBS
->LocateProtocol (
1298 &gEfiFormBrowser2ProtocolGuid
,
1300 (VOID
**) &FormBrowser2
1302 if (EFI_ERROR (Status
)) {
1306 CallbackInfo
= AllocateZeroPool (sizeof (EFI_CALLBACK_INFO
));
1307 if (CallbackInfo
== NULL
) {
1308 return EFI_BAD_BUFFER_SIZE
;
1311 CallbackInfo
->Signature
= EFI_CALLBACK_INFO_SIGNATURE
;
1312 CallbackInfo
->ConfigAccess
.ExtractConfig
= PlatOverMngrExtractConfig
;
1313 CallbackInfo
->ConfigAccess
.RouteConfig
= PlatOverMngrRouteConfig
;
1314 CallbackInfo
->ConfigAccess
.Callback
= PlatOverMngrCallback
;
1317 // Create driver handle used by HII database
1319 Status
= HiiLibCreateHiiDriverHandle (&DriverHandle
);
1320 if (EFI_ERROR (Status
)) {
1323 CallbackInfo
->DriverHandle
= DriverHandle
;
1326 // Install Config Access protocol to driver handle
1328 Status
= gBS
->InstallProtocolInterface (
1330 &gEfiHiiConfigAccessProtocolGuid
,
1331 EFI_NATIVE_INTERFACE
,
1332 &CallbackInfo
->ConfigAccess
1334 if (EFI_ERROR (Status
)) {
1339 // Publish our HII data
1341 PackageList
= HiiLibPreparePackageList (
1343 &mPlatformOverridesManagerGuid
,
1347 ASSERT (PackageList
!= NULL
);
1349 Status
= HiiDatabase
->NewPackageList (
1353 &CallbackInfo
->RegisteredHandle
1355 FreePool (PackageList
);
1357 if (EFI_ERROR (Status
)) {
1362 // Locate ConfigRouting protocol
1364 Status
= gBS
->LocateProtocol (
1365 &gEfiHiiConfigRoutingProtocolGuid
,
1367 (VOID
**) &CallbackInfo
->HiiConfigRouting
1369 if (EFI_ERROR (Status
)) {
1374 // Clear all the globle variable
1376 mDriverImageHandleCount
= 0;
1378 ZeroMem (mDriverImageToken
, MAX_CHOICE_NUM
* sizeof (EFI_STRING_ID
));
1379 ZeroMem (mDriverImageFilePathToken
, MAX_CHOICE_NUM
* sizeof (EFI_STRING_ID
));
1380 ZeroMem (mControllerToken
, MAX_CHOICE_NUM
* sizeof (EFI_STRING_ID
));
1381 ZeroMem (mDriverImageProtocol
, MAX_CHOICE_NUM
* sizeof (EFI_LOADED_IMAGE_PROTOCOL
*));
1386 Status
= FormBrowser2
->SendForm (
1388 &CallbackInfo
->RegisteredHandle
,
1395 if (EFI_ERROR (Status
)) {
1399 Status
= HiiDatabase
->RemovePackageList (HiiDatabase
, CallbackInfo
->RegisteredHandle
);
1400 if (EFI_ERROR (Status
)) {
1407 if (CallbackInfo
->DriverHandle
!= NULL
) {
1408 HiiLibDestroyHiiDriverHandle (CallbackInfo
->DriverHandle
);
1410 if (CallbackInfo
!= NULL
) {
1411 FreePool (CallbackInfo
);
1418 Converting a given device to an unicode string.
1420 This function will dependent on gEfiDevicePathToTextProtocolGuid, if protocol
1421 does not installed, then return unknown device path L"?" directly.
1423 @param DevPath Given device path instance
1425 @return Converted string from given device path.
1426 @retval L"?" Can not locate gEfiDevicePathToTextProtocolGuid protocol for converting.
1430 IN EFI_DEVICE_PATH_PROTOCOL
*DevPath
1434 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
*DevPathToText
;
1437 if (DevPath
== NULL
) {
1441 Status
= gBS
->LocateProtocol (
1442 &gEfiDevicePathToTextProtocolGuid
,
1444 (VOID
**) &DevPathToText
1446 if (!EFI_ERROR (Status
)) {
1447 ToText
= DevPathToText
->ConvertDevicePathToText (
1452 ASSERT (ToText
!= NULL
);