On Wed, 17 Sep 2025, Lucas De Marchi wrote: > Now that xe_pci.c calls the rebar directly, it doens't make sense to > keep it in xe_vram.c since it's closer to the PCI initialization than to > the vram. Move it to its own file. > > While at it, add a better comment to document the possible values for > the vram_bar_size module parameter. > > Signed-off-by: Lucas De Marchi <lucas.demar...@intel.com> > --- > drivers/gpu/drm/xe/Makefile | 1 + > drivers/gpu/drm/xe/xe_pci.c | 3 +- > drivers/gpu/drm/xe/xe_pci_rebar.c | 125 > ++++++++++++++++++++++++++++++++++++++ > drivers/gpu/drm/xe/xe_pci_rebar.h | 13 ++++ > drivers/gpu/drm/xe/xe_vram.c | 109 --------------------------------- > drivers/gpu/drm/xe/xe_vram.h | 1 - > 6 files changed, 141 insertions(+), 111 deletions(-) > > diff --git a/drivers/gpu/drm/xe/Makefile b/drivers/gpu/drm/xe/Makefile > index 7a065c98a3b85..5a66d7a53d0db 100644 > --- a/drivers/gpu/drm/xe/Makefile > +++ b/drivers/gpu/drm/xe/Makefile > @@ -95,6 +95,7 @@ xe-y += xe_bb.o \ > xe_observation.o \ > xe_pat.o \ > xe_pci.o \ > + xe_pci_rebar.o \ > xe_pcode.o \ > xe_pm.o \ > xe_preempt_fence.o \ > diff --git a/drivers/gpu/drm/xe/xe_pci.c b/drivers/gpu/drm/xe/xe_pci.c > index 1f4120b535137..6cc5e7b6901a8 100644 > --- a/drivers/gpu/drm/xe/xe_pci.c > +++ b/drivers/gpu/drm/xe/xe_pci.c > @@ -27,6 +27,7 @@ > #include "xe_macros.h" > #include "xe_mmio.h" > #include "xe_module.h" > +#include "xe_pci_rebar.h" > #include "xe_pci_sriov.h" > #include "xe_pci_types.h" > #include "xe_pm.h" > @@ -866,7 +867,7 @@ static int xe_pci_probe(struct pci_dev *pdev, const > struct pci_device_id *ent) > if (err) > return err; > > - xe_vram_resize_bar(xe); > + xe_pci_rebar(xe); > > err = xe_device_probe_early(xe); > /* > diff --git a/drivers/gpu/drm/xe/xe_pci_rebar.c > b/drivers/gpu/drm/xe/xe_pci_rebar.c > new file mode 100644 > index 0000000000000..e04416630b573 > --- /dev/null > +++ b/drivers/gpu/drm/xe/xe_pci_rebar.c > @@ -0,0 +1,125 @@ > +// SPDX-License-Identifier: MIT > +/* > + * Copyright © 2025 Intel Corporation > + */ > + > +#include "xe_pci_rebar.h" > + > +#include <linux/pci.h> > +#include <linux/types.h> > + > +#include <drm/drm_print.h> > + > +#include "regs/xe_bars.h" > +#include "xe_device_types.h" > +#include "xe_module.h" > + > +#define BAR_SIZE_SHIFT 20 > + > +static void release_bars(struct pci_dev *pdev) > +{ > + int resno; > + > + for (resno = PCI_STD_RESOURCES; resno < PCI_STD_RESOURCE_END; resno++) { > + if (pci_resource_len(pdev, resno)) > + pci_release_resource(pdev, resno); > + } > +} > + > +static void resize_bar(struct xe_device *xe, int resno, resource_size_t size) > +{ > + struct pci_dev *pdev = to_pci_dev(xe->drm.dev); > + int bar_size = pci_rebar_bytes_to_size(size); > + int ret; > + > + release_bars(pdev); > + > + ret = pci_resize_resource(pdev, resno, bar_size); > + if (ret) { > + drm_info(&xe->drm, "Failed to resize BAR%d to %dM (%pe). > Consider enabling 'Resizable BAR' support in your BIOS\n", > + resno, 1 << bar_size, ERR_PTR(ret)); > + return; > + } > + > + drm_info(&xe->drm, "BAR%d resized to %dM\n", resno, 1 << bar_size); > +} > + > +void xe_pci_rebar(struct xe_device *xe) > +{ > + int force_vram_bar_size = xe_modparam.force_vram_bar_size; > + struct pci_dev *pdev = to_pci_dev(xe->drm.dev); > + struct pci_bus *root = pdev->bus; > + resource_size_t current_size; > + resource_size_t rebar_size; > + struct resource *root_res; > + u32 bar_size_mask; > + u32 pci_cmd; > + int i; > + > + /* gather some relevant info */ > + current_size = pci_resource_len(pdev, LMEM_BAR); > + bar_size_mask = pci_rebar_get_possible_sizes(pdev, LMEM_BAR); > + > + if (!bar_size_mask) > + return; > + > + /* > + * Handle force_vram_bar_size: > + * - negative: resize is disabled > + * - 0: try to resize to maximum possible > + * - positive: resize to specific value > + */ > + if (force_vram_bar_size < 0) > + return; > + > + if (force_vram_bar_size) { > + u32 bar_size_bit; > + > + rebar_size = force_vram_bar_size * (resource_size_t)SZ_1M; > + > + bar_size_bit = bar_size_mask & > BIT(pci_rebar_bytes_to_size(rebar_size)); > + > + if (!bar_size_bit) { > + drm_info(&xe->drm, > + "Requested size: %lluMiB is not supported by > rebar sizes: 0x%x. Leaving default: %lluMiB\n", > + (u64)rebar_size >> 20, bar_size_mask, > (u64)current_size >> 20); > + return; > + } > + > + rebar_size = 1ULL << (__fls(bar_size_bit) + BAR_SIZE_SHIFT); > + > + if (rebar_size == current_size) > + return; > + } else { > + rebar_size = 1ULL << (__fls(bar_size_mask) + BAR_SIZE_SHIFT); > + > + /* only resize if larger than current */ > + if (rebar_size <= current_size) > + return; > + } > + > + drm_info(&xe->drm, "Attempting to resize bar from %lluMiB -> %lluMiB\n", > + (u64)current_size >> 20, (u64)rebar_size >> 20);
BTW, if you want to do additional cleanups, all these 20 could be replaced with ilog(SZ_1M) as it makes more obvious where that number comes from. But this conflicts anyway with my rebar rework series so perhaps this is not the best time for such cleanup. -- i.