From 2245d3d1a674d3f6ecf0a5967a9ff475fe3df9a2 Mon Sep 17 00:00:00 2001 From: Michal Wajdeczko Date: Wed, 8 Jul 2026 00:08:03 +0200 Subject: [PATCH] drm/xe/guc: Allow to print single KLV MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We can decode and print all KLVs from the buffer, but it might be helpful also to allow printing just single already decoded KLV. Extract existing code into new function and make it public. Signed-off-by: Michal Wajdeczko Reviewed-by: MichaƂ Winiarski Link: https://patch.msgid.link/20260707220816.677-2-michal.wajdeczko@intel.com --- drivers/gpu/drm/xe/xe_guc_klv_helpers.c | 54 ++++++++++++++++--------- drivers/gpu/drm/xe/xe_guc_klv_helpers.h | 1 + 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_guc_klv_helpers.c b/drivers/gpu/drm/xe/xe_guc_klv_helpers.c index be992b8da9a1..073b35957790 100644 --- a/drivers/gpu/drm/xe/xe_guc_klv_helpers.c +++ b/drivers/gpu/drm/xe/xe_guc_klv_helpers.c @@ -78,6 +78,39 @@ const char *xe_guc_klv_key_to_string(u16 key) } } +/** + * xe_guc_klv_print_one() - Print single `GuC KLV`_. + * @key: KLV key + * @len: KLV length (in u32 dwords) of the KLV @value + * @value: KLV value (as array of @len u32 dwords) + * @p: the &drm_printer + * + * The buffer may contain more than one KLV. + */ +void xe_guc_klv_print_one(u16 key, u16 len, const u32 *value, struct drm_printer *p) +{ + const char *name = xe_guc_klv_key_to_string(key); + + switch (len) { + case 0: + drm_printf(p, "{ key %#06x : no value } # %s\n", key, name); + break; + case 1: + drm_printf(p, "{ key %#06x : 32b value %u } # %s\n", + key, value[0], name); + break; + case 2: + drm_printf(p, "{ key %#06x : 64b value %#llx } # %s\n", + key, make_u64(value[1], value[0]), name); + break; + default: + drm_printf(p, "{ key %#06x : %zu bytes %*ph } # %s\n", + key, len * sizeof(u32), (int)(len * sizeof(u32)), + value, name); + break; + } +} + /** * xe_guc_klv_print - Print content of the buffer with `GuC KLV`_. * @klvs: the buffer with KLVs @@ -103,26 +136,7 @@ void xe_guc_klv_print(const u32 *klvs, u32 num_dwords, struct drm_printer *p) return; } - switch (len) { - case 0: - drm_printf(p, "{ key %#06x : no value } # %s\n", - key, xe_guc_klv_key_to_string(key)); - break; - case 1: - drm_printf(p, "{ key %#06x : 32b value %u } # %s\n", - key, klvs[0], xe_guc_klv_key_to_string(key)); - break; - case 2: - drm_printf(p, "{ key %#06x : 64b value %#llx } # %s\n", - key, make_u64(klvs[1], klvs[0]), - xe_guc_klv_key_to_string(key)); - break; - default: - drm_printf(p, "{ key %#06x : %zu bytes %*ph } # %s\n", - key, len * sizeof(u32), (int)(len * sizeof(u32)), - klvs, xe_guc_klv_key_to_string(key)); - break; - } + xe_guc_klv_print_one(key, len, klvs, p); klvs += len; num_dwords -= len; diff --git a/drivers/gpu/drm/xe/xe_guc_klv_helpers.h b/drivers/gpu/drm/xe/xe_guc_klv_helpers.h index c676d21c173b..c7b7e61c1250 100644 --- a/drivers/gpu/drm/xe/xe_guc_klv_helpers.h +++ b/drivers/gpu/drm/xe/xe_guc_klv_helpers.h @@ -13,6 +13,7 @@ struct drm_printer; const char *xe_guc_klv_key_to_string(u16 key); +void xe_guc_klv_print_one(u16 key, u16 len, const u32 *value, struct drm_printer *p); 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);