mirror of
https://github.com/torvalds/linux.git
synced 2026-09-23 13:14:02 +02:00
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
This commit is contained in:
parent
961826fbcd
commit
ac95833097
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user