Commit graph

220 commits

Author SHA1 Message Date
Hans de Goede
06543e06e9 ucm: Fix sysw sequence command not working when requesting to ignore errors
When the user requests to ignore sysfs write errors by prefixing
the path with a '-' then we need to skip the '-' when building the
actual path otherwise the write will never work.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-04 10:36:22 +02:00
Jaroslav Kysela
6ddba54a07 ucm: fix the local ucm control device name caching
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-23 21:19:34 +02:00
Jaroslav Kysela
22dfb4bc20 ucm: limit the master config scan to conf.virt.d
The composition of the list of valid UCM cards is a bit
tricky. Scan only ucm2/conf.virt.d tree.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-22 11:47:52 +02:00
Jaroslav Kysela
508506a80c ucm: fixed find-device substitution (non-continuous PCM devices)
The PCM device numbers may be non-continous. Skip them when -ENOENT error
is returned.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-16 14:48:11 +02:00
Jaroslav Kysela
652ddf866f ucm: allow to escape the trailing variable substitution character
Example:

  ${find-device:ctl='hw:0',type=pcm,field=id,regex='USB A{1\\}'}

Unescaped find-device arguments:

  ctl='hw:0',type=pcm,field=id,regex='USB A{1}'

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-16 12:38:29 +02:00
Jaroslav Kysela
ddb0871ec6 ucm: find-device / pcm - the ctl_list may be empty
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-16 10:48:35 +02:00
Jaroslav Kysela
447a676ee5 ucm: add missing uc_mgr_card_close() call to snd_use_case_mgr_open()
Handle the error path correctly.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-15 16:58:29 +02:00
Jaroslav Kysela
02b234a39c ucm: cosmetic code reshuffle in rval_lookup_main()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-15 16:45:12 +02:00
Jaroslav Kysela
1237905559 ucm: fix uc_mgr_has_local_config()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-15 11:49:32 +02:00
Jaroslav Kysela
8e097fd14a ucm: rewrite device value only when the local config exists
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-15 11:38:39 +02:00
Jaroslav Kysela
c83ddd8e56 ucm: return error if fixedboot_list is empty
The application should know, that there is no special
initialization sequence. It's counterpart for
"ucm: return error if boot_list is empty".

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-13 19:13:20 +02:00
Hui Wang
2368a95b8f ucm: return error if boot_list is empty
If bootlist is empty, that means there is no BootSequence defined
in the ucm for this sound card, let set_boot_user() return error,
then alsactl could have chance to use non-ucm ways to initialize the
sound card.

BugLink: https://github.com/alsa-project/alsa-lib/pull/94
Signed-off-by: Hui Wang <hui.wang@canonical.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-13 19:12:35 +02:00
Jaroslav Kysela
f93a28730a ucm: ucm_filename() - avoid double //
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-13 17:20:01 +02:00
Jaroslav Kysela
7e4390137a ucm: handle better the system() call
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-13 17:14:30 +02:00
Jaroslav Kysela
8f5779eb3f ucm: add LibraryConfig support
This commit allows to define private alsa-lib's configuration. When
the configuration is present, the device values ("PlaybackCTL",
"CaptureCTL", "PlaybackMixer", "CaptureMixer", "CapturePCM")
are prefixed with '_ucmHEXA.' string where HEXA is replaced by the
unique hexadecimal number identifying the opened ucm manager handle.

    Syntax 4

    LibraryConfig.a_label.SubstiConfig {
            # substituted library configuration like:
            usr_share_dir "${ConfLibDir}"
    }

    LibraryConfig.b_label.Config {
            # non-substituted library configuration like:
            usr_share_dir "/usr/share/alsa"
    }

    The File counterparts:

    LibraryConfig.c_label.SubstiFile "/some/path"
    LibraryConfig.d_label.File "/some/path"

Note that for files the contents is substituted on the request,
but the file name is always substituted (useful for ${ConfDir} etc.).

The private configuration is not saved or preserved. It's life time
belongs to the opened ucm manager handle.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-13 17:14:28 +02:00
Jaroslav Kysela
62a51c1da1 ucm: add ${ConfLibDir} substitution
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-13 09:23:06 +02:00
Jaroslav Kysela
3cfbacdc34 ucm: add ctl-remove sequence command to delete controls from UCM
Syntax:

   ctl-remove "name='ABCD'"

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-29 11:31:08 +02:00
Jaroslav Kysela
02423dc970 ucm: add cset-new sequence command to create new controls from UCM
This command create a new control using ID, description and value.

Syntax:

    cset-new "name='ABCD',index=2 type=boolean,count=2 on,on"
    cset-new "name='Enum' type=enum,labels='L1;L2;L3' 'L2'"

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-29 11:00:25 +02:00
Jaroslav Kysela
b0b9e4b88d ucm: move __snd_ctl_ascii_elem_id_parse prototype to control_local.h
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-25 20:40:22 +01:00
Jaroslav Kysela
2f57b404b1 ucm: add Path condition type
Check for a file presence and mode.

Modes: exists, read, write, exec

Example:

	If.0 {
		Condition {
			Type Path
			Mode read
			Path "/etc/alsa/something"
			True {
				...
			}
		}
	}

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-23 17:16:14 +01:00
Jaroslav Kysela
0afa61e8f0 ucm: rename sysset to sysw
Fixes: 1c6fb202 ("ucm: implement sysset sequence command")
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-23 11:40:30 +01:00
Jaroslav Kysela
56c11293e3 ucm: warn about unknown sequence commands
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-11 09:26:07 +01:00
Jaroslav Kysela
1c6fb20232 ucm: implement sysset sequence command
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-11 09:26:07 +01:00
Jaroslav Kysela
2b418648cf ucm: ucm_main.c - cosmetic tab cleanups
This file is problematic for the git's tab checker.
The unexpand tool is used to convert initial spaces
to tabs.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-11 09:26:07 +01:00
Jaroslav Kysela
9c194a0ba7 ucm: add _fboot / FixedBootSequence
Actually, the BootSequence is executed only when the driver controls
(identifiers or value types) are changed. It may be handy to have
also a sequence which is executed at _each_ boot without any condition.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-11 09:25:52 +01:00
Jaroslav Kysela
0d232d714a ucm: fix two error messages
- add missing argument to error msg in if_eval_regex_match()
- print correct error value in uc_mgr_config_load_file()

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-02-03 11:57:49 +01:00
Jaroslav Kysela
296b067fc7 ucm: add ${find-card} and ${find-device} substitutions
It may be useful to find a correct card or device through
control API information fields.

Increase the syntax version to 4.

Examples:

  ${find-card:field=name,regex='HDA Intel'}
  ${find-device:type=pcm,field=id,regex='HDMI 1$'}
  ${find-device:ctl=hw:acp,type=pcm,field=id,regex=DMIC}

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-02-03 11:42:56 +01:00
Jaroslav Kysela
3f63dc2644 ucm: uc_mgr_substitute_tree() fix use after free
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-01-07 17:41:38 +01:00
Jaroslav Kysela
437b5b3aae ucm: fix possible memory leak in parse_verb_file()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-01-07 17:32:11 +01:00
Alex Henrie
0f4821ec17 ucm: fix bad frees in get_list0 and get_list20
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2020-12-27 09:21:55 +01:00
Jaroslav Kysela
d77fb47318 ucm: handle correctly Linked configuration
BugLink: https://github.com/alsa-project/alsa-ucm-conf/issues/54
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-10-19 10:52:13 +02:00
Jaroslav Kysela
2b217b7010 ucm: rename once_list to boot_list
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-10-06 10:47:11 +02:00
Jaroslav Kysela
61749cf400 ucm: substitute the comment string also in the main configuration file
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-10-06 10:43:38 +02:00
Jaroslav Kysela
22d5ca8b6b ucm: add a check for the empty configuration
Return an error if the UCM configuration is empty (no verbs
or no boot sequence).

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-10-06 10:43:13 +02:00
Jaroslav Kysela
e80f35611d ucm: Handle 'Error' keyword in the master file
With the conditional blocks, it may be useful to terminate
the hardware detection from the configuration. Introduce
'Error' keyword for the master UCM configuration file.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-10-06 10:23:25 +02:00
Jaroslav Kysela
32addac948 ucm: substitute the merged tree completely
We need to define the common shared configuration like for multiple
HDMI devices or so. Substitute the whole merged configuration tree
including identifiers.

Fixes: https://github.com/alsa-project/alsa-lib/issues/67
Fixes: dcef48f13d
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-07-06 16:34:35 +02:00
Jaroslav Kysela
30d12e930c ucm: fix parse_get_safe_name() - safe name must be checked after substitution
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-07-03 14:48:18 +02:00
Jaroslav Kysela
485930ea5d ucm: substitution - remove duplicate allow_empty assignment
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-06-30 09:22:12 +02:00
Hans de Goede
f4e48d0d15 ucm: Allow empty strings in "${var:...}" substitutions
Recent ucm-conf changes introduce checks like this one in various places:

If.mspk {
        Condition {
                Type String
                Empty "${var:MonoSpeaker}"
        }
        True ...
        False ...
}

The 'Empty "${var:MonoSpeaker}"' part can only every succeed if we do:

Define.MonoSpeaker ""

But so far that would result in an error like this one:

ALSA lib ucm_subs.c:367:(uc_mgr_get_substituted_value) variable '${var:MonoSpeaker}' is not defined in this context!
ALSA lib main.c:983:(snd_use_case_mgr_open) error: failed to import cht-bsw-rt5672 use case configuration -22
alsaucm: error failed to open sound card cht-bsw-rt5672: Invalid argument

This commit fixes this by allowing empty values for "${var:...}"
substitutions.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Tested-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-06-28 17:51:46 +02:00
Jaroslav Kysela
7c9f0fa436 ucm: implement AlwaysTrue Condition.Type
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-06-24 19:27:05 +02:00
Jaroslav Kysela
730481ec2f ucm: simplify get_by_card() in parser.c
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-06-22 09:05:24 +02:00
Jaroslav Kysela
089bb8762f ucm: fix the possible buffer overflow (substitution)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-06-22 09:05:05 +02:00
Jaroslav Kysela
68d3cbfbc3 ucm: implement CardNumberByName substitution
The syntax is ${CardNumberByName:CARDNAME[#INDEX]}.

The CARDNAME is the ALSA's soundcard name (short form).
The INDEX is the instance (0 = first, 1 = second etc.).

Example: ${CardNumberByName:HDA Intel PCH}
(which is identical to ${CardNumberByName:HDA Intel PCH#0})

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-06-18 16:21:16 +02:00
Jaroslav Kysela
f0276cc0bd ucm: allow to use the defined variables in the substitution argument
Example (set variable 'Module' to the kernel module name for the given card):

  Define.SysfsPath "class/sound/card${CardNumber}/device/driver"
  Define.Module "${sys:$SysfsPath}"

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-06-18 16:10:37 +02:00
Jaroslav Kysela
e6be544227 ucm: allow to ignore errors for the value substitution
It may be useful to ignore the errors where the environment
or sysfs values are not defined for the specific hardware.

Enhance substitution for 'syntax 3' so $${} substitution
means ignore the errors (return an empty string).

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-06-18 16:06:12 +02:00
Jaroslav Kysela
7036ea07c8 ucm: include - fix compound_merge for arrays
There is a case where the original array has already new indexes
(the merged array is placed before the original nodes).

Set the temporary index string identifiers to unique strings.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-06-15 19:49:27 +02:00
Jaroslav Kysela
6eb78d41a1 ucm: fix use-after-free in parse_component_seq()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-06-08 18:17:23 +02:00
Jaroslav Kysela
6fad36dd38 ucm: fix the wrong return value in uc_mgr_open_ctl()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-06-08 09:57:35 +02:00
Jaroslav Kysela
9b5fde5054 ucm: remove strict: in ${OpenName} substitution
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-06-08 09:17:57 +02:00
Jaroslav Kysela
e1777ee1a1 ucm: fix the error path in parse_toplevel_path()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-06-08 09:09:39 +02:00