1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
3 // This file is provided under a dual BSD/GPLv2 license. When using or
4 // redistributing this file, you may do so under either license.
6 // Copyright(c) 2018 Intel Corporation. All rights reserved.
8 // Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
10 // Generic firmware loader.
13 #include <linux/firmware.h>
14 #include <sound/sof.h>
15 #include <sound/sof/ext_manifest.h>
18 static int get_ext_windows(struct snd_sof_dev *sdev,
19 const struct sof_ipc_ext_data_hdr *ext_hdr)
21 const struct sof_ipc_window *w =
22 container_of(ext_hdr, struct sof_ipc_window, ext_hdr);
24 if (w->num_windows == 0 || w->num_windows > SOF_IPC_MAX_ELEMS)
27 if (sdev->info_window) {
28 if (memcmp(sdev->info_window, w, ext_hdr->hdr.size)) {
29 dev_err(sdev->dev, "error: mismatch between window descriptor from extended manifest and mailbox");
35 /* keep a local copy of the data */
36 sdev->info_window = devm_kmemdup(sdev->dev, w, ext_hdr->hdr.size,
38 if (!sdev->info_window)
44 static int get_cc_info(struct snd_sof_dev *sdev,
45 const struct sof_ipc_ext_data_hdr *ext_hdr)
49 const struct sof_ipc_cc_version *cc =
50 container_of(ext_hdr, struct sof_ipc_cc_version, ext_hdr);
52 if (sdev->cc_version) {
53 if (memcmp(sdev->cc_version, cc, cc->ext_hdr.hdr.size)) {
54 dev_err(sdev->dev, "error: receive diverged cc_version descriptions");
60 dev_dbg(sdev->dev, "Firmware info: used compiler %s %d:%d:%d%s used optimization flags %s\n",
61 cc->name, cc->major, cc->minor, cc->micro, cc->desc,
64 /* create read-only cc_version debugfs to store compiler version info */
65 /* use local copy of the cc_version to prevent data corruption */
66 if (sdev->first_boot) {
67 sdev->cc_version = devm_kmalloc(sdev->dev, cc->ext_hdr.hdr.size,
70 if (!sdev->cc_version)
73 memcpy(sdev->cc_version, cc, cc->ext_hdr.hdr.size);
74 ret = snd_sof_debugfs_buf_item(sdev, sdev->cc_version,
78 /* errors are only due to memory allocation, not debugfs */
80 dev_err(sdev->dev, "error: snd_sof_debugfs_buf_item failed\n");
88 /* parse the extended FW boot data structures from FW boot message */
89 int snd_sof_fw_parse_ext_data(struct snd_sof_dev *sdev, u32 bar, u32 offset)
91 struct sof_ipc_ext_data_hdr *ext_hdr;
95 ext_data = kzalloc(PAGE_SIZE, GFP_KERNEL);
99 /* get first header */
100 snd_sof_dsp_block_read(sdev, bar, offset, ext_data,
104 while (ext_hdr->hdr.cmd == SOF_IPC_FW_READY) {
105 /* read in ext structure */
106 snd_sof_dsp_block_read(sdev, bar, offset + sizeof(*ext_hdr),
107 (void *)((u8 *)ext_data + sizeof(*ext_hdr)),
108 ext_hdr->hdr.size - sizeof(*ext_hdr));
110 dev_dbg(sdev->dev, "found ext header type %d size 0x%x\n",
111 ext_hdr->type, ext_hdr->hdr.size);
113 /* process structure data */
114 switch (ext_hdr->type) {
115 case SOF_IPC_EXT_WINDOW:
116 ret = get_ext_windows(sdev, ext_hdr);
118 case SOF_IPC_EXT_CC_INFO:
119 ret = get_cc_info(sdev, ext_hdr);
121 case SOF_IPC_EXT_UNUSED:
122 case SOF_IPC_EXT_PROBE_INFO:
123 case SOF_IPC_EXT_USER_ABI_INFO:
124 /* They are supported but we don't do anything here */
127 dev_info(sdev->dev, "unknown ext header type %d size 0x%x\n",
128 ext_hdr->type, ext_hdr->hdr.size);
134 dev_err(sdev->dev, "error: failed to parse ext data type %d\n",
139 /* move to next header */
140 offset += ext_hdr->hdr.size;
141 snd_sof_dsp_block_read(sdev, bar, offset, ext_data,
149 EXPORT_SYMBOL(snd_sof_fw_parse_ext_data);
151 static int ext_man_get_fw_version(struct snd_sof_dev *sdev,
152 const struct sof_ext_man_elem_header *hdr)
154 const struct sof_ext_man_fw_version *v =
155 container_of(hdr, struct sof_ext_man_fw_version, hdr);
157 memcpy(&sdev->fw_ready.version, &v->version, sizeof(v->version));
158 sdev->fw_ready.flags = v->flags;
160 /* log ABI versions and check FW compatibility */
161 return snd_sof_ipc_valid(sdev);
164 static int ext_man_get_windows(struct snd_sof_dev *sdev,
165 const struct sof_ext_man_elem_header *hdr)
167 const struct sof_ext_man_window *w;
169 w = container_of(hdr, struct sof_ext_man_window, hdr);
171 return get_ext_windows(sdev, &w->ipc_window.ext_hdr);
174 static int ext_man_get_cc_info(struct snd_sof_dev *sdev,
175 const struct sof_ext_man_elem_header *hdr)
177 const struct sof_ext_man_cc_version *cc;
179 cc = container_of(hdr, struct sof_ext_man_cc_version, hdr);
181 return get_cc_info(sdev, &cc->cc_version.ext_hdr);
184 static int ext_man_get_dbg_abi_info(struct snd_sof_dev *sdev,
185 const struct sof_ext_man_elem_header *hdr)
187 const struct ext_man_dbg_abi *dbg_abi =
188 container_of(hdr, struct ext_man_dbg_abi, hdr);
190 if (sdev->first_boot)
192 "Firmware: DBG_ABI %d:%d:%d\n",
193 SOF_ABI_VERSION_MAJOR(dbg_abi->dbg_abi.abi_dbg_version),
194 SOF_ABI_VERSION_MINOR(dbg_abi->dbg_abi.abi_dbg_version),
195 SOF_ABI_VERSION_PATCH(dbg_abi->dbg_abi.abi_dbg_version));
200 static int ext_man_get_config_data(struct snd_sof_dev *sdev,
201 const struct sof_ext_man_elem_header *hdr)
203 const struct sof_ext_man_config_data *config =
204 container_of(hdr, struct sof_ext_man_config_data, hdr);
205 const struct sof_config_elem *elem;
211 /* calculate elements counter */
212 elems_size = config->hdr.size - sizeof(struct sof_ext_man_elem_header);
213 elems_counter = elems_size / sizeof(struct sof_config_elem);
215 dev_dbg(sdev->dev, "%s can hold up to %d config elements\n",
216 __func__, elems_counter);
218 for (i = 0; i < elems_counter; ++i) {
219 elem = &config->elems[i];
220 dev_dbg(sdev->dev, "%s get index %d token %d val %d\n",
221 __func__, i, elem->token, elem->value);
222 switch (elem->token) {
223 case SOF_EXT_MAN_CONFIG_EMPTY:
224 /* unused memory space is zero filled - mapped to EMPTY elements */
226 case SOF_EXT_MAN_CONFIG_IPC_MSG_SIZE:
227 /* TODO: use ipc msg size from config data */
229 case SOF_EXT_MAN_CONFIG_MEMORY_USAGE_SCAN:
230 if (sdev->first_boot && elem->value)
231 ret = snd_sof_dbg_memory_info_init(sdev);
234 dev_info(sdev->dev, "Unknown firmware configuration token %d value %d",
235 elem->token, elem->value);
239 dev_err(sdev->dev, "error: processing sof_ext_man_config_data failed for token %d value 0x%x, %d\n",
240 elem->token, elem->value, ret);
248 static ssize_t snd_sof_ext_man_size(const struct firmware *fw)
250 const struct sof_ext_man_header *head;
252 head = (struct sof_ext_man_header *)fw->data;
255 * assert fw size is big enough to contain extended manifest header,
256 * it prevents from reading unallocated memory from `head` in following
259 if (fw->size < sizeof(*head))
263 * When fw points to extended manifest,
264 * then first u32 must be equal SOF_EXT_MAN_MAGIC_NUMBER.
266 if (head->magic == SOF_EXT_MAN_MAGIC_NUMBER)
267 return head->full_size;
269 /* otherwise given fw don't have an extended manifest */
273 /* parse extended FW manifest data structures */
274 static int snd_sof_fw_ext_man_parse(struct snd_sof_dev *sdev,
275 const struct firmware *fw)
277 const struct sof_ext_man_elem_header *elem_hdr;
278 const struct sof_ext_man_header *head;
279 ssize_t ext_man_size;
284 head = (struct sof_ext_man_header *)fw->data;
285 remaining = head->full_size - head->header_size;
286 ext_man_size = snd_sof_ext_man_size(fw);
288 /* Assert firmware starts with extended manifest */
289 if (ext_man_size <= 0)
292 /* incompatible version */
293 if (SOF_EXT_MAN_VERSION_INCOMPATIBLE(SOF_EXT_MAN_VERSION,
294 head->header_version)) {
295 dev_err(sdev->dev, "error: extended manifest version 0x%X differ from used 0x%X\n",
296 head->header_version, SOF_EXT_MAN_VERSION);
300 /* get first extended manifest element header */
301 iptr = (uintptr_t)fw->data + head->header_size;
303 while (remaining > sizeof(*elem_hdr)) {
304 elem_hdr = (struct sof_ext_man_elem_header *)iptr;
306 dev_dbg(sdev->dev, "found sof_ext_man header type %d size 0x%X\n",
307 elem_hdr->type, elem_hdr->size);
309 if (elem_hdr->size < sizeof(*elem_hdr) ||
310 elem_hdr->size > remaining) {
311 dev_err(sdev->dev, "error: invalid sof_ext_man header size, type %d size 0x%X\n",
312 elem_hdr->type, elem_hdr->size);
316 /* process structure data */
317 switch (elem_hdr->type) {
318 case SOF_EXT_MAN_ELEM_FW_VERSION:
319 ret = ext_man_get_fw_version(sdev, elem_hdr);
321 case SOF_EXT_MAN_ELEM_WINDOW:
322 ret = ext_man_get_windows(sdev, elem_hdr);
324 case SOF_EXT_MAN_ELEM_CC_VERSION:
325 ret = ext_man_get_cc_info(sdev, elem_hdr);
327 case SOF_EXT_MAN_ELEM_DBG_ABI:
328 ret = ext_man_get_dbg_abi_info(sdev, elem_hdr);
330 case SOF_EXT_MAN_ELEM_CONFIG_DATA:
331 ret = ext_man_get_config_data(sdev, elem_hdr);
333 case SOF_EXT_MAN_ELEM_PLATFORM_CONFIG_DATA:
334 ret = snd_sof_dsp_parse_platform_ext_manifest(sdev, elem_hdr);
337 dev_info(sdev->dev, "unknown sof_ext_man header type %d size 0x%X\n",
338 elem_hdr->type, elem_hdr->size);
343 dev_err(sdev->dev, "error: failed to parse sof_ext_man header type %d size 0x%X\n",
344 elem_hdr->type, elem_hdr->size);
348 remaining -= elem_hdr->size;
349 iptr += elem_hdr->size;
353 dev_err(sdev->dev, "error: sof_ext_man header is inconsistent\n");
361 * IPC Firmware ready.
363 static void sof_get_windows(struct snd_sof_dev *sdev)
365 struct sof_ipc_window_elem *elem;
366 u32 outbox_offset = 0;
367 u32 stream_offset = 0;
368 u32 inbox_offset = 0;
373 u32 debug_offset = 0;
378 if (!sdev->info_window) {
379 dev_err(sdev->dev, "error: have no window info\n");
383 bar = snd_sof_dsp_get_bar_index(sdev, SOF_FW_BLK_TYPE_SRAM);
385 dev_err(sdev->dev, "error: have no bar mapping\n");
389 for (i = 0; i < sdev->info_window->num_windows; i++) {
390 elem = &sdev->info_window->window[i];
392 window_offset = snd_sof_dsp_get_window_offset(sdev, elem->id);
393 if (window_offset < 0) {
394 dev_warn(sdev->dev, "warn: no offset for window %d\n",
399 switch (elem->type) {
400 case SOF_IPC_REGION_UPBOX:
401 inbox_offset = window_offset + elem->offset;
402 inbox_size = elem->size;
403 snd_sof_debugfs_io_item(sdev,
407 SOF_DEBUGFS_ACCESS_D0_ONLY);
409 case SOF_IPC_REGION_DOWNBOX:
410 outbox_offset = window_offset + elem->offset;
411 outbox_size = elem->size;
412 snd_sof_debugfs_io_item(sdev,
415 elem->size, "outbox",
416 SOF_DEBUGFS_ACCESS_D0_ONLY);
418 case SOF_IPC_REGION_TRACE:
419 snd_sof_debugfs_io_item(sdev,
423 elem->size, "etrace",
424 SOF_DEBUGFS_ACCESS_D0_ONLY);
426 case SOF_IPC_REGION_DEBUG:
427 debug_offset = window_offset + elem->offset;
428 debug_size = elem->size;
429 snd_sof_debugfs_io_item(sdev,
434 SOF_DEBUGFS_ACCESS_D0_ONLY);
436 case SOF_IPC_REGION_STREAM:
437 stream_offset = window_offset + elem->offset;
438 stream_size = elem->size;
439 snd_sof_debugfs_io_item(sdev,
442 elem->size, "stream",
443 SOF_DEBUGFS_ACCESS_D0_ONLY);
445 case SOF_IPC_REGION_REGS:
446 snd_sof_debugfs_io_item(sdev,
451 SOF_DEBUGFS_ACCESS_D0_ONLY);
453 case SOF_IPC_REGION_EXCEPTION:
454 sdev->dsp_oops_offset = window_offset + elem->offset;
455 snd_sof_debugfs_io_item(sdev,
459 elem->size, "exception",
460 SOF_DEBUGFS_ACCESS_D0_ONLY);
463 dev_err(sdev->dev, "error: get illegal window info\n");
468 if (outbox_size == 0 || inbox_size == 0) {
469 dev_err(sdev->dev, "error: get illegal mailbox window\n");
473 snd_sof_dsp_mailbox_init(sdev, inbox_offset, inbox_size,
474 outbox_offset, outbox_size);
475 sdev->stream_box.offset = stream_offset;
476 sdev->stream_box.size = stream_size;
478 sdev->debug_box.offset = debug_offset;
479 sdev->debug_box.size = debug_size;
481 dev_dbg(sdev->dev, " mailbox upstream 0x%x - size 0x%x\n",
482 inbox_offset, inbox_size);
483 dev_dbg(sdev->dev, " mailbox downstream 0x%x - size 0x%x\n",
484 outbox_offset, outbox_size);
485 dev_dbg(sdev->dev, " stream region 0x%x - size 0x%x\n",
486 stream_offset, stream_size);
487 dev_dbg(sdev->dev, " debug region 0x%x - size 0x%x\n",
488 debug_offset, debug_size);
491 /* check for ABI compatibility and create memory windows on first boot */
492 int sof_fw_ready(struct snd_sof_dev *sdev, u32 msg_id)
494 struct sof_ipc_fw_ready *fw_ready = &sdev->fw_ready;
499 /* mailbox must be on 4k boundary */
500 offset = snd_sof_dsp_get_mailbox_offset(sdev);
502 dev_err(sdev->dev, "error: have no mailbox offset\n");
506 bar = snd_sof_dsp_get_bar_index(sdev, SOF_FW_BLK_TYPE_SRAM);
508 dev_err(sdev->dev, "error: have no bar mapping\n");
512 dev_dbg(sdev->dev, "ipc: DSP is ready 0x%8.8x offset 0x%x\n",
515 /* no need to re-check version/ABI for subsequent boots */
516 if (!sdev->first_boot)
519 /* copy data from the DSP FW ready offset */
520 sof_block_read(sdev, bar, offset, fw_ready, sizeof(*fw_ready));
522 /* make sure ABI version is compatible */
523 ret = snd_sof_ipc_valid(sdev);
527 /* now check for extended data */
528 snd_sof_fw_parse_ext_data(sdev, bar, offset +
529 sizeof(struct sof_ipc_fw_ready));
531 sof_get_windows(sdev);
535 EXPORT_SYMBOL(sof_fw_ready);
537 /* generic module parser for mmaped DSPs */
538 int snd_sof_parse_module_memcpy(struct snd_sof_dev *sdev,
539 struct snd_sof_mod_hdr *module)
541 struct snd_sof_blk_hdr *block;
546 dev_dbg(sdev->dev, "new module size 0x%x blocks 0x%x type 0x%x\n",
547 module->size, module->num_blocks, module->type);
549 block = (struct snd_sof_blk_hdr *)((u8 *)module + sizeof(*module));
551 /* module->size doesn't include header size */
552 remaining = module->size;
553 for (count = 0; count < module->num_blocks; count++) {
555 if (remaining < sizeof(*block)) {
556 dev_err(sdev->dev, "error: not enough data remaining\n");
560 /* minus header size of block */
561 remaining -= sizeof(*block);
563 if (block->size == 0) {
565 "warning: block %d size zero\n", count);
566 dev_warn(sdev->dev, " type 0x%x offset 0x%x\n",
567 block->type, block->offset);
571 switch (block->type) {
572 case SOF_FW_BLK_TYPE_RSRVD0:
573 case SOF_FW_BLK_TYPE_ROM...SOF_FW_BLK_TYPE_RSRVD14:
574 continue; /* not handled atm */
575 case SOF_FW_BLK_TYPE_IRAM:
576 case SOF_FW_BLK_TYPE_DRAM:
577 case SOF_FW_BLK_TYPE_SRAM:
578 offset = block->offset;
579 bar = snd_sof_dsp_get_bar_index(sdev, block->type);
582 "error: no BAR mapping for block type 0x%x\n",
588 dev_err(sdev->dev, "error: bad type 0x%x for block 0x%x\n",
594 "block %d type 0x%x size 0x%x ==> offset 0x%x\n",
595 count, block->type, block->size, offset);
597 /* checking block->size to avoid unaligned access */
598 if (block->size % sizeof(u32)) {
599 dev_err(sdev->dev, "error: invalid block size 0x%x\n",
603 snd_sof_dsp_block_write(sdev, bar, offset,
604 block + 1, block->size);
606 if (remaining < block->size) {
607 dev_err(sdev->dev, "error: not enough data remaining\n");
611 /* minus body size of block */
612 remaining -= block->size;
614 block = (struct snd_sof_blk_hdr *)((u8 *)block + sizeof(*block)
620 EXPORT_SYMBOL(snd_sof_parse_module_memcpy);
622 static int check_header(struct snd_sof_dev *sdev, const struct firmware *fw,
625 struct snd_sof_fw_header *header;
626 size_t fw_size = fw->size - fw_offset;
628 if (fw->size <= fw_offset) {
629 dev_err(sdev->dev, "error: firmware size must be greater than firmware offset\n");
633 /* Read the header information from the data pointer */
634 header = (struct snd_sof_fw_header *)(fw->data + fw_offset);
637 if (strncmp(header->sig, SND_SOF_FW_SIG, SND_SOF_FW_SIG_SIZE) != 0) {
638 dev_err(sdev->dev, "error: invalid firmware signature\n");
642 /* check size is valid */
643 if (fw_size != header->file_size + sizeof(*header)) {
644 dev_err(sdev->dev, "error: invalid filesize mismatch got 0x%zx expected 0x%zx\n",
645 fw_size, header->file_size + sizeof(*header));
649 dev_dbg(sdev->dev, "header size=0x%x modules=0x%x abi=0x%x size=%zu\n",
650 header->file_size, header->num_modules,
651 header->abi, sizeof(*header));
656 static int load_modules(struct snd_sof_dev *sdev, const struct firmware *fw,
659 struct snd_sof_fw_header *header;
660 struct snd_sof_mod_hdr *module;
661 int (*load_module)(struct snd_sof_dev *sof_dev,
662 struct snd_sof_mod_hdr *hdr);
666 header = (struct snd_sof_fw_header *)(fw->data + fw_offset);
667 load_module = sof_ops(sdev)->load_module;
671 /* parse each module */
672 module = (struct snd_sof_mod_hdr *)(fw->data + fw_offset +
674 remaining = fw->size - sizeof(*header) - fw_offset;
676 if (remaining > fw->size) {
677 dev_err(sdev->dev, "error: fw size smaller than header size\n");
681 for (count = 0; count < header->num_modules; count++) {
683 if (remaining < sizeof(*module)) {
684 dev_err(sdev->dev, "error: not enough data remaining\n");
688 /* minus header size of module */
689 remaining -= sizeof(*module);
692 ret = load_module(sdev, module);
694 dev_err(sdev->dev, "error: invalid module %d\n", count);
698 if (remaining < module->size) {
699 dev_err(sdev->dev, "error: not enough data remaining\n");
703 /* minus body size of module */
704 remaining -= module->size;
705 module = (struct snd_sof_mod_hdr *)((u8 *)module
706 + sizeof(*module) + module->size);
712 int snd_sof_load_firmware_raw(struct snd_sof_dev *sdev)
714 struct snd_sof_pdata *plat_data = sdev->pdata;
715 const char *fw_filename;
716 ssize_t ext_man_size;
719 /* Don't request firmware again if firmware is already requested */
723 fw_filename = kasprintf(GFP_KERNEL, "%s/%s",
724 plat_data->fw_filename_prefix,
725 plat_data->fw_filename);
729 ret = request_firmware(&plat_data->fw, fw_filename, sdev->dev);
732 dev_err(sdev->dev, "error: request firmware %s failed err: %d\n",
735 "you may need to download the firmware from https://github.com/thesofproject/sof-bin/\n");
738 dev_dbg(sdev->dev, "request_firmware %s successful\n",
742 /* check for extended manifest */
743 ext_man_size = snd_sof_fw_ext_man_parse(sdev, plat_data->fw);
744 if (ext_man_size > 0) {
745 /* when no error occurred, drop extended manifest */
746 plat_data->fw_offset = ext_man_size;
747 } else if (!ext_man_size) {
748 /* No extended manifest, so nothing to skip during FW load */
749 dev_dbg(sdev->dev, "firmware doesn't contain extended manifest\n");
752 dev_err(sdev->dev, "error: firmware %s contains unsupported or invalid extended manifest: %d\n",
761 EXPORT_SYMBOL(snd_sof_load_firmware_raw);
763 int snd_sof_load_firmware_memcpy(struct snd_sof_dev *sdev)
765 struct snd_sof_pdata *plat_data = sdev->pdata;
768 ret = snd_sof_load_firmware_raw(sdev);
772 /* make sure the FW header and file is valid */
773 ret = check_header(sdev, plat_data->fw, plat_data->fw_offset);
775 dev_err(sdev->dev, "error: invalid FW header\n");
779 /* prepare the DSP for FW loading */
780 ret = snd_sof_dsp_reset(sdev);
782 dev_err(sdev->dev, "error: failed to reset DSP\n");
786 /* parse and load firmware modules to DSP */
787 ret = load_modules(sdev, plat_data->fw, plat_data->fw_offset);
789 dev_err(sdev->dev, "error: invalid FW modules\n");
796 release_firmware(plat_data->fw);
797 plat_data->fw = NULL;
801 EXPORT_SYMBOL(snd_sof_load_firmware_memcpy);
803 int snd_sof_load_firmware(struct snd_sof_dev *sdev)
805 dev_dbg(sdev->dev, "loading firmware\n");
807 if (sof_ops(sdev)->load_firmware)
808 return sof_ops(sdev)->load_firmware(sdev);
811 EXPORT_SYMBOL(snd_sof_load_firmware);
813 int snd_sof_run_firmware(struct snd_sof_dev *sdev)
817 init_waitqueue_head(&sdev->boot_wait);
819 /* create read-only fw_version debugfs to store boot version info */
820 if (sdev->first_boot) {
821 ret = snd_sof_debugfs_buf_item(sdev, &sdev->fw_version,
822 sizeof(sdev->fw_version),
824 /* errors are only due to memory allocation, not debugfs */
826 dev_err(sdev->dev, "error: snd_sof_debugfs_buf_item failed\n");
831 /* perform pre fw run operations */
832 ret = snd_sof_dsp_pre_fw_run(sdev);
834 dev_err(sdev->dev, "error: failed pre fw run op\n");
838 dev_dbg(sdev->dev, "booting DSP firmware\n");
840 /* boot the firmware on the DSP */
841 ret = snd_sof_dsp_run(sdev);
843 dev_err(sdev->dev, "error: failed to reset DSP\n");
848 * now wait for the DSP to boot. There are 3 possible outcomes:
849 * 1. Boot wait times out indicating FW boot failure.
850 * 2. FW boots successfully and fw_ready op succeeds.
851 * 3. FW boots but fw_ready op fails.
853 ret = wait_event_timeout(sdev->boot_wait,
854 sdev->fw_state > SOF_FW_BOOT_IN_PROGRESS,
855 msecs_to_jiffies(sdev->boot_timeout));
857 dev_err(sdev->dev, "error: firmware boot failure\n");
858 snd_sof_dsp_dbg_dump(sdev, SOF_DBG_DUMP_REGS | SOF_DBG_DUMP_MBOX |
859 SOF_DBG_DUMP_TEXT | SOF_DBG_DUMP_PCI | SOF_DBG_DUMP_FORCE_ERR_LEVEL);
860 sdev->fw_state = SOF_FW_BOOT_FAILED;
864 if (sdev->fw_state == SOF_FW_BOOT_COMPLETE)
865 dev_dbg(sdev->dev, "firmware boot complete\n");
867 return -EIO; /* FW boots but fw_ready op failed */
869 /* perform post fw run operations */
870 ret = snd_sof_dsp_post_fw_run(sdev);
872 dev_err(sdev->dev, "error: failed post fw run op\n");
878 EXPORT_SYMBOL(snd_sof_run_firmware);
880 void snd_sof_fw_unload(struct snd_sof_dev *sdev)
882 /* TODO: support module unloading at runtime */
884 EXPORT_SYMBOL(snd_sof_fw_unload);