/** @file\r
\r
-Copyright (c) 2007, Intel Corporation\r
+ EHCI transfer scheduling routines.\r
+\r
+Copyright (c) 2007 - 2009, Intel Corporation\r
All rights reserved. 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
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
\r
-Module Name:\r
-\r
- EhciSched.c\r
-\r
-Abstract:\r
-\r
- EHCI transfer scheduling routines\r
-\r
-Revision History\r
-\r
**/\r
\r
#include "Ehci.h"\r
\r
\r
/**\r
- Create helper QTD/QH for the EHCI device\r
+ Create helper QTD/QH for the EHCI device.\r
\r
- @param Ehc The EHCI device\r
+ @param Ehc The EHCI device.\r
\r
- @retval EFI_OUT_OF_RESOURCES Failed to allocate resource for helper QTD/QH\r
- @retval EFI_SUCCESS Helper QH/QTD are created\r
+ @retval EFI_OUT_OF_RESOURCES Failed to allocate resource for helper QTD/QH.\r
+ @retval EFI_SUCCESS Helper QH/QTD are created.\r
\r
**/\r
-STATIC\r
EFI_STATUS\r
EhcCreateHelpQ (\r
IN USB2_HC_DEV *Ehc\r
}\r
\r
\r
-\r
/**\r
- Initialize the schedule data structure such as frame list\r
+ Initialize the schedule data structure such as frame list.\r
\r
- @param Ehc The EHCI device to init schedule data for\r
+ @param Ehc The EHCI device to init schedule data.\r
\r
- @retval EFI_OUT_OF_RESOURCES Failed to allocate resource to init schedule data\r
- @retval EFI_SUCCESS The schedule data is initialized\r
+ @retval EFI_OUT_OF_RESOURCES Failed to allocate resource to init schedule data.\r
+ @retval EFI_SUCCESS The schedule data is initialized.\r
\r
**/\r
EFI_STATUS\r
}\r
\r
\r
-\r
/**\r
Free the schedule data. It may be partially initialized.\r
\r
- @param Ehc The EHCI device\r
-\r
- @return None\r
+ @param Ehc The EHCI device.\r
\r
**/\r
VOID\r
}\r
\r
\r
-\r
/**\r
Link the queue head to the asynchronous schedule list.\r
UEFI only supports one CTRL/BULK transfer at a time\r
management: A reclamation header is always linked to\r
the AsyncListAddr, the only active QH is appended to it.\r
\r
- @param Ehc The EHCI device\r
- @param Qh The queue head to link\r
-\r
- @return None\r
+ @param Ehc The EHCI device.\r
+ @param Qh The queue head to link.\r
\r
**/\r
VOID\r
\r
/**\r
Unlink a queue head from the asynchronous schedule list.\r
- Need to synchronize with hardware\r
-\r
- @param Ehc The EHCI device\r
- @param Qh The queue head to unlink\r
+ Need to synchronize with hardware.\r
\r
- @return None\r
+ @param Ehc The EHCI device.\r
+ @param Qh The queue head to unlink.\r
\r
**/\r
VOID\r
//\r
// Set and wait the door bell to synchronize with the hardware\r
//\r
- Status = EhcSetAndWaitDoorBell (Ehc, EHC_GENERIC_TIME);\r
+ Status = EhcSetAndWaitDoorBell (Ehc, EHC_GENERIC_TIMEOUT);\r
\r
if (EFI_ERROR (Status)) {\r
- EHC_ERROR (("EhcUnlinkQhFromAsync: Failed to synchronize with doorbell\n"));\r
+ DEBUG ((EFI_D_ERROR, "EhcUnlinkQhFromAsync: Failed to synchronize with doorbell\n"));\r
}\r
}\r
\r
schedule frame list. This code is very much the same as\r
that in UHCI.\r
\r
- @param Ehc The EHCI device\r
- @param Qh The queue head to link\r
-\r
- @return None\r
+ @param Ehc The EHCI device.\r
+ @param Qh The queue head to link.\r
\r
**/\r
VOID\r
\r
/**\r
Unlink an interrupt queue head from the periodic\r
- schedule frame list\r
-\r
- @param Ehc The EHCI device\r
- @param Qh The queue head to unlink\r
+ schedule frame list.\r
\r
- @return None\r
+ @param Ehc The EHCI device.\r
+ @param Qh The queue head to unlink.\r
\r
**/\r
VOID\r
}\r
\r
\r
-\r
/**\r
Check the URB's execution result and update the URB's\r
result accordingly.\r
\r
- @param Ehc The EHCI device\r
- @param Urb The URB to check result\r
+ @param Ehc The EHCI device.\r
+ @param Urb The URB to check result.\r
\r
@return Whether the result of URB transfer is finialized.\r
\r
**/\r
-STATIC\r
BOOLEAN\r
EhcCheckUrbResult (\r
IN USB2_HC_DEV *Ehc,\r
}\r
\r
if ((QtdHw->TotalBytes != 0) && (QtdHw->Pid == QTD_PID_INPUT)) {\r
- EHC_DUMP_QH ((Urb->Qh, "Short packet read", FALSE));\r
+ EhcDumpQh (Urb->Qh, "Short packet read", FALSE);\r
\r
//\r
// Short packet read condition. If it isn't a setup transfer,\r
// Status Stage of the setup transfer to get the finial result\r
//\r
if (QtdHw->AltNext == QTD_LINK (Ehc->ShortReadStop, FALSE)) {\r
- EHC_DEBUG (("EhcCheckUrbResult: Short packet read, break\n"));\r
+ DEBUG ((EFI_D_INFO, "EhcCheckUrbResult: Short packet read, break\n"));\r
\r
Finished = TRUE;\r
goto ON_EXIT;\r
}\r
\r
- EHC_DEBUG (("EhcCheckUrbResult: Short packet read, continue\n"));\r
+ DEBUG ((EFI_D_INFO, "EhcCheckUrbResult: Short packet read, continue\n"));\r
}\r
}\r
}\r
/**\r
Execute the transfer by polling the URB. This is a synchronous operation.\r
\r
- @param Ehc The EHCI device\r
- @param Urb The URB to execute\r
- @param TimeOut The time to wait before abort, in millisecond.\r
+ @param Ehc The EHCI device.\r
+ @param Urb The URB to execute.\r
+ @param TimeOut The time to wait before abort, in millisecond.\r
\r
- @return EFI_DEVICE_ERROR : The transfer failed due to transfer error\r
- @return EFI_TIMEOUT : The transfer failed due to time out\r
- @return EFI_SUCCESS : The transfer finished OK\r
+ @return EFI_DEVICE_ERROR The transfer failed due to transfer error.\r
+ @return EFI_TIMEOUT The transfer failed due to time out.\r
+ @return EFI_SUCCESS The transfer finished OK.\r
\r
**/\r
EFI_STATUS\r
BOOLEAN Finished;\r
\r
Status = EFI_SUCCESS;\r
- Loop = (TimeOut * EHC_STALL_1_MILLISECOND / EHC_SYNC_POLL_TIME) + 1;\r
+ Loop = (TimeOut * EHC_1_MILLISECOND / EHC_SYNC_POLL_INTERVAL) + 1;\r
Finished = FALSE;\r
\r
for (Index = 0; Index < Loop; Index++) {\r
break;\r
}\r
\r
- gBS->Stall (EHC_SYNC_POLL_TIME);\r
+ gBS->Stall (EHC_SYNC_POLL_INTERVAL);\r
}\r
\r
if (!Finished) {\r
- EHC_ERROR (("EhcExecTransfer: transfer not finished in %dms\n", TimeOut));\r
- EHC_DUMP_QH ((Urb->Qh, NULL, FALSE));\r
+ DEBUG ((EFI_D_ERROR, "EhcExecTransfer: transfer not finished in %dms\n", (UINT32)TimeOut));\r
+ EhcDumpQh (Urb->Qh, NULL, FALSE);\r
\r
Status = EFI_TIMEOUT;\r
\r
} else if (Urb->Result != EFI_USB_NOERROR) {\r
- EHC_ERROR (("EhcExecTransfer: transfer failed with %x\n", Urb->Result));\r
- EHC_DUMP_QH ((Urb->Qh, NULL, FALSE));\r
+ DEBUG ((EFI_D_ERROR, "EhcExecTransfer: transfer failed with %x\n", Urb->Result));\r
+ EhcDumpQh (Urb->Qh, NULL, FALSE);\r
\r
Status = EFI_DEVICE_ERROR;\r
}\r
\r
/**\r
Delete a single asynchronous interrupt transfer for\r
- the device and endpoint\r
+ the device and endpoint.\r
\r
- @param Ehc The EHCI device\r
- @param DevAddr The address of the target device\r
- @param EpNum The endpoint of the target\r
- @param DataToggle Return the next data toggle to use\r
+ @param Ehc The EHCI device.\r
+ @param DevAddr The address of the target device.\r
+ @param EpNum The endpoint of the target.\r
+ @param DataToggle Return the next data toggle to use.\r
\r
- @retval EFI_SUCCESS An asynchronous transfer is removed\r
- @retval EFI_NOT_FOUND No transfer for the device is found\r
+ @retval EFI_SUCCESS An asynchronous transfer is removed.\r
+ @retval EFI_NOT_FOUND No transfer for the device is found.\r
\r
**/\r
EFI_STATUS\r
URB *Urb;\r
EFI_USB_DATA_DIRECTION Direction;\r
\r
- Direction = ((EpNum & 0x80) ? EfiUsbDataIn : EfiUsbDataOut);\r
+ Direction = (((EpNum & 0x80) != 0) ? EfiUsbDataIn : EfiUsbDataOut);\r
EpNum &= 0x0F;\r
\r
EFI_LIST_FOR_EACH_SAFE (Entry, Next, &Ehc->AsyncIntTransfers) {\r
\r
\r
/**\r
- Remove all the asynchronous interrutp transfers\r
+ Remove all the asynchronous interrutp transfers.\r
\r
- @param Ehc The EHCI device\r
-\r
- @return None\r
+ @param Ehc The EHCI device.\r
\r
**/\r
VOID\r
}\r
\r
\r
-\r
/**\r
- Update the queue head for next round of asynchronous transfer\r
+ Flush data from PCI controller specific address to mapped system\r
+ memory address.\r
+\r
+ @param Ehc The EHCI device.\r
+ @param Urb The URB to unmap.\r
+\r
+ @retval EFI_SUCCESS Success to flush data to mapped system memory.\r
+ @retval EFI_DEVICE_ERROR Fail to flush data to mapped system memory.\r
+\r
+**/\r
+EFI_STATUS\r
+EhcFlushAsyncIntMap (\r
+ IN USB2_HC_DEV *Ehc,\r
+ IN URB *Urb\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_PHYSICAL_ADDRESS PhyAddr;\r
+ EFI_PCI_IO_PROTOCOL_OPERATION MapOp;\r
+ EFI_PCI_IO_PROTOCOL *PciIo;\r
+ UINTN Len;\r
+ VOID *Map;\r
+\r
+ PciIo = Ehc->PciIo;\r
+ Len = Urb->DataLen;\r
+\r
+ if (Urb->Ep.Direction == EfiUsbDataIn) {\r
+ MapOp = EfiPciIoOperationBusMasterWrite;\r
+ } else {\r
+ MapOp = EfiPciIoOperationBusMasterRead;\r
+ }\r
+\r
+ Status = PciIo->Unmap (PciIo, Urb->DataMap);\r
+ if (EFI_ERROR (Status)) {\r
+ goto ON_ERROR;\r
+ }\r
+\r
+ Urb->DataMap = NULL;\r
+\r
+ Status = PciIo->Map (PciIo, MapOp, Urb->Data, &Len, &PhyAddr, &Map);\r
+ if (EFI_ERROR (Status) || (Len != Urb->DataLen)) {\r
+ goto ON_ERROR;\r
+ }\r
\r
- @param Urb The URB to update\r
+ Urb->DataPhy = (VOID *) ((UINTN) PhyAddr);\r
+ Urb->DataMap = Map;\r
+ return EFI_SUCCESS;\r
+\r
+ON_ERROR:\r
+ return EFI_DEVICE_ERROR;\r
+}\r
+\r
+\r
+/**\r
+ Update the queue head for next round of asynchronous transfer.\r
\r
- @return None\r
+ @param Urb The URB to update.\r
\r
**/\r
-STATIC\r
VOID\r
EhcUpdateAsyncRequest (\r
IN URB *Urb\r
\r
\r
/**\r
- Interrupt transfer periodic check handler\r
+ Interrupt transfer periodic check handler.\r
\r
- @param Event Interrupt event\r
- @param Context Pointer to USB2_HC_DEV\r
-\r
- @return None\r
+ @param Event Interrupt event.\r
+ @param Context Pointer to USB2_HC_DEV.\r
\r
**/\r
VOID\r
-EhcMoniteAsyncRequests (\r
+EFIAPI\r
+EhcMonitorAsyncRequests (\r
IN EFI_EVENT Event,\r
IN VOID *Context\r
)\r
BOOLEAN Finished;\r
UINT8 *ProcBuf;\r
URB *Urb;\r
+ EFI_STATUS Status;\r
\r
OldTpl = gBS->RaiseTPL (EHC_TPL);\r
Ehc = (USB2_HC_DEV *) Context;\r
continue;\r
}\r
\r
+ //\r
+ // Flush any PCI posted write transactions from a PCI host\r
+ // bridge to system memory.\r
+ //\r
+ Status = EhcFlushAsyncIntMap (Ehc, Urb);\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((EFI_D_ERROR, "EhcMonitorAsyncRequests: Fail to Flush AsyncInt Mapped Memeory\n"));\r
+ }\r
+\r
//\r
// Allocate a buffer then copy the transferred data for user.\r
// If failed to allocate the buffer, update the URB for next\r
}\r
\r
if (ProcBuf != NULL) {\r
- gBS->FreePool (ProcBuf);\r
+ FreePool (ProcBuf);\r
}\r
}\r
\r