1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2020 Intel Corporation. All rights reserved.
4  *
5  * Author: Marcin Maka <marcin.maka@linux.intel.com>
6  */
7 
8 #ifndef __SOF_LIB_UUID_H__
9 #define __SOF_LIB_UUID_H__
10 
11 #include <sof/common.h>
12 
13 /** \addtogroup uuid_api UUID API
14  *  UUID API specification.
15  *  @{
16  */
17 
18 /** \brief UUID is 16 bytes long */
19 #define UUID_SIZE 16
20 
21 /** \brief UUID name string max length in bytes, including null termination */
22 #define UUID_NAME_MAX_LEN 32
23 
24 /**
25  * \brief UUID (Universally Unique IDentifier) structure.
26  *
27  * Use DECLARE_SOF_UUID() to assigned UUID to the fw part (component
28  * implementation, dai implementation, ...).
29  *
30  * Use SOF_UUID() to store an address of declared UUID.
31  *
32  * See existing implementation of components and dais for examples how to
33  * UUIDs are declared and assigned to the drivers to provide identification
34  * of the source for their log entries.
35  *
36  * UUID for a new component may be generated with uuidgen Linux tool, part
37  * of the util-linux package.
38  */
39 struct sof_uuid {
40 	uint32_t a;
41 	uint16_t b;
42 	uint16_t c;
43 	uint8_t  d[8];
44 };
45 
46 /**
47  * \brief Connects UUID with component description
48  *
49  * Declaration of this structure should be done by DECLARE_SOF_UUID(),
50  * then declaration will be part of `.static_uuids` section and `SMEX` tool
51  * use it during `ldc` file creation.
52  */
53 struct sof_uuid_entry {
54 	struct sof_uuid id;
55 	const char name[UUID_NAME_MAX_LEN];
56 };
57 
58 #if CONFIG_LIBRARY
59 #define DECLARE_SOF_UUID(entity_name, uuid_name,			\
60 			 va, vb, vc,					\
61 			 vd0, vd1, vd2, vd3, vd4, vd5, vd6, vd7)
62 #define DECLARE_SOF_RT_UUID(entity_name, uuid_name,			\
63 			 va, vb, vc,					\
64 			 vd0, vd1, vd2, vd3, vd4, vd5, vd6, vd7)
65 
66 #define SOF_UUID(uuid_name) 0
67 #define SOF_RT_UUID(uuid_name) NULL
68 
69 #else
70 
71 /** \brief Declares UUID (aaaaaaaa-bbbb-cccc-d0d1-d2d3d4d5d6d7) and name.
72  *
73  * UUID value from variables declared with this macro are unaccessible in
74  * runtime code - UUID dictionary from ldc file is needed get UUID value.
75  *
76  * \param entity_name Name of the object pinted by the software tools.
77  * \param uuid_name Uuid symbol name used with SOF_UUID().
78  * \param va aaaaaaaa value.
79  * \param vb bbbb value.
80  * \param vc cccc value.
81  * \param vd0 d0 value (note how d0 and d1 are grouped in formatted uuid)
82  * \param vd1 d1 value.
83  * \param vd2 d2 value.
84  * \param vd3 d3 value.
85  * \param vd4 d4 value.
86  * \param vd5 d5 value.
87  * \param vd6 d6 value.
88  * \param vd7 d7 value.
89  */
90 #define DECLARE_SOF_UUID(entity_name, uuid_name,			\
91 			 va, vb, vc,					\
92 			 vd0, vd1, vd2, vd3, vd4, vd5, vd6, vd7)	\
93 	__section(".static_uuids")					\
94 	static const struct sof_uuid_entry uuid_name ## _ldc = {	\
95 		{.a = va, .b = vb, .c = vc,				\
96 		 .d = {vd0, vd1, vd2, vd3, vd4, vd5, vd6, vd7}},	\
97 		entity_name "\0"					\
98 	}
99 
100 /** \brief Declares runtime UUID (aaaaaaaa-bbbb-cccc-d0d1-d2d3d4d5d6d7) and name.
101  *
102  * UUID value from variables declared with this macro are accessible in
103  * runtime code - to dereference use SOF_RT_UUID()
104  *
105  * \param entity_name Name of the object pinted by the software tools.
106  * \param uuid_name Uuid symbol name used with SOF_UUID() and SOF_RT_UUID().
107  * \param va aaaaaaaa value.
108  * \param vb bbbb value.
109  * \param vc cccc value.
110  * \param vd0 d0 value (note how d0 and d1 are grouped in formatted uuid)
111  * \param vd1 d1 value.
112  * \param vd2 d2 value.
113  * \param vd3 d3 value.
114  * \param vd4 d4 value.
115  * \param vd5 d5 value.
116  * \param vd6 d6 value.
117  * \param vd7 d7 value.
118  */
119 #define DECLARE_SOF_RT_UUID(entity_name, uuid_name,			\
120 			 va, vb, vc,					\
121 			 vd0, vd1, vd2, vd3, vd4, vd5, vd6, vd7)	\
122 	DECLARE_SOF_UUID(entity_name, uuid_name,			\
123 			 va, vb, vc,					\
124 			 vd0, vd1, vd2, vd3, vd4, vd5, vd6, vd7);	\
125 	const struct sof_uuid uuid_name = {				\
126 		.a = va, .b = vb, .c = vc,				\
127 		.d = {vd0, vd1, vd2, vd3, vd4, vd5, vd6, vd7}		\
128 	}
129 
130 /** \brief Creates local unique 32-bit representation of UUID structure.
131  *
132  * \param uuid_name UUID symbol name declared with DECLARE_SOF_UUID() or
133  *		    DECLARE_SOF_RT_UUID().
134  */
135 #define SOF_UUID(uuid_name) (&(uuid_name ## _ldc))
136 
137 /** \brief Dereference unique 32-bit representation of UUID structure in runtime.
138  *
139  * \param uuid_name UUID symbol name declared with DECLARE_SOF_RT_UUID().
140  */
141 #define SOF_RT_UUID(uuid_name) (&(uuid_name))
142 #endif
143 
144 /** @}*/
145 
146 #endif /* __SOF_LIB_UUID_H__ */
147