]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/PciSioSerial: Fix a bug that wrongly produces 2 UARTs
authorRuiyu Ni <ruiyu.ni@intel.com>
Tue, 8 Nov 2016 02:35:22 +0000 (10:35 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Thu, 10 Nov 2016 02:09:13 +0000 (10:09 +0800)
When PciSioSerial is firstly started with a non-NULL remaining
device path, the UART instance is created using the parameters
specified in the remaining device path. Later when the driver
is started again on the same UART controller with NULL remaining
device path, the correct logic is to directly return SUCCESS
instead of current buggy implementation which wrongly produces
another UART using the default parameters.

The bug causes two UARTs are created when the UART is configured
in 57600 baud rate.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
MdeModulePkg/Bus/Pci/PciSioSerialDxe/Serial.c

index aeafee247c9b11c2755b16c161043112739a3019..a48783660e2c87349e0b83451d2f25a635e43509 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Serial driver for PCI or SIO UARTS.\r
 \r
-Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
 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
@@ -863,67 +863,75 @@ SerialControllerDriverStart (
   ControllerNumber = 0;\r
   ContainsControllerNode = FALSE;\r
   SerialDevices = GetChildSerialDevices (Controller, IoProtocolGuid, &SerialDeviceCount);\r
-  //\r
-  // If the SerialIo instance specified by RemainingDevicePath is already created,\r
-  // update the attributes/control.\r
-  //\r
-  if ((SerialDeviceCount != 0) && (RemainingDevicePath != NULL)) {\r
-    Uart = (UART_DEVICE_PATH *) SkipControllerDevicePathNode (RemainingDevicePath, &ContainsControllerNode, &ControllerNumber);\r
-    for (Index = 0; Index < SerialDeviceCount; Index++) {\r
-      ASSERT ((SerialDevices != NULL) && (SerialDevices[Index] != NULL));\r
-      if ((!SerialDevices[Index]->ContainsControllerNode && !ContainsControllerNode) ||\r
-          (SerialDevices[Index]->ContainsControllerNode && ContainsControllerNode && SerialDevices[Index]->Instance == ControllerNumber)\r
-          ) {\r
-        SerialIo = &SerialDevices[Index]->SerialIo;\r
-        Status = EFI_INVALID_PARAMETER;\r
-        //\r
-        // Pass NULL ActualBaudRate to VerifyUartParameters to disallow baudrate degrade.\r
-        // DriverBindingStart() shouldn't create a handle with different UART device path.\r
-        //\r
-        if (VerifyUartParameters (SerialDevices[Index]->ClockRate, Uart->BaudRate, Uart->DataBits,\r
-                                  (EFI_PARITY_TYPE) Uart->Parity, (EFI_STOP_BITS_TYPE) Uart->StopBits, NULL, NULL)) {\r
-          Status = SerialIo->SetAttributes (\r
-                               SerialIo,\r
-                               Uart->BaudRate,\r
-                               SerialIo->Mode->ReceiveFifoDepth,\r
-                               SerialIo->Mode->Timeout,\r
-                               (EFI_PARITY_TYPE) Uart->Parity,\r
-                               Uart->DataBits,\r
-                               (EFI_STOP_BITS_TYPE) Uart->StopBits\r
-                               );\r
-        }\r
-        FlowControl = (UART_FLOW_CONTROL_DEVICE_PATH *) NextDevicePathNode (Uart);\r
-        if (!EFI_ERROR (Status) && IsUartFlowControlDevicePathNode (FlowControl)) {\r
-          Status = SerialIo->GetControl (SerialIo, &Control);\r
-          if (!EFI_ERROR (Status)) {\r
-            if (ReadUnaligned32 (&FlowControl->FlowControlMap) == UART_FLOW_CONTROL_HARDWARE) {\r
-              Control |= EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE;\r
-            } else {\r
-              Control &= ~EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE;\r
+\r
+  if (SerialDeviceCount != 0) {\r
+    if (RemainingDevicePath == NULL) {\r
+      //\r
+      // If the SerialIo instance is already created, NULL as RemainingDevicePath is treated\r
+      // as to create the same SerialIo instance.\r
+      //\r
+      return EFI_SUCCESS;\r
+    } else {\r
+      //\r
+      // Update the attributes/control of the SerialIo instance specified by RemainingDevicePath.\r
+      //\r
+      Uart = (UART_DEVICE_PATH *) SkipControllerDevicePathNode (RemainingDevicePath, &ContainsControllerNode, &ControllerNumber);\r
+      for (Index = 0; Index < SerialDeviceCount; Index++) {\r
+        ASSERT ((SerialDevices != NULL) && (SerialDevices[Index] != NULL));\r
+        if ((!SerialDevices[Index]->ContainsControllerNode && !ContainsControllerNode) ||\r
+            (SerialDevices[Index]->ContainsControllerNode && ContainsControllerNode && SerialDevices[Index]->Instance == ControllerNumber)\r
+            ) {\r
+          SerialIo = &SerialDevices[Index]->SerialIo;\r
+          Status = EFI_INVALID_PARAMETER;\r
+          //\r
+          // Pass NULL ActualBaudRate to VerifyUartParameters to disallow baudrate degrade.\r
+          // DriverBindingStart() shouldn't create a handle with different UART device path.\r
+          //\r
+          if (VerifyUartParameters (SerialDevices[Index]->ClockRate, Uart->BaudRate, Uart->DataBits,\r
+                                    (EFI_PARITY_TYPE) Uart->Parity, (EFI_STOP_BITS_TYPE) Uart->StopBits, NULL, NULL)) {\r
+            Status = SerialIo->SetAttributes (\r
+                                 SerialIo,\r
+                                 Uart->BaudRate,\r
+                                 SerialIo->Mode->ReceiveFifoDepth,\r
+                                 SerialIo->Mode->Timeout,\r
+                                 (EFI_PARITY_TYPE) Uart->Parity,\r
+                                 Uart->DataBits,\r
+                                 (EFI_STOP_BITS_TYPE) Uart->StopBits\r
+                                 );\r
+          }\r
+          FlowControl = (UART_FLOW_CONTROL_DEVICE_PATH *) NextDevicePathNode (Uart);\r
+          if (!EFI_ERROR (Status) && IsUartFlowControlDevicePathNode (FlowControl)) {\r
+            Status = SerialIo->GetControl (SerialIo, &Control);\r
+            if (!EFI_ERROR (Status)) {\r
+              if (ReadUnaligned32 (&FlowControl->FlowControlMap) == UART_FLOW_CONTROL_HARDWARE) {\r
+                Control |= EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE;\r
+              } else {\r
+                Control &= ~EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE;\r
+              }\r
+              //\r
+              // Clear the bits that are not allowed to pass to SetControl\r
+              //\r
+              Control &= (EFI_SERIAL_REQUEST_TO_SEND | EFI_SERIAL_DATA_TERMINAL_READY |\r
+                          EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE | EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE |\r
+                          EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE);\r
+              Status = SerialIo->SetControl (SerialIo, Control);\r
             }\r
-            //\r
-            // Clear the bits that are not allowed to pass to SetControl\r
-            //\r
-            Control &= (EFI_SERIAL_REQUEST_TO_SEND | EFI_SERIAL_DATA_TERMINAL_READY |\r
-                        EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE | EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE |\r
-                        EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE);\r
-            Status = SerialIo->SetControl (SerialIo, Control);\r
           }\r
+          break;\r
         }\r
-        break;\r
       }\r
-    }\r
-    if (Index != SerialDeviceCount) {\r
-      //\r
-      // Directly return if the SerialIo instance specified by RemainingDevicePath is found and updated.\r
-      // Otherwise continue to create the instance specified by RemainingDevicePath.\r
-      //\r
-      if (SerialDevices != NULL) {\r
-        FreePool (SerialDevices);\r
+      if (Index != SerialDeviceCount) {\r
+        //\r
+        // Directly return if the SerialIo instance specified by RemainingDevicePath is found and updated.\r
+        // Otherwise continue to create the instance specified by RemainingDevicePath.\r
+        //\r
+        if (SerialDevices != NULL) {\r
+          FreePool (SerialDevices);\r
+        }\r
+        return Status;\r
       }\r
-      return Status;\r
     }\r
-  }\r
+  }\r\r
 \r
   if (RemainingDevicePath != NULL) {\r
     Uart = (UART_DEVICE_PATH *) SkipControllerDevicePathNode (RemainingDevicePath, &ContainsControllerNode, &ControllerNumber);\r