conplatform.c
来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 861 行 · 第 1/2 页
C
861 行
/*++
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:
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
EFIAPI
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 = INSTALL_ALL_DRIVER_PROTOCOLS (
ImageHandle,
SystemTable,
&gConPlatformTextOutDriverBinding,
ImageHandle,
&gConPlatformComponentName,
NULL,
NULL
);
if (EFI_ERROR (Status)) {
return Status;
}
return INSTALL_ALL_DRIVER_PROTOCOLS (
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
--*/
{
return ConPlatformDriverBindingSupported (
This,
ControllerHandle,
RemainingDevicePath,
&gEfiSimpleTextInProtocolGuid
);
}
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
--*/
{
return ConPlatformDriverBindingSupported (
This,
ControllerHandle,
RemainingDevicePath,
&gEfiSimpleTextOutProtocolGuid
);
}
EFI_STATUS
ConPlatformDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath,
IN EFI_GUID *ProtocolGuid
)
/*++
Routine Description:
Supported
Arguments:
(Standard DriverBinding Protocol Supported() function)
Returns:
None
--*/
{
EFI_STATUS Status;
VOID *Interface;
//
// 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,
ProtocolGuid,
(VOID **) &Interface,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
gBS->CloseProtocol (
ControllerHandle,
ProtocolGuid,
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)) {
gBS->InstallMultipleProtocolInterfaces (
&ControllerHandle,
&gEfiConsoleInDeviceGuid,
NULL,
NULL
);
} else {
//
// Append the device path to the ConInDev environment variable
//
ConPlatformUpdateDeviceVariable (
VarConsoleInpDev,
DevicePath,
APPEND
);
//
// If the device path is an instance in the ConIn environment variable,
// then install EfiConsoleInDeviceGuid onto ControllerHandle
//
Status = ConPlatformUpdateDeviceVariable (
VarConsoleInp,
DevicePath,
CHECK
);
if (!EFI_ERROR (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)) {
gBS->InstallMultipleProtocolInterfaces (
&ControllerHandle,
&gEfiConsoleOutDeviceGuid,
NULL,
NULL
);
} else {
//
// Append the device path to the ConOutDev environment variable
//
ConPlatformUpdateDeviceVariable (
VarConsoleOutDev,
DevicePath,
APPEND
);
//
// Append the device path to the StdErrDev environment variable
//
ConPlatformUpdateDeviceVariable (
VarErrorOutDev,
DevicePath,
APPEND
);
//
// If the device path is an instance in the ConOut environment variable,
// then install EfiConsoleOutDeviceGuid onto ControllerHandle
//
Status = ConPlatformUpdateDeviceVariable (
VarConsoleOut,
DevicePath,
CHECK
);
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 = ConPlatformUpdateDeviceVariable (
VarErrorOut,
DevicePath,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?