diff options
| author | Michal Wajdeczko <michal.wajdeczko@intel.com> | 2026-07-08 00:08:05 +0200 |
|---|---|---|
| committer | Michal Wajdeczko <michal.wajdeczko@intel.com> | 2026-07-11 16:15:22 +0200 |
| commit | ac958330974399ad2b9b5e0924333ecef5e78bed (patch) | |
| tree | bbca3758284b1fec4625aa86e0da198fda1049ad /drivers/gpu/drm/xe | |
| parent | 961826fbcd79133033bc6a90bcf7cb1bb907a250 (diff) | |
| download | linux-next-ac958330974399ad2b9b5e0924333ecef5e78bed.tar.gz linux-next-ac958330974399ad2b9b5e0924333ecef5e78bed.zip | |
drm/xe/guc: Add basic KLV encoding helpers
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>
Link: https://patch.msgid.link/20260707220816.677-4-michal.wajdeczko@intel.com
Diffstat (limited to 'drivers/gpu/drm/xe')
| -rw-r--r-- | drivers/gpu/drm/xe/xe_guc_klv_helpers.c | 56 | ||||
| -rw-r--r-- | drivers/gpu/drm/xe/xe_guc_klv_helpers.h | 3 |
2 files changed, 59 insertions, 0 deletions
diff --git a/drivers/gpu/drm/xe/xe_guc_klv_helpers.c b/drivers/gpu/drm/xe/xe_guc_klv_helpers.c index d0663c226e87..667c4c119541 100644 --- a/drivers/gpu/drm/xe/xe_guc_klv_helpers.c +++ b/drivers/gpu/drm/xe/xe_guc_klv_helpers.c @@ -189,3 +189,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 |
