USB2_HC_DEV *Ehc;\r
EFI_TPL OldTpl;\r
EFI_STATUS Status;\r
- UINT32 DbgCtrlStatus;\r
\r
Ehc = EHC_FROM_THIS (This);\r
\r
//\r
// Host Controller must be Halt when Reset it\r
//\r
- if (Ehc->DebugPortNum != 0) {\r
- DbgCtrlStatus = EhcReadDbgRegister(Ehc, 0);\r
- if ((DbgCtrlStatus & (USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_OWNER)) == (USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_OWNER)) {\r
- Status = EFI_SUCCESS;\r
- goto ON_EXIT;\r
- }\r
+ if (EhcIsDebugPortInUse (Ehc, NULL)) {\r
+ Status = EFI_SUCCESS;\r
+ goto ON_EXIT;\r
}\r
\r
if (!EhcIsHalt (Ehc)) {\r
UINTN Index;\r
UINTN MapSize;\r
EFI_STATUS Status;\r
- UINT32 DbgCtrlStatus;\r
\r
if (PortStatus == NULL) {\r
return EFI_INVALID_PARAMETER;\r
PortStatus->PortStatus = 0;\r
PortStatus->PortChangeStatus = 0;\r
\r
- if ((Ehc->DebugPortNum != 0) && (PortNumber == (Ehc->DebugPortNum - 1))) {\r
- DbgCtrlStatus = EhcReadDbgRegister(Ehc, 0);\r
- if ((DbgCtrlStatus & (USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_OWNER)) == (USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_OWNER)) {\r
- goto ON_EXIT;\r
- }\r
+ if (EhcIsDebugPortInUse (Ehc, &PortNumber)) {\r
+ goto ON_EXIT;\r
}\r
\r
State = EhcReadOpReg (Ehc, Offset);\r
UINTN EhciBusNumber;\r
UINTN EhciDeviceNumber;\r
UINTN EhciFunctionNumber;\r
- UINT32 State;\r
EFI_DEVICE_PATH_PROTOCOL *HcDevicePath;\r
\r
//\r
EhcClearLegacySupport (Ehc);\r
}\r
\r
- if (Ehc->DebugPortNum == 0) {\r
+ if (!EhcIsDebugPortInUse (Ehc, NULL)) {\r
EhcResetHC (Ehc, EHC_RESET_TIMEOUT);\r
- } else {\r
- State = EhcReadDbgRegister(Ehc, 0);\r
- if ((State & (USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_OWNER)) != (USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_OWNER)) {\r
- EhcResetHC (Ehc, EHC_RESET_TIMEOUT);\r
- }\r
}\r
\r
Status = EhcInitHC (Ehc);\r
#define USB_DEBUG_PORT_IN_USE BIT10\r
#define USB_DEBUG_PORT_ENABLE BIT28\r
#define USB_DEBUG_PORT_OWNER BIT30\r
+#define USB_DEBUG_PORT_IN_USE_MASK (USB_DEBUG_PORT_IN_USE | \\r
+ USB_DEBUG_PORT_OWNER)\r
\r
//\r
// EHC raises TPL to TPL_NOTIFY to serialize all its operations\r
**/\r
UINT32\r
EhcReadDbgRegister (\r
- IN USB2_HC_DEV *Ehc,\r
+ IN CONST USB2_HC_DEV *Ehc,\r
IN UINT32 Offset\r
)\r
{\r
}\r
\r
\r
+/**\r
+ Check whether the host controller has an in-use debug port.\r
+\r
+ @param[in] Ehc The Enhanced Host Controller to query.\r
+\r
+ @param[in] PortNumber If PortNumber is not NULL, then query whether\r
+ PortNumber is an in-use debug port on Ehc. (PortNumber\r
+ is taken in UEFI notation, i.e., zero-based.)\r
+ Otherwise, query whether Ehc has any in-use debug\r
+ port.\r
+\r
+ @retval TRUE PortNumber is an in-use debug port on Ehc (if PortNumber is\r
+ not NULL), or some port on Ehc is an in-use debug port\r
+ (otherwise).\r
+\r
+ @retval FALSE PortNumber is not an in-use debug port on Ehc (if PortNumber\r
+ is not NULL), or no port on Ehc is an in-use debug port\r
+ (otherwise).\r
+**/\r
+BOOLEAN\r
+EhcIsDebugPortInUse (\r
+ IN CONST USB2_HC_DEV *Ehc,\r
+ IN CONST UINT8 *PortNumber OPTIONAL\r
+ )\r
+{\r
+ UINT32 State;\r
+\r
+ if (Ehc->DebugPortNum == 0) {\r
+ //\r
+ // The host controller has no debug port.\r
+ //\r
+ return FALSE;\r
+ }\r
+\r
+ //\r
+ // The Debug Port Number field in HCSPARAMS is one-based.\r
+ //\r
+ if (PortNumber != NULL && *PortNumber != Ehc->DebugPortNum - 1) {\r
+ //\r
+ // The caller specified a port, but it's not the debug port of the host\r
+ // controller.\r
+ //\r
+ return FALSE;\r
+ }\r
+\r
+ //\r
+ // Deduce usage from the Control Register.\r
+ //\r
+ State = EhcReadDbgRegister(Ehc, 0);\r
+ return (State & USB_DEBUG_PORT_IN_USE_MASK) == USB_DEBUG_PORT_IN_USE_MASK;\r
+}\r
+\r
+\r
/**\r
Read EHCI Operation register.\r
\r
);\r
\r
/**\r
- Read EHCI debug port register.\r
+ Check whether the host controller has an in-use debug port.\r
\r
- @param Ehc The EHCI device.\r
- @param Offset Debug port register address.\r
+ @param[in] Ehc The Enhanced Host Controller to query.\r
+\r
+ @param[in] PortNumber If PortNumber is not NULL, then query whether\r
+ PortNumber is an in-use debug port on Ehc. (PortNumber\r
+ is taken in UEFI notation, i.e., zero-based.)\r
+ Otherwise, query whether Ehc has any in-use debug\r
+ port.\r
\r
- @return The register content read.\r
- @retval If err, return 0xffff.\r
+ @retval TRUE PortNumber is an in-use debug port on Ehc (if PortNumber is\r
+ not NULL), or some port on Ehc is an in-use debug port\r
+ (otherwise).\r
\r
+ @retval FALSE PortNumber is not an in-use debug port on Ehc (if PortNumber\r
+ is not NULL), or no port on Ehc is an in-use debug port\r
+ (otherwise).\r
**/\r
-UINT32\r
-EhcReadDbgRegister (\r
- IN USB2_HC_DEV *Ehc,\r
- IN UINT32 Offset\r
+BOOLEAN\r
+EhcIsDebugPortInUse (\r
+ IN CONST USB2_HC_DEV *Ehc,\r
+ IN CONST UINT8 *PortNumber OPTIONAL\r
);\r
\r
/**\r