|
| 1 | +.. _uuid: |
| 2 | + |
| 3 | +UUID Usage in SOF |
| 4 | +################# |
| 5 | + |
| 6 | +We use universally unique identifier (UUID) for component type |
| 7 | +definition in SOF, and for the whole SOF stack, the UUID usage is |
| 8 | +following below rules: |
| 9 | + |
| 10 | +UUID allocation |
| 11 | +*************** |
| 12 | +The UUID of a specific component should be specified in the firmware |
| 13 | +component dirver, e.g. for src component, in sof/src/audio/src.c: |
| 14 | + |
| 15 | +.. code-block:: none |
| 16 | +
|
| 17 | + /* c1c5326d-8390-46b4-aa47-95c3beca6550 */ |
| 18 | + DECLARE_SOF_UUID("src", src_uuid, 0xc1c5326d, 0x8390, 0x46b4, |
| 19 | + 0xaa, 0x47, 0x95, 0xc3, 0xbe, 0xca, 0x65, 0x50); |
| 20 | +
|
| 21 | +UUID in topology |
| 22 | +**************** |
| 23 | +We should provide UUID string in topology .m4 file in the exactly same |
| 24 | +format as commented in the firmware, e.g for host it is |
| 25 | +c1c5326d-8390-46b4-aa47-95c3beca6550, so in the topology .m4 file |
| 26 | +tools/topology/m4/src.m4: |
| 27 | + |
| 28 | +.. code-block:: none |
| 29 | +
|
| 30 | + dnl Defines the macro for SRC widget |
| 31 | + define(SRC_UUID_ARRAY, UUID_ARRAY("c1c5326d-8390-46b4-aa47-95c3beca6550")) |
| 32 | +
|
| 33 | +We have a .m4 macro UUID_ARRAY() will help to transfer format in #2 (36 |
| 34 | +digits) to 16 Bytes byte array, after compiled, the corresponding ALSA |
| 35 | +UUID token defined here will be generated: |
| 36 | + |
| 37 | +.. code-block:: none |
| 38 | +
|
| 39 | + /* vendor tuple for uuid */ |
| 40 | + struct snd_soc_tplg_vendor_uuid_elem { |
| 41 | + __le32 token; |
| 42 | + char uuid[16]; |
| 43 | + } __attribute__((packed)); |
| 44 | +
|
| 45 | +Linux topology driver |
| 46 | +********************* |
| 47 | +The topology driver will parse the 16Bytes UUID token and sent it to the |
| 48 | +firmware in component creation stage, **for all components**. |
| 49 | + |
| 50 | +.. code-block:: none |
| 51 | +
|
| 52 | + /* Generic component tokens */ |
| 53 | + static const struct sof_topology_token comp_tokens[] = { |
| 54 | + {SOF_TKN_COMP_CORE_ID, |
| 55 | + SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32, |
| 56 | + offsetof(struct sof_ipc_comp, core), 0}, |
| 57 | + {SOF_TKN_COMP_UUID, |
| 58 | + SND_SOC_TPLG_TUPLE_TYPE_UUID, get_token_uuid, |
| 59 | + offsetof(struct sof_ipc_comp, uuid), 0}, |
| 60 | + }; |
| 61 | +
|
| 62 | +.. code-block:: none |
| 63 | +
|
| 64 | + static int sof_widget_ready(struct snd_soc_component *scomp, int index, |
| 65 | + struct snd_soc_dapm_widget *w, |
| 66 | + struct snd_soc_tplg_dapm_widget *tw) |
| 67 | + { |
| 68 | + ... |
| 69 | + ret = sof_parse_tokens(scomp, &template, comp_tokens, |
| 70 | + ARRAY_SIZE(comp_tokens), tw->priv.array, |
| 71 | + le32_to_cpu(tw->priv.size)); |
| 72 | + ... |
| 73 | + } |
| 74 | +
|
| 75 | +UUID arrays stored section |
| 76 | +************************** |
| 77 | +The UUID arrays are stored to SRAM in firmware, though it will lead to a |
| 78 | +1~4KB (depends on how many modules are compiled) memory consumption |
| 79 | +increase. e.g. in src/platform/cannonlake/cannonlake.x.in: |
| 80 | + |
| 81 | +.. code-block:: none |
| 82 | +
|
| 83 | + .fw_ready : ALIGN(4) |
| 84 | + { |
| 85 | + KEEP (*(.fw_ready)) |
| 86 | + KEEP (*(.fw_ready_metadata)) |
| 87 | + } >sof_fw :sof_fw_phdr |
| 88 | +
|
| 89 | +UUID to component driver mapping |
| 90 | +******************************** |
| 91 | +The firmware will use UUID byte array as the first choice to match the |
| 92 | +component driver, and fallback to use traditional component type if |
| 93 | +failed: |
| 94 | + |
| 95 | +.. code-block:: none |
| 96 | +
|
| 97 | + struct comp_dev *comp_new(struct sof_ipc_comp *comp) |
| 98 | + { |
| 99 | + struct comp_dev *cdev; |
| 100 | + const struct comp_driver *drv; |
| 101 | +
|
| 102 | + /* find the driver for our new component with uuid */ |
| 103 | + drv = get_drv_from_uuid(comp->uuid); |
| 104 | + if (!drv) { |
| 105 | + tr_warn(&comp_tr, "comp_new(), no matched uuid, fallback to use type"); |
| 106 | + drv = get_drv(comp->type); |
| 107 | + if (!drv) { |
| 108 | + tr_err(&comp_tr, "comp_new(): driver not found, comp->type = %u", |
| 109 | + comp->type); |
| 110 | + return NULL; |
| 111 | + } |
| 112 | + } |
| 113 | + ... |
| 114 | + } |
| 115 | +
|
| 116 | +For UUID definition details, please refer to wikepedia page: |
| 117 | +https://en.wikipedia.org/wiki/Universally_unique_identifier |
| 118 | + |
0 commit comments