From 6679f9299534e488a171a9bb8f9bb891de247aab Mon Sep 17 00:00:00 2001 From: Gerald Van Baren Date: Fri, 6 Apr 2007 14:17:14 -0400 Subject: libfdt: Make fdt_check_header() public Changed _fdt_check_header() to fdt_check_header() and made it part of the interface - it is a useful routine. Also did some asthetics cleanup to the include files (headers). --- libfdt/fdt_ro.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libfdt/fdt_ro.c') diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c index ce01dc7..2711324 100644 --- a/libfdt/fdt_ro.c +++ b/libfdt/fdt_ro.c @@ -25,7 +25,7 @@ #define CHECK_HEADER(fdt) { \ int err; \ - if ((err = _fdt_check_header(fdt)) != 0) \ + if ((err = fdt_check_header(fdt)) != 0) \ return err; \ } @@ -188,7 +188,7 @@ struct fdt_property *fdt_get_property(const void *fdt, int offset, nextoffset; int err; - if ((err = _fdt_check_header(fdt)) != 0) + if ((err = fdt_check_header(fdt)) != 0) goto fail; err = -FDT_ERR_BADOFFSET; -- cgit v1.1 From 3f9f08cf91c8a6949a5d78a18bd3d8df7b86d888 Mon Sep 17 00:00:00 2001 From: Gerald Van Baren Date: Sat, 14 Apr 2007 22:46:41 -0400 Subject: Add some utilities to manipulate the reserved memory map. --- libfdt/fdt_ro.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'libfdt/fdt_ro.c') diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c index 2711324..af33336 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; +} + -- cgit v1.1 From 37837828d89084879bee2f2b8c7c68d4695940df Mon Sep 17 00:00:00 2001 From: Wolfgang Denk Date: Wed, 18 Apr 2007 17:49:29 +0200 Subject: Clenaup, update CHANGELOG Signed-off-by: Wolfgang Denk --- libfdt/fdt_ro.c | 1 - 1 file changed, 1 deletion(-) (limited to 'libfdt/fdt_ro.c') diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c index af33336..4e2c325 100644 --- a/libfdt/fdt_ro.c +++ b/libfdt/fdt_ro.c @@ -400,4 +400,3 @@ int fdt_get_reservemap(void *fdt, int n, struct fdt_reserve_entry *re) } return 0; } - -- cgit v1.1