Lines Matching +full:class +full:- +full:d
1 // SPDX-License-Identifier: GPL-2.0-only
8 * Ohad Ben-Cohen <ohad@wizery.com>
12 * Suman Anna <s-anna@ti.com>
29 * rproc_elf_sanity_check() - Sanity Check for ELF32/ELF64 firmware image
35 * Return: 0 on success and -EINVAL upon any failure
39 const char *name = rproc->firmware;
40 struct device *dev = &rproc->dev;
49 char class; local
54 return -EINVAL;
57 if (fw->size < sizeof(struct elf32_hdr)) {
59 return -EINVAL;
62 ehdr = (struct elf32_hdr *)fw->data;
64 if (memcmp(ehdr->e_ident, ELFMAG, SELFMAG)) {
66 return -EINVAL;
69 class = ehdr->e_ident[EI_CLASS];
70 if (class != ELFCLASS32 && class != ELFCLASS64) {
71 dev_err(dev, "Unsupported class: %d\n", class);
72 return -EINVAL;
75 if (class == ELFCLASS64 && fw->size < sizeof(struct elf64_hdr)) {
77 return -EINVAL;
82 if (ehdr->e_ident[EI_DATA] != ELFDATA2LSB) {
84 if (ehdr->e_ident[EI_DATA] != ELFDATA2MSB) {
87 return -EINVAL;
90 phoff = elf_hdr_get_e_phoff(class, fw->data);
91 shoff = elf_hdr_get_e_shoff(class, fw->data);
92 phnum = elf_hdr_get_e_phnum(class, fw->data);
93 elf_shdr_get_size = elf_size_of_shdr(class);
95 if (fw->size < shoff + elf_shdr_get_size) {
97 return -EINVAL;
102 return -EINVAL;
105 if (phoff > fw->size) {
107 return -EINVAL;
110 dev_dbg(dev, "Firmware is an elf%d file\n",
111 class == ELFCLASS32 ? 32 : 64);
118 * rproc_elf_get_boot_addr() - Get rproc's boot address.
123 * processors. Some will always boot at a specific hard-coded address.
130 return elf_hdr_get_e_entry(fw_elf_get_class(fw), fw->data);
135 * rproc_elf_load_segments() - load firmware segments to memory
162 struct device *dev = &rproc->dev;
166 const u8 *elf_data = fw->data;
167 u8 class = fw_elf_get_class(fw); local
168 u32 elf_phdr_get_size = elf_size_of_phdr(class);
171 phnum = elf_hdr_get_e_phnum(class, ehdr);
172 phdr = elf_data + elf_hdr_get_e_phoff(class, ehdr);
176 u64 da = elf_phdr_get_p_paddr(class, phdr);
177 u64 memsz = elf_phdr_get_p_memsz(class, phdr);
178 u64 filesz = elf_phdr_get_p_filesz(class, phdr);
179 u64 offset = elf_phdr_get_p_offset(class, phdr);
180 u32 type = elf_phdr_get_p_type(class, phdr);
187 dev_dbg(dev, "phdr: type %d da 0x%llx memsz 0x%llx filesz 0x%llx\n",
193 ret = -EINVAL;
197 if (offset + filesz > fw->size) {
199 offset + filesz, fw->size);
200 ret = -EINVAL;
207 ret = -EOVERFLOW;
216 ret = -EINVAL;
237 memset_io((void __iomem *)(ptr + filesz), 0, memsz - filesz);
239 memset(ptr + filesz, 0, memsz - filesz);
254 const u8 *elf_data = (void *)fw->data;
255 u8 class = fw_elf_get_class(fw); local
256 size_t fw_size = fw->size;
258 u16 shnum = elf_hdr_get_e_shnum(class, ehdr);
259 u32 elf_shdr_get_size = elf_size_of_shdr(class);
260 u16 shstrndx = elf_hdr_get_e_shstrndx(class, ehdr);
263 /* First, get the section header according to the elf class */
264 shdr = elf_data + elf_hdr_get_e_shoff(class, ehdr);
268 name_table = elf_data + elf_shdr_get_sh_offset(class, name_table_shdr);
271 u64 size = elf_shdr_get_sh_size(class, shdr);
272 u64 offset = elf_shdr_get_sh_offset(class, shdr);
273 u32 name = elf_shdr_get_sh_name(class, shdr);
288 dev_err(dev, "header-less resource table\n");
293 if (table->ver != 1) {
294 dev_err(dev, "unsupported fw ver: %d\n", table->ver);
299 if (table->reserved[0] || table->reserved[1]) {
305 if (struct_size(table, offset, table->num) > size) {
317 * rproc_elf_load_rsc_table() - load the resource table
329 struct device *dev = &rproc->dev;
331 const u8 *elf_data = fw->data;
333 u8 class = fw_elf_get_class(fw); local
338 return -EINVAL;
340 sh_offset = elf_shdr_get_sh_offset(class, shdr);
342 tablesz = elf_shdr_get_sh_size(class, shdr);
350 rproc->cached_table = kmemdup(table, tablesz, GFP_KERNEL);
351 if (!rproc->cached_table)
352 return -ENOMEM;
354 rproc->table_ptr = rproc->cached_table;
355 rproc->table_sz = tablesz;
362 * rproc_elf_find_loaded_rsc_table() - find the loaded resource table
367 * call this function if the table wasn't loaded yet - it's a bug if you do.
377 u8 class = fw_elf_get_class(fw); local
378 struct device *dev = &rproc->dev;
380 shdr = find_table(&rproc->dev, fw);
384 sh_addr = elf_shdr_get_sh_addr(class, shdr);
385 sh_size = elf_shdr_get_sh_size(class, shdr);