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 /** \brief Declares UUID (aaaaaaaa-bbbb-cccc-d0d1-d2d3d4d5d6d7) and name. 59 * 60 * UUID value from variables declared with this macro are unaccessible in 61 * runtime code - UUID dictionary from ldc file is needed get UUID value. 62 * 63 * \param entity_name Name of the object pinted by the software tools. 64 * \param uuid_name Uuid symbol name used with SOF_UUID(). 65 * \param va aaaaaaaa value. 66 * \param vb bbbb value. 67 * \param vc cccc value. 68 * \param vd0 d0 value (note how d0 and d1 are grouped in formatted uuid) 69 * \param vd1 d1 value. 70 * \param vd2 d2 value. 71 * \param vd3 d3 value. 72 * \param vd4 d4 value. 73 * \param vd5 d5 value. 74 * \param vd6 d6 value. 75 * \param vd7 d7 value. 76 */ 77 #define DECLARE_SOF_UUID(entity_name, uuid_name, \ 78 va, vb, vc, \ 79 vd0, vd1, vd2, vd3, vd4, vd5, vd6, vd7) \ 80 __section(".static_uuids") \ 81 static const struct sof_uuid_entry uuid_name ## _ldc = { \ 82 {.a = va, .b = vb, .c = vc, \ 83 .d = {vd0, vd1, vd2, vd3, vd4, vd5, vd6, vd7}}, \ 84 entity_name "\0" \ 85 } 86 87 /** \brief Declares runtime UUID (aaaaaaaa-bbbb-cccc-d0d1-d2d3d4d5d6d7) and name. 88 * 89 * UUID value from variables declared with this macro are accessible in 90 * runtime code - to dereference use SOF_RT_UUID() 91 * 92 * \param entity_name Name of the object pinted by the software tools. 93 * \param uuid_name Uuid symbol name used with SOF_UUID() and SOF_RT_UUID(). 94 * \param va aaaaaaaa value. 95 * \param vb bbbb value. 96 * \param vc cccc value. 97 * \param vd0 d0 value (note how d0 and d1 are grouped in formatted uuid) 98 * \param vd1 d1 value. 99 * \param vd2 d2 value. 100 * \param vd3 d3 value. 101 * \param vd4 d4 value. 102 * \param vd5 d5 value. 103 * \param vd6 d6 value. 104 * \param vd7 d7 value. 105 */ 106 #define DECLARE_SOF_RT_UUID(entity_name, uuid_name, \ 107 va, vb, vc, \ 108 vd0, vd1, vd2, vd3, vd4, vd5, vd6, vd7) \ 109 DECLARE_SOF_UUID(entity_name, uuid_name, \ 110 va, vb, vc, \ 111 vd0, vd1, vd2, vd3, vd4, vd5, vd6, vd7); \ 112 const struct sof_uuid uuid_name = { \ 113 .a = va, .b = vb, .c = vc, \ 114 .d = {vd0, vd1, vd2, vd3, vd4, vd5, vd6, vd7} \ 115 } 116 117 /** \brief Creates local unique 32-bit representation of UUID structure. 118 * 119 * \param uuid_name UUID symbol name declared with DECLARE_SOF_UUID() or 120 * DECLARE_SOF_RT_UUID(). 121 */ 122 #define SOF_UUID(uuid_name) (&(uuid_name ## _ldc)) 123 124 /** \brief Dereference unique 32-bit representation of UUID structure in runtime. 125 * 126 * \param uuid_name UUID symbol name declared with DECLARE_SOF_RT_UUID(). 127 */ 128 #define SOF_RT_UUID(uuid_name) (&(uuid_name)) 129 130 /** @}*/ 131 132 #endif /* __SOF_LIB_UUID_H__ */ 133