public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] MdeModulePkg/PciSioSerial: Fix a bug that wrongly produces 2 UARTs
@ 2016-11-08  2:35 Ruiyu Ni
  2016-11-08  8:41 ` Zeng, Star
  0 siblings, 1 reply; 2+ messages in thread
From: Ruiyu Ni @ 2016-11-08  2:35 UTC (permalink / raw)
  To: edk2-devel; +Cc: Star Zeng, Eric Dong

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>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
---
 MdeModulePkg/Bus/Pci/PciSioSerialDxe/Serial.c | 120 ++++++++++++++------------
 1 file changed, 64 insertions(+), 56 deletions(-)

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

 
   if (RemainingDevicePath != NULL) {
     Uart = (UART_DEVICE_PATH *) SkipControllerDevicePathNode (RemainingDevicePath, &ContainsControllerNode, &ControllerNumber);
-- 
2.9.0.windows.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] MdeModulePkg/PciSioSerial: Fix a bug that wrongly produces 2 UARTs
  2016-11-08  2:35 [PATCH] MdeModulePkg/PciSioSerial: Fix a bug that wrongly produces 2 UARTs Ruiyu Ni
@ 2016-11-08  8:41 ` Zeng, Star
  0 siblings, 0 replies; 2+ messages in thread
From: Zeng, Star @ 2016-11-08  8:41 UTC (permalink / raw)
  To: Ni, Ruiyu, edk2-devel@lists.01.org; +Cc: Dong, Eric, Zeng, Star

Reviewed-by: Star Zeng <star.zeng@intel.com>

-----Original Message-----
From: Ni, Ruiyu 
Sent: Tuesday, November 8, 2016 10:36 AM
To: edk2-devel@lists.01.org
Cc: Zeng, Star <star.zeng@intel.com>; Dong, Eric <eric.dong@intel.com>
Subject: [PATCH] MdeModulePkg/PciSioSerial: Fix a bug that wrongly produces 2 UARTs

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>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
---
 MdeModulePkg/Bus/Pci/PciSioSerialDxe/Serial.c | 120 ++++++++++++++------------
 1 file changed, 64 insertions(+), 56 deletions(-)

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

 
   if (RemainingDevicePath != NULL) {
     Uart = (UART_DEVICE_PATH *) SkipControllerDevicePathNode (RemainingDevicePath, &ContainsControllerNode, &ControllerNumber);
--
2.9.0.windows.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-11-08  8:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-08  2:35 [PATCH] MdeModulePkg/PciSioSerial: Fix a bug that wrongly produces 2 UARTs Ruiyu Ni
2016-11-08  8:41 ` Zeng, Star

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox