[PATCH i-g-t 3/5] lib/xe/xe_sriov_provisioning: Add shared resource provisionability check

Marcin Bernatowicz marcin.bernatowicz at linux.intel.com
Wed Dec 18 12:00:54 UTC 2024


Introduce a helper `xe_sriov_is_shared_res_provisionable` to determine
if a shared resource can be provisioned.

Add macros `xe_sriov_for_each_shared_res` and
`xe_sriov_for_each_provisionable_shared_res` to iterate over shared
resources and provisionable shared resources, respectively.

Signed-off-by: Marcin Bernatowicz <marcin.bernatowicz at linux.intel.com>
Cc: Adam Miszczak <adam.miszczak at linux.intel.com>
Cc: Jakub Kolakowski <jakub1.kolakowski at intel.com>
Cc: Lukasz Laguna <lukasz.laguna at intel.com>
Cc: Michał Wajdeczko <michal.wajdeczko at intel.com>
Cc: Michał Winiarski <michal.winiarski at intel.com>
Cc: Narasimha C V <narasimha.c.v at intel.com>
Cc: Piotr Piórkowski <piotr.piorkowski at intel.com>
Cc: Satyanarayana K V P <satyanarayana.k.v.p at intel.com>
Cc: Tomasz Lis <tomasz.lis at intel.com>
---
 lib/xe/xe_sriov_provisioning.c | 22 ++++++++++++++++++++++
 lib/xe/xe_sriov_provisioning.h | 29 +++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)

diff --git a/lib/xe/xe_sriov_provisioning.c b/lib/xe/xe_sriov_provisioning.c
index 536121931..22035ffd8 100644
--- a/lib/xe/xe_sriov_provisioning.c
+++ b/lib/xe/xe_sriov_provisioning.c
@@ -9,6 +9,7 @@
 #include "intel_chipset.h"
 #include "linux_scaffold.h"
 #include "xe/xe_mmio.h"
+#include "xe/xe_query.h"
 #include "xe/xe_sriov_debugfs.h"
 #include "xe/xe_sriov_provisioning.h"
 
@@ -274,3 +275,24 @@ void xe_sriov_pf_set_shared_res_attr(int pf, enum xe_sriov_shared_res res,
 {
 	igt_fail_on(__xe_sriov_pf_set_shared_res_attr(pf, res, vf_num, gt_num, value));
 }
+
+/**
+ * xe_sriov_is_shared_res_provisionable - Check if a shared resource is provisionable
+ * @pf: PF device file descriptor
+ * @res: Shared resource type (see enum xe_sriov_shared_res)
+ * @gt_num: GT number
+ *
+ * Determines whether a specified shared resource can be provisioned.
+ *
+ * Return: true if the shared resource is provisionable, false otherwise.
+ */
+bool xe_sriov_is_shared_res_provisionable(int pf, enum xe_sriov_shared_res res,
+					  unsigned int gt_num)
+{
+	if (res == XE_SRIOV_SHARED_RES_LMEM)
+		return xe_has_vram(pf) && !xe_is_media_gt(pf, gt_num);
+	else if (res == XE_SRIOV_SHARED_RES_GGTT)
+		return !xe_is_media_gt(pf, gt_num);
+
+	return true;
+}
diff --git a/lib/xe/xe_sriov_provisioning.h b/lib/xe/xe_sriov_provisioning.h
index 168b50394..b4300ec2e 100644
--- a/lib/xe/xe_sriov_provisioning.h
+++ b/lib/xe/xe_sriov_provisioning.h
@@ -27,6 +27,34 @@ enum xe_sriov_shared_res {
 	XE_SRIOV_SHARED_RES_LMEM,
 };
 
+/**
+ * XE_SRIOV_SHARED_RES_NUM - Number of shared resource types
+ */
+#define XE_SRIOV_SHARED_RES_NUM (XE_SRIOV_SHARED_RES_LMEM + 1)
+
+/**
+ * xe_sriov_for_each_shared_res - Iterate over all shared resource types
+ * @res: Loop counter variable of type `enum xe_sriov_shared_res`
+ *
+ * Iterates over each shared resource type defined in the `enum xe_sriov_shared_res`.
+ */
+#define xe_sriov_for_each_shared_res(res) \
+	for ((res) = 0; (res) < XE_SRIOV_SHARED_RES_NUM; (res)++)
+
+/**
+ * xe_sriov_for_each_provisionable_shared_res - Iterate over provisionable shared
+ * resource types
+ * @res: Loop counter variable of type `enum xe_sriov_shared_res`
+ * @pf: PF device file descriptor of type int
+ * @gt: GT number of type unsigned int
+ *
+ * Iterates over each provisionable shared resource type for the given PF device
+ * and GT number.
+ */
+#define xe_sriov_for_each_provisionable_shared_res(res, pf, gt) \
+	for ((res) = 0; (res) < XE_SRIOV_SHARED_RES_NUM; (res)++) \
+		for_if(xe_sriov_is_shared_res_provisionable((pf), (res), (gt)))
+
 /**
  * struct xe_sriov_provisioned_range - Provisioned range for a Virtual Function (VF)
  * @vf_id: The ID of the VF
@@ -43,6 +71,7 @@ struct xe_sriov_provisioned_range {
 };
 
 const char *xe_sriov_shared_res_to_string(enum xe_sriov_shared_res res);
+bool xe_sriov_is_shared_res_provisionable(int pf, enum xe_sriov_shared_res res, unsigned int gt);
 int xe_sriov_find_ggtt_provisioned_pte_offsets(int pf_fd, int gt, struct xe_mmio *mmio,
 					       struct xe_sriov_provisioned_range **ranges,
 					       unsigned int *nr_ranges);
-- 
2.31.1



More information about the igt-dev mailing list