From 43cbaf061587e7e8b3529e4b1d30de3ab1b52d3e Mon Sep 17 00:00:00 2001 From: Roberto Vargas Date: Thu, 3 Aug 2017 08:56:38 +0100 Subject: Add mem_region utility functions This commit introduces a new type (mem_region_t) used to describe memory regions and it adds two utility functions: - clear_mem_regions: This function clears (write 0) to a set of regions described with an array of mem_region_t. - mem_region_in_array_chk This function checks if a region is covered by some of the regions described with an array of mem_region_t. Change-Id: I12ce549f5e81dd15ac0981645f6e08ee7c120811 Signed-off-by: Roberto Vargas --- include/lib/utils.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'include/lib/utils.h') diff --git a/include/lib/utils.h b/include/lib/utils.h index b75813f7..cfc83022 100644 --- a/include/lib/utils.h +++ b/include/lib/utils.h @@ -19,6 +19,25 @@ #include +typedef struct mem_region_t { + uintptr_t base; + size_t nbytes; +} mem_region_t; + +/* + * zero_normalmem all the regions defined in tbl. + */ +void clear_mem_regions(mem_region_t *tbl, size_t nregions); + + +/* + * checks that a region (addr + nbytes-1) of memory is totally covered by + * one of the regions defined in tbl. Caller must ensure that (addr+nbytes-1) + * doesn't overflow. + */ +int mem_region_in_array_chk(mem_region_t *tbl, size_t nregions, + uintptr_t addr, size_t nbytes); + /* * Fill a region of normal memory of size "length" in bytes with zero bytes. * -- cgit v1.2.3