summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Universal/DebugPortDxe/DebugPort.c
diff options
context:
space:
mode:
Diffstat (limited to 'MdeModulePkg/Universal/DebugPortDxe/DebugPort.c')
-rw-r--r--MdeModulePkg/Universal/DebugPortDxe/DebugPort.c177
1 files changed, 97 insertions, 80 deletions
diff --git a/MdeModulePkg/Universal/DebugPortDxe/DebugPort.c b/MdeModulePkg/Universal/DebugPortDxe/DebugPort.c
index 2616299df..00889a246 100644
--- a/MdeModulePkg/Universal/DebugPortDxe/DebugPort.c
+++ b/MdeModulePkg/Universal/DebugPortDxe/DebugPort.c
@@ -4,7 +4,7 @@
ALL CODE IN THE SERIALIO STACK MUST BE RE-ENTRANT AND CALLABLE FROM
INTERRUPT CONTEXT
-Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
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
@@ -33,7 +33,6 @@ DEBUGPORT_DEVICE mDebugPortDevice = {
DEBUGPORT_DEVICE_SIGNATURE,
(EFI_HANDLE) 0,
(EFI_HANDLE) 0,
- (VOID *) NULL,
(EFI_DEVICE_PATH_PROTOCOL *) NULL,
{
DebugPortReset,
@@ -57,72 +56,52 @@ DEBUGPORT_DEVICE mDebugPortDevice = {
Records requested settings in DebugPort device structure.
**/
-VOID
+EFI_DEVICE_PATH_PROTOCOL *
GetDebugPortVariable (
VOID
)
{
UINTN DataSize;
+ EFI_DEVICE_PATH_PROTOCOL *DebugPortVariable;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
- EFI_STATUS Status;
-
- DataSize = 0;
- Status = gRT->GetVariable (
- (CHAR16 *) EFI_DEBUGPORT_VARIABLE_NAME,
- &gEfiDebugPortVariableGuid,
- NULL,
- &DataSize,
- mDebugPortDevice.DebugPortVariable
- );
-
- if (Status == EFI_BUFFER_TOO_SMALL) {
- if (mDebugPortDevice.DebugPortVariable != NULL) {
- FreePool (mDebugPortDevice.DebugPortVariable);
- }
+ GetVariable2 (EFI_DEBUGPORT_VARIABLE_NAME, &gEfiDebugPortVariableGuid, (VOID **) &DebugPortVariable, &DataSize);
+ if (DebugPortVariable == NULL) {
+ return NULL;
+ }
- mDebugPortDevice.DebugPortVariable = AllocatePool (DataSize);
- if (mDebugPortDevice.DebugPortVariable != NULL) {
- gRT->GetVariable (
- (CHAR16 *) EFI_DEBUGPORT_VARIABLE_NAME,
- &gEfiDebugPortVariableGuid,
- NULL,
- &DataSize,
- mDebugPortDevice.DebugPortVariable
- );
- DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) mDebugPortDevice.DebugPortVariable;
- while (!IsDevicePathEnd (DevicePath) && !IS_UART_DEVICEPATH (DevicePath)) {
- DevicePath = NextDevicePathNode (DevicePath);
- }
+ DevicePath = DebugPortVariable;
+ while (!IsDevicePathEnd (DevicePath) && !IS_UART_DEVICEPATH (DevicePath)) {
+ DevicePath = NextDevicePathNode (DevicePath);
+ }
- if (IsDevicePathEnd (DevicePath)) {
- FreePool (mDebugPortDevice.DebugPortVariable);
- mDebugPortDevice.DebugPortVariable = NULL;
- } else {
- CopyMem (
- &mDebugPortDevice.BaudRate,
- &((UART_DEVICE_PATH *) DevicePath)->BaudRate,
- sizeof (((UART_DEVICE_PATH *) DevicePath)->BaudRate)
- );
- mDebugPortDevice.ReceiveFifoDepth = DEBUGPORT_UART_DEFAULT_FIFO_DEPTH;
- mDebugPortDevice.Timeout = DEBUGPORT_UART_DEFAULT_TIMEOUT;
- CopyMem (
- &mDebugPortDevice.Parity,
- &((UART_DEVICE_PATH *) DevicePath)->Parity,
- sizeof (((UART_DEVICE_PATH *) DevicePath)->Parity)
- );
- CopyMem (
- &mDebugPortDevice.DataBits,
- &((UART_DEVICE_PATH *) DevicePath)->DataBits,
- sizeof (((UART_DEVICE_PATH *) DevicePath)->DataBits)
- );
- CopyMem (
- &mDebugPortDevice.StopBits,
- &((UART_DEVICE_PATH *) DevicePath)->StopBits,
- sizeof (((UART_DEVICE_PATH *) DevicePath)->StopBits)
- );
- }
- }
+ if (IsDevicePathEnd (DevicePath)) {
+ FreePool (DebugPortVariable);
+ return NULL;
+ } else {
+ CopyMem (
+ &mDebugPortDevice.BaudRate,
+ &((UART_DEVICE_PATH *) DevicePath)->BaudRate,
+ sizeof (((UART_DEVICE_PATH *) DevicePath)->BaudRate)
+ );
+ mDebugPortDevice.ReceiveFifoDepth = DEBUGPORT_UART_DEFAULT_FIFO_DEPTH;
+ mDebugPortDevice.Timeout = DEBUGPORT_UART_DEFAULT_TIMEOUT;
+ CopyMem (
+ &mDebugPortDevice.Parity,
+ &((UART_DEVICE_PATH *) DevicePath)->Parity,
+ sizeof (((UART_DEVICE_PATH *) DevicePath)->Parity)
+ );
+ CopyMem (
+ &mDebugPortDevice.DataBits,
+ &((UART_DEVICE_PATH *) DevicePath)->DataBits,
+ sizeof (((UART_DEVICE_PATH *) DevicePath)->DataBits)
+ );
+ CopyMem (
+ &mDebugPortDevice.StopBits,
+ &((UART_DEVICE_PATH *) DevicePath)->StopBits,
+ sizeof (((UART_DEVICE_PATH *) DevicePath)->StopBits)
+ );
+ return DebugPortVariable;
}
}
@@ -196,8 +175,8 @@ DebugPortSupported (
)
{
EFI_STATUS Status;
- EFI_DEVICE_PATH_PROTOCOL *Dp1;
- EFI_DEVICE_PATH_PROTOCOL *Dp2;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ EFI_DEVICE_PATH_PROTOCOL *DebugPortVariable;
EFI_SERIAL_IO_PROTOCOL *SerialIo;
EFI_DEBUGPORT_PROTOCOL *DebugPortInterface;
EFI_HANDLE TempHandle;
@@ -212,25 +191,19 @@ DebugPortSupported (
//
// Read DebugPort variable to determine debug port selection and parameters
//
- GetDebugPortVariable ();
+ DebugPortVariable = GetDebugPortVariable ();
- if (mDebugPortDevice.DebugPortVariable != NULL) {
+ if (DebugPortVariable != NULL) {
//
// 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.
//
- Dp1 = DuplicateDevicePath ((EFI_DEVICE_PATH_PROTOCOL *) mDebugPortDevice.DebugPortVariable);
- if (Dp1 == NULL) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- Dp2 = Dp1;
-
+ DevicePath = DebugPortVariable;
Status = gBS->LocateDevicePath (
&gEfiSerialIoProtocolGuid,
- &Dp2,
+ &DevicePath,
&TempHandle
);
@@ -239,18 +212,18 @@ DebugPortSupported (
}
if (Status == EFI_SUCCESS &&
- (Dp2->Type != MESSAGING_DEVICE_PATH ||
- Dp2->SubType != MSG_VENDOR_DP ||
- *((UINT16 *) Dp2->Length) != sizeof (DEBUGPORT_DEVICE_PATH))) {
+ (DevicePath->Type != MESSAGING_DEVICE_PATH ||
+ DevicePath->SubType != MSG_VENDOR_DP ||
+ *((UINT16 *) DevicePath->Length) != sizeof (DEBUGPORT_DEVICE_PATH))) {
Status = EFI_UNSUPPORTED;
}
- if (Status == EFI_SUCCESS && !CompareGuid (&gEfiDebugPortDevicePathGuid, (GUID *) (Dp2 + 1))) {
+ if (Status == EFI_SUCCESS && !CompareGuid (&gEfiDebugPortDevicePathGuid, (GUID *) (DevicePath + 1))) {
Status = EFI_UNSUPPORTED;
}
- FreePool (Dp1);
+ FreePool (DebugPortVariable);
if (EFI_ERROR (Status)) {
return Status;
}
@@ -713,16 +686,60 @@ ImageUnloadHandler (
EFI_HANDLE ImageHandle
)
{
+ EFI_STATUS Status;
+ VOID *ComponentName;
+ VOID *ComponentName2;
+
if (mDebugPortDevice.SerialIoBinding != NULL) {
return EFI_ABORTED;
}
//
- // Clean up allocations
+ // Driver is stopped already.
//
- if (mDebugPortDevice.DebugPortVariable != NULL) {
- FreePool (mDebugPortDevice.DebugPortVariable);
+ Status = gBS->HandleProtocol (ImageHandle, &gEfiComponentNameProtocolGuid, &ComponentName);
+ if (EFI_ERROR (Status)) {
+ ComponentName = NULL;
}
- return EFI_SUCCESS;
+ Status = gBS->HandleProtocol (ImageHandle, &gEfiComponentName2ProtocolGuid, &ComponentName2);
+ if (EFI_ERROR (Status)) {
+ ComponentName2 = NULL;
+ }
+
+ if (ComponentName == NULL) {
+ if (ComponentName2 == NULL) {
+ Status = gBS->UninstallMultipleProtocolInterfaces (
+ ImageHandle,
+ &gEfiDriverBindingProtocolGuid, &gDebugPortDriverBinding,
+ NULL
+ );
+ } else {
+ Status = gBS->UninstallMultipleProtocolInterfaces (
+ ImageHandle,
+ &gEfiDriverBindingProtocolGuid, &gDebugPortDriverBinding,
+ &gEfiComponentName2ProtocolGuid, ComponentName2,
+ NULL
+ );
+ }
+ } else {
+ if (ComponentName2 == NULL) {
+ Status = gBS->UninstallMultipleProtocolInterfaces (
+ ImageHandle,
+ &gEfiDriverBindingProtocolGuid, &gDebugPortDriverBinding,
+ &gEfiComponentNameProtocolGuid, ComponentName,
+ NULL
+ );
+ } else {
+ Status = gBS->UninstallMultipleProtocolInterfaces (
+ ImageHandle,
+ &gEfiDriverBindingProtocolGuid, &gDebugPortDriverBinding,
+ &gEfiComponentNameProtocolGuid, ComponentName,
+ &gEfiComponentName2ProtocolGuid, ComponentName2,
+ NULL
+ );
+ }
+ }
+
+ return Status;
}