Sound Open Firmware
Loading...
Searching...
No Matches
tlv.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 *
3 * Copyright(c) 2023 Intel Corporation. All rights reserved.
4 *
5 * Author: Tomasz Leman <tomasz.m.leman@intel.com>
6 */
7
8#ifndef __SOF_TLV_H__
9#define __SOF_TLV_H__
10
11#include <stdint.h>
12#include <string.h>
13#include <sof/compiler_attributes.h>
14
22struct sof_tlv {
23 uint32_t type;
24 uint32_t length;
25 char value[];
27
28struct sof_tl {
29 uint32_t type;
30 uint32_t max_length;
32
39static inline struct sof_tlv *tlv_next(const struct sof_tlv *tlv)
40{
41 if (tlv->length % sizeof(uint32_t) != 0)
42 return NULL;
43
44 return (struct sof_tlv *)((char *)(tlv) + sizeof(*tlv) + tlv->length);
45}
46
54static inline void tlv_value_uint32_set(struct sof_tlv *tlv, uint32_t type, uint32_t value)
55{
56 tlv->type = type;
57 tlv->length = sizeof(uint32_t);
58 memcpy_s(tlv->value, tlv->length, &value, tlv->length);
59}
60
69static inline void tlv_value_set(struct sof_tlv *tlv, uint32_t type, uint32_t length, void *value)
70{
71 tlv->type = type;
72 tlv->length = length;
74}
75
85static inline void tlv_value_get(const void *data,
86 uint32_t size,
87 uint32_t type,
88 void **value,
89 uint32_t *length)
90{
91 const struct sof_tlv *tlv = (const struct sof_tlv *)data;
92 const uint32_t end_addr = (uint32_t)data + size;
93
94 while (tlv && (uint32_t)tlv < end_addr) {
95 if (tlv->type == type) {
96 *value = (void *)tlv->value;
97 *length = tlv->length;
98 break;
99 }
100
101 tlv = tlv_next(tlv);
102 }
103}
104
112static inline void *tlv_value_ptr_get(struct sof_tlv *tlv, uint32_t type)
113{
114 if ((uintptr_t)tlv % sizeof(uint32_t) != 0)
115 return NULL;
116
117 if (tlv->type != type)
118 return NULL;
119
120 return (void *)tlv->value;
121}
122
123#endif /* __SOF_TLV_H__ */
uint32_t data[]
Definition debug_stream_slot.h:2
#define __packed
Definition ext_manifest.h:43
static int memcpy_s(void *dest, size_t dest_size, const void *src, size_t count)
Definition string.h:38
Definition tlv.h:28
uint32_t max_length
Definition tlv.h:30
uint32_t type
Definition tlv.h:29
Type–length–value struct.
Definition tlv.h:22
char value[]
Definition tlv.h:25
uint32_t type
Definition tlv.h:23
uint32_t length
Definition tlv.h:24
static void tlv_value_get(const void *data, uint32_t size, uint32_t type, void **value, uint32_t *length)
Searches a sequence of TLV structures for values of the specified type.
Definition tlv.h:85
static struct sof_tlv * tlv_next(const struct sof_tlv *tlv)
Allows to step through successive values in a sequence of TLV structures.
Definition tlv.h:39
static void tlv_value_set(struct sof_tlv *tlv, uint32_t type, uint32_t length, void *value)
Fills the TLV Structure (general purpose version).
Definition tlv.h:69
char value[]
Definition tlv.h:2
static void tlv_value_uint32_set(struct sof_tlv *tlv, uint32_t type, uint32_t value)
Fills the TLV Structure (version for 32-bit values).
Definition tlv.h:54
uint32_t type
Definition tlv.h:0
static void * tlv_value_ptr_get(struct sof_tlv *tlv, uint32_t type)
Retrieves pointer to the TLV Structure value of the specified type.
Definition tlv.h:112
uint32_t length
Definition tlv.h:1
#define __aligned(x)
Definition compiler_attributes.h:27