From: Christian König Date: Tue, 23 Apr 2019 09:50:00 +0000 (+0200) Subject: PCI: Restore resized BAR state on resume X-Git-Tag: Ubuntu-4.15.0-51.55~26 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=2b2e00eb353bd13907ed607c458ade5d2db5abb5;p=mirror_ubuntu-bionic-kernel.git PCI: Restore resized BAR state on resume BugLink: https://bugs.launchpad.net/bugs/1825958 Resize BARs after resume to the expected size again. BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=199959 Fixes: d6895ad39f3b ("drm/amdgpu: resize VRAM BAR for CPU access v6") Fixes: 276b738deb5b ("PCI: Add resizable BAR infrastructure") Signed-off-by: Christian König Signed-off-by: Bjorn Helgaas CC: stable@vger.kernel.org # v4.15+ (cherry picked from commit d3252ace0bc652a1a244455556b6a549f969bf99) Signed-off-by: You-Sheng Yang Acked-By: AceLan Kao Acked-by: Kleber Sacilotto de Souza Signed-off-by: Kleber Sacilotto de Souza --- diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 7e600b75d186..e04b375da9f0 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1170,6 +1170,33 @@ static void pci_restore_config_space(struct pci_dev *pdev) } } +static void pci_restore_rebar_state(struct pci_dev *pdev) +{ + unsigned int pos, nbars, i; + u32 ctrl; + + pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_REBAR); + if (!pos) + return; + + pci_read_config_dword(pdev, pos + PCI_REBAR_CTRL, &ctrl); + nbars = (ctrl & PCI_REBAR_CTRL_NBAR_MASK) >> + PCI_REBAR_CTRL_NBAR_SHIFT; + + for (i = 0; i < nbars; i++, pos += 8) { + struct resource *res; + int bar_idx, size; + + pci_read_config_dword(pdev, pos + PCI_REBAR_CTRL, &ctrl); + bar_idx = ctrl & PCI_REBAR_CTRL_BAR_IDX; + res = pdev->resource + bar_idx; + size = order_base_2((resource_size(res) >> 20) | 1) - 1; + ctrl &= ~PCI_REBAR_CTRL_BAR_SIZE; + ctrl |= size << 8; + pci_write_config_dword(pdev, pos + PCI_REBAR_CTRL, ctrl); + } +} + /** * pci_restore_state - Restore the saved state of a PCI device * @dev: - PCI device that we're dealing with @@ -1185,6 +1212,7 @@ void pci_restore_state(struct pci_dev *dev) pci_restore_pri_state(dev); pci_restore_ats_state(dev); pci_restore_vc_state(dev); + pci_restore_rebar_state(dev); pci_cleanup_aer_error_status_regs(dev);