]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Nt32Pkg/WinNtSerialIoDxe/WinNtSerialIo.c
Nt32Pkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / Nt32Pkg / WinNtSerialIoDxe / WinNtSerialIo.c
index ed8ee3c4538e6cfa59a754a1fc0e4907f5c1bc65..96167d572370ef88b60bd72e908bea6538e70e67 100644 (file)
@@ -1,13 +1,7 @@
 /**@file\r
 \r
-Copyright (c) 2006 - 2007, Intel Corporation\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 - 2010, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 Module Name:\r
 \r
@@ -61,6 +55,51 @@ EFI_DRIVER_BINDING_PROTOCOL gWinNtSerialIoDriverBinding = {
 //\r
 UINT64 mBaudRateCurrentSupport[] = {50, 75, 110, 134, 150, 300, 600, 1200, 1800, 2000, 2400, 3600, 4800, 7200, 9600, 19200, 38400, 57600, 115200, SERIAL_PORT_MAX_BAUD_RATE + 1};\r
 \r
+/**\r
+  Check the device path node whether it's the Flow Control node or not.\r
+\r
+  @param[in] FlowControl    The device path node to be checked.\r
+  \r
+  @retval TRUE              It's the Flow Control node.\r
+  @retval FALSE             It's not.\r
+\r
+**/\r
+BOOLEAN\r
+IsUartFlowControlNode (\r
+  IN UART_FLOW_CONTROL_DEVICE_PATH *FlowControl\r
+  )\r
+{\r
+  return (BOOLEAN) (\r
+           (DevicePathType (FlowControl) == MESSAGING_DEVICE_PATH) &&\r
+           (DevicePathSubType (FlowControl) == MSG_VENDOR_DP) &&\r
+           (CompareGuid (&FlowControl->Guid, &gEfiUartDevicePathGuid))\r
+           );\r
+}\r
+\r
+/**\r
+  Check the device path node whether it contains Flow Control node or not.\r
+\r
+  @param[in] DevicePath     The device path to be checked.\r
+  \r
+  @retval TRUE              It contains the Flow Control node.\r
+  @retval FALSE             It doesn't.\r
+\r
+**/\r
+BOOLEAN\r
+ContainsFlowControl (\r
+  IN EFI_DEVICE_PATH_PROTOCOL      *DevicePath\r
+  )\r
+{\r
+  while (!IsDevicePathEnd (DevicePath)) {\r
+    if (IsUartFlowControlNode ((UART_FLOW_CONTROL_DEVICE_PATH *) DevicePath)) {\r
+      return TRUE;\r
+    }\r
+    DevicePath = NextDevicePathNode (DevicePath);\r
+  }\r
+\r
+  return FALSE;\r
+}\r
+\r
 /**\r
   The user Entry Point for module WinNtSerialIo. The user code starts with this function.\r
 \r
@@ -97,7 +136,6 @@ InitializeWinNtSerialIo(
   return Status;\r
 }\r
 \r
-STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 WinNtSerialIoDriverBindingSupported (\r
@@ -122,41 +160,150 @@ Returns:
 // TODO:    EFI_SUCCESS - add return value to function comment\r
 // TODO:    EFI_SUCCESS - add return value to function comment\r
 {\r
-  EFI_STATUS                Status;\r
-  EFI_DEVICE_PATH_PROTOCOL  *ParentDevicePath;\r
-  EFI_WIN_NT_IO_PROTOCOL    *WinNtIo;\r
-  UART_DEVICE_PATH          *UartNode;\r
+  EFI_STATUS                          Status;\r
+  EFI_DEVICE_PATH_PROTOCOL            *ParentDevicePath;\r
+  EFI_WIN_NT_IO_PROTOCOL              *WinNtIo;\r
+  UART_DEVICE_PATH                    *UartNode;\r
+  EFI_DEVICE_PATH_PROTOCOL            *DevicePath;\r
+  UART_FLOW_CONTROL_DEVICE_PATH       *FlowControlNode;\r
+  EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;\r
+  UINTN                               EntryCount;\r
+  UINTN                               Index;\r
+  BOOLEAN                             RemainingDevicePathContainsFlowControl; \r
+\r
+  //\r
+  // Check RemainingDevicePath validation\r
+  //\r
+  if (RemainingDevicePath != NULL) {\r
+    //\r
+    // Check if RemainingDevicePath is the End of Device Path Node, \r
+    // if yes, go on checking other conditions\r
+    //\r
+    if (!IsDevicePathEnd (RemainingDevicePath)) {\r
+      //\r
+      // If RemainingDevicePath isn't the End of Device Path Node,\r
+      // check its validation\r
+      //\r
+      Status = EFI_UNSUPPORTED;\r
+\r
+      UartNode  = (UART_DEVICE_PATH *) RemainingDevicePath;\r
+      if (UartNode->Header.Type != MESSAGING_DEVICE_PATH ||\r
+          UartNode->Header.SubType != MSG_UART_DP ||\r
+          DevicePathNodeLength((EFI_DEVICE_PATH_PROTOCOL *)UartNode) != sizeof(UART_DEVICE_PATH)) {\r
+        goto Error;\r
+      }\r
+      if ( UartNode->BaudRate > SERIAL_PORT_MAX_BAUD_RATE) {\r
+        goto Error;\r
+      }\r
+      if (UartNode->Parity < NoParity || UartNode->Parity > SpaceParity) {\r
+        goto Error;\r
+      }\r
+      if (UartNode->DataBits < 5 || UartNode->DataBits > 8) {\r
+        goto Error;\r
+      }\r
+      if (UartNode->StopBits < OneStopBit || UartNode->StopBits > TwoStopBits) {\r
+        goto Error;\r
+      }\r
+      if ((UartNode->DataBits == 5) && (UartNode->StopBits == TwoStopBits)) {\r
+        goto Error;\r
+      }\r
+      if ((UartNode->DataBits >= 6) && (UartNode->DataBits <= 8) && (UartNode->StopBits == OneFiveStopBits)) {\r
+        goto Error;\r
+      }\r
+\r
+      FlowControlNode = (UART_FLOW_CONTROL_DEVICE_PATH *) NextDevicePathNode (UartNode);\r
+      if (IsUartFlowControlNode (FlowControlNode)) {\r
+        //\r
+        // If the second node is Flow Control Node,\r
+        //   return error when it request other than hardware flow control.\r
+        //\r
+        if ((FlowControlNode->FlowControlMap & ~UART_FLOW_CONTROL_HARDWARE) != 0) {\r
+          goto Error;\r
+        }\r
+      }\r
+    }\r
+  }\r
 \r
   //\r
   // Open the IO Abstraction(s) needed to perform the supported test\r
   //\r
   Status = gBS->OpenProtocol (\r
                   Handle,\r
-                  &gEfiDevicePathProtocolGuid,\r
-                  &ParentDevicePath,\r
+                  &gEfiWinNtIoProtocolGuid,\r
+                  (VOID **) &WinNtIo,\r
                   This->DriverBindingHandle,\r
                   Handle,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
                   );\r
   if (Status == EFI_ALREADY_STARTED) {\r
-    return EFI_SUCCESS;\r
+    if (RemainingDevicePath == NULL || IsDevicePathEnd (RemainingDevicePath)) {\r
+      //\r
+      // If RemainingDevicePath is NULL or is the End of Device Path Node\r
+      //\r
+      return EFI_SUCCESS;\r
+    }\r
+    //\r
+    // When the driver has produced device path with flow control node but RemainingDevicePath only contains UART node,\r
+    //   return unsupported, and vice versa.\r
+    //\r
+    Status = gBS->OpenProtocolInformation (\r
+                    Handle,\r
+                    &gEfiWinNtIoProtocolGuid,\r
+                    &OpenInfoBuffer,\r
+                    &EntryCount\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    //\r
+    // See if RemainingDevicePath has a Flow Control device path node\r
+    //\r
+    RemainingDevicePathContainsFlowControl = ContainsFlowControl (RemainingDevicePath);\r
+    \r
+    for (Index = 0; Index < EntryCount; Index++) {\r
+      if ((OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r
+        Status = gBS->OpenProtocol (\r
+                        OpenInfoBuffer[Index].ControllerHandle,\r
+                        &gEfiDevicePathProtocolGuid,\r
+                        (VOID **) &DevicePath,\r
+                        This->DriverBindingHandle,\r
+                        Handle,\r
+                        EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                        );\r
+        if (!EFI_ERROR (Status)) {\r
+          if (RemainingDevicePathContainsFlowControl ^ ContainsFlowControl (DevicePath)) {\r
+            Status = EFI_UNSUPPORTED;\r
+          }\r
+        }\r
+        break;\r
+      }\r
+    }\r
+    FreePool (OpenInfoBuffer);\r
+    return Status;\r
   }\r
 \r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
 \r
+  //\r
+  // Close the I/O Abstraction(s) used to perform the supported test\r
+  //\r
   gBS->CloseProtocol (\r
         Handle,\r
-        &gEfiDevicePathProtocolGuid,\r
+        &gEfiWinNtIoProtocolGuid,\r
         This->DriverBindingHandle,\r
         Handle\r
         );\r
 \r
+  //\r
+  // Open the EFI Device Path protocol needed to perform the supported test\r
+  //\r
   Status = gBS->OpenProtocol (\r
                   Handle,\r
-                  &gEfiWinNtIoProtocolGuid,\r
-                  &WinNtIo,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **) &ParentDevicePath,\r
                   This->DriverBindingHandle,\r
                   Handle,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
@@ -169,6 +316,16 @@ Returns:
     return Status;\r
   }\r
 \r
+  //\r
+  // Close protocol, don't use device path protocol in the Support() function\r
+  //\r
+  gBS->CloseProtocol (\r
+        Handle,\r
+        &gEfiDevicePathProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        Handle\r
+        );\r
+\r
   //\r
   // Make sure that the WinNt Thunk Protocol is valid\r
   //\r
@@ -185,50 +342,12 @@ Returns:
     goto Error;\r
   }\r
 \r
-  if (RemainingDevicePath != NULL) {\r
-    Status    = EFI_UNSUPPORTED;\r
-    UartNode  = (UART_DEVICE_PATH *) RemainingDevicePath;\r
-    if (UartNode->Header.Type != MESSAGING_DEVICE_PATH ||\r
-        UartNode->Header.SubType != MSG_UART_DP ||\r
-        DevicePathNodeLength((EFI_DEVICE_PATH_PROTOCOL *)UartNode) != sizeof(UART_DEVICE_PATH)) {\r
-      goto Error;\r
-    }\r
-    if (UartNode->BaudRate < 0 || UartNode->BaudRate > SERIAL_PORT_MAX_BAUD_RATE) {\r
-      goto Error;\r
-    }\r
-    if (UartNode->Parity < NoParity || UartNode->Parity > SpaceParity) {\r
-      goto Error;\r
-    }\r
-    if (UartNode->DataBits < 5 || UartNode->DataBits > 8) {\r
-      goto Error;\r
-    }\r
-    if (UartNode->StopBits < OneStopBit || UartNode->StopBits > TwoStopBits) {\r
-      goto Error;\r
-    }\r
-    if ((UartNode->DataBits == 5) && (UartNode->StopBits == TwoStopBits)) {\r
-      goto Error;\r
-    }\r
-    if ((UartNode->DataBits >= 6) && (UartNode->DataBits <= 8) && (UartNode->StopBits == OneFiveStopBits)) {\r
-      goto Error;\r
-    }\r
-    Status = EFI_SUCCESS;\r
-  }\r
+  return EFI_SUCCESS;\r
 \r
 Error:\r
-  //\r
-  // Close the I/O Abstraction(s) used to perform the supported test\r
-  //\r
-  gBS->CloseProtocol (\r
-        Handle,\r
-        &gEfiWinNtIoProtocolGuid,\r
-        This->DriverBindingHandle,\r
-        Handle\r
-        );\r
-\r
   return Status;\r
 }\r
 \r
-STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 WinNtSerialIoDriverBindingStart (\r
@@ -257,23 +376,28 @@ Returns:
   EFI_WIN_NT_IO_PROTOCOL              *WinNtIo;\r
   WIN_NT_SERIAL_IO_PRIVATE_DATA       *Private;\r
   HANDLE                              NtHandle;\r
-  UART_DEVICE_PATH                    Node;\r
+  UART_DEVICE_PATH                    UartNode;\r
   EFI_DEVICE_PATH_PROTOCOL            *ParentDevicePath;\r
   EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;\r
   UINTN                               EntryCount;\r
   UINTN                               Index;\r
   EFI_SERIAL_IO_PROTOCOL              *SerialIo;\r
+  UART_DEVICE_PATH                    *Uart;\r
+  UINT32                              FlowControlMap;\r
+  UART_FLOW_CONTROL_DEVICE_PATH       *FlowControl;\r
+  EFI_DEVICE_PATH_PROTOCOL            *TempDevicePath;\r
+  UINT32                              Control;\r
 \r
   Private   = NULL;\r
   NtHandle  = INVALID_HANDLE_VALUE;\r
 \r
   //\r
-  // Grab the protocols we need\r
+  // Get the Parent Device Path\r
   //\r
   Status = gBS->OpenProtocol (\r
                   Handle,\r
                   &gEfiDevicePathProtocolGuid,\r
-                  &ParentDevicePath,\r
+                  (VOID **) &ParentDevicePath,\r
                   This->DriverBindingHandle,\r
                   Handle,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
@@ -288,7 +412,7 @@ Returns:
   Status = gBS->OpenProtocol (\r
                   Handle,\r
                   &gEfiWinNtIoProtocolGuid,\r
-                  &WinNtIo,\r
+                  (VOID **) &WinNtIo,\r
                   This->DriverBindingHandle,\r
                   Handle,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
@@ -305,7 +429,10 @@ Returns:
 \r
   if (Status == EFI_ALREADY_STARTED) {\r
 \r
-    if (RemainingDevicePath == NULL) {\r
+    if (RemainingDevicePath == NULL || IsDevicePathEnd (RemainingDevicePath)) {\r
+      //\r
+      // If RemainingDevicePath is NULL or is the End of Device Path Node\r
+      //\r
       return EFI_SUCCESS;\r
     }\r
 \r
@@ -325,26 +452,44 @@ Returns:
 \r
     Status = EFI_ALREADY_STARTED;\r
     for (Index = 0; Index < EntryCount; Index++) {\r
-      if (OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) {\r
+      if ((OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r
         Status = gBS->OpenProtocol (\r
                         OpenInfoBuffer[Index].ControllerHandle,\r
                         &gEfiSerialIoProtocolGuid,\r
-                        &SerialIo,\r
+                        (VOID **) &SerialIo,\r
                         This->DriverBindingHandle,\r
                         Handle,\r
                         EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
                         );\r
         if (!EFI_ERROR (Status)) {\r
-          CopyMem (&Node, RemainingDevicePath, sizeof (UART_DEVICE_PATH));\r
+          Uart   = (UART_DEVICE_PATH *) RemainingDevicePath;\r
           Status = SerialIo->SetAttributes (\r
-                              SerialIo,\r
-                              Node.BaudRate,\r
-                              SerialIo->Mode->ReceiveFifoDepth,\r
-                              SerialIo->Mode->Timeout,\r
-                              Node.Parity,\r
-                              Node.DataBits,\r
-                              Node.StopBits\r
-                              );\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
+          FlowControl = (UART_FLOW_CONTROL_DEVICE_PATH *) NextDevicePathNode (Uart);\r
+          if (!EFI_ERROR (Status) && IsUartFlowControlNode (FlowControl)) {\r
+            Status = SerialIo->GetControl (SerialIo, &Control);\r
+            if (!EFI_ERROR (Status)) {\r
+              if (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
         }\r
         break;\r
       }\r
@@ -354,6 +499,45 @@ Returns:
     return Status;\r
   }\r
 \r
+  FlowControl    = NULL;\r
+  FlowControlMap = 0;\r
+  if (RemainingDevicePath == NULL) {\r
+    //\r
+    // Build the device path by appending the UART node to the ParentDevicePath\r
+    // from the WinNtIo handle. The Uart setings are zero here, since\r
+    // SetAttribute() will update them to match the default setings.\r
+    //\r
+    ZeroMem (&UartNode, sizeof (UART_DEVICE_PATH));\r
+    UartNode.Header.Type     = MESSAGING_DEVICE_PATH;\r
+    UartNode.Header.SubType  = MSG_UART_DP;\r
+    SetDevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) &UartNode, sizeof (UART_DEVICE_PATH));\r
+\r
+  } else if (!IsDevicePathEnd (RemainingDevicePath)) {\r
+    //\r
+    // If RemainingDevicePath isn't the End of Device Path Node, \r
+    // only scan the specified device by RemainingDevicePath\r
+    //\r
+    //\r
+    // Match the configuration of the RemainingDevicePath. IsHandleSupported()\r
+    // already checked to make sure the RemainingDevicePath contains settings\r
+    // that we can support.\r
+    //\r
+    CopyMem (&UartNode, RemainingDevicePath, sizeof (UART_DEVICE_PATH));\r
+    FlowControl = (UART_FLOW_CONTROL_DEVICE_PATH *) NextDevicePathNode (RemainingDevicePath);\r
+    if (IsUartFlowControlNode (FlowControl)) {\r
+      FlowControlMap = FlowControl->FlowControlMap;\r
+    } else {\r
+      FlowControl    = NULL;\r
+    }\r
+\r
+  } else {\r
+    //\r
+    // If RemainingDevicePath is the End of Device Path Node,\r
+    // skip enumerate any device and return EFI_SUCESSS\r
+    // \r
+    return EFI_SUCCESS;\r
+  }\r
+\r
   //\r
   // Check to see if we can access the hardware device. If it's Open in NT we\r
   // will not get access.\r
@@ -393,11 +577,13 @@ Returns:
 \r
   Private->SoftwareLoopbackEnable = FALSE;\r
   Private->HardwareLoopbackEnable = FALSE;\r
-  Private->HardwareFlowControl    = FALSE;\r
+  Private->HardwareFlowControl    = (BOOLEAN) (FlowControlMap == UART_FLOW_CONTROL_HARDWARE);\r
   Private->Fifo.First             = 0;\r
   Private->Fifo.Last              = 0;\r
   Private->Fifo.Surplus           = SERIAL_MAX_BUFFER_SIZE;\r
 \r
+  CopyMem (&Private->UartDevicePath, &UartNode, sizeof (UART_DEVICE_PATH));\r
+\r
   AddUnicodeString2 (\r
     "eng",\r
     gWinNtSerialIoComponentName.SupportedLanguages,\r
@@ -423,25 +609,6 @@ Returns:
   Private->SerialIo.Read          = WinNtSerialIoRead;\r
   Private->SerialIo.Mode          = &Private->SerialIoMode;\r
 \r
-  if (RemainingDevicePath != NULL) {\r
-    //\r
-    // Match the configuration of the RemainingDevicePath. IsHandleSupported()\r
-    // already checked to make sure the RemainingDevicePath contains settings\r
-    // that we can support.\r
-    //\r
-    CopyMem (&Private->UartDevicePath, RemainingDevicePath, sizeof (UART_DEVICE_PATH));\r
-  } else {\r
-    //\r
-    // Build the device path by appending the UART node to the ParentDevicePath\r
-    // from the WinNtIo handle. The Uart setings are zero here, since\r
-    // SetAttribute() will update them to match the default setings.\r
-    //\r
-    ZeroMem (&Private->UartDevicePath, sizeof (UART_DEVICE_PATH));\r
-    Private->UartDevicePath.Header.Type     = MESSAGING_DEVICE_PATH;\r
-    Private->UartDevicePath.Header.SubType  = MSG_UART_DP;\r
-    SetDevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) &Private->UartDevicePath, sizeof (UART_DEVICE_PATH));\r
-  }\r
-\r
   //\r
   // Build the device path by appending the UART node to the ParentDevicePath\r
   // from the WinNtIo handle. The Uart setings are zero here, since\r
@@ -451,6 +618,19 @@ Returns:
                           ParentDevicePath,\r
                           (EFI_DEVICE_PATH_PROTOCOL *) &Private->UartDevicePath\r
                           );\r
+  //\r
+  // Only produce the FlowControl node when remaining device path has it\r
+  //\r
+  if (FlowControl != NULL) {\r
+    TempDevicePath = Private->DevicePath;\r
+    if (TempDevicePath != NULL) {\r
+      Private->DevicePath = AppendDevicePathNode (\r
+                              TempDevicePath,\r
+                              (EFI_DEVICE_PATH_PROTOCOL *) FlowControl\r
+                              );\r
+      FreePool (TempDevicePath);\r
+    }\r
+  }\r
   if (Private->DevicePath == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto Error;\r
@@ -496,7 +676,7 @@ Returns:
   Status = gBS->OpenProtocol (\r
                   Handle,\r
                   &gEfiWinNtIoProtocolGuid,\r
-                  &WinNtIo,\r
+                  (VOID **) &WinNtIo,\r
                   This->DriverBindingHandle,\r
                   Private->Handle,\r
                   EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
@@ -534,7 +714,6 @@ Error:
   return Status;\r
 }\r
 \r
-STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 WinNtSerialIoDriverBindingStop (\r
@@ -600,7 +779,7 @@ Returns:
     Status = gBS->OpenProtocol (\r
                     ChildHandleBuffer[Index],\r
                     &gEfiSerialIoProtocolGuid,\r
-                    &SerialIo,\r
+                    (VOID **) &SerialIo,\r
                     This->DriverBindingHandle,\r
                     Handle,\r
                     EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
@@ -662,7 +841,6 @@ Returns:
 // Serial IO Protocol member functions\r
 //\r
 \r
-STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 WinNtSerialIoReset (\r
@@ -703,13 +881,12 @@ Returns:
                 This->Mode->BaudRate,\r
                 This->Mode->ReceiveFifoDepth,\r
                 This->Mode->Timeout,\r
-                This->Mode->Parity,\r
+                (EFI_PARITY_TYPE)This->Mode->Parity,\r
                 (UINT8) This->Mode->DataBits,\r
-                This->Mode->StopBits\r
+                (EFI_STOP_BITS_TYPE)This->Mode->StopBits\r
                 );\r
 }\r
 \r
-STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 WinNtSerialIoSetAttributes (\r
@@ -757,7 +934,7 @@ Returns:
   COMMTIMEOUTS                  PortTimeOuts;\r
   DWORD                         ConvertedTime;\r
   BOOL                          Result;\r
-  EFI_DEVICE_PATH_PROTOCOL      *NewDevicePath;\r
+  UART_DEVICE_PATH              *Uart;\r
   EFI_TPL                       Tpl;\r
 \r
   Private = WIN_NT_SERIAL_IO_PRIVATE_DATA_FROM_THIS (This);\r
@@ -767,7 +944,7 @@ Returns:
   //   we must set the default values if a null argument is passed in.\r
   //\r
   if (BaudRate == 0) {\r
-    BaudRate = FixedPcdGet64 (PcdUartDefaultBaudRate);\r
+    BaudRate = PcdGet64 (PcdUartDefaultBaudRate);\r
   }\r
 \r
   if (ReceiveFifoDepth == 0) {\r
@@ -779,15 +956,15 @@ Returns:
   }\r
 \r
   if (Parity == DefaultParity) {\r
-    Parity = FixedPcdGet8 (PcdUartDefaultParity);\r
+    Parity = (EFI_PARITY_TYPE) (PcdGet8 (PcdUartDefaultParity));\r
   }\r
 \r
   if (DataBits == 0) {\r
-    DataBits = FixedPcdGet8 (PcdUartDefaultDataBits);\r
+    DataBits = PcdGet8 (PcdUartDefaultDataBits);\r
   }\r
 \r
   if (StopBits == DefaultStopBits) {\r
-    StopBits = (EFI_STOP_BITS_TYPE) FixedPcdGet8 (PcdUartDefaultStopBits);\r
+    StopBits = (EFI_STOP_BITS_TYPE) PcdGet8 (PcdUartDefaultStopBits);\r
   }\r
 \r
   //\r
@@ -801,13 +978,13 @@ Returns:
   //The lower baud rate supported by the serial device will be selected without exceeding the unsupported BaudRate parameter\r
   // \r
   \r
-  for (Index = 1; Index < (sizeof (mBaudRateCurrentSupport) / sizeof (mBaudRateCurrentSupport[0])); Index++) {\r
+  for (Index = 1; Index < (ARRAY_SIZE (mBaudRateCurrentSupport)); Index++) {\r
     if (BaudRate < mBaudRateCurrentSupport[Index]) {\r
       BaudRate = mBaudRateCurrentSupport[Index-1];\r
       break;\r
       }\r
   }\r
-       \r
+\r
   if ((ReceiveFifoDepth < 1) || (ReceiveFifoDepth > SERIAL_PORT_MAX_RECEIVE_FIFO_DEPTH)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -942,40 +1119,27 @@ Returns:
   Private->UartDevicePath.Parity    = (UINT8) Parity;\r
   Private->UartDevicePath.StopBits  = (UINT8) StopBits;\r
 \r
-  NewDevicePath = AppendDevicePathNode (\r
-                    Private->ParentDevicePath,\r
-                    (EFI_DEVICE_PATH_PROTOCOL *) &Private->UartDevicePath\r
-                    );\r
-  if (NewDevicePath == NULL) {\r
-    gBS->RestoreTPL (Tpl);\r
-    return EFI_DEVICE_ERROR;\r
-  }\r
-\r
+  Status = EFI_SUCCESS;\r
   if (Private->Handle != NULL) {\r
+    Uart = (UART_DEVICE_PATH *) (\r
+             (UINTN) Private->DevicePath\r
+             + GetDevicePathSize (Private->ParentDevicePath)\r
+             - END_DEVICE_PATH_LENGTH\r
+             );\r
+    CopyMem (Uart, &Private->UartDevicePath, sizeof (UART_DEVICE_PATH));\r
     Status = gBS->ReinstallProtocolInterface (\r
                     Private->Handle,\r
                     &gEfiDevicePathProtocolGuid,\r
                     Private->DevicePath,\r
-                    NewDevicePath\r
+                    Private->DevicePath\r
                     );\r
-    if (EFI_ERROR (Status)) {\r
-      gBS->RestoreTPL (Tpl);\r
-      return Status;\r
-    }\r
   }\r
 \r
-  if (Private->DevicePath != NULL) {\r
-    FreePool (Private->DevicePath);\r
-  }\r
-\r
-  Private->DevicePath = NewDevicePath;\r
-\r
   gBS->RestoreTPL (Tpl);\r
 \r
-  return EFI_SUCCESS;\r
+  return Status;\r
 }\r
 \r
-STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 WinNtSerialIoSetControl (\r
@@ -1005,6 +1169,8 @@ Returns:
   BOOL                          Result;\r
   DCB                           Dcb;\r
   EFI_TPL                       Tpl;\r
+  UART_FLOW_CONTROL_DEVICE_PATH *FlowControl;\r
+  EFI_STATUS                    Status;\r
 \r
   //\r
   // first determine the parameter is invalid\r
@@ -1066,12 +1232,34 @@ Returns:
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
+  Status = EFI_SUCCESS;\r
+  if (Private->Handle != NULL) {\r
+    FlowControl = (UART_FLOW_CONTROL_DEVICE_PATH *) (\r
+                    (UINTN) Private->DevicePath\r
+                    + GetDevicePathSize (Private->ParentDevicePath)\r
+                    - END_DEVICE_PATH_LENGTH\r
+                    + sizeof (UART_DEVICE_PATH)\r
+                    );\r
+    if (IsUartFlowControlNode (FlowControl) &&\r
+        ((FlowControl->FlowControlMap == UART_FLOW_CONTROL_HARDWARE) ^ Private->HardwareFlowControl)) {\r
+      //\r
+      // Flow Control setting is changed, need to reinstall device path protocol\r
+      //\r
+      FlowControl->FlowControlMap = Private->HardwareFlowControl ? UART_FLOW_CONTROL_HARDWARE : 0;\r
+      Status = gBS->ReinstallProtocolInterface (\r
+                      Private->Handle,\r
+                      &gEfiDevicePathProtocolGuid,\r
+                      Private->DevicePath,\r
+                      Private->DevicePath\r
+                      );\r
+    }\r
+  }\r
+\r
   gBS->RestoreTPL (Tpl);\r
 \r
-  return EFI_SUCCESS;\r
+  return Status;\r
 }\r
 \r
-STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 WinNtSerialIoGetControl (\r
@@ -1186,7 +1374,6 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
-STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 WinNtSerialIoWrite (\r
@@ -1290,7 +1477,6 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
-STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 WinNtSerialIoRead (\r