Skip to content

Commit a91d1a1

Browse files
aabodunrinmatt-auld
authored andcommitted
drm/i915: Add support for LMEM PCIe resizable bar
Add support for the local memory PICe resizable bar, so that local memory can be resized to the maximum size supported by the device, and mapped correctly to the PCIe memory bar. It is usual that GPU devices expose only 256MB BARs primarily to be compatible with 32-bit systems. So, those devices cannot claim larger memory BAR windows size due to the system BIOS limitation. With this change, it would be possible to reprogram the windows of the bridge directly above the requesting device on the same BAR type. v2:Moved code to gt/intel_region_lmem.c and used only single underscore for function names.(Jani) v3: Optimised code. Signed-off-by: Akeem G Abodunrin <akeem.g.abodunrin@intel.com> Signed-off-by: Michał Winiarski <michal.winiarski@intel.com> Cc: Stuart Summers <stuart.summers@intel.com> Cc: Michael J Ruhl <michael.j.ruhl@intel.com> Cc: Prathap Kumar Valsan <prathap.kumar.valsan@intel.com> Cc: Jani Nikula <jani.nikula@intel.com> Signed-off-by: Priyanka Dandamudi <priyanka.dandamudi@intel.com> Reviewed-by: Matthew Auld <matthew.auld@intel.com> Reviewed-by: Nirmoy Das <nirmoy.das@intel.com> Signed-off-by: Matthew Auld <matthew.auld@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20220713130209.2573233-2-priyanka.dandamudi@intel.com
1 parent a5e4a53 commit a91d1a1

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

drivers/gpu/drm/i915/gt/intel_region_lmem.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,79 @@
1515
#include "gt/intel_gt_mcr.h"
1616
#include "gt/intel_gt_regs.h"
1717

18+
static void _release_bars(struct pci_dev *pdev)
19+
{
20+
int resno;
21+
22+
for (resno = PCI_STD_RESOURCES; resno < PCI_STD_RESOURCE_END; resno++) {
23+
if (pci_resource_len(pdev, resno))
24+
pci_release_resource(pdev, resno);
25+
}
26+
}
27+
28+
static void
29+
_resize_bar(struct drm_i915_private *i915, int resno, resource_size_t size)
30+
{
31+
struct pci_dev *pdev = to_pci_dev(i915->drm.dev);
32+
int bar_size = pci_rebar_bytes_to_size(size);
33+
int ret;
34+
35+
_release_bars(pdev);
36+
37+
ret = pci_resize_resource(pdev, resno, bar_size);
38+
if (ret) {
39+
drm_info(&i915->drm, "Failed to resize BAR%d to %dM (%pe)\n",
40+
resno, 1 << bar_size, ERR_PTR(ret));
41+
return;
42+
}
43+
44+
drm_info(&i915->drm, "BAR%d resized to %dM\n", resno, 1 << bar_size);
45+
}
46+
47+
#define LMEM_BAR_NUM 2
48+
static void i915_resize_lmem_bar(struct drm_i915_private *i915, resource_size_t lmem_size)
49+
{
50+
struct pci_dev *pdev = to_pci_dev(i915->drm.dev);
51+
struct pci_bus *root = pdev->bus;
52+
struct resource *root_res;
53+
resource_size_t rebar_size;
54+
u32 pci_cmd;
55+
int i;
56+
57+
rebar_size = roundup_pow_of_two(pci_resource_len(pdev, LMEM_BAR_NUM));
58+
59+
if (rebar_size != roundup_pow_of_two(lmem_size))
60+
rebar_size = lmem_size;
61+
else
62+
return;
63+
64+
/* Find out if root bus contains 64bit memory addressing */
65+
while (root->parent)
66+
root = root->parent;
67+
68+
pci_bus_for_each_resource(root, root_res, i) {
69+
if (root_res && root_res->flags & (IORESOURCE_MEM | IORESOURCE_MEM_64) &&
70+
root_res->start > 0x100000000ull)
71+
break;
72+
}
73+
74+
/* pci_resize_resource will fail anyways */
75+
if (!root_res) {
76+
drm_info(&i915->drm, "Can't resize LMEM BAR - platform support is missing\n");
77+
return;
78+
}
79+
80+
/* First disable PCI memory decoding references */
81+
pci_read_config_dword(pdev, PCI_COMMAND, &pci_cmd);
82+
pci_write_config_dword(pdev, PCI_COMMAND,
83+
pci_cmd & ~PCI_COMMAND_MEMORY);
84+
85+
_resize_bar(i915, LMEM_BAR_NUM, rebar_size);
86+
87+
pci_assign_unassigned_bus_resources(pdev->bus);
88+
pci_write_config_dword(pdev, PCI_COMMAND, pci_cmd);
89+
}
90+
1891
static int
1992
region_lmem_release(struct intel_memory_region *mem)
2093
{
@@ -128,6 +201,8 @@ static struct intel_memory_region *setup_lmem(struct intel_gt *gt)
128201
lmem_size = intel_uncore_read64(&i915->uncore, GEN12_GSMBASE);
129202
}
130203

204+
i915_resize_lmem_bar(i915, lmem_size);
205+
131206
if (i915->params.lmem_size > 0) {
132207
lmem_size = min_t(resource_size_t, lmem_size,
133208
mul_u32_u32(i915->params.lmem_size, SZ_1M));

0 commit comments

Comments
 (0)