diff options
author | Gerald Van Baren <vanbaren@cideas.com> | 2007-04-14 22:46:41 -0400 |
---|---|---|
committer | Gerald Van Baren <vanbaren@cideas.com> | 2007-04-14 22:46:41 -0400 |
commit | 3f9f08cf91c8a6949a5d78a18bd3d8df7b86d888 (patch) | |
tree | 1b8be22f97b41128b210f98dc0262d606ce56913 /libfdt | |
parent | 64dbbd40c58349b64f43fd33dbb5ca0adb67d642 (diff) | |
download | u-boot-3f9f08cf91c8a6949a5d78a18bd3d8df7b86d888.tar.gz u-boot-3f9f08cf91c8a6949a5d78a18bd3d8df7b86d888.tar.bz2 u-boot-3f9f08cf91c8a6949a5d78a18bd3d8df7b86d888.zip |
Add some utilities to manipulate the reserved memory map.
Diffstat (limited to 'libfdt')
-rw-r--r-- | libfdt/fdt_ro.c | 72 | ||||
-rw-r--r-- | libfdt/fdt_wip.c | 26 |
2 files changed, 98 insertions, 0 deletions
diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c index 2711324870..af33336869 100644 --- a/libfdt/fdt_ro.c +++ b/libfdt/fdt_ro.c @@ -329,3 +329,75 @@ uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset, char **namep return tag; } + +/* + * Return the number of used reserve map entries and total slots available. + */ +int fdt_num_reservemap(void *fdt, int *used, int *total) +{ + struct fdt_reserve_entry *re; + int start; + int end; + int err = fdt_check_header(fdt); + + if (err != 0) + return err; + + start = fdt_off_mem_rsvmap(fdt); + + /* + * Convention is that the reserve map is before the dt_struct, + * but it does not have to be. + */ + end = fdt_totalsize(fdt); + if (end > fdt_off_dt_struct(fdt)) + end = fdt_off_dt_struct(fdt); + if (end > fdt_off_dt_strings(fdt)) + end = fdt_off_dt_strings(fdt); + + /* + * Since the reserved area list is zero terminated, you get one fewer. + */ + if (total) + *total = ((end - start) / sizeof(struct fdt_reserve_entry)) - 1; + + if (used) { + *used = 0; + while (start < end) { + re = (struct fdt_reserve_entry *)(fdt + start); + if (re->size == 0) + return 0; /* zero size terminates the list */ + + *used += 1; + start += sizeof(struct fdt_reserve_entry); + } + /* + * If we get here, there was no zero size termination. + */ + return -FDT_ERR_BADLAYOUT; + } + return 0; +} + +/* + * Return the nth reserve map entry. + */ +int fdt_get_reservemap(void *fdt, int n, struct fdt_reserve_entry *re) +{ + int used; + int total; + int err; + + err = fdt_num_reservemap(fdt, &used, &total); + if (err != 0) + return err; + + if (n >= total) + return -FDT_ERR_NOSPACE; + if (re) { + *re = *(struct fdt_reserve_entry *) + _fdt_offset_ptr(fdt, n * sizeof(struct fdt_reserve_entry)); + } + return 0; +} + diff --git a/libfdt/fdt_wip.c b/libfdt/fdt_wip.c index 261b9b0dc9..cf811830a7 100644 --- a/libfdt/fdt_wip.c +++ b/libfdt/fdt_wip.c @@ -110,3 +110,29 @@ int fdt_nop_node(void *fdt, int nodeoffset) nop_region(fdt_offset_ptr(fdt, nodeoffset, 0), endoffset - nodeoffset); return 0; } + +/* + * Replace a reserve map entry in the nth slot. + */ +int fdt_replace_reservemap_entry(void *fdt, int n, uint64_t addr, uint64_t size) +{ + struct fdt_reserve_entry *re; + int used; + int total; + int err; + + err = fdt_num_reservemap(fdt, &used, &total); + if (err != 0) + return err; + + if (n >= total) + return -FDT_ERR_NOSPACE; + re = (struct fdt_reserve_entry *) + (fdt + fdt_off_mem_rsvmap(fdt) + + (n * sizeof(struct fdt_reserve_entry))); + re->address = cpu_to_fdt64(addr); + re->size = cpu_to_fdt64(size); + + return 0; +} + |