]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UnixSerialIo driver was changed to produce the flow control device path node when...
authorniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 9 Apr 2010 08:39:53 +0000 (08:39 +0000)
committerniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 9 Apr 2010 08:39:53 +0000 (08:39 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10353 6f19259b-4bc3-4df7-8a09-765794883524

UnixPkg/UnixSerialIoDxe/UnixSerialIo.c
UnixPkg/UnixSerialIoDxe/UnixSerialIo.h
UnixPkg/UnixSerialIoDxe/UnixSerialIo.inf

index e41e74964fda7ee8e4ed670f60a8344e19d669d6..436df8ca962b60d69ba943e5bac3693debf02cb5 100644 (file)
@@ -1,6 +1,6 @@
 /*++\r
 \r
-Copyright (c) 2006 - 2009, Intel Corporation\r
+Copyright (c) 2006 - 2010, 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
@@ -56,6 +56,51 @@ EFI_DRIVER_BINDING_PROTOCOL gUnixSerialIoDriverBinding = {
   NULL\r
 };\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
 UINTN\r
 ConvertBaud2Unix (\r
   UINT64 BaudRate\r
@@ -217,10 +262,15 @@ Returns:
 \r
 --*/\r
 {\r
-  EFI_STATUS                Status;\r
-  EFI_DEVICE_PATH_PROTOCOL  *ParentDevicePath;\r
-  EFI_UNIX_IO_PROTOCOL      *UnixIo;\r
-  UART_DEVICE_PATH          *UartNode;\r
+  EFI_STATUS                          Status;\r
+  EFI_DEVICE_PATH_PROTOCOL            *ParentDevicePath;\r
+  EFI_UNIX_IO_PROTOCOL                *UnixIo;\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
 \r
   //\r
   // Check RemainingDevicePath validation\r
@@ -260,6 +310,17 @@ Returns:
       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
@@ -275,7 +336,45 @@ Returns:
                   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
+                    &gEfiUnixIoProtocolGuid,\r
+                    &OpenInfoBuffer,\r
+                    &EntryCount\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\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
+            (ContainsFlowControl (RemainingDevicePath) ^ ContainsFlowControl (DevicePath))) {\r
+          Status = EFI_UNSUPPORTED;\r
+        }\r
+        break;\r
+      }\r
+    }\r
+    FreePool (OpenInfoBuffer);\r
+    return Status;\r
   }\r
 \r
   if (EFI_ERROR (Status)) {\r
@@ -366,21 +465,25 @@ Returns:
   EFI_UNIX_IO_PROTOCOL                *UnixIo;\r
   UNIX_SERIAL_IO_PRIVATE_DATA         *Private;\r
   UINTN                               UnixHandle;\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
   CHAR8                               AsciiDevName[1024];\r
-  UART_DEVICE_PATH                    *UartNode;\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
   DEBUG ((EFI_D_INFO, "SerialIo drive binding start!\r\n"));\r
   Private   = NULL;\r
   UnixHandle  = -1;\r
 \r
   //\r
-  // Grab the protocols we need\r
+  // Get the Parent Device Path\r
   //\r
   Status = gBS->OpenProtocol (\r
                   Handle,\r
@@ -440,7 +543,7 @@ 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
@@ -450,16 +553,35 @@ Returns:
                         EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
                         );\r
         if (!EFI_ERROR (Status)) {\r
-          UartNode = (UART_DEVICE_PATH *) RemainingDevicePath;\r
+          Uart   = (UART_DEVICE_PATH *) RemainingDevicePath;\r
           Status = SerialIo->SetAttributes (\r
-                              SerialIo,\r
-                              UartNode->BaudRate,\r
-                              SerialIo->Mode->ReceiveFifoDepth,\r
-                              SerialIo->Mode->Timeout,\r
-                              UartNode->Parity,\r
-                              UartNode->DataBits,\r
-                              UartNode->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
+\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
@@ -469,16 +591,18 @@ 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 UnixIo handle. The Uart setings are zero here, since\r
     // SetAttribute() will update them to match the default setings.\r
     //\r
-    ZeroMem (&Node, sizeof (UART_DEVICE_PATH));\r
-    Node.Header.Type     = MESSAGING_DEVICE_PATH;\r
-    Node.Header.SubType  = MSG_UART_DP;\r
-    SetDevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) &Node, sizeof (UART_DEVICE_PATH));\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
@@ -490,7 +614,13 @@ Returns:
     // already checked to make sure the RemainingDevicePath contains settings\r
     // that we can support.\r
     //\r
-    CopyMem (&Node, RemainingDevicePath, sizeof (UART_DEVICE_PATH));\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
@@ -536,12 +666,12 @@ 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, &Node, sizeof (UART_DEVICE_PATH));\r
+  CopyMem (&Private->UartDevicePath, &UartNode, sizeof (UART_DEVICE_PATH));\r
 \r
   AddUnicodeString (\r
     "eng",\r
@@ -570,6 +700,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
@@ -876,8 +1019,8 @@ Returns:
 {\r
   EFI_STATUS                    Status;\r
   UNIX_SERIAL_IO_PRIVATE_DATA   *Private;\r
+  UART_DEVICE_PATH              *Uart;\r
   EFI_TPL                       Tpl;\r
-  EFI_DEVICE_PATH_PROTOCOL      *NewDevicePath;\r
 \r
   Tpl     = gBS->RaiseTPL (TPL_NOTIFY);\r
   Private = UNIX_SERIAL_IO_PRIVATE_DATA_FROM_THIS (This);\r
@@ -977,9 +1120,10 @@ Returns:
                         &Private->UnixTermios\r
                         )) {\r
     DEBUG ((EFI_D_INFO, "Fail to set options for serial device!\r\n"));\r
+    gBS->RestoreTPL (Tpl);\r
     return EFI_DEVICE_ERROR;\r
   }\r
-  \r
+\r
   //\r
   //  Update mode\r
   //\r
@@ -989,6 +1133,7 @@ Returns:
   Private->SerialIoMode.Parity            = Parity;\r
   Private->SerialIoMode.DataBits          = DataBits;\r
   Private->SerialIoMode.StopBits          = StopBits;\r
+\r
   //\r
   // See if Device Path Node has actually changed\r
   //\r
@@ -1008,37 +1153,25 @@ 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
 EFI_STATUS\r
@@ -1066,17 +1199,28 @@ Returns:
 \r
 --*/\r
 {\r
-  UNIX_SERIAL_IO_PRIVATE_DATA *Private;\r
-  UINTN                       Result;\r
-  UINTN                       Status;\r
-  struct termios              Options;\r
-  EFI_TPL                     Tpl;\r
+  UNIX_SERIAL_IO_PRIVATE_DATA   *Private;\r
+  UINTN                         Result;\r
+  UINTN                         IoStatus;\r
+  struct termios                Options;\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
+  //\r
+  if (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
+    return EFI_UNSUPPORTED;\r
+  }\r
 \r
   Tpl     = gBS->RaiseTPL (TPL_NOTIFY);\r
 \r
   Private = UNIX_SERIAL_IO_PRIVATE_DATA_FROM_THIS (This);\r
 \r
-  Result  = Private->UnixThunk->IoCtl (Private->UnixHandle, TIOCMGET, &Status);\r
+  Result  = Private->UnixThunk->IoCtl (Private->UnixHandle, TIOCMGET, &IoStatus);\r
 \r
   if (Result == -1) {\r
     Private->UnixThunk->Perror ("SerialSetControl");\r
@@ -1108,7 +1252,7 @@ Returns:
     Private->HardwareLoopbackEnable = TRUE;\r
   }\r
 \r
-  Result  = Private->UnixThunk->IoCtl (Private->UnixHandle, TIOCMSET, &Status);\r
+  Result  = Private->UnixThunk->IoCtl (Private->UnixHandle, TIOCMSET, &IoStatus);\r
 \r
   if (Result == -1) {\r
     Private->UnixThunk->Perror ("SerialSetControl");\r
@@ -1116,9 +1260,32 @@ 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
 EFI_STATUS\r
index bcd8018e4c0df87bb2ec2dc2d95c27806fd42d4c..d392f95e80213275cf8873c8da0897d22d5ddd5b 100644 (file)
@@ -120,12 +120,15 @@ extern EFI_COMPONENT_NAME_PROTOCOL  gUnixSerialIoComponentName;
 #define SERIAL_PARITY_DEFAULT   DefaultParity\r
 #define SERIAL_STOPBITS_DEFAULT DefaultStopBits\r
 \r
-#define SERIAL_CONTROL_MASK     (EFI_SERIAL_CLEAR_TO_SEND       | \\r
-                                 EFI_SERIAL_DATA_SET_READY      | \\r
-                                 EFI_SERIAL_RING_INDICATE       | \\r
-                                 EFI_SERIAL_CARRIER_DETECT      | \\r
-                                 EFI_SERIAL_REQUEST_TO_SEND     | \\r
-                                 EFI_SERIAL_DATA_TERMINAL_READY | \\r
+#define SERIAL_CONTROL_MASK     (EFI_SERIAL_CLEAR_TO_SEND                | \\r
+                                 EFI_SERIAL_DATA_SET_READY               | \\r
+                                 EFI_SERIAL_RING_INDICATE                | \\r
+                                 EFI_SERIAL_CARRIER_DETECT               | \\r
+                                 EFI_SERIAL_REQUEST_TO_SEND              | \\r
+                                 EFI_SERIAL_DATA_TERMINAL_READY          | \\r
+                                 EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE     | \\r
+                                 EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE     | \\r
+                                 EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE | \\r
                                  EFI_SERIAL_INPUT_BUFFER_EMPTY)\r
 \r
 #define ConvertBaud2Nt(x)       (DWORD) x\r
index 0dd672b313c895bef6e984ed1933789c7c3bfeb6..e951d807360436221b533ebf3386504b5567dbe4 100644 (file)
@@ -57,8 +57,8 @@
 \r
 \r
 [Guids]\r
-  gEfiUnixSerialPortGuid                       # ALWAYS_CONSUMED\r
-\r
+  gEfiUnixSerialPortGuid                        # ALWAYS_CONSUMED\r
+  gEfiUartDevicePathGuid                        # BY_START\r
 \r
 [Protocols]\r
   gEfiSerialIoProtocolGuid                      # PROTOCOL BY_START\r