]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/xe/pf: Add functions for VRAM provisioning
authorMichal Wajdeczko <michal.wajdeczko@intel.com>
Wed, 18 Feb 2026 20:55:45 +0000 (21:55 +0100)
committerMichal Wajdeczko <michal.wajdeczko@intel.com>
Fri, 20 Feb 2026 14:50:01 +0000 (15:50 +0100)
We already have functions to configure VF LMEM (aka VRAM) on the
tile/GT level, used by the auto-provisioning and debugfs, but we
also need functions that will work on the device level that will
configure VRAM on all tiles at once.

We will use these new functions in upcoming patch.

Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Reviewed-by: Piotr Piórkowski <piotr.piorkowski@intel.com>
Link: https://patch.msgid.link/20260218205553.3561-4-michal.wajdeczko@intel.com
drivers/gpu/drm/xe/xe_sriov_pf_provision.c
drivers/gpu/drm/xe/xe_sriov_pf_provision.h

index 01470c42e8a72f51843a6313423c63e8c4ba4fee..f22ff65c59aa0e2c51625a05ff446ac7eaa44f79 100644 (file)
@@ -7,6 +7,7 @@
 #include "xe_device.h"
 #include "xe_gt_sriov_pf_config.h"
 #include "xe_gt_sriov_pf_policy.h"
+#include "xe_lmtt.h"
 #include "xe_sriov.h"
 #include "xe_sriov_pf_helpers.h"
 #include "xe_sriov_pf_provision.h"
@@ -436,3 +437,108 @@ int xe_sriov_pf_provision_query_vf_priority(struct xe_device *xe, unsigned int v
 
        return !count ? -ENODATA : 0;
 }
+
+static u64 vram_per_tile(struct xe_tile *tile, u64 total)
+{
+       struct xe_device *xe = tile->xe;
+       unsigned int tcount = xe->info.tile_count;
+       u64 alignment = xe_lmtt_page_size(&tile->sriov.pf.lmtt);
+
+       total = round_up(total, tcount * alignment);
+       return div_u64(total, tcount);
+}
+
+/**
+ * xe_sriov_pf_provision_bulk_apply_vram() - Change VRAM provisioning for all VFs.
+ * @xe: the PF &xe_device
+ * @size: the VRAM size in [bytes] to set
+ *
+ * Change all VFs VRAM (LMEM) provisioning on all tiles.
+ *
+ * This function can only be called on PF.
+ *
+ * Return: 0 on success or a negative error code on failure.
+ */
+int xe_sriov_pf_provision_bulk_apply_vram(struct xe_device *xe, u64 size)
+{
+       unsigned int num_vfs = xe_sriov_pf_get_totalvfs(xe);
+       struct xe_tile *tile;
+       unsigned int id;
+       int result = 0;
+       int err;
+
+       xe_assert(xe, xe_device_has_lmtt(xe));
+
+       guard(mutex)(xe_sriov_pf_master_mutex(xe));
+
+       for_each_tile(tile, xe, id) {
+               err = xe_gt_sriov_pf_config_bulk_set_lmem_locked(tile->primary_gt,
+                                                                VFID(1), num_vfs,
+                                                                vram_per_tile(tile, size));
+               result = result ?: err;
+       }
+
+       return result;
+}
+
+/**
+ * xe_sriov_pf_provision_apply_vf_vram() - Change single VF VRAM allocation.
+ * @xe: the PF &xe_device
+ * @vfid: the VF identifier (can't be 0 == PFID)
+ * @size: VRAM size to set
+ *
+ * Change VF's VRAM provisioning on all tiles/GTs.
+ *
+ * This function can only be called on PF.
+ *
+ * Return: 0 on success or a negative error code on failure.
+ */
+int xe_sriov_pf_provision_apply_vf_vram(struct xe_device *xe, unsigned int vfid, u64 size)
+{
+       struct xe_tile *tile;
+       unsigned int id;
+       int result = 0;
+       int err;
+
+       xe_assert(xe, vfid);
+       xe_assert(xe, xe_device_has_lmtt(xe));
+
+       guard(mutex)(xe_sriov_pf_master_mutex(xe));
+
+       for_each_tile(tile, xe, id) {
+               err = xe_gt_sriov_pf_config_set_lmem_locked(tile->primary_gt, vfid,
+                                                           vram_per_tile(tile, size));
+               result = result ?: err;
+       }
+
+       return result;
+}
+
+/**
+ * xe_sriov_pf_provision_query_vf_vram() - Query VF's VRAM allocation.
+ * @xe: the PF &xe_device
+ * @vfid: the VF identifier (can't be 0 == PFID)
+ * @size: placeholder for the returned VRAM size
+ *
+ * Query VF's VRAM provisioning from all tiles/GTs.
+ *
+ * This function can only be called on PF.
+ *
+ * Return: 0 on success or a negative error code on failure.
+ */
+int xe_sriov_pf_provision_query_vf_vram(struct xe_device *xe, unsigned int vfid, u64 *size)
+{
+       struct xe_tile *tile;
+       unsigned int id;
+       u64 total = 0;
+
+       xe_assert(xe, vfid);
+
+       guard(mutex)(xe_sriov_pf_master_mutex(xe));
+
+       for_each_tile(tile, xe, id)
+               total += xe_gt_sriov_pf_config_get_lmem_locked(tile->primary_gt, vfid);
+
+       *size = total;
+       return 0;
+}
index bccf23d51396ba3734ac54c667350c20e544d91d..f26f49539697bfd1a8b421d9f385baeeb94547c2 100644 (file)
@@ -24,6 +24,10 @@ int xe_sriov_pf_provision_bulk_apply_priority(struct xe_device *xe, u32 prio);
 int xe_sriov_pf_provision_apply_vf_priority(struct xe_device *xe, unsigned int vfid, u32 prio);
 int xe_sriov_pf_provision_query_vf_priority(struct xe_device *xe, unsigned int vfid, u32 *prio);
 
+int xe_sriov_pf_provision_bulk_apply_vram(struct xe_device *xe, u64 size);
+int xe_sriov_pf_provision_apply_vf_vram(struct xe_device *xe, unsigned int vfid, u64 size);
+int xe_sriov_pf_provision_query_vf_vram(struct xe_device *xe, unsigned int vfid, u64 *size);
+
 int xe_sriov_pf_provision_vfs(struct xe_device *xe, unsigned int num_vfs);
 int xe_sriov_pf_unprovision_vfs(struct xe_device *xe, unsigned int num_vfs);