From: Xin Wang <x.wang@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: "Xin Wang" <x.wang@intel.com>,
"Kamil Konieczny" <kamil.konieczny@linux.intel.com>,
"Matt Roper" <matthew.d.roper@intel.com>,
"Zbigniew Kempczyński" <zbigniew.kempczynski@intel.com>,
"Ravi Kumar V" <ravi.kumar.vodapalli@intel.com>
Subject: [PATCH v2 2/3] lib/intel: add fd-based intel_gen/intel_graphics_ver via Xe query
Date: Thu, 22 Jan 2026 07:15:29 +0000 [thread overview]
Message-ID: <20260122071530.1629046-3-x.wang@intel.com> (raw)
In-Reply-To: <20260122071530.1629046-1-x.wang@intel.com>
Add fd‑based intel_gen() and intel_graphics_ver() that prefer Xe query
ip_ver_{major,minor} from the main GT, falling back to PCI ID legacy mapping.
Export xe_get_main_gt() to access main GT data from the cached query info.
Cc: Kamil Konieczny <kamil.konieczny@linux.intel.com>
Cc: Matt Roper <matthew.d.roper@intel.com>
Cc: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Cc: Ravi Kumar V <ravi.kumar.vodapalli@intel.com>
Signed-off-by: Xin Wang <x.wang@intel.com>
---
lib/intel_chipset.c | 51 +++++++++++++++++++++++++++++++++++++++++++++
lib/intel_chipset.h | 2 ++
lib/xe/xe_query.c | 25 ++++++++++++++++++++++
lib/xe/xe_query.h | 1 +
4 files changed, 79 insertions(+)
diff --git a/lib/intel_chipset.c b/lib/intel_chipset.c
index 760faede2..3e2d7a19c 100644
--- a/lib/intel_chipset.c
+++ b/lib/intel_chipset.c
@@ -127,6 +127,57 @@ static uint32_t __i915_get_drm_devid(int fd)
return devid;
}
+/**
+ * intel_graphics_ver:
+ * @fd: Open DRM device file descriptor
+ *
+ * Returns the graphics/IP version encoded with IP_VER(major, minor).
+ *
+ * The function prefers the modern XE path: if a main GT is available via
+ * xe_get_main_gt() and it reports a non-zero ip_ver_major, the version is
+ * constructed from main_gt->ip_ver_major and main_gt->ip_ver_minor.
+ *
+ * If XE information is unavailable, it falls back to the legacy path by reading
+ * the DRM device ID with intel_get_drm_devid() and translating it via
+ * intel_graphics_ver_legacy().
+ *
+ * Return: Encoded IP version (IP_VER(major, minor)).
+ */
+unsigned intel_graphics_ver(int fd)
+{
+ uint16_t devid;
+ const struct drm_xe_gt* main_gt = xe_get_main_gt(fd);
+
+ if (main_gt && main_gt->ip_ver_major)
+ return IP_VER(main_gt->ip_ver_major, main_gt->ip_ver_minor);
+
+ devid = intel_get_drm_devid(fd);
+ return intel_graphics_ver_legacy(devid);
+}
+
+/**
+ * intel_gen:
+ * @fd: DRM device file descriptor.
+ *
+ * Attempts to determine the graphics "generation" by querying the Xe driver for
+ * the main GT IP version major. If unavailable (e.g., not an Xe device or no IP
+ * version reported), falls back to retrieving the DRM device ID and mapping it
+ * to a legacy graphics version.
+ *
+ * Return: The graphics generation/major IP version for the device.
+ */
+unsigned intel_gen(int fd)
+{
+ uint16_t devid;
+ const struct drm_xe_gt* main_gt = xe_get_main_gt(fd);
+
+ if (main_gt && main_gt->ip_ver_major)
+ return main_gt->ip_ver_major;
+
+ devid = intel_get_drm_devid(fd);
+ return intel_gen_legacy(devid);
+}
+
/**
* intel_get_drm_devid:
* @fd: open i915/xe drm file descriptor
diff --git a/lib/intel_chipset.h b/lib/intel_chipset.h
index fb360268d..59edf70ea 100644
--- a/lib/intel_chipset.h
+++ b/lib/intel_chipset.h
@@ -106,6 +106,8 @@ const struct intel_cmds_info *intel_get_cmds_info(uint16_t devid) __attribute__(
unsigned intel_gen_legacy(uint16_t devid) __attribute__((pure));
unsigned intel_graphics_ver_legacy(uint16_t devid) __attribute__((pure));
unsigned intel_display_ver(uint16_t devid) __attribute__((pure));
+unsigned intel_gen(int fd);
+unsigned intel_graphics_ver(int fd);
extern enum pch_type intel_pch;
diff --git a/lib/xe/xe_query.c b/lib/xe/xe_query.c
index 981d76948..742e48c11 100644
--- a/lib/xe/xe_query.c
+++ b/lib/xe/xe_query.c
@@ -931,6 +931,31 @@ uint16_t xe_tile_get_main_gt_id(int fd, uint8_t tile)
return gt_id;
}
+/**
+ * xe_get_main_gt:
+ * @fd: xe device fd
+ *
+ * Returns pointer to main GT data structure for given xe device @fd.
+ */
+const struct drm_xe_gt* xe_get_main_gt(int fd)
+{
+ struct xe_device *xe_dev;
+
+ xe_dev = find_in_cache(fd);
+
+ if (xe_dev) {
+ for (int i = 0; i < xe_dev->gt_list->num_gt; i++) {
+ const struct drm_xe_gt *gt_data = &xe_dev->gt_list->gt_list[i];
+
+ if (gt_data->type == DRM_XE_QUERY_GT_TYPE_MAIN) {
+ return gt_data;
+ }
+ }
+ }
+
+ return NULL;
+}
+
/**
* xe_hwconfig_lookup_value:
* @fd: xe device fd
diff --git a/lib/xe/xe_query.h b/lib/xe/xe_query.h
index d7a9f95f9..bbf6bf9b6 100644
--- a/lib/xe/xe_query.h
+++ b/lib/xe/xe_query.h
@@ -160,6 +160,7 @@ 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);
+const struct drm_xe_gt* xe_get_main_gt(int fd);
/**
* xe_query_device:
--
2.43.0
next prev parent reply other threads:[~2026-01-22 7:15 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-22 7:15 [PATCH v2 0/3] lib/intel: switch graphics/IP version queries to fd-based APIs Xin Wang
2026-01-22 7:15 ` [PATCH v2 1/3] lib/intel: suffix PCI ID based gen/graphics_ver with _legacy Xin Wang
2026-02-04 18:30 ` Matt Roper
2026-01-22 7:15 ` Xin Wang [this message]
2026-02-05 9:09 ` [PATCH v2 2/3] lib/intel: add fd-based intel_gen/intel_graphics_ver via Xe query Jani Nikula
2026-01-22 7:15 ` [PATCH v2 3/3] intel/xe: use fd-based graphics/IP version helpers Xin Wang
2026-02-04 18:56 ` Matt Roper
2026-02-25 8:51 ` Wang, X
2026-02-25 23:18 ` Matt Roper
2026-01-22 8:01 ` ✓ i915.CI.BAT: success for lib/intel: switch graphics/IP version queries to fd-based APIs (rev2) Patchwork
2026-01-22 8:04 ` ✓ Xe.CI.BAT: " Patchwork
2026-01-22 18:13 ` ✗ Xe.CI.Full: failure " 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=20260122071530.1629046-3-x.wang@intel.com \
--to=x.wang@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=kamil.konieczny@linux.intel.com \
--cc=matthew.d.roper@intel.com \
--cc=ravi.kumar.vodapalli@intel.com \
--cc=zbigniew.kempczynski@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