Skip to content

Commit 21723da

Browse files
Lucas De Marchigregkh
authored andcommitted
drm/xe: Move rebar to be done earlier
[ Upstream commit d30203739be798d3de5c84db3060e96f00c54e82 ] There may be cases in which the BAR0 also needs to move to accommodate the bigger BAR2. However if it's not released, the BAR2 resize fails. During the vram probe it can't be released as it's already in use by xe_mmio for early register access. Add a new function in xe_vram and let xe_pci call it directly before even early device probe. This allows the BAR2 to resize in cases BAR0 also needs to move, assuming there aren't other reasons to hold that move: [] xe 0000:03:00.0: vgaarb: deactivate vga console [] xe 0000:03:00.0: [drm] Attempting to resize bar from 8192MiB -> 16384MiB [] xe 0000:03:00.0: BAR 0 [mem 0x83000000-0x83ffffff 64bit]: releasing [] xe 0000:03:00.0: BAR 2 [mem 0x4000000000-0x41ffffffff 64bit pref]: releasing [] pcieport 0000:02:01.0: bridge window [mem 0x4000000000-0x41ffffffff 64bit pref]: releasing [] pcieport 0000:01:00.0: bridge window [mem 0x4000000000-0x41ffffffff 64bit pref]: releasing [] pcieport 0000:01:00.0: bridge window [mem 0x4000000000-0x43ffffffff 64bit pref]: assigned [] pcieport 0000:02:01.0: bridge window [mem 0x4000000000-0x43ffffffff 64bit pref]: assigned [] xe 0000:03:00.0: BAR 2 [mem 0x4000000000-0x43ffffffff 64bit pref]: assigned [] xe 0000:03:00.0: BAR 0 [mem 0x83000000-0x83ffffff 64bit]: assigned [] pcieport 0000:00:01.0: PCI bridge to [bus 01-04] [] pcieport 0000:00:01.0: bridge window [mem 0x83000000-0x840fffff] [] pcieport 0000:00:01.0: bridge window [mem 0x4000000000-0x44007fffff 64bit pref] [] pcieport 0000:01:00.0: PCI bridge to [bus 02-04] [] pcieport 0000:01:00.0: bridge window [mem 0x83000000-0x840fffff] [] pcieport 0000:01:00.0: bridge window [mem 0x4000000000-0x43ffffffff 64bit pref] [] pcieport 0000:02:01.0: PCI bridge to [bus 03] [] pcieport 0000:02:01.0: bridge window [mem 0x83000000-0x83ffffff] [] pcieport 0000:02:01.0: bridge window [mem 0x4000000000-0x43ffffffff 64bit pref] [] xe 0000:03:00.0: [drm] BAR2 resized to 16384M [] xe 0000:03:00.0: [drm:xe_pci_probe [xe]] BATTLEMAGE e221:0000 dgfx:1 gfx:Xe2_HPG (20.02) ... For BMG there are additional fix needed in the PCI side, but this helps getting it to a working resize. All the rebar logic is more pci-specific than xe-specific and can be done very early in the probe sequence. In future it would be good to move it out of xe_vram.c, but this refactor is left for later. Cc: Ilpo Järvinen <[email protected]> Cc: [email protected] # 6.12+ Link: https://lore.kernel.org/intel-xe/[email protected] Reviewed-by: Ilpo Järvinen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lucas De Marchi <[email protected]> (cherry picked from commit 45e33f220fd625492c11e15733d8e9b4f9db82a4) Signed-off-by: Lucas De Marchi <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5a99274 commit 21723da

3 files changed

Lines changed: 29 additions & 8 deletions

File tree

drivers/gpu/drm/xe/xe_pci.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,8 @@ static int xe_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
805805
if (err)
806806
return err;
807807

808+
xe_vram_resize_bar(xe);
809+
808810
err = xe_device_probe_early(xe);
809811
/*
810812
* In Boot Survivability mode, no drm card is exposed and driver

drivers/gpu/drm/xe/xe_vram.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,35 @@
2626

2727
#define BAR_SIZE_SHIFT 20
2828

29-
static void
30-
_resize_bar(struct xe_device *xe, int resno, resource_size_t size)
29+
/*
30+
* Release all the BARs that could influence/block LMEMBAR resizing, i.e.
31+
* assigned IORESOURCE_MEM_64 BARs
32+
*/
33+
static void release_bars(struct pci_dev *pdev)
34+
{
35+
struct resource *res;
36+
int i;
37+
38+
pci_dev_for_each_resource(pdev, res, i) {
39+
/* Resource already un-assigned, do not reset it */
40+
if (!res->parent)
41+
continue;
42+
43+
/* No need to release unrelated BARs */
44+
if (!(res->flags & IORESOURCE_MEM_64))
45+
continue;
46+
47+
pci_release_resource(pdev, i);
48+
}
49+
}
50+
51+
static void resize_bar(struct xe_device *xe, int resno, resource_size_t size)
3152
{
3253
struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
3354
int bar_size = pci_rebar_bytes_to_size(size);
3455
int ret;
3556

36-
if (pci_resource_len(pdev, resno))
37-
pci_release_resource(pdev, resno);
57+
release_bars(pdev);
3858

3959
ret = pci_resize_resource(pdev, resno, bar_size);
4060
if (ret) {
@@ -50,7 +70,7 @@ _resize_bar(struct xe_device *xe, int resno, resource_size_t size)
5070
* if force_vram_bar_size is set, attempt to set to the requested size
5171
* else set to maximum possible size
5272
*/
53-
static void resize_vram_bar(struct xe_device *xe)
73+
void xe_vram_resize_bar(struct xe_device *xe)
5474
{
5575
int force_vram_bar_size = xe_modparam.force_vram_bar_size;
5676
struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
@@ -119,7 +139,7 @@ static void resize_vram_bar(struct xe_device *xe)
119139
pci_read_config_dword(pdev, PCI_COMMAND, &pci_cmd);
120140
pci_write_config_dword(pdev, PCI_COMMAND, pci_cmd & ~PCI_COMMAND_MEMORY);
121141

122-
_resize_bar(xe, LMEM_BAR, rebar_size);
142+
resize_bar(xe, LMEM_BAR, rebar_size);
123143

124144
pci_assign_unassigned_bus_resources(pdev->bus);
125145
pci_write_config_dword(pdev, PCI_COMMAND, pci_cmd);
@@ -148,8 +168,6 @@ static int determine_lmem_bar_size(struct xe_device *xe, struct xe_vram_region *
148168
return -ENXIO;
149169
}
150170

151-
resize_vram_bar(xe);
152-
153171
lmem_bar->io_start = pci_resource_start(pdev, LMEM_BAR);
154172
lmem_bar->io_size = pci_resource_len(pdev, LMEM_BAR);
155173
if (!lmem_bar->io_size)

drivers/gpu/drm/xe/xe_vram.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
struct xe_device;
1212
struct xe_vram_region;
1313

14+
void xe_vram_resize_bar(struct xe_device *xe);
1415
int xe_vram_probe(struct xe_device *xe);
1516

1617
struct xe_vram_region *xe_vram_region_alloc(struct xe_device *xe, u8 id, u32 placement);

0 commit comments

Comments
 (0)