Commit 2925748e authored by Charles Keepax's avatar Charles Keepax Committed by Mark Brown

firmware: cs_dsp: Add version checks on coefficient loading

The firmware coefficient files contain version information that is
currently ignored by the cs_dsp code. This information specifies which
version of the firmware the coefficient were generated for. Add a check
into the code which prints a warning in the case the coefficient and
firmware differ in version, in many cases this will be ok but it is not
always, so best to let the user know there is a potential issue.
Co-authored-by: default avatarSimon Trimmer <simont@opensource.cirrus.com>
Signed-off-by: default avatarSimon Trimmer <simont@opensource.cirrus.com>
Signed-off-by: default avatarCharles Keepax <ckeepax@opensource.cirrus.com>
Link: https://lore.kernel.org/r/20211117132300.1290-3-ckeepax@opensource.cirrus.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 5065cfab
...@@ -1569,7 +1569,7 @@ EXPORT_SYMBOL_GPL(cs_dsp_find_alg_region); ...@@ -1569,7 +1569,7 @@ EXPORT_SYMBOL_GPL(cs_dsp_find_alg_region);
static struct cs_dsp_alg_region *cs_dsp_create_region(struct cs_dsp *dsp, static struct cs_dsp_alg_region *cs_dsp_create_region(struct cs_dsp *dsp,
int type, __be32 id, int type, __be32 id,
__be32 base) __be32 ver, __be32 base)
{ {
struct cs_dsp_alg_region *alg_region; struct cs_dsp_alg_region *alg_region;
...@@ -1579,6 +1579,7 @@ static struct cs_dsp_alg_region *cs_dsp_create_region(struct cs_dsp *dsp, ...@@ -1579,6 +1579,7 @@ static struct cs_dsp_alg_region *cs_dsp_create_region(struct cs_dsp *dsp,
alg_region->type = type; alg_region->type = type;
alg_region->alg = be32_to_cpu(id); alg_region->alg = be32_to_cpu(id);
alg_region->ver = be32_to_cpu(ver);
alg_region->base = be32_to_cpu(base); alg_region->base = be32_to_cpu(base);
list_add_tail(&alg_region->list, &dsp->alg_regions); list_add_tail(&alg_region->list, &dsp->alg_regions);
...@@ -1628,14 +1629,14 @@ static void cs_dsp_parse_wmfw_v3_id_header(struct cs_dsp *dsp, ...@@ -1628,14 +1629,14 @@ static void cs_dsp_parse_wmfw_v3_id_header(struct cs_dsp *dsp,
nalgs); nalgs);
} }
static int cs_dsp_create_regions(struct cs_dsp *dsp, __be32 id, int nregions, static int cs_dsp_create_regions(struct cs_dsp *dsp, __be32 id, __be32 ver,
const int *type, __be32 *base) int nregions, const int *type, __be32 *base)
{ {
struct cs_dsp_alg_region *alg_region; struct cs_dsp_alg_region *alg_region;
int i; int i;
for (i = 0; i < nregions; i++) { for (i = 0; i < nregions; i++) {
alg_region = cs_dsp_create_region(dsp, type[i], id, base[i]); alg_region = cs_dsp_create_region(dsp, type[i], id, ver, base[i]);
if (IS_ERR(alg_region)) if (IS_ERR(alg_region))
return PTR_ERR(alg_region); return PTR_ERR(alg_region);
} }
...@@ -1670,12 +1671,14 @@ static int cs_dsp_adsp1_setup_algs(struct cs_dsp *dsp) ...@@ -1670,12 +1671,14 @@ static int cs_dsp_adsp1_setup_algs(struct cs_dsp *dsp)
cs_dsp_parse_wmfw_id_header(dsp, &adsp1_id.fw, n_algs); cs_dsp_parse_wmfw_id_header(dsp, &adsp1_id.fw, n_algs);
alg_region = cs_dsp_create_region(dsp, WMFW_ADSP1_ZM, alg_region = cs_dsp_create_region(dsp, WMFW_ADSP1_ZM,
adsp1_id.fw.id, adsp1_id.zm); adsp1_id.fw.id, adsp1_id.fw.ver,
adsp1_id.zm);
if (IS_ERR(alg_region)) if (IS_ERR(alg_region))
return PTR_ERR(alg_region); return PTR_ERR(alg_region);
alg_region = cs_dsp_create_region(dsp, WMFW_ADSP1_DM, alg_region = cs_dsp_create_region(dsp, WMFW_ADSP1_DM,
adsp1_id.fw.id, adsp1_id.dm); adsp1_id.fw.id, adsp1_id.fw.ver,
adsp1_id.dm);
if (IS_ERR(alg_region)) if (IS_ERR(alg_region))
return PTR_ERR(alg_region); return PTR_ERR(alg_region);
...@@ -1698,6 +1701,7 @@ static int cs_dsp_adsp1_setup_algs(struct cs_dsp *dsp) ...@@ -1698,6 +1701,7 @@ static int cs_dsp_adsp1_setup_algs(struct cs_dsp *dsp)
alg_region = cs_dsp_create_region(dsp, WMFW_ADSP1_DM, alg_region = cs_dsp_create_region(dsp, WMFW_ADSP1_DM,
adsp1_alg[i].alg.id, adsp1_alg[i].alg.id,
adsp1_alg[i].alg.ver,
adsp1_alg[i].dm); adsp1_alg[i].dm);
if (IS_ERR(alg_region)) { if (IS_ERR(alg_region)) {
ret = PTR_ERR(alg_region); ret = PTR_ERR(alg_region);
...@@ -1719,6 +1723,7 @@ static int cs_dsp_adsp1_setup_algs(struct cs_dsp *dsp) ...@@ -1719,6 +1723,7 @@ static int cs_dsp_adsp1_setup_algs(struct cs_dsp *dsp)
alg_region = cs_dsp_create_region(dsp, WMFW_ADSP1_ZM, alg_region = cs_dsp_create_region(dsp, WMFW_ADSP1_ZM,
adsp1_alg[i].alg.id, adsp1_alg[i].alg.id,
adsp1_alg[i].alg.ver,
adsp1_alg[i].zm); adsp1_alg[i].zm);
if (IS_ERR(alg_region)) { if (IS_ERR(alg_region)) {
ret = PTR_ERR(alg_region); ret = PTR_ERR(alg_region);
...@@ -1771,17 +1776,20 @@ static int cs_dsp_adsp2_setup_algs(struct cs_dsp *dsp) ...@@ -1771,17 +1776,20 @@ static int cs_dsp_adsp2_setup_algs(struct cs_dsp *dsp)
cs_dsp_parse_wmfw_id_header(dsp, &adsp2_id.fw, n_algs); cs_dsp_parse_wmfw_id_header(dsp, &adsp2_id.fw, n_algs);
alg_region = cs_dsp_create_region(dsp, WMFW_ADSP2_XM, alg_region = cs_dsp_create_region(dsp, WMFW_ADSP2_XM,
adsp2_id.fw.id, adsp2_id.xm); adsp2_id.fw.id, adsp2_id.fw.ver,
adsp2_id.xm);
if (IS_ERR(alg_region)) if (IS_ERR(alg_region))
return PTR_ERR(alg_region); return PTR_ERR(alg_region);
alg_region = cs_dsp_create_region(dsp, WMFW_ADSP2_YM, alg_region = cs_dsp_create_region(dsp, WMFW_ADSP2_YM,
adsp2_id.fw.id, adsp2_id.ym); adsp2_id.fw.id, adsp2_id.fw.ver,
adsp2_id.ym);
if (IS_ERR(alg_region)) if (IS_ERR(alg_region))
return PTR_ERR(alg_region); return PTR_ERR(alg_region);
alg_region = cs_dsp_create_region(dsp, WMFW_ADSP2_ZM, alg_region = cs_dsp_create_region(dsp, WMFW_ADSP2_ZM,
adsp2_id.fw.id, adsp2_id.zm); adsp2_id.fw.id, adsp2_id.fw.ver,
adsp2_id.zm);
if (IS_ERR(alg_region)) if (IS_ERR(alg_region))
return PTR_ERR(alg_region); return PTR_ERR(alg_region);
...@@ -1806,6 +1814,7 @@ static int cs_dsp_adsp2_setup_algs(struct cs_dsp *dsp) ...@@ -1806,6 +1814,7 @@ static int cs_dsp_adsp2_setup_algs(struct cs_dsp *dsp)
alg_region = cs_dsp_create_region(dsp, WMFW_ADSP2_XM, alg_region = cs_dsp_create_region(dsp, WMFW_ADSP2_XM,
adsp2_alg[i].alg.id, adsp2_alg[i].alg.id,
adsp2_alg[i].alg.ver,
adsp2_alg[i].xm); adsp2_alg[i].xm);
if (IS_ERR(alg_region)) { if (IS_ERR(alg_region)) {
ret = PTR_ERR(alg_region); ret = PTR_ERR(alg_region);
...@@ -1827,6 +1836,7 @@ static int cs_dsp_adsp2_setup_algs(struct cs_dsp *dsp) ...@@ -1827,6 +1836,7 @@ static int cs_dsp_adsp2_setup_algs(struct cs_dsp *dsp)
alg_region = cs_dsp_create_region(dsp, WMFW_ADSP2_YM, alg_region = cs_dsp_create_region(dsp, WMFW_ADSP2_YM,
adsp2_alg[i].alg.id, adsp2_alg[i].alg.id,
adsp2_alg[i].alg.ver,
adsp2_alg[i].ym); adsp2_alg[i].ym);
if (IS_ERR(alg_region)) { if (IS_ERR(alg_region)) {
ret = PTR_ERR(alg_region); ret = PTR_ERR(alg_region);
...@@ -1848,6 +1858,7 @@ static int cs_dsp_adsp2_setup_algs(struct cs_dsp *dsp) ...@@ -1848,6 +1858,7 @@ static int cs_dsp_adsp2_setup_algs(struct cs_dsp *dsp)
alg_region = cs_dsp_create_region(dsp, WMFW_ADSP2_ZM, alg_region = cs_dsp_create_region(dsp, WMFW_ADSP2_ZM,
adsp2_alg[i].alg.id, adsp2_alg[i].alg.id,
adsp2_alg[i].alg.ver,
adsp2_alg[i].zm); adsp2_alg[i].zm);
if (IS_ERR(alg_region)) { if (IS_ERR(alg_region)) {
ret = PTR_ERR(alg_region); ret = PTR_ERR(alg_region);
...@@ -1873,7 +1884,7 @@ static int cs_dsp_adsp2_setup_algs(struct cs_dsp *dsp) ...@@ -1873,7 +1884,7 @@ static int cs_dsp_adsp2_setup_algs(struct cs_dsp *dsp)
return ret; return ret;
} }
static int cs_dsp_halo_create_regions(struct cs_dsp *dsp, __be32 id, static int cs_dsp_halo_create_regions(struct cs_dsp *dsp, __be32 id, __be32 ver,
__be32 xm_base, __be32 ym_base) __be32 xm_base, __be32 ym_base)
{ {
static const int types[] = { static const int types[] = {
...@@ -1882,7 +1893,7 @@ static int cs_dsp_halo_create_regions(struct cs_dsp *dsp, __be32 id, ...@@ -1882,7 +1893,7 @@ static int cs_dsp_halo_create_regions(struct cs_dsp *dsp, __be32 id,
}; };
__be32 bases[] = { xm_base, xm_base, ym_base, ym_base }; __be32 bases[] = { xm_base, xm_base, ym_base, ym_base };
return cs_dsp_create_regions(dsp, id, ARRAY_SIZE(types), types, bases); return cs_dsp_create_regions(dsp, id, ver, ARRAY_SIZE(types), types, bases);
} }
static int cs_dsp_halo_setup_algs(struct cs_dsp *dsp) static int cs_dsp_halo_setup_algs(struct cs_dsp *dsp)
...@@ -1910,7 +1921,7 @@ static int cs_dsp_halo_setup_algs(struct cs_dsp *dsp) ...@@ -1910,7 +1921,7 @@ static int cs_dsp_halo_setup_algs(struct cs_dsp *dsp)
cs_dsp_parse_wmfw_v3_id_header(dsp, &halo_id.fw, n_algs); cs_dsp_parse_wmfw_v3_id_header(dsp, &halo_id.fw, n_algs);
ret = cs_dsp_halo_create_regions(dsp, halo_id.fw.id, ret = cs_dsp_halo_create_regions(dsp, halo_id.fw.id, halo_id.fw.ver,
halo_id.xm_base, halo_id.ym_base); halo_id.xm_base, halo_id.ym_base);
if (ret) if (ret)
return ret; return ret;
...@@ -1934,6 +1945,7 @@ static int cs_dsp_halo_setup_algs(struct cs_dsp *dsp) ...@@ -1934,6 +1945,7 @@ static int cs_dsp_halo_setup_algs(struct cs_dsp *dsp)
be32_to_cpu(halo_alg[i].ym_base)); be32_to_cpu(halo_alg[i].ym_base));
ret = cs_dsp_halo_create_regions(dsp, halo_alg[i].alg.id, ret = cs_dsp_halo_create_regions(dsp, halo_alg[i].alg.id,
halo_alg[i].alg.ver,
halo_alg[i].xm_base, halo_alg[i].xm_base,
halo_alg[i].ym_base); halo_alg[i].ym_base);
if (ret) if (ret)
...@@ -1955,7 +1967,7 @@ static int cs_dsp_load_coeff(struct cs_dsp *dsp, const struct firmware *firmware ...@@ -1955,7 +1967,7 @@ static int cs_dsp_load_coeff(struct cs_dsp *dsp, const struct firmware *firmware
const struct cs_dsp_region *mem; const struct cs_dsp_region *mem;
struct cs_dsp_alg_region *alg_region; struct cs_dsp_alg_region *alg_region;
const char *region_name; const char *region_name;
int ret, pos, blocks, type, offset, reg; int ret, pos, blocks, type, offset, reg, version;
struct cs_dsp_buf *buf; struct cs_dsp_buf *buf;
if (!firmware) if (!firmware)
...@@ -1999,6 +2011,7 @@ static int cs_dsp_load_coeff(struct cs_dsp *dsp, const struct firmware *firmware ...@@ -1999,6 +2011,7 @@ static int cs_dsp_load_coeff(struct cs_dsp *dsp, const struct firmware *firmware
type = le16_to_cpu(blk->type); type = le16_to_cpu(blk->type);
offset = le16_to_cpu(blk->offset); offset = le16_to_cpu(blk->offset);
version = le32_to_cpu(blk->ver) >> 8;
cs_dsp_dbg(dsp, "%s.%d: %x v%d.%d.%d\n", cs_dsp_dbg(dsp, "%s.%d: %x v%d.%d.%d\n",
file, blocks, le32_to_cpu(blk->id), file, blocks, le32_to_cpu(blk->id),
...@@ -2056,6 +2069,16 @@ static int cs_dsp_load_coeff(struct cs_dsp *dsp, const struct firmware *firmware ...@@ -2056,6 +2069,16 @@ static int cs_dsp_load_coeff(struct cs_dsp *dsp, const struct firmware *firmware
alg_region = cs_dsp_find_alg_region(dsp, type, alg_region = cs_dsp_find_alg_region(dsp, type,
le32_to_cpu(blk->id)); le32_to_cpu(blk->id));
if (alg_region) { if (alg_region) {
if (version != alg_region->ver)
cs_dsp_warn(dsp,
"Algorithm coefficient version %d.%d.%d but expected %d.%d.%d\n",
(version >> 16) & 0xFF,
(version >> 8) & 0xFF,
version & 0xFF,
(alg_region->ver >> 16) & 0xFF,
(alg_region->ver >> 8) & 0xFF,
alg_region->ver & 0xFF);
reg = alg_region->base; reg = alg_region->base;
reg = dsp->ops->region_to_reg(mem, reg); reg = dsp->ops->region_to_reg(mem, reg);
reg += offset; reg += offset;
......
...@@ -54,12 +54,14 @@ struct cs_dsp_region { ...@@ -54,12 +54,14 @@ struct cs_dsp_region {
* struct cs_dsp_alg_region - Describes a logical algorithm region in DSP address space * struct cs_dsp_alg_region - Describes a logical algorithm region in DSP address space
* @list: List node for internal use * @list: List node for internal use
* @alg: Algorithm id * @alg: Algorithm id
* @ver: Expected algorithm version
* @type: Memory region type * @type: Memory region type
* @base: Address of region * @base: Address of region
*/ */
struct cs_dsp_alg_region { struct cs_dsp_alg_region {
struct list_head list; struct list_head list;
unsigned int alg; unsigned int alg;
unsigned int ver;
int type; int type;
unsigned int base; unsigned int base;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment