Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Maslak <jan.maslak@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: dominik.grzegorzek@intel.com, jonathan.cavitt@intel.com,
	matthew.d.roper@intel.com, Jan Maslak <jan.maslak@intel.com>
Subject: [PATCH 2/3] lib/xe_query: add xe_hwconfig_lookup_value() helper
Date: Wed, 20 Nov 2024 22:28:49 +0000	[thread overview]
Message-ID: <20241120222850.1497784-3-jan.maslak@intel.com> (raw)
In-Reply-To: <20241120222850.1497784-1-jan.maslak@intel.com>

Add a new helper function, xe_hw_config_lookup_value(), that
returns a pointer to the value of a given hwconfig attribute.

Signed-off-by: Jan Maslak <jan.maslak@intel.com>
---
 lib/xe/xe_query.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 lib/xe/xe_query.h |  2 ++
 2 files changed, 46 insertions(+)

diff --git a/lib/xe/xe_query.c b/lib/xe/xe_query.c
index 49bed033b..73c8ed948 100644
--- a/lib/xe/xe_query.c
+++ b/lib/xe/xe_query.c
@@ -839,6 +839,50 @@ uint16_t xe_gt_get_tile_id(int fd, int gt)
 	return xe_dev->gt_list->gt_list[gt].tile_id;
 }
 
+/**
+ * xe_hwconfig_lookup_value:
+ * @fd: xe device fd
+ * @attribute: hwconfig attribute id
+ * @len: pointer to store length of the value
+ *
+ * Returns a pointer to the value of the hwconfig attribute @attribute and
+ * writes the length of the value to @len.
+ * The caller is responsible for freeing the returned pointer.
+ */
+uint32_t *xe_hwconfig_lookup_value(int fd, enum intel_hwconfig attribute, uint32_t *len)
+{
+	struct xe_device *xe_dev;
+	uint32_t *hwconfig;
+	uint32_t pos, hwconfig_len;
+	uint32_t *value = NULL;
+
+	xe_dev = find_in_cache(fd);
+	igt_assert(xe_dev);
+
+	hwconfig = xe_dev->hwconfig;
+	igt_assert(hwconfig);
+
+	/* Extract the value from the hwconfig */
+	pos = 0;
+	hwconfig_len = xe_dev->hwconfig_size / sizeof(uint32_t);
+	while (pos + 2 < hwconfig_len) {
+		uint32_t attribute_id = hwconfig[pos];
+		uint32_t attribute_len = hwconfig[pos + 1];
+		uint32_t *attribute_data = &hwconfig[pos + 2];
+
+		if (attribute_id == attribute) {
+			value = malloc(attribute_len * sizeof(uint32_t));
+			igt_assert(value);
+			memcpy(value, attribute_data, attribute_len * sizeof(uint32_t));
+			*len = attribute_len;
+			break;
+		}
+		pos += 2 + attribute_len;
+	}
+
+	return value;
+}
+
 igt_constructor
 {
 	xe_device_cache_init();
diff --git a/lib/xe/xe_query.h b/lib/xe/xe_query.h
index f8836578e..30ea5ad41 100644
--- a/lib/xe/xe_query.h
+++ b/lib/xe/xe_query.h
@@ -15,6 +15,7 @@
 #include "igt_aux.h"
 #include "igt_list.h"
 #include "igt_sizes.h"
+#include "intel_hwconfig_types.h"
 
 #define XE_DEFAULT_ALIGNMENT           SZ_4K
 #define XE_DEFAULT_ALIGNMENT_64K       SZ_64K
@@ -118,6 +119,7 @@ struct drm_xe_engine *xe_find_engine_by_class(int fd, uint16_t engine_class);
 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);
 
 struct xe_device *xe_device_get(int fd);
 void xe_device_put(int fd);
-- 
2.34.1


  parent reply	other threads:[~2024-11-20 22:29 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-20 22:28 [PATCH 0/3] tests/xe_eudebug_online: update thread count handling in query_attention_bitmask_size() Jan Maslak
2024-11-20 22:28 ` [PATCH 1/3] lib/xe_query: add hwconfig to xe_device Jan Maslak
2024-11-26  8:34   ` Grzegorzek, Dominik
2024-11-20 22:28 ` Jan Maslak [this message]
2024-11-26  9:13   ` [PATCH 2/3] lib/xe_query: add xe_hwconfig_lookup_value() helper Grzegorzek, Dominik
2024-11-26  9:16     ` Grzegorzek, Dominik
2024-11-20 22:28 ` [PATCH 3/3] tests/xe_eudebug_online: update thread count handling in query_attention_bitmask_size() Jan Maslak
2024-11-21 10:18   ` Grzegorzek, Dominik
2024-11-20 22:54 ` ✗ GitLab.Pipeline: warning for tests/xe_eudebug_online: update thread count handling in query_attention_bitmask_size() (rev2) Patchwork
2024-11-20 23:19 ` ✓ Fi.CI.BAT: success " Patchwork
2024-11-21  6:43 ` ✗ Xe.CI.Full: failure " Patchwork
2024-11-24  8:17 ` ✗ i915.CI.Full: " Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2024-11-28 13:05 [PATCH 0/3] tests/xe_eudebug_online: update thread count handling in query_attention_bitmask_size() Jan Maslak
2024-11-28 13:05 ` [PATCH 2/3] lib/xe_query: add xe_hwconfig_lookup_value() helper Jan Maslak
2024-11-28 13:10   ` Grzegorzek, Dominik

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=20241120222850.1497784-3-jan.maslak@intel.com \
    --to=jan.maslak@intel.com \
    --cc=dominik.grzegorzek@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=jonathan.cavitt@intel.com \
    --cc=matthew.d.roper@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