Revision: 16762
          http://sourceforge.net/p/edk2/code/16762
Author:   li-elvin
Date:     2015-02-05 01:15:09 +0000 (Thu, 05 Feb 2015)
Log Message:
-----------
Use MaxPacketSize as the initial buffer size to read data.

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...@intel.com>
Reviewed-by: Feng Tian <feng.t...@intel.com>

Modified Paths:
--------------
    
trunk/edk2/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c
    
trunk/edk2/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Internal.h
    
trunk/edk2/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Transfer.c

Modified: 
trunk/edk2/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c
===================================================================
--- 
trunk/edk2/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c
  2015-02-05 01:00:53 UTC (rev 16761)
+++ 
trunk/edk2/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c
  2015-02-05 01:15:09 UTC (rev 16762)
@@ -1,7 +1,7 @@
 /** @file
   Debug Port Library implementation based on usb3 debug port.
 
-  Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
   which accompanies this distribution.  The full text of the license may be 
found at
@@ -571,7 +571,7 @@
   //
   DebugCapabilityContext->EpOutContext.CErr             = 0x3;
   DebugCapabilityContext->EpOutContext.EPType           = ED_BULK_OUT;
-  DebugCapabilityContext->EpOutContext.MaxPacketSize    = 0x400;
+  DebugCapabilityContext->EpOutContext.MaxPacketSize    = 
XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE;
   DebugCapabilityContext->EpOutContext.AverageTRBLength = 0x1000;
   
   //
@@ -579,7 +579,7 @@
   //
   DebugCapabilityContext->EpInContext.CErr             = 0x3;
   DebugCapabilityContext->EpInContext.EPType           = ED_BULK_IN;
-  DebugCapabilityContext->EpInContext.MaxPacketSize    = 0x400;
+  DebugCapabilityContext->EpInContext.MaxPacketSize    = 
XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE;
   DebugCapabilityContext->EpInContext.AverageTRBLength = 0x1000;
   
   //
@@ -709,9 +709,11 @@
   }
 
   //
-  // Initialize for PEI phase when AllocatePages can work
+  // Initialize for PEI phase when AllocatePages can work.
+  // Allocate data buffer with max packet size for data read and data poll.
+  // Allocate data buffer for data write.
   //
-  Buffer = AllocateAlignBuffer (XHC_DEBUG_PORT_DATA_LENGTH);
+  Buffer = AllocateAlignBuffer (XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE * 2 + 
USB3_DEBUG_PORT_WRITE_MAX_PACKET_SIZE);
   if (Buffer == NULL) {
     //
     // AllocatePages can not still work now, return fail and do not initialize 
now.
@@ -728,10 +730,11 @@
   }
 
   //
-  // Construct the buffer for URB in and URB out
+  // Construct the buffer for read, poll and write.
   //
   Handle->UrbIn.Data  = (EFI_PHYSICAL_ADDRESS)(UINTN) Buffer;
-  Handle->UrbOut.Data = (EFI_PHYSICAL_ADDRESS)(UINTN) Buffer + 
XHC_DEBUG_PORT_DATA_LENGTH;
+  Handle->Data        = (EFI_PHYSICAL_ADDRESS)(UINTN) Buffer + 
XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE;
+  Handle->UrbOut.Data = Handle->UrbIn.Data + XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE 
* 2;
    
   //
   // Initialize event ring
@@ -831,6 +834,7 @@
   UINT64                    TimeoutTicker;
   UINT64                    TimerRound;
   EFI_PHYSICAL_ADDRESS      XhciMmioBase;
+  UINT8                     *Data;
 
   if (NumberOfBytes == 0 || Buffer == NULL) {
     return 0;
@@ -864,6 +868,8 @@
     }
   }
 
+  Data = (UINT8 *)(UINTN)UsbDebugPortHandle->Data;
+
   //
   // First read data from buffer, then read debug port hw to get received data.
   //
@@ -875,14 +881,14 @@
     }
 
     for (Index = 0; Index < Total; Index++) {
-      Buffer[Index] = UsbDebugPortHandle->Data[Index];
+      Buffer[Index] = Data[Index];
     }
 
     for (Index = 0; Index < UsbDebugPortHandle->DataCount - Total; Index++) {
-      if (Total + Index >= 8) {
+      if (Total + Index >= XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE) {
         return 0;
       }
-      UsbDebugPortHandle->Data[Index] = UsbDebugPortHandle->Data[Total + 
Index];
+      Data[Index] = Data[Total + Index];
     }
     UsbDebugPortHandle->DataCount = (UINT8)(UsbDebugPortHandle->DataCount - 
(UINT8)Total);
   }
@@ -928,12 +934,12 @@
       }
     }
     Remaining = NumberOfBytes - Total;
-    if (Remaining >= USB3_DEBUG_PORT_MAX_PACKET_SIZE) {
-      Received = USB3_DEBUG_PORT_MAX_PACKET_SIZE;
+    if (Remaining >= XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE) {
+      Received = XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE;
       Status = XhcDataTransfer (UsbDebugPortHandle, EfiUsbDataIn, Buffer + 
Total, &Received, DATA_TRANSFER_READ_TIMEOUT);
     } else {
-      Received = USB3_DEBUG_PORT_MAX_PACKET_SIZE;
-      Status = XhcDataTransfer (UsbDebugPortHandle, EfiUsbDataIn, 
&UsbDebugPortHandle->Data[0], &Received, DATA_TRANSFER_READ_TIMEOUT);
+      Received = XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE;
+      Status = XhcDataTransfer (UsbDebugPortHandle, EfiUsbDataIn, (VOID 
*)Data, &Received, DATA_TRANSFER_READ_TIMEOUT);
       UsbDebugPortHandle->DataCount = (UINT8) Received;
 
       if (Remaining <= Received) {
@@ -952,7 +958,7 @@
       // Copy required data from the data buffer to user buffer.
       //
       for (Index = 0; Index < Length; Index++) {
-        (Buffer + Total)[Index] = UsbDebugPortHandle->Data[Index];
+        (Buffer + Total)[Index] = Data[Index];
         UsbDebugPortHandle->DataCount--;
       }
 
@@ -960,10 +966,10 @@
       // reorder the data buffer to make available data arranged from the 
beginning of the data buffer.
       //
       for (Index = 0; Index < Received - Length; Index++) {
-        if (Length + Index >= 8) {
+        if (Length + Index >= XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE) {
           return 0;
         }
-        UsbDebugPortHandle->Data[Index] = UsbDebugPortHandle->Data[Length + 
Index];
+        Data[Index] = Data[Length + Index];
       }
       //
       // fixup the real required length of data.
@@ -1050,8 +1056,8 @@
 
   Index = 0;
   while ((Total < NumberOfBytes)) {
-    if (NumberOfBytes - Total > USB3_DEBUG_PORT_MAX_PACKET_SIZE) {
-      Sent = USB3_DEBUG_PORT_MAX_PACKET_SIZE;
+    if (NumberOfBytes - Total > USB3_DEBUG_PORT_WRITE_MAX_PACKET_SIZE) {
+      Sent = USB3_DEBUG_PORT_WRITE_MAX_PACKET_SIZE;
     } else {
       Sent = (UINT8)(NumberOfBytes - Total);
     }
@@ -1084,7 +1090,6 @@
   USB3_DEBUG_PORT_HANDLE     *UsbDebugPortHandle;
   UINTN                     Length;
   RETURN_STATUS             Status;
-  UINT8                     Buffer[XHC_DEBUG_PORT_DATA_LENGTH];
   EFI_PHYSICAL_ADDRESS      XhciMmioBase;
 
   //
@@ -1120,12 +1125,12 @@
   }
 
   //
-  // Read most 8-bytes data
+  // Read data as much as we can
   //
-  Length = XHC_DEBUG_PORT_DATA_LENGTH;
-  XhcDataTransfer (Handle, EfiUsbDataIn, Buffer, &Length, 
DATA_TRANSFER_POLL_TIMEOUT);
+  Length = XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE;
+  XhcDataTransfer (Handle, EfiUsbDataIn, (VOID 
*)(UINTN)UsbDebugPortHandle->Data, &Length, DATA_TRANSFER_POLL_TIMEOUT);
 
-  if (Length > 8) {
+  if (Length > XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE) {
     return FALSE;
   }
 
@@ -1136,7 +1141,6 @@
   //
   // Store data into internal buffer for use later
   //
-  CopyMem (UsbDebugPortHandle->Data, Buffer, Length);
   UsbDebugPortHandle->DataCount = (UINT8) Length;
   return TRUE;
 }

Modified: 
trunk/edk2/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Internal.h
===================================================================
--- 
trunk/edk2/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Internal.h
        2015-02-05 01:00:53 UTC (rev 16761)
+++ 
trunk/edk2/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Internal.h
        2015-02-05 01:15:09 UTC (rev 16762)
@@ -1,7 +1,7 @@
 /** @file
   Debug Port Library implementation based on usb3 debug port.
 
-  Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
   which accompanies this distribution.  The full text of the license may be 
found at
@@ -30,15 +30,8 @@
 #include <Library/TimerLib.h>
 #include <Library/DebugCommunicationLib.h>
 #include <Library/PciLib.h>
-#include <Library/SerialPortLib.h>      // Todo: remove in future
 
 //
-// Internal serial debug - remove finally
-//
-#include <Library/SerialPortLib.h>
-#include <Library/PrintLib.h>
-
-//
 // USB Debug GUID value
 //
 #define USB3_DBG_GUID \
@@ -54,8 +47,13 @@
 #define USB3DBG_ENABLED       2   // The XHCI debug device is enabled
 #define USB3DBG_NOT_ENABLED   4   // The XHCI debug device is not enabled
 
-#define USB3_DEBUG_PORT_MAX_PACKET_SIZE 0x08
+#define USB3_DEBUG_PORT_WRITE_MAX_PACKET_SIZE 0x08
 
+//
+// MaxPacketSize for DbC Endpoint Descriptor IN and OUT
+//
+#define XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE    0x400
+
 #define XHCI_DEBUG_DEVICE_VENDOR_ID   0x0525
 #define XHCI_DEBUG_DEVICE_PRODUCT_ID  0x127A
 #define XHCI_DEBUG_DEVICE_PROTOCOL    0xFF
@@ -80,11 +78,6 @@
 #define XHC_USBSTS_HALT               BIT0
 
 //
-// Transfer the data of 8 bytes each time
-//
-#define XHC_DEBUG_PORT_DATA_LENGTH   8
-
-//
 // Indicate the timeout when data is transferred in microsecond. 0 means 
infinite timeout.
 //
 #define DATA_TRANSFER_WRITE_TIMEOUT      0
@@ -528,9 +521,9 @@
   //
   UINT8                                   DataCount;
   //
-  // The data buffer. Maximum length is 8 bytes.
+  // The data buffer address for data read and poll.
   //
-  UINT8                                   Data[8];
+  EFI_PHYSICAL_ADDRESS                    Data;
   //
   // Timter settings
   //

Modified: 
trunk/edk2/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Transfer.c
===================================================================
--- 
trunk/edk2/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Transfer.c
        2015-02-05 01:00:53 UTC (rev 16761)
+++ 
trunk/edk2/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Transfer.c
        2015-02-05 01:15:09 UTC (rev 16762)
@@ -1,7 +1,7 @@
 /** @file
   Debug Port Library implementation based on usb3 debug port.
 
-  Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
   which accompanies this distribution.  The full text of the license may be 
found at
@@ -262,7 +262,7 @@
       // Internal buffer is used by next read.
       //
       Handle->DataCount = (UINT8) (Handle->UrbIn.DataLen - EvtTrb->Length);
-      CopyMem (Handle->Data, (VOID *)(UINTN)Handle->UrbIn.Data, 
Handle->DataCount);
+      CopyMem ((VOID *)(UINTN)Handle->Data, (VOID *)(UINTN)Handle->UrbIn.Data, 
Handle->DataCount);
       //
       // Fill this TRB complete with CycleBit, otherwise next read will fail 
with old TRB.
       //
@@ -460,7 +460,6 @@
 
   Urb->Trb = EPRing->RingEnqueue;
   Trb = (TRB *)(UINTN)EPRing->RingEnqueue;
-  Trb = (TRB *)(UINTN)EPRing->RingEnqueue;
   Trb->TrbNormal.TRBPtrLo  = XHC_LOW_32BIT (Urb->Data);
   Trb->TrbNormal.TRBPtrHi  = XHC_HIGH_32BIT (Urb->Data);
   Trb->TrbNormal.Length    = Urb->DataLen;


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
edk2-commits mailing list
edk2-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to