]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/DebugPortDxe/DebugPort.c
MdeModulePkg: Fix spelling mistake for occurred
[mirror_edk2.git] / MdeModulePkg / Universal / DebugPortDxe / DebugPort.c
index a63ef84a3040be8cf60024613b0d26cc177674f0..172c1cbca38d8a215ec9e4cb1baf3fa7f643f246 100644 (file)
@@ -4,14 +4,8 @@
   ALL CODE IN THE SERIALIO STACK MUST BE RE-ENTRANT AND CALLABLE FROM\r
   INTERRUPT CONTEXT\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -33,12 +27,11 @@ DEBUGPORT_DEVICE mDebugPortDevice = {
   DEBUGPORT_DEVICE_SIGNATURE,\r
   (EFI_HANDLE) 0,\r
   (EFI_HANDLE) 0,\r
-  (VOID *) NULL,\r
   (EFI_DEVICE_PATH_PROTOCOL *) NULL,\r
   {\r
     DebugPortReset,\r
-    DebugPortRead,\r
     DebugPortWrite,\r
+    DebugPortRead,\r
     DebugPortPoll\r
   },\r
   (EFI_HANDLE) 0,\r
@@ -57,72 +50,52 @@ DEBUGPORT_DEVICE mDebugPortDevice = {
   Records requested settings in DebugPort device structure.\r
 \r
 **/\r
-VOID\r
+EFI_DEVICE_PATH_PROTOCOL *\r
 GetDebugPortVariable (\r
   VOID\r
   )\r
 {\r
   UINTN                     DataSize;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DebugPortVariable;\r
   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
-  EFI_STATUS                Status;\r
 \r
-  DataSize = 0;\r
-\r
-  Status = gRT->GetVariable (\r
-                  (CHAR16 *) EFI_DEBUGPORT_VARIABLE_NAME,\r
-                  &gEfiDebugPortVariableGuid,\r
-                  NULL,\r
-                  &DataSize,\r
-                  mDebugPortDevice.DebugPortVariable\r
-                  );\r
-\r
-  if (Status == EFI_BUFFER_TOO_SMALL) {\r
-    if (mDebugPortDevice.DebugPortVariable != NULL) {\r
-      FreePool (mDebugPortDevice.DebugPortVariable);\r
-    }\r
+  GetVariable2 (EFI_DEBUGPORT_VARIABLE_NAME, &gEfiDebugPortVariableGuid, (VOID **) &DebugPortVariable, &DataSize);\r
+  if (DebugPortVariable == NULL) {\r
+    return NULL;\r
+  }\r
 \r
-    mDebugPortDevice.DebugPortVariable = AllocatePool (DataSize);\r
-    if (mDebugPortDevice.DebugPortVariable != NULL) {\r
-      gRT->GetVariable (\r
-            (CHAR16 *) EFI_DEBUGPORT_VARIABLE_NAME,\r
-            &gEfiDebugPortVariableGuid,\r
-            NULL,\r
-            &DataSize,\r
-            mDebugPortDevice.DebugPortVariable\r
-            );\r
-      DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) mDebugPortDevice.DebugPortVariable;\r
-      while (!IsDevicePathEnd (DevicePath) && !IS_UART_DEVICEPATH (DevicePath)) {\r
-        DevicePath = NextDevicePathNode (DevicePath);\r
-      }\r
+  DevicePath = DebugPortVariable;\r
+  while (!IsDevicePathEnd (DevicePath) && !IS_UART_DEVICEPATH (DevicePath)) {\r
+    DevicePath = NextDevicePathNode (DevicePath);\r
+  }\r
 \r
-      if (IsDevicePathEnd (DevicePath)) {\r
-        FreePool (mDebugPortDevice.DebugPortVariable);\r
-        mDebugPortDevice.DebugPortVariable = NULL;\r
-      } else {\r
-        CopyMem (\r
-          &mDebugPortDevice.BaudRate,\r
-          &((UART_DEVICE_PATH *) DevicePath)->BaudRate,\r
-          sizeof (((UART_DEVICE_PATH *) DevicePath)->BaudRate)\r
-          );\r
-        mDebugPortDevice.ReceiveFifoDepth = DEBUGPORT_UART_DEFAULT_FIFO_DEPTH;\r
-        mDebugPortDevice.Timeout          = DEBUGPORT_UART_DEFAULT_TIMEOUT;\r
-        CopyMem (\r
-          &mDebugPortDevice.Parity,\r
-          &((UART_DEVICE_PATH *) DevicePath)->Parity,\r
-          sizeof (((UART_DEVICE_PATH *) DevicePath)->Parity)\r
-          );\r
-        CopyMem (\r
-          &mDebugPortDevice.DataBits,\r
-          &((UART_DEVICE_PATH *) DevicePath)->DataBits,\r
-          sizeof (((UART_DEVICE_PATH *) DevicePath)->DataBits)\r
-          );\r
-        CopyMem (\r
-          &mDebugPortDevice.StopBits,\r
-          &((UART_DEVICE_PATH *) DevicePath)->StopBits,\r
-          sizeof (((UART_DEVICE_PATH *) DevicePath)->StopBits)\r
-          );\r
-      }\r
-    }\r
+  if (IsDevicePathEnd (DevicePath)) {\r
+    FreePool (DebugPortVariable);\r
+    return NULL;\r
+  } else {\r
+    CopyMem (\r
+      &mDebugPortDevice.BaudRate,\r
+      &((UART_DEVICE_PATH *) DevicePath)->BaudRate,\r
+      sizeof (((UART_DEVICE_PATH *) DevicePath)->BaudRate)\r
+      );\r
+    mDebugPortDevice.ReceiveFifoDepth = DEBUGPORT_UART_DEFAULT_FIFO_DEPTH;\r
+    mDebugPortDevice.Timeout          = DEBUGPORT_UART_DEFAULT_TIMEOUT;\r
+    CopyMem (\r
+      &mDebugPortDevice.Parity,\r
+      &((UART_DEVICE_PATH *) DevicePath)->Parity,\r
+      sizeof (((UART_DEVICE_PATH *) DevicePath)->Parity)\r
+      );\r
+    CopyMem (\r
+      &mDebugPortDevice.DataBits,\r
+      &((UART_DEVICE_PATH *) DevicePath)->DataBits,\r
+      sizeof (((UART_DEVICE_PATH *) DevicePath)->DataBits)\r
+      );\r
+    CopyMem (\r
+      &mDebugPortDevice.StopBits,\r
+      &((UART_DEVICE_PATH *) DevicePath)->StopBits,\r
+      sizeof (((UART_DEVICE_PATH *) DevicePath)->StopBits)\r
+      );\r
+    return DebugPortVariable;\r
   }\r
 }\r
 \r
@@ -163,7 +136,7 @@ InitializeDebugPortDriver (
              );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  return EFI_SUCCESS;\r
+  return Status;\r
 }\r
 \r
 /**\r
@@ -196,8 +169,8 @@ DebugPortSupported (
   )\r
 {\r
   EFI_STATUS                Status;\r
-  EFI_DEVICE_PATH_PROTOCOL  *Dp1;\r
-  EFI_DEVICE_PATH_PROTOCOL  *Dp2;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DebugPortVariable;\r
   EFI_SERIAL_IO_PROTOCOL    *SerialIo;\r
   EFI_DEBUGPORT_PROTOCOL    *DebugPortInterface;\r
   EFI_HANDLE                TempHandle;\r
@@ -212,25 +185,19 @@ DebugPortSupported (
   //\r
   // Read DebugPort variable to determine debug port selection and parameters\r
   //\r
-  GetDebugPortVariable ();\r
+  DebugPortVariable = GetDebugPortVariable ();\r
 \r
-  if (mDebugPortDevice.DebugPortVariable != NULL) {\r
+  if (DebugPortVariable != NULL) {\r
     //\r
     // There's a DEBUGPORT variable, so do LocateDevicePath and check to see if\r
     // the closest matching handle matches the controller handle, and if it does,\r
     // check to see that the remaining device path has the DebugPort GUIDed messaging\r
     // device path only.  Otherwise, it's a mismatch and EFI_UNSUPPORTED is returned.\r
     //\r
-    Dp1 = DuplicateDevicePath ((EFI_DEVICE_PATH_PROTOCOL *) mDebugPortDevice.DebugPortVariable);\r
-    if (Dp1 == NULL) {\r
-      return EFI_OUT_OF_RESOURCES;\r
-    }\r
-\r
-    Dp2 = Dp1;\r
-\r
+    DevicePath = DebugPortVariable;\r
     Status = gBS->LocateDevicePath (\r
                     &gEfiSerialIoProtocolGuid,\r
-                    &Dp2,\r
+                    &DevicePath,\r
                     &TempHandle\r
                     );\r
 \r
@@ -239,18 +206,18 @@ DebugPortSupported (
     }\r
 \r
     if (Status == EFI_SUCCESS &&\r
-        (Dp2->Type != MESSAGING_DEVICE_PATH ||\r
-         Dp2->SubType != MSG_VENDOR_DP ||\r
-         *((UINT16 *) Dp2->Length) != sizeof (DEBUGPORT_DEVICE_PATH))) {\r
+        (DevicePath->Type != MESSAGING_DEVICE_PATH ||\r
+         DevicePath->SubType != MSG_VENDOR_DP ||\r
+         *((UINT16 *) DevicePath->Length) != sizeof (DEBUGPORT_DEVICE_PATH))) {\r
 \r
       Status = EFI_UNSUPPORTED;\r
     }\r
 \r
-    if (Status == EFI_SUCCESS && !CompareGuid (&gEfiDebugPortDevicePathGuid, (GUID *) (Dp2 + 1))) {\r
+    if (Status == EFI_SUCCESS && !CompareGuid (&gEfiDebugPortDevicePathGuid, (GUID *) (DevicePath + 1))) {\r
       Status = EFI_UNSUPPORTED;\r
     }\r
 \r
-    FreePool (Dp1);\r
+    FreePool (DebugPortVariable);\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
@@ -268,14 +235,14 @@ DebugPortSupported (
     return Status;\r
   }\r
 \r
-  gBS->CloseProtocol (\r
-        ControllerHandle,\r
-        &gEfiSerialIoProtocolGuid,\r
-        This->DriverBindingHandle,\r
-        ControllerHandle\r
-        );\r
+  Status = gBS->CloseProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiSerialIoProtocolGuid,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle\r
+                  );\r
 \r
-  return EFI_SUCCESS;\r
+  return Status;\r
 }\r
 \r
 /**\r
@@ -411,18 +378,6 @@ DebugPortStart (
                   );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    DEBUG_CODE_BEGIN ();\r
-      UINTN  BufferSize;\r
-\r
-      BufferSize = 48;\r
-      DebugPortWrite (\r
-        &mDebugPortDevice.DebugPortInterface,\r
-        0,\r
-        &BufferSize,\r
-        "DebugPort driver failed to open child controller\n\n"\r
-        );\r
-    DEBUG_CODE_END ();\r
-\r
     gBS->CloseProtocol (\r
           ControllerHandle,\r
           &gEfiSerialIoProtocolGuid,\r
@@ -432,19 +387,6 @@ DebugPortStart (
     return Status;\r
   }\r
 \r
-  DEBUG_CODE_BEGIN ();\r
-    UINTN                     BufferSize;\r
-\r
-    BufferSize = 38;\r
-    DebugPortWrite (\r
-      &mDebugPortDevice.DebugPortInterface,\r
-      0,\r
-      &BufferSize,\r
-      "Hello World from the DebugPort driver\n\n"\r
-      );\r
-\r
-  DEBUG_CODE_END ();\r
-\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -621,7 +563,7 @@ DebugPortRead (
     LocalBufferSize = *BufferSize - (BufferPtr - (UINT8 *) Buffer);\r
   } while (LocalBufferSize != 0 && Timeout > 0);\r
 \r
-  *BufferSize = (UINTN) (BufferPtr - (UINT8 *) Buffer);\r
+  *BufferSize = (UINTN) BufferPtr - (UINTN) Buffer;\r
 \r
   return Status;\r
 }\r
@@ -690,7 +632,7 @@ DebugPortWrite (
                               the DebugPort interface.\r
   @retval EFI_NOT_READY       There are no characters ready to read from the\r
                               DebugPort interface\r
-  @retval EFI_DEVICE_ERROR    A hardware failure occured... (from SerialIo)\r
+  @retval EFI_DEVICE_ERROR    A hardware failure occurred... (from SerialIo)\r
 \r
 **/\r
 EFI_STATUS\r
@@ -738,16 +680,60 @@ ImageUnloadHandler (
   EFI_HANDLE ImageHandle\r
   )\r
 {\r
+  EFI_STATUS  Status;\r
+  VOID        *ComponentName;\r
+  VOID        *ComponentName2;\r
+\r
   if (mDebugPortDevice.SerialIoBinding != NULL) {\r
     return EFI_ABORTED;\r
   }\r
 \r
   //\r
-  // Clean up allocations\r
+  // Driver is stopped already.\r
   //\r
-  if (mDebugPortDevice.DebugPortVariable != NULL) {\r
-    FreePool (mDebugPortDevice.DebugPortVariable);\r
+  Status = gBS->HandleProtocol (ImageHandle, &gEfiComponentNameProtocolGuid, &ComponentName);\r
+  if (EFI_ERROR (Status)) {\r
+    ComponentName = NULL;\r
   }\r
 \r
-  return EFI_SUCCESS;\r
+  Status = gBS->HandleProtocol (ImageHandle, &gEfiComponentName2ProtocolGuid, &ComponentName2);\r
+  if (EFI_ERROR (Status)) {\r
+    ComponentName2 = NULL;\r
+  }\r
+\r
+  if (ComponentName == NULL) {\r
+    if (ComponentName2 == NULL) {\r
+      Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                      ImageHandle,\r
+                      &gEfiDriverBindingProtocolGuid,  &gDebugPortDriverBinding,\r
+                      NULL\r
+                      );\r
+    } else {\r
+      Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                      ImageHandle,\r
+                      &gEfiDriverBindingProtocolGuid,  &gDebugPortDriverBinding,\r
+                      &gEfiComponentName2ProtocolGuid, ComponentName2,\r
+                      NULL\r
+                      );\r
+    }\r
+  } else {\r
+    if (ComponentName2 == NULL) {\r
+      Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                      ImageHandle,\r
+                      &gEfiDriverBindingProtocolGuid,  &gDebugPortDriverBinding,\r
+                      &gEfiComponentNameProtocolGuid,  ComponentName,\r
+                      NULL\r
+                      );\r
+    } else {\r
+      Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                      ImageHandle,\r
+                      &gEfiDriverBindingProtocolGuid,  &gDebugPortDriverBinding,\r
+                      &gEfiComponentNameProtocolGuid,  ComponentName,\r
+                      &gEfiComponentName2ProtocolGuid, ComponentName2,\r
+                      NULL\r
+                      );\r
+    }\r
+  }\r
+\r
+  return Status;\r
 }\r