Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Dominik Karol Piątkowski" <dominik.karol.piatkowski@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: "Zbigniew Kempczyński" <zbigniew.kempczynski@intel.com>,
	"Dominik Grzegorzek" <dominik.grzegorzek@intel.com>,
	"Christoph Manszewski" <christoph.manszewski@intel.com>,
	"Pawel Sikora" <pawel.sikora@intel.com>,
	"Jonathan Cavitt" <jonathan.cavitt@intel.com>,
	"Dominik Karol Piątkowski" <dominik.karol.piatkowski@intel.com>
Subject: [PATCH v2 i-g-t 1/2] lib/igt_sysfs: Introduce engine_class property helpers
Date: Wed,  2 Oct 2024 13:29:13 +0200	[thread overview]
Message-ID: <20241002112914.5556-2-dominik.karol.piatkowski@intel.com> (raw)
In-Reply-To: <20241002112914.5556-1-dominik.karol.piatkowski@intel.com>

Introduce the following engine_class helpers:
 - xe_sysfs_engine_class_get_property
   Convenience wrapper to get value of given property for given engine
   class on given gt.
 - xe_sysfs_engine_class_set_property
   Convenience wrapper to set given property for given engine class on
   given gt to given value.

Signed-off-by: Dominik Karol Piątkowski <dominik.karol.piatkowski@intel.com>
---
 lib/igt_sysfs.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_sysfs.h |  5 +++
 2 files changed, 90 insertions(+)

diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index aec0bb53d..8fe6d7ede 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -1360,3 +1360,88 @@ int xe_sysfs_get_num_tiles(int xe_device)
 
 	return num_tiles;
 }
+
+/**
+ * xe_sysfs_engine_class_get_property
+ * @xe_device: fd of the device
+ * @gt: gt number
+ * @class: engine class
+ * @property: property of engine class to retrieve
+ * @value: pointer for storing read value
+ *
+ * Convenience wrapper to get value of given property for given engine class on given gt.
+ *
+ * Returns: true on success, false on failure.
+ */
+bool xe_sysfs_engine_class_get_property(int xe_device, int gt, uint16_t class, const char *property,
+					uint32_t *value)
+{
+	int engines_fd;
+
+	engines_fd = xe_sysfs_engine_open(xe_device, gt, class);
+
+	if (engines_fd == -1) {
+		igt_debug("Failed to open %s on gt%d.\n", xe_engine_class_to_str(class), gt);
+
+		return false;
+	}
+
+	if (!__igt_sysfs_get_u32(engines_fd, property, value)) {
+		igt_debug("Failed to read %s property of %s on gt%d.\n", property,
+			  xe_engine_class_to_str(class), gt);
+		close(engines_fd);
+
+		return false;
+	}
+
+	close(engines_fd);
+
+	return true;
+}
+
+/**
+ * xe_sysfs_engine_class_set_property
+ * @xe_device: fd of the device
+ * @gt: gt number
+ * @class: engine class
+ * @property: property of engine class to be modified
+ * @new_value: value to be set
+ * @old_value: pointer for storing old value, can be NULL
+ *
+ * Convenience wrapper to set given property for given engine class on given gt to given value.
+ *
+ * Returns: true on success, false on failure.
+ */
+bool xe_sysfs_engine_class_set_property(int xe_device, int gt, uint16_t class, const char *property,
+					uint32_t new_value, uint32_t *old_value)
+{
+	int engines_fd;
+
+	engines_fd = xe_sysfs_engine_open(xe_device, gt, class);
+
+	if (engines_fd == -1) {
+		igt_debug("Failed to open %s on gt%d.\n", xe_engine_class_to_str(class), gt);
+
+		return false;
+	}
+
+	if (old_value && !__igt_sysfs_get_u32(engines_fd, property, old_value)) {
+		igt_debug("Failed to read %s property of %s on gt%d.\n", property,
+			  xe_engine_class_to_str(class), gt);
+		close(engines_fd);
+
+		return false;
+	}
+
+	if (!__igt_sysfs_set_u32(engines_fd, property, new_value)) {
+		igt_debug("Failed to write %s property of %s on gt%d.\n", property,
+			  xe_engine_class_to_str(class), gt);
+		close(engines_fd);
+
+		return false;
+	}
+
+	close(engines_fd);
+
+	return true;
+}
diff --git a/lib/igt_sysfs.h b/lib/igt_sysfs.h
index 2a1e3b1bf..3cede07f9 100644
--- a/lib/igt_sysfs.h
+++ b/lib/igt_sysfs.h
@@ -175,4 +175,9 @@ int xe_sysfs_get_num_tiles(int xe_device);
 char *xe_sysfs_engine_path(int xe_device, int gt, int class, char *path, int pathlen);
 int xe_sysfs_engine_open(int xe_device, int gt, int class);
 
+bool xe_sysfs_engine_class_get_property(int xe_device, int gt, uint16_t class, const char *property,
+					uint32_t *value);
+bool xe_sysfs_engine_class_set_property(int xe_device, int gt, uint16_t class, const char *property,
+					uint32_t new_value, uint32_t *old_value);
+
 #endif /* __IGT_SYSFS_H__ */
-- 
2.34.1


  reply	other threads:[~2024-10-02 11:29 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-02 11:29 [PATCH v2 i-g-t 0/2] Fix xe_eudebug_online@interrupt-other test Dominik Karol Piątkowski
2024-10-02 11:29 ` Dominik Karol Piątkowski [this message]
2024-10-03 13:58   ` [PATCH v2 i-g-t 1/2] lib/igt_sysfs: Introduce engine_class property helpers Grzegorzek, Dominik
2024-10-07  4:03     ` Zbigniew Kempczyński
2024-10-07  8:15     ` Zbigniew Kempczyński
2024-10-07 11:45   ` Grzegorzek, Dominik
2024-10-02 11:29 ` [PATCH v2 i-g-t 2/2] tests/xe_eudebug_online: Adjust interrupt-other test Dominik Karol Piątkowski
2024-10-03 13:49   ` Grzegorzek, Dominik
2024-10-04  6:01     ` Piatkowski, Dominik Karol
2024-10-02 13:05 ` ✓ CI.xeBAT: success for Fix xe_eudebug_online@interrupt-other test (rev2) Patchwork
2024-10-02 13:13 ` ✓ Fi.CI.BAT: " Patchwork
2024-10-02 14:49 ` ✗ CI.xeFULL: failure " Patchwork
2024-10-03 12:06 ` ✗ Fi.CI.IGT: " 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=20241002112914.5556-2-dominik.karol.piatkowski@intel.com \
    --to=dominik.karol.piatkowski@intel.com \
    --cc=christoph.manszewski@intel.com \
    --cc=dominik.grzegorzek@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=jonathan.cavitt@intel.com \
    --cc=pawel.sikora@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