Commit graph

152 commits

Author SHA1 Message Date
Jaroslav Kysela
f33e596fa6 ucm: config - change the in-place include evaluation order
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-25 19:20:53 +02:00
Jaroslav Kysela
9c88ead1bb ucm: allow syntax version 3
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-25 19:20:53 +02:00
Jaroslav Kysela
04c77aa7f4 ucm: substitute arguments in sequences
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-25 19:20:53 +02:00
Jaroslav Kysela
63c4b49cff ucm: configuration - add DefineRegex
Syntax:

  DefineRegex.VariableName {
    String "something to match"
    Regex "(me)thi(ng)"
  }

Result:

- configuration variable "VariableName" is equal to "mething"
- configuration variable "VariableName1" is equal to "me"
- configuration variable "VariableName2" is equal to "ng"

Notes:

The "Flags" string in the DefineRegex compound may specify
the compilation flags (e = extended, i = ignore case,
s = no substitutes, n = newline). See 'man 3 regex' for
more details.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-25 19:20:53 +02:00
Jaroslav Kysela
ed4567d1c9 ucm: configuration - allow to define the configuration variables
It may be useful for the library files to use the runtime configuration
variables.

Example:

 Define.Var1 "hw:${CardId},2"
 Value.PlaybackPCM "${var:Var1}"

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-25 19:20:53 +02:00
Jaroslav Kysela
6cc6024ac5 ucm: config - substitute File string to allow variables in include
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-25 19:20:53 +02:00
Jaroslav Kysela
8a36b43e03 ucm: configuration - substitute ${ConfDir} and ${ConfTopDir}
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-25 19:20:53 +02:00
Jaroslav Kysela
3edfebc522 ucm: configuration - implement in-place Include
An example:

	Include {
		File "Inc.conf"
		Before.SectionDevice "Mic"
	}

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-25 19:20:53 +02:00
Jaroslav Kysela
14636be4a8 ucm: rename _once command to _boot command
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-25 19:20:18 +02:00
Jaroslav Kysela
d05bd80593 ucm: rename SectionOnce to BootSequence
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-25 19:07:12 +02:00
Jaroslav Kysela
2d6eff3927 ucm: fix compilation error in set_defaults_user()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-19 10:55:35 +02:00
Jaroslav Kysela
3cab9018cf ucm: fix SectionOnce comment
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-19 08:31:39 +02:00
root
449bf7e191 ucm: initialize mgr->once_list
BugLink: https://github.com/alsa-project/alsa-lib/pull/50

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-16 15:48:35 +02:00
Jaroslav Kysela
0c3776a354 ucm: handle 'set _defaults' command
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-14 18:32:05 +02:00
Jaroslav Kysela
a570634a22 ucm: handle 'set _once' command
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-14 18:25:58 +02:00
Jaroslav Kysela
afb5a9cf61 ucm: execute SectionDefaults lately (when the first verb is set)
We need a way to set the SectionOnce at first before SectionDefaults.
It also does not make sense to run SectionDefaults when the API is
used only to query for values or so.

Execute the SectionDefaults commands only when the first verb
is set (before the verb specific commands).

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-14 18:24:39 +02:00
Jaroslav Kysela
e0da1d2a2a ucm: parse SectionOnce section in the master UCM configuration file
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-14 16:04:38 +02:00
Jaroslav Kysela
76c098bf6e ucm: merge the array items from the condition blocks
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-09 21:51:55 +02:00
Jaroslav Kysela
fb48ad9e4f ucm: fix copy-n-paste typo (RemoveDevice list)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-04-06 17:20:24 +02:00
Jaroslav Kysela
c9605484d1 ucm: fix the device remove operation
- allow to remove device only from conflicting lists
- unify the error codes when the device is not found (ENODEV)

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-04-06 13:25:46 +02:00
Jaroslav Kysela
6137d263f3 ucm: fix uc_mgr_scan_master_configs()
Skip the lookup, if the top level filename does not exist.

Fixes: https://github.com/alsa-project/alsa-ucm-conf/issues/16

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-03-17 16:21:46 +01:00
Jaroslav Kysela
5bc3d4c4c1 ucm: parser - add error message to verb_dev_list_add()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-02-11 10:38:51 +01:00
Jaroslav Kysela
fdf96312fa ucm: fill missing device entries (conflicting / supported)
It is not necessary to maintain this information in sync in the configuration
files. Fill the missing entries to the complementary devices.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-02-07 16:20:56 +01:00
Jaroslav Kysela
251bc204a1 ucm: implement RenameDevice and RemoveDevice verb management
With the conditionals, it may be useful to define the devices
in the included configuration files. To satisfy the specification
requirements (device naming) those device names might require
to be renamed or deleted wrong references from the conflicting
or supported lists.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-02-07 16:20:49 +01:00
Jaroslav Kysela
71a1367bca ucm: the ucm2/ subdirectory is driver name based
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-02-03 15:24:19 +01:00
Jaroslav Kysela
c5a09b0fea ucm: parser - use correct filename in parser_master_file()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-02-03 14:44:13 +01:00
Jaroslav Kysela
7d3fec6ac6 ucm: parser - cosmetic fixes in the comments
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-01-17 18:23:44 +01:00
Jaroslav Kysela
ebf5213cd6 ucm: remove MAX_FILE definition and use correct PATH_MAX
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-01-15 10:40:39 +01:00
Jaroslav Kysela
fe6425af75 ucm: split conf_file_name and conf_dir_name
With ucm2, the file name might differ from the directory
name. Also, allocate those fields.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-01-15 10:40:35 +01:00
Jaroslav Kysela
b34715004f ucm: fix the configuration directory (longname) for ucm2
The new ucm2 expects that the longname directory is shared with
the driver directory. Fix that for 'Syntax 2'.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-01-15 09:49:56 +01:00
Libin Yang
1744159180 ucm: setup conf_format after getting ALSA_CONFIG_UCM_VAR successfully
Set the conf_format to 1 after getting ALSA_CONFIG_UCM_VAR successfully.
Otherwise, the conf_format is not set in this scenario.

Signed-off-by: Libin Yang <libin.yang@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-12-11 08:01:47 +01:00
Fabrice Fontaine
8e2c70add7 src/ucm/main.c: fix build without mixer
Commit 4ce38a5ff4 breaks the build without
mixer on:

  CCLD     libasound.la
/home/buildroot/autobuild/instance-1/output-1/host/lib/gcc/xtensa-buildroot-linux-uclibc/8.3.0/../../../../xtensa-buildroot-linux-uclibc/bin/ld: ucm/.libs/libucm.a(main.o): in function `snd_use_case_set':
main.c:(.text+0x185c): undefined reference to `snd_mixer_selem_id_parse'

Fixes: http://autobuild.buildroot.org/results/4d91c9f82a2a61c50c457a851073b85cc09ea345

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-12-03 20:55:34 +01:00
Hans de Goede
e59034a0be ucm: Do not fail to parse configs on cards with an empty CardComponents lists
Since the UCM profiles for all Bay- and Cherry-Trail SST cards have been
moved over to UCM2, parsing them fails with:

ALSA lib ucm_subs.c:220:(uc_mgr_get_substituted_value) variable '${CardComponents}' is not defined in this context!

This completely breaks audio support on all Bay- and Cherry-Trail devices.

This is caused by these non-SOF ASoC using cards having an empty
CardComponents list. Which in itself is fine, but is rejected by
the ucm_subs.c code. This commit changes the ucm_subs code to accept
an empty string as a valid value for CardComponents restoring audio
functionality on these boards.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-12-03 20:37:43 +01:00
Jaroslav Kysela
ebdd2b6cdb ucm: add _identifiers list
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-30 20:31:55 +01:00
Jaroslav Kysela
9baf64da2f ucm: return always at least NULL if no list is available in snd_use_case_get_list()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-29 22:32:21 +01:00
paulhsia
c79f09e1f5 ucm: Use strncmp to avoid access-out-of-boundary
If the length of the identifier is less than the length of the prefix,
access-out-of-boundary will occur in memcmp().

Signed-off-by: paulhsia <paulhsia@chromium.org>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-29 20:48:56 +01:00
Jaroslav Kysela
15970ebf7f ucm: add support for ControlEnum in ControlExists condition
Condition {
  Type ControlExists
  Control "name='Capture Input'"
  ControlEnum "Headphone Mic"
}

The result is true if the control exists, it is the enumerated
type and has the item with the ControlEnum text (name).

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-29 09:34:09 +01:00
Jaroslav Kysela
6eb4f8a724 ucm: conditions - fix the wrong string/substring match
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-28 19:54:52 +01:00
Jaroslav Kysela
4c89f4eb90 ucm: fix the cdev initialization sequence
The default values must be set before the defaults
UCM sequence is executed.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-26 17:35:18 +01:00
Jaroslav Kysela
cf630e4e54 ucm: remove the new-line for uc_error() calls
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-25 19:50:47 +01:00
Jaroslav Kysela
4a480362eb ucm: add ${CardDriver} substitution
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-21 08:15:38 +01:00
Jaroslav Kysela
cb84b02702 ucm: implement ${sys:sysfs/path} substitution
Example:

Condition {
	Type String
	String1 "${sys:class/dmi/id/board_vendor}"
	String2 "LENOVO"
}

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-20 13:58:17 +01:00
Jaroslav Kysela
2e53bbd876 ucm: quick fix for the previous commit when ALSA_CONFIG_UCM_VAR is set
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-19 14:15:00 +01:00
Jaroslav Kysela
10a63e093c ucm: fix again the long name configuration filename lookup
The fix in commit 77119d83a1 assumes that both ucm1 / ucm2 directories
have the configurations for the long name in the same directory. For v2
we changed the location to card_name/card_long_name aka
driver_name/driver_long_name to make the directory layout more structured.

Fixes: 77119d83a1 ("ucm: Fix opening of master-configs by the card's longname")

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-19 13:11:35 +01:00
Hans de Goede
8c4301e7a8 ucm: parser: Fix snprintf usage
There is no need to manually 0 terminate the buffer with snprintf,
only strncpy has the very unfortunate behavior of not guaranteeing 0
termination.

Likewise there is no need to substract one from the buffer size of
the buffer passed to snprintf.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-19 12:45:46 +01:00
Hans de Goede
b3a02322d4 ucm: Only look in ucm[1] or ucm2 dir once we've found a config file in one
Unless environment variables are set, then configuration_filename()
when initially called by load_master_config() will first try to find
the requested master-config under <prefix>/alsa/ucm2 and then under
<prefix>/alsa/ucm.

Once a master-config is found this way, we should set conf_format to
match, so that subsequent lookups only look under the same directory
as where the master-config was found.

This fixes 2 problems:
1. uc_mgr_config_load() looking under <prefix>/alsa/ucm for includes for
   UCM2 profiles because it is called with uc_mgr->conf_format as format
   and before this commit that would stay 0 when autodetecion is used.

2. parse_verb_file() possibly loading an UCM2 verb-file for an UCM1 profile,
   the chance of this happening is small as this means that even though
   there is no UCM2 master-config there is an UCM2 profile dir matching
   uc_mgr->conf_file_name, which would be weird.

Fixes: aba2260ae7 ("ucm: switch to ucm2 directory and v2 format, keep backward compatibility")
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-19 12:45:38 +01:00
Hans de Goede
77119d83a1 ucm: Fix fallback to card_name (shortname) config for ucm1 profiles
uc_mgr_import_master_config() first calls load_master_config()
with the card's longname and if that fails then calls it again with the
card_name.

Before this commit configuration_filename() would force conf_format to 2
when it the access(fn, R_OK) test failed for the ucm1 longname
master-config filename.

This would cause configuration_filename() to blindly return a filename
under <prefix>/ucm2 without seeing if that is actually there and without
trying to fallback to the old profiles under <prefix>/ucm, breaking the
loading of UCM1 profiles by card_name.

This commit fixes this by modifying configuration_filename() to not set
conf_format when checking for the UCM1 config filename fails.
Instead, to make sure that any errors about opening the file still report
the new path, configuration_filename() now resets the filename to the UCM2
path if the access() check has failed for both the UCM2 and UCM1 paths,
without touching conf_format.

Fixes: aba2260ae7 ("ucm: switch to ucm2 directory and v2 format, keep backward compatibility")
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-19 12:45:30 +01:00
Hans de Goede
86c449d231 ucm: Fix opening of master-configs by the card's longname
Prior to commit aba2260ae7 ("ucm: switch to ucm2 directory and v2 format,
keep backward compatibility").

The filename build in parse_verb_file() was build like this:
<prefix>/<uc_mgr->conf_file_name>/<file>

Where uc_mgr->conf_file_name would contain either the card_name or the
card's longname depending on the detection of a longname based config in
uc_mgr_import_master_config().

While the filename used in load_master_config() was build like this:
<prefix>/<card_name>/<card_name>.conf

And uc_mgr_import_master_config() first calls load_master_config()
with the card's longname and if that succeeds it overwrites
uc_mgr->conf_file_name with the longname so that the subsequent uses
of uc_mgr->conf_file_name in parse_verb_file() correctly use the longname.

But the new configuration_filename() helper added in commit aba2260ae7
_always_ builds the filename like this:
<prefix>/<uc_mgr->conf_file_name>/<file><suffix>

This breaks the loading of the master-config by its longname, as when
the longname is tried uc_mgr->conf_file_name still contains the card_name.

This commit fixes this by adding a dir parameter to configuration_filename()
and restoring the old behavior by passing card_name as dir in
load_master_config().

Fixes: aba2260ae7 ("ucm: switch to ucm2 directory and v2 format, keep backward compatibility")
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-19 12:25:19 +01:00
Jaroslav Kysela
6a76c01a01 ucm: fix memory leaks detected by the coverity checker
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-15 12:52:36 +01:00
Jaroslav Kysela
a0b00a954e ucm: add possibility to keep order of childs for If blocks
Because of the nature of the structured parser, it is not guaranteed
that the order of the parsed tree is equal to the lines in the source.

Add possibility to insert the If results before or after the selected
identifier like:

SectionDevice."Speaker" {
  ...
}

If.1 {
	Condition { ... }
	Before.SectionDevice "Speaker"
	True { ... }
}
If.2 {
	Condition { ... }
	After.SectionDevice "Speaker"
	True { ... }
}

If the "After" or "Before" identifiers are not found, the result is added
after the last entry in the block.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-14 17:21:20 +01:00