1ed81f3ebSSandrine Bailleux /* 29edac047SDavid Cunado * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved. 3ed81f3ebSSandrine Bailleux * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 5ed81f3ebSSandrine Bailleux */ 6ed81f3ebSSandrine Bailleux 7ed81f3ebSSandrine Bailleux #ifndef __UTILS_H__ 8ed81f3ebSSandrine Bailleux #define __UTILS_H__ 9ed81f3ebSSandrine Bailleux 1053d9c9c8SScott Branden #if !ERROR_DEPRECATED 1153d9c9c8SScott Branden #include <utils_def.h> 129edac047SDavid Cunado #endif 139edac047SDavid Cunado 14308d359bSDouglas Raillard /* 15308d359bSDouglas Raillard * C code should be put in this part of the header to avoid breaking ASM files 16308d359bSDouglas Raillard * or linker scripts including it. 17308d359bSDouglas Raillard */ 18308d359bSDouglas Raillard #if !(defined(__LINKER__) || defined(__ASSEMBLY__)) 19308d359bSDouglas Raillard 20308d359bSDouglas Raillard #include <types.h> 21308d359bSDouglas Raillard 22*43cbaf06SRoberto Vargas typedef struct mem_region_t { 23*43cbaf06SRoberto Vargas uintptr_t base; 24*43cbaf06SRoberto Vargas size_t nbytes; 25*43cbaf06SRoberto Vargas } mem_region_t; 26*43cbaf06SRoberto Vargas 27*43cbaf06SRoberto Vargas /* 28*43cbaf06SRoberto Vargas * zero_normalmem all the regions defined in tbl. 29*43cbaf06SRoberto Vargas */ 30*43cbaf06SRoberto Vargas void clear_mem_regions(mem_region_t *tbl, size_t nregions); 31*43cbaf06SRoberto Vargas 32*43cbaf06SRoberto Vargas 33*43cbaf06SRoberto Vargas /* 34*43cbaf06SRoberto Vargas * checks that a region (addr + nbytes-1) of memory is totally covered by 35*43cbaf06SRoberto Vargas * one of the regions defined in tbl. Caller must ensure that (addr+nbytes-1) 36*43cbaf06SRoberto Vargas * doesn't overflow. 37*43cbaf06SRoberto Vargas */ 38*43cbaf06SRoberto Vargas int mem_region_in_array_chk(mem_region_t *tbl, size_t nregions, 39*43cbaf06SRoberto Vargas uintptr_t addr, size_t nbytes); 40*43cbaf06SRoberto Vargas 41308d359bSDouglas Raillard /* 42308d359bSDouglas Raillard * Fill a region of normal memory of size "length" in bytes with zero bytes. 43308d359bSDouglas Raillard * 44308d359bSDouglas Raillard * WARNING: This function can only operate on normal memory. This means that 45308d359bSDouglas Raillard * the MMU must be enabled when using this function. Otherwise, use 46308d359bSDouglas Raillard * zeromem. 47308d359bSDouglas Raillard */ 48308d359bSDouglas Raillard void zero_normalmem(void *mem, u_register_t length); 49308d359bSDouglas Raillard 50308d359bSDouglas Raillard /* 51308d359bSDouglas Raillard * Fill a region of memory of size "length" in bytes with null bytes. 52308d359bSDouglas Raillard * 53308d359bSDouglas Raillard * Unlike zero_normalmem, this function has no restriction on the type of 54308d359bSDouglas Raillard * memory targeted and can be used for any device memory as well as normal 55308d359bSDouglas Raillard * memory. This function must be used instead of zero_normalmem when MMU is 56308d359bSDouglas Raillard * disabled. 57308d359bSDouglas Raillard * 58308d359bSDouglas Raillard * NOTE: When data cache and MMU are enabled, prefer zero_normalmem for faster 59308d359bSDouglas Raillard * zeroing. 60308d359bSDouglas Raillard */ 61308d359bSDouglas Raillard void zeromem(void *mem, u_register_t length); 62308d359bSDouglas Raillard #endif /* !(defined(__LINKER__) || defined(__ASSEMBLY__)) */ 63308d359bSDouglas Raillard 64ed81f3ebSSandrine Bailleux #endif /* __UTILS_H__ */ 65