From patchwork Sun Sep 25 05:58:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 9349655 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 B5614601C2 for ; Sun, 25 Sep 2016 10:55:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 992E528D98 for ; Sun, 25 Sep 2016 10:55:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7760C28D9A; Sun, 25 Sep 2016 10:55:36 +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 7ECDC28D98 for ; Sun, 25 Sep 2016 10:55:34 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 98C912669E4; Sun, 25 Sep 2016 12:55:33 +0200 (CEST) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 17964261740; Sun, 25 Sep 2016 12:53:08 +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 0FFCB2665B6; Sun, 25 Sep 2016 07:59:01 +0200 (CEST) Received: from mezzanine.sirena.org.uk (mezzanine.sirena.org.uk [106.187.55.193]) by alsa0.perex.cz (Postfix) with ESMTP id 36A2F2665B1 for ; Sun, 25 Sep 2016 07:58:59 +0200 (CEST) Received: from [67.238.99.186] (helo=finisterre) by mezzanine.sirena.org.uk with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bo2Sj-0007qq-Gb; Sun, 25 Sep 2016 05:58:55 +0000 Received: from broonie by finisterre with local (Exim 4.87) (envelope-from ) id 1bo2SZ-00032M-K1; Sat, 24 Sep 2016 22:58:43 -0700 From: Mark Brown To: Dharageswari R In-Reply-To: <1474533040-14222-2-git-send-email-vinod.koul@intel.com> Message-Id: Date: Sat, 24 Sep 2016 22:58:43 -0700 X-SA-Exim-Connect-IP: 67.238.99.186 X-SA-Exim-Mail-From: broonie@sirena.org.uk X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:24:06 +0000) X-SA-Exim-Scanned: No (on mezzanine.sirena.org.uk); Unknown failure Cc: Vinod Koul , liam.r.girdwood@linux.intel.com, alsa-devel@alsa-project.org, broonie@kernel.org, patches.audio@intel.com Subject: [alsa-devel] Applied "ASoC: Intel: Skylake: Add module instance id generation APIs" to the asoc tree 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 The patch ASoC: Intel: Skylake: Add module instance id generation APIs has been applied to the asoc tree at git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. Thanks, Mark From 700a9a63f9c1bc13abaa956eacc0bfcaf3a201c2 Mon Sep 17 00:00:00 2001 From: Dharageswari R Date: Thu, 22 Sep 2016 14:00:37 +0530 Subject: [PATCH] ASoC: Intel: Skylake: Add module instance id generation APIs Driver needs to send unique module instance id to firmware while creating the module and uses this id to communicate with DSP for setting parameters while audio use case is ongoing. But, we have upper bound of instance ID. The current IDs are coming from topology but it doesn't know the upper bound and can't assign unique id's subject to upper bounds as we can create a big graph but not all parts running at same time. This patch adds a 128bit unique id management routines which are built on top of ffz() for faster implementation. Unfortunately ffz() works on 32bits values, so additional code is added on top of ffz() to create a 128bit unique id. Signed-off-by: Dharageswari R Signed-off-by: Vinod Koul Signed-off-by: Mark Brown --- sound/soc/intel/skylake/skl-sst-dsp.h | 4 ++ sound/soc/intel/skylake/skl-sst-utils.c | 115 ++++++++++++++++++++++++++++++++ sound/soc/intel/skylake/skl-topology.h | 1 + 3 files changed, 120 insertions(+) diff --git a/sound/soc/intel/skylake/skl-sst-dsp.h b/sound/soc/intel/skylake/skl-sst-dsp.h index 6ad5cab4b0d5..b61bd03ee4f0 100644 --- a/sound/soc/intel/skylake/skl-sst-dsp.h +++ b/sound/soc/intel/skylake/skl-sst-dsp.h @@ -215,6 +215,10 @@ int snd_skl_get_module_info(struct skl_sst *ctx, struct skl_module_cfg *mconfig); int snd_skl_parse_uuids(struct sst_dsp *ctx, const struct firmware *fw, unsigned int offset, int index); +int skl_get_pvt_id(struct skl_sst *ctx, + struct skl_module_cfg *mconfig); +int skl_put_pvt_id(struct skl_sst *ctx, + struct skl_module_cfg *mconfig); void skl_freeup_uuid_list(struct skl_sst *ctx); int skl_dsp_strip_extended_manifest(struct firmware *fw); diff --git a/sound/soc/intel/skylake/skl-sst-utils.c b/sound/soc/intel/skylake/skl-sst-utils.c index 9ce93e9a03b5..5f1c203a448e 100644 --- a/sound/soc/intel/skylake/skl-sst-utils.c +++ b/sound/soc/intel/skylake/skl-sst-utils.c @@ -94,10 +94,14 @@ struct adsp_fw_hdr { u32 load_offset; } __packed; +#define MAX_INSTANCE_BUFF 2 + struct uuid_module { uuid_le uuid; int id; int is_loadable; + int max_instance; + u64 pvt_id[MAX_INSTANCE_BUFF]; struct list_head list; }; @@ -131,6 +135,116 @@ int snd_skl_get_module_info(struct skl_sst *ctx, } EXPORT_SYMBOL_GPL(snd_skl_get_module_info); +static inline int skl_getid_32(struct uuid_module *module, u64 *val, + int word1_mask, int word2_mask) +{ + int index, max_inst, pvt_id; + u32 mask_val; + + max_inst = module->max_instance; + mask_val = (u32)(*val >> word1_mask); + + if (mask_val != 0xffffffff) { + index = ffz(mask_val); + pvt_id = index + word1_mask + word2_mask; + if (pvt_id <= (max_inst - 1)) { + *val |= 1 << (index + word1_mask); + return pvt_id; + } + } + + return -EINVAL; +} + +static inline int skl_pvtid_128(struct uuid_module *module) +{ + int j, i, word1_mask, word2_mask = 0, pvt_id; + + for (j = 0; j < MAX_INSTANCE_BUFF; j++) { + word1_mask = 0; + + for (i = 0; i < 2; i++) { + pvt_id = skl_getid_32(module, &module->pvt_id[j], + word1_mask, word2_mask); + if (pvt_id >= 0) + return pvt_id; + + word1_mask += 32; + if ((word1_mask + word2_mask) >= module->max_instance) + return -EINVAL; + } + + word2_mask += 64; + if (word2_mask >= module->max_instance) + return -EINVAL; + } + + return -EINVAL; +} + +/** + * skl_get_pvt_id: generate a private id for use as module id + * + * @ctx: driver context + * @mconfig: module configuration data + * + * This generates a 128 bit private unique id for a module TYPE so that + * module instance is unique + */ +int skl_get_pvt_id(struct skl_sst *ctx, struct skl_module_cfg *mconfig) +{ + struct uuid_module *module; + uuid_le *uuid_mod; + int pvt_id; + + uuid_mod = (uuid_le *)mconfig->guid; + + list_for_each_entry(module, &ctx->uuid_list, list) { + if (uuid_le_cmp(*uuid_mod, module->uuid) == 0) { + + pvt_id = skl_pvtid_128(module); + if (pvt_id >= 0) + return pvt_id; + } + } + + return -EINVAL; +} +EXPORT_SYMBOL_GPL(skl_get_pvt_id); + +/** + * skl_put_pvt_id: free up the private id allocated + * + * @ctx: driver context + * @mconfig: module configuration data + * + * This frees a 128 bit private unique id previously generated + */ +int skl_put_pvt_id(struct skl_sst *ctx, struct skl_module_cfg *mconfig) +{ + int i; + uuid_le *uuid_mod; + struct uuid_module *module; + + uuid_mod = (uuid_le *)mconfig->guid; + list_for_each_entry(module, &ctx->uuid_list, list) { + if (uuid_le_cmp(*uuid_mod, module->uuid) == 0) { + + if (mconfig->id.pvt_id != 0) + i = (mconfig->id.pvt_id) / 64; + else + i = 0; + + module->pvt_id[i] &= ~(1 << (mconfig->id.pvt_id)); + mconfig->id.pvt_id = -1; + return 0; + } + } + + return -EINVAL; +} +EXPORT_SYMBOL_GPL(skl_put_pvt_id); + /* * Parse the firmware binary to get the UUID, module id * and loadable flags @@ -203,6 +317,7 @@ int snd_skl_parse_uuids(struct sst_dsp *ctx, const struct firmware *fw, module->id = (i | (index << 12)); module->is_loadable = mod_entry->type.load_type; + module->max_instance = mod_entry->instance_max_count; list_add_tail(&module->list, &skl->uuid_list); diff --git a/sound/soc/intel/skylake/skl-topology.h b/sound/soc/intel/skylake/skl-topology.h index 37f45cc32a44..def03912b1bd 100644 --- a/sound/soc/intel/skylake/skl-topology.h +++ b/sound/soc/intel/skylake/skl-topology.h @@ -218,6 +218,7 @@ struct skl_module_cfg; struct skl_module_inst_id { int module_id; u32 instance_id; + int pvt_id; }; enum skl_module_pin_state {