diff options
author | Ruiyu Ni <ruiyu.ni@intel.com> | 2014-01-10 03:42:36 +0000 |
---|---|---|
committer | niruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524> | 2014-01-10 03:42:36 +0000 |
commit | 54d5bb7d16536cab30d782825b0d342f4e02ab4c (patch) | |
tree | 9a7e98e87a4b3b3c4cada5f7296a01eae9a98ccd /MdeModulePkg/Universal/DebugPortDxe | |
parent | 554dddfcd938be621514593d2b2d0d86f42579ac (diff) | |
download | edk2-platforms-54d5bb7d16536cab30d782825b0d342f4e02ab4c.tar.xz |
Fix a bug in DebugPort driver's Unload() that leaves the DriverBinding/ComponentName(2) installed.
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15087 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdeModulePkg/Universal/DebugPortDxe')
-rw-r--r-- | MdeModulePkg/Universal/DebugPortDxe/DebugPort.c | 177 | ||||
-rw-r--r-- | MdeModulePkg/Universal/DebugPortDxe/DebugPort.h | 3 |
2 files changed, 98 insertions, 82 deletions
diff --git a/MdeModulePkg/Universal/DebugPortDxe/DebugPort.c b/MdeModulePkg/Universal/DebugPortDxe/DebugPort.c index 2616299df7..984288e302 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, &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;
}
diff --git a/MdeModulePkg/Universal/DebugPortDxe/DebugPort.h b/MdeModulePkg/Universal/DebugPortDxe/DebugPort.h index f108223650..3ce702dfa4 100644 --- a/MdeModulePkg/Universal/DebugPortDxe/DebugPort.h +++ b/MdeModulePkg/Universal/DebugPortDxe/DebugPort.h @@ -1,7 +1,7 @@ /** @file
Definitions and prototypes for DebugPort driver.
-Copyright (c) 2006 - 2011, 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
@@ -52,7 +52,6 @@ typedef struct { UINT32 Signature;
EFI_HANDLE DriverBindingHandle;
EFI_HANDLE DebugPortDeviceHandle;
- VOID *DebugPortVariable;
EFI_DEVICE_PATH_PROTOCOL *DebugPortDevicePath;
EFI_DEBUGPORT_PROTOCOL DebugPortInterface;
|