]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.c
SourceLevelDebugPkg: Check if PcdUsbEhciPciAddress is set correctly to avoid assertion
[mirror_edk2.git] / SourceLevelDebugPkg / Library / DebugCommunicationLibUsb / DebugCommunicationLibUsb.c
index 7fb671eb4b31368ff55a9a14b9589911ed409f51..567e06c9d36e9cfe8c43766a61840b2276183058 100644 (file)
@@ -164,9 +164,29 @@ CalculateUsbDebugPortBar (
  )\r
 {\r
   UINT16     PciStatus;\r
+  UINT16     VendorId;\r
+  UINT16     DeviceId;\r
+  UINT8      ProgInterface;\r
+  UINT8      SubClassCode;\r
+  UINT8      BaseCode;\r
   UINT8      CapabilityPtr;\r
   UINT8      CapabilityId;\r
 \r
+  VendorId = PciRead16 (PcdGet32(PcdUsbEhciPciAddress) + PCI_VENDOR_ID_OFFSET);\r
+  DeviceId = PciRead16 (PcdGet32(PcdUsbEhciPciAddress) + PCI_DEVICE_ID_OFFSET);\r
+  \r
+  if ((VendorId == 0xFFFF) || (DeviceId == 0xFFFF)) {\r
+    return RETURN_UNSUPPORTED;\r
+  }\r
+\r
+  ProgInterface = PciRead8 (PcdGet32(PcdUsbEhciPciAddress) + PCI_CLASSCODE_OFFSET);\r
+  SubClassCode  = PciRead8 (PcdGet32(PcdUsbEhciPciAddress) + PCI_CLASSCODE_OFFSET + 1);\r
+  BaseCode      = PciRead8 (PcdGet32(PcdUsbEhciPciAddress) + PCI_CLASSCODE_OFFSET + 2);\r
+  \r
+  if ((ProgInterface != PCI_IF_EHCI) || (SubClassCode != PCI_CLASS_SERIAL_USB) || (BaseCode != PCI_CLASS_SERIAL)) {\r
+    return RETURN_UNSUPPORTED;\r
+  }\r
+\r
   //\r
   // Enable Ehci Host Controller MMIO Space.\r
   //\r
@@ -1068,7 +1088,7 @@ DebugPortInitialize (
 \r
   Status = CalculateUsbDebugPortBar(&Handle.DebugPortOffset, &Handle.DebugPortBarNumber);\r
   if (RETURN_ERROR (Status)) {\r
-    DEBUG ((EFI_D_ERROR, "USB Debug Port: EHCI host controller does not support debug port capability!\n"));\r
+    DEBUG ((EFI_D_ERROR, "USB Debug Port: the pci device pointed by PcdUsbEhciPciAddress is not EHCI host controller or does not support debug port capability!\n"));\r
     goto Exit;\r
   }\r
 \r