]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/PciSioSerialDxe/Serial.c
MdeModulePkg/PciSioSerial: Fix bad EOL
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / PciSioSerialDxe / Serial.c
index 86e75a43f71961df29cde02a38c76dd60fc81b5d..65ddf5dc2ba70fc7ac3c0f3c21466b3033ce6518 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
@@ -31,8 +31,10 @@ CONTROLLER_DEVICE_PATH mControllerDevicePathTemplate = {
   {\r
     HARDWARE_DEVICE_PATH,\r
     HW_CONTROLLER_DP,\r
-    sizeof (CONTROLLER_DEVICE_PATH),\r
-    0\r
+    {\r
+      (UINT8) (sizeof (CONTROLLER_DEVICE_PATH)),\r
+      (UINT8) ((sizeof (CONTROLLER_DEVICE_PATH)) >> 8)\r
+    }\r
   },\r
   0\r
 };\r
@@ -858,66 +860,76 @@ SerialControllerDriverStart (
     return EFI_SUCCESS;\r
   }\r
 \r
-\r
+  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
-      if ((!SerialDevices[Index]->ContainsControllerNode && !ContainsControllerNode) ||\r
-          (SerialDevices[Index]->ContainsControllerNode && ContainsControllerNode && SerialDevices[Index]->Instance == ControllerNumber)\r
-          ) {\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
+\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 = 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
+          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
@@ -960,6 +972,7 @@ SerialControllerDriverStart (
         // Restore the PCI attributes when all children is destroyed (PciDeviceInfo->ChildCount == 0).\r
         //\r
         PciDeviceInfo = AllocatePool (sizeof (PCI_DEVICE_INFO));\r
+        ASSERT (PciDeviceInfo != NULL);\r
         PciDeviceInfo->ChildCount = 0;\r
         PciDeviceInfo->PciIo = ParentIo.PciIo;\r
         Status = ParentIo.PciIo->Attributes (\r
@@ -977,7 +990,7 @@ SerialControllerDriverStart (
             &Supports\r
             );\r
           if (!EFI_ERROR (Status)) {\r
-            Supports &= EFI_PCI_IO_ATTRIBUTE_IO | EFI_PCI_IO_ATTRIBUTE_MEMORY;\r
+            Supports &= (UINT64)(EFI_PCI_IO_ATTRIBUTE_IO | EFI_PCI_IO_ATTRIBUTE_MEMORY);\r
             Status = ParentIo.PciIo->Attributes (\r
               ParentIo.PciIo,\r
               EfiPciIoAttributeOperationEnable,\r
@@ -990,6 +1003,7 @@ SerialControllerDriverStart (
         //\r
         // Re-use the PciDeviceInfo stored in existing children.\r
         //\r
+        ASSERT ((SerialDevices != NULL) && (SerialDevices[0] != NULL));\r
         PciDeviceInfo = SerialDevices[0]->PciDeviceInfo;\r
         ASSERT (PciDeviceInfo != NULL);\r
       }\r