conplatform.c
来自「Next BIOS Source code : Extensible Firmw」· C语言 代码 · 共 948 行 · 第 1/2 页
C
948 行
/*++
Copyright (c) 1999 - 2002 Intel Corporation. All rights reserved
This software and associated documentation (if any) is furnished
under a license and may only be used or copied in accordance
with the terms of the license. Except as permitted by such
license, no part of this software or documentation may be
reproduced, stored in a retrieval system, or transmitted in any
form or by any means without the express written consent of
Intel Corporation.
Module Name:
ConPlatform.c
Abstract:
--*/
#include "ConPlatform.h"
EFI_DRIVER_BINDING_PROTOCOL gConPlatformTextInDriverBinding = {
ConPlatformTextInDriverBindingSupported,
ConPlatformTextInDriverBindingStart,
ConPlatformDriverBindingStop,
0x10,
NULL,
NULL
};
EFI_DRIVER_BINDING_PROTOCOL gConPlatformTextOutDriverBinding = {
ConPlatformTextOutDriverBindingSupported,
ConPlatformTextOutDriverBindingStart,
ConPlatformDriverBindingStop,
0x10,
NULL,
NULL
};
EFI_DRIVER_ENTRY_POINT (ConPlatformDriverEntry)
EFI_STATUS
ConPlatformDriverEntry (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
/*++
Routine Description:
Arguments:
(Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
Returns:
EFI_STATUS
--*/
{
EFI_STATUS Status;
//
// Install driver binding protocols and component name protocols
//
Status = EfiLibInstallAllDriverProtocols (
ImageHandle,
SystemTable,
&gConPlatformTextOutDriverBinding,
ImageHandle,
&gConPlatformComponentName,
NULL,
NULL
);
if (EFI_ERROR (Status)) {
return Status;
}
return EfiLibInstallAllDriverProtocols (
ImageHandle,
SystemTable,
&gConPlatformTextInDriverBinding,
NULL,
&gConPlatformComponentName,
NULL,
NULL
);
}
STATIC
EFI_STATUS
EFIAPI
ConPlatformTextInDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
/*++
Routine Description:
Supported
Arguments:
(Standard DriverBinding Protocol Supported() function)
Returns:
None
--*/
{
EFI_STATUS Status;
EFI_SIMPLE_TEXT_IN_PROTOCOL *TextIn;
//
// Test to see if this is a physical device by checking to see
// if it has a Device Path Protocol
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiDevicePathProtocolGuid,
NULL,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_TEST_PROTOCOL
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Test to see if this device supports the Simple Input Protocol
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiSimpleTextInProtocolGuid,
(VOID **)&TextIn,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
gBS->CloseProtocol (
ControllerHandle,
&gEfiSimpleTextInProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
return EFI_SUCCESS;
}
STATIC
EFI_STATUS
EFIAPI
ConPlatformTextOutDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
/*++
Routine Description:
Supported
Arguments:
(Standard DriverBinding Protocol Supported() function)
Returns:
None
--*/
{
EFI_STATUS Status;
EFI_SIMPLE_TEXT_OUT_PROTOCOL *TextOut;
//
// Test to see if this is a physical device by checking to see if
// it has a Device Path Protocol
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiDevicePathProtocolGuid,
NULL,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_TEST_PROTOCOL
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Test to see if this device supports the Simple Text Output Protocol
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiSimpleTextOutProtocolGuid,
(VOID **)&TextOut,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
gBS->CloseProtocol (
ControllerHandle,
&gEfiSimpleTextOutProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
return EFI_SUCCESS;
}
STATIC
EFI_STATUS
EFIAPI
ConPlatformTextInDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
/*++
Routine Description:
Arguments:
(Standard DriverBinding Protocol Start() function)
Returns:
--*/
{
EFI_STATUS Status;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
EFI_SIMPLE_TEXT_IN_PROTOCOL *TextIn;
//
// Get the Device Path Protocol so the environment variables can be updated
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiDevicePathProtocolGuid,
(VOID **)&DevicePath,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Open the Simple Input Protocol BY_DRIVER
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiSimpleTextInProtocolGuid,
(VOID **)&TextIn,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Check the device handle, if it is a hot plug device,
// do not put the device path into ConInDev, and install
// gEfiConsoleInDeviceGuid to the device handle directly.
// The policy is, make hot plug device plug in and play immediately.
//
if (IsHotPlugDevice (This->DriverBindingHandle,ControllerHandle)) {
Status = gBS->InstallMultipleProtocolInterfaces (
&ControllerHandle,
&gEfiConsoleInDeviceGuid, NULL,
NULL
);
} else {
//
// Append the device path to the ConInDev environment variable
//
Status = ConPlatformUpdateDeviceVariable (VarConsoleInpDev,DevicePath,TRUE);
//
// If the device path is an instance in the ConIn environment variable,
// then install EfiConsoleInDeviceGuid onto ControllerHandle
//
Status = ConPlatformCheckVariable (VarConsoleInp, DevicePath);
if (!EFI_ERROR (Status)) {
Status = gBS->InstallMultipleProtocolInterfaces (
&ControllerHandle,
&gEfiConsoleInDeviceGuid, NULL,
NULL
);
} else {
gBS->CloseProtocol (
ControllerHandle,
&gEfiSimpleTextInProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
}
}
return EFI_SUCCESS;
}
STATIC
EFI_STATUS
EFIAPI
ConPlatformTextOutDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
/*++
Routine Description:
Arguments:
(Standard DriverBinding Protocol Start() function)
Returns:
--*/
{
EFI_STATUS Status;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
EFI_SIMPLE_TEXT_OUT_PROTOCOL *TextOut;
BOOLEAN NeedClose;
NeedClose = TRUE;
//
// Get the Device Path Protocol so the environment variables can be updated
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiDevicePathProtocolGuid,
(VOID **)&DevicePath,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Open the Simple Text Output Protocol BY_DRIVER
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiSimpleTextOutProtocolGuid,
(VOID **)&TextOut,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Check the device handle, if it is a hot plug device,
// do not put the device path into ConOutDev and StdErrDev,
// and install gEfiConsoleOutDeviceGuid to the device handle directly.
// The policy is, make hot plug device plug in and play immediately.
//
if (IsHotPlugDevice (This->DriverBindingHandle,ControllerHandle)) {
Status = gBS->InstallMultipleProtocolInterfaces (
&ControllerHandle,
&gEfiConsoleOutDeviceGuid, NULL,
NULL
);
} else {
//
// Append the device path to the ConOutDev environment variable
//
Status = ConPlatformUpdateDeviceVariable (
VarConsoleOutDev,
DevicePath,
TRUE
);
//
// Append the device path to the StdErrDev environment variable
//
Status = ConPlatformUpdateDeviceVariable (VarErrorOutDev, DevicePath, TRUE);
//
// If the device path is an instance in the ConOut environment variable,
// then install EfiConsoleOutDeviceGuid onto ControllerHandle
//
Status = ConPlatformCheckVariable (VarConsoleOut, DevicePath);
if (!EFI_ERROR (Status)) {
NeedClose = FALSE;
Status = gBS->InstallMultipleProtocolInterfaces (
&ControllerHandle,
&gEfiConsoleOutDeviceGuid, NULL,
NULL
);
}
//
// If the device path is an instance in the StdErr environment variable,
// then install EfiStandardErrorDeviceGuid onto ControllerHandle
//
Status = ConPlatformCheckVariable (VarErrorOut, DevicePath);
if (!EFI_ERROR (Status)) {
NeedClose = FALSE;
Status = gBS->InstallMultipleProtocolInterfaces (
&ControllerHandle,
&gEfiStandardErrorDeviceGuid, NULL,
NULL
);
}
if (NeedClose) {
gBS->CloseProtocol (
ControllerHandle,
&gEfiSimpleTextOutProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
}
}
return EFI_SUCCESS;
}
STATIC
EFI_STATUS
EFIAPI
ConPlatformDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
)
/*++
Routine Description:
Arguments:
(Standard DriverBinding Protocol Stop() function)
Returns:
None
--*/
{
EFI_STATUS Status;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
//
// hot plug device is not included into the console associated variables,
// so no need to check variable for those hot plug devices.
//
if (!IsHotPlugDevice (This->DriverBindingHandle,ControllerHandle)) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?