[alsa-devel] [PATCH v3 0/3] ucm: Add support for component devices
From: Mengdong Lin mengdong.lin@linux.intel.com
Sound cards are defined by machines. And off-soc codecs and DSPs embedded in DSP can be taken as the components and resued by different machines/ sound cards. This series allows codec and SOC vendors to install UCM configuration files for a specific codec or DSP, and sound card verb files can include these conf files of components.
Component devices will not be exposed to applications for backward compatibility. So audio servers like PulseAudio and CRAS still only see the machine devices.
History: v2: Use an array to define component directories. Document syntax to enable/disable a component device. Hide cdev defined by the parent device in ucm manager for executing a component sequence.
v3: No longer use macros for UCM manager to enter/exit component domain, to make code simpler.
Mengdong Lin (3): ucm: Skip component directories when scanning sound card configuration files ucm: Parse sequence of component devices ucm: Execute sequence of component devices
src/ucm/main.c | 78 +++++++++++++++++++++++++- src/ucm/parser.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++- src/ucm/ucm_local.h | 19 +++++++ src/ucm/utils.c | 1 + 4 files changed, 249 insertions(+), 3 deletions(-)
From: Mengdong Lin mengdong.lin@linux.intel.com
Cards are defined by machines. DSPs embedded in SoC and off-soc codecs can be taken as components for machines, and can be reused by different machines/cards. Codec and SoC vendors can define their own UCM config files. If a codec or DSP is used by a machine, the card configuration file can include the conf file of the codec and DSP. Later patches will complete support for this feature.
Two new directories will be used to store the UCM configuration files for a specific codec or DSP firmware: - /usr/share/alsa/ucm/dsps ... for DSP embedded in SoC - /usr/share/alsa/ucm/codecs ... for off-soc codecs
These two directories will be skipped when UCM manager scans the card directories under /usr/share/alsa/ucm.
Signed-off-by: Mengdong Lin mengdong.lin@linux.intel.com
diff --git a/src/ucm/parser.c b/src/ucm/parser.c index 13f62d7..5c99ab4 100644 --- a/src/ucm/parser.c +++ b/src/ucm/parser.c @@ -36,6 +36,25 @@ /** The name of the environment variable containing the UCM directory */ #define ALSA_CONFIG_UCM_VAR "ALSA_CONFIG_UCM"
+/* Directories to store UCM configuration files for components, like + * off-soc codecs or embedded DSPs. Components can define their own + * devices and sequences, to be reused by sound cards/machines. UCM + * manager should not scan these component directories. + * Machine use case files can include component configratuation files + * via alsaconf syntax: + * searchdir:component-directory-name and <component-conf-file-name>. + * Alsaconf will import the included files automatically. After including + * a component file, a machine device's sequence can enable or disable + * a component device via syntax: + * enadev "component_device_name" + * disdev "component_device_name" + */ +static const char * const component_dir[] = { + "codecs", /* for off-soc codecs */ + "dsps", /* for DSPs embedded in SoC */ + NULL, /* terminator */ +}; + static int parse_sequence(snd_use_case_mgr_t *uc_mgr, struct list_head *base, snd_config_t *cfg); @@ -1259,7 +1278,28 @@ static int filename_filter(const struct dirent *dirent) return 0; }
-/* scan all cards and comments */ +/* whether input dir is a predefined component directory */ +static int is_component_directory(const char *dir) +{ + int i = 0; + + while (component_dir[i]) { + if (!strncmp(dir, component_dir[i], PATH_MAX)) + return 1; + i++; + }; + + return 0; +} + +/* scan all cards and comments + * + * Cards are defined by machines. Each card/machine installs its UCM + * configuration files in a subdirectory with the same name as the sound + * card under /usr/share/alsa/ucm. This function will scan all the card + * directories and skip the component directories defined in the array + * component_dir. + */ int uc_mgr_scan_master_configs(const char **_list[]) { char filename[MAX_FILE], dfl[MAX_FILE]; @@ -1309,6 +1349,11 @@ int uc_mgr_scan_master_configs(const char **_list[]) }
for (i = 0; i < cnt; i++) { + + /* Skip the directories for component devices */ + if (is_component_directory(namelist[i]->d_name)) + continue; + err = load_master_config(namelist[i]->d_name, &cfg); if (err < 0) goto __err;
From: Mengdong Lin mengdong.lin@linux.intel.com
A machine device's sequence can enable or disable a component device by keyword 'enadev' and 'disdev' followed the name of the component device.
UCM sequence parser will find the component device and mark if its enable or disable sequence is needed by the parent, the machine device.
New element type and struct are defined for the sequence of a component device. Component devices will be removed from the machine device list 'device_list' of a verb, since we don't want to expose them to audio servers with original API to list devices for backward compatibility. A new list 'cmpt_device_list' is used for the component devices of a verb.
Signed-off-by: Mengdong Lin mengdong.lin@linux.intel.com
diff --git a/src/ucm/parser.c b/src/ucm/parser.c index 5c99ab4..c98373a 100644 --- a/src/ucm/parser.c +++ b/src/ucm/parser.c @@ -254,6 +254,82 @@ static int parse_device_list(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED, return 0; }
+/* Find a component device by its name, and remove it from machine device + * list. + * + * Component devices are defined by machine components (usually off-soc + * codes or DSP embeded in SoC). Since alsaconf imports their configuration + * files automatically, we don't know which devices are component devices + * until they are referenced by a machine device sequence. So here when we + * find a referenced device, we move it from the machine device list to the + * component device list. Component devices will not be exposed to applications + * by the original API to list devices for backward compatibility. So sound + * servers can only see the machine devices. + */ +struct use_case_device *find_component_dev(snd_use_case_mgr_t *uc_mgr, + const char *name) +{ + struct list_head *pos, *posdev, *_posdev; + struct use_case_verb *verb; + struct use_case_device *dev; + + list_for_each(pos, &uc_mgr->verb_list) { + verb = list_entry(pos, struct use_case_verb, list); + + /* search in the component device list */ + list_for_each(posdev, &verb->cmpt_device_list) { + dev = list_entry(posdev, struct use_case_device, list); + if (!strcmp(dev->name, name)) + return dev; + } + + /* search the machine device list */ + list_for_each_safe(posdev, _posdev, &verb->device_list) { + dev = list_entry(posdev, struct use_case_device, list); + if (!strcmp(dev->name, name)) { + /* find the component device, move it from the + * machine device list to the component device + * list. + */ + list_del(&dev->list); + list_add_tail(&dev->list, + &verb->cmpt_device_list); + return dev; + } + } + } + + return NULL; +} + +/* parse sequence of a component device + * + * This function will find the component device and mark if its enable or + * disable sequence is needed by its parenet device. + */ +static int parse_component_seq(snd_use_case_mgr_t *uc_mgr, + snd_config_t *n, int enable, + struct component_sequence *cmpt_seq) +{ + const char *val; + int err; + + err = snd_config_get_string(n, &val); + if (err < 0) + return err; + + cmpt_seq->device = find_component_dev(uc_mgr, val); + if (!cmpt_seq->device) { + uc_error("error: Cannot find component device %s", val); + return -EINVAL; + } + + /* Parent needs its enable or disable sequence */ + cmpt_seq->enable = enable; + + return 0; +} + /* * Parse sequences. * @@ -263,12 +339,16 @@ static int parse_device_list(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED, * cset "element_id_syntax value_syntax" * usleep time * exec "any unix command with arguments" + * enadev "component device name" + * disdev "component device name" * * e.g. * cset "name='Master Playback Switch' 0,0" * cset "iface=PCM,name='Disable HDMI',index=1 0" + * enadev "rt286:Headphones" + * disdev "rt286:Speaker" */ -static int parse_sequence(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED, +static int parse_sequence(snd_use_case_mgr_t *uc_mgr, struct list_head *base, snd_config_t *cfg) { @@ -325,6 +405,30 @@ static int parse_sequence(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED, continue; }
+ if (strcmp(cmd, "enadev") == 0) { + /* need to enable a component device */ + curr->type = SEQUENCE_ELEMENT_TYPE_CMPT_SEQ; + err = parse_component_seq(uc_mgr, n, 1, + &curr->data.cmpt_seq); + if (err < 0) { + uc_error("error: enadev requires a valid device!"); + return err; + } + continue; + } + + if (strcmp(cmd, "disdev") == 0) { + /* need to disable a component device */ + curr->type = SEQUENCE_ELEMENT_TYPE_CMPT_SEQ; + err = parse_component_seq(uc_mgr, n, 0, + &curr->data.cmpt_seq); + if (err < 0) { + uc_error("error: disdev requires a valid device!"); + return err; + } + continue; + } + if (strcmp(cmd, "cset-bin-file") == 0) { curr->type = SEQUENCE_ELEMENT_TYPE_CSET_BIN_FILE; err = parse_string(n, &curr->data.cset); @@ -957,6 +1061,7 @@ static int parse_verb_file(snd_use_case_mgr_t *uc_mgr, INIT_LIST_HEAD(&verb->disable_list); INIT_LIST_HEAD(&verb->transition_list); INIT_LIST_HEAD(&verb->device_list); + INIT_LIST_HEAD(&verb->cmpt_device_list); INIT_LIST_HEAD(&verb->modifier_list); INIT_LIST_HEAD(&verb->value_list); list_add_tail(&verb->list, &uc_mgr->verb_list); diff --git a/src/ucm/ucm_local.h b/src/ucm/ucm_local.h index b89de2a..3bfdd67 100644 --- a/src/ucm/ucm_local.h +++ b/src/ucm/ucm_local.h @@ -49,6 +49,7 @@ #define SEQUENCE_ELEMENT_TYPE_EXEC 4 #define SEQUENCE_ELEMENT_TYPE_CSET_BIN_FILE 5 #define SEQUENCE_ELEMENT_TYPE_CSET_TLV 6 +#define SEQUENCE_ELEMENT_TYPE_CMPT_SEQ 7
struct ucm_value { struct list_head list; @@ -56,6 +57,12 @@ struct ucm_value { char *data; };
+/* sequence of a component device */ +struct component_sequence { + struct use_case_device *device; /* component device */ + int enable; /* flag to choose enable or disable list of the device */ +}; + struct sequence_element { struct list_head list; unsigned int type; @@ -64,6 +71,7 @@ struct sequence_element { char *cdev; char *cset; char *exec; + struct component_sequence cmpt_seq; /* component sequence */ } data; };
@@ -167,6 +175,9 @@ struct use_case_verb { /* hardware devices that can be used with this use case */ struct list_head device_list;
+ /* component device list */ + struct list_head cmpt_device_list; + /* modifiers that can be used with this use case */ struct list_head modifier_list;
diff --git a/src/ucm/utils.c b/src/ucm/utils.c index 45307b0..0fba85a 100644 --- a/src/ucm/utils.c +++ b/src/ucm/utils.c @@ -210,6 +210,7 @@ void uc_mgr_free_verb(snd_use_case_mgr_t *uc_mgr) uc_mgr_free_transition(&verb->transition_list); uc_mgr_free_value(&verb->value_list); uc_mgr_free_device(&verb->device_list); + uc_mgr_free_device(&verb->cmpt_device_list); uc_mgr_free_modifier(&verb->modifier_list); list_del(&verb->list); free(verb);
From: Mengdong Lin mengdong.lin@linux.intel.com
A machine device's sequence can enable or disable a component device. So when executing a machine device's sequence, the enable or disable sequence of its component devices will also be excecuted.
Components don't define card device cdev in their sequences. So before executing a component device sequence, UCM manager will - store cdev defined by the sequence of its parent, the machine device; - mark itself entering 'component domain'.
Then this cdev will be used to excute the sequence of the component device.
When UCM manager completes executing the sequence of the component device, it will leave 'compnent domain' and reset the saved cdev to NULL.
Signed-off-by: Mengdong Lin mengdong.lin@linux.intel.com
diff --git a/src/ucm/main.c b/src/ucm/main.c index 8cc9208..750e65d 100644 --- a/src/ucm/main.c +++ b/src/ucm/main.c @@ -35,6 +35,7 @@ #include <stdarg.h> #include <pthread.h> #include <sys/stat.h> +#include <limits.h>
/* * misc @@ -48,6 +49,13 @@ static int get_value3(char **value, struct list_head *value_list2, struct list_head *value_list3);
+static int execute_component_seq(snd_use_case_mgr_t *uc_mgr, + struct component_sequence *cmpt_seq, + struct list_head *value_list1, + struct list_head *value_list2, + struct list_head *value_list3, + char *cdev); + static int check_identifier(const char *identifier, const char *prefix) { int len; @@ -366,7 +374,19 @@ static int execute_sequence(snd_use_case_mgr_t *uc_mgr, case SEQUENCE_ELEMENT_TYPE_CSET: case SEQUENCE_ELEMENT_TYPE_CSET_BIN_FILE: case SEQUENCE_ELEMENT_TYPE_CSET_TLV: - if (cdev == NULL) { + if (cdev == NULL && uc_mgr->in_component_domain) { + /* For sequence of a component device, use + * its parent's cdev stored by ucm manager. + */ + if (uc_mgr->cdev == NULL) { + uc_error("cdev is not defined!"); + return err; + } + + cdev = strndup(uc_mgr->cdev, PATH_MAX); + if (!cdev) + return -ENOMEM; + } else if (cdev == NULL) { char *playback_ctl = NULL; char *capture_ctl = NULL;
@@ -427,6 +447,19 @@ static int execute_sequence(snd_use_case_mgr_t *uc_mgr, if (err < 0) goto __fail; break; + case SEQUENCE_ELEMENT_TYPE_CMPT_SEQ: + /* Execute enable or disable sequence of a component + * device. Pass the cdev defined by the machine device. + */ + err = execute_component_seq(uc_mgr, + &s->data.cmpt_seq, + value_list1, + value_list2, + value_list3, + cdev); + if (err < 0) + goto __fail; + break; default: uc_error("unknown sequence command %i", s->type); break; @@ -442,6 +475,49 @@ static int execute_sequence(snd_use_case_mgr_t *uc_mgr,
}
+/* Execute enable or disable sequence of a component device. + * + * For a component device (a codec or embedded DSP), its sequence doesn't + * specify the sound card device 'cdev', because a component can be reused + * by different sound cards (machines). So when executing its sequence, a + * parameter 'cdev' is used to pass cdev defined by the sequence of its + * parent, the machine device. UCM manger will store the cdev when entering + * the component domain. + */ +static int execute_component_seq(snd_use_case_mgr_t *uc_mgr, + struct component_sequence *cmpt_seq, + struct list_head *value_list1, + struct list_head *value_list2, + struct list_head *value_list3, + char *cdev) +{ + struct use_case_device *device = cmpt_seq->device; + struct list_head *seq; + int err; + + /* enter component domain and store cdev for the component */ + uc_mgr->in_component_domain = 1; + uc_mgr->cdev = cdev; + + /* choose enable or disable sequence of the component device */ + if (cmpt_seq->enable) + seq = &device->enable_list; + else + seq = &device->disable_list; + + /* excecute the sequence of the component dev */ + err = execute_sequence(uc_mgr, seq, + &device->value_list, + &uc_mgr->active_verb->value_list, + &uc_mgr->value_list); + + /* exit component domain and clear cdev */ + uc_mgr->in_component_domain = 0; + uc_mgr->cdev = NULL; + + return err; +} + /** * \brief Import master config and execute the default sequence * \param uc_mgr Use case manager diff --git a/src/ucm/ucm_local.h b/src/ucm/ucm_local.h index 3bfdd67..6d3302f 100644 --- a/src/ucm/ucm_local.h +++ b/src/ucm/ucm_local.h @@ -212,6 +212,14 @@ struct snd_use_case_mgr { /* change to list of ctl handles */ snd_ctl_t *ctl; char *ctl_dev; + + /* Components don't define cdev, the card device. When executing + * a sequence of a component device, ucm manager enters component + * domain and needs to provide cdev to the component. This cdev + * should be defined by the machine, parent of the component. + */ + int in_component_domain; + char *cdev; };
#define uc_error SNDERR
On Mon, 2016-11-28 at 13:33 +0800, mengdong.lin@linux.intel.com wrote:
From: Mengdong Lin mengdong.lin@linux.intel.com
Sound cards are defined by machines. And off-soc codecs and DSPs embedded in DSP can be taken as the components and resued by different machines/ sound cards. This series allows codec and SOC vendors to install UCM configuration files for a specific codec or DSP, and sound card verb files can include these conf files of components.
Component devices will not be exposed to applications for backward compatibility. So audio servers like PulseAudio and CRAS still only see the machine devices.
History: v2: Use an array to define component directories. Document syntax to enable/disable a component device. Hide cdev defined by the parent device in ucm manager for executing a component sequence.
v3: No longer use macros for UCM manager to enter/exit component domain, to make code simpler.
Mengdong Lin (3): ucm: Skip component directories when scanning sound card configuration files ucm: Parse sequence of component devices ucm: Execute sequence of component devices
src/ucm/main.c | 78 +++++++++++++++++++++++++- src/ucm/parser.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++- src/ucm/ucm_local.h | 19 +++++++ src/ucm/utils.c | 1 + 4 files changed, 249 insertions(+), 3 deletions(-)
All
Acked-by: Liam Girdwood liam.r.girdwood@linux.intel.com
On Mon, 28 Nov 2016 06:33:27 +0100, mengdong.lin@linux.intel.com wrote:
From: Mengdong Lin mengdong.lin@linux.intel.com
Sound cards are defined by machines. And off-soc codecs and DSPs embedded in DSP can be taken as the components and resued by different machines/ sound cards. This series allows codec and SOC vendors to install UCM configuration files for a specific codec or DSP, and sound card verb files can include these conf files of components.
Component devices will not be exposed to applications for backward compatibility. So audio servers like PulseAudio and CRAS still only see the machine devices.
History: v2: Use an array to define component directories. Document syntax to enable/disable a component device. Hide cdev defined by the parent device in ucm manager for executing a component sequence.
v3: No longer use macros for UCM manager to enter/exit component domain, to make code simpler.
Mengdong Lin (3): ucm: Skip component directories when scanning sound card configuration files ucm: Parse sequence of component devices ucm: Execute sequence of component devices
Applied all three patches now. Thanks.
Takashi
participants (3)
-
Liam Girdwood
-
mengdong.lin@linux.intel.com
-
Takashi Iwai