2008-04-10 10:49:28 +02:00
|
|
|
/** @file
|
|
|
|
Top level C file for debugport driver. Contains initialization function.
|
|
|
|
This driver layers on top of SerialIo.
|
|
|
|
ALL CODE IN THE SERIALIO STACK MUST BE RE-ENTRANT AND CALLABLE FROM
|
|
|
|
INTERRUPT CONTEXT
|
2007-07-03 16:09:20 +02:00
|
|
|
|
2008-04-10 10:49:28 +02:00
|
|
|
Copyright (c) 2006 - 2008, Intel Corporation. <BR>
|
|
|
|
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
|
2007-07-03 16:09:20 +02:00
|
|
|
|
2008-04-10 10:49:28 +02:00
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
2007-07-03 16:09:20 +02:00
|
|
|
|
2008-04-10 10:49:28 +02:00
|
|
|
**/
|
2007-07-03 16:09:20 +02:00
|
|
|
|
|
|
|
#include "DebugPort.h"
|
|
|
|
|
|
|
|
//
|
2008-11-04 06:35:49 +01:00
|
|
|
// Globals
|
2007-07-03 16:09:20 +02:00
|
|
|
//
|
2008-11-04 06:35:49 +01:00
|
|
|
EFI_DRIVER_BINDING_PROTOCOL gDebugPortDriverBinding = {
|
|
|
|
DebugPortSupported,
|
|
|
|
DebugPortStart,
|
|
|
|
DebugPortStop,
|
|
|
|
DEBUGPORT_DRIVER_VERSION,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
2008-04-10 10:49:28 +02:00
|
|
|
|
2008-11-21 08:13:33 +01:00
|
|
|
DEBUGPORT_DEVICE mDebugPortDevice = {
|
|
|
|
DEBUGPORT_DEVICE_SIGNATURE,
|
|
|
|
(EFI_HANDLE) 0,
|
|
|
|
(EFI_HANDLE) 0,
|
|
|
|
(VOID *) NULL,
|
|
|
|
(EFI_DEVICE_PATH_PROTOCOL *) NULL,
|
|
|
|
{
|
|
|
|
DebugPortReset,
|
2008-12-30 08:10:46 +01:00
|
|
|
DebugPortRead,
|
|
|
|
DebugPortWrite,
|
|
|
|
DebugPortPoll
|
2008-11-21 08:13:33 +01:00
|
|
|
},
|
|
|
|
(EFI_HANDLE) 0,
|
|
|
|
(EFI_SERIAL_IO_PROTOCOL *) NULL,
|
|
|
|
DEBUGPORT_UART_DEFAULT_BAUDRATE,
|
|
|
|
DEBUGPORT_UART_DEFAULT_FIFO_DEPTH,
|
|
|
|
DEBUGPORT_UART_DEFAULT_TIMEOUT,
|
|
|
|
(EFI_PARITY_TYPE) DEBUGPORT_UART_DEFAULT_PARITY,
|
|
|
|
DEBUGPORT_UART_DEFAULT_DATA_BITS,
|
|
|
|
(EFI_STOP_BITS_TYPE) DEBUGPORT_UART_DEFAULT_STOP_BITS
|
|
|
|
};
|
2007-07-03 16:09:20 +02:00
|
|
|
|
2008-11-04 06:35:49 +01:00
|
|
|
/**
|
|
|
|
Local worker function to obtain device path information from DebugPort variable.
|
2007-07-03 16:09:20 +02:00
|
|
|
|
2008-11-04 06:35:49 +01:00
|
|
|
Records requested settings in DebugPort device structure.
|
2007-07-03 16:09:20 +02:00
|
|
|
|
2008-11-04 06:35:49 +01:00
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
GetDebugPortVariable (
|
2008-11-21 08:13:33 +01:00
|
|
|
VOID
|
2008-11-04 06:35:49 +01:00
|
|
|
)
|
2007-07-03 16:09:20 +02:00
|
|
|
{
|
|
|
|
UINTN DataSize;
|
|
|
|
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
DataSize = 0;
|
|
|
|
|
|
|
|
Status = gRT->GetVariable (
|
|
|
|
(CHAR16 *) EFI_DEBUGPORT_VARIABLE_NAME,
|
|
|
|
&gEfiDebugPortVariableGuid,
|
|
|
|
NULL,
|
|
|
|
&DataSize,
|
2008-11-21 08:13:33 +01:00
|
|
|
mDebugPortDevice.DebugPortVariable
|
2007-07-03 16:09:20 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
2008-11-21 08:13:33 +01:00
|
|
|
if (mDebugPortDevice.DebugPortVariable != NULL) {
|
|
|
|
FreePool (mDebugPortDevice.DebugPortVariable);
|
2007-07-03 16:09:20 +02:00
|
|
|
}
|
|
|
|
|
2008-11-21 08:13:33 +01:00
|
|
|
mDebugPortDevice.DebugPortVariable = AllocatePool (DataSize);
|
|
|
|
if (mDebugPortDevice.DebugPortVariable != NULL) {
|
2007-07-03 16:09:20 +02:00
|
|
|
gRT->GetVariable (
|
|
|
|
(CHAR16 *) EFI_DEBUGPORT_VARIABLE_NAME,
|
|
|
|
&gEfiDebugPortVariableGuid,
|
|
|
|
NULL,
|
|
|
|
&DataSize,
|
2008-11-21 08:13:33 +01:00
|
|
|
mDebugPortDevice.DebugPortVariable
|
2007-07-03 16:09:20 +02:00
|
|
|
);
|
2008-11-21 08:13:33 +01:00
|
|
|
DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) mDebugPortDevice.DebugPortVariable;
|
2008-11-11 16:42:40 +01:00
|
|
|
while (!IsDevicePathEnd (DevicePath) && !IS_UART_DEVICEPATH (DevicePath)) {
|
|
|
|
DevicePath = NextDevicePathNode (DevicePath);
|
2007-07-03 16:09:20 +02:00
|
|
|
}
|
|
|
|
|
2008-11-11 16:42:40 +01:00
|
|
|
if (IsDevicePathEnd (DevicePath)) {
|
2008-11-21 08:13:33 +01:00
|
|
|
FreePool (mDebugPortDevice.DebugPortVariable);
|
|
|
|
mDebugPortDevice.DebugPortVariable = NULL;
|
2007-07-03 16:09:20 +02:00
|
|
|
} else {
|
|
|
|
CopyMem (
|
2008-11-21 08:13:33 +01:00
|
|
|
&mDebugPortDevice.BaudRate,
|
2007-07-03 16:09:20 +02:00
|
|
|
&((UART_DEVICE_PATH *) DevicePath)->BaudRate,
|
|
|
|
sizeof (((UART_DEVICE_PATH *) DevicePath)->BaudRate)
|
|
|
|
);
|
2008-11-21 08:13:33 +01:00
|
|
|
mDebugPortDevice.ReceiveFifoDepth = DEBUGPORT_UART_DEFAULT_FIFO_DEPTH;
|
|
|
|
mDebugPortDevice.Timeout = DEBUGPORT_UART_DEFAULT_TIMEOUT;
|
2007-07-03 16:09:20 +02:00
|
|
|
CopyMem (
|
2008-11-21 08:13:33 +01:00
|
|
|
&mDebugPortDevice.Parity,
|
2007-07-03 16:09:20 +02:00
|
|
|
&((UART_DEVICE_PATH *) DevicePath)->Parity,
|
|
|
|
sizeof (((UART_DEVICE_PATH *) DevicePath)->Parity)
|
|
|
|
);
|
|
|
|
CopyMem (
|
2008-11-21 08:13:33 +01:00
|
|
|
&mDebugPortDevice.DataBits,
|
2007-07-03 16:09:20 +02:00
|
|
|
&((UART_DEVICE_PATH *) DevicePath)->DataBits,
|
|
|
|
sizeof (((UART_DEVICE_PATH *) DevicePath)->DataBits)
|
|
|
|
);
|
|
|
|
CopyMem (
|
2008-11-21 08:13:33 +01:00
|
|
|
&mDebugPortDevice.StopBits,
|
2007-07-03 16:09:20 +02:00
|
|
|
&((UART_DEVICE_PATH *) DevicePath)->StopBits,
|
|
|
|
sizeof (((UART_DEVICE_PATH *) DevicePath)->StopBits)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 06:35:49 +01:00
|
|
|
/**
|
2008-12-30 08:10:46 +01:00
|
|
|
Debug Port Driver entry point.
|
2007-07-03 16:09:20 +02:00
|
|
|
|
2008-11-04 06:35:49 +01:00
|
|
|
Reads DebugPort variable to determine what device and settings to use as the
|
|
|
|
debug port. Binds exclusively to SerialIo. Reverts to defaults if no variable
|
|
|
|
is found.
|
2007-07-03 16:09:20 +02:00
|
|
|
|
2008-12-30 08:10:46 +01:00
|
|
|
@param[in] ImageHandle The firmware allocated handle for the EFI image.
|
2008-11-04 06:35:49 +01:00
|
|
|
@param[in] SystemTable A pointer to the EFI System Table.
|
2008-12-30 08:10:46 +01:00
|
|
|
|
2008-11-04 06:35:49 +01:00
|
|
|
@retval EFI_SUCCESS The entry point is executed successfully.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Fails to allocate memory for device.
|
|
|
|
@retval other Some error occurs when executing this entry point.
|
2007-07-03 16:09:20 +02:00
|
|
|
|
2008-11-04 06:35:49 +01:00
|
|
|
**/
|
2007-07-03 16:09:20 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
InitializeDebugPortDriver (
|
|
|
|
IN EFI_HANDLE ImageHandle,
|
|
|
|
IN EFI_SYSTEM_TABLE *SystemTable
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Install driver model protocol(s).
|
|
|
|
//
|
2007-09-30 05:02:26 +02:00
|
|
|
Status = EfiLibInstallDriverBindingComponentName2 (
|
2007-07-03 16:09:20 +02:00
|
|
|
ImageHandle,
|
|
|
|
SystemTable,
|
|
|
|
&gDebugPortDriverBinding,
|
|
|
|
ImageHandle,
|
|
|
|
&gDebugPortComponentName,
|
2007-09-30 05:02:26 +02:00
|
|
|
&gDebugPortComponentName2
|
2007-07-03 16:09:20 +02:00
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-11-04 06:35:49 +01:00
|
|
|
/**
|
2008-12-30 08:10:46 +01:00
|
|
|
Checks to see if there's not already a DebugPort interface somewhere.
|
2008-04-10 10:49:28 +02:00
|
|
|
|
2007-07-03 16:09:20 +02:00
|
|
|
If there's a DEBUGPORT variable, the device path must match exactly. If there's
|
|
|
|
no DEBUGPORT variable, then device path is not checked and does not matter.
|
|
|
|
Checks to see that there's a serial io interface on the controller handle
|
|
|
|
that can be bound BY_DRIVER | EXCLUSIVE.
|
|
|
|
If all these tests succeed, then we return EFI_SUCCESS, else, EFI_UNSUPPORTED
|
|
|
|
or other error returned by OpenProtocol.
|
|
|
|
|
2008-11-04 06:35:49 +01:00
|
|
|
@param This Protocol instance pointer.
|
|
|
|
@param ControllerHandle Handle of device to test.
|
|
|
|
@param RemainingDevicePath Optional parameter use to pick a specific child
|
|
|
|
device to start.
|
2008-04-10 10:49:28 +02:00
|
|
|
|
2008-11-04 06:35:49 +01:00
|
|
|
@retval EFI_SUCCESS This driver supports this device.
|
|
|
|
@retval EFI_UNSUPPORTED Debug Port device is not supported.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Fails to allocate memory for device.
|
|
|
|
@retval others Some error occurs.
|
2008-04-10 10:49:28 +02:00
|
|
|
|
2008-11-04 06:35:49 +01:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
DebugPortSupported (
|
|
|
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
|
|
|
IN EFI_HANDLE ControllerHandle,
|
|
|
|
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
|
|
|
)
|
2007-07-03 16:09:20 +02:00
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_DEVICE_PATH_PROTOCOL *Dp1;
|
|
|
|
EFI_DEVICE_PATH_PROTOCOL *Dp2;
|
|
|
|
EFI_SERIAL_IO_PROTOCOL *SerialIo;
|
|
|
|
EFI_DEBUGPORT_PROTOCOL *DebugPortInterface;
|
|
|
|
EFI_HANDLE TempHandle;
|
|
|
|
|
|
|
|
//
|
2008-12-17 03:17:53 +01:00
|
|
|
// Check to see that there's not a debugport protocol already published,
|
|
|
|
// since only one standard UART serial port could be supported by this driver.
|
2007-07-03 16:09:20 +02:00
|
|
|
//
|
|
|
|
if (gBS->LocateProtocol (&gEfiDebugPortProtocolGuid, NULL, (VOID **) &DebugPortInterface) != EFI_NOT_FOUND) {
|
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Read DebugPort variable to determine debug port selection and parameters
|
|
|
|
//
|
2008-11-21 08:13:33 +01:00
|
|
|
GetDebugPortVariable ();
|
2007-07-03 16:09:20 +02:00
|
|
|
|
2008-11-21 08:13:33 +01:00
|
|
|
if (mDebugPortDevice.DebugPortVariable != NULL) {
|
2007-07-03 16:09:20 +02:00
|
|
|
//
|
|
|
|
// There's a DEBUGPORT variable, so do LocateDevicePath and check to see if
|
|
|
|
// the closest matching handle matches the controller handle, and if it does,
|
|
|
|
// check to see that the remaining device path has the DebugPort GUIDed messaging
|
|
|
|
// device path only. Otherwise, it's a mismatch and EFI_UNSUPPORTED is returned.
|
|
|
|
//
|
2008-11-21 08:13:33 +01:00
|
|
|
Dp1 = DuplicateDevicePath ((EFI_DEVICE_PATH_PROTOCOL *) mDebugPortDevice.DebugPortVariable);
|
2007-07-03 16:09:20 +02:00
|
|
|
if (Dp1 == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
Dp2 = Dp1;
|
|
|
|
|
|
|
|
Status = gBS->LocateDevicePath (
|
|
|
|
&gEfiSerialIoProtocolGuid,
|
|
|
|
&Dp2,
|
|
|
|
&TempHandle
|
|
|
|
);
|
|
|
|
|
|
|
|
if (Status == EFI_SUCCESS && TempHandle != ControllerHandle) {
|
|
|
|
Status = EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
2008-12-30 08:10:46 +01:00
|
|
|
if (Status == EFI_SUCCESS &&
|
2008-11-21 08:13:33 +01:00
|
|
|
(Dp2->Type != MESSAGING_DEVICE_PATH ||
|
2008-12-30 08:10:46 +01:00
|
|
|
Dp2->SubType != MSG_VENDOR_DP ||
|
2008-11-21 10:48:41 +01:00
|
|
|
*((UINT16 *) Dp2->Length) != sizeof (DEBUGPORT_DEVICE_PATH))) {
|
2008-11-21 08:13:33 +01:00
|
|
|
|
2007-07-03 16:09:20 +02:00
|
|
|
Status = EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
2008-12-30 08:10:46 +01:00
|
|
|
if (Status == EFI_SUCCESS && !CompareGuid (&gEfiDebugPortDevicePathGuid, (GUID *) (Dp2 + 1))) {
|
2007-07-03 16:09:20 +02:00
|
|
|
Status = EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
FreePool (Dp1);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
ControllerHandle,
|
|
|
|
&gEfiSerialIoProtocolGuid,
|
|
|
|
(VOID **) &SerialIo,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
ControllerHandle,
|
|
|
|
EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
gBS->CloseProtocol (
|
|
|
|
ControllerHandle,
|
|
|
|
&gEfiSerialIoProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
ControllerHandle
|
|
|
|
);
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-11-04 06:35:49 +01:00
|
|
|
/**
|
|
|
|
Binds exclusively to serial io on the controller handle, Produces DebugPort
|
|
|
|
protocol and DevicePath on new handle.
|
|
|
|
|
|
|
|
@param This Protocol instance pointer.
|
|
|
|
@param ControllerHandle Handle of device to bind driver to.
|
|
|
|
@param RemainingDevicePath Optional parameter use to pick a specific child
|
|
|
|
device to start.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS This driver is added to ControllerHandle.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Fails to allocate memory for device.
|
2008-12-30 08:10:46 +01:00
|
|
|
@retval others Some error occurs.
|
2008-11-04 06:35:49 +01:00
|
|
|
|
|
|
|
**/
|
2007-07-03 16:09:20 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
DebugPortStart (
|
|
|
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
|
|
|
IN EFI_HANDLE ControllerHandle,
|
|
|
|
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
DEBUGPORT_DEVICE_PATH DebugPortDP;
|
|
|
|
EFI_DEVICE_PATH_PROTOCOL EndDP;
|
|
|
|
EFI_DEVICE_PATH_PROTOCOL *Dp1;
|
|
|
|
|
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
ControllerHandle,
|
|
|
|
&gEfiSerialIoProtocolGuid,
|
2008-11-21 08:13:33 +01:00
|
|
|
(VOID **) &mDebugPortDevice.SerialIoBinding,
|
2007-07-03 16:09:20 +02:00
|
|
|
This->DriverBindingHandle,
|
|
|
|
ControllerHandle,
|
|
|
|
EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-11-21 08:13:33 +01:00
|
|
|
mDebugPortDevice.SerialIoDeviceHandle = ControllerHandle;
|
2007-07-03 16:09:20 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Initialize the Serial Io interface...
|
|
|
|
//
|
2008-11-21 08:13:33 +01:00
|
|
|
Status = mDebugPortDevice.SerialIoBinding->SetAttributes (
|
|
|
|
mDebugPortDevice.SerialIoBinding,
|
|
|
|
mDebugPortDevice.BaudRate,
|
|
|
|
mDebugPortDevice.ReceiveFifoDepth,
|
|
|
|
mDebugPortDevice.Timeout,
|
|
|
|
mDebugPortDevice.Parity,
|
|
|
|
mDebugPortDevice.DataBits,
|
|
|
|
mDebugPortDevice.StopBits
|
2007-07-03 16:09:20 +02:00
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
2008-11-21 08:13:33 +01:00
|
|
|
mDebugPortDevice.BaudRate = 0;
|
|
|
|
mDebugPortDevice.Parity = DefaultParity;
|
|
|
|
mDebugPortDevice.DataBits = 0;
|
|
|
|
mDebugPortDevice.StopBits = DefaultStopBits;
|
|
|
|
mDebugPortDevice.ReceiveFifoDepth = 0;
|
|
|
|
Status = mDebugPortDevice.SerialIoBinding->SetAttributes (
|
|
|
|
mDebugPortDevice.SerialIoBinding,
|
|
|
|
mDebugPortDevice.BaudRate,
|
|
|
|
mDebugPortDevice.ReceiveFifoDepth,
|
|
|
|
mDebugPortDevice.Timeout,
|
|
|
|
mDebugPortDevice.Parity,
|
|
|
|
mDebugPortDevice.DataBits,
|
|
|
|
mDebugPortDevice.StopBits
|
2007-07-03 16:09:20 +02:00
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
gBS->CloseProtocol (
|
|
|
|
ControllerHandle,
|
|
|
|
&gEfiSerialIoProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
ControllerHandle
|
|
|
|
);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-21 08:13:33 +01:00
|
|
|
mDebugPortDevice.SerialIoBinding->Reset (mDebugPortDevice.SerialIoBinding);
|
2007-07-03 16:09:20 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Create device path instance for DebugPort
|
|
|
|
//
|
|
|
|
DebugPortDP.Header.Type = MESSAGING_DEVICE_PATH;
|
|
|
|
DebugPortDP.Header.SubType = MSG_VENDOR_DP;
|
|
|
|
SetDevicePathNodeLength (&(DebugPortDP.Header), sizeof (DebugPortDP));
|
2008-12-30 08:10:46 +01:00
|
|
|
CopyGuid (&DebugPortDP.Guid, &gEfiDebugPortDevicePathGuid);
|
2007-07-03 16:09:20 +02:00
|
|
|
|
|
|
|
Dp1 = DevicePathFromHandle (ControllerHandle);
|
|
|
|
if (Dp1 == NULL) {
|
|
|
|
Dp1 = &EndDP;
|
|
|
|
SetDevicePathEndNode (Dp1);
|
|
|
|
}
|
|
|
|
|
2008-11-21 08:13:33 +01:00
|
|
|
mDebugPortDevice.DebugPortDevicePath = AppendDevicePathNode (Dp1, (EFI_DEVICE_PATH_PROTOCOL *) &DebugPortDP);
|
|
|
|
if (mDebugPortDevice.DebugPortDevicePath == NULL) {
|
2007-07-03 16:09:20 +02:00
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Publish DebugPort and Device Path protocols
|
|
|
|
//
|
|
|
|
Status = gBS->InstallMultipleProtocolInterfaces (
|
2008-11-21 08:13:33 +01:00
|
|
|
&mDebugPortDevice.DebugPortDeviceHandle,
|
2007-07-03 16:09:20 +02:00
|
|
|
&gEfiDevicePathProtocolGuid,
|
2008-11-21 08:13:33 +01:00
|
|
|
mDebugPortDevice.DebugPortDevicePath,
|
2007-07-03 16:09:20 +02:00
|
|
|
&gEfiDebugPortProtocolGuid,
|
2008-11-21 08:13:33 +01:00
|
|
|
&mDebugPortDevice.DebugPortInterface,
|
2007-07-03 16:09:20 +02:00
|
|
|
NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
gBS->CloseProtocol (
|
|
|
|
ControllerHandle,
|
|
|
|
&gEfiSerialIoProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
ControllerHandle
|
|
|
|
);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Connect debugport child to serial io
|
|
|
|
//
|
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
ControllerHandle,
|
|
|
|
&gEfiSerialIoProtocolGuid,
|
2008-11-21 08:13:33 +01:00
|
|
|
(VOID **) &mDebugPortDevice.SerialIoBinding,
|
2007-07-03 16:09:20 +02:00
|
|
|
This->DriverBindingHandle,
|
2008-11-21 08:13:33 +01:00
|
|
|
mDebugPortDevice.DebugPortDeviceHandle,
|
2007-07-03 16:09:20 +02:00
|
|
|
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG_CODE_BEGIN ();
|
|
|
|
UINTN BufferSize;
|
|
|
|
|
|
|
|
BufferSize = 48;
|
|
|
|
DebugPortWrite (
|
2008-11-21 08:13:33 +01:00
|
|
|
&mDebugPortDevice.DebugPortInterface,
|
2007-07-03 16:09:20 +02:00
|
|
|
0,
|
|
|
|
&BufferSize,
|
|
|
|
"DebugPort driver failed to open child controller\n\n"
|
|
|
|
);
|
|
|
|
DEBUG_CODE_END ();
|
|
|
|
|
|
|
|
gBS->CloseProtocol (
|
|
|
|
ControllerHandle,
|
|
|
|
&gEfiSerialIoProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
ControllerHandle
|
|
|
|
);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG_CODE_BEGIN ();
|
2008-11-21 08:13:33 +01:00
|
|
|
UINTN BufferSize;
|
2007-07-03 16:09:20 +02:00
|
|
|
|
|
|
|
BufferSize = 38;
|
|
|
|
DebugPortWrite (
|
2008-11-21 08:13:33 +01:00
|
|
|
&mDebugPortDevice.DebugPortInterface,
|
2007-07-03 16:09:20 +02:00
|
|
|
0,
|
|
|
|
&BufferSize,
|
|
|
|
"Hello World from the DebugPort driver\n\n"
|
|
|
|
);
|
2008-11-21 08:13:33 +01:00
|
|
|
|
2007-07-03 16:09:20 +02:00
|
|
|
DEBUG_CODE_END ();
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-11-04 06:35:49 +01:00
|
|
|
/**
|
|
|
|
Stop this driver on ControllerHandle by removing Serial IO protocol on
|
|
|
|
the ControllerHandle.
|
|
|
|
|
|
|
|
@param This Protocol instance pointer.
|
|
|
|
@param ControllerHandle Handle of device to stop driver on
|
|
|
|
@param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
|
|
|
|
children is zero stop the entire bus driver.
|
|
|
|
@param ChildHandleBuffer List of Child Handles to Stop.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS This driver is removed ControllerHandle.
|
|
|
|
@retval other This driver was not removed from this device.
|
|
|
|
|
|
|
|
**/
|
2007-07-03 16:09:20 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
DebugPortStop (
|
|
|
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
|
|
|
IN EFI_HANDLE ControllerHandle,
|
|
|
|
IN UINTN NumberOfChildren,
|
|
|
|
IN EFI_HANDLE *ChildHandleBuffer
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
if (NumberOfChildren == 0) {
|
|
|
|
//
|
|
|
|
// Close the bus driver
|
|
|
|
//
|
|
|
|
gBS->CloseProtocol (
|
|
|
|
ControllerHandle,
|
|
|
|
&gEfiSerialIoProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
ControllerHandle
|
|
|
|
);
|
|
|
|
|
2008-11-21 08:13:33 +01:00
|
|
|
mDebugPortDevice.SerialIoBinding = NULL;
|
2007-07-03 16:09:20 +02:00
|
|
|
|
|
|
|
gBS->CloseProtocol (
|
|
|
|
ControllerHandle,
|
|
|
|
&gEfiDevicePathProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
ControllerHandle
|
|
|
|
);
|
|
|
|
|
2008-11-21 08:13:33 +01:00
|
|
|
FreePool (mDebugPortDevice.DebugPortDevicePath);
|
2007-07-03 16:09:20 +02:00
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// Disconnect SerialIo child handle
|
|
|
|
//
|
|
|
|
Status = gBS->CloseProtocol (
|
2008-11-21 08:13:33 +01:00
|
|
|
mDebugPortDevice.SerialIoDeviceHandle,
|
2007-07-03 16:09:20 +02:00
|
|
|
&gEfiSerialIoProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
2008-11-21 08:13:33 +01:00
|
|
|
mDebugPortDevice.DebugPortDeviceHandle
|
2007-07-03 16:09:20 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Unpublish our protocols (DevicePath, DebugPort)
|
|
|
|
//
|
|
|
|
Status = gBS->UninstallMultipleProtocolInterfaces (
|
2008-11-21 08:13:33 +01:00
|
|
|
mDebugPortDevice.DebugPortDeviceHandle,
|
2007-07-03 16:09:20 +02:00
|
|
|
&gEfiDevicePathProtocolGuid,
|
2008-11-21 08:13:33 +01:00
|
|
|
mDebugPortDevice.DebugPortDevicePath,
|
2007-07-03 16:09:20 +02:00
|
|
|
&gEfiDebugPortProtocolGuid,
|
2008-11-21 08:13:33 +01:00
|
|
|
&mDebugPortDevice.DebugPortInterface,
|
2007-07-03 16:09:20 +02:00
|
|
|
NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
gBS->OpenProtocol (
|
|
|
|
ControllerHandle,
|
|
|
|
&gEfiSerialIoProtocolGuid,
|
2008-11-21 08:13:33 +01:00
|
|
|
(VOID **) &mDebugPortDevice.SerialIoBinding,
|
2007-07-03 16:09:20 +02:00
|
|
|
This->DriverBindingHandle,
|
2008-11-21 08:13:33 +01:00
|
|
|
mDebugPortDevice.DebugPortDeviceHandle,
|
2007-07-03 16:09:20 +02:00
|
|
|
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
|
|
|
|
);
|
|
|
|
} else {
|
2008-11-21 08:13:33 +01:00
|
|
|
mDebugPortDevice.DebugPortDeviceHandle = NULL;
|
2007-07-03 16:09:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-11-04 06:35:49 +01:00
|
|
|
/**
|
2007-07-03 16:09:20 +02:00
|
|
|
DebugPort protocol member function. Calls SerialIo:GetControl to flush buffer.
|
|
|
|
We cannot call SerialIo:SetAttributes because it uses pool services, which use
|
|
|
|
locks, which affect TPL, so it's not interrupt context safe or re-entrant.
|
|
|
|
SerialIo:Reset() calls SetAttributes, so it can't be used either.
|
2008-04-10 10:49:28 +02:00
|
|
|
|
|
|
|
The port itself should be fine since it was set up during initialization.
|
|
|
|
|
2008-12-30 08:10:46 +01:00
|
|
|
@param This Protocol instance pointer.
|
2007-07-03 16:09:20 +02:00
|
|
|
|
2008-11-04 06:35:49 +01:00
|
|
|
@return EFI_SUCCESS Always.
|
2007-07-03 16:09:20 +02:00
|
|
|
|
2008-12-30 08:10:46 +01:00
|
|
|
**/
|
2008-11-04 06:35:49 +01:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
DebugPortReset (
|
|
|
|
IN EFI_DEBUGPORT_PROTOCOL *This
|
|
|
|
)
|
2007-07-03 16:09:20 +02:00
|
|
|
{
|
|
|
|
UINTN BufferSize;
|
|
|
|
UINTN BitBucket;
|
|
|
|
|
|
|
|
while (This->Poll (This) == EFI_SUCCESS) {
|
|
|
|
BufferSize = 1;
|
|
|
|
This->Read (This, 0, &BufferSize, &BitBucket);
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-11-04 06:35:49 +01:00
|
|
|
/**
|
|
|
|
DebugPort protocol member function. Calls SerialIo:Read() after setting
|
|
|
|
if it's different than the last SerialIo access.
|
|
|
|
|
|
|
|
@param This Pointer to DebugPort protocol.
|
|
|
|
@param Timeout Timeout value.
|
|
|
|
@param BufferSize On input, the size of Buffer.
|
|
|
|
On output, the amount of data actually written.
|
|
|
|
@param Buffer Pointer to buffer to read.
|
|
|
|
|
2008-12-30 08:10:46 +01:00
|
|
|
@retval EFI_SUCCESS
|
|
|
|
@retval others
|
2008-11-04 06:35:49 +01:00
|
|
|
|
|
|
|
**/
|
2007-07-03 16:09:20 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
DebugPortRead (
|
|
|
|
IN EFI_DEBUGPORT_PROTOCOL *This,
|
|
|
|
IN UINT32 Timeout,
|
|
|
|
IN OUT UINTN *BufferSize,
|
|
|
|
IN VOID *Buffer
|
|
|
|
)
|
|
|
|
{
|
|
|
|
DEBUGPORT_DEVICE *DebugPortDevice;
|
|
|
|
UINTN LocalBufferSize;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT8 *BufferPtr;
|
|
|
|
|
|
|
|
DebugPortDevice = DEBUGPORT_DEVICE_FROM_THIS (This);
|
|
|
|
BufferPtr = Buffer;
|
|
|
|
LocalBufferSize = *BufferSize;
|
2008-11-21 08:13:33 +01:00
|
|
|
|
2007-07-03 16:09:20 +02:00
|
|
|
do {
|
|
|
|
Status = DebugPortDevice->SerialIoBinding->Read (
|
|
|
|
DebugPortDevice->SerialIoBinding,
|
|
|
|
&LocalBufferSize,
|
|
|
|
BufferPtr
|
|
|
|
);
|
|
|
|
if (Status == EFI_TIMEOUT) {
|
|
|
|
if (Timeout > DEBUGPORT_UART_DEFAULT_TIMEOUT) {
|
|
|
|
Timeout -= DEBUGPORT_UART_DEFAULT_TIMEOUT;
|
|
|
|
} else {
|
|
|
|
Timeout = 0;
|
|
|
|
}
|
|
|
|
} else if (EFI_ERROR (Status)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
BufferPtr += LocalBufferSize;
|
|
|
|
LocalBufferSize = *BufferSize - (BufferPtr - (UINT8 *) Buffer);
|
|
|
|
} while (LocalBufferSize != 0 && Timeout > 0);
|
|
|
|
|
|
|
|
*BufferSize = (UINTN) (BufferPtr - (UINT8 *) Buffer);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-11-04 06:35:49 +01:00
|
|
|
/**
|
|
|
|
DebugPort protocol member function. Calls SerialIo:Write() Writes 8 bytes at
|
|
|
|
a time and does a GetControl between 8 byte writes to help insure reads are
|
|
|
|
interspersed This is poor-man's flow control.
|
|
|
|
|
|
|
|
@param This Pointer to DebugPort protocol.
|
|
|
|
@param Timeout Timeout value.
|
|
|
|
@param BufferSize On input, the size of Buffer.
|
|
|
|
On output, the amount of data actually written.
|
|
|
|
@param Buffer Pointer to buffer to read.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The data was written.
|
|
|
|
@retval others Fails when writting datas to debug port device.
|
|
|
|
|
|
|
|
**/
|
2007-07-03 16:09:20 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
DebugPortWrite (
|
|
|
|
IN EFI_DEBUGPORT_PROTOCOL *This,
|
|
|
|
IN UINT32 Timeout,
|
|
|
|
IN OUT UINTN *BufferSize,
|
|
|
|
OUT VOID *Buffer
|
|
|
|
)
|
|
|
|
{
|
|
|
|
DEBUGPORT_DEVICE *DebugPortDevice;
|
|
|
|
UINTN Position;
|
|
|
|
UINTN WriteSize;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT32 SerialControl;
|
|
|
|
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
DebugPortDevice = DEBUGPORT_DEVICE_FROM_THIS (This);
|
|
|
|
|
|
|
|
WriteSize = 8;
|
|
|
|
for (Position = 0; Position < *BufferSize && !EFI_ERROR (Status); Position += WriteSize) {
|
|
|
|
DebugPortDevice->SerialIoBinding->GetControl (
|
|
|
|
DebugPortDevice->SerialIoBinding,
|
|
|
|
&SerialControl
|
|
|
|
);
|
|
|
|
if (*BufferSize - Position < 8) {
|
|
|
|
WriteSize = *BufferSize - Position;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = DebugPortDevice->SerialIoBinding->Write (
|
|
|
|
DebugPortDevice->SerialIoBinding,
|
|
|
|
&WriteSize,
|
|
|
|
&((UINT8 *) Buffer)[Position]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
*BufferSize = Position;
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-11-04 06:35:49 +01:00
|
|
|
/**
|
2007-07-03 16:09:20 +02:00
|
|
|
DebugPort protocol member function. Calls SerialIo:Write() after setting
|
|
|
|
if it's different than the last SerialIo access.
|
2008-04-10 10:49:28 +02:00
|
|
|
|
2008-11-04 06:35:49 +01:00
|
|
|
@param This Pointer to DebugPort protocol.
|
2007-07-03 16:09:20 +02:00
|
|
|
|
2008-11-04 06:35:49 +01:00
|
|
|
@retval EFI_SUCCESS At least 1 character is ready to be read from
|
|
|
|
the DebugPort interface.
|
|
|
|
@retval EFI_NOT_READY There are no characters ready to read from the
|
|
|
|
DebugPort interface
|
|
|
|
@retval EFI_DEVICE_ERROR A hardware failure occured... (from SerialIo)
|
2007-07-03 16:09:20 +02:00
|
|
|
|
2008-12-30 08:10:46 +01:00
|
|
|
**/
|
2008-11-04 06:35:49 +01:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
DebugPortPoll (
|
|
|
|
IN EFI_DEBUGPORT_PROTOCOL *This
|
|
|
|
)
|
2007-07-03 16:09:20 +02:00
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT32 SerialControl;
|
|
|
|
DEBUGPORT_DEVICE *DebugPortDevice;
|
|
|
|
|
|
|
|
DebugPortDevice = DEBUGPORT_DEVICE_FROM_THIS (This);
|
|
|
|
|
|
|
|
Status = DebugPortDevice->SerialIoBinding->GetControl (
|
|
|
|
DebugPortDevice->SerialIoBinding,
|
|
|
|
&SerialControl
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!EFI_ERROR (Status)) {
|
2008-11-04 06:35:49 +01:00
|
|
|
if ((SerialControl & EFI_SERIAL_INPUT_BUFFER_EMPTY) != 0) {
|
2007-07-03 16:09:20 +02:00
|
|
|
Status = EFI_NOT_READY;
|
|
|
|
} else {
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-11-04 06:35:49 +01:00
|
|
|
/**
|
2007-07-03 16:09:20 +02:00
|
|
|
Unload function that is registered in the LoadImage protocol. It un-installs
|
|
|
|
protocols produced and deallocates pool used by the driver. Called by the core
|
|
|
|
when unloading the driver.
|
2008-04-10 10:49:28 +02:00
|
|
|
|
2008-11-04 06:35:49 +01:00
|
|
|
@param ImageHandle
|
2007-07-03 16:09:20 +02:00
|
|
|
|
2008-11-04 06:35:49 +01:00
|
|
|
@retval EFI_SUCCESS Unload Debug Port driver successfully.
|
|
|
|
@retval EFI_ABORTED Serial IO is still binding.
|
2007-07-03 16:09:20 +02:00
|
|
|
|
2008-11-04 06:35:49 +01:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
ImageUnloadHandler (
|
|
|
|
EFI_HANDLE ImageHandle
|
|
|
|
)
|
2007-07-03 16:09:20 +02:00
|
|
|
{
|
2008-11-21 08:13:33 +01:00
|
|
|
if (mDebugPortDevice.SerialIoBinding != NULL) {
|
2007-07-03 16:09:20 +02:00
|
|
|
return EFI_ABORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Clean up allocations
|
|
|
|
//
|
2008-11-21 08:13:33 +01:00
|
|
|
if (mDebugPortDevice.DebugPortVariable != NULL) {
|
|
|
|
FreePool (mDebugPortDevice.DebugPortVariable);
|
2007-07-03 16:09:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|