Ranjani Sridharan | 4670402 | 2018-05-31 19:29:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018, Intel Corporation |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * * Neither the name of the Intel Corporation nor the |
| 13 | * names of its contributors may be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 26 | * POSSIBILITY OF SUCH DAMAGE. |
| 27 | * |
| 28 | * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com> |
| 29 | * Ranjani Sridharan <ranjani.sridharan@linux.intel.com> |
| 30 | */ |
| 31 | #ifndef _COMMON_TPLG_H |
| 32 | #define _COMMON_TPLG_H |
| 33 | |
| 34 | #include <sound/asoc.h> |
| 35 | #include "common_test.h" |
| 36 | |
| 37 | /* |
| 38 | * TODO: include these token from kernel uapi header |
| 39 | * Tokens - must match values in topology configurations |
| 40 | */ |
| 41 | |
| 42 | /* buffers */ |
| 43 | #define SOF_TKN_BUF_SIZE 100 |
| 44 | #define SOF_TKN_BUF_CAPS 101 |
| 45 | |
| 46 | /* scheduling */ |
| 47 | #define SOF_TKN_SCHED_DEADLINE 200 |
| 48 | #define SOF_TKN_SCHED_PRIORITY 201 |
| 49 | #define SOF_TKN_SCHED_MIPS 202 |
| 50 | #define SOF_TKN_SCHED_CORE 203 |
| 51 | #define SOF_TKN_SCHED_FRAMES 204 |
| 52 | #define SOF_TKN_SCHED_TIMER 205 |
| 53 | |
| 54 | /* volume */ |
| 55 | #define SOF_TKN_VOLUME_RAMP_STEP_TYPE 250 |
| 56 | #define SOF_TKN_VOLUME_RAMP_STEP_MS 251 |
| 57 | |
| 58 | /* SRC */ |
| 59 | #define SOF_TKN_SRC_RATE_IN 300 |
| 60 | #define SOF_TKN_SRC_RATE_OUT 301 |
| 61 | |
| 62 | /* Generic components */ |
| 63 | #define SOF_TKN_COMP_PERIOD_SINK_COUNT 400 |
| 64 | #define SOF_TKN_COMP_PERIOD_SOURCE_COUNT 401 |
| 65 | #define SOF_TKN_COMP_FORMAT 402 |
| 66 | #define SOF_TKN_COMP_PRELOAD_COUNT 403 |
| 67 | |
| 68 | struct comp_info { |
| 69 | char *name; |
| 70 | int id; |
| 71 | int type; |
| 72 | int pipeline_id; |
| 73 | }; |
| 74 | |
| 75 | struct frame_types { |
| 76 | char *name; |
| 77 | enum sof_ipc_frame frame; |
| 78 | }; |
| 79 | |
| 80 | static const struct frame_types sof_frames[] = { |
| 81 | /* TODO: fix topology to use ALSA formats */ |
| 82 | {"s16le", SOF_IPC_FRAME_S16_LE}, |
| 83 | {"s24le", SOF_IPC_FRAME_S24_4LE}, |
| 84 | {"s32le", SOF_IPC_FRAME_S32_LE}, |
| 85 | {"float", SOF_IPC_FRAME_FLOAT}, |
| 86 | /* ALSA formats */ |
| 87 | {"S16_LE", SOF_IPC_FRAME_S16_LE}, |
| 88 | {"S24_LE", SOF_IPC_FRAME_S24_4LE}, |
| 89 | {"S32_LE", SOF_IPC_FRAME_S32_LE}, |
| 90 | {"FLOAT_LE", SOF_IPC_FRAME_FLOAT}, |
| 91 | }; |
| 92 | |
| 93 | struct sof_topology_token { |
| 94 | uint32_t token; |
| 95 | uint32_t type; |
| 96 | int (*get_token)(void *elem, void *object, uint32_t offset, |
| 97 | uint32_t size); |
| 98 | uint32_t offset; |
| 99 | uint32_t size; |
| 100 | }; |
| 101 | |
| 102 | enum sof_ipc_frame find_format(const char *name); |
| 103 | |
| 104 | int get_token_uint32_t(void *elem, void *object, uint32_t offset, |
| 105 | uint32_t size); |
| 106 | |
| 107 | int get_token_comp_format(void *elem, void *object, uint32_t offset, |
| 108 | uint32_t size); |
| 109 | |
| 110 | /* Buffers */ |
| 111 | static const struct sof_topology_token buffer_tokens[] = { |
| 112 | {SOF_TKN_BUF_SIZE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_uint32_t, |
| 113 | offsetof(struct sof_ipc_buffer, size), 0}, |
| 114 | {SOF_TKN_BUF_CAPS, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_uint32_t, |
| 115 | offsetof(struct sof_ipc_buffer, caps), 0}, |
| 116 | }; |
| 117 | |
| 118 | /* scheduling */ |
| 119 | static const struct sof_topology_token sched_tokens[] = { |
| 120 | {SOF_TKN_SCHED_DEADLINE, SND_SOC_TPLG_TUPLE_TYPE_WORD, |
| 121 | get_token_uint32_t, |
| 122 | offsetof(struct sof_ipc_pipe_new, deadline), 0}, |
| 123 | {SOF_TKN_SCHED_PRIORITY, SND_SOC_TPLG_TUPLE_TYPE_WORD, |
| 124 | get_token_uint32_t, |
| 125 | offsetof(struct sof_ipc_pipe_new, priority), 0}, |
| 126 | {SOF_TKN_SCHED_MIPS, SND_SOC_TPLG_TUPLE_TYPE_WORD, |
| 127 | get_token_uint32_t, |
| 128 | offsetof(struct sof_ipc_pipe_new, mips), 0}, |
| 129 | {SOF_TKN_SCHED_CORE, SND_SOC_TPLG_TUPLE_TYPE_WORD, |
| 130 | get_token_uint32_t, |
| 131 | offsetof(struct sof_ipc_pipe_new, core), 0}, |
| 132 | {SOF_TKN_SCHED_FRAMES, SND_SOC_TPLG_TUPLE_TYPE_WORD, |
| 133 | get_token_uint32_t, |
| 134 | offsetof(struct sof_ipc_pipe_new, frames_per_sched), 0}, |
| 135 | {SOF_TKN_SCHED_TIMER, SND_SOC_TPLG_TUPLE_TYPE_WORD, |
| 136 | get_token_uint32_t, |
| 137 | offsetof(struct sof_ipc_pipe_new, timer), 0}, |
| 138 | }; |
| 139 | |
| 140 | /* volume */ |
| 141 | static const struct sof_topology_token volume_tokens[] = { |
| 142 | {SOF_TKN_VOLUME_RAMP_STEP_TYPE, SND_SOC_TPLG_TUPLE_TYPE_WORD, |
| 143 | get_token_uint32_t, |
| 144 | offsetof(struct sof_ipc_comp_volume, ramp), 0}, |
| 145 | {SOF_TKN_VOLUME_RAMP_STEP_MS, |
| 146 | SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_uint32_t, |
| 147 | offsetof(struct sof_ipc_comp_volume, initial_ramp), 0}, |
| 148 | }; |
| 149 | |
| 150 | /* SRC */ |
| 151 | static const struct sof_topology_token src_tokens[] = { |
| 152 | {SOF_TKN_SRC_RATE_IN, SND_SOC_TPLG_TUPLE_TYPE_WORD, |
| 153 | get_token_uint32_t, |
| 154 | offsetof(struct sof_ipc_comp_src, source_rate), 0}, |
| 155 | {SOF_TKN_SRC_RATE_OUT, SND_SOC_TPLG_TUPLE_TYPE_WORD, |
| 156 | get_token_uint32_t, |
| 157 | offsetof(struct sof_ipc_comp_src, sink_rate), 0}, |
| 158 | }; |
| 159 | |
| 160 | /* Tone */ |
| 161 | static const struct sof_topology_token tone_tokens[] = { |
| 162 | }; |
| 163 | |
| 164 | /* Generic components */ |
| 165 | static const struct sof_topology_token comp_tokens[] = { |
| 166 | {SOF_TKN_COMP_PERIOD_SINK_COUNT, |
| 167 | SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_uint32_t, |
| 168 | offsetof(struct sof_ipc_comp_config, periods_sink), 0}, |
| 169 | {SOF_TKN_COMP_PERIOD_SOURCE_COUNT, |
| 170 | SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_uint32_t, |
| 171 | offsetof(struct sof_ipc_comp_config, periods_source), 0}, |
| 172 | {SOF_TKN_COMP_FORMAT, |
| 173 | SND_SOC_TPLG_TUPLE_TYPE_STRING, get_token_comp_format, |
| 174 | offsetof(struct sof_ipc_comp_config, frame_fmt), 0}, |
| 175 | {SOF_TKN_COMP_PRELOAD_COUNT, |
| 176 | SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_uint32_t, |
| 177 | offsetof(struct sof_ipc_comp_config, preload_count), 0}, |
| 178 | }; |
| 179 | |
| 180 | int sof_parse_tokens(void *object, |
| 181 | const struct sof_topology_token *tokens, |
| 182 | int count, struct snd_soc_tplg_vendor_array *array, |
| 183 | int priv_size); |
| 184 | void sof_parse_string_tokens(void *object, |
| 185 | const struct sof_topology_token *tokens, |
| 186 | int count, |
| 187 | struct snd_soc_tplg_vendor_array *array); |
| 188 | void sof_parse_uuid_tokens(void *object, |
| 189 | const struct sof_topology_token *tokens, |
| 190 | int count, |
| 191 | struct snd_soc_tplg_vendor_array *array); |
| 192 | void sof_parse_word_tokens(void *object, |
| 193 | const struct sof_topology_token *tokens, |
| 194 | int count, |
| 195 | struct snd_soc_tplg_vendor_array *array); |
| 196 | |
| 197 | int parse_topology(char *filename, struct sof *sof, int *fr_id, int *fw_id, |
Ranjani Sridharan | 03067c6 | 2018-06-27 15:09:25 -0700 | [diff] [blame] | 198 | int *sched_id, char *bits_in, char *in_file, |
| 199 | char *out_file, struct shared_lib_table *library_table, |
| 200 | char *pipeline_msg); |
Ranjani Sridharan | 4670402 | 2018-05-31 19:29:05 -0700 | [diff] [blame] | 201 | |
| 202 | #endif |