Skip to content

Commit 81a2991

Browse files
crojewsk-intelbroonie
authored andcommitted
ASoC: Intel: avs: Account for libraries when booting basefw
Not all modules are part of base firmware. Some are part of loadable libraries. These need to be loaded after base firmware reports ready status through FW_READY notification. Their loading process is similar to the base firmware's one. Request the binary file, verify and strip the manifest and load the actual code into DSP memory with help of CLDMA or HD-Audio render stream, depending on audio device generation. List of libraries needed for loading is obtained through the topology - vendor sections specifying the name of firmware files to request. Signed-off-by: Cezary Rojewski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent dba2d5a commit 81a2991

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

sound/soc/intel/avs/avs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
struct avs_dev;
2121
struct avs_tplg;
22+
struct avs_tplg_library;
23+
struct avs_soc_component;
2224

2325
/*
2426
* struct avs_dsp_ops - Platform-specific DSP operations
@@ -241,6 +243,7 @@ void avs_hda_clock_gating_enable(struct avs_dev *adev, bool enable);
241243
void avs_hda_power_gating_enable(struct avs_dev *adev, bool enable);
242244
void avs_hda_l1sen_enable(struct avs_dev *adev, bool enable);
243245

246+
int avs_dsp_load_libraries(struct avs_dev *adev, struct avs_tplg_library *libs, u32 num_libs);
244247
int avs_dsp_boot_firmware(struct avs_dev *adev, bool purge);
245248
int avs_dsp_first_boot_firmware(struct avs_dev *adev);
246249

sound/soc/intel/avs/loader.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "cldma.h"
1616
#include "messages.h"
1717
#include "registers.h"
18+
#include "topology.h"
1819

1920
#define AVS_ROM_STS_MASK 0xFF
2021
#define AVS_ROM_INIT_DONE 0x1
@@ -466,6 +467,71 @@ int avs_hda_transfer_modules(struct avs_dev *adev, bool load,
466467
return 0;
467468
}
468469

470+
int avs_dsp_load_libraries(struct avs_dev *adev, struct avs_tplg_library *libs, u32 num_libs)
471+
{
472+
int start, id, i = 0;
473+
int ret;
474+
475+
/* Calculate the id to assign for the next lib. */
476+
for (id = 0; id < adev->fw_cfg.max_libs_count; id++)
477+
if (adev->lib_names[id][0] == '\0')
478+
break;
479+
if (id + num_libs >= adev->fw_cfg.max_libs_count)
480+
return -EINVAL;
481+
482+
start = id;
483+
while (i < num_libs) {
484+
struct avs_fw_manifest *man;
485+
const struct firmware *fw;
486+
struct firmware stripped_fw;
487+
char *filename;
488+
int j;
489+
490+
filename = kasprintf(GFP_KERNEL, "%s/%s/%s", AVS_ROOT_DIR, adev->spec->name,
491+
libs[i].name);
492+
if (!filename)
493+
return -ENOMEM;
494+
495+
/*
496+
* If any call after this one fails, requested firmware is not released with
497+
* avs_release_last_firmware() as failing to load code results in need for reload
498+
* of entire driver module. And then avs_release_firmwares() is in place already.
499+
*/
500+
ret = avs_request_firmware(adev, &fw, filename);
501+
kfree(filename);
502+
if (ret < 0)
503+
return ret;
504+
505+
stripped_fw = *fw;
506+
ret = avs_fw_manifest_strip_verify(adev, &stripped_fw, NULL);
507+
if (ret) {
508+
dev_err(adev->dev, "invalid library data: %d\n", ret);
509+
return ret;
510+
}
511+
512+
ret = avs_fw_manifest_offset(&stripped_fw);
513+
if (ret < 0)
514+
return ret;
515+
man = (struct avs_fw_manifest *)(stripped_fw.data + ret);
516+
517+
/* Don't load anything that's already in DSP memory. */
518+
for (j = 0; j < id; j++)
519+
if (!strncmp(adev->lib_names[j], man->name, AVS_LIB_NAME_SIZE))
520+
goto next_lib;
521+
522+
ret = avs_dsp_op(adev, load_lib, &stripped_fw, id);
523+
if (ret)
524+
return ret;
525+
526+
strncpy(adev->lib_names[id], man->name, AVS_LIB_NAME_SIZE);
527+
id++;
528+
next_lib:
529+
i++;
530+
}
531+
532+
return start == id ? 1 : 0;
533+
}
534+
469535
static int avs_dsp_load_basefw(struct avs_dev *adev)
470536
{
471537
const struct avs_fw_version *min_req;
@@ -519,6 +585,7 @@ static int avs_dsp_load_basefw(struct avs_dev *adev)
519585

520586
int avs_dsp_boot_firmware(struct avs_dev *adev, bool purge)
521587
{
588+
struct avs_soc_component *acomp;
522589
int ret, i;
523590

524591
/* Forgo full boot if flash from IMR succeeds. */
@@ -538,7 +605,20 @@ int avs_dsp_boot_firmware(struct avs_dev *adev, bool purge)
538605
avs_hda_l1sen_enable(adev, false);
539606

540607
ret = avs_dsp_load_basefw(adev);
608+
if (ret)
609+
goto reenable_gating;
610+
611+
mutex_lock(&adev->comp_list_mutex);
612+
list_for_each_entry(acomp, &adev->comp_list, node) {
613+
struct avs_tplg *tplg = acomp->tplg;
614+
615+
ret = avs_dsp_load_libraries(adev, tplg->libs, tplg->num_libs);
616+
if (ret < 0)
617+
break;
618+
}
619+
mutex_unlock(&adev->comp_list_mutex);
541620

621+
reenable_gating:
542622
avs_hda_l1sen_enable(adev, true);
543623
avs_hda_clock_gating_enable(adev, true);
544624

0 commit comments

Comments
 (0)