drivers/remoteproc/remoteproc_elf_loader.c
Source file repositories/reference/linux-study-clean/drivers/remoteproc/remoteproc_elf_loader.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/remoteproc/remoteproc_elf_loader.c- Extension
.c- Size
- 11349 bytes
- Lines
- 396
- Domain
- Driver Families
- Bucket
- drivers/remoteproc
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/firmware.hlinux/remoteproc.hlinux/elf.hremoteproc_internal.hremoteproc_elf_helpers.h
Detected Declarations
function Copyrightfunction rproc_elf_get_boot_addrfunction rproc_elf_load_segmentsfunction find_tablefunction rproc_elf_load_rsc_tablefunction rproc_elf_find_loaded_rsc_tableexport rproc_elf_sanity_checkexport rproc_elf_get_boot_addrexport rproc_elf_load_segmentsexport rproc_elf_load_rsc_tableexport rproc_elf_find_loaded_rsc_table
Annotated Snippet
if (filesz > memsz) {
dev_err(dev, "bad phdr filesz 0x%llx memsz 0x%llx\n",
filesz, memsz);
ret = -EINVAL;
break;
}
if (offset + filesz > fw->size) {
dev_err(dev, "truncated fw: need 0x%llx avail 0x%zx\n",
offset + filesz, fw->size);
ret = -EINVAL;
break;
}
if (!rproc_u64_fit_in_size_t(memsz)) {
dev_err(dev, "size (%llx) does not fit in size_t type\n",
memsz);
ret = -EOVERFLOW;
break;
}
/* grab the kernel address for this device address */
ptr = rproc_da_to_va(rproc, da, memsz, &is_iomem);
if (!ptr) {
dev_err(dev, "bad phdr da 0x%llx mem 0x%llx\n", da,
memsz);
ret = -EINVAL;
break;
}
/* put the segment where the remote processor expects it */
if (filesz) {
if (is_iomem)
memcpy_toio((void __iomem *)ptr, elf_data + offset, filesz);
else
memcpy(ptr, elf_data + offset, filesz);
}
/*
* Zero out remaining memory for this segment.
*
* This isn't strictly required since dma_alloc_coherent already
* did this for us. albeit harmless, we may consider removing
* this.
*/
if (memsz > filesz) {
if (is_iomem)
memset_io((void __iomem *)(ptr + filesz), 0, memsz - filesz);
else
memset(ptr + filesz, 0, memsz - filesz);
}
}
return ret;
}
EXPORT_SYMBOL(rproc_elf_load_segments);
static const void *
find_table(struct device *dev, const struct firmware *fw)
{
const void *shdr, *name_table_shdr;
int i;
const char *name_table;
struct resource_table *table = NULL;
const u8 *elf_data = (void *)fw->data;
u8 class = fw_elf_get_class(fw);
size_t fw_size = fw->size;
const void *ehdr = elf_data;
u16 shnum = elf_hdr_get_e_shnum(class, ehdr);
u32 elf_shdr_get_size = elf_size_of_shdr(class);
u16 shstrndx = elf_hdr_get_e_shstrndx(class, ehdr);
/* look for the resource table and handle it */
/* First, get the section header according to the elf class */
shdr = elf_data + elf_hdr_get_e_shoff(class, ehdr);
/* Compute name table section header entry in shdr array */
name_table_shdr = shdr + (shstrndx * elf_shdr_get_size);
/* Finally, compute the name table section address in elf */
name_table = elf_data + elf_shdr_get_sh_offset(class, name_table_shdr);
for (i = 0; i < shnum; i++, shdr += elf_shdr_get_size) {
u64 size = elf_shdr_get_sh_size(class, shdr);
u64 offset = elf_shdr_get_sh_offset(class, shdr);
u32 name = elf_shdr_get_sh_name(class, shdr);
if (strcmp(name_table + name, ".resource_table"))
continue;
table = (struct resource_table *)(elf_data + offset);
Annotation
- Immediate include surface: `linux/module.h`, `linux/firmware.h`, `linux/remoteproc.h`, `linux/elf.h`, `remoteproc_internal.h`, `remoteproc_elf_helpers.h`.
- Detected declarations: `function Copyright`, `function rproc_elf_get_boot_addr`, `function rproc_elf_load_segments`, `function find_table`, `function rproc_elf_load_rsc_table`, `function rproc_elf_find_loaded_rsc_table`, `export rproc_elf_sanity_check`, `export rproc_elf_get_boot_addr`, `export rproc_elf_load_segments`, `export rproc_elf_load_rsc_table`.
- Atlas domain: Driver Families / drivers/remoteproc.
- Implementation status: integration implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.