public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Xin Wang <x.wang@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Xin Wang <x.wang@intel.com>
Subject: [PATCH v5 2/4] lib/intel: add fd-based graphics IP version query helpers
Date: Tue, 10 Mar 2026 23:23:07 -0700	[thread overview]
Message-ID: <20260311062311.1623823-3-x.wang@intel.com> (raw)
In-Reply-To: <20260311062311.1623823-1-x.wang@intel.com>

Add two new functions to query the graphics IP version from a DRM
device fd:

  unsigned intel_gfx_ver(int fd)
  unsigned intel_gfx_ver_major(int fd)

intel_gfx_ver() returns the full IP version encoded as
IP_VER(major, minor), replacing the role of the pciid-based
intel_graphics_ver_from_pciid(). intel_gfx_ver_major() returns
only the major version, replacing the role of intel_gen_from_pciid().

For Xe devices both functions query the graphics IP version directly
from the kernel via the GT query interface (drm_xe_gt.ip_ver_major /
ip_ver_minor), avoiding any PCI ID table lookup. For other devices they
fall back to intel_graphics_ver_from_pciid() / intel_gen_from_pciid()
using the device ID obtained via intel_get_drm_devid(fd).

The new fd-based names differ from the legacy pciid-based names so that
any remaining call sites that mistakenly pass a devid instead of an fd
will produce a build failure rather than silently computing wrong
results through implicit integer conversion.

To support the Xe path, export xe_get_main_gt(int fd) from xe_query,
which returns a pointer to the first MAIN GT descriptor from the
cached Xe device query result.

Signed-off-by: Xin Wang <x.wang@intel.com>
---
 lib/intel_chipset.c     | 43 +++++++++++++++++++++++++++++++++++++++++
 lib/intel_chipset.h     |  2 ++
 lib/intel_device_info.c | 12 ++++++------
 lib/xe/xe_query.c       | 25 ++++++++++++++++++++++++
 lib/xe/xe_query.h       |  1 +
 5 files changed, 77 insertions(+), 6 deletions(-)

diff --git a/lib/intel_chipset.c b/lib/intel_chipset.c
index 760faede2..835c4ab34 100644
--- a/lib/intel_chipset.c
+++ b/lib/intel_chipset.c
@@ -189,3 +189,46 @@ intel_check_pch(void)
 		return;
 	}
 }
+
+/**
+ * intel_gfx_ver:
+ * @fd: drm device fd
+ *
+ * Returns the graphics IP version for the device identified by @fd, encoded
+ * as IP_VER(major, minor).  For Xe devices the value is read directly from
+ * the kernel via the GT query interface.  For other devices it falls back to
+ * a PCI ID table lookup.
+ *
+ * Returns:
+ * The graphics IP version.
+ */
+unsigned intel_gfx_ver(int fd)
+{
+	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);
+
+	return intel_graphics_ver_from_pciid(intel_get_drm_devid(fd));
+}
+
+/**
+ * intel_gfx_ver_major:
+ * @fd: drm device fd
+ *
+ * Returns the graphics IP major version for the device identified by @fd.
+ * For Xe devices the value is read directly from the kernel via the GT query
+ * interface.  For other devices it falls back to a PCI ID table lookup.
+ *
+ * Returns:
+ * The graphics IP major version.
+ */
+unsigned intel_gfx_ver_major(int fd)
+{
+	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;
+
+	return intel_gen_from_pciid(intel_get_drm_devid(fd));
+}
diff --git a/lib/intel_chipset.h b/lib/intel_chipset.h
index 4a9b7bef1..0e48c248a 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_from_pciid(uint16_t devid) __attribute__((pure));
 unsigned intel_graphics_ver_from_pciid(uint16_t devid) __attribute__((pure));
 unsigned intel_display_ver(uint16_t devid) __attribute__((pure));
+unsigned intel_gfx_ver(int fd);
+unsigned intel_gfx_ver_major(int fd);
 
 extern enum pch_type intel_pch;
 
diff --git a/lib/intel_device_info.c b/lib/intel_device_info.c
index ba16975f5..c0fde6182 100644
--- a/lib/intel_device_info.c
+++ b/lib/intel_device_info.c
@@ -742,14 +742,14 @@ const struct intel_cmds_info *intel_get_cmds_info(uint16_t devid)
  * intel_gen_from_pciid:
  * @devid: pci device id
  *
- * Computes the Intel GFX generation for the given device id.
+ * Intel graphics IP major version for the given device id.
  *
- * Deprecated: Prefer the fd-based intel_gen() where a DRM device fd is
- * available. Use this function only in contexts where no fd is accessible,
+ * Deprecated: Prefer the fd-based intel_gfx_ver_major() where a DRM device fd
+ * is available. Use this function only in contexts where no fd is accessible,
  * e.g. when the DRM driver is not loaded or in cross-environment tools.
  *
  * Returns:
- * The GFX generation on successful lookup, -1u on failure.
+ * The major version of the graphics IP on successful lookup, -1u on failure.
  */
 unsigned intel_gen_from_pciid(uint16_t devid)
 {
@@ -760,9 +760,9 @@ unsigned intel_gen_from_pciid(uint16_t devid)
  * intel_graphics_ver_from_pciid:
  * @devid: pci device id
  *
- * Computes the Intel graphics IP version for the given device id.
+ * Intel graphics IP version for the given device id.
  *
- * Deprecated: Prefer the fd-based intel_graphics_ver() where a DRM device fd
+ * Deprecated: Prefer the fd-based intel_gfx_ver() where a DRM device fd
  * is available. Use this function only in contexts where no fd is accessible,
  * e.g. when the DRM driver is not loaded or in cross-environment tools.
  *
diff --git a/lib/xe/xe_query.c b/lib/xe/xe_query.c
index 3afca353e..23f57bf1f 100644
--- a/lib/xe/xe_query.c
+++ b/lib/xe/xe_query.c
@@ -903,6 +903,31 @@ bool xe_is_main_gt(int fd, int gt)
 	return xe_gt_type(fd, gt) == DRM_XE_QUERY_GT_TYPE_MAIN;
 }
 
+/**
+ * xe_get_main_gt:
+ * @fd: xe device fd
+ *
+ * Returns a pointer to the drm_xe_gt descriptor of the first MAIN GT found
+ * for device @fd, or NULL if none is found.
+ */
+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 = &xe_dev->gt_list->gt_list[i];
+
+			if (gt->type == DRM_XE_QUERY_GT_TYPE_MAIN)
+				return gt;
+		}
+	}
+
+	return NULL;
+}
+
 /**
  * xe_gt_to_tile_id:
  * @fd: xe device fd
diff --git a/lib/xe/xe_query.h b/lib/xe/xe_query.h
index 05e2ad84f..aab4a64a8 100644
--- a/lib/xe/xe_query.h
+++ b/lib/xe/xe_query.h
@@ -158,6 +158,7 @@ bool xe_has_media_gt(int fd);
 uint16_t xe_gt_type(int fd, int gt);
 bool xe_is_media_gt(int fd, int gt);
 bool xe_is_main_gt(int fd, int gt);
+const struct drm_xe_gt *xe_get_main_gt(int fd);
 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);
-- 
2.43.0


  parent reply	other threads:[~2026-03-11  6:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-11  6:23 [PATCH v5 0/4] lib/intel: switch graphics/IP version queries to fd-based APIs Xin Wang
2026-03-11  6:23 ` [PATCH v5 1/4] lib/intel: rename intel_gen() and intel_graphics_ver() to *_from_pciid() variants Xin Wang
2026-03-11  6:23 ` Xin Wang [this message]
2026-03-11  6:23 ` [PATCH v5 3/4] intel/{lib, tests}: switch fd-backed version checks to intel_gfx_ver* Xin Wang
2026-03-11  6:23 ` [PATCH v5 4/4] lib/intel_device_info: remove the graphcs_rel from xe2+ devices Xin Wang
2026-03-11  6:23 ` [PATCH v5 4/4] lib/intel_device_info: remove the graphics_rel " Xin Wang
2026-03-11 19:04 ` ✗ Xe.CI.BAT: failure for lib/intel: switch graphics/IP version queries to fd-based APIs Patchwork
2026-03-11 19:21 ` ✓ i915.CI.BAT: success " Patchwork
2026-03-12 10:39 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-03-12 12:29 ` ✗ 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=20260311062311.1623823-3-x.wang@intel.com \
    --to=x.wang@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /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