]> www.infradead.org Git - users/hch/misc.git/commitdiff
drm/xe/pf: Set VF LMEM BAR size
authorMichał Winiarski <michal.winiarski@intel.com>
Tue, 27 May 2025 12:06:37 +0000 (14:06 +0200)
committerRodrigo Vivi <rodrigo.vivi@intel.com>
Thu, 14 Aug 2025 14:30:53 +0000 (10:30 -0400)
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>
(cherry picked from commit 32a4d1b98e6663101fd0abfaf151c48feea7abb1)
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
drivers/gpu/drm/xe/regs/xe_bars.h
drivers/gpu/drm/xe/xe_pci_sriov.c

index ce05b6ae832f17b0c0799aed436b23dc0a2f518d..880140d6ccdcae544aa256a624d4a5548034c25c 100644 (file)
@@ -7,5 +7,6 @@
 
 #define GTTMMADR_BAR                   0 /* MMIO + GTT */
 #define LMEM_BAR                       2 /* VRAM */
+#define VF_LMEM_BAR                    9 /* VF VRAM */
 
 #endif
index 447a7867eecbaffb9055eeb76afb6fa6e2e145dc..af05db07162e45b0f24a5fcf0fa8b8d2de0c59ab 100644 (file)
@@ -3,6 +3,10 @@
  * Copyright © 2023-2024 Intel Corporation
  */
 
+#include <linux/bitops.h>
+#include <linux/pci.h>
+
+#include "regs/xe_bars.h"
 #include "xe_assert.h"
 #include "xe_device.h"
 #include "xe_gt_sriov_pf_config.h"
@@ -128,6 +132,18 @@ static void pf_engine_activity_stats(struct xe_device *xe, unsigned int num_vfs,
        }
 }
 
+static int resize_vf_vram_bar(struct xe_device *xe, int num_vfs)
+{
+       struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
+       u32 sizes;
+
+       sizes = pci_iov_vf_bar_get_sizes(pdev, VF_LMEM_BAR, num_vfs);
+       if (!sizes)
+               return 0;
+
+       return pci_iov_vf_bar_set_size(pdev, VF_LMEM_BAR, __fls(sizes));
+}
+
 static int pf_enable_vfs(struct xe_device *xe, int num_vfs)
 {
        struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
@@ -158,6 +174,12 @@ static int pf_enable_vfs(struct xe_device *xe, int num_vfs)
        if (err < 0)
                goto failed;
 
+       if (IS_DGFX(xe)) {
+               err = resize_vf_vram_bar(xe, num_vfs);
+               if (err)
+                       xe_sriov_info(xe, "Failed to set VF LMEM BAR size: %d\n", err);
+       }
+
        err = pci_enable_sriov(pdev, num_vfs);
        if (err < 0)
                goto failed;