setoptions.c
来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 870 行 · 第 1/3 页
C
870 行
/*++
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
SetOptions.c
Abstract:
A UI driver to offer a UI interface in device manager to let user use the SetOptions() function in configuration protocol to configure device.
The main flow:
1. The UI driver dynamicly locate all drivers which support configuration protocol and its managed device infos.
2. The UI driver export and dynamicly update a formset titled 'Set Options' according to the collected infos
3. Device manager present the formset page to let user select
4. The UI driver invoke the SetOptions() function in configuration protocol according to user's selection
--*/
#include "SetOptions.h"
#define SET_OPTIONS_GUID \
{ \
0x22afbab1, 0x23b, 0x452d, 0x80, 0xcf, 0x63, 0x75, 0xe0, 0x33, 0x91, 0x2e \
}
EFI_DRIVER_ENTRY_POINT (SetOptionsInit)
STATIC CFG_PROTOCOL_INVOKER_CHOICE mChoice[MAX_CHOICE_NUM];
EFI_STATUS
EFIAPI
SetOptionsInit (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
/*++
Routine Description:
The driver Entry Point.
The funciton will export a disk device class formset and its callback function to hii database
Arguments:
ImageHandle - EFI_HANDLE
SystemTable - EFI_SYSTEM_TABLE
Returns:
EFI_STATUS
--*/
{
EFI_STATUS Status;
EFI_HII_PROTOCOL *Hii;
EFI_HII_PACKAGES *PackageList;
EFI_HII_HANDLE HiiHandle;
EFI_HII_UPDATE_DATA *UpdateData;
EFI_CALLBACK_INFO *CallbackInfo;
EFI_HANDLE Handle;
UINTN ChoiceIndex;
EFI_GUID SetOptionsGuid = SET_OPTIONS_GUID;
//
// Initialize the library and our protocol.
//
EfiInitializeDriverLib (ImageHandle, SystemTable);
//
// There should only be one HII protocol
//
Status = gBS->LocateProtocol (
&gEfiHiiProtocolGuid,
NULL,
&Hii
);
if (EFI_ERROR (Status)) {
return Status ;
}
CallbackInfo = EfiLibAllocateZeroPool (sizeof (EFI_CALLBACK_INFO));
if (CallbackInfo == NULL) {
return EFI_BAD_BUFFER_SIZE;
}
CallbackInfo->Signature = EFI_CALLBACK_INFO_SIGNATURE;
CallbackInfo->Hii = Hii;
//
// This driver not implement worker functions for the NV accessor functions. Only a callback evaluator
//
CallbackInfo->DriverCallback.NvRead = NULL;
CallbackInfo->DriverCallback.NvWrite = NULL;
CallbackInfo->DriverCallback.Callback = SetOptionsCallback;
//
// Install protocol interface
//
Handle = NULL;
Status = gBS->InstallProtocolInterface (
&Handle,
&gEfiFormCallbackProtocolGuid,
EFI_NATIVE_INTERFACE,
&CallbackInfo->DriverCallback
);
ASSERT_EFI_ERROR (Status);
CallbackInfo->CallbackHandle = Handle;
PackageList = PreparePackages (2, &SetOptionsGuid, VfrBin, SetOptionsStrings);
Status = Hii->NewPack (Hii, PackageList, &HiiHandle);
gBS->FreePool (PackageList);
CallbackInfo->RegisteredHandle = HiiHandle;
//
// Allocate space for creation of Buffer
//
UpdateData = EfiLibAllocateZeroPool (0x1000);
ASSERT (UpdateData != NULL);
//
// Flag update pending in FormSet
//
UpdateData->FormSetUpdate = TRUE;
//
// Register CallbackHandle data for FormSet
//
UpdateData->FormCallbackHandle = (EFI_PHYSICAL_ADDRESS) (UINTN) CallbackInfo->CallbackHandle;
UpdateData->FormUpdate = FALSE;
UpdateData->FormTitle = 0;
UpdateData->DataCount = 0;
Hii->UpdateForm (Hii, HiiHandle, (EFI_FORM_LABEL) 0x0, TRUE, UpdateData);
gBS->FreePool (UpdateData);
//
// Clear all the mChoices
//
for (ChoiceIndex = 0; ChoiceIndex < MAX_CHOICE_NUM; ChoiceIndex++) {
mChoice[ChoiceIndex].DriverImageHandle = NULL;
mChoice[ChoiceIndex].DriverConfiguration = NULL;
mChoice[ChoiceIndex].ControllerHandle = NULL;
mChoice[ChoiceIndex].ChildControllerHandle = NULL;
mChoice[ChoiceIndex].DescriptionToken = 0;
}
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
SetOptionsCallback (
IN EFI_FORM_CALLBACK_PROTOCOL *This,
IN UINT16 KeyValue,
IN EFI_IFR_DATA_ARRAY *Data,
OUT EFI_HII_CALLBACK_PACKET **Packet
)
/*++
Routine Description:
This is the function that is called to provide results data to the driver. This data
consists of a unique key which is used to identify what data is either being passed back
or being asked for.
The callback function finish two main task:
1. Invoke the configuration protocol setoptions function according to user selection which
is recorded by KeyValue.
2. Collect all the available driver and controller infos to update the formset.
Arguments:
KeyValue - A unique Goto OpCode callback value which record user's selection,
In Set Options page, every item is associated to a goto IFR, and has a unique callback key.
Data - No use here.
Packet- No use here.
Returns - Always successful
--*/
{
EFI_CALLBACK_INFO *Private;
EFI_HII_UPDATE_DATA *UpdateData;
EFI_STATUS Status;
CHAR8 Language[4];
CHAR16 Lang[4];
UINTN LangSize;
UINTN Index;
UINTN ChoiceIndex;
UINT8 *Location;
UINTN DriverImageHandleCount;
EFI_HANDLE *DriverImageHandleBuffer;
EFI_DRIVER_CONFIGURATION_PROTOCOL *DriverConfiguration;
EFI_DRIVER_BINDING_PROTOCOL *DriverBinding;
EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
EFI_COMPONENT_NAME_PROTOCOL *ComponentName;
EFI_FORM_BROWSER_PROTOCOL *FormBrowser;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
UINTN ControllerHandleIndex;
CHAR16 *ControllerHandleName;
BOOLEAN FreeControllerHandleName;
UINTN ControllerHandleCount;
EFI_HANDLE *ControllerHandleBuffer;
UINTN ChildControllerHandleIndex;
CHAR16 *ChildControllerHandleName;
BOOLEAN FreeChildControllerHandleName;
UINTN ChildControllerHandleCount;
EFI_HANDLE *ChildControllerHandleBuffer;
CHAR16 *NewString;
STRING_REF NewStringToken;
CHAR16 *DriverName;
BOOLEAN FreeDriverName;
EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED ActionRequired;
Private = EFI_CALLBACK_INFO_FROM_THIS (This);
//
// Get current language to set options
//
LangSize = 0x3;
Status = gRT->GetVariable (
L"Lang",
&gEfiGlobalVariableGuid,
NULL,
&LangSize,
Language
);
ASSERT_EFI_ERROR (Status);
Status = GetCurrentLanguage (Lang);
ASSERT_EFI_ERROR (Status);
//
// Tast1: Invoke the configuration protocol setoptions function according to user selection.
// KeyValue between 0x100~0x200 means user select a driver or device item in 'Set Options' dynamic page
//
if ((0x100 <= KeyValue) && (KeyValue <= 0x200)) {
ChoiceIndex = KeyValue - 0x100;
ActionRequired = 0;
//
// There should only be one Form Configuration protocol
//
Status = gBS->LocateProtocol (
&gEfiFormBrowserProtocolGuid,
NULL,
&FormBrowser
);
ASSERT_EFI_ERROR (Status);
//
// Invoke the user selceted item's SetOptions function with corresponding driver or device handles
//
gST->ConOut->ClearScreen (gST->ConOut);
mChoice[ChoiceIndex].DriverConfiguration->SetOptions (
mChoice[ChoiceIndex].DriverConfiguration,
mChoice[ChoiceIndex].ControllerHandle,
mChoice[ChoiceIndex].ChildControllerHandle,
Language,
&ActionRequired
);
gST->ConOut->ClearScreen (gST->ConOut);
//
// Notify user the action required after SetOptions function finish, and do the action according to user intent
//
Status = ProcessActionRequired (
FormBrowser,
Private,
ActionRequired,
mChoice[ChoiceIndex].DriverImageHandle,
mChoice[ChoiceIndex].ControllerHandle,
mChoice[ChoiceIndex].ChildControllerHandle
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?