summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorMichal Wajdeczko <michal.wajdeczko@intel.com>2026-02-18 23:55:45 +0300
committerMichal Wajdeczko <michal.wajdeczko@intel.com>2026-02-20 17:50:01 +0300
commit5ae3c886a1f5d54fbd5e477bcbfb4f3154a7247e (patch)
tree7a093858d050c048ec619cb5d80b9d32d8f73de5 /drivers
parent146f25b40ce4b97b193ec19ae747629e44dfdce9 (diff)
downloadlinux-5ae3c886a1f5d54fbd5e477bcbfb4f3154a7247e.tar.xz
drm/xe/pf: Add functions for VRAM provisioning
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
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gpu/drm/xe/xe_sriov_pf_provision.c106
-rw-r--r--drivers/gpu/drm/xe/xe_sriov_pf_provision.h4
2 files changed, 110 insertions, 0 deletions
diff --git a/drivers/gpu/drm/xe/xe_sriov_pf_provision.c b/drivers/gpu/drm/xe/xe_sriov_pf_provision.c
index 01470c42e8a7..f22ff65c59aa 100644
--- a/drivers/gpu/drm/xe/xe_sriov_pf_provision.c
+++ b/drivers/gpu/drm/xe/xe_sriov_pf_provision.c
@@ -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;
+}
diff --git a/drivers/gpu/drm/xe/xe_sriov_pf_provision.h b/drivers/gpu/drm/xe/xe_sriov_pf_provision.h
index bccf23d51396..f26f49539697 100644
--- a/drivers/gpu/drm/xe/xe_sriov_pf_provision.h
+++ b/drivers/gpu/drm/xe/xe_sriov_pf_provision.h
@@ -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);