drm/radeon: handle vfct with multiple vbios images
authorAlex Deucher <alexander.deucher@amd.com>
Wed, 25 Jan 2017 20:33:44 +0000 (15:33 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 27 Jan 2017 17:20:41 +0000 (12:20 -0500)
The vfct table can contain multiple vbios images if the
platform contains multiple GPUs. Noticed by netkas on
phoronix forums.  This patch fixes those platforms.

Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Cc: stable@vger.kernel.org
drivers/gpu/drm/radeon/radeon_bios.c

index c829cfb02fc4c994a1167e9daa7b4c1010a97ab0..00cfb5d2875fd16f3038ca87e2d49d554905020f 100644 (file)
@@ -596,52 +596,58 @@ static bool radeon_read_disabled_bios(struct radeon_device *rdev)
 #ifdef CONFIG_ACPI
 static bool radeon_acpi_vfct_bios(struct radeon_device *rdev)
 {
-       bool ret = false;
        struct acpi_table_header *hdr;
        acpi_size tbl_size;
        UEFI_ACPI_VFCT *vfct;
-       GOP_VBIOS_CONTENT *vbios;
-       VFCT_IMAGE_HEADER *vhdr;
+       unsigned offset;
 
        if (!ACPI_SUCCESS(acpi_get_table("VFCT", 1, &hdr)))
                return false;
        tbl_size = hdr->length;
        if (tbl_size < sizeof(UEFI_ACPI_VFCT)) {
                DRM_ERROR("ACPI VFCT table present but broken (too short #1)\n");
-               goto out_unmap;
+               return false;
        }
 
        vfct = (UEFI_ACPI_VFCT *)hdr;
-       if (vfct->VBIOSImageOffset + sizeof(VFCT_IMAGE_HEADER) > tbl_size) {
-               DRM_ERROR("ACPI VFCT table present but broken (too short #2)\n");
-               goto out_unmap;
-       }
+       offset = vfct->VBIOSImageOffset;
 
-       vbios = (GOP_VBIOS_CONTENT *)((char *)hdr + vfct->VBIOSImageOffset);
-       vhdr = &vbios->VbiosHeader;
-       DRM_INFO("ACPI VFCT contains a BIOS for %02x:%02x.%d %04x:%04x, size %d\n",
-                       vhdr->PCIBus, vhdr->PCIDevice, vhdr->PCIFunction,
-                       vhdr->VendorID, vhdr->DeviceID, vhdr->ImageLength);
-
-       if (vhdr->PCIBus != rdev->pdev->bus->number ||
-           vhdr->PCIDevice != PCI_SLOT(rdev->pdev->devfn) ||
-           vhdr->PCIFunction != PCI_FUNC(rdev->pdev->devfn) ||
-           vhdr->VendorID != rdev->pdev->vendor ||
-           vhdr->DeviceID != rdev->pdev->device) {
-               DRM_INFO("ACPI VFCT table is not for this card\n");
-               goto out_unmap;
-       }
+       while (offset < tbl_size) {
+               GOP_VBIOS_CONTENT *vbios = (GOP_VBIOS_CONTENT *)((char *)hdr + offset);
+               VFCT_IMAGE_HEADER *vhdr = &vbios->VbiosHeader;
 
-       if (vfct->VBIOSImageOffset + sizeof(VFCT_IMAGE_HEADER) + vhdr->ImageLength > tbl_size) {
-               DRM_ERROR("ACPI VFCT image truncated\n");
-               goto out_unmap;
-       }
+               offset += sizeof(VFCT_IMAGE_HEADER);
+               if (offset > tbl_size) {
+                       DRM_ERROR("ACPI VFCT image header truncated\n");
+                       return false;
+               }
 
-       rdev->bios = kmemdup(&vbios->VbiosContent, vhdr->ImageLength, GFP_KERNEL);
-       ret = !!rdev->bios;
+               offset += vhdr->ImageLength;
+               if (offset > tbl_size) {
+                       DRM_ERROR("ACPI VFCT image truncated\n");
+                       return false;
+               }
+
+               if (vhdr->ImageLength &&
+                   vhdr->PCIBus == rdev->pdev->bus->number &&
+                   vhdr->PCIDevice == PCI_SLOT(rdev->pdev->devfn) &&
+                   vhdr->PCIFunction == PCI_FUNC(rdev->pdev->devfn) &&
+                   vhdr->VendorID == rdev->pdev->vendor &&
+                   vhdr->DeviceID == rdev->pdev->device) {
+                       rdev->bios = kmemdup(&vbios->VbiosContent,
+                                            vhdr->ImageLength,
+                                            GFP_KERNEL);
+
+                       if (!rdev->bios) {
+                               kfree(rdev->bios);
+                               return false;
+                       }
+                       return true;
+               }
+       }
 
-out_unmap:
-       return ret;
+       DRM_ERROR("ACPI VFCT table present but broken (too short #2)\n");
+       return false;
 }
 #else
 static inline bool radeon_acpi_vfct_bios(struct radeon_device *rdev)