From: erictian Date: Tue, 8 Nov 2011 06:12:06 +0000 (+0000) Subject: SourceLevelDebugPkg: Check if PcdUsbEhciPciAddress is set correctly to avoid assertion X-Git-Tag: edk2-stable201903~13935 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=f98c2685597a15bbc01637777b831717e52424fe SourceLevelDebugPkg: Check if PcdUsbEhciPciAddress is set correctly to avoid assertion Signed-off-by: erictian Reviewed-by: niruiyu Reviewed-by: vanjeff git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12670 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.c b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.c index 7fb671eb4b..567e06c9d3 100644 --- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.c +++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.c @@ -164,9 +164,29 @@ CalculateUsbDebugPortBar ( ) { UINT16 PciStatus; + UINT16 VendorId; + UINT16 DeviceId; + UINT8 ProgInterface; + UINT8 SubClassCode; + UINT8 BaseCode; UINT8 CapabilityPtr; UINT8 CapabilityId; + VendorId = PciRead16 (PcdGet32(PcdUsbEhciPciAddress) + PCI_VENDOR_ID_OFFSET); + DeviceId = PciRead16 (PcdGet32(PcdUsbEhciPciAddress) + PCI_DEVICE_ID_OFFSET); + + if ((VendorId == 0xFFFF) || (DeviceId == 0xFFFF)) { + return RETURN_UNSUPPORTED; + } + + ProgInterface = PciRead8 (PcdGet32(PcdUsbEhciPciAddress) + PCI_CLASSCODE_OFFSET); + SubClassCode = PciRead8 (PcdGet32(PcdUsbEhciPciAddress) + PCI_CLASSCODE_OFFSET + 1); + BaseCode = PciRead8 (PcdGet32(PcdUsbEhciPciAddress) + PCI_CLASSCODE_OFFSET + 2); + + if ((ProgInterface != PCI_IF_EHCI) || (SubClassCode != PCI_CLASS_SERIAL_USB) || (BaseCode != PCI_CLASS_SERIAL)) { + return RETURN_UNSUPPORTED; + } + // // Enable Ehci Host Controller MMIO Space. // @@ -1068,7 +1088,7 @@ DebugPortInitialize ( Status = CalculateUsbDebugPortBar(&Handle.DebugPortOffset, &Handle.DebugPortBarNumber); if (RETURN_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "USB Debug Port: EHCI host controller does not support debug port capability!\n")); + 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")); goto Exit; }