[PATCH i-g-t 1/2] lib/xe/xe_query: move PXP query functions to common file
Daniele Ceraolo Spurio
daniele.ceraolospurio at intel.com
Tue Aug 19 00:56:23 UTC 2025
We already have a few tests using the PXP query functions and a new one
will be added in the next patch, so move the code to the common query
file to reduce duplication.
Signed-off-by: Daniele Ceraolo Spurio <daniele.ceraolospurio at intel.com>
---
lib/xe/xe_query.c | 81 ++++++++++++++++++++++++++++++++++++++++++++
lib/xe/xe_query.h | 2 ++
tests/intel/xe_pxp.c | 61 +++------------------------------
tests/intel/xe_vm.c | 13 +------
4 files changed, 88 insertions(+), 69 deletions(-)
diff --git a/lib/xe/xe_query.c b/lib/xe/xe_query.c
index 3b8a682f8..920c20b06 100644
--- a/lib/xe/xe_query.c
+++ b/lib/xe/xe_query.c
@@ -996,6 +996,87 @@ uint32_t *xe_hwconfig_lookup_value(int fd, enum intel_hwconfig attribute, uint32
return NULL;
}
+/**
+ * xe_query_pxp_status:
+ * @fd: xe device fd
+ *
+ * Returns the PXP status value if PXP is supported, a negative errno otherwise.
+ * See DRM_XE_DEVICE_QUERY_PXP_STATUS documentation for the possible errno
+ * values and their meaning.
+ */
+int xe_query_pxp_status(int fd)
+{
+ struct drm_xe_query_pxp_status *pxp_query;
+ struct drm_xe_device_query query = {
+ .extensions = 0,
+ .query = DRM_XE_DEVICE_QUERY_PXP_STATUS,
+ .size = 0,
+ .data = 0,
+ };
+ int ret;
+
+ if (igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query))
+ return -errno;
+
+ pxp_query = malloc(query.size);
+ igt_assert(pxp_query);
+ memset(pxp_query, 0, query.size);
+
+ query.data = to_user_pointer(pxp_query);
+
+ if (igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query))
+ ret = -errno;
+ else
+ ret = pxp_query->status;
+
+ free(pxp_query);
+
+ return ret;
+}
+
+/**
+ * xe_wait_for_pxp_init:
+ * @fd: xe device fd
+ *
+ * Returns 0 once PXP is initialized and ready, -EINVAL if PXP is not supported
+ * in the kernel, -ENODEV if PXP is not supported in HW. This function asserts
+ * if something went wrong during PXP initialization.
+ */
+int xe_wait_for_pxp_init(int fd)
+{
+ int pxp_status;
+ int i = 0;
+
+ /* PXP init completes after driver init, so we might have to wait for it */
+ while (i++ < 50) {
+ pxp_status = xe_query_pxp_status(fd);
+
+ /*
+ * -EINVAL and -ENODEV are both valid return values and they
+ * respectively indicate that the the PXP interface is not
+ * available (i.e., kernel too old) and that PXP is not
+ * supported or disabled in HW.
+ */
+ if (pxp_status == -EINVAL || pxp_status == -ENODEV)
+ return pxp_status;
+
+ /* status 1 means pxp is ready */
+ if (pxp_status == 1)
+ return 0;
+
+ /*
+ * 0 means init still in progress, any other remaining state
+ * is an unexpected error
+ */
+ igt_assert_eq(pxp_status, 0);
+
+ usleep(50*1000);
+ }
+
+ igt_assert_f(0, "PXP failed to initialize within the timeout\n");
+ return -ETIMEDOUT;
+}
+
igt_constructor
{
xe_device_cache_init();
diff --git a/lib/xe/xe_query.h b/lib/xe/xe_query.h
index cc54ec956..32917991d 100644
--- a/lib/xe/xe_query.h
+++ b/lib/xe/xe_query.h
@@ -130,6 +130,8 @@ bool xe_has_media_gt(int fd);
bool xe_is_media_gt(int fd, int gt);
uint16_t xe_gt_get_tile_id(int fd, int gt);
uint32_t *xe_hwconfig_lookup_value(int fd, enum intel_hwconfig attribute, uint32_t *len);
+int xe_query_pxp_status(int fd);
+int xe_wait_for_pxp_init(int fd);
struct xe_device *xe_device_get(int fd);
void xe_device_put(int fd);
diff --git a/tests/intel/xe_pxp.c b/tests/intel/xe_pxp.c
index 9eddc03fc..98f06ae13 100644
--- a/tests/intel/xe_pxp.c
+++ b/tests/intel/xe_pxp.c
@@ -105,67 +105,14 @@ static uint32_t create_regular_rcs_queue(int fd, uint32_t vm)
return xe_exec_queue_create(fd, vm, &inst, 0);
}
-static int query_pxp_status(int fd)
-{
- struct drm_xe_query_pxp_status *pxp_query;
- struct drm_xe_device_query query = {
- .extensions = 0,
- .query = DRM_XE_DEVICE_QUERY_PXP_STATUS,
- .size = 0,
- .data = 0,
- };
- int ret;
-
- if (igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query))
- return -errno;
-
- pxp_query = malloc(query.size);
- igt_assert(pxp_query);
- memset(pxp_query, 0, query.size);
-
- query.data = to_user_pointer(pxp_query);
-
- if (igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query))
- ret = -errno;
- else
- ret = pxp_query->status;
-
- free(pxp_query);
-
- return ret;
-}
-
static bool is_pxp_hw_supported(int fd)
{
- int pxp_status;
- int i = 0;
-
- /* PXP init completes after driver init, so we might have to wait for it */
- while (i++ < 50) {
- pxp_status = query_pxp_status(fd);
-
- /* -EINVAL means the PXP interface is not available */
- igt_require(pxp_status != -EINVAL);
-
- /* -ENODEV means PXP not supported or disabled */
- if (pxp_status == -ENODEV)
- return false;
+ int ret = xe_wait_for_pxp_init(fd);
- /* status 1 means pxp is ready */
- if (pxp_status == 1)
- return true;
-
- /*
- * 0 means init still in progress, any other remaining state
- * is an error
- */
- igt_assert_eq(pxp_status, 0);
-
- usleep(50*1000);
- }
+ /* -EINVAL means the PXP interface is not available */
+ igt_require(ret != -EINVAL);
- igt_assert_f(0, "PXP failed to initialize within the timeout\n");
- return false;
+ return ret == 0;
}
/**
diff --git a/tests/intel/xe_vm.c b/tests/intel/xe_vm.c
index 3ce54053c..90bd2722b 100644
--- a/tests/intel/xe_vm.c
+++ b/tests/intel/xe_vm.c
@@ -2177,18 +2177,7 @@ test_mmap_style_bind(int fd, struct drm_xe_engine_class_instance *eci,
static bool pxp_interface_supported(int fd)
{
- struct drm_xe_device_query query = {
- .extensions = 0,
- .query = DRM_XE_DEVICE_QUERY_PXP_STATUS,
- .size = 0,
- .data = 0,
- };
- int ret = 0;
-
- if (igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query))
- ret = -errno;
-
- return ret != -EINVAL;
+ return xe_query_pxp_status(fd) != -EINVAL;
}
/**
--
2.43.0
More information about the igt-dev
mailing list