]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/EhciDxe: factor out EhcIsDebugPortInUse()
authorLaszlo Ersek <lersek@redhat.com>
Wed, 5 Sep 2018 17:06:19 +0000 (19:06 +0200)
committerLaszlo Ersek <lersek@redhat.com>
Thu, 6 Sep 2018 12:07:50 +0000 (14:07 +0200)
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>
MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c
MdeModulePkg/Bus/Pci/EhciDxe/Ehci.h
MdeModulePkg/Bus/Pci/EhciDxe/EhciReg.c
MdeModulePkg/Bus/Pci/EhciDxe/EhciReg.h

index 89ed034b9093151e839b06e323f5a7121c3be9d6..50b5598df4fb9c6fb3252cd1330dc040897cfa2a 100644 (file)
@@ -121,7 +121,6 @@ EhcReset (
   USB2_HC_DEV             *Ehc;\r
   EFI_TPL                 OldTpl;\r
   EFI_STATUS              Status;\r
-  UINT32                  DbgCtrlStatus;\r
 \r
   Ehc = EHC_FROM_THIS (This);\r
 \r
@@ -147,12 +146,9 @@ EhcReset (
     //\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
@@ -345,7 +341,6 @@ EhcGetRootHubPortStatus (
   UINTN                   Index;\r
   UINTN                   MapSize;\r
   EFI_STATUS              Status;\r
-  UINT32                  DbgCtrlStatus;\r
 \r
   if (PortStatus == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -367,11 +362,8 @@ EhcGetRootHubPortStatus (
   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
@@ -1696,7 +1688,6 @@ EhcDriverBindingStart (
   UINTN                   EhciBusNumber;\r
   UINTN                   EhciDeviceNumber;\r
   UINTN                   EhciFunctionNumber;\r
-  UINT32                  State;\r
   EFI_DEVICE_PATH_PROTOCOL  *HcDevicePath;\r
 \r
   //\r
@@ -1918,13 +1909,8 @@ EhcDriverBindingStart (
     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
index f7556754f8ead8399221a5a6227d4edf934f304f..d7fbecb43003f048b126d2097bf3c7eae6bcad51 100644 (file)
@@ -77,6 +77,8 @@ typedef struct _USB2_HC_DEV  USB2_HC_DEV;
 #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
index 59752d1bdc649ba213af3465d58bf73cc38a2349..11c36132fd4f77a57b6f4cc4926c7e931a04bdc9 100644 (file)
@@ -65,7 +65,7 @@ EhcReadCapRegister (
 **/\r
 UINT32\r
 EhcReadDbgRegister (\r
-  IN  USB2_HC_DEV         *Ehc,\r
+  IN  CONST USB2_HC_DEV   *Ehc,\r
   IN  UINT32              Offset\r
   )\r
 {\r
@@ -90,6 +90,59 @@ EhcReadDbgRegister (
 }\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
index 2347ee125fa72f95b35dddbd79f865e16e130c48..1ee12455b8d058cebfe394fc738a69906a320244 100644 (file)
@@ -137,19 +137,28 @@ EhcReadCapRegister (
   );\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