MdeModulePkg/EhciDxe: factor out EhcIsDebugPortInUse()

The EhcReset(), EhcGetRootHubPortStatus() and EhcDriverBindingStart()
functions need to see whether the host controller (or a specific port on
the host controller) can be accessed, dependent on the controller having
(or the specific port being) an in-use debug port. Because the condition
isn't simple, extract it to a separate function.

Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Suggested-by: Star Zeng <star.zeng@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
This commit is contained in:
Laszlo Ersek 2018-09-05 19:06:19 +02:00
parent 22cf747fcf
commit b48ec0e8ab
4 changed files with 80 additions and 30 deletions

View File

@ -121,7 +121,6 @@ EhcReset (
USB2_HC_DEV *Ehc; USB2_HC_DEV *Ehc;
EFI_TPL OldTpl; EFI_TPL OldTpl;
EFI_STATUS Status; EFI_STATUS Status;
UINT32 DbgCtrlStatus;
Ehc = EHC_FROM_THIS (This); Ehc = EHC_FROM_THIS (This);
@ -147,12 +146,9 @@ EhcReset (
// //
// Host Controller must be Halt when Reset it // Host Controller must be Halt when Reset it
// //
if (Ehc->DebugPortNum != 0) { if (EhcIsDebugPortInUse (Ehc, NULL)) {
DbgCtrlStatus = EhcReadDbgRegister(Ehc, 0); Status = EFI_SUCCESS;
if ((DbgCtrlStatus & (USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_OWNER)) == (USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_OWNER)) { goto ON_EXIT;
Status = EFI_SUCCESS;
goto ON_EXIT;
}
} }
if (!EhcIsHalt (Ehc)) { if (!EhcIsHalt (Ehc)) {
@ -345,7 +341,6 @@ EhcGetRootHubPortStatus (
UINTN Index; UINTN Index;
UINTN MapSize; UINTN MapSize;
EFI_STATUS Status; EFI_STATUS Status;
UINT32 DbgCtrlStatus;
if (PortStatus == NULL) { if (PortStatus == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
@ -367,11 +362,8 @@ EhcGetRootHubPortStatus (
PortStatus->PortStatus = 0; PortStatus->PortStatus = 0;
PortStatus->PortChangeStatus = 0; PortStatus->PortChangeStatus = 0;
if ((Ehc->DebugPortNum != 0) && (PortNumber == (Ehc->DebugPortNum - 1))) { if (EhcIsDebugPortInUse (Ehc, &PortNumber)) {
DbgCtrlStatus = EhcReadDbgRegister(Ehc, 0); goto ON_EXIT;
if ((DbgCtrlStatus & (USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_OWNER)) == (USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_OWNER)) {
goto ON_EXIT;
}
} }
State = EhcReadOpReg (Ehc, Offset); State = EhcReadOpReg (Ehc, Offset);
@ -1696,7 +1688,6 @@ EhcDriverBindingStart (
UINTN EhciBusNumber; UINTN EhciBusNumber;
UINTN EhciDeviceNumber; UINTN EhciDeviceNumber;
UINTN EhciFunctionNumber; UINTN EhciFunctionNumber;
UINT32 State;
EFI_DEVICE_PATH_PROTOCOL *HcDevicePath; EFI_DEVICE_PATH_PROTOCOL *HcDevicePath;
// //
@ -1918,13 +1909,8 @@ EhcDriverBindingStart (
EhcClearLegacySupport (Ehc); EhcClearLegacySupport (Ehc);
} }
if (Ehc->DebugPortNum == 0) { if (!EhcIsDebugPortInUse (Ehc, NULL)) {
EhcResetHC (Ehc, EHC_RESET_TIMEOUT); EhcResetHC (Ehc, EHC_RESET_TIMEOUT);
} else {
State = EhcReadDbgRegister(Ehc, 0);
if ((State & (USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_OWNER)) != (USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_OWNER)) {
EhcResetHC (Ehc, EHC_RESET_TIMEOUT);
}
} }
Status = EhcInitHC (Ehc); Status = EhcInitHC (Ehc);

View File

@ -77,6 +77,8 @@ typedef struct _USB2_HC_DEV USB2_HC_DEV;
#define USB_DEBUG_PORT_IN_USE BIT10 #define USB_DEBUG_PORT_IN_USE BIT10
#define USB_DEBUG_PORT_ENABLE BIT28 #define USB_DEBUG_PORT_ENABLE BIT28
#define USB_DEBUG_PORT_OWNER BIT30 #define USB_DEBUG_PORT_OWNER BIT30
#define USB_DEBUG_PORT_IN_USE_MASK (USB_DEBUG_PORT_IN_USE | \
USB_DEBUG_PORT_OWNER)
// //
// EHC raises TPL to TPL_NOTIFY to serialize all its operations // EHC raises TPL to TPL_NOTIFY to serialize all its operations

View File

@ -65,7 +65,7 @@ EhcReadCapRegister (
**/ **/
UINT32 UINT32
EhcReadDbgRegister ( EhcReadDbgRegister (
IN USB2_HC_DEV *Ehc, IN CONST USB2_HC_DEV *Ehc,
IN UINT32 Offset IN UINT32 Offset
) )
{ {
@ -90,6 +90,59 @@ EhcReadDbgRegister (
} }
/**
Check whether the host controller has an in-use debug port.
@param[in] Ehc The Enhanced Host Controller to query.
@param[in] PortNumber If PortNumber is not NULL, then query whether
PortNumber is an in-use debug port on Ehc. (PortNumber
is taken in UEFI notation, i.e., zero-based.)
Otherwise, query whether Ehc has any in-use debug
port.
@retval TRUE PortNumber is an in-use debug port on Ehc (if PortNumber is
not NULL), or some port on Ehc is an in-use debug port
(otherwise).
@retval FALSE PortNumber is not an in-use debug port on Ehc (if PortNumber
is not NULL), or no port on Ehc is an in-use debug port
(otherwise).
**/
BOOLEAN
EhcIsDebugPortInUse (
IN CONST USB2_HC_DEV *Ehc,
IN CONST UINT8 *PortNumber OPTIONAL
)
{
UINT32 State;
if (Ehc->DebugPortNum == 0) {
//
// The host controller has no debug port.
//
return FALSE;
}
//
// The Debug Port Number field in HCSPARAMS is one-based.
//
if (PortNumber != NULL && *PortNumber != Ehc->DebugPortNum - 1) {
//
// The caller specified a port, but it's not the debug port of the host
// controller.
//
return FALSE;
}
//
// Deduce usage from the Control Register.
//
State = EhcReadDbgRegister(Ehc, 0);
return (State & USB_DEBUG_PORT_IN_USE_MASK) == USB_DEBUG_PORT_IN_USE_MASK;
}
/** /**
Read EHCI Operation register. Read EHCI Operation register.

View File

@ -137,19 +137,28 @@ EhcReadCapRegister (
); );
/** /**
Read EHCI debug port register. Check whether the host controller has an in-use debug port.
@param Ehc The EHCI device. @param[in] Ehc The Enhanced Host Controller to query.
@param Offset Debug port register address.
@return The register content read. @param[in] PortNumber If PortNumber is not NULL, then query whether
@retval If err, return 0xffff. PortNumber is an in-use debug port on Ehc. (PortNumber
is taken in UEFI notation, i.e., zero-based.)
Otherwise, query whether Ehc has any in-use debug
port.
@retval TRUE PortNumber is an in-use debug port on Ehc (if PortNumber is
not NULL), or some port on Ehc is an in-use debug port
(otherwise).
@retval FALSE PortNumber is not an in-use debug port on Ehc (if PortNumber
is not NULL), or no port on Ehc is an in-use debug port
(otherwise).
**/ **/
UINT32 BOOLEAN
EhcReadDbgRegister ( EhcIsDebugPortInUse (
IN USB2_HC_DEV *Ehc, IN CONST USB2_HC_DEV *Ehc,
IN UINT32 Offset IN CONST UINT8 *PortNumber OPTIONAL
); );
/** /**