[PATCH 1/2] lib/xe_query: add xe_hwconfig_lookup_value() helper
Maslak, Jan
jan.maslak at intel.com
Thu Nov 14 16:28:42 UTC 2024
---
lib/xe/xe_query.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++
lib/xe/xe_query.h | 2 ++
2 files changed, 58 insertions(+)
diff --git a/lib/xe/xe_query.c b/lib/xe/xe_query.c
index 0c9cff066..07d790f37 100644
--- a/lib/xe/xe_query.c
+++ b/lib/xe/xe_query.c
@@ -811,6 +811,62 @@ 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)
+{
+ uint32_t *hwconfig;
+ uint32_t pos, hwconfig_len;
+ uint32_t *value = NULL;
+
+ struct drm_xe_device_query query = {
+ .extensions = 0,
+ .query = DRM_XE_DEVICE_QUERY_HWCONFIG,
+ .size = 0,
+ .data = 0,
+ };
+
+ /* Perform the initial query to get the size */
+ igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
+ igt_assert_neq(query.size, 0);
+
+ hwconfig = malloc(query.size);
+ igt_assert(hwconfig);
+
+ query.data = to_user_pointer(hwconfig);
+
+ /* Perform the query to get the actual data */
+ igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
+
+ /* Extract the value from the hwconfig */
+ pos = 0;
+ hwconfig_len = query.size / 4;
+ 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;
+ }
+
+ free(hwconfig);
+ return value;
+}
+
igt_constructor
{
xe_device_cache_init();
diff --git a/lib/xe/xe_query.h b/lib/xe/xe_query.h
index cabb8078c..580f82958 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
@@ -112,6 +113,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
---------------------------------------------------------------------
Intel Technology Poland sp. z o.o.
ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN.
Spolka oswiadcza, ze posiada status duzego przedsiebiorcy w rozumieniu ustawy z dnia 8 marca 2013 r. o przeciwdzialaniu nadmiernym opoznieniom w transakcjach handlowych.
Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek przegladanie lub rozpowszechnianie jest zabronione.
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by others is strictly prohibited.
More information about the igt-dev
mailing list