From: Gaurav Jain Date: Tue, 25 Feb 2020 12:00:41 +0000 (+0800) Subject: MdeModulePkg/Pci: Fixed Asserts in SCT PCIIO Protocol Test. X-Git-Tag: edk2-stable202005~354 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=3b9cd714542a8744252d973e1f163222a9f21b9e;hp=9bfaa3da1ee553ee40f584e47aa6418d7d83460d MdeModulePkg/Pci: Fixed Asserts in SCT PCIIO Protocol Test. ASSERT in PollMem_Conf, CopyMem_Conf, SetBarAttributes_Conf Conformance Test. SCT Test expect return as Invalid Parameter or Unsupported. Added Checks for Function Parameters. return Invalid or Unsupported if Check fails. Added Checks in PciIoPollIo(), PciIoIoRead() PciIoIoWrite() Signed-off-by: Gaurav Jain Reviewed-by: Hao A Wu --- diff --git a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c index 2d55c96993..c3e83003a0 100644 --- a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c +++ b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c @@ -93,6 +93,31 @@ PciIoPollMem ( OUT UINT64 *Result ) { + NON_DISCOVERABLE_PCI_DEVICE *Dev; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc; + UINTN Count; + EFI_STATUS Status; + + if ((UINT32)Width > EfiPciIoWidthUint64) { + return EFI_INVALID_PARAMETER; + } + + if (Result == NULL) { + return EFI_INVALID_PARAMETER; + } + + Dev = NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + Count = 1; + + Status = GetBarResource (Dev, BarIndex, &Desc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (Offset + (Count << (Width & 0x3)) > Desc->AddrLen) { + return EFI_UNSUPPORTED; + } + ASSERT (FALSE); return EFI_UNSUPPORTED; } @@ -126,6 +151,31 @@ PciIoPollIo ( OUT UINT64 *Result ) { + NON_DISCOVERABLE_PCI_DEVICE *Dev; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc; + UINTN Count; + EFI_STATUS Status; + + if ((UINT32)Width > EfiPciIoWidthUint64) { + return EFI_INVALID_PARAMETER; + } + + if (Result == NULL) { + return EFI_INVALID_PARAMETER; + } + + Dev = NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + Count = 1; + + Status = GetBarResource (Dev, BarIndex, &Desc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (Offset + (Count << (Width & 0x3)) > Desc->AddrLen) { + return EFI_UNSUPPORTED; + } + ASSERT (FALSE); return EFI_UNSUPPORTED; } @@ -396,6 +446,29 @@ PciIoIoRead ( IN OUT VOID *Buffer ) { + NON_DISCOVERABLE_PCI_DEVICE *Dev; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc; + EFI_STATUS Status; + + if ((UINT32)Width >= EfiPciIoWidthMaximum) { + return EFI_INVALID_PARAMETER; + } + + if (Buffer == NULL) { + return EFI_INVALID_PARAMETER; + } + + Dev = NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + + Status = GetBarResource (Dev, BarIndex, &Desc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (Offset + (Count << (Width & 0x3)) > Desc->AddrLen) { + return EFI_UNSUPPORTED; + } + ASSERT (FALSE); return EFI_UNSUPPORTED; } @@ -425,6 +498,29 @@ PciIoIoWrite ( IN OUT VOID *Buffer ) { + NON_DISCOVERABLE_PCI_DEVICE *Dev; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc; + EFI_STATUS Status; + + if ((UINT32)Width >= EfiPciIoWidthMaximum) { + return EFI_INVALID_PARAMETER; + } + + if (Buffer == NULL) { + return EFI_INVALID_PARAMETER; + } + + Dev = NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + + Status = GetBarResource (Dev, BarIndex, &Desc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (Offset + (Count << (Width & 0x3)) > Desc->AddrLen) { + return EFI_UNSUPPORTED; + } + ASSERT (FALSE); return EFI_UNSUPPORTED; } @@ -556,6 +652,35 @@ PciIoCopyMem ( IN UINTN Count ) { + NON_DISCOVERABLE_PCI_DEVICE *Dev; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *DestDesc; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *SrcDesc; + EFI_STATUS Status; + + if ((UINT32)Width > EfiPciIoWidthUint64) { + return EFI_INVALID_PARAMETER; + } + + Dev = NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + + Status = GetBarResource (Dev, DestBarIndex, &DestDesc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (DestOffset + (Count << (Width & 0x3)) > DestDesc->AddrLen) { + return EFI_UNSUPPORTED; + } + + Status = GetBarResource (Dev, SrcBarIndex, &SrcDesc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (SrcOffset + (Count << (Width & 0x3)) > SrcDesc->AddrLen) { + return EFI_UNSUPPORTED; + } + ASSERT (FALSE); return EFI_UNSUPPORTED; } @@ -1265,9 +1390,6 @@ PciIoAttributes ( NON_DISCOVERABLE_PCI_DEVICE *Dev; BOOLEAN Enable; - #define DEV_SUPPORTED_ATTRIBUTES \ - (EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE) - Dev = NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); if ((Attributes & (~(DEV_SUPPORTED_ATTRIBUTES))) != 0) { @@ -1414,6 +1536,33 @@ PciIoSetBarAttributes ( IN OUT UINT64 *Length ) { + NON_DISCOVERABLE_PCI_DEVICE *Dev; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc; + EFI_PCI_IO_PROTOCOL_WIDTH Width; + UINTN Count; + EFI_STATUS Status; + + if ((Attributes & (~DEV_SUPPORTED_ATTRIBUTES)) != 0) { + return EFI_UNSUPPORTED; + } + + if (Offset == NULL || Length == NULL) { + return EFI_INVALID_PARAMETER; + } + + Dev = NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + Width = EfiPciIoWidthUint8; + Count = (UINT32) *Length; + + Status = GetBarResource(Dev, BarIndex, &Desc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (*Offset + (Count << (Width & 0x3)) > Desc->AddrLen) { + return EFI_UNSUPPORTED; + } + ASSERT (FALSE); return EFI_UNSUPPORTED; } diff --git a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.h b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.h index 6511fbb137..15541c2811 100644 --- a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.h +++ b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.h @@ -30,6 +30,9 @@ CR (PciIoPointer, NON_DISCOVERABLE_PCI_DEVICE, PciIo, \ NON_DISCOVERABLE_PCI_DEVICE_SIG) +#define DEV_SUPPORTED_ATTRIBUTES \ + (EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE) + #define PCI_ID_VENDOR_UNKNOWN 0xffff #define PCI_ID_DEVICE_DONTCARE 0x0000