]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c
Use MaxPacketSize as the initial buffer size to read data.
[mirror_edk2.git] / SourceLevelDebugPkg / Library / DebugCommunicationLibUsb3 / DebugCommunicationLibUsb3Common.c
index fe6aec1ca522fc2a205834067f518b188e9f21ed..320998b32a12f68ec385f61f7363da854870acdc 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Debug Port Library implementation based on usb3 debug port.\r
 \r
-  Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2014 - 2015, 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
@@ -571,7 +571,7 @@ CreateDebugCapabilityContext (
   //\r
   DebugCapabilityContext->EpOutContext.CErr             = 0x3;\r
   DebugCapabilityContext->EpOutContext.EPType           = ED_BULK_OUT;\r
-  DebugCapabilityContext->EpOutContext.MaxPacketSize    = 0x400;\r
+  DebugCapabilityContext->EpOutContext.MaxPacketSize    = XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE;\r
   DebugCapabilityContext->EpOutContext.AverageTRBLength = 0x1000;\r
   \r
   //\r
@@ -579,7 +579,7 @@ CreateDebugCapabilityContext (
   //\r
   DebugCapabilityContext->EpInContext.CErr             = 0x3;\r
   DebugCapabilityContext->EpInContext.EPType           = ED_BULK_IN;\r
-  DebugCapabilityContext->EpInContext.MaxPacketSize    = 0x400;\r
+  DebugCapabilityContext->EpInContext.MaxPacketSize    = XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE;\r
   DebugCapabilityContext->EpInContext.AverageTRBLength = 0x1000;\r
   \r
   //\r
@@ -709,9 +709,11 @@ InitializeUsbDebugHardware (
   }\r
 \r
   //\r
-  // Initialize for PEI phase when AllocatePages can work\r
+  // Initialize for PEI phase when AllocatePages can work.\r
+  // Allocate data buffer with max packet size for data read and data poll.\r
+  // Allocate data buffer for data write.\r
   //\r
-  Buffer = AllocateAlignBuffer (XHC_DEBUG_PORT_DATA_LENGTH);\r
+  Buffer = AllocateAlignBuffer (XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE * 2 + USB3_DEBUG_PORT_WRITE_MAX_PACKET_SIZE);\r
   if (Buffer == NULL) {\r
     //\r
     // AllocatePages can not still work now, return fail and do not initialize now.\r
@@ -728,10 +730,11 @@ InitializeUsbDebugHardware (
   }\r
 \r
   //\r
-  // Construct the buffer for URB in and URB out\r
+  // Construct the buffer for read, poll and write.\r
   //\r
   Handle->UrbIn.Data  = (EFI_PHYSICAL_ADDRESS)(UINTN) Buffer;\r
-  Handle->UrbOut.Data = (EFI_PHYSICAL_ADDRESS)(UINTN) Buffer + XHC_DEBUG_PORT_DATA_LENGTH;\r
+  Handle->Data        = (EFI_PHYSICAL_ADDRESS)(UINTN) Buffer + XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE;\r
+  Handle->UrbOut.Data = Handle->UrbIn.Data + XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE * 2;\r
    \r
   //\r
   // Initialize event ring\r
@@ -831,6 +834,7 @@ DebugPortReadBuffer (
   UINT64                    TimeoutTicker;\r
   UINT64                    TimerRound;\r
   EFI_PHYSICAL_ADDRESS      XhciMmioBase;\r
+  UINT8                     *Data;\r
 \r
   if (NumberOfBytes == 0 || Buffer == NULL) {\r
     return 0;\r
@@ -864,6 +868,8 @@ DebugPortReadBuffer (
     }\r
   }\r
 \r
+  Data = (UINT8 *)(UINTN)UsbDebugPortHandle->Data;\r
+\r
   //\r
   // First read data from buffer, then read debug port hw to get received data.\r
   //\r
@@ -875,14 +881,14 @@ DebugPortReadBuffer (
     }\r
 \r
     for (Index = 0; Index < Total; Index++) {\r
-      Buffer[Index] = UsbDebugPortHandle->Data[Index];\r
+      Buffer[Index] = Data[Index];\r
     }\r
 \r
     for (Index = 0; Index < UsbDebugPortHandle->DataCount - Total; Index++) {\r
-      if (Total + Index >= 8) {\r
+      if (Total + Index >= XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE) {\r
         return 0;\r
       }\r
-      UsbDebugPortHandle->Data[Index] = UsbDebugPortHandle->Data[Total + Index];\r
+      Data[Index] = Data[Total + Index];\r
     }\r
     UsbDebugPortHandle->DataCount = (UINT8)(UsbDebugPortHandle->DataCount - (UINT8)Total);\r
   }\r
@@ -928,12 +934,12 @@ DebugPortReadBuffer (
       }\r
     }\r
     Remaining = NumberOfBytes - Total;\r
-    if (Remaining >= USB3_DEBUG_PORT_MAX_PACKET_SIZE) {\r
-      Received = USB3_DEBUG_PORT_MAX_PACKET_SIZE;\r
+    if (Remaining >= XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE) {\r
+      Received = XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE;\r
       Status = XhcDataTransfer (UsbDebugPortHandle, EfiUsbDataIn, Buffer + Total, &Received, DATA_TRANSFER_READ_TIMEOUT);\r
     } else {\r
-      Received = USB3_DEBUG_PORT_MAX_PACKET_SIZE;\r
-      Status = XhcDataTransfer (UsbDebugPortHandle, EfiUsbDataIn, &UsbDebugPortHandle->Data[0], &Received, DATA_TRANSFER_READ_TIMEOUT);\r
+      Received = XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE;\r
+      Status = XhcDataTransfer (UsbDebugPortHandle, EfiUsbDataIn, (VOID *)Data, &Received, DATA_TRANSFER_READ_TIMEOUT);\r
       UsbDebugPortHandle->DataCount = (UINT8) Received;\r
 \r
       if (Remaining <= Received) {\r
@@ -952,7 +958,7 @@ DebugPortReadBuffer (
       // Copy required data from the data buffer to user buffer.\r
       //\r
       for (Index = 0; Index < Length; Index++) {\r
-        (Buffer + Total)[Index] = UsbDebugPortHandle->Data[Index];\r
+        (Buffer + Total)[Index] = Data[Index];\r
         UsbDebugPortHandle->DataCount--;\r
       }\r
 \r
@@ -960,10 +966,10 @@ DebugPortReadBuffer (
       // reorder the data buffer to make available data arranged from the beginning of the data buffer.\r
       //\r
       for (Index = 0; Index < Received - Length; Index++) {\r
-        if (Length + Index >= 8) {\r
+        if (Length + Index >= XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE) {\r
           return 0;\r
         }\r
-        UsbDebugPortHandle->Data[Index] = UsbDebugPortHandle->Data[Length + Index];\r
+        Data[Index] = Data[Length + Index];\r
       }\r
       //\r
       // fixup the real required length of data.\r
@@ -1050,8 +1056,8 @@ DebugPortWriteBuffer (
 \r
   Index = 0;\r
   while ((Total < NumberOfBytes)) {\r
-    if (NumberOfBytes - Total > USB3_DEBUG_PORT_MAX_PACKET_SIZE) {\r
-      Sent = USB3_DEBUG_PORT_MAX_PACKET_SIZE;\r
+    if (NumberOfBytes - Total > USB3_DEBUG_PORT_WRITE_MAX_PACKET_SIZE) {\r
+      Sent = USB3_DEBUG_PORT_WRITE_MAX_PACKET_SIZE;\r
     } else {\r
       Sent = (UINT8)(NumberOfBytes - Total);\r
     }\r
@@ -1084,7 +1090,6 @@ DebugPortPollBuffer (
   USB3_DEBUG_PORT_HANDLE     *UsbDebugPortHandle;\r
   UINTN                     Length;\r
   RETURN_STATUS             Status;\r
-  UINT8                     Buffer[XHC_DEBUG_PORT_DATA_LENGTH];\r
   EFI_PHYSICAL_ADDRESS      XhciMmioBase;\r
 \r
   //\r
@@ -1120,12 +1125,12 @@ DebugPortPollBuffer (
   }\r
 \r
   //\r
-  // Read most 8-bytes data\r
+  // Read data as much as we can\r
   //\r
-  Length = XHC_DEBUG_PORT_DATA_LENGTH;\r
-  XhcDataTransfer (Handle, EfiUsbDataIn, Buffer, &Length, DATA_TRANSFER_POLL_TIMEOUT);\r
+  Length = XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE;\r
+  XhcDataTransfer (Handle, EfiUsbDataIn, (VOID *)(UINTN)UsbDebugPortHandle->Data, &Length, DATA_TRANSFER_POLL_TIMEOUT);\r
 \r
-  if (Length > 8) {\r
+  if (Length > XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE) {\r
     return FALSE;\r
   }\r
 \r
@@ -1136,7 +1141,6 @@ DebugPortPollBuffer (
   //\r
   // Store data into internal buffer for use later\r
   //\r
-  CopyMem (UsbDebugPortHandle->Data, Buffer, Length);\r
   UsbDebugPortHandle->DataCount = (UINT8) Length;\r
   return TRUE;\r
 }\r