]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Use MaxPacketSize as the initial buffer size to read data.
authorElvin Li <elvin.li@intel.com>
Thu, 5 Feb 2015 01:15:09 +0000 (01:15 +0000)
committerli-elvin <li-elvin@Edk2>
Thu, 5 Feb 2015 01:15:09 +0000 (01:15 +0000)
If host sends more than 8 bytes of data, BABBLE error would happen if USB3 debug library uses 8 byte of buffer to read data.
We need use MaxPacketSize in USB3 debug descriptor to create buffer and read data into this buffer.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Elvin Li <elvin.li@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16762 6f19259b-4bc3-4df7-8a09-765794883524

SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c
SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Internal.h
SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Transfer.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
index 2f2025075a11438e8d67e4309ac4450ea4cd67a8..9190853c568282c91f78d52cb9d55b7eb58f1277 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
 #include <Library/TimerLib.h>\r
 #include <Library/DebugCommunicationLib.h>\r
 #include <Library/PciLib.h>\r
-#include <Library/SerialPortLib.h>      // Todo: remove in future\r
-\r
-//\r
-// Internal serial debug - remove finally\r
-//\r
-#include <Library/SerialPortLib.h>\r
-#include <Library/PrintLib.h>\r
 \r
 //\r
 // USB Debug GUID value\r
 #define USB3DBG_ENABLED       2   // The XHCI debug device is enabled\r
 #define USB3DBG_NOT_ENABLED   4   // The XHCI debug device is not enabled\r
 \r
-#define USB3_DEBUG_PORT_MAX_PACKET_SIZE 0x08\r
+#define USB3_DEBUG_PORT_WRITE_MAX_PACKET_SIZE 0x08\r
+\r
+//\r
+// MaxPacketSize for DbC Endpoint Descriptor IN and OUT\r
+//\r
+#define XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE    0x400\r
 \r
 #define XHCI_DEBUG_DEVICE_VENDOR_ID   0x0525\r
 #define XHCI_DEBUG_DEVICE_PRODUCT_ID  0x127A\r
 \r
 #define XHC_USBSTS_HALT               BIT0\r
 \r
-//\r
-// Transfer the data of 8 bytes each time\r
-//\r
-#define XHC_DEBUG_PORT_DATA_LENGTH   8\r
-\r
 //\r
 // Indicate the timeout when data is transferred in microsecond. 0 means infinite timeout.\r
 //\r
@@ -528,9 +521,9 @@ typedef struct _USB3_DEBUG_PORT_INSTANCE {
   //\r
   UINT8                                   DataCount;\r
   //\r
-  // The data buffer. Maximum length is 8 bytes.\r
+  // The data buffer address for data read and poll.\r
   //\r
-  UINT8                                   Data[8];\r
+  EFI_PHYSICAL_ADDRESS                    Data;\r
   //\r
   // Timter settings\r
   //\r
index 73963e11990e07d4249e094047452fbb1a7a8764..deb802e4adf4d9cd35a3fe6445de77190e6d6d28 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
@@ -262,7 +262,7 @@ XhcCheckUrbResult (
       // Internal buffer is used by next read.\r
       //\r
       Handle->DataCount = (UINT8) (Handle->UrbIn.DataLen - EvtTrb->Length);\r
-      CopyMem (Handle->Data, (VOID *)(UINTN)Handle->UrbIn.Data, Handle->DataCount);\r
+      CopyMem ((VOID *)(UINTN)Handle->Data, (VOID *)(UINTN)Handle->UrbIn.Data, Handle->DataCount);\r
       //\r
       // Fill this TRB complete with CycleBit, otherwise next read will fail with old TRB.\r
       //\r
@@ -460,7 +460,6 @@ XhcCreateTransferTrb (
 \r
   Urb->Trb = EPRing->RingEnqueue;\r
   Trb = (TRB *)(UINTN)EPRing->RingEnqueue;\r
-  Trb = (TRB *)(UINTN)EPRing->RingEnqueue;\r
   Trb->TrbNormal.TRBPtrLo  = XHC_LOW_32BIT (Urb->Data);\r
   Trb->TrbNormal.TRBPtrHi  = XHC_HIGH_32BIT (Urb->Data);\r
   Trb->TrbNormal.Length    = Urb->DataLen;\r