summaryrefslogtreecommitdiff
path: root/SourceLevelDebugPkg
diff options
context:
space:
mode:
authorElvin Li <elvin.li@intel.com>2015-02-05 01:15:09 +0000
committerli-elvin <li-elvin@Edk2>2015-02-05 01:15:09 +0000
commit5d6507a14687f133d2ab8643ad274b22e578a907 (patch)
treec19ee5a67097ec18f175a4d9626a0d3cd6f682cc /SourceLevelDebugPkg
parent4b4a068cd4cc21d767a25d6f1e966dac12acd4fd (diff)
downloadedk2-platforms-5d6507a14687f133d2ab8643ad274b22e578a907.tar.xz
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.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
Diffstat (limited to 'SourceLevelDebugPkg')
-rw-r--r--SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c54
-rw-r--r--SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Internal.h25
-rw-r--r--SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Transfer.c5
3 files changed, 40 insertions, 44 deletions
diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c
index fe6aec1ca5..320998b32a 100644
--- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c
+++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c
@@ -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 @@ CreateDebugCapabilityContext (
//
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 @@ CreateDebugCapabilityContext (
//
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 @@ InitializeUsbDebugHardware (
}
//
- // 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 @@ InitializeUsbDebugHardware (
}
//
- // 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 @@ DebugPortReadBuffer (
UINT64 TimeoutTicker;
UINT64 TimerRound;
EFI_PHYSICAL_ADDRESS XhciMmioBase;
+ UINT8 *Data;
if (NumberOfBytes == 0 || Buffer == NULL) {
return 0;
@@ -864,6 +868,8 @@ DebugPortReadBuffer (
}
}
+ Data = (UINT8 *)(UINTN)UsbDebugPortHandle->Data;
+
//
// First read data from buffer, then read debug port hw to get received data.
//
@@ -875,14 +881,14 @@ DebugPortReadBuffer (
}
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 @@ DebugPortReadBuffer (
}
}
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 @@ DebugPortReadBuffer (
// 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 @@ DebugPortReadBuffer (
// 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 @@ DebugPortWriteBuffer (
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 @@ DebugPortPollBuffer (
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 @@ DebugPortPollBuffer (
}
//
- // 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 @@ DebugPortPollBuffer (
//
// Store data into internal buffer for use later
//
- CopyMem (UsbDebugPortHandle->Data, Buffer, Length);
UsbDebugPortHandle->DataCount = (UINT8) Length;
return TRUE;
}
diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Internal.h b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Internal.h
index 2f2025075a..9190853c56 100644
--- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Internal.h
+++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Internal.h
@@ -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,13 +30,6 @@
#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
@@ -54,7 +47,12 @@
#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
@@ -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 @@ typedef struct _USB3_DEBUG_PORT_INSTANCE {
//
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
//
diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Transfer.c b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Transfer.c
index 73963e1199..deb802e4ad 100644
--- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Transfer.c
+++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Transfer.c
@@ -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 @@ XhcCheckUrbResult (
// 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 @@ XhcCreateTransferTrb (
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;