Skip to contentSkip to conversation

ASoC: Intel: Skylake: Add DSP firmware manifest parsing

PATCH Superseded Vinod Koul 2 participants 3 messages Apr 2, 2016 – Apr 12, 2016

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Vinod Koul

author
#0 lore raw

PATCH 1/1 ASoC: Intel: Skylake: Add DSP firmware manifest parsing

From: "Nc,Shreyas" <[email protected]>

Module params like module_id and loadable flag can changed in the DSP Firmware. These are kept in the firmware manifest and driver should read these values from this manifest.

So, add support to parse the DSP firmware manifest and read these module params.

---
 sound/soc/intel/skylake/Makefile        |   2 +-
 sound/soc/intel/skylake/skl-dsp-parse.c | 134 ++++++++++++++++++++++++++++++++
 sound/soc/intel/skylake/skl-dsp-parse.h | 109 ++++++++++++++++++++++++++
 sound/soc/intel/skylake/skl-sst-ipc.h   |   4 +
 sound/soc/intel/skylake/skl-sst.c       |  11 ++-
 sound/soc/intel/skylake/skl-topology.c  |  15 ++--
 6 files changed, 268 insertions(+), 7 deletions(-)
 create mode 100644 sound/soc/intel/skylake/skl-dsp-parse.c
 create mode 100644 sound/soc/intel/skylake/skl-dsp-parse.h
sound/soc/intel/skylake/Makefile +1 -1
index c28f5d0e1d99..e2fb5b763b21 100644
@@ -5,6 +5,6 @@ obj-$(CONFIG_SND_SOC_INTEL_SKYLAKE) += snd-soc-skl.o
 
 # Skylake IPC Support
 snd-soc-skl-ipc-objs := skl-sst-ipc.o skl-sst-dsp.o skl-sst-cldma.o \
-		skl-sst.o bxt-sst.o
+		skl-sst.o skl-dsp-parse.o bxt-sst.o
 
 obj-$(CONFIG_SND_SOC_INTEL_SKYLAKE) += snd-soc-skl-ipc.o
sound/soc/intel/skylake/skl-dsp-parse.c new file +134 -0

134 lines not on this page · raw message

sound/soc/intel/skylake/skl-dsp-parse.h new file +109 -0

109 lines not on this page · raw message

sound/soc/intel/skylake/skl-sst-ipc.h +4 -0
index d59d1ba62a43..67d56be8cb77 100644
@@ -60,6 +60,10 @@ struct skl_sst {
 	void (*enable_miscbdcge)(struct device *dev, bool enable);
 	/*Is CGCTL.MISCBDCGE disabled*/
 	bool miscbdcg_disabled;
+
+	/* Populate module information */
+	struct uuid_tbl *tbl;
+	int num_modules;
 };
 
 struct skl_ipc_init_instance_msg {
sound/soc/intel/skylake/skl-sst.c +10 -1
index 348a734f8e24..9fbe922d05ce 100644
@@ -24,6 +24,7 @@
 #include "../common/sst-dsp-priv.h"
 #include "../common/sst-ipc.h"
 #include "skl-sst-ipc.h"
+#include "skl-dsp-parse.h"
 
 #define SKL_BASEFW_TIMEOUT	300
 #define SKL_INIT_TIMEOUT	1000
@@ -69,7 +70,7 @@ static int skl_transfer_firmware(struct sst_dsp *ctx,
 
 static int skl_load_base_firmware(struct sst_dsp *ctx)
 {
-	int ret = 0, i;
+	int ret = 0, i, err;
 	struct skl_sst *skl = ctx->thread_context;
 	u32 reg;
 
@@ -83,6 +84,14 @@ static int skl_load_base_firmware(struct sst_dsp *ctx)
 			skl_dsp_disable_core(ctx);
 			return -EIO;
 		}
+
+		err = parse_fw_bin(ctx);
+		if (err < 0) {
+			dev_err(ctx->dev,
+					"Firmware parsing err: %d\n", ret);
+			release_firmware(ctx->fw);
+			return err;
+		}
 	}
 
 	ret = skl_dsp_boot(ctx);
sound/soc/intel/skylake/skl-topology.c +10 -5
index 545b4e77b8aa..d64edfa45b6e 100644
@@ -28,6 +28,7 @@
 #include "skl-tplg-interface.h"
 #include "../common/sst-dsp.h"
 #include "../common/sst-dsp-priv.h"
+#include "skl-dsp-parse.h"
 
 #define SKL_CH_FIXUP_MASK		(1 << 0)
 #define SKL_RATE_FIXUP_MASK		(1 << 1)
@@ -1550,7 +1551,15 @@ static int skl_tplg_widget_load(struct snd_soc_component *cmpnt,
 		return -ENOMEM;
 
 	w->priv = mconfig;
+	memcpy(mconfig->guid, dfw_config->uuid,
+					ARRAY_SIZE(dfw_config->uuid));
+
+	ret = snd_skl_get_module_info(skl->skl_sst, mconfig->guid, dfw_config);
+	if (ret < 0)
+		return ret;
+
 	mconfig->id.module_id = dfw_config->module_id;
+	mconfig->is_loadable = dfw_config->is_loadable;
 	mconfig->id.instance_id = dfw_config->instance_id;
 	mconfig->mcps = dfw_config->max_mcps;
 	mconfig->ibs = dfw_config->ibs;
@@ -1558,7 +1567,7 @@ static int skl_tplg_widget_load(struct snd_soc_component *cmpnt,
 	mconfig->core_id = dfw_config->core_id;
 	mconfig->max_in_queue = dfw_config->max_in_queue;
 	mconfig->max_out_queue = dfw_config->max_out_queue;
-	mconfig->is_loadable = dfw_config->is_loadable;
+
 	skl_tplg_fill_fmt(mconfig->in_fmt, dfw_config->in_fmt,
 						MODULE_MAX_IN_PINS);
 	skl_tplg_fill_fmt(mconfig->out_fmt, dfw_config->out_fmt,
@@ -1579,10 +1588,6 @@ static int skl_tplg_widget_load(struct snd_soc_component *cmpnt,
 	mconfig->time_slot = dfw_config->time_slot;
 	mconfig->formats_config.caps_size = dfw_config->caps.caps_size;
 
-	if (dfw_config->is_loadable)
-		memcpy(mconfig->guid, dfw_config->uuid,
-					ARRAY_SIZE(dfw_config->uuid));
-
 	mconfig->m_in_pin = devm_kzalloc(bus->dev, (mconfig->max_in_queue) *
 						sizeof(*mconfig->m_in_pin),
 						GFP_KERNEL);
Signature · 1 line
2.4.3
maintainer
#1 lore raw

sound/soc/intel/skylake/skl-dsp-parse.c line 46

Quoted 2 lines · Vinod Koul
sound/soc/intel/skylake/skl-dsp-parse.c new file +2 -0
+	for (i = 0; i < num; i++) {
+		if (!strcmp(uuid, tbl[i].uuid)) {

Do we really want to be working with UUIDs in string format all the time? It seems error prone and as far as I can see at least some of the time we get them in in binary format.

Review

Quoted 2 lines
(quoted diff) +2 -0
+	sprintf(buf, "%08X", entry->uuid.id_1);
+	sprintf(buf+strlen(buf), "-");

Coding style, spaces around +. I'd also like to be a bit more confident that this can't result in a buffer overflow, sprintf() isn't reassuring especially in conjunction with buf being passed in from elsewhere with no length information.

sound/soc/intel/skylake/skl-dsp-parse.c line 122

Quoted 9 lines
sound/soc/intel/skylake/skl-dsp-parse.c new file +8 -0
+	adsp_hdr = (struct adsp_fw_hdr *)(buf + SKL_ADSP_FW_BIN_HDR_OFFSET);
+
+	mod_entry = (struct adsp_module_entry *)
+		(buf + SKL_ADSP_FW_BIN_HDR_OFFSET + adsp_hdr->header_len);
+
+	num_entry = adsp_hdr->num_module_entries;
 
+	for (i = 0; i < num_entry; i++, mod_entry++) {
+		get_canonical_uuid(uuid_str, mod_entry);

We're not checking that we're not walking off the end of the file here.

author
#2 lore raw
Quoted 8 lines · Mark Brown

sound/soc/intel/skylake/skl-dsp-parse.c line 46

Quoted 2 lines · Vinod Koul
sound/soc/intel/skylake/skl-dsp-parse.c new file +2 -0
+	for (i = 0; i < num; i++) {
+		if (!strcmp(uuid, tbl[i].uuid)) {

Do we really want to be working with UUIDs in string format all the time? It seems error prone and as far as I can see at least some of the time we get them in in binary format.

I agree that it would be saner to handle uuid in bin format and print to strings when string are required.

Quoted 7 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	sprintf(buf, "%08X", entry->uuid.id_1);
+	sprintf(buf+strlen(buf), "-");

Coding style, spaces around +. I'd also like to be a bit more confident that this can't result in a buffer overflow, sprintf() isn't reassuring especially in conjunction with buf being passed in from elsewhere with no length information.

Okay I think we cna remove this if don't use strings

Quoted 11 lines

sound/soc/intel/skylake/skl-dsp-parse.c line 122

Quoted 9 lines
sound/soc/intel/skylake/skl-dsp-parse.c new file +8 -0
+	adsp_hdr = (struct adsp_fw_hdr *)(buf + SKL_ADSP_FW_BIN_HDR_OFFSET);
+
+	mod_entry = (struct adsp_module_entry *)
+		(buf + SKL_ADSP_FW_BIN_HDR_OFFSET + adsp_hdr->header_len);
+
+	num_entry = adsp_hdr->num_module_entries;
 
+	for (i = 0; i < num_entry; i++, mod_entry++) {
+		get_canonical_uuid(uuid_str, mod_entry);

We're not checking that we're not walking off the end of the file here.

Will fix

Thanks

Signature · 1 line
~Vinod