]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Bus/Isa/IsaSerialDxe/Serial.c
Remove unnecessary use of FixedPcdxxx() functions and [FixedPcd] INF sections. These...
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Isa / IsaSerialDxe / Serial.c
index f9d08ce3a0cc6831973b14408b13102d21c9471b..03dae25b2d5ad958312609c17e97197a49d5ad43 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Serial driver for standard UARTS on an ISA bus.\r
 \r
-Copyright (c) 2006 - 2009, Intel Corporation<BR>\r
+Copyright (c) 2006 - 2010, Intel Corporation<BR>\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
@@ -144,18 +144,66 @@ SerialControllerDriverSupported (
   EFI_STATUS                                Status;\r
   EFI_DEVICE_PATH_PROTOCOL                  *ParentDevicePath;\r
   EFI_ISA_IO_PROTOCOL                       *IsaIo;\r
-  UART_DEVICE_PATH                          UartNode;\r
+  UART_DEVICE_PATH                          *UartNode;\r
 \r
   //\r
-  // Ignore the RemainingDevicePath\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
+          sizeof (UART_DEVICE_PATH) != DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) UartNode)\r
+                                        ) {\r
+        goto Error;\r
+      }\r
+  \r
+      if (UartNode->BaudRate > SERIAL_PORT_MAX_BAUD_RATE) {\r
+        goto Error;\r
+      }\r
+  \r
+      if (UartNode->Parity < NoParity || UartNode->Parity > SpaceParity) {\r
+        goto Error;\r
+      }\r
+  \r
+      if (UartNode->DataBits < 5 || UartNode->DataBits > 8) {\r
+        goto Error;\r
+      }\r
+  \r
+      if (UartNode->StopBits < OneStopBit || UartNode->StopBits > TwoStopBits) {\r
+        goto Error;\r
+      }\r
+  \r
+      if ((UartNode->DataBits == 5) && (UartNode->StopBits == TwoStopBits)) {\r
+        goto Error;\r
+      }\r
+  \r
+      if ((UartNode->DataBits >= 6) && (UartNode->DataBits <= 8) && (UartNode->StopBits == OneFiveStopBits)) {\r
+        goto Error;\r
+      }\r
+  \r
+      Status = EFI_SUCCESS;\r
+    }\r
+  }\r
+\r
   //\r
   // Open the IO Abstraction(s) needed to perform the supported test\r
   //\r
   Status = gBS->OpenProtocol (\r
                   Controller,\r
-                  &gEfiDevicePathProtocolGuid,\r
-                  (VOID **) &ParentDevicePath,\r
+                  &gEfiIsaIoProtocolGuid,\r
+                  (VOID **) &IsaIo,\r
                   This->DriverBindingHandle,\r
                   Controller,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
@@ -168,22 +216,27 @@ SerialControllerDriverSupported (
     return Status;\r
   }\r
 \r
+  //\r
+  // Close the I/O Abstraction(s) used to perform the supported test\r
+  //\r
   gBS->CloseProtocol (\r
          Controller,\r
-         &gEfiDevicePathProtocolGuid,\r
+         &gEfiIsaIoProtocolGuid,\r
          This->DriverBindingHandle,\r
          Controller\r
          );\r
 \r
+  //\r
+  // Open the EFI Device Path protocol needed to perform the supported test\r
+  //\r
   Status = gBS->OpenProtocol (\r
                   Controller,\r
-                  &gEfiIsaIoProtocolGuid,\r
-                  (VOID **) &IsaIo,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **) &ParentDevicePath,\r
                   This->DriverBindingHandle,\r
                   Controller,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
                   );\r
-\r
   if (Status == EFI_ALREADY_STARTED) {\r
     return EFI_SUCCESS;\r
   }\r
@@ -200,57 +253,14 @@ SerialControllerDriverSupported (
     Status = EFI_UNSUPPORTED;\r
     goto Error;\r
   }\r
-  //\r
-  // Make sure RemainingDevicePath is valid\r
-  //\r
-  if (RemainingDevicePath != NULL) {\r
-    Status = EFI_UNSUPPORTED;\r
-    CopyMem (\r
-      &UartNode,\r
-      (UART_DEVICE_PATH *) RemainingDevicePath,\r
-      sizeof (UART_DEVICE_PATH)\r
-      );\r
-    if (UartNode.Header.Type != MESSAGING_DEVICE_PATH ||\r
-        UartNode.Header.SubType != MSG_UART_DP ||\r
-        sizeof (UART_DEVICE_PATH) != DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) &UartNode)\r
-                                      ) {\r
-      goto Error;\r
-    }\r
-\r
-    if (UartNode.BaudRate > SERIAL_PORT_MAX_BAUD_RATE) {\r
-      goto Error;\r
-    }\r
-\r
-    if (UartNode.Parity < NoParity || UartNode.Parity > SpaceParity) {\r
-      goto Error;\r
-    }\r
-\r
-    if (UartNode.DataBits < 5 || UartNode.DataBits > 8) {\r
-      goto Error;\r
-    }\r
-\r
-    if (UartNode.StopBits < OneStopBit || UartNode.StopBits > TwoStopBits) {\r
-      goto Error;\r
-    }\r
-\r
-    if ((UartNode.DataBits == 5) && (UartNode.StopBits == TwoStopBits)) {\r
-      goto Error;\r
-    }\r
-\r
-    if ((UartNode.DataBits >= 6) && (UartNode.DataBits <= 8) && (UartNode.StopBits == OneFiveStopBits)) {\r
-      goto Error;\r
-    }\r
-\r
-    Status = EFI_SUCCESS;\r
-  }\r
 \r
 Error:\r
   //\r
-  // Close the I/O Abstraction(s) used to perform the supported test\r
+  // Close protocol, don't use device path protocol in the Support() function\r
   //\r
   gBS->CloseProtocol (\r
          Controller,\r
-         &gEfiIsaIoProtocolGuid,\r
+         &gEfiDevicePathProtocolGuid,\r
          This->DriverBindingHandle,\r
          Controller\r
          );\r
@@ -281,11 +291,11 @@ SerialControllerDriverStart (
   EFI_ISA_IO_PROTOCOL                 *IsaIo;\r
   SERIAL_DEV                          *SerialDevice;\r
   UINTN                               Index;\r
-  UART_DEVICE_PATH                    Node;\r
   EFI_DEVICE_PATH_PROTOCOL            *ParentDevicePath;\r
   EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;\r
   UINTN                               EntryCount;\r
   EFI_SERIAL_IO_PROTOCOL              *SerialIo;\r
+  UART_DEVICE_PATH                    *UartNode;\r
 \r
   SerialDevice = NULL;\r
   //\r
@@ -328,9 +338,13 @@ SerialControllerDriverStart (
 \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
     //\r
     // Make sure a child handle does not already exist.  This driver can only\r
     // produce one child per serial port.\r
@@ -347,7 +361,7 @@ SerialControllerDriverStart (
 \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
@@ -357,24 +371,35 @@ SerialControllerDriverStart (
                         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
-                               (EFI_PARITY_TYPE) Node.Parity,\r
-                               Node.DataBits,\r
-                               (EFI_STOP_BITS_TYPE) Node.StopBits\r
+                               (EFI_PARITY_TYPE) UartNode->Parity,\r
+                               UartNode->DataBits,\r
+                               (EFI_STOP_BITS_TYPE) UartNode->StopBits\r
                                );\r
         }\r
         break;\r
       }\r
     }\r
 \r
-    gBS->FreePool (OpenInfoBuffer);\r
+    FreePool (OpenInfoBuffer);\r
     return Status;\r
   }\r
+\r
+  if (RemainingDevicePath != NULL) {\r
+    if (IsDevicePathEnd (RemainingDevicePath)) {\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
   //\r
   // Initialize the serial device instance\r
   //\r
@@ -388,6 +413,21 @@ SerialControllerDriverStart (
   SerialDevice->IsaIo               = IsaIo;\r
   SerialDevice->ParentDevicePath    = ParentDevicePath;\r
 \r
+  //\r
+  // Check if RemainingDevicePath is NULL, \r
+  // if yes, use the values from the gSerialDevTempate as no remaining device path was\r
+  // passed in.\r
+  //\r
+  if (RemainingDevicePath != NULL) {\r
+    //\r
+    // If RemainingDevicePath isn't NULL, \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 (&SerialDevice->UartDevicePath, RemainingDevicePath, sizeof (UART_DEVICE_PATH));\r
+  }\r
+\r
   AddName (SerialDevice, IsaIo);\r
 \r
   for (Index = 0; SerialDevice->IsaIo->ResourceList->ResourceItem[Index].Type != EfiIsaAcpiResourceEndOfList; Index++) {\r
@@ -414,23 +454,10 @@ SerialControllerDriverStart (
     goto Error;\r
   }\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 (&SerialDevice->UartDevicePath, RemainingDevicePath, sizeof (UART_DEVICE_PATH));\r
-  } else {\r
-    //\r
-    // Use the values from the gSerialDevTempate as no remaining device path was\r
-    // passed in.\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
-  // SetAttribute() will update them to match the current setings.\r
+  // Build the device path by appending the UART node to the ParentDevicePath.\r
+  //The Uart setings are zero here, since  SetAttribute() will update them to match \r
+  // the default setings.\r
   //\r
   SerialDevice->DevicePath = AppendDevicePathNode (\r
                                ParentDevicePath,\r
@@ -801,6 +828,18 @@ IsaSerialReceiveTransmit (
     } while (!IsaSerialFifoEmpty (&SerialDevice->Transmit));\r
   } else {\r
     ReceiveFifoFull = IsaSerialFifoFull (&SerialDevice->Receive);\r
+    //\r
+    // For full handshake flow control, tell the peer to send data\r
+    // if receive buffer is available.\r
+    //\r
+    if (SerialDevice->HardwareFlowControl &&\r
+        !FeaturePcdGet(PcdIsaBusSerialUseHalfHandshake)&&\r
+        !ReceiveFifoFull\r
+        ) {\r
+      Mcr.Data     = READ_MCR (SerialDevice->IsaIo, SerialDevice->BaseAddress);\r
+      Mcr.Bits.Rts = 1;\r
+      WRITE_MCR (SerialDevice->IsaIo, SerialDevice->BaseAddress, Mcr.Data);\r
+    }\r
     do {\r
       Lsr.Data = READ_LSR (SerialDevice->IsaIo, SerialDevice->BaseAddress);\r
 \r
@@ -821,27 +860,24 @@ IsaSerialReceiveTransmit (
               continue;\r
             }\r
           }\r
-          //\r
-          // Make sure the receive data will not be missed, Assert DTR\r
-          //\r
-          if (SerialDevice->HardwareFlowControl) {\r
-            Mcr.Data = READ_MCR (SerialDevice->IsaIo, SerialDevice->BaseAddress);\r
-            Mcr.Bits.DtrC &= 0;\r
-            WRITE_MCR (SerialDevice->IsaIo, SerialDevice->BaseAddress, Mcr.Data);\r
-          }\r
 \r
           Data = READ_RBR (SerialDevice->IsaIo, SerialDevice->BaseAddress);\r
 \r
+          IsaSerialFifoAdd (&SerialDevice->Receive, Data);\r
+          \r
           //\r
-          // Deassert DTR\r
+          // For full handshake flow control, if receive buffer full\r
+          // tell the peer to stop sending data.\r
           //\r
-          if (SerialDevice->HardwareFlowControl) {\r
-            Mcr.Data = READ_MCR (SerialDevice->IsaIo, SerialDevice->BaseAddress);\r
-            Mcr.Bits.DtrC |= 1;\r
+          if (SerialDevice->HardwareFlowControl &&\r
+              !FeaturePcdGet(PcdIsaBusSerialUseHalfHandshake)   &&\r
+              IsaSerialFifoFull (&SerialDevice->Receive)\r
+              ) {\r
+            Mcr.Data     = READ_MCR (SerialDevice->IsaIo, SerialDevice->BaseAddress);\r
+            Mcr.Bits.Rts = 0;\r
             WRITE_MCR (SerialDevice->IsaIo, SerialDevice->BaseAddress, Mcr.Data);\r
           }\r
 \r
-          IsaSerialFifoAdd (&SerialDevice->Receive, Data);\r
 \r
           continue;\r
         } else {\r
@@ -861,17 +897,19 @@ IsaSerialReceiveTransmit (
         //\r
         if (SerialDevice->HardwareFlowControl) {\r
           //\r
-          // Send RTS\r
+          // For half handshake flow control assert RTS before sending.\r
           //\r
-          Mcr.Data = READ_MCR (SerialDevice->IsaIo, SerialDevice->BaseAddress);\r
-          Mcr.Bits.Rts |= 1;\r
-          WRITE_MCR (SerialDevice->IsaIo, SerialDevice->BaseAddress, Mcr.Data);\r
+          if (FeaturePcdGet(PcdIsaBusSerialUseHalfHandshake)) {\r
+            Mcr.Data     = READ_MCR (SerialDevice->IsaIo, SerialDevice->BaseAddress);\r
+            Mcr.Bits.Rts= 0;\r
+            WRITE_MCR (SerialDevice->IsaIo, SerialDevice->BaseAddress, Mcr.Data);\r
+          }\r
           //\r
           // Wait for CTS\r
           //\r
           TimeOut   = 0;\r
           Msr.Data  = READ_MSR (SerialDevice->IsaIo, SerialDevice->BaseAddress);\r
-          while (Msr.Bits.Cts == 0) {\r
+          while ((Msr.Bits.Dcd == 1) && ((Msr.Bits.Cts == 0) || FeaturePcdGet(PcdIsaBusSerialUseHalfHandshake))) {\r
             gBS->Stall (TIMEOUT_STALL_INTERVAL);\r
             TimeOut++;\r
             if (TimeOut > 5) {\r
@@ -881,28 +919,22 @@ IsaSerialReceiveTransmit (
             Msr.Data = READ_MSR (SerialDevice->IsaIo, SerialDevice->BaseAddress);\r
           }\r
 \r
-          if (Msr.Bits.Cts == 1) {\r
+          if ((Msr.Bits.Dcd == 0) && ((Msr.Bits.Cts == 1) || FeaturePcdGet(PcdIsaBusSerialUseHalfHandshake))) {\r
             IsaSerialFifoRemove (&SerialDevice->Transmit, &Data);\r
             WRITE_THR (SerialDevice->IsaIo, SerialDevice->BaseAddress, Data);\r
           }\r
-        }\r
-        //\r
-        // write the data out\r
-        //\r
-        if (!SerialDevice->HardwareFlowControl) {\r
-          IsaSerialFifoRemove (&SerialDevice->Transmit, &Data);\r
-          WRITE_THR (SerialDevice->IsaIo, SerialDevice->BaseAddress, Data);\r
-        }\r
-        //\r
-        // Make sure the transmit data will not be missed\r
-        //\r
-        if (SerialDevice->HardwareFlowControl) {\r
+\r
           //\r
-          // Assert RTS\r
+          // For half handshake flow control, tell DCE we are done.\r
           //\r
-          Mcr.Data = READ_MCR (SerialDevice->IsaIo, SerialDevice->BaseAddress);\r
-          Mcr.Bits.Rts &= 0;\r
-          WRITE_MCR (SerialDevice->IsaIo, SerialDevice->BaseAddress, Mcr.Data);\r
+          if (FeaturePcdGet(PcdIsaBusSerialUseHalfHandshake)) {\r
+            Mcr.Data = READ_MCR (SerialDevice->IsaIo, SerialDevice->BaseAddress);\r
+            Mcr.Bits.Rts = 1;\r
+            WRITE_MCR (SerialDevice->IsaIo, SerialDevice->BaseAddress, Mcr.Data);\r
+          }\r
+        } else {\r
+          IsaSerialFifoRemove (&SerialDevice->Transmit, &Data);\r
+          WRITE_THR (SerialDevice->IsaIo, SerialDevice->BaseAddress, Data);\r
         }\r
       }\r
     } while (Lsr.Bits.Thre == 1 && !IsaSerialFifoEmpty (&SerialDevice->Transmit));\r
@@ -1085,7 +1117,7 @@ IsaSerialSetAttributes (
   // Check for default settings and fill in actual values.\r
   //\r
   if (BaudRate == 0) {\r
-    BaudRate = FixedPcdGet64 (PcdUartDefaultBaudRate);\r
+    BaudRate = PcdGet64 (PcdUartDefaultBaudRate);\r
   }\r
 \r
   if (ReceiveFifoDepth == 0) {\r
@@ -1097,15 +1129,15 @@ IsaSerialSetAttributes (
   }\r
 \r
   if (Parity == DefaultParity) {\r
-    Parity = (EFI_PARITY_TYPE)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
   // 5 and 6 data bits can not be verified on a 16550A UART\r
@@ -1183,12 +1215,7 @@ IsaSerialSetAttributes (
   if ((StopBits < OneStopBit) || (StopBits > TwoStopBits)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  //\r
-  // for DataBits = 5, StopBits can not set TwoStopBits\r
-  //\r
-  // if ((DataBits == 5) && (StopBits == TwoStopBits)) {\r
-  //  return EFI_INVALID_PARAMETER;\r
-  // }\r
+\r
   //\r
   // for DataBits = 6,7,8, StopBits can not set OneFiveStopBits\r
   //\r