Commit graph

98 commits

Author SHA1 Message Date
Jaska Uimonen
c57391dd26 topology: plugins: nhlt: fix ssp dai index
There was a conceptual error in handling the separate ssp dais, so fix
it.

Fixes: https://github.com/alsa-project/alsa-utils/pull/164
Signed-off-by: Jaska Uimonen <jaska.uimonen@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-11-04 22:04:40 +01:00
Jaska Uimonen
e13a7d3cf6 topology: plugins: nhlt: add dmic dai index
Dmic might have multiple configurations for the same hw, so add them to
nhlt blob. The configurations are separated by dai_index.

Fixes: https://github.com/alsa-project/alsa-utils/pull/164
Signed-off-by: Jaska Uimonen <jaska.uimonen@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-11-04 22:04:29 +01:00
Yong Zhi
038ed518e9 topology: plugins: fix off by 1 mem allocation error
Fix valgrind memcheck error:

==1337389== Invalid write of size 1
==1337389==    at 0x4A4AFAB: __vsnprintf_internal (vsnprintf.c:117)
==1337389==    by 0x4AECF40: __snprintf_chk (snprintf_chk.c:38)
==1337389==    by 0x484B870: snprintf (stdio2.h:67)
==1337389==    by 0x484B870: print_as_hex_bytes (nhlt-processor.c:112)
==1337389==    by 0x484B870: merge_manifest_data (nhlt-processor.c:154)
==1337389==    by 0x484B870: do_nhlt (nhlt-processor.c:420)
==1337389==    by 0x484B870: _snd_topology_nhlt_process (nhlt-processor.c:484)

The consecutive snprintf overwrites always the previous terminator until
it hits the very last call of:

snprintf(dst, ALSA_BYTE_CHARS + 1, "0x%02x,", *nhlt_buffer);

when the size n given to snprintf is 1 more than allocated.

Fixes: https://github.com/alsa-project/alsa-utils/pull/162
Signed-off-by: Yong Zhi <yong.zhi@intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-11-04 22:03:35 +01:00
Jaroslav Kysela
265dda7715 configure: use AC_DISABLE_STATIC (for topology modules)
Fixes: https://github.com/alsa-project/alsa-utils/issues/152
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-06-02 08:25:51 +02:00
Jaroslav Kysela
65841efdf5 topology: nhlt plugin: second attempt to fix the .so linking
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-31 18:23:59 +02:00
Jaroslav Kysela
cae9b71589 topology: nhlt plugin: fix the .so linking
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-31 18:11:50 +02:00
Jaska Uimonen
96ddc346e0 topology: plugins: nhlt: fix intel dmic mode calculation
Dmic find_modes function was used with same sampling rate for both fifo
a and b parameter calculations. This bug was found in testing two
simultaneous dmic dais in topology. Fix this by introducing a sampling
rate argument for find_modes.

Fixes: https://github.com/alsa-project/alsa-utils/pull/148
Signed-off-by: Jaska Uimonen <jaska.uimonen@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-31 14:10:25 +02:00
Jaroslav Kysela
904bc1dfd4 topology: add missing nhlt headers to Makefile.am
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-03 14:16:43 +02:00
Jaroslav Kysela
3862452e4e topology: add missing pre-process-external.h to Makefile.am
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-03 14:06:13 +02:00
Jaroslav Kysela
42010cfeba topology: do not pass pre_processor_defs to pre_process_plugins()
This parameter is not used.

Link: https://github.com/alsa-project/alsa-utils/pull/129
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-03 13:24:36 +02:00
Jaska Uimonen
f9e6010d5e topology: plugins - add Intel nhlt encoder plugin
Add Intel nhlt acpi table encoder plugin into topology2.0 processing.
Nhlt internal structure is defined in:
https://01.org/sites/default/files/595976_intel_sst_nhlt.pdf
Nhlt acpi table contain vendor specific binary data blobs that are used
in some Intel dsp platforms for configuring the dmic and ssp hardware.

The function of this code is mainly to generate the vendor specific
binary blobs, but as there is existing nhlt parser code and header in
kernel there's no point of re-inventing the container: just use the
existing nhlt acpi table format. Basically this code is creating similar
nhlt acpi table that you would get from: cat
/sys/firmware/acpi/tables/NHLT

This code will have implementation for dmic and ssp endpoints. Thus the
code will translate the topology dai tokens into vendor specific binary
blobs and pack them into nhlt acpi table. Ssp and dmic code is lifted
from Sound Open Firmware (sof) code base, thus it will have BSD-3
license.

This plugin can be enabled from command line with:

alsatplg -DPREPROCESS_PLUGINS="nhlt" -c foo.conf -p -o bar.tplg

You can also dump the nhlt binary into a file with additional define:

-DNHLT_BIN="nhlt.bin"

Link: https://github.com/alsa-project/alsa-utils/pull/129
Signed-off-by: Jaska Uimonen <jaska.uimonen@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-03 13:24:03 +02:00
Jaska Uimonen
44d3e8aa44 topology: add simple topology plugin mechanism
Add a simple plugin interface for processing the topology tree. There
can be cases where parts of the topology need to be translated from the
original format into something else. For example one could calculate
some kind of filter coefficients from filter parameters or some other
binary interface parameters from plain text topology tokens.

Mechanism is similar as in alsa-plugins and in the plugin there should
be only 1 function exported of the form:

int _snd_topology_##pluginname##_process (snd_config_t *input, snd_config_t *output)

Input and output parameters are snd_config tree before and after topology2
pre-processing. So the plugin can modify both if needed. There are cases
where the plugin may need to get information from input tree, but make
modifications to the output.

The plugins to be used can be defined in command line with:

alsatplg -DPREPROCESS_PLUGINS="foobar" -c topology.conf -p -o topology.tplg

Multiple plugins should be separated by ":".

Plugins to be used can also be defined with "Define" clause inside the
topology file (but command line takes precedence):

Define {
       PREPROCESS_PLUGINS "foobar"
}

Link: https://github.com/alsa-project/alsa-utils/pull/129
Signed-off-by: Jaska Uimonen <jaska.uimonen@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-03 13:23:36 +02:00
Ranjani Sridharan
ed36ce25a7 topology: pre-processor: fix seg fault when there no command line defines
In case there are not command line definitions, there is nothing to
merge or delete.

Fixes: https://github.com/alsa-project/alsa-utils/pull/141
Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-01-28 22:39:45 +01:00
Jaroslav Kysela
b5748d329b topology: use a copy of the command line defines
Fixes: a9b3525 ("topology: don't fail when Define section is missing in the included file")
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-01-28 18:53:52 +01:00
Jaroslav Kysela
a9b35252b4 topology: don't fail when Define section is missing in the included file
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-01-28 18:07:46 +01:00
Jaroslav Kysela
31d4afd8ca topology: create Define subtree for command line defines only
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-01-28 18:03:08 +01:00
Jaroslav Kysela
3afa353c0a topology: the includes should be deleted not removed
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-01-28 18:03:07 +01:00
Jaroslav Kysela
7245f63b2e topology: use cached Define subtree in pre_process_includes()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-01-28 10:04:07 +01:00
Jaroslav Kysela
123eecf7fa topology: fix the define section merge from the included files
The bellow commit assumed that the merge of the included file
is to the main configuration tree, but it's for the subtree.
The Define compound from the included file must be handled
separately.

Link: https://github.com/alsa-project/alsa-utils/pull/140
Fixes: e1a0711 ("topology: fix the command line define merge for new includes")
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-01-28 09:45:42 +01:00
Jaroslav Kysela
329cc772af topology: fix the comment for improved -D option
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-01-28 09:29:34 +01:00
Jaroslav Kysela
16f9311174 topology: add support for multiple -D arguments
It may be useful in the makefile rules for example.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-01-27 18:48:20 +01:00
Ranjani Sridharan
c47188f258 topology: pre-process-object: expand variables before validating attributes
With the introduction of variables in the topology files, validation of
attributes values must be done after they are expanded to their defined
values. Also, since valid values for attributes in the class definition
can also be variables, they need to be expanded as well. So, first expand
the attribute values and then check them against expanded valid values.

Fixes: https://github.com/alsa-project/alsa-utils/pull/138
Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-01-27 18:32:06 +01:00
Jaroslav Kysela
5a7ffd5171 topology: rename function free_pre_preprocessor to free_pre_processor
Line up this name with others.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-01-27 15:02:02 +01:00
Jaroslav Kysela
3c665532e0 topology: optimization for pre_processor_defs parsing
Parse the configuration tree only one time and then reuse
it for the merge.

Also, do not pass inc_path to all functions - add it
to the pre-processor structure.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-01-27 14:58:58 +01:00
Jaroslav Kysela
6723b5d413 topology: merge the pre-processor call to one function
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-01-27 14:33:20 +01:00
Jaroslav Kysela
e1a0711329 topology: fix the command line define merge for new includes
The defines from the command line must overwrite the defines
from the included configuration files forcefully.

Link: https://github.com/alsa-project/alsa-utils/pull/129
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-01-27 14:16:38 +01:00
Jaroslav Kysela
84173ff9e3 topology: don't allow to mix verbose level and output to stdout
Fixes: https://github.com/alsa-project/alsa-utils/issues/131
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-01-27 13:04:01 +01:00
Ranjani Sridharan
90f5967178 topology: pre-processor: Move the call to expand variables
Remove the call to snd_config_expand_custom() to expand the top-level
input config. And replace it with calls to snd_config_evaluate_string()
for each non-compound config while processing individual objects. This
will allow retreving variable definitions from object attribute values
and global definitions.

Add a new field "current_obj_cfg" to hold the current object config
being pre-processed.

This will facilitate adding simple math expressions for computing
attribute values for objects based on other attributes. For ex: we can
set the expression for buffer size as follows:

buffer_size "$[($in_channels * 48) * 4]"

The buffer_size attribute value will be computed with the attribute
value "in_channels" based on the expression above. So if $in_channels =
2, buffer_size will be evaluated to 384.

Additionally this change also permits computing attribute values based
on previously computed values. For example:

buffer_size "$[($in_channels * 48) * 4]"
dma_buffer_size "$[$buffer_size * 2]"

dma_buffer_size will be computed as 768. Note that the order of
definitions for buffer_size and dma_buffer_size matters because the
evaluation for dma_buffer_size depends on the evaluation of buffer_size.
In order to conform to this, the tplg_object_copy_and_add_param() is
modified to add attribute configs from class config to an object using
snd_config_before() instead of snd_config_add().

With this change, we no longer need to set the auto_attr_updater for
buffer type widget objects. So remove it.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-12-19 20:32:38 +01:00
Jaroslav Kysela
8e71fba810 topology: fix the file permissions for the generated files
The owner r/w file permissions are too restrictive.
Let umask do it's work and set the r/w permissions to any.

Fixes: https://github.com/alsa-project/alsa-utils/issues/126
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-12-12 19:58:54 +01:00
Jaroslav Kysela
c8c348e28a topology: define -I option only for alsa-lib 1.2.6+
Link: https://github.com/alsa-project/alsa-utils/pull/125
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-12-08 09:56:38 +01:00
Ranjani Sridharan
79f8ae46b6 topology: Add option to pass include path for conditional includes
The include path passed with -I option will override the relative
include path based on the source file.

Fixes: https://github.com/alsa-project/alsa-utils/pull/125
Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-12-08 09:56:25 +01:00
Jaroslav Kysela
7692cfa0c5 topology: fix the include path parsing
When the last '/' is not found use '.' as the source path.

Fixes: https://github.com/alsa-project/alsa-utils/issues/123
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-12-07 09:39:28 +01:00
Jaroslav Kysela
15a5a16eb7 topology: fix compilation for older alsa-lib
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-12-06 11:00:02 +01:00
Jaroslav Kysela
66693b1a77 topology: change include path
Add support for relative (based on the path from the parsed
configuration file) and absolute include path without
ALSA_CONFIG_DIR environment variable usage. The dependency
on the alsa-lib config tree may be added on demand.

Link: https://github.com/alsa-project/alsa-utils/pull/117
Link: https://github.com/alsa-project/alsa-utils/issues/118
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-12-06 10:21:41 +01:00
Ranjani Sridharan
ef3a96367e topology: pre-processor: Add support for conditional includes
Add a new keyword "IncludeByKey" that will be used to conditional
include configuration files based on the argument value supplied during
build time. For example:

IncludeByKey.DMIC_CH_COUNT {
	"[1-4]"	"include/platform/intel/dmic-generic.conf"
}

The above config will include the dmic-generic.conf file if the argument
value for DMIC_CH_COUNT is between 1 and 4.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-12-06 09:19:20 +01:00
Ranjani Sridharan
da8f90c424 topology: Add option to pass pre-processor definitions
Add a -D switch to be able to pass pre-processor definitions that will
be used to expand arguments in the input config file. This will be
useful to generate multiple topology binaries from the same input config
file with different argument values.

For example: if we had a pipeline config as follows:

Object.Pipeline {
	volume-playback.1 {
		dynamic_pipeline $DYNAMIC_PIPELINE
	}
}

We can define the variable for DYNAMIC_PIPELINE as:

Define {
	DYNAMIC_PIPELINE 0
}

And when pre-processing the conf file pass "-D DYNAMIC_PIPELINE=1" to
override the default value for dynamic_pipeline attribute in the input
conf file.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-12-06 09:19:20 +01:00
Jaroslav Kysela
1a32420577 alsatplg: use standard include/asoundlib.h instead direct headers
BugLink: https://github.com/alsa-project/alsa-lib/pull/169
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-09-03 08:49:03 +02:00
Ranjani Sridharan
a1c2275090 topology:pre-process-object: merge object config with parent object config
An object can be declared within a class definition as follows:

Class.Pipeline.volume-playback {
	Object.Widget.pga.0 {
		ramp_step_ms 250
	}
}

While instantiating the volume-pipeline class, the pga object
could be modified as follows:

Object.Pipeline.volume-playback.0 {
	Object.Widget.pga.0 {
		format "s24le"
	}
}

When building the pga.0 object in the class definition, merge
the attributes declared in the volume-playback.0 object to create
a new config as follows to make sure that all attributes are
set for the pga object.

	Object.Widget.pga.0 {
		ramp_step_ms 250
                format "s24le"
        }

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-08-23 16:49:56 +02:00
Ranjani Sridharan
814dc3b19e pre-process-object: set tlv name if config exists already
Do not create TLV config if it exists already. Just
set the string value with the name name.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-08-23 16:49:56 +02:00
Ranjani Sridharan
b13a940618 pre-process-dapm: add data section for kcontrols
Allow support for adding data section for kcontrols.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-08-23 16:49:56 +02:00
Ranjani Sridharan
3d55a99ccd topology: pre-processor: fix typo in pre_process_config()
Fix typo in config variable name. Should be n2 instead of n.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-08-23 16:49:56 +02:00
Ranjani Sridharan
c1f0ec46b4 topology: pre-process-object: dont create if section already exists
Skip creating section when it exists already.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-08-23 16:49:56 +02:00
Ranjani Sridharan
3c81766242 pre-process-object: skip parent update if parent is NULL
Nothing to do for top-level objects with no parent.
Also, add access to the bytes control template.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-08-23 16:49:56 +02:00
Ranjani Sridharan
268f599d24 pre-process-dapm: fix source and sink for DAPM routes
Switch source and sink widgets in the DAPM route.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-08-23 16:49:56 +02:00
Ranjani Sridharan
48ebb1dc0c topology: pre-process-object: Add support for pre-process objects with no builder
Some objects just need tobe processed to add their attributes
to the private data section of their parent objects.
An example of this would be the pdm_config objects for
DMIC DAI's. Each pdm_config object's attributes need
to be added as separate arrays in the DAI object's
private data.

Modify the signature of tplg_add_object_data() to pass
the array_name parameter when multiple objects of the
same type in the same parent are processed.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-08-23 16:49:56 +02:00
Chao Song
b848786f42 topology: pre-process-dapm: update automatic attributes for buffer
Add the function to compute the value for the
"size" automatic attribute in the buffer objects.

Signed-off-by: Chao Song <chao.song@linux.intel.com>
Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-08-23 16:49:56 +02:00
Chao Song
88c6dd6cf4 topology: pre-process-object: add support for updating automatic attributes
Classes definitions in Topology2.0 can have attributes
qualified with the "automatic" constraint. Values for
these attributes will be calculated by the compiler.
This patch provides a generic method for defining automatic
attributes computation logic for different classes.

To update automatic attributes for a class, add an item
in object_build_map with auto_attr_updater defined, and then
add updating logic in the custom auto_attr_updater function.

Signed-off-by: Chao Song <chao.song@linux.intel.com>
Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-08-23 16:49:56 +02:00
Jaroslav Kysela
f076518254 alsatplg: do not do NULL check for string arrays
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-18 10:15:46 +02:00
Jaroslav Kysela
0b8d2dfdcc alsatplg: fix memory-leak in tplg_construct_object_name()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-18 10:11:34 +02:00
Jaroslav Kysela
c58f981e15 topology: fix few coverity detected defects
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-04 10:19:41 +02:00