Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Wajdeczko <michal.wajdeczko@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: "Michal Wajdeczko" <michal.wajdeczko@intel.com>,
	"Michał Winiarski" <michal.winiarski@intel.com>
Subject: [PATCH v2 03/13] drm/xe/guc: Add basic KLV encoding helpers
Date: Wed,  8 Jul 2026 00:08:05 +0200	[thread overview]
Message-ID: <20260707220816.677-4-michal.wajdeczko@intel.com> (raw)
In-Reply-To: <20260707220816.677-1-michal.wajdeczko@intel.com>

We plan to encode more data as KLVs. Add helpers for that.

Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Reviewed-by: Michał Winiarski <michal.winiarski@intel.com>
---
 drivers/gpu/drm/xe/xe_guc_klv_helpers.c | 56 +++++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_guc_klv_helpers.h |  3 ++
 2 files changed, 59 insertions(+)

diff --git a/drivers/gpu/drm/xe/xe_guc_klv_helpers.c b/drivers/gpu/drm/xe/xe_guc_klv_helpers.c
index f672f4947768..5f94852a906f 100644
--- a/drivers/gpu/drm/xe/xe_guc_klv_helpers.c
+++ b/drivers/gpu/drm/xe/xe_guc_klv_helpers.c
@@ -187,3 +187,59 @@ int xe_guc_klv_count(const u32 *klvs, u32 num_dwords)
 
 	return num_dwords ? -ENODATA : num_klvs;
 }
+
+static u16 to_num_dwords(size_t size)
+{
+	return round_up(size, sizeof(u32)) / sizeof(u32);
+}
+
+/**
+ * xe_guc_klv_encode_u32() - Encode 32-bit value as KLV.
+ * @klvs: the buffer where to place KLV
+ * @avail: number of dwords (u32) available in the buffer
+ * @key: key to be used
+ * @value: value to be encoded
+ *
+ * Return: pointer to the buffer location past the encoded KLV or
+ *         an ERR_PTR if there was no space to encode the KLV.
+ */
+u32 *xe_guc_klv_encode_u32(u32 *klvs, u32 avail, u16 key, u32 value)
+{
+	u16 len = to_num_dwords(sizeof(u32));
+
+	if (IS_ERR(klvs))
+		return klvs;
+
+	if (avail < GUC_KLV_LEN_MIN + len)
+		return ERR_PTR(-ENOSPC);
+
+	*klvs++ = PREP_GUC_KLV(key, len);
+	*klvs++ = value;
+	return klvs;
+}
+
+/**
+ * xe_guc_klv_encode_u64() - Encode 64-bit value as KLV.
+ * @klvs: the buffer where to place KLV
+ * @avail: number of dwords (u32) available in the buffer
+ * @key: key to be used
+ * @value: value to be encoded
+ *
+ * Return: pointer to the buffer location past the encoded KLV or
+ *         an ERR_PTR if there was no space to encode the KLV.
+ */
+u32 *xe_guc_klv_encode_u64(u32 *klvs, u32 avail, u16 key, u64 value)
+{
+	u16 len = to_num_dwords(sizeof(u64));
+
+	if (IS_ERR(klvs))
+		return klvs;
+
+	if (avail < GUC_KLV_LEN_MIN + len)
+		return ERR_PTR(-ENOSPC);
+
+	*klvs++ = PREP_GUC_KLV(key, len);
+	*klvs++ = lower_32_bits(value);
+	*klvs++ = upper_32_bits(value);
+	return klvs;
+}
diff --git a/drivers/gpu/drm/xe/xe_guc_klv_helpers.h b/drivers/gpu/drm/xe/xe_guc_klv_helpers.h
index c7b7e61c1250..713ef7f7b9f2 100644
--- a/drivers/gpu/drm/xe/xe_guc_klv_helpers.h
+++ b/drivers/gpu/drm/xe/xe_guc_klv_helpers.h
@@ -17,6 +17,9 @@ void xe_guc_klv_print_one(u16 key, u16 len, const u32 *value, struct drm_printer
 void xe_guc_klv_print(const u32 *klvs, u32 num_dwords, struct drm_printer *p);
 int xe_guc_klv_count(const u32 *klvs, u32 num_dwords);
 
+u32 *xe_guc_klv_encode_u32(u32 *klvs, u32 avail, u16 key, u32 value);
+u32 *xe_guc_klv_encode_u64(u32 *klvs, u32 avail, u16 key, u64 value);
+
 /**
  * PREP_GUC_KLV - Prepare KLV header value based on provided key and len.
  * @key: KLV key
-- 
2.47.1


  parent reply	other threads:[~2026-07-07 22:08 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-07 22:08 [PATCH v2 00/13] drm/xe: Add and use more KLV helpers Michal Wajdeczko
2026-07-07 22:08 ` [PATCH v2 01/13] drm/xe/guc: Allow to print single KLV Michal Wajdeczko
2026-07-07 22:08 ` [PATCH v2 02/13] drm/xe/guc: Prepare to print group KLVs Michal Wajdeczko
2026-07-07 22:08 ` Michal Wajdeczko [this message]
2026-07-07 22:08 ` [PATCH v2 04/13] drm/xe/guc: Add string KLV encoding helper Michal Wajdeczko
2026-07-09 12:51   ` Michał Winiarski
2026-07-07 22:08 ` [PATCH v2 05/13] drm/xe/guc: Add object " Michal Wajdeczko
2026-07-09 12:53   ` Michał Winiarski
2026-07-07 22:08 ` [PATCH v2 06/13] drm/xe/guc: Add KLV parsing helper Michal Wajdeczko
2026-07-07 22:08 ` [PATCH v2 07/13] drm/xe/guc: Formalize Reserved KLVs Michal Wajdeczko
2026-07-10 17:25   ` [PATCH v3 " Michal Wajdeczko
2026-07-07 22:08 ` [PATCH v2 08/13] drm/xe/tests: Add GuC KLV helpers basic tests Michal Wajdeczko
2026-07-07 22:08 ` [PATCH v2 09/13] drm/xe/tests: Add string encoding helper test Michal Wajdeczko
2026-07-08 18:07   ` [PATCH v3 " Michal Wajdeczko
2026-07-07 22:08 ` [PATCH v2 10/13] drm/xe/tests: Add object " Michal Wajdeczko
2026-07-10 19:59   ` [PATCH v3 " Michal Wajdeczko
2026-07-07 22:08 ` [PATCH v2 11/13] drm/xe/tests: Add GuC KLV printer test Michal Wajdeczko
2026-07-11  7:36   ` [PATCH v3 " Michal Wajdeczko
2026-07-07 22:08 ` [PATCH v2 12/13] drm/xe/tests: Add migration packet test Michal Wajdeczko
2026-07-08 18:09   ` [PATCH v3 " Michal Wajdeczko
2026-07-07 22:08 ` [PATCH v2 13/13] drm/xe/pf: Handle migration descriptor using KLV helpers Michal Wajdeczko
2026-07-07 22:16 ` ✗ CI.checkpatch: warning for drm/xe: Add and use more KLV helpers (rev2) Patchwork
2026-07-07 22:18 ` ✓ CI.KUnit: success " Patchwork
2026-07-07 23:04 ` ✓ Xe.CI.BAT: " Patchwork
2026-07-08  0:20 ` ✓ Xe.CI.FULL: " Patchwork
2026-07-08 19:04 ` ✗ CI.checkpatch: warning for drm/xe: Add and use more KLV helpers (rev4) Patchwork
2026-07-08 19:05 ` ✓ CI.KUnit: success " Patchwork
2026-07-08 19:55 ` ✓ Xe.CI.BAT: " Patchwork
2026-07-08 23:56 ` ✓ Xe.CI.FULL: " Patchwork
2026-07-10 17:31 ` ✗ CI.checkpatch: warning for drm/xe: Add and use more KLV helpers (rev5) Patchwork
2026-07-10 17:32 ` ✓ CI.KUnit: success " Patchwork
2026-07-10 18:22 ` ✓ Xe.CI.BAT: " Patchwork
2026-07-11  4:04 ` ✓ Xe.CI.FULL: " Patchwork
2026-07-11  7:42 ` ✗ CI.checkpatch: warning for drm/xe: Add and use more KLV helpers (rev7) Patchwork
2026-07-11  7:43 ` ✓ CI.KUnit: success " Patchwork
2026-07-11  8:18 ` ✓ Xe.CI.BAT: " Patchwork
2026-07-11 11:12 ` ✓ Xe.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=20260707220816.677-4-michal.wajdeczko@intel.com \
    --to=michal.wajdeczko@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=michal.winiarski@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