devicemanager.c

来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 503 行 · 第 1/2 页

C
503
字号
/*++

Copyright (c) 2004 - 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: 

  DeviceManager.c

Abstract:

  The platform device manager reference implement

--*/

#include "DeviceManager.h"

STATIC UINT16                     mTokenCount;
EFI_FRONTPAGE_CALLBACK_INFO       FPCallbackInfo;
extern UINTN                      gCallbackKey;
extern EFI_FORM_BROWSER_PROTOCOL  *gBrowser;
extern EFI_GUID                   gBdsStringPackGuid;
extern BOOLEAN                    gConnectAllHappened;

STRING_REF                        gStringTokenTable[] = {
  STR_VIDEO_DEVICE,
  STR_NETWORK_DEVICE,
  STR_INPUT_DEVICE,
  STR_ON_BOARD_DEVICE,
  STR_OTHER_DEVICE,
  STR_EMPTY_STRING,
  0xFFFF
};

EFI_STATUS
EFIAPI
DeviceManagerCallbackRoutine (
  IN EFI_FORM_CALLBACK_PROTOCOL       *This,
  IN UINT16                           KeyValue,
  IN EFI_IFR_DATA_ARRAY               *DataArray,
  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. 

Arguments:

  KeyValue -        A unique value which is sent to the original exporting driver so that it
                    can identify the type of data to expect.  The format of the data tends to
                    vary based on the op-code that geerated the callback.

  Data -            A pointer to the data being sent to the original exporting driver.

Returns: 

--*/
{
  //
  // The KeyValue corresponds in this case to the handle which was requested to be displayed
  //
  EFI_FRONTPAGE_CALLBACK_INFO *CallbackInfo;

  CallbackInfo = EFI_FP_CALLBACK_DATA_FROM_THIS (This);
  switch (KeyValue) {
  case 0x2000:
    CallbackInfo->Data.VideoBIOS = (UINT8) (UINTN) DataArray->Data[0].Data;
    gRT->SetVariable (
          L"VBIOS",
          &gEfiGlobalVariableGuid,
          EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
          sizeof (UINT8),
          &CallbackInfo->Data.VideoBIOS
          );
    break;

  default:
    break;
  }

  gCallbackKey = KeyValue;
  return EFI_SUCCESS;
}

EFI_STATUS
InitializeDeviceManager (
  VOID
  )
/*++

Routine Description:

  Initialize HII information for the FrontPage

Arguments:
  None
            
Returns:

--*/
{
  EFI_STATUS          Status;
  EFI_HII_PACKAGES    *PackageList;
  EFI_HII_UPDATE_DATA *UpdateData;

  //
  // Allocate space for creation of UpdateData Buffer
  //
  UpdateData = EfiLibAllocateZeroPool (0x1000);
  ASSERT (UpdateData != NULL);

  PackageList = PreparePackages (1, &gBdsStringPackGuid, DeviceManagerVfrBin);
  Status      = Hii->NewPack (Hii, PackageList, &FPCallbackInfo.DevMgrHiiHandle);
  gBS->FreePool (PackageList);

  //
  // This example does not implement worker functions for the NV accessor functions.  Only a callback evaluator
  //
  FPCallbackInfo.Signature                = EFI_FP_CALLBACK_DATA_SIGNATURE;
  FPCallbackInfo.DevMgrCallback.NvRead    = NULL;
  FPCallbackInfo.DevMgrCallback.NvWrite   = NULL;
  FPCallbackInfo.DevMgrCallback.Callback  = DeviceManagerCallbackRoutine;

  //
  // Install protocol interface
  //
  FPCallbackInfo.CallbackHandle = NULL;

  Status = gBS->InstallProtocolInterface (
                  &FPCallbackInfo.CallbackHandle,
                  &gEfiFormCallbackProtocolGuid,
                  EFI_NATIVE_INTERFACE,
                  &FPCallbackInfo.DevMgrCallback
                  );

  ASSERT_EFI_ERROR (Status);

  //
  // Flag update pending in FormSet
  //
  UpdateData->FormSetUpdate = TRUE;
  //
  // Register CallbackHandle data for FormSet
  //
  UpdateData->FormCallbackHandle = (EFI_PHYSICAL_ADDRESS) (UINTN) FPCallbackInfo.CallbackHandle;
  //
  // Simply registering the callback handle
  //
  Hii->UpdateForm (Hii, FPCallbackInfo.DevMgrHiiHandle, (EFI_FORM_LABEL) 0x0000, TRUE, UpdateData);

  gBS->FreePool (UpdateData);
  return Status;
}

EFI_STATUS
CallDeviceManager (
  VOID
  )
/*++

Routine Description:
  
  Call the browser and display the device manager

Arguments:
  
  None
  
Returns:
  EFI_SUCCESS            - Operation is successful.
  EFI_INVALID_PARAMETER  - If the inputs to SendForm function is not valid.
  
--*/
{
  EFI_STATUS          Status;
  UINTN               BufferSize;
  UINTN               Count;
  EFI_HII_HANDLE      Index;
  UINT8               *Buffer;
  EFI_IFR_FORM_SET    *FormSetData;
  CHAR16              *String;
  UINTN               StringLength;
  EFI_HII_UPDATE_DATA *UpdateData;
  STRING_REF          Token;
  STRING_REF          TokenHelp;
  IFR_OPTION          *IfrOptionList;
  UINT8               *VideoOption;
  UINTN               VideoOptionSize;
  EFI_HII_HANDLE      *HiiHandles;
  UINT16              HandleBufferLength;
  BOOLEAN	            BootDeviceMngrMenuResetRequired;
  
  IfrOptionList       = NULL;
  VideoOption         = NULL;
  HiiHandles          = NULL;
  HandleBufferLength  = 0;

  //
  // Connect all prior to entering the platform setup menu.
  //
  if (!gConnectAllHappened) {
    BdsLibConnectAllDriversToAllControllers ();
    gConnectAllHappened = TRUE;
  }
  //
  // Allocate space for creation of UpdateData Buffer
  //
  UpdateData = EfiLibAllocateZeroPool (0x1000);
  ASSERT (UpdateData != NULL);

  Status        = EFI_SUCCESS;
  Buffer        = NULL;
  FormSetData   = NULL;
  gCallbackKey  = 0;
  if (mTokenCount == 0) {
    Hii->NewString (Hii, NULL, FPCallbackInfo.DevMgrHiiHandle, &mTokenCount, L" ");
  }

  Token     = mTokenCount;
  TokenHelp = (UINT16) (Token + 1);

  //
  // Reset the menu
  //
  for (Index = 0, Count = 1; Count < 0x10000; Count <<= 1, Index++) {
    //
    // We will strip off all previous menu entries
    //
    UpdateData->DataCount = 0xFF;

    //
    // Erase entries on this label
    //
    Hii->UpdateForm (Hii, FPCallbackInfo.DevMgrHiiHandle, (EFI_FORM_LABEL) Count, FALSE, UpdateData);

    //
    // Did we reach the end of the Token Table?
    //
    if (gStringTokenTable[Index] == 0xFFFF) {
      break;
    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?