ASoC: Intel: Skylake: Add DSP firmware manifest parsing
Subsystems (3)
PATCH v4 1/1 ASoC: Intel: Skylake: Add DSP firmware manifest parsing
From: Shreyas NC <[email protected]>
Module params like module_id and loadable flag can be 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.
---
Changes in v4:
rebase on asoc-next, resolve rebase conflict
Changes in v3:
add bound check for firmware file
sound/soc/intel/skylake/Makefile | 2 +- sound/soc/intel/skylake/skl-dsp-parse.c | 118 ++++++++++++++++++++++++++++++++ sound/soc/intel/skylake/skl-dsp-parse.h | 107 +++++++++++++++++++++++++++++ sound/soc/intel/skylake/skl-sst-ipc.h | 4 ++ sound/soc/intel/skylake/skl-sst.c | 11 ++- sound/soc/intel/skylake/skl-topology.c | 5 ++ 6 files changed, 245 insertions(+), 2 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
@@ -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 +118 -0
118 lines not on this page · raw message
sound/soc/intel/skylake/skl-dsp-parse.h new file +107 -0
107 lines not on this page · raw message
sound/soc/intel/skylake/skl-sst-ipc.h +4 -0
@@ -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
@@ -25,6 +25,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
@@ -70,7 +71,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;
@@ -84,6 +85,14 @@ static int skl_load_base_firmware(struct sst_dsp *ctx)skl_dsp_disable_core (ctx);return -EIO ; } + + err =snd_skl_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 +5 -0
@@ -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)
@@ -1566,6 +1567,10 @@ static int skl_tplg_widget_load(struct snd_soc_component *cmpnt, w->priv = mconfig;memcpy (&mconfig->guid, &dfw_config->uuid,16 ); + 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->id.instance_id = dfw_config->instance_id; mconfig->mcps = dfw_config->max_mcps;
Signature · 1 line
1.9.1
Mark Brown
maintainersound/soc/intel/skylake/skl-dsp-parse.c line 74
Quoted 7 lines · Vinod Koul
sound/soc/intel/skylake/skl-dsp-parse.c new file +5
-0+/* Get the FW pointer to derive ADSP header */ + buf = ctx->fw->data; + 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);
What if we somehow managed to end up with a zero length firmware (or something smaller than these headers)?
sound/soc/intel/skylake/skl-dsp-parse.c line 104
Quoted 11 lines
sound/soc/intel/skylake/skl-dsp-parse.c new file +11
-0+/* +* we check if current pointer is larger than file size from +* base value to check excceding the file while parsing +*/ +if ((const char *)mod_entry >= buf + ctx->fw->size) { +dev_err (ctx->dev, +"Exceeds file bound: Entry %d Ptr %p\n" , + i, mod_entry); + +return -EIO ; + }
This checks the start of the entry but it still lets us read beyond the end of the file.
Quoted 5 lines · Mark Brown
Quoted 2 lines · Vinod Koul
sound/soc/intel/skylake/skl-dsp-parse.c new file +2
-0+/* Get the FW pointer to derive ADSP header */ + buf = ctx->fw->data;
Quoted 7 lines
sound/soc/intel/skylake/skl-dsp-parse.c line 74
Quoted 4 lines
sound/soc/intel/skylake/skl-dsp-parse.c new file +3
-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);What if we somehow managed to end up with a zero length firmware (or something smaller than these headers)?
I recall that firmware core checks if file is zero sized. But then it won't help us here if the size is less than SKL_ADSP_FW_BIN_HDR_OFFSET, so will add proper checks in this case as well
Quoted 15 lines
sound/soc/intel/skylake/skl-dsp-parse.c line 104
Quoted 12 lines
sound/soc/intel/skylake/skl-dsp-parse.c new file +11
-0+/* +* we check if current pointer is larger than file size from +* base value to check excceding the file while parsing +*/ +if ((const char *)mod_entry >= buf + ctx->fw->size) { +dev_err (ctx->dev, +"Exceeds file bound: Entry %d Ptr %p\n" , + i, mod_entry); + +return -EIO ; + }This checks the start of the entry but it still lets us read beyond the end of the file.
Yup we need to check before incrementing, will fix that
Btw wanted to ask you on the update for this. Do you prefer that is sent after merge window or anytime is fine by you :)
Thanks
Signature · 1 line
~Vinod
Mark Brown
maintainerQuoted 2 lines · Vinod Koul
Btw wanted to ask you on the update for this. Do you prefer that is sent after merge window or anytime is fine by you :)
Whenever.