/** @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
//\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
//\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
}\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
}\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
UINT64 TimeoutTicker;\r
UINT64 TimerRound;\r
EFI_PHYSICAL_ADDRESS XhciMmioBase;\r
+ UINT8 *Data;\r
\r
if (NumberOfBytes == 0 || Buffer == NULL) {\r
return 0;\r
}\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
}\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
}\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
// 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
// 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
\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
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
}\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
//\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