void _fdt_fill_device_info(void *fdt, struct dt_node_info *info, int offs) { struct dt_node_info dinfo = { .reg = DT_INFO_INVALID_REG, .clock = DT_INFO_INVALID_CLOCK, .reset = DT_INFO_INVALID_RESET, }; const fdt32_t *cuint; dinfo.reg = _fdt_reg_base_address(fdt, offs); cuint = fdt_getprop(fdt, offs, "clocks", NULL); if (cuint) { cuint++; dinfo.clock = (int)fdt32_to_cpu(*cuint); } cuint = fdt_getprop(fdt, offs, "resets", NULL); if (cuint) { cuint++; dinfo.reset = (int)fdt32_to_cpu(*cuint); } dinfo.status = _fdt_get_status(fdt, offs); *info = dinfo; }
int dt_map_dev(const void *fdt, int offs, vaddr_t *base, size_t *size) { enum teecore_memtypes mtype; paddr_t pbase; vaddr_t vbase; ssize_t sz; int st; assert(cpu_mmu_enabled()); st = _fdt_get_status(fdt, offs); if (st == DT_STATUS_DISABLED) return -1; pbase = _fdt_reg_base_address(fdt, offs); if (pbase == (paddr_t)-1) return -1; sz = _fdt_reg_size(fdt, offs); if (sz < 0) return -1; if ((st & DT_STATUS_OK_SEC) && !(st & DT_STATUS_OK_NSEC)) mtype = MEM_AREA_IO_SEC; else mtype = MEM_AREA_IO_NSEC; /* Check if we have a mapping, create one if needed */ if (!core_mmu_add_mapping(mtype, pbase, sz)) { EMSG("Failed to map %zu bytes at PA 0x%"PRIxPA, (size_t)sz, pbase); return -1; } vbase = (vaddr_t)phys_to_virt(pbase, mtype); if (!vbase) { EMSG("Failed to get VA for PA 0x%"PRIxPA, pbase); return -1; } *base = vbase; *size = sz; return 0; }