Skip to content

Commit c745714

Browse files
MrVanmathieupoirier
authored andcommitted
remoteproc: imx_dsp_rproc: use common rproc_elf_load_segments
remoteproc elf loader supports the specific case that segments have PT_LOAD and memsz/filesz set to zero, so no duplicate code. Acked-by: Daniel Baluta <[email protected]> Signed-off-by: Peng Fan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mathieu Poirier <[email protected]>
1 parent f340d5a commit c745714

File tree

1 file changed

+1
-94
lines changed

1 file changed

+1
-94
lines changed

drivers/remoteproc/imx_dsp_rproc.c

Lines changed: 1 addition & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -649,99 +649,6 @@ static int imx_dsp_rproc_add_carveout(struct imx_dsp_rproc *priv)
649649
return 0;
650650
}
651651

652-
/**
653-
* imx_dsp_rproc_elf_load_segments() - load firmware segments to memory
654-
* @rproc: remote processor which will be booted using these fw segments
655-
* @fw: the ELF firmware image
656-
*
657-
* This function specially checks if memsz is zero or not, otherwise it
658-
* is mostly same as rproc_elf_load_segments().
659-
*/
660-
static int imx_dsp_rproc_elf_load_segments(struct rproc *rproc,
661-
const struct firmware *fw)
662-
{
663-
struct device *dev = &rproc->dev;
664-
u8 class = fw_elf_get_class(fw);
665-
u32 elf_phdr_get_size = elf_size_of_phdr(class);
666-
const u8 *elf_data = fw->data;
667-
const void *ehdr, *phdr;
668-
int i, ret = 0;
669-
u16 phnum;
670-
671-
ehdr = elf_data;
672-
phnum = elf_hdr_get_e_phnum(class, ehdr);
673-
phdr = elf_data + elf_hdr_get_e_phoff(class, ehdr);
674-
675-
/* go through the available ELF segments */
676-
for (i = 0; i < phnum; i++, phdr += elf_phdr_get_size) {
677-
u64 da = elf_phdr_get_p_paddr(class, phdr);
678-
u64 memsz = elf_phdr_get_p_memsz(class, phdr);
679-
u64 filesz = elf_phdr_get_p_filesz(class, phdr);
680-
u64 offset = elf_phdr_get_p_offset(class, phdr);
681-
u32 type = elf_phdr_get_p_type(class, phdr);
682-
void *ptr;
683-
684-
/*
685-
* There is a case that with PT_LOAD type, the
686-
* filesz = memsz = 0. If memsz = 0, rproc_da_to_va
687-
* should return NULL ptr, then error is returned.
688-
* So this case should be skipped from the loop.
689-
* Add !memsz checking here.
690-
*/
691-
if (type != PT_LOAD || !memsz)
692-
continue;
693-
694-
dev_dbg(dev, "phdr: type %d da 0x%llx memsz 0x%llx filesz 0x%llx\n",
695-
type, da, memsz, filesz);
696-
697-
if (filesz > memsz) {
698-
dev_err(dev, "bad phdr filesz 0x%llx memsz 0x%llx\n",
699-
filesz, memsz);
700-
ret = -EINVAL;
701-
break;
702-
}
703-
704-
if (offset + filesz > fw->size) {
705-
dev_err(dev, "truncated fw: need 0x%llx avail 0x%zx\n",
706-
offset + filesz, fw->size);
707-
ret = -EINVAL;
708-
break;
709-
}
710-
711-
if (!rproc_u64_fit_in_size_t(memsz)) {
712-
dev_err(dev, "size (%llx) does not fit in size_t type\n",
713-
memsz);
714-
ret = -EOVERFLOW;
715-
break;
716-
}
717-
718-
/* grab the kernel address for this device address */
719-
ptr = rproc_da_to_va(rproc, da, memsz, NULL);
720-
if (!ptr) {
721-
dev_err(dev, "bad phdr da 0x%llx mem 0x%llx\n", da,
722-
memsz);
723-
ret = -EINVAL;
724-
break;
725-
}
726-
727-
/* put the segment where the remote processor expects it */
728-
if (filesz)
729-
memcpy(ptr, elf_data + offset, filesz);
730-
731-
/*
732-
* Zero out remaining memory for this segment.
733-
*
734-
* This isn't strictly required since dma_alloc_coherent already
735-
* did this for us. albeit harmless, we may consider removing
736-
* this.
737-
*/
738-
if (memsz > filesz)
739-
memset(ptr + filesz, 0, memsz - filesz);
740-
}
741-
742-
return ret;
743-
}
744-
745652
/* Prepare function for rproc_ops */
746653
static int imx_dsp_rproc_prepare(struct rproc *rproc)
747654
{
@@ -808,7 +715,7 @@ static const struct rproc_ops imx_dsp_rproc_ops = {
808715
.start = imx_dsp_rproc_start,
809716
.stop = imx_dsp_rproc_stop,
810717
.kick = imx_dsp_rproc_kick,
811-
.load = imx_dsp_rproc_elf_load_segments,
718+
.load = rproc_elf_load_segments,
812719
.parse_fw = rproc_elf_load_rsc_table,
813720
.sanity_check = rproc_elf_sanity_check,
814721
.get_boot_addr = rproc_elf_get_boot_addr,

0 commit comments

Comments
 (0)