]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UnixPkg/UnixSerialIoDxe/UnixSerialIo.c
Update the modules with the different module GUID to avoid the different modules...
[mirror_edk2.git] / UnixPkg / UnixSerialIoDxe / UnixSerialIo.c
index fa4e3aad362651fc3b27a8bf2dd7df64da80558a..e41e74964fda7ee8e4ed670f60a8344e19d669d6 100644 (file)
@@ -1,6 +1,6 @@
 /*++\r
 \r
-Copyright (c) 2006 - 2007, Intel Corporation\r
+Copyright (c) 2006 - 2009, 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
@@ -46,7 +46,6 @@ Abstract:
 --*/\r
 \r
 #include "UnixSerialIo.h"\r
-#include <termio.h>\r
 \r
 EFI_DRIVER_BINDING_PROTOCOL gUnixSerialIoDriverBinding = {\r
   UnixSerialIoDriverBindingSupported,\r
@@ -223,13 +222,54 @@ Returns:
   EFI_UNIX_IO_PROTOCOL      *UnixIo;\r
   UART_DEVICE_PATH          *UartNode;\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
+      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
+    }\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
-                  (VOID**)&ParentDevicePath,\r
+                  &gEfiUnixIoProtocolGuid,\r
+                  (VOID**)&UnixIo,\r
                   This->DriverBindingHandle,\r
                   Handle,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
@@ -242,17 +282,23 @@ Returns:
     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
+        &gEfiUnixIoProtocolGuid,\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
-                  &gEfiUnixIoProtocolGuid,\r
-                  (VOID**)&UnixIo,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID**)&ParentDevicePath,\r
                   This->DriverBindingHandle,\r
                   Handle,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
@@ -265,6 +311,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 Unix Thunk Protocol is valid\r
   //\r
@@ -281,46 +337,9 @@ 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
-        &gEfiUnixIoProtocolGuid,\r
-        This->DriverBindingHandle,\r
-        Handle\r
-        );\r
-\r
   return Status;\r
 }\r
 \r
@@ -354,6 +373,7 @@ Returns:
   UINTN                               Index;\r
   EFI_SERIAL_IO_PROTOCOL              *SerialIo;\r
   CHAR8                               AsciiDevName[1024];\r
+  UART_DEVICE_PATH                    *UartNode;\r
 \r
   DEBUG ((EFI_D_INFO, "SerialIo drive binding start!\r\n"));\r
   Private   = NULL;\r
@@ -397,7 +417,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
@@ -427,15 +450,15 @@ Returns:
                         EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
                         );\r
         if (!EFI_ERROR (Status)) {\r
-          CopyMem (&Node, RemainingDevicePath, sizeof (UART_DEVICE_PATH));\r
+          UartNode = (UART_DEVICE_PATH *) RemainingDevicePath;\r
           Status = SerialIo->SetAttributes (\r
                               SerialIo,\r
-                              Node.BaudRate,\r
+                              UartNode->BaudRate,\r
                               SerialIo->Mode->ReceiveFifoDepth,\r
                               SerialIo->Mode->Timeout,\r
-                              Node.Parity,\r
-                              Node.DataBits,\r
-                              Node.StopBits\r
+                              UartNode->Parity,\r
+                              UartNode->DataBits,\r
+                              UartNode->StopBits\r
                               );\r
         }\r
         break;\r
@@ -446,6 +469,37 @@ Returns:
     return Status;\r
   }\r
 \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
+\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 (&Node, RemainingDevicePath, sizeof (UART_DEVICE_PATH));\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 Unix we\r
   // will not get access.\r
@@ -454,7 +508,7 @@ Returns:
   UnixHandle = UnixIo->UnixThunk->Open (AsciiDevName, O_RDWR | O_NOCTTY, 0);\r
   \r
   if (UnixHandle == -1) {\r
-    DEBUG ((EFI_D_INFO, "Faile to open serial device, %s!\r\n", UnixIo->EnvString ));\r
+    DEBUG ((EFI_D_INFO, "Failed to open serial device, %s!\r\n", UnixIo->EnvString ));\r
     UnixIo->UnixThunk->Perror (AsciiDevName);\r
     Status = EFI_DEVICE_ERROR;\r
     goto Error;\r
@@ -487,6 +541,8 @@ Returns:
   Private->Fifo.Last              = 0;\r
   Private->Fifo.Surplus           = SERIAL_MAX_BUFFER_SIZE;\r
 \r
+  CopyMem (&Private->UartDevicePath, &Node, sizeof (UART_DEVICE_PATH));\r
+\r
   AddUnicodeString (\r
     "eng",\r
     gUnixSerialIoComponentName.SupportedLanguages,\r
@@ -503,24 +559,7 @@ Returns:
   Private->SerialIo.Read          = UnixSerialIoRead;\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 UnixIo 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
   //\r
   // Build the device path by appending the UART node to the ParentDevicePath\r
@@ -1125,6 +1164,7 @@ Returns:
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
+  Bits = 0;\r
   if ((Status & TIOCM_CTS) == TIOCM_CTS) {\r
     Bits |= EFI_SERIAL_CLEAR_TO_SEND;\r
   }\r
@@ -1206,6 +1246,7 @@ Returns:
 --*/\r
 {\r
   UNIX_SERIAL_IO_PRIVATE_DATA   *Private;\r
+  EFI_STATUS                    Status;\r
   UINT8                         *ByteBuffer;\r
   UINT32                        TotalBytesWritten;\r
   UINT32                        BytesToGo;\r
@@ -1219,6 +1260,7 @@ Returns:
   Private           = UNIX_SERIAL_IO_PRIVATE_DATA_FROM_THIS (This); \r
 \r
   ByteBuffer        = (UINT8 *) Buffer;\r
+  Status = EFI_SUCCESS;\r
   TotalBytesWritten = 0;\r
 \r
   if (Private->SoftwareLoopbackEnable || Private->HardwareLoopbackEnable) {\r
@@ -1250,6 +1292,10 @@ Returns:
                                            &ByteBuffer[TotalBytesWritten],\r
                                            BytesToGo\r
                                            );\r
+      if (BytesWritten == -1) {\r
+        Status = EFI_DEVICE_ERROR;\r
+        break;\r
+      }\r
 \r
       if (Private->HardwareFlowControl) {\r
         //\r
@@ -1269,7 +1315,7 @@ Returns:
 \r
   gBS->RestoreTPL (Tpl);\r
 \r
-  return EFI_SUCCESS;\r
+  return Status;\r
 }\r
 \r
 EFI_STATUS\r