This allows BAR0 resizing to be done for cards which don't advertise support for a size large enough to cover the VRAM but which do advertise at least one size larger than the default. For example, my RX 5600 XT, which advertises 256MB, 512MB and 1GB. Signed-off-by: Darren Salt <devspam@xxxxxxxxxxxxxxxxx> --- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 44 +++++++++++++++++----- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index 355fa0057c26..ec3610b4110b 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -1078,6 +1078,11 @@ void amdgpu_device_wb_free(struct amdgpu_device *adev, u32 wb) __clear_bit(wb, adev->wb.used); } +static inline u32 bytes_to_size_pci(u64 bytes) +{ + return order_base_2(((bytes >> 20) | 1)) - 1; +} + /** * amdgpu_device_resize_fb_bar - try to resize FB BAR * @@ -1090,20 +1095,25 @@ void amdgpu_device_wb_free(struct amdgpu_device *adev, u32 wb) int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev) { u64 space_needed = roundup_pow_of_two(adev->gmc.real_vram_size); - u32 rbar_size = order_base_2(((space_needed >> 20) | 1)) - 1; + u32 rbar_size = bytes_to_size_pci(space_needed); struct pci_bus *root; struct resource *res; + u64 current_bytes; + u32 current_size; unsigned i; u16 cmd; int r; + bool nospc = false; /* Bypass for VF */ if (amdgpu_sriov_vf(adev)) return 0; - /* skip if the bios has already enabled large BAR */ - if (adev->gmc.real_vram_size && - (pci_resource_len(adev->pdev, 0) >= adev->gmc.real_vram_size)) + current_bytes = pci_resource_len(adev->pdev, 0); + current_size = bytes_to_size_pci(current_bytes); + + /* Skip if the BIOS has already enabled large BAR, covering the VRAM */ + if (current_size >= rbar_size) return 0; /* Check if the root BUS has 64bit memory resources */ @@ -1121,6 +1131,9 @@ int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev) if (!res) return 0; + dev_dbg(adev->dev, "BIOS-allocated BAR0 was %lluMB; trying to get %lluMB", + current_bytes >> 20, space_needed >> 20); + /* Disable memory decoding while we change the BAR addresses and size */ pci_read_config_word(adev->pdev, PCI_COMMAND, &cmd); pci_write_config_word(adev->pdev, PCI_COMMAND, @@ -1133,11 +1146,24 @@ int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev) pci_release_resource(adev->pdev, 0); - r = pci_resize_resource(adev->pdev, 0, rbar_size); - if (r == -ENOSPC) - DRM_INFO("Not enough PCI address space for a large BAR."); - else if (r && r != -ENOTSUPP) - DRM_ERROR("Problem resizing BAR0 (%d).", r); + while (rbar_size > current_size) { + r = pci_resize_resource(adev->pdev, 0, rbar_size); + if (r == 0 || r == -ENOTSUPP) { + break; + } else if (r == -ENOSPC) { + if (!nospc) { + /* Warn only the first time */ + dev_info(adev->dev, "Not enough PCI address space for a large BAR."); + nospc = true; + } + --rbar_size; + } else if (r == -EINVAL) { + --rbar_size; + } else { + dev_err(adev->dev, "Problem resizing BAR0 (%d).", r); + break; + } + } pci_assign_unassigned_bus_resources(adev->pdev->bus); -- 2.20.1 _______________________________________________ amd-gfx mailing list amd-gfx@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/amd-gfx