Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d3252ace authored by Christian König's avatar Christian König Committed by Bjorn Helgaas
Browse files

PCI: Restore resized BAR state on resume

Resize BARs after resume to the expected size again.

BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=199959


Fixes: d6895ad3 ("drm/amdgpu: resize VRAM BAR for CPU access v6")
Fixes: 276b738d ("PCI: Add resizable BAR infrastructure")
Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
CC: stable@vger.kernel.org      # v4.15+
parent 93c9a7f8
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -1171,6 +1171,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
@@ -1186,6 +1213,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);