| /* |
| * Copyright (c) 2018, Intel Corporation |
| * All rights reserved. |
| * |
| * Redistribution and use in source and binary forms, with or without |
| * modification, are permitted provided that the following conditions are met: |
| * * Redistributions of source code must retain the above copyright |
| * notice, this list of conditions and the following disclaimer. |
| * * Redistributions in binary form must reproduce the above copyright |
| * notice, this list of conditions and the following disclaimer in the |
| * documentation and/or other materials provided with the distribution. |
| * * Neither the name of the Intel Corporation nor the |
| * names of its contributors may be used to endorse or promote products |
| * derived from this software without specific prior written permission. |
| * |
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| * POSSIBILITY OF SUCH DAMAGE. |
| * |
| * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com> |
| * Ranjani Sridharan <ranjani.sridharan@linux.intel.com> |
| */ |
| #ifndef _COMMON_TPLG_H |
| #define _COMMON_TPLG_H |
| |
| #include <sound/asoc.h> |
| #include "common_test.h" |
| |
| /* |
| * TODO: include these token from kernel uapi header |
| * Tokens - must match values in topology configurations |
| */ |
| |
| /* buffers */ |
| #define SOF_TKN_BUF_SIZE 100 |
| #define SOF_TKN_BUF_CAPS 101 |
| |
| /* scheduling */ |
| #define SOF_TKN_SCHED_DEADLINE 200 |
| #define SOF_TKN_SCHED_PRIORITY 201 |
| #define SOF_TKN_SCHED_MIPS 202 |
| #define SOF_TKN_SCHED_CORE 203 |
| #define SOF_TKN_SCHED_FRAMES 204 |
| #define SOF_TKN_SCHED_TIMER 205 |
| |
| /* volume */ |
| #define SOF_TKN_VOLUME_RAMP_STEP_TYPE 250 |
| #define SOF_TKN_VOLUME_RAMP_STEP_MS 251 |
| |
| /* SRC */ |
| #define SOF_TKN_SRC_RATE_IN 300 |
| #define SOF_TKN_SRC_RATE_OUT 301 |
| |
| /* Generic components */ |
| #define SOF_TKN_COMP_PERIOD_SINK_COUNT 400 |
| #define SOF_TKN_COMP_PERIOD_SOURCE_COUNT 401 |
| #define SOF_TKN_COMP_FORMAT 402 |
| #define SOF_TKN_COMP_PRELOAD_COUNT 403 |
| |
| struct comp_info { |
| char *name; |
| int id; |
| int type; |
| int pipeline_id; |
| }; |
| |
| struct frame_types { |
| char *name; |
| enum sof_ipc_frame frame; |
| }; |
| |
| static const struct frame_types sof_frames[] = { |
| /* TODO: fix topology to use ALSA formats */ |
| {"s16le", SOF_IPC_FRAME_S16_LE}, |
| {"s24le", SOF_IPC_FRAME_S24_4LE}, |
| {"s32le", SOF_IPC_FRAME_S32_LE}, |
| {"float", SOF_IPC_FRAME_FLOAT}, |
| /* ALSA formats */ |
| {"S16_LE", SOF_IPC_FRAME_S16_LE}, |
| {"S24_LE", SOF_IPC_FRAME_S24_4LE}, |
| {"S32_LE", SOF_IPC_FRAME_S32_LE}, |
| {"FLOAT_LE", SOF_IPC_FRAME_FLOAT}, |
| }; |
| |
| struct sof_topology_token { |
| uint32_t token; |
| uint32_t type; |
| int (*get_token)(void *elem, void *object, uint32_t offset, |
| uint32_t size); |
| uint32_t offset; |
| uint32_t size; |
| }; |
| |
| enum sof_ipc_frame find_format(const char *name); |
| |
| int get_token_uint32_t(void *elem, void *object, uint32_t offset, |
| uint32_t size); |
| |
| int get_token_comp_format(void *elem, void *object, uint32_t offset, |
| uint32_t size); |
| |
| /* Buffers */ |
| static const struct sof_topology_token buffer_tokens[] = { |
| {SOF_TKN_BUF_SIZE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_uint32_t, |
| offsetof(struct sof_ipc_buffer, size), 0}, |
| {SOF_TKN_BUF_CAPS, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_uint32_t, |
| offsetof(struct sof_ipc_buffer, caps), 0}, |
| }; |
| |
| /* scheduling */ |
| static const struct sof_topology_token sched_tokens[] = { |
| {SOF_TKN_SCHED_DEADLINE, SND_SOC_TPLG_TUPLE_TYPE_WORD, |
| get_token_uint32_t, |
| offsetof(struct sof_ipc_pipe_new, deadline), 0}, |
| {SOF_TKN_SCHED_PRIORITY, SND_SOC_TPLG_TUPLE_TYPE_WORD, |
| get_token_uint32_t, |
| offsetof(struct sof_ipc_pipe_new, priority), 0}, |
| {SOF_TKN_SCHED_MIPS, SND_SOC_TPLG_TUPLE_TYPE_WORD, |
| get_token_uint32_t, |
| offsetof(struct sof_ipc_pipe_new, mips), 0}, |
| {SOF_TKN_SCHED_CORE, SND_SOC_TPLG_TUPLE_TYPE_WORD, |
| get_token_uint32_t, |
| offsetof(struct sof_ipc_pipe_new, core), 0}, |
| {SOF_TKN_SCHED_FRAMES, SND_SOC_TPLG_TUPLE_TYPE_WORD, |
| get_token_uint32_t, |
| offsetof(struct sof_ipc_pipe_new, frames_per_sched), 0}, |
| {SOF_TKN_SCHED_TIMER, SND_SOC_TPLG_TUPLE_TYPE_WORD, |
| get_token_uint32_t, |
| offsetof(struct sof_ipc_pipe_new, timer), 0}, |
| }; |
| |
| /* volume */ |
| static const struct sof_topology_token volume_tokens[] = { |
| {SOF_TKN_VOLUME_RAMP_STEP_TYPE, SND_SOC_TPLG_TUPLE_TYPE_WORD, |
| get_token_uint32_t, |
| offsetof(struct sof_ipc_comp_volume, ramp), 0}, |
| {SOF_TKN_VOLUME_RAMP_STEP_MS, |
| SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_uint32_t, |
| offsetof(struct sof_ipc_comp_volume, initial_ramp), 0}, |
| }; |
| |
| /* SRC */ |
| static const struct sof_topology_token src_tokens[] = { |
| {SOF_TKN_SRC_RATE_IN, SND_SOC_TPLG_TUPLE_TYPE_WORD, |
| get_token_uint32_t, |
| offsetof(struct sof_ipc_comp_src, source_rate), 0}, |
| {SOF_TKN_SRC_RATE_OUT, SND_SOC_TPLG_TUPLE_TYPE_WORD, |
| get_token_uint32_t, |
| offsetof(struct sof_ipc_comp_src, sink_rate), 0}, |
| }; |
| |
| /* Tone */ |
| static const struct sof_topology_token tone_tokens[] = { |
| }; |
| |
| /* Generic components */ |
| static const struct sof_topology_token comp_tokens[] = { |
| {SOF_TKN_COMP_PERIOD_SINK_COUNT, |
| SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_uint32_t, |
| offsetof(struct sof_ipc_comp_config, periods_sink), 0}, |
| {SOF_TKN_COMP_PERIOD_SOURCE_COUNT, |
| SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_uint32_t, |
| offsetof(struct sof_ipc_comp_config, periods_source), 0}, |
| {SOF_TKN_COMP_FORMAT, |
| SND_SOC_TPLG_TUPLE_TYPE_STRING, get_token_comp_format, |
| offsetof(struct sof_ipc_comp_config, frame_fmt), 0}, |
| {SOF_TKN_COMP_PRELOAD_COUNT, |
| SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_uint32_t, |
| offsetof(struct sof_ipc_comp_config, preload_count), 0}, |
| }; |
| |
| int sof_parse_tokens(void *object, |
| const struct sof_topology_token *tokens, |
| int count, struct snd_soc_tplg_vendor_array *array, |
| int priv_size); |
| void sof_parse_string_tokens(void *object, |
| const struct sof_topology_token *tokens, |
| int count, |
| struct snd_soc_tplg_vendor_array *array); |
| void sof_parse_uuid_tokens(void *object, |
| const struct sof_topology_token *tokens, |
| int count, |
| struct snd_soc_tplg_vendor_array *array); |
| void sof_parse_word_tokens(void *object, |
| const struct sof_topology_token *tokens, |
| int count, |
| struct snd_soc_tplg_vendor_array *array); |
| |
| int parse_topology(char *filename, struct sof *sof, int *fr_id, int *fw_id, |
| int *sched_id, char *bits_in, char *in_file, |
| char *out_file, struct shared_lib_table *library_table, |
| char *pipeline_msg); |
| |
| #endif |