]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/EhciDxe/EhciReg.c
MdeModulePkg/EhciDxe: factor out EhcIsDebugPortInUse()
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / EhciDxe / EhciReg.c
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