Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/xe/pf: Set VF LMEM BAR size

LMEM is partitioned between multiple VFs and we expect that the more
VFs we have, the less LMEM is assigned to each VF.
This means that we can achieve full LMEM BAR access without the need to
attempt full VF LMEM BAR resize via pci_resize_resource().

Always try to set the largest possible BAR size that allows to fit the
number of enabled VFs and inform the user in case the resize attempt is
not successful.

Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://lore.kernel.org/r/20250527120637.665506-7-michal.winiarski@intel.com
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>

authored by

Michał Winiarski and committed by
Lucas De Marchi
32a4d1b9 ca994e89

+23
+1
drivers/gpu/drm/xe/regs/xe_bars.h
··· 7 7 8 8 #define GTTMMADR_BAR 0 /* MMIO + GTT */ 9 9 #define LMEM_BAR 2 /* VRAM */ 10 + #define VF_LMEM_BAR 9 /* VF VRAM */ 10 11 11 12 #endif
+22
drivers/gpu/drm/xe/xe_pci_sriov.c
··· 3 3 * Copyright © 2023-2024 Intel Corporation 4 4 */ 5 5 6 + #include <linux/bitops.h> 7 + #include <linux/pci.h> 8 + 9 + #include "regs/xe_bars.h" 6 10 #include "xe_assert.h" 7 11 #include "xe_device.h" 8 12 #include "xe_gt_sriov_pf_config.h" ··· 132 128 } 133 129 } 134 130 131 + static int resize_vf_vram_bar(struct xe_device *xe, int num_vfs) 132 + { 133 + struct pci_dev *pdev = to_pci_dev(xe->drm.dev); 134 + u32 sizes; 135 + 136 + sizes = pci_iov_vf_bar_get_sizes(pdev, VF_LMEM_BAR, num_vfs); 137 + if (!sizes) 138 + return 0; 139 + 140 + return pci_iov_vf_bar_set_size(pdev, VF_LMEM_BAR, __fls(sizes)); 141 + } 142 + 135 143 static int pf_enable_vfs(struct xe_device *xe, int num_vfs) 136 144 { 137 145 struct pci_dev *pdev = to_pci_dev(xe->drm.dev); ··· 173 157 err = pf_provision_vfs(xe, num_vfs); 174 158 if (err < 0) 175 159 goto failed; 160 + 161 + if (IS_DGFX(xe)) { 162 + err = resize_vf_vram_bar(xe, num_vfs); 163 + if (err) 164 + xe_sriov_info(xe, "Failed to set VF LMEM BAR size: %d\n", err); 165 + } 176 166 177 167 err = pci_enable_sriov(pdev, num_vfs); 178 168 if (err < 0)