static size_t remove_reserved_memory( const void *fdt, Heap_Area *areas, size_t area_count ) { int node; node = fdt_path_offset_namelen( fdt, reserved_memory_path, (int) sizeof(reserved_memory_path) - 1 ); if (node >= 0) { node = fdt_first_subnode(fdt, node); while (node >= 0) { int len; const void *val; uintptr_t area_begin; uintptr_t area_end; uintptr_t hole_begin; uintptr_t hole_end; Heap_Area *area; val = fdt_getprop(fdt, node, "reg", &len); if (len == 8) { hole_begin = fdt32_to_cpu(((fdt32_t *) val)[0]); hole_end = hole_begin + fdt32_to_cpu(((fdt32_t *) val)[1]); } else { rtems_panic("unexpected reserved memory area"); } area = find_area(areas, area_count, hole_begin); area_begin = (uintptr_t) area->begin; area_end = area_begin + (uintptr_t) area->size; area->size = hole_begin - area_begin; if (hole_end <= area_end) { if (area_count >= AREA_COUNT_MAX) { rtems_panic("too many reserved memory areas"); } area = &areas[area_count]; ++area_count; area->begin = (void *) hole_end; area->size = area_end - hole_end; } node = fdt_next_subnode(fdt, node); } } return area_count; }
static void adjust_memory_size(const void *fdt, Heap_Area *area) { int node; node = fdt_path_offset_namelen( fdt, memory_path, (int) sizeof(memory_path) - 1 ); if (node >= 0) { int len; const void *val; uintptr_t begin; uintptr_t size; uintptr_t a_bit; val = fdt_getprop(fdt, node, "reg", &len); if (len == 8) { begin = fdt32_to_cpu(((fdt32_t *) val)[0]); size = fdt32_to_cpu(((fdt32_t *) val)[1]); } else { begin = 0; size = 0; } /* * Remove a bit to avoid problems with speculative memory accesses beyond * the valid memory area. */ a_bit = 0x100000; if (size >= a_bit) { size -= a_bit; } if ( begin == 0 && size > (uintptr_t) bsp_section_work_end && (uintptr_t) bsp_section_nocache_end < (uintptr_t) bsp_section_work_end ) { area->size += size - (uintptr_t) bsp_section_work_end; } } }
static void check_path_offset_namelen(void *fdt, char *path, int namelen, int offset) { int rc; verbose_printf("Checking offset of \"%s\" [first %d characters]" " is %d...\n", path, namelen, offset); rc = fdt_path_offset_namelen(fdt, path, namelen); if (rc == offset) return; if (rc < 0) FAIL("fdt_path_offset_namelen(\"%s\", %d) failed: %s", path, namelen, fdt_strerror(rc)); else FAIL("fdt_path_offset_namelen(\"%s\", %d) returned incorrect" " offset %d instead of %d", path, namelen, rc, offset); }
int fdt_path_offset(const void *fdt, const char *path) { return fdt_path_offset_namelen(fdt, path, strlen(path)); }