From: Andrzej Hajda <andrzej.hajda@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: "Kamil Konieczny" <kamil.konieczny@linux.intel.com>,
"Priyanka Dandamudi" <priyanka.dandamudi@intel.com>,
"Gwan-gyeong Mun" <gwan-gyeong.mun@intel.com>,
"Piotr Piórkowski" <piotr.piorkowski@intel.com>,
"Christoph Manszewski" <christoph.manszewski@intel.com>,
"Andrzej Hajda" <andrzej.hajda@intel.com>
Subject: [PATCH v5 2/5] lib/xe/xe_query: introduce helpers for device query
Date: Fri, 21 Nov 2025 11:59:01 +0100 [thread overview]
Message-ID: <20251121-xe_query_helpers-v5-2-d69c1c160e96@intel.com> (raw)
In-Reply-To: <20251121-xe_query_helpers-v5-0-d69c1c160e96@intel.com>
Helpers abstracts out common bits of DRM_XE_DEVICE_QUERY_HWCONFIG ioctl:
- query data size,
- alloc memory,
- get data,
- error checks,
- valgrind annotations.
There are two flawors, to fulfill current usage patterns:
- xe_query_device_may_fail - returns NULL if query is not supported,
- xe_query_device - asserts on error otherwise returns valid pointer.
Signed-off-by: Andrzej Hajda <andrzej.hajda@intel.com>
---
lib/xe/xe_query.c | 43 +++++++++++++++++++++++++++++++++++++++++++
lib/xe/xe_query.h | 20 ++++++++++++++++++++
2 files changed, 63 insertions(+)
diff --git a/lib/xe/xe_query.c b/lib/xe/xe_query.c
index 53af86a99378dfda6f988e01a4d842b266e94a80..a185b852e19b87e393f4bc6edbf9e0952439d518 100644
--- a/lib/xe/xe_query.c
+++ b/lib/xe/xe_query.c
@@ -25,6 +25,49 @@
#include "xe_query.h"
#include "xe_ioctl.h"
+/**
+ * xe_query_device_may_fail:
+ * @fd: xe device fd
+ * @type: query type, one of DRM_XE_DEVICE_QUERY_* values
+ * @size: pointer to get size of returned data, can be NULL
+ *
+ * Calls DRM_IOCTL_XE_DEVICE_QUERY ioctl to query device information
+ * about specified @type. Returns pointer to malloc'ed data, which
+ * should be freed later by the user. If @query is not supported
+ * function returns NULL. On any other error it asserts.
+ */
+void *xe_query_device_may_fail(int fd, uint32_t type, uint32_t *size)
+{
+ struct drm_xe_device_query query = {
+ .extensions = 0,
+ .query = type,
+ .size = 0,
+ .data = 0,
+ };
+ void *data = NULL;
+
+ /* In case of unsupported query xe driver usually returns error,
+ * but in case of HWCONFIG it can also return query.size == 0
+ * on older platforms.
+ */
+ if (igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query) || !query.size)
+ goto skip_query;
+
+ data = malloc(query.size);
+ igt_assert(data);
+
+ query.data = to_user_pointer(data);
+ igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
+
+ VG(VALGRIND_MAKE_MEM_DEFINED(data, query.size));
+
+skip_query:
+ if (size)
+ *size = query.size;
+
+ return data;
+}
+
static struct drm_xe_query_config *xe_query_config_new(int fd)
{
struct drm_xe_query_config *config;
diff --git a/lib/xe/xe_query.h b/lib/xe/xe_query.h
index 6a97d384a364979e1a3fa4e0785397236068d0fc..15d5c26baf5be6e107495247ca1aaefea551d821 100644
--- a/lib/xe/xe_query.h
+++ b/lib/xe/xe_query.h
@@ -143,9 +143,29 @@ uint16_t xe_gt_get_tile_id(int fd, int gt);
uint16_t xe_tile_get_main_gt_id(int fd, uint8_t tile);
uint32_t *xe_hwconfig_lookup_value(int fd, enum intel_hwconfig attribute, uint32_t *len);
uint32_t xe_hwconfig_lookup_value_u32(int fd, enum intel_hwconfig attribute);
+void *xe_query_device_may_fail(int fd, uint32_t type, uint32_t *size);
int xe_query_pxp_status(int fd);
int xe_wait_for_pxp_init(int fd);
+/**
+ * xe_query_device:
+ * @fd: xe device fd
+ * @type: query type, one of DRM_XE_DEVICE_QUERY_* values
+ * @size: pointer to get size of returned data, can be NULL
+ *
+ * Calls DRM_IOCTL_XE_DEVICE_QUERY ioctl to query device information
+ * about specified @type. Returns pointer to malloc'ed data, which
+ * should be freed later by the user. If @query is not supported
+ * or on any other error it asserts.
+ */
+static inline void *xe_query_device(int fd, uint32_t type, uint32_t *size)
+{
+ void *data = xe_query_device_may_fail(fd, type, size);
+
+ igt_assert(data);
+ return data;
+}
+
struct xe_device *xe_device_get(int fd);
void xe_device_put(int fd);
--
2.43.0
next prev parent reply other threads:[~2025-11-21 11:00 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-21 10:58 [PATCH v5 0/5] lib/xe/xe_query: implement few query helpers Andrzej Hajda
2025-11-21 10:59 ` [PATCH v5 1/5] tests/intel/xe_eudebug_online: use helper to get hwconfig value Andrzej Hajda
2025-11-21 10:59 ` Andrzej Hajda [this message]
2025-11-24 8:13 ` [PATCH v5 2/5] lib/xe/xe_query: introduce helpers for device query Dandamudi, Priyanka
2025-11-24 8:55 ` Dandamudi, Priyanka
2025-11-24 9:29 ` Kamil Konieczny
2025-11-24 9:41 ` Kamil Konieczny
2025-11-21 10:59 ` [PATCH v5 3/5] lib/xe/xe_query: use recently introduced helper to query device Andrzej Hajda
2025-11-24 11:01 ` Kamil Konieczny
2025-11-21 10:59 ` [PATCH v5 4/5] lib/xe/xe_query: introduce iterator for GT topology masks Andrzej Hajda
2025-11-21 10:59 ` [PATCH v5 5/5] xe/treewide: use xe_query helpers for query GT topology Andrzej Hajda
2025-11-24 11:16 ` Kamil Konieczny
2025-11-25 3:47 ` ✓ i915.CI.BAT: success for lib/xe/xe_query: implement few query helpers (rev5) Patchwork
2025-11-25 3:48 ` ✓ Xe.CI.BAT: " Patchwork
2025-11-25 5:44 ` ✗ Xe.CI.Full: failure " Patchwork
2025-11-25 9:48 ` ✗ i915.CI.Full: " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251121-xe_query_helpers-v5-2-d69c1c160e96@intel.com \
--to=andrzej.hajda@intel.com \
--cc=christoph.manszewski@intel.com \
--cc=gwan-gyeong.mun@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=kamil.konieczny@linux.intel.com \
--cc=piotr.piorkowski@intel.com \
--cc=priyanka.dandamudi@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).