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/DevicePathLib.h>
43 #include <Library/BaseLib.h>
44 #include <Library/DebugLib.h>
45 #include <Library/UefiLib.h>
46 #include <Library/UefiApplicationEntryPoint.h>
47 #include <Library/UefiBootServicesTableLib.h>
48 #include <Library/PlatformDriverOverrideLib.h>
49 #include <Library/HiiLib.h>
50 #include <Library/IfrSupportLib.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
;
72 /// HII specific Vendor Device Path definition.
75 VENDOR_DEVICE_PATH VendorDevicePath
;
76 EFI_DEVICE_PATH_PROTOCOL End
;
77 } HII_VENDOR_DEVICE_PATH
;
82 // uni string and Vfr Binary data.
84 extern UINT8 VfrBin
[];
85 extern UINT8 PlatOverMngrStrings
[];
90 EFI_GUID mPlatformOverridesManagerGuid
= PLAT_OVER_MNGR_GUID
;
91 LIST_ENTRY mMappingDataBase
= INITIALIZE_LIST_HEAD_VARIABLE (mMappingDataBase
);
93 EFI_HANDLE
*mDevicePathHandleBuffer
;
94 EFI_HANDLE
*mDriverImageHandleBuffer
;
96 INTN mSelectedCtrIndex
;
97 EFI_STRING_ID mControllerToken
[MAX_CHOICE_NUM
];
98 UINTN mDriverImageHandleCount
;
99 EFI_STRING_ID mDriverImageToken
[MAX_CHOICE_NUM
];
100 EFI_STRING_ID mDriverImageFilePathToken
[MAX_CHOICE_NUM
];
101 EFI_LOADED_IMAGE_PROTOCOL
*mDriverImageProtocol
[MAX_CHOICE_NUM
];
102 EFI_DEVICE_PATH_PROTOCOL
*mControllerDevicePathProtocol
[MAX_CHOICE_NUM
];
103 UINTN mSelectedDriverImageNum
;
104 UINTN mLastSavedDriverImageNum
;
107 HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath
= {
110 HARDWARE_DEVICE_PATH
,
113 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
114 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
118 // {99936717-BF3D-4b04-9787-76CEE324D76F}
120 { 0x99936717, 0xbf3d, 0x4b04, { 0x97, 0x87, 0x76, 0xce, 0xe3, 0x24, 0xd7, 0x6f } }
123 END_DEVICE_PATH_TYPE
,
124 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
126 (UINT8
) (END_DEVICE_PATH_LENGTH
),
127 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
133 Converting a given device to an unicode string.
135 This function will dependent on gEfiDevicePathToTextProtocolGuid, if protocol
136 does not installed, then return unknown device path L"?" directly.
138 @param DevPath Given device path instance
140 @return Converted string from given device path.
141 @retval L"?" Can not locate gEfiDevicePathToTextProtocolGuid protocol for converting.
145 IN EFI_DEVICE_PATH_PROTOCOL
*DevPath
149 Worker function to get the driver name by ComponentName or ComponentName2 protocol
150 according to the driver binding handle.
152 @param DriverBindingHandle The Handle of DriverBinding.
153 @param ProtocolGuid The pointer to Component Name (2) protocol GUID.
154 @param VariableName The name of the RFC 4646 or ISO 639-2 language variable.
156 @retval !NULL Pointer into the image name if the image name is found,
157 @retval NULL Pointer to NULL if the image name is not found.
161 GetComponentNameWorker (
162 IN EFI_HANDLE DriverBindingHandle
,
163 IN EFI_GUID
*ProtocolGuid
,
164 IN CONST CHAR16
*VariableName
168 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
173 Status
= gBS
->OpenProtocol (
176 (VOID
*) &ComponentName
,
179 EFI_OPEN_PROTOCOL_GET_PROTOCOL
181 if (EFI_ERROR (Status
)) {
186 // Find the best matching language.
188 Language
= GetEfiGlobalVariable (VariableName
);
189 BestLanguage
= GetBestLanguage (
190 ComponentName
->SupportedLanguages
,
191 (BOOLEAN
) (ProtocolGuid
== &gEfiComponentNameProtocolGuid
),
197 if (BestLanguage
!= NULL
) {
198 ComponentName
->GetDriverName (
203 FreePool (BestLanguage
);
206 if (Language
!= NULL
) {
215 Get the driver name by ComponentName or ComponentName2 protocol
216 according to the driver binding handle
218 @param DriverBindingHandle The Handle of DriverBinding.
220 @retval !NULL Pointer into the image name if the image name is found,
221 @retval NULL Pointer to NULL if the image name is not found.
226 IN EFI_HANDLE DriverBindingHandle
232 // Try RFC 4646 Component Name 2 protocol first.
234 DriverName
= GetComponentNameWorker (DriverBindingHandle
, &gEfiComponentName2ProtocolGuid
, L
"PlatformLang");
235 if (DriverName
== NULL
) {
237 // If we can not get driver name from Component Name 2 protocol, we can try ISO 639-2 Component Name protocol.
239 DriverName
= GetComponentNameWorker (DriverBindingHandle
, &gEfiComponentNameProtocolGuid
, L
"Lang");
246 Get the image name from EFI UI section.
247 Get FV protocol by its loaded image protocol to abstract EFI UI section.
249 @param Image Pointer to the loaded image protocol
251 @retval !NULL Pointer to the image name if the image name is found,
252 @retval NULL NULL if the image name is not found.
257 IN EFI_LOADED_IMAGE_PROTOCOL
*Image
261 EFI_DEVICE_PATH_PROTOCOL
*DevPathNode
;
262 EFI_DEVICE_PATH_PROTOCOL
*AlignedDevPathNode
;
263 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*FvFilePath
;
266 UINT32 AuthenticationStatus
;
268 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv2
;
274 if (Image
->FilePath
== NULL
) {
277 DevPathNode
= Image
->FilePath
;
279 while (!IsDevicePathEnd (DevPathNode
)) {
281 // Make sure device path node is aligned when accessing it's FV Name Guid field.
283 AlignedDevPathNode
= AllocateCopyPool (DevicePathNodeLength(DevPathNode
), DevPathNode
);
286 // Find the Fv File path
288 NameGuid
= EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*)AlignedDevPathNode
);
289 if (NameGuid
!= NULL
) {
290 FvFilePath
= (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*) AlignedDevPathNode
;
291 Status
= gBS
->HandleProtocol (
293 &gEfiFirmwareVolume2ProtocolGuid
,
297 // Locate Image EFI UI section to get the image name.
299 if (!EFI_ERROR (Status
)) {
300 Status
= Fv2
->ReadSection (
302 &FvFilePath
->FvFileName
,
303 EFI_SECTION_USER_INTERFACE
,
307 &AuthenticationStatus
309 if (!EFI_ERROR (Status
)) {
310 FreePool (AlignedDevPathNode
);
317 FreePool (AlignedDevPathNode
);
320 // Next device path node
322 DevPathNode
= NextDevicePathNode (DevPathNode
);
329 Prepare the first page to let user select the device controller which need to
330 add mapping drivers if user select 'Refresh' in first page.
331 During first page, user will see all currnet controller device path in system,
332 select any device path will go to second page to select its overrides drivers.
334 @param Private Pointer to EFI_CALLBACK_INFO.
335 @param KeyValue The callback key value of device controller item in first page.
336 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
338 @retval EFI_SUCCESS Always returned.
342 UpdateDeviceSelectPage (
343 IN EFI_CALLBACK_INFO
*Private
,
345 IN PLAT_OVER_MNGR_DATA
*FakeNvData
348 EFI_HII_UPDATE_DATA UpdateData
;
351 UINTN DevicePathHandleCount
;
353 EFI_STRING_ID NewStringToken
;
354 CHAR16
*ControllerName
;
355 EFI_DEVICE_PATH_PROTOCOL
*ControllerDevicePath
;
356 EFI_PCI_IO_PROTOCOL
*PciIo
;
357 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*BusSpecificDriverOverride
;
361 // set current page form ID.
363 mCurrentPage
= FORM_ID_DEVICE
;
366 // Initial the mapping database in memory
368 FreeMappingDatabase (&mMappingDataBase
);
369 Status
= InitOverridesMapping (&mMappingDataBase
);
372 // Clear all the content in the first page
374 UpdateData
.BufferSize
= UPDATE_DATA_SIZE
;
375 UpdateData
.Offset
= 0;
376 UpdateData
.Data
= AllocateZeroPool (UPDATE_DATA_SIZE
);
377 ASSERT (UpdateData
.Data
!= NULL
);
379 // Clear first page form
382 Private
->RegisteredHandle
,
383 &mPlatformOverridesManagerGuid
,
391 // When user enter the page at first time, the 'first refresh' string is given to notify user to refresh all the drivers,
392 // then the 'first refresh' string will be replaced by the 'refresh' string, and the two strings content are same after the replacement
394 NewStringToken
= STRING_TOKEN (STR_FIRST_REFRESH
);
395 HiiLibGetStringFromHandle (Private
->RegisteredHandle
, STRING_TOKEN (STR_REFRESH
), &NewString
);
396 ASSERT (NewString
!= NULL
);
397 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
);
398 ASSERT_EFI_ERROR (Status
);
399 FreePool (NewString
);
401 NewStringToken
= STRING_TOKEN (STR_FIRST_REFRESH_HELP
);
402 HiiLibGetStringFromHandle (Private
->RegisteredHandle
, STRING_TOKEN (STR_REFRESH_HELP
), &NewString
);
403 ASSERT (NewString
!= NULL
);
404 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
);
405 ASSERT_EFI_ERROR (Status
);
406 FreePool (NewString
);
409 // created needed controller device item in first page
411 DevicePathHandleCount
= 0;
412 Status
= gBS
->LocateHandleBuffer (
414 &gEfiDevicePathProtocolGuid
,
416 &DevicePathHandleCount
,
417 &mDevicePathHandleBuffer
419 if (EFI_ERROR (Status
) || (DevicePathHandleCount
== 0)) {
423 for (Index
= 0; Index
< DevicePathHandleCount
; Index
++) {
424 if (FakeNvData
->PciDeviceFilter
== 0x01) {
426 // Only care PCI device which contain efi driver in its option rom.
430 // Check whether it is a pci device
432 ControllerDevicePath
= NULL
;
433 Status
= gBS
->OpenProtocol (
434 mDevicePathHandleBuffer
[Index
],
435 &gEfiPciIoProtocolGuid
,
439 EFI_OPEN_PROTOCOL_GET_PROTOCOL
441 if (EFI_ERROR (Status
)) {
445 // Check whether it contain efi driver in its option rom
447 Status
= gBS
->HandleProtocol(
448 mDevicePathHandleBuffer
[Index
],
449 &gEfiBusSpecificDriverOverrideProtocolGuid
,
450 (VOID
**) &BusSpecificDriverOverride
452 if (EFI_ERROR (Status
) || BusSpecificDriverOverride
== NULL
) {
457 ControllerDevicePath
= NULL
;
458 Status
= gBS
->OpenProtocol (
459 mDevicePathHandleBuffer
[Index
],
460 &gEfiDevicePathProtocolGuid
,
461 (VOID
**) &ControllerDevicePath
,
464 EFI_OPEN_PROTOCOL_GET_PROTOCOL
466 ASSERT_EFI_ERROR (Status
);
468 // Save the device path protocol interface
470 mControllerDevicePathProtocol
[Index
] = ControllerDevicePath
;
473 // Get the driver name
475 ControllerName
= DevicePathToStr (ControllerDevicePath
);
478 // Export the driver name string and create item in set options page
480 Len
= StrSize (ControllerName
);
481 NewString
= AllocateZeroPool (Len
+ StrSize (L
"--"));
482 ASSERT (NewString
!= NULL
);
483 if (EFI_ERROR (CheckMapping (ControllerDevicePath
,NULL
, &mMappingDataBase
, NULL
, NULL
))) {
484 StrCat (NewString
, L
"--");
486 StrCat (NewString
, L
"**");
488 StrCat (NewString
, ControllerName
);
490 NewStringToken
= mControllerToken
[Index
];
491 if (NewStringToken
== 0) {
492 Status
= HiiLibNewString (Private
->RegisteredHandle
, &NewStringToken
, NewString
);
494 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
);
496 ASSERT_EFI_ERROR (Status
);
497 FreePool (NewString
);
499 // Save the device path string toke for next access use
501 mControllerToken
[Index
] = NewStringToken
;
506 STRING_TOKEN (STR_GOTO_HELP_DRIVER
),
507 EFI_IFR_FLAG_CALLBACK
,
508 (UINT16
) (Index
+ KEY_VALUE_DEVICE_OFFSET
),
514 // Update first page form
517 Private
->RegisteredHandle
,
518 &mPlatformOverridesManagerGuid
,
525 FreePool (UpdateData
.Data
);
530 Get the first Driver Binding handle which has the specific image handle.
532 @param ImageHandle The Image handle
534 @return Handle to Driver binding
535 @retval NULL The paramter is not valid or the driver binding handle is not found.
539 GetDriverBindingHandleFromImageHandle (
540 IN EFI_HANDLE ImageHandle
545 UINTN DriverBindingHandleCount
;
546 EFI_HANDLE
*DriverBindingHandleBuffer
;
547 EFI_DRIVER_BINDING_PROTOCOL
*DriverBindingInterface
;
548 EFI_HANDLE DriverBindingHandle
;
550 DriverBindingHandle
= NULL
;
552 if (ImageHandle
== NULL
) {
556 // Get all drivers which support driver binding protocol
558 DriverBindingHandleCount
= 0;
559 Status
= gBS
->LocateHandleBuffer (
561 &gEfiDriverBindingProtocolGuid
,
563 &DriverBindingHandleCount
,
564 &DriverBindingHandleBuffer
566 if (EFI_ERROR (Status
) || (DriverBindingHandleCount
== 0)) {
571 // Get the first Driver Binding handle which has the specific image handle.
573 for (Index
= 0; Index
< DriverBindingHandleCount
; Index
++) {
574 DriverBindingInterface
= NULL
;
575 Status
= gBS
->OpenProtocol (
576 DriverBindingHandleBuffer
[Index
],
577 &gEfiDriverBindingProtocolGuid
,
578 (VOID
**) &DriverBindingInterface
,
581 EFI_OPEN_PROTOCOL_GET_PROTOCOL
583 if (EFI_ERROR (Status
)) {
587 if (DriverBindingInterface
->ImageHandle
== ImageHandle
) {
588 DriverBindingHandle
= DriverBindingHandleBuffer
[Index
];
593 FreePool (DriverBindingHandleBuffer
);
594 return DriverBindingHandle
;
598 Prepare to let user select the drivers which need mapping with the device controller
599 selected in first page.
601 @param Private Pointer to EFI_CALLBACK_INFO.
602 @param KeyValue The callback key value of device controller item in first page.
603 KeyValue is larger than or equal to KEY_VALUE_DEVICE_OFFSET.
604 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
606 @retval EFI_SUCCESS Always returned.
610 UpdateBindingDriverSelectPage (
611 IN EFI_CALLBACK_INFO
*Private
,
613 IN PLAT_OVER_MNGR_DATA
*FakeNvData
616 EFI_HII_UPDATE_DATA UpdateData
;
620 EFI_STRING_ID NewStringToken
;
621 EFI_STRING_ID NewStringHelpToken
;
622 UINTN DriverImageHandleCount
;
623 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
625 BOOLEAN FreeDriverName
;
626 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
627 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*BusSpecificDriverOverride
;
628 EFI_HANDLE DriverBindingHandle
;
631 // If user select a controller item in the first page the following code will be run.
632 // During second page, user will see all currnet driver bind protocol driver, the driver name and its device path will be shown
634 //First acquire the list of Loaded Image Protocols, and then when want the name of the driver, look up all the Driver Binding Protocols
635 // and find the first one whose ImageHandle field matches the image handle of the Loaded Image Protocol.
636 // 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.
639 mCurrentPage
= FORM_ID_DRIVER
;
641 // Switch the item callback key value to its NO. in mDevicePathHandleBuffer
643 mSelectedCtrIndex
= KeyValue
- KEY_VALUE_DEVICE_OFFSET
;
644 ASSERT (mSelectedCtrIndex
> 0 && mSelectedCtrIndex
< MAX_CHOICE_NUM
);
646 mLastSavedDriverImageNum
= 0;
648 // Clear all the content in dynamic page
650 UpdateData
.BufferSize
= UPDATE_DATA_SIZE
;
651 UpdateData
.Offset
= 0;
652 UpdateData
.Data
= AllocateZeroPool (UPDATE_DATA_SIZE
);
653 ASSERT (UpdateData
.Data
!= NULL
);
655 // Clear second page form
658 Private
->RegisteredHandle
,
659 &mPlatformOverridesManagerGuid
,
667 // Show all driver which support loaded image protocol in second page
669 DriverImageHandleCount
= 0;
670 Status
= gBS
->LocateHandleBuffer (
672 &gEfiLoadedImageProtocolGuid
,
674 &DriverImageHandleCount
,
675 &mDriverImageHandleBuffer
677 if (EFI_ERROR (Status
) || (DriverImageHandleCount
== 0)) {
678 return EFI_NOT_FOUND
;
681 mDriverImageHandleCount
= DriverImageHandleCount
;
682 for (Index
= 0; Index
< DriverImageHandleCount
; Index
++) {
684 // Step1: Get the driver image total file path for help string and the driver name.
688 // Find driver's Loaded Image protocol
692 Status
= gBS
->OpenProtocol (
693 mDriverImageHandleBuffer
[Index
],
694 &gEfiLoadedImageProtocolGuid
,
695 (VOID
**) &LoadedImage
,
698 EFI_OPEN_PROTOCOL_GET_PROTOCOL
700 if (EFI_ERROR (Status
)) {
701 FakeNvData
->DriSelection
[Index
] = 0x00;
704 mDriverImageProtocol
[Index
] = LoadedImage
;
706 // Find its related driver binding protocol
708 DriverBindingHandle
= GetDriverBindingHandleFromImageHandle (mDriverImageHandleBuffer
[Index
]);
709 if (DriverBindingHandle
== NULL
) {
710 FakeNvData
->DriSelection
[Index
] = 0x00;
715 // Get the EFI Loaded Image Device Path Protocol
717 LoadedImageDevicePath
= NULL
;
718 Status
= gBS
->HandleProtocol (
719 mDriverImageHandleBuffer
[Index
],
720 &gEfiLoadedImageDevicePathProtocolGuid
,
721 (VOID
**) &LoadedImageDevicePath
723 if (LoadedImageDevicePath
== NULL
) {
724 FakeNvData
->DriSelection
[Index
] = 0x00;
728 if (FakeNvData
->PciDeviceFilter
== 0x01) {
730 // only care the driver which is in a Pci device option rom,
731 // and the driver's LoadedImage->DeviceHandle must point to a pci device which has efi option rom
733 if (!EFI_ERROR (Status
)) {
734 Status
= gBS
->HandleProtocol(
735 LoadedImage
->DeviceHandle
,
736 &gEfiBusSpecificDriverOverrideProtocolGuid
,
737 (VOID
**) &BusSpecificDriverOverride
739 if (EFI_ERROR (Status
) || BusSpecificDriverOverride
== NULL
) {
740 FakeNvData
->DriSelection
[Index
] = 0x00;
744 FakeNvData
->DriSelection
[Index
] = 0x00;
750 // For driver name, try to get its component name, if fail, get its image name,
751 // if also fail, give a default name.
753 FreeDriverName
= FALSE
;
754 DriverName
= GetComponentName (DriverBindingHandle
);
755 if (DriverName
== NULL
) {
757 // get its image name
759 DriverName
= GetImageName (LoadedImage
);
761 if (DriverName
== NULL
) {
763 // give a default name
765 HiiLibGetStringFromHandle (Private
->RegisteredHandle
, STRING_TOKEN (STR_DRIVER_DEFAULT_NAME
), &DriverName
);
766 ASSERT (DriverName
!= NULL
);
767 FreeDriverName
= TRUE
; // the DriverName string need to free pool
772 // Step2 Export the driver name string and create check box item in second page
776 // First create the driver image name
778 NewString
= AllocateZeroPool (StrSize (DriverName
));
779 ASSERT (NewString
!= NULL
);
780 if (EFI_ERROR (CheckMapping (mControllerDevicePathProtocol
[mSelectedCtrIndex
], LoadedImageDevicePath
, &mMappingDataBase
, NULL
, NULL
))) {
781 FakeNvData
->DriSelection
[Index
] = 0x00;
783 FakeNvData
->DriSelection
[Index
] = 0x01;
784 mLastSavedDriverImageNum
++;
786 StrCat (NewString
, DriverName
);
787 NewStringToken
= mDriverImageToken
[Index
];
788 if (NewStringToken
== 0) {
789 Status
= HiiLibNewString (Private
->RegisteredHandle
, &NewStringToken
, NewString
);
791 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, NewString
);
793 mDriverImageToken
[Index
] = NewStringToken
;
794 ASSERT_EFI_ERROR (Status
);
795 FreePool (NewString
);
796 if (FreeDriverName
) {
797 FreePool (DriverName
);
801 // Second create the driver image device path as item help string
803 DriverName
= DevicePathToStr (LoadedImageDevicePath
);
805 NewString
= AllocateZeroPool (StrSize (DriverName
));
806 ASSERT (NewString
!= NULL
);
807 StrCat (NewString
, DriverName
);
808 NewStringHelpToken
= mDriverImageFilePathToken
[Index
];
809 if (NewStringHelpToken
== 0) {
810 Status
= HiiLibNewString (Private
->RegisteredHandle
, &NewStringHelpToken
, NewString
);
812 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringHelpToken
, NewString
);
814 mDriverImageFilePathToken
[Index
] = NewStringHelpToken
;
815 ASSERT_EFI_ERROR (Status
);
816 FreePool (NewString
);
817 FreePool (DriverName
);
819 CreateCheckBoxOpCode (
820 (UINT16
) (DRIVER_SELECTION_QUESTION_ID
+ Index
),
821 VARSTORE_ID_PLAT_OVER_MNGR
,
822 (UINT16
) (DRIVER_SELECTION_VAR_OFFSET
+ Index
),
832 // Update second page form
835 Private
->RegisteredHandle
,
836 &mPlatformOverridesManagerGuid
,
843 FreePool (UpdateData
.Data
);
848 Prepare to let user select the priority order of the drivers which are
849 selected in second page.
851 @param Private Pointer to EFI_CALLBACK_INFO.
852 @param KeyValue The callback key value of device controller item in first page.
853 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
855 @retval EFI_SUCCESS Always returned.
859 UpdatePrioritySelectPage (
860 IN EFI_CALLBACK_INFO
*Private
,
862 IN PLAT_OVER_MNGR_DATA
*FakeNvData
865 EFI_HII_UPDATE_DATA UpdateData
;
867 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
868 IFR_OPTION
*IfrOptionList
;
869 UINTN SelectedDriverImageNum
;
870 UINT32 DriverImageNO
;
876 // Following code will be run if user select 'order ... priority' item in second page
877 // Prepare third page. In third page, user will order the drivers priority which are selected in second page
879 mCurrentPage
= FORM_ID_ORDER
;
881 UpdateData
.BufferSize
= UPDATE_DATA_SIZE
;
882 UpdateData
.Offset
= 0;
883 UpdateData
.Data
= AllocateZeroPool (UPDATE_DATA_SIZE
);
884 ASSERT (UpdateData
.Data
!= NULL
);
886 // Clear third page form
889 Private
->RegisteredHandle
,
890 &mPlatformOverridesManagerGuid
,
898 // Check how many drivers have been selected
900 SelectedDriverImageNum
= 0;
901 for (Index
= 0; Index
< mDriverImageHandleCount
; Index
++) {
902 if (FakeNvData
->DriSelection
[Index
] != 0) {
903 SelectedDriverImageNum
++;
907 mSelectedDriverImageNum
= SelectedDriverImageNum
;
908 if (SelectedDriverImageNum
== 0) {
912 IfrOptionList
= AllocateZeroPool (sizeof (IFR_OPTION
) * mSelectedDriverImageNum
);
913 ASSERT (IfrOptionList
!= NULL
);
915 // Create order list for those selected drivers
917 SelectedDriverImageNum
= 0;
918 for (Index
= 0; Index
< mDriverImageHandleCount
; Index
++) {
919 if (FakeNvData
->DriSelection
[Index
] != 0) {
920 IfrOptionList
[SelectedDriverImageNum
].StringToken
= mDriverImageToken
[Index
];
922 // Use the NO. in driver binding buffer as value, will use it later
924 IfrOptionList
[SelectedDriverImageNum
].Value
.u8
= (UINT8
) (Index
+ 1);
925 IfrOptionList
[SelectedDriverImageNum
].Flags
= 0;
928 // Get the EFI Loaded Image Device Path Protocol
930 LoadedImageDevicePath
= NULL
;
931 gBS
->HandleProtocol (
932 mDriverImageHandleBuffer
[Index
],
933 &gEfiLoadedImageDevicePathProtocolGuid
,
934 (VOID
**) &LoadedImageDevicePath
936 ASSERT (LoadedImageDevicePath
!= NULL
);
939 // Check the driver DriverImage's order number in mapping database
943 mControllerDevicePathProtocol
[mSelectedCtrIndex
],
944 LoadedImageDevicePath
,
949 if (DriverImageNO
== 0) {
950 DriverImageNO
= (UINT32
) mLastSavedDriverImageNum
+ 1;
951 mLastSavedDriverImageNum
++;
953 TempNO
[SelectedDriverImageNum
] = DriverImageNO
;
954 SelectedDriverImageNum
++;
958 ASSERT (SelectedDriverImageNum
== mSelectedDriverImageNum
);
960 // NvRamMap Must be clear firstly
962 ZeroMem (FakeNvData
->DriOrder
, sizeof (FakeNvData
->DriOrder
));
965 // Order the selected drivers according to the info already in mapping database
966 // the less order number in mapping database the less order number in NvRamMap
968 for (Index
=0; Index
< SelectedDriverImageNum
; Index
++) {
970 // Find the minimal order number in TempNO array, its index in TempNO is same as IfrOptionList array
973 for (Index1
=0; Index1
< SelectedDriverImageNum
; Index1
++) {
974 if (TempNO
[Index1
] < TempNO
[MinNO
]) {
979 // the IfrOptionList[MinNO].Value = the driver NO. in driver binding buffer
981 FakeNvData
->DriOrder
[Index
] =IfrOptionList
[MinNO
].Value
.u8
;
982 TempNO
[MinNO
] = MAX_CHOICE_NUM
+ 1;
985 CreateOrderedListOpCode (
986 (UINT16
) DRIVER_ORDER_QUESTION_ID
,
987 VARSTORE_ID_PLAT_OVER_MNGR
,
988 (UINT16
) DRIVER_ORDER_VAR_OFFSET
,
989 mControllerToken
[mSelectedCtrIndex
],
990 mControllerToken
[mSelectedCtrIndex
],
991 EFI_IFR_FLAG_RESET_REQUIRED
,
993 EFI_IFR_NUMERIC_SIZE_1
,
994 (UINT8
) MAX_CHOICE_NUM
,
996 SelectedDriverImageNum
,
1001 // Update third page form
1004 Private
->RegisteredHandle
,
1005 &mPlatformOverridesManagerGuid
,
1012 FreePool (IfrOptionList
);
1013 FreePool (UpdateData
.Data
);
1018 Save the save the mapping database to NV variable.
1020 @param Private Pointer to EFI_CALLBACK_INFO.
1021 @param KeyValue The callback key value of device controller item in first page.
1022 @param FakeNvData Pointer to PLAT_OVER_MNGR_DATA.
1024 @retval EFI_SUCCESS Always returned.
1029 IN EFI_CALLBACK_INFO
*Private
,
1031 IN PLAT_OVER_MNGR_DATA
*FakeNvData
1036 UINTN SelectedDriverImageNum
;
1037 EFI_DEVICE_PATH_PROTOCOL
*LoadedImageDevicePath
;
1039 // Following code will be run if user select 'commint changes' in third page
1040 // user enter 'Commit Changes' to save the mapping database
1042 DeleteDriverImage (mControllerDevicePathProtocol
[mSelectedCtrIndex
], NULL
, &mMappingDataBase
);
1043 for (SelectedDriverImageNum
= 0; SelectedDriverImageNum
< mSelectedDriverImageNum
; SelectedDriverImageNum
++) {
1045 // DriOrder[SelectedDriverImageNum] = the driver NO. in driver binding buffer
1047 Index
= FakeNvData
->DriOrder
[SelectedDriverImageNum
] - 1;
1050 // Get the EFI Loaded Image Device Path Protocol
1052 LoadedImageDevicePath
= NULL
;
1053 Status
= gBS
->HandleProtocol (
1054 mDriverImageHandleBuffer
[Index
],
1055 &gEfiLoadedImageDevicePathProtocolGuid
,
1056 (VOID
**) &LoadedImageDevicePath
1058 ASSERT (LoadedImageDevicePath
!= NULL
);
1061 mControllerDevicePathProtocol
[mSelectedCtrIndex
],
1062 LoadedImageDevicePath
,
1064 (UINT32
)SelectedDriverImageNum
+ 1
1067 Status
= SaveOverridesMapping (&mMappingDataBase
);
1073 This function allows a caller to extract the current configuration for one
1074 or more named elements from the target driver.
1076 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1077 @param Request A null-terminated Unicode string in <ConfigRequest> format.
1078 @param Progress On return, points to a character in the Request string.
1079 Points to the string's null terminator if request was successful.
1080 Points to the most recent '&' before the first failing name/value
1081 pair (or the beginning of the string if the failure is in the
1082 first name/value pair) if the request was not successful.
1083 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
1084 has all values filled in for the names in the Request string.
1085 String to be allocated by the called function.
1087 @retval EFI_SUCCESS The Results is filled with the requested values.
1088 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
1089 @retval EFI_INVALID_PARAMETER Request is NULL, illegal syntax, or unknown name.
1090 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
1095 PlatOverMngrExtractConfig (
1096 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1097 IN CONST EFI_STRING Request
,
1098 OUT EFI_STRING
*Progress
,
1099 OUT EFI_STRING
*Results
1103 EFI_CALLBACK_INFO
*Private
;
1104 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
1106 if (Request
== NULL
) {
1107 return EFI_NOT_FOUND
;
1110 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1111 HiiConfigRouting
= Private
->HiiConfigRouting
;
1114 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
1116 Status
= HiiConfigRouting
->BlockToConfig (
1119 (UINT8
*) &Private
->FakeNvData
,
1120 sizeof (PLAT_OVER_MNGR_DATA
),
1128 This function processes the results of changes in configuration.
1130 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1131 @param Configuration A null-terminated Unicode string in <ConfigRequest> format.
1132 @param Progress A pointer to a string filled in with the offset of the most
1133 recent '&' before the first failing name/value pair (or the
1134 beginning of the string if the failure is in the first
1135 name/value pair) or the terminating NULL if all was successful.
1137 @retval EFI_SUCCESS The Results is processed successfully.
1138 @retval EFI_INVALID_PARAMETER Configuration is NULL.
1139 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
1144 PlatOverMngrRouteConfig (
1145 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1146 IN CONST EFI_STRING Configuration
,
1147 OUT EFI_STRING
*Progress
1150 EFI_CALLBACK_INFO
*Private
;
1154 PLAT_OVER_MNGR_DATA
*FakeNvData
;
1156 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1158 FakeNvData
= &Private
->FakeNvData
;
1159 BufferSize
= sizeof (PLAT_OVER_MNGR_DATA
);
1160 Status
= GetBrowserData (NULL
, NULL
, &BufferSize
, (UINT8
*) FakeNvData
);
1161 if (EFI_ERROR (Status
)) {
1165 if (mCurrentPage
== FORM_ID_DRIVER
) {
1166 KeyValue
= KEY_VALUE_DRIVER_GOTO_ORDER
;
1167 UpdatePrioritySelectPage (Private
, KeyValue
, FakeNvData
);
1168 KeyValue
= KEY_VALUE_ORDER_SAVE_AND_EXIT
;
1169 CommintChanges (Private
, KeyValue
, FakeNvData
);
1171 // Since UpdatePrioritySelectPage will change mCurrentPage,
1172 // should ensure the mCurrentPage still indicate the second page here
1174 mCurrentPage
= FORM_ID_DRIVER
;
1177 if (mCurrentPage
== FORM_ID_ORDER
) {
1178 KeyValue
= KEY_VALUE_ORDER_SAVE_AND_EXIT
;
1179 CommintChanges (Private
, KeyValue
, FakeNvData
);
1185 This is the function that is called to provide results data to the driver. This data
1186 consists of a unique key which is used to identify what data is either being passed back
1189 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1190 @param Action A null-terminated Unicode string in <ConfigRequest> format.
1191 @param KeyValue A unique Goto OpCode callback value which record user's selection.
1192 0x100 <= KeyValue <0x500 : user select a controller item in the first page;
1193 KeyValue == 0x1234 : user select 'Refresh' in first page, or user select 'Go to Previous Menu' in second page
1194 KeyValue == 0x1235 : user select 'Pci device filter' in first page
1195 KeyValue == 0x1500 : user select 'order ... priority' item in second page
1196 KeyValue == 0x1800 : user select 'commint changes' in third page
1197 KeyValue == 0x2000 : user select 'Go to Previous Menu' in third page
1198 @param Type The type of value for the question.
1199 @param Value A pointer to the data being sent to the original exporting driver.
1200 @param ActionRequest On return, points to the action requested by the callback function.
1202 @retval EFI_SUCCESS Always returned.
1207 PlatOverMngrCallback (
1208 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1209 IN EFI_BROWSER_ACTION Action
,
1210 IN EFI_QUESTION_ID KeyValue
,
1212 IN EFI_IFR_TYPE_VALUE
*Value
,
1213 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
1216 EFI_CALLBACK_INFO
*Private
;
1218 EFI_STRING_ID NewStringToken
;
1220 PLAT_OVER_MNGR_DATA
*FakeNvData
;
1223 Private
= EFI_CALLBACK_INFO_FROM_THIS (This
);
1225 FakeNvData
= &Private
->FakeNvData
;
1226 BufferSize
= sizeof (PLAT_OVER_MNGR_DATA
);
1227 Status
= GetBrowserData (NULL
, NULL
, &BufferSize
, (UINT8
*) FakeNvData
);
1228 if (EFI_ERROR (Status
)) {
1232 if (KeyValue
== KEY_VALUE_DEVICE_REFRESH
||
1233 KeyValue
== KEY_VALUE_DEVICE_FILTER
||
1234 KeyValue
== KEY_VALUE_DRIVER_GOTO_PREVIOUS
1236 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1238 // Update page title string
1240 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1241 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, L
"First, Select the controller by device path");
1242 ASSERT_EFI_ERROR (Status
);
1245 if (((KeyValue
>= KEY_VALUE_DEVICE_OFFSET
) && (KeyValue
< KEY_VALUE_DEVICE_MAX
)) || (KeyValue
== KEY_VALUE_ORDER_GOTO_PREVIOUS
)) {
1246 if (KeyValue
== KEY_VALUE_ORDER_GOTO_PREVIOUS
) {
1247 KeyValue
= (EFI_QUESTION_ID
) (mSelectedCtrIndex
+ KEY_VALUE_DEVICE_OFFSET
);
1249 UpdateBindingDriverSelectPage (Private
, KeyValue
, FakeNvData
);
1251 // Update page title string
1253 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1254 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, L
"Second, Select drivers for the previous selected controller");
1255 ASSERT_EFI_ERROR (Status
);
1258 if (KeyValue
== KEY_VALUE_DRIVER_GOTO_ORDER
) {
1259 UpdatePrioritySelectPage (Private
, KeyValue
, FakeNvData
);
1261 // Update page title string
1263 NewStringToken
= STRING_TOKEN (STR_TITLE
);
1264 Status
= HiiLibSetString (Private
->RegisteredHandle
, NewStringToken
, L
"Finally, Set the priority order for the drivers and save them");
1265 ASSERT_EFI_ERROR (Status
);
1268 if (KeyValue
== KEY_VALUE_ORDER_SAVE_AND_EXIT
) {
1269 Status
= CommintChanges (Private
, KeyValue
, FakeNvData
);
1270 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1271 if (EFI_ERROR (Status
)) {
1272 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Single Override Info too large, Saving Error!", NULL
);
1273 return EFI_DEVICE_ERROR
;
1277 if (KeyValue
== KEY_VALUE_DEVICE_CLEAR
) {
1279 // Deletes all environment variable(s) that contain the override mappings info
1281 FreeMappingDatabase (&mMappingDataBase
);
1282 Status
= SaveOverridesMapping (&mMappingDataBase
);
1283 UpdateDeviceSelectPage (Private
, KeyValue
, FakeNvData
);
1286 // Pass changed uncommitted data back to Form Browser
1288 BufferSize
= sizeof (PLAT_OVER_MNGR_DATA
);
1289 Status
= SetBrowserData (NULL
, NULL
, BufferSize
, (UINT8
*) FakeNvData
, NULL
);
1295 The driver Entry Point. The funciton will export a disk device class formset and
1296 its callback function to hii database.
1298 @param ImageHandle The firmware allocated handle for the EFI image.
1299 @param SystemTable A pointer to the EFI System Table.
1301 @retval EFI_SUCCESS The entry point is executed successfully.
1302 @retval other Some error occurs when executing this entry point.
1308 IN EFI_HANDLE ImageHandle
,
1309 IN EFI_SYSTEM_TABLE
*SystemTable
1313 EFI_HII_DATABASE_PROTOCOL
*HiiDatabase
;
1314 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
1315 EFI_CALLBACK_INFO
*CallbackInfo
;
1316 EFI_FORM_BROWSER2_PROTOCOL
*FormBrowser2
;
1319 // There should only be one HII protocol
1321 Status
= gBS
->LocateProtocol (
1322 &gEfiHiiDatabaseProtocolGuid
,
1324 (VOID
**) &HiiDatabase
1326 if (EFI_ERROR (Status
)) {
1331 // There should only be one Form Configuration protocol
1333 Status
= gBS
->LocateProtocol (
1334 &gEfiFormBrowser2ProtocolGuid
,
1336 (VOID
**) &FormBrowser2
1338 if (EFI_ERROR (Status
)) {
1342 CallbackInfo
= AllocateZeroPool (sizeof (EFI_CALLBACK_INFO
));
1343 if (CallbackInfo
== NULL
) {
1344 return EFI_BAD_BUFFER_SIZE
;
1347 CallbackInfo
->Signature
= EFI_CALLBACK_INFO_SIGNATURE
;
1348 CallbackInfo
->ConfigAccess
.ExtractConfig
= PlatOverMngrExtractConfig
;
1349 CallbackInfo
->ConfigAccess
.RouteConfig
= PlatOverMngrRouteConfig
;
1350 CallbackInfo
->ConfigAccess
.Callback
= PlatOverMngrCallback
;
1353 // Install Device Path Protocol and Config Access protocol to driver handle
1355 Status
= gBS
->InstallMultipleProtocolInterfaces (
1356 &CallbackInfo
->DriverHandle
,
1357 &gEfiDevicePathProtocolGuid
,
1358 &mHiiVendorDevicePath
,
1359 &gEfiHiiConfigAccessProtocolGuid
,
1360 &CallbackInfo
->ConfigAccess
,
1363 if (EFI_ERROR (Status
)) {
1368 // Publish our HII data
1370 PackageList
= HiiLibPreparePackageList (
1372 &mPlatformOverridesManagerGuid
,
1376 ASSERT (PackageList
!= NULL
);
1378 Status
= HiiDatabase
->NewPackageList (
1381 CallbackInfo
->DriverHandle
,
1382 &CallbackInfo
->RegisteredHandle
1384 FreePool (PackageList
);
1386 if (EFI_ERROR (Status
)) {
1391 // Locate ConfigRouting protocol
1393 Status
= gBS
->LocateProtocol (
1394 &gEfiHiiConfigRoutingProtocolGuid
,
1396 (VOID
**) &CallbackInfo
->HiiConfigRouting
1398 if (EFI_ERROR (Status
)) {
1403 // Clear all the globle variable
1405 mDriverImageHandleCount
= 0;
1407 ZeroMem (mDriverImageToken
, MAX_CHOICE_NUM
* sizeof (EFI_STRING_ID
));
1408 ZeroMem (mDriverImageFilePathToken
, MAX_CHOICE_NUM
* sizeof (EFI_STRING_ID
));
1409 ZeroMem (mControllerToken
, MAX_CHOICE_NUM
* sizeof (EFI_STRING_ID
));
1410 ZeroMem (mDriverImageProtocol
, MAX_CHOICE_NUM
* sizeof (EFI_LOADED_IMAGE_PROTOCOL
*));
1415 Status
= FormBrowser2
->SendForm (
1417 &CallbackInfo
->RegisteredHandle
,
1424 if (EFI_ERROR (Status
)) {
1428 Status
= HiiDatabase
->RemovePackageList (HiiDatabase
, CallbackInfo
->RegisteredHandle
);
1429 if (EFI_ERROR (Status
)) {
1436 if (CallbackInfo
->DriverHandle
!= NULL
) {
1437 gBS
->UninstallMultipleProtocolInterfaces (
1438 CallbackInfo
->DriverHandle
,
1439 &gEfiDevicePathProtocolGuid
,
1440 &mHiiVendorDevicePath
,
1441 &gEfiHiiConfigAccessProtocolGuid
,
1442 &CallbackInfo
->ConfigAccess
,
1446 if (CallbackInfo
!= NULL
) {
1447 FreePool (CallbackInfo
);
1454 Converting a given device to an unicode string.
1456 This function will dependent on gEfiDevicePathToTextProtocolGuid, if protocol
1457 does not installed, then return unknown device path L"?" directly.
1459 @param DevPath Given device path instance
1461 @return Converted string from given device path.
1462 @retval L"?" Can not locate gEfiDevicePathToTextProtocolGuid protocol for converting.
1466 IN EFI_DEVICE_PATH_PROTOCOL
*DevPath
1470 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
*DevPathToText
;
1473 if (DevPath
== NULL
) {
1477 Status
= gBS
->LocateProtocol (
1478 &gEfiDevicePathToTextProtocolGuid
,
1480 (VOID
**) &DevPathToText
1482 if (!EFI_ERROR (Status
)) {
1483 ToText
= DevPathToText
->ConvertDevicePathToText (
1488 ASSERT (ToText
!= NULL
);