Lines Matching +full:offset +full:- +full:x
1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
24 if (w->num_windows == 0 || w->num_windows > SOF_IPC_MAX_ELEMS) in get_ext_windows()
25 return -EINVAL; in get_ext_windows()
27 if (sdev->info_window) { in get_ext_windows()
28 if (memcmp(sdev->info_window, w, ext_hdr->hdr.size)) { in get_ext_windows()
29 …dev_err(sdev->dev, "error: mismatch between window descriptor from extended manifest and mailbox"); in get_ext_windows()
30 return -EINVAL; in get_ext_windows()
36 sdev->info_window = devm_kmemdup(sdev->dev, w, ext_hdr->hdr.size, in get_ext_windows()
38 if (!sdev->info_window) in get_ext_windows()
39 return -ENOMEM; in get_ext_windows()
52 if (sdev->cc_version) { in get_cc_info()
53 if (memcmp(sdev->cc_version, cc, cc->ext_hdr.hdr.size)) { in get_cc_info()
54 dev_err(sdev->dev, "error: receive diverged cc_version descriptions"); in get_cc_info()
55 return -EINVAL; in get_cc_info()
60 dev_dbg(sdev->dev, "Firmware info: used compiler %s %d:%d:%d%s used optimization flags %s\n", in get_cc_info()
61 cc->name, cc->major, cc->minor, cc->micro, cc->desc, in get_cc_info()
62 cc->optim); in get_cc_info()
64 /* create read-only cc_version debugfs to store compiler version info */ in get_cc_info()
66 if (sdev->first_boot) { in get_cc_info()
67 sdev->cc_version = devm_kmalloc(sdev->dev, cc->ext_hdr.hdr.size, in get_cc_info()
70 if (!sdev->cc_version) in get_cc_info()
71 return -ENOMEM; in get_cc_info()
73 memcpy(sdev->cc_version, cc, cc->ext_hdr.hdr.size); in get_cc_info()
74 ret = snd_sof_debugfs_buf_item(sdev, sdev->cc_version, in get_cc_info()
75 cc->ext_hdr.hdr.size, in get_cc_info()
80 dev_err(sdev->dev, "error: snd_sof_debugfs_buf_item failed\n"); in get_cc_info()
89 int snd_sof_fw_parse_ext_data(struct snd_sof_dev *sdev, u32 bar, u32 offset) in snd_sof_fw_parse_ext_data() argument
97 return -ENOMEM; in snd_sof_fw_parse_ext_data()
100 snd_sof_dsp_block_read(sdev, bar, offset, ext_data, in snd_sof_fw_parse_ext_data()
104 while (ext_hdr->hdr.cmd == SOF_IPC_FW_READY) { in snd_sof_fw_parse_ext_data()
106 snd_sof_dsp_block_read(sdev, bar, offset + sizeof(*ext_hdr), in snd_sof_fw_parse_ext_data()
108 ext_hdr->hdr.size - sizeof(*ext_hdr)); in snd_sof_fw_parse_ext_data()
110 dev_dbg(sdev->dev, "found ext header type %d size 0x%x\n", in snd_sof_fw_parse_ext_data()
111 ext_hdr->type, ext_hdr->hdr.size); in snd_sof_fw_parse_ext_data()
114 switch (ext_hdr->type) { in snd_sof_fw_parse_ext_data()
127 dev_warn(sdev->dev, "warning: unknown ext header type %d size 0x%x\n", in snd_sof_fw_parse_ext_data()
128 ext_hdr->type, ext_hdr->hdr.size); in snd_sof_fw_parse_ext_data()
134 dev_err(sdev->dev, "error: failed to parse ext data type %d\n", in snd_sof_fw_parse_ext_data()
135 ext_hdr->type); in snd_sof_fw_parse_ext_data()
140 offset += ext_hdr->hdr.size; in snd_sof_fw_parse_ext_data()
141 snd_sof_dsp_block_read(sdev, bar, offset, ext_data, in snd_sof_fw_parse_ext_data()
157 memcpy(&sdev->fw_ready.version, &v->version, sizeof(v->version)); in ext_man_get_fw_version()
158 sdev->fw_ready.flags = v->flags; in ext_man_get_fw_version()
171 return get_ext_windows(sdev, &w->ipc_window.ext_hdr); in ext_man_get_windows()
181 return get_cc_info(sdev, &cc->cc_version.ext_hdr); in ext_man_get_cc_info()
190 if (sdev->first_boot) in ext_man_get_dbg_abi_info()
191 dev_dbg(sdev->dev, in ext_man_get_dbg_abi_info()
193 SOF_ABI_VERSION_MAJOR(dbg_abi->dbg_abi.abi_dbg_version), in ext_man_get_dbg_abi_info()
194 SOF_ABI_VERSION_MINOR(dbg_abi->dbg_abi.abi_dbg_version), in ext_man_get_dbg_abi_info()
195 SOF_ABI_VERSION_PATCH(dbg_abi->dbg_abi.abi_dbg_version)); in ext_man_get_dbg_abi_info()
204 head = (struct sof_ext_man_header *)fw->data; in snd_sof_ext_man_size()
211 if (fw->size < sizeof(*head)) in snd_sof_ext_man_size()
212 return -EINVAL; in snd_sof_ext_man_size()
218 if (head->magic == SOF_EXT_MAN_MAGIC_NUMBER) in snd_sof_ext_man_size()
219 return head->full_size; in snd_sof_ext_man_size()
236 head = (struct sof_ext_man_header *)fw->data; in snd_sof_fw_ext_man_parse()
237 remaining = head->full_size - head->header_size; in snd_sof_fw_ext_man_parse()
246 head->header_version)) { in snd_sof_fw_ext_man_parse()
247 dev_err(sdev->dev, "error: extended manifest version 0x%X differ from used 0x%X\n", in snd_sof_fw_ext_man_parse()
248 head->header_version, SOF_EXT_MAN_VERSION); in snd_sof_fw_ext_man_parse()
249 return -EINVAL; in snd_sof_fw_ext_man_parse()
253 iptr = (uintptr_t)fw->data + head->header_size; in snd_sof_fw_ext_man_parse()
258 dev_dbg(sdev->dev, "found sof_ext_man header type %d size 0x%X\n", in snd_sof_fw_ext_man_parse()
259 elem_hdr->type, elem_hdr->size); in snd_sof_fw_ext_man_parse()
261 if (elem_hdr->size < sizeof(*elem_hdr) || in snd_sof_fw_ext_man_parse()
262 elem_hdr->size > remaining) { in snd_sof_fw_ext_man_parse()
263 dev_err(sdev->dev, "error: invalid sof_ext_man header size, type %d size 0x%X\n", in snd_sof_fw_ext_man_parse()
264 elem_hdr->type, elem_hdr->size); in snd_sof_fw_ext_man_parse()
265 return -EINVAL; in snd_sof_fw_ext_man_parse()
269 switch (elem_hdr->type) { in snd_sof_fw_ext_man_parse()
283 dev_warn(sdev->dev, "warning: unknown sof_ext_man header type %d size 0x%X\n", in snd_sof_fw_ext_man_parse()
284 elem_hdr->type, elem_hdr->size); in snd_sof_fw_ext_man_parse()
289 dev_err(sdev->dev, "error: failed to parse sof_ext_man header type %d size 0x%X\n", in snd_sof_fw_ext_man_parse()
290 elem_hdr->type, elem_hdr->size); in snd_sof_fw_ext_man_parse()
294 remaining -= elem_hdr->size; in snd_sof_fw_ext_man_parse()
295 iptr += elem_hdr->size; in snd_sof_fw_ext_man_parse()
299 dev_err(sdev->dev, "error: sof_ext_man header is inconsistent\n"); in snd_sof_fw_ext_man_parse()
300 return -EINVAL; in snd_sof_fw_ext_man_parse()
324 if (!sdev->info_window) { in sof_get_windows()
325 dev_err(sdev->dev, "error: have no window info\n"); in sof_get_windows()
331 dev_err(sdev->dev, "error: have no bar mapping\n"); in sof_get_windows()
335 for (i = 0; i < sdev->info_window->num_windows; i++) { in sof_get_windows()
336 elem = &sdev->info_window->window[i]; in sof_get_windows()
338 window_offset = snd_sof_dsp_get_window_offset(sdev, elem->id); in sof_get_windows()
340 dev_warn(sdev->dev, "warn: no offset for window %d\n", in sof_get_windows()
341 elem->id); in sof_get_windows()
345 switch (elem->type) { in sof_get_windows()
347 inbox_offset = window_offset + elem->offset; in sof_get_windows()
348 inbox_size = elem->size; in sof_get_windows()
350 sdev->bar[bar] + in sof_get_windows()
352 elem->size, "inbox", in sof_get_windows()
356 outbox_offset = window_offset + elem->offset; in sof_get_windows()
357 outbox_size = elem->size; in sof_get_windows()
359 sdev->bar[bar] + in sof_get_windows()
361 elem->size, "outbox", in sof_get_windows()
366 sdev->bar[bar] + in sof_get_windows()
368 elem->offset, in sof_get_windows()
369 elem->size, "etrace", in sof_get_windows()
373 debug_offset = window_offset + elem->offset; in sof_get_windows()
374 debug_size = elem->size; in sof_get_windows()
376 sdev->bar[bar] + in sof_get_windows()
378 elem->offset, in sof_get_windows()
379 elem->size, "debug", in sof_get_windows()
383 stream_offset = window_offset + elem->offset; in sof_get_windows()
384 stream_size = elem->size; in sof_get_windows()
386 sdev->bar[bar] + in sof_get_windows()
388 elem->size, "stream", in sof_get_windows()
393 sdev->bar[bar] + in sof_get_windows()
395 elem->offset, in sof_get_windows()
396 elem->size, "regs", in sof_get_windows()
400 sdev->dsp_oops_offset = window_offset + elem->offset; in sof_get_windows()
402 sdev->bar[bar] + in sof_get_windows()
404 elem->offset, in sof_get_windows()
405 elem->size, "exception", in sof_get_windows()
409 dev_err(sdev->dev, "error: get illegal window info\n"); in sof_get_windows()
415 dev_err(sdev->dev, "error: get illegal mailbox window\n"); in sof_get_windows()
421 sdev->stream_box.offset = stream_offset; in sof_get_windows()
422 sdev->stream_box.size = stream_size; in sof_get_windows()
424 sdev->debug_box.offset = debug_offset; in sof_get_windows()
425 sdev->debug_box.size = debug_size; in sof_get_windows()
427 dev_dbg(sdev->dev, " mailbox upstream 0x%x - size 0x%x\n", in sof_get_windows()
429 dev_dbg(sdev->dev, " mailbox downstream 0x%x - size 0x%x\n", in sof_get_windows()
431 dev_dbg(sdev->dev, " stream region 0x%x - size 0x%x\n", in sof_get_windows()
433 dev_dbg(sdev->dev, " debug region 0x%x - size 0x%x\n", in sof_get_windows()
440 struct sof_ipc_fw_ready *fw_ready = &sdev->fw_ready; in sof_fw_ready()
441 int offset; in sof_fw_ready() local
446 offset = snd_sof_dsp_get_mailbox_offset(sdev); in sof_fw_ready()
447 if (offset < 0) { in sof_fw_ready()
448 dev_err(sdev->dev, "error: have no mailbox offset\n"); in sof_fw_ready()
449 return offset; in sof_fw_ready()
454 dev_err(sdev->dev, "error: have no bar mapping\n"); in sof_fw_ready()
455 return -EINVAL; in sof_fw_ready()
458 dev_dbg(sdev->dev, "ipc: DSP is ready 0x%8.8x offset 0x%x\n", in sof_fw_ready()
459 msg_id, offset); in sof_fw_ready()
461 /* no need to re-check version/ABI for subsequent boots */ in sof_fw_ready()
462 if (!sdev->first_boot) in sof_fw_ready()
465 /* copy data from the DSP FW ready offset */ in sof_fw_ready()
466 sof_block_read(sdev, bar, offset, fw_ready, sizeof(*fw_ready)); in sof_fw_ready()
474 snd_sof_fw_parse_ext_data(sdev, bar, offset + in sof_fw_ready()
489 u32 offset; in snd_sof_parse_module_memcpy() local
492 dev_dbg(sdev->dev, "new module size 0x%x blocks 0x%x type 0x%x\n", in snd_sof_parse_module_memcpy()
493 module->size, module->num_blocks, module->type); in snd_sof_parse_module_memcpy()
497 /* module->size doesn't include header size */ in snd_sof_parse_module_memcpy()
498 remaining = module->size; in snd_sof_parse_module_memcpy()
499 for (count = 0; count < module->num_blocks; count++) { in snd_sof_parse_module_memcpy()
502 dev_err(sdev->dev, "error: not enough data remaining\n"); in snd_sof_parse_module_memcpy()
503 return -EINVAL; in snd_sof_parse_module_memcpy()
507 remaining -= sizeof(*block); in snd_sof_parse_module_memcpy()
509 if (block->size == 0) { in snd_sof_parse_module_memcpy()
510 dev_warn(sdev->dev, in snd_sof_parse_module_memcpy()
512 dev_warn(sdev->dev, " type 0x%x offset 0x%x\n", in snd_sof_parse_module_memcpy()
513 block->type, block->offset); in snd_sof_parse_module_memcpy()
517 switch (block->type) { in snd_sof_parse_module_memcpy()
524 offset = block->offset; in snd_sof_parse_module_memcpy()
525 bar = snd_sof_dsp_get_bar_index(sdev, block->type); in snd_sof_parse_module_memcpy()
527 dev_err(sdev->dev, in snd_sof_parse_module_memcpy()
528 "error: no BAR mapping for block type 0x%x\n", in snd_sof_parse_module_memcpy()
529 block->type); in snd_sof_parse_module_memcpy()
534 dev_err(sdev->dev, "error: bad type 0x%x for block 0x%x\n", in snd_sof_parse_module_memcpy()
535 block->type, count); in snd_sof_parse_module_memcpy()
536 return -EINVAL; in snd_sof_parse_module_memcpy()
539 dev_dbg(sdev->dev, in snd_sof_parse_module_memcpy()
540 "block %d type 0x%x size 0x%x ==> offset 0x%x\n", in snd_sof_parse_module_memcpy()
541 count, block->type, block->size, offset); in snd_sof_parse_module_memcpy()
543 /* checking block->size to avoid unaligned access */ in snd_sof_parse_module_memcpy()
544 if (block->size % sizeof(u32)) { in snd_sof_parse_module_memcpy()
545 dev_err(sdev->dev, "error: invalid block size 0x%x\n", in snd_sof_parse_module_memcpy()
546 block->size); in snd_sof_parse_module_memcpy()
547 return -EINVAL; in snd_sof_parse_module_memcpy()
549 snd_sof_dsp_block_write(sdev, bar, offset, in snd_sof_parse_module_memcpy()
550 block + 1, block->size); in snd_sof_parse_module_memcpy()
552 if (remaining < block->size) { in snd_sof_parse_module_memcpy()
553 dev_err(sdev->dev, "error: not enough data remaining\n"); in snd_sof_parse_module_memcpy()
554 return -EINVAL; in snd_sof_parse_module_memcpy()
558 remaining -= block->size; in snd_sof_parse_module_memcpy()
561 + block->size); in snd_sof_parse_module_memcpy()
572 size_t fw_size = fw->size - fw_offset; in check_header()
574 if (fw->size <= fw_offset) { in check_header()
575 dev_err(sdev->dev, "error: firmware size must be greater than firmware offset\n"); in check_header()
576 return -EINVAL; in check_header()
580 header = (struct snd_sof_fw_header *)(fw->data + fw_offset); in check_header()
583 if (strncmp(header->sig, SND_SOF_FW_SIG, SND_SOF_FW_SIG_SIZE) != 0) { in check_header()
584 dev_err(sdev->dev, "error: invalid firmware signature\n"); in check_header()
585 return -EINVAL; in check_header()
589 if (fw_size != header->file_size + sizeof(*header)) { in check_header()
590 dev_err(sdev->dev, "error: invalid filesize mismatch got 0x%zx expected 0x%zx\n", in check_header()
591 fw_size, header->file_size + sizeof(*header)); in check_header()
592 return -EINVAL; in check_header()
595 dev_dbg(sdev->dev, "header size=0x%x modules=0x%x abi=0x%x size=%zu\n", in check_header()
596 header->file_size, header->num_modules, in check_header()
597 header->abi, sizeof(*header)); in check_header()
612 header = (struct snd_sof_fw_header *)(fw->data + fw_offset); in load_modules()
613 load_module = sof_ops(sdev)->load_module; in load_modules()
615 return -EINVAL; in load_modules()
618 module = (struct snd_sof_mod_hdr *)(fw->data + fw_offset + in load_modules()
620 remaining = fw->size - sizeof(*header) - fw_offset; in load_modules()
622 if (remaining > fw->size) { in load_modules()
623 dev_err(sdev->dev, "error: fw size smaller than header size\n"); in load_modules()
624 return -EINVAL; in load_modules()
627 for (count = 0; count < header->num_modules; count++) { in load_modules()
630 dev_err(sdev->dev, "error: not enough data remaining\n"); in load_modules()
631 return -EINVAL; in load_modules()
635 remaining -= sizeof(*module); in load_modules()
640 dev_err(sdev->dev, "error: invalid module %d\n", count); in load_modules()
644 if (remaining < module->size) { in load_modules()
645 dev_err(sdev->dev, "error: not enough data remaining\n"); in load_modules()
646 return -EINVAL; in load_modules()
650 remaining -= module->size; in load_modules()
652 + sizeof(*module) + module->size); in load_modules()
660 struct snd_sof_pdata *plat_data = sdev->pdata; in snd_sof_load_firmware_raw()
666 if (plat_data->fw) in snd_sof_load_firmware_raw()
670 plat_data->fw_filename_prefix, in snd_sof_load_firmware_raw()
671 plat_data->fw_filename); in snd_sof_load_firmware_raw()
673 return -ENOMEM; in snd_sof_load_firmware_raw()
675 ret = request_firmware(&plat_data->fw, fw_filename, sdev->dev); in snd_sof_load_firmware_raw()
678 dev_err(sdev->dev, "error: request firmware %s failed err: %d\n", in snd_sof_load_firmware_raw()
682 dev_dbg(sdev->dev, "request_firmware %s successful\n", in snd_sof_load_firmware_raw()
687 ext_man_size = snd_sof_fw_ext_man_parse(sdev, plat_data->fw); in snd_sof_load_firmware_raw()
690 plat_data->fw_offset = ext_man_size; in snd_sof_load_firmware_raw()
693 dev_dbg(sdev->dev, "firmware doesn't contain extended manifest\n"); in snd_sof_load_firmware_raw()
696 dev_err(sdev->dev, "error: firmware %s contains unsupported or invalid extended manifest: %d\n", in snd_sof_load_firmware_raw()
709 struct snd_sof_pdata *plat_data = sdev->pdata; in snd_sof_load_firmware_memcpy()
717 ret = check_header(sdev, plat_data->fw, plat_data->fw_offset); in snd_sof_load_firmware_memcpy()
719 dev_err(sdev->dev, "error: invalid FW header\n"); in snd_sof_load_firmware_memcpy()
726 dev_err(sdev->dev, "error: failed to reset DSP\n"); in snd_sof_load_firmware_memcpy()
731 ret = load_modules(sdev, plat_data->fw, plat_data->fw_offset); in snd_sof_load_firmware_memcpy()
733 dev_err(sdev->dev, "error: invalid FW modules\n"); in snd_sof_load_firmware_memcpy()
740 release_firmware(plat_data->fw); in snd_sof_load_firmware_memcpy()
741 plat_data->fw = NULL; in snd_sof_load_firmware_memcpy()
749 dev_dbg(sdev->dev, "loading firmware\n"); in snd_sof_load_firmware()
751 if (sof_ops(sdev)->load_firmware) in snd_sof_load_firmware()
752 return sof_ops(sdev)->load_firmware(sdev); in snd_sof_load_firmware()
762 init_waitqueue_head(&sdev->boot_wait); in snd_sof_run_firmware()
764 /* create read-only fw_version debugfs to store boot version info */ in snd_sof_run_firmware()
765 if (sdev->first_boot) { in snd_sof_run_firmware()
766 ret = snd_sof_debugfs_buf_item(sdev, &sdev->fw_version, in snd_sof_run_firmware()
767 sizeof(sdev->fw_version), in snd_sof_run_firmware()
771 dev_err(sdev->dev, "error: snd_sof_debugfs_buf_item failed\n"); in snd_sof_run_firmware()
779 dev_err(sdev->dev, "error: failed pre fw run op\n"); in snd_sof_run_firmware()
783 dev_dbg(sdev->dev, "booting DSP firmware\n"); in snd_sof_run_firmware()
788 dev_err(sdev->dev, "error: failed to reset DSP\n"); in snd_sof_run_firmware()
800 ret = wait_event_timeout(sdev->boot_wait, in snd_sof_run_firmware()
801 sdev->fw_state > SOF_FW_BOOT_IN_PROGRESS, in snd_sof_run_firmware()
802 msecs_to_jiffies(sdev->boot_timeout)); in snd_sof_run_firmware()
804 dev_err(sdev->dev, "error: firmware boot failure\n"); in snd_sof_run_firmware()
807 sdev->fw_state = SOF_FW_BOOT_FAILED; in snd_sof_run_firmware()
808 return -EIO; in snd_sof_run_firmware()
811 if (sdev->fw_state == SOF_FW_BOOT_COMPLETE) in snd_sof_run_firmware()
812 dev_dbg(sdev->dev, "firmware boot complete\n"); in snd_sof_run_firmware()
814 return -EIO; /* FW boots but fw_ready op failed */ in snd_sof_run_firmware()
819 dev_err(sdev->dev, "error: failed post fw run op\n"); in snd_sof_run_firmware()
824 sdev->enabled_cores_mask = init_core_mask; in snd_sof_run_firmware()