From patchwork Wed Jul 13 08:45:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mengdong.lin@linux.intel.com X-Patchwork-Id: 9227119 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1A1896075D for ; Wed, 13 Jul 2016 08:43:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 08AB12574A for ; Wed, 13 Jul 2016 08:43:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F10BA27813; Wed, 13 Jul 2016 08:43:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3B3F27F8E for ; Wed, 13 Jul 2016 08:42:59 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id A9E3626668C; Wed, 13 Jul 2016 10:42:58 +0200 (CEST) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id DD031266504; Wed, 13 Jul 2016 10:41:05 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 8E79F26668B; Wed, 13 Jul 2016 10:41:04 +0200 (CEST) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by alsa0.perex.cz (Postfix) with ESMTP id 5F9802663DF for ; Wed, 13 Jul 2016 10:40:08 +0200 (CEST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga104.fm.intel.com with ESMTP; 13 Jul 2016 01:40:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,356,1464678000"; d="scan'208";a="994245346" Received: from amanda-haswell-pc.sh.intel.com ([10.239.159.169]) by orsmga001.jf.intel.com with ESMTP; 13 Jul 2016 01:40:06 -0700 From: mengdong.lin@linux.intel.com To: alsa-devel@alsa-project.org, broonie@kernel.org Date: Wed, 13 Jul 2016 16:45:02 +0800 Message-Id: <5e5337dd75d6291b6f12e678adc9c5ea0f62138f.1468397702.git.mengdong.lin@linux.intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: References: Cc: Mengdong Lin , tiwai@suse.de, mengdong.lin@intel.com, liam.r.girdwood@intel.com, shreyas.nc@intel.com Subject: [alsa-devel] [PATCH 4/5] topology: Parse vendor private data for manifest X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Mengdong Lin In text conf file, user can define a manifest section and let it refer to private data sections, in the same syntax as other element types. The text conf file can have at most 1 manifest section. Signed-off-by: Mengdong Lin diff --git a/include/topology.h b/include/topology.h index 89bed6c..644e548 100644 --- a/include/topology.h +++ b/include/topology.h @@ -586,6 +586,20 @@ extern "C" { * } * * + *

Manifest Private Data

+ * Manfiest may have private data. Users need to define a manifest section + * and add the references to 1 or multiple data sections. Please refer to + * section 'How to define an element with private data'.
+ * And the text conf file can have at most 1 manifest section.

+ * + * Manifest section is defined as follows :- + * + *
+ * SectionManifest"name" {
+ *
+ *	data "name"			# optional private data
+ * }
+ * 
*/ /** Maximum number of channels supported in one control */ diff --git a/src/topology/data.c b/src/topology/data.c index 65054d7..f04544b 100644 --- a/src/topology/data.c +++ b/src/topology/data.c @@ -26,6 +26,10 @@ struct snd_soc_tplg_private *get_priv_data(struct tplg_elem *elem) struct snd_soc_tplg_private *priv = NULL; switch (elem->type) { + case SND_TPLG_TYPE_MANIFEST: + priv = &elem->manifest->priv; + break; + case SND_TPLG_TYPE_MIXER: priv = &elem->mixer_ctrl->priv; break; @@ -835,6 +839,101 @@ void tplg_free_tuples(void *obj) free(tuples->set); } +/* Parse manifest's data references + */ +int tplg_parse_manifest_data(snd_tplg_t *tplg, snd_config_t *cfg, + void *private ATTRIBUTE_UNUSED) +{ + struct snd_soc_tplg_manifest *manifest; + struct tplg_elem *elem; + snd_config_iterator_t i, next; + snd_config_t *n; + const char *id, *val = NULL; + int err; + + if (!list_empty(&tplg->manifest_list)) { + SNDERR("error: already has manifest data\n"); + return -EINVAL; + } + + elem = tplg_elem_new_common(tplg, cfg, NULL, SND_TPLG_TYPE_MANIFEST); + if (!elem) + return -ENOMEM; + + manifest = elem->manifest; + manifest->size = elem->size; + + tplg_dbg(" Manifest: %s\n", elem->id); + + snd_config_for_each(i, next, cfg) { + n = snd_config_iterator_entry(i); + if (snd_config_get_id(n, &id) < 0) + continue; + + /* skip comments */ + if (strcmp(id, "comment") == 0) + continue; + if (id[0] == '#') + continue; + + + if (strcmp(id, "data") == 0) { + err = tplg_parse_data_refs(tplg, n, elem); + if (err < 0) + return err; + continue; + } + } +} + +/* merge private data of manifest */ +int tplg_build_manifest_data(snd_tplg_t *tplg) +{ + struct list_head *base, *pos; + struct tplg_elem *elem = NULL; + struct tplg_ref *ref; + struct snd_soc_tplg_manifest *manifest; + int err = 0; + + base = &tplg->manifest_list; + list_for_each(pos, base) { + + elem = list_entry(pos, struct tplg_elem, list); + break; + } + + if (!elem) /* no manifest data */ + return 0; + + base = &elem->ref_list; + + /* for each ref in this manifest elem */ + list_for_each(pos, base) { + + ref = list_entry(pos, struct tplg_ref, list); + if (ref->id == NULL || ref->elem) + continue; + + if (ref->type == SND_TPLG_TYPE_DATA) { + err = tplg_copy_data(tplg, elem, ref); + if (err < 0) + return err; + } + } + + manifest = elem->manifest; + if (!manifest->priv.size) /* no manifest data */ + return 0; + + tplg->manifest_pdata = malloc(manifest->priv.size); + if (!tplg->manifest_pdata) + return -ENOMEM; + + tplg->manifest.priv.size = manifest->priv.size; + memcpy(tplg->manifest_pdata, manifest->priv.data, manifest->priv.size); + return 0; +} + /* Parse Private data. * * Object private data can either be from file or defined as bytes, shorts, diff --git a/src/topology/elem.c b/src/topology/elem.c index 50414f0..029c9ab 100644 --- a/src/topology/elem.c +++ b/src/topology/elem.c @@ -150,6 +150,10 @@ struct tplg_elem* tplg_elem_new_common(snd_tplg_t *tplg, case SND_TPLG_TYPE_DATA: list_add_tail(&elem->list, &tplg->pdata_list); break; + case SND_TPLG_TYPE_MANIFEST: + list_add_tail(&elem->list, &tplg->manifest_list); + obj_size = sizeof(struct snd_soc_tplg_manifest); + break; case SND_TPLG_TYPE_TEXT: list_add_tail(&elem->list, &tplg->text_list); break; diff --git a/src/topology/parser.c b/src/topology/parser.c index f6fc944..3ab64f4 100644 --- a/src/topology/parser.c +++ b/src/topology/parser.c @@ -189,6 +189,15 @@ static int tplg_parse_config(snd_tplg_t *tplg, snd_config_t *cfg) continue; } + if (strcmp(id, "SectionManifest") == 0) { + err = tplg_parse_compound(tplg, n, + tplg_parse_manifest_data, + NULL); + if (err < 0) + return err; + continue; + } + SNDERR("error: unknown section %s\n", id); } return 0; @@ -246,6 +255,10 @@ static int tplg_build_integ(snd_tplg_t *tplg) if (err < 0) return err; + err = tplg_build_manifest_data(tplg); + if (err < 0) + return err; + err = tplg_build_controls(tplg); if (err < 0) return err; @@ -374,8 +387,16 @@ out: int snd_tplg_set_manifest_data(snd_tplg_t *tplg, const void *data, int len) { + if (len <= 0) + return 0; + tplg->manifest.priv.size = len; - tplg->manifest_pdata = data; + + tplg->manifest_pdata = malloc(len); + if (!tplg->manifest_pdata) + return -ENOMEM; + + memcpy(tplg->manifest_pdata, data, len); return 0; } @@ -423,6 +444,7 @@ snd_tplg_t *snd_tplg_new(void) INIT_LIST_HEAD(&tplg->cc_list); INIT_LIST_HEAD(&tplg->route_list); INIT_LIST_HEAD(&tplg->pdata_list); + INIT_LIST_HEAD(&tplg->manifest_list); INIT_LIST_HEAD(&tplg->text_list); INIT_LIST_HEAD(&tplg->pcm_config_list); INIT_LIST_HEAD(&tplg->pcm_caps_list); @@ -437,6 +459,9 @@ snd_tplg_t *snd_tplg_new(void) void snd_tplg_free(snd_tplg_t *tplg) { + if (tplg->manifest_pdata) + free(tplg->manifest_pdata); + tplg_elem_free_list(&tplg->tlv_list); tplg_elem_free_list(&tplg->widget_list); tplg_elem_free_list(&tplg->pcm_list); @@ -444,6 +469,7 @@ void snd_tplg_free(snd_tplg_t *tplg) tplg_elem_free_list(&tplg->cc_list); tplg_elem_free_list(&tplg->route_list); tplg_elem_free_list(&tplg->pdata_list); + tplg_elem_free_list(&tplg->manifest_list); tplg_elem_free_list(&tplg->text_list); tplg_elem_free_list(&tplg->pcm_config_list); tplg_elem_free_list(&tplg->pcm_caps_list); diff --git a/src/topology/tplg_local.h b/src/topology/tplg_local.h index c93429a..5e3235b 100644 --- a/src/topology/tplg_local.h +++ b/src/topology/tplg_local.h @@ -58,7 +58,7 @@ struct snd_tplg { /* manifest */ struct snd_soc_tplg_manifest manifest; - const void *manifest_pdata; /* copied by builder at file write */ + void *manifest_pdata; /* copied by builder at file write */ /* list of each element type */ struct list_head tlv_list; @@ -71,6 +71,7 @@ struct snd_tplg { struct list_head pdata_list; struct list_head token_list; struct list_head tuple_list; + struct list_head manifest_list; struct list_head pcm_config_list; struct list_head pcm_caps_list; @@ -154,6 +155,7 @@ struct tplg_elem { struct snd_soc_tplg_private *data; struct tplg_vendor_tokens *tokens; struct tplg_vendor_tuples *tuples; + struct snd_soc_tplg_manifest *manifest; }; /* an element may refer to other elements: @@ -195,6 +197,9 @@ int tplg_parse_tuples(snd_tplg_t *tplg, snd_config_t *cfg, void tplg_free_tuples(void *obj); +int tplg_parse_manifest_data(snd_tplg_t *tplg, snd_config_t *cfg, + void *private ATTRIBUTE_UNUSED); + int tplg_parse_control_bytes(snd_tplg_t *tplg, snd_config_t *cfg, void *private ATTRIBUTE_UNUSED); @@ -223,6 +228,7 @@ int tplg_parse_cc(snd_tplg_t *tplg, snd_config_t *cfg, void *private ATTRIBUTE_UNUSED); int tplg_build_data(snd_tplg_t *tplg); +int tplg_build_manifest_data(snd_tplg_t *tplg); int tplg_build_controls(snd_tplg_t *tplg); int tplg_build_widgets(snd_tplg_t *tplg); int tplg_build_routes(snd_tplg_t *tplg);