|
| 1 | +.. _uuid: |
| 2 | + |
| 3 | +UUID Usage in SOF |
| 4 | +################# |
| 5 | + |
| 6 | +Why UUID Needed |
| 7 | +*************** |
| 8 | + |
| 9 | +To develop a new audio signal processing component, we traditionally |
| 10 | +implemented the component driver with a new unique component type |
| 11 | +introduced. The pain points with this method include how to keep the |
| 12 | +ABI (Application Binary Interface) aligned for the topology file, the |
| 13 | +driver, and the firmware. And if unaligned, how should we make them |
| 14 | +backward compatible. For example, When adding a new component, we could |
| 15 | +have 8 types of combination of topology/driver/firmware versions with |
| 16 | +either the new component is supported or not in each |
| 17 | +topology/driver/firmware part. Even more, if enumerated type is used |
| 18 | +for the component type and the sequence in the enumerate list |
| 19 | +(the value) is changed during an update, there could be component type |
| 20 | +collision if versions are not aligned. |
| 21 | + |
| 22 | +UUIDs (Universally Unique Identifiers) provide a more scalable and |
| 23 | +collision-free way of component identification. UUIDs are used as the |
| 24 | +standard interface by all users of the SOF firmware, including the |
| 25 | +tracing subsystem, the topology .m4 files, and the Linux topology |
| 26 | +driver. |
| 27 | + |
| 28 | +Allocating a new UUID for the new added component is recommended, as |
| 29 | +the component type will be replaced by UUID in the IPC structures, |
| 30 | +in the future. For the whole SOF stack, the usage of the UUID shall |
| 31 | +follow rules as below: |
| 32 | + |
| 33 | +UUID Allocation |
| 34 | +*************** |
| 35 | +The UUID allocation of a specific component shall use the version 4 in |
| 36 | +`UUID wikipedia <https://en.wikipedia.org/wiki/Universally_unique_identifier>`__, |
| 37 | +and the value shall be declared in the firmware component driver with |
| 38 | +``DECLARE_SOF_RT_UUID``, for details, please refer to the API |
| 39 | +documentation :ref:`uuid-api`. |
| 40 | + |
| 41 | +UUID in Topology |
| 42 | +**************** |
| 43 | +The same UUID shall be used in topology .m4 file for a new added |
| 44 | +widget (corresponding to the new added component), since we have |
| 45 | +implemented macro to help to handle the conversion task, just use the |
| 46 | +exactly same macro ``DECLARE_SOF_RT_UUID`` as depicted in the firmware |
| 47 | +source, e.g for SRC component the below shall be added to the topology |
| 48 | +.m4 tools/topology/m4/src.m4: |
| 49 | + |
| 50 | +.. code-block:: none |
| 51 | +
|
| 52 | + DECLARE_SOF_RT_UUID("host", host_uuid, 0x8b9d100c, 0x6d78, 0x418f, |
| 53 | + 0x90, 0xa3, 0xe0, 0xe8, 0x05, 0xd0, 0x85, 0x2b); |
| 54 | +
|
| 55 | +Linux Topology Driver |
| 56 | +********************* |
| 57 | +The topology driver will parse the 16-byte UUID token, append it to the |
| 58 | +extended data of the IPC struct, and sent it to the |
| 59 | +firmware in component creation stage, **for all components**. |
| 60 | + |
| 61 | +.. code-block:: none |
| 62 | +
|
| 63 | + /* Component extended tokens */ |
| 64 | + static const struct sof_topology_token comp_ext_tokens[] = { |
| 65 | + {SOF_TKN_COMP_UUID, |
| 66 | + SND_SOC_TPLG_TUPLE_TYPE_UUID, get_token_uuid, |
| 67 | + offsetof(struct sof_ipc_comp_new_ext, uuid), 0}, |
| 68 | + }; |
| 69 | +
|
| 70 | +.. code-block:: none |
| 71 | +
|
| 72 | + static int sof_widget_ready(struct snd_soc_component *scomp, int index, |
| 73 | + struct snd_soc_dapm_widget *w, |
| 74 | + struct snd_soc_tplg_dapm_widget *tw) |
| 75 | + { |
| 76 | + ... |
| 77 | + ret = sof_parse_tokens(scomp, &swidget->comp_ext, comp_ext_tokens, |
| 78 | + ARRAY_SIZE(comp_ext_tokens), tw->priv.array, |
| 79 | + le32_to_cpu(tw->priv.size)); |
| 80 | + ... |
| 81 | + } |
| 82 | +
|
| 83 | +UUID Arrays Stored Section |
| 84 | +************************** |
| 85 | +Only the UUID arrays for component types used in topology file are |
| 86 | +stored to the .rodata section as static data, for limited memory |
| 87 | +footprint purpose, e.g. |
| 88 | +19 component types * 16 Bytes/component type = 304 Bytes. |
| 89 | + |
| 90 | +UUID to Component Driver Mapping |
| 91 | +******************************** |
| 92 | +The firmware will use UUID byte array to match the component driver, if |
| 93 | +it is provided from the Linux driver side, otherwise, fallback to use |
| 94 | +the traditional component type for backwards-compatible behavior. |
| 95 | + |
| 96 | +.. code-block:: none |
| 97 | +
|
| 98 | + static const struct comp_driver *get_drv(struct sof_ipc_comp *comp) |
| 99 | + { |
| 100 | + ... |
| 101 | + /* validate the extended data */ |
| 102 | + ... |
| 103 | + /* use UUID to match the driver if UUID is provided */ |
| 104 | + if (comp->ext_data_offset) { |
| 105 | + /* use component type if old tplg without UUID used */ |
| 106 | + if (sof_is_uuid_nil(comp_ext->uuid)) |
| 107 | + goto comp_type_match; |
| 108 | +
|
| 109 | + /* search driver list with UUID */ |
| 110 | + ... |
| 111 | + /* matched, return drv */ |
| 112 | + return drv; |
| 113 | +
|
| 114 | + /* not found, failed */ |
| 115 | + return NULL; |
| 116 | + } |
| 117 | +
|
| 118 | + comp_type_match: |
| 119 | + /* search driver list for driver type */ |
| 120 | + ... |
| 121 | + /* return the component type matched driver */ |
| 122 | + return drv; |
| 123 | + } |
| 124 | +
|
| 125 | +ABI Alignment for UUID Support |
| 126 | +****************************** |
| 127 | +In general, UUID will be used only all FW/tplg/driver are in ABI version |
| 128 | +equal or greater than 3.17, otherwise component type will be used. |
| 129 | + |
0 commit comments