1ed81f3ebSSandrine Bailleux /* 2*638b034cSRoberto Vargas * Copyright (c) 2016-2018, 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 22109ae263SMasahiro Yamada typedef struct mem_region { 2343cbaf06SRoberto Vargas uintptr_t base; 2443cbaf06SRoberto Vargas size_t nbytes; 2543cbaf06SRoberto Vargas } mem_region_t; 2643cbaf06SRoberto Vargas 2743cbaf06SRoberto Vargas /* 2843cbaf06SRoberto Vargas * zero_normalmem all the regions defined in tbl. 2943cbaf06SRoberto Vargas */ 3043cbaf06SRoberto Vargas void clear_mem_regions(mem_region_t *tbl, size_t nregions); 3143cbaf06SRoberto Vargas 32*638b034cSRoberto Vargas /* 33*638b034cSRoberto Vargas * zero_normalmem all the regions defined in region. It dynamically 34*638b034cSRoberto Vargas * maps chunks of 'chunk_size' in 'va' virtual address and clears them. 35*638b034cSRoberto Vargas * For this reason memory regions must be multiple of chunk_size and 36*638b034cSRoberto Vargas * must be aligned to it as well. chunk_size and va can be selected 37*638b034cSRoberto Vargas * in a way that they minimize the number of entries used in the 38*638b034cSRoberto Vargas * translation tables. 39*638b034cSRoberto Vargas */ 40*638b034cSRoberto Vargas void clear_map_dyn_mem_regions(mem_region_t *region, 41*638b034cSRoberto Vargas size_t nregions, 42*638b034cSRoberto Vargas uintptr_t va, 43*638b034cSRoberto Vargas size_t chunk_size); 4443cbaf06SRoberto Vargas 4543cbaf06SRoberto Vargas /* 4643cbaf06SRoberto Vargas * checks that a region (addr + nbytes-1) of memory is totally covered by 4743cbaf06SRoberto Vargas * one of the regions defined in tbl. Caller must ensure that (addr+nbytes-1) 4843cbaf06SRoberto Vargas * doesn't overflow. 4943cbaf06SRoberto Vargas */ 5043cbaf06SRoberto Vargas int mem_region_in_array_chk(mem_region_t *tbl, size_t nregions, 5143cbaf06SRoberto Vargas uintptr_t addr, size_t nbytes); 5243cbaf06SRoberto Vargas 53308d359bSDouglas Raillard /* 54308d359bSDouglas Raillard * Fill a region of normal memory of size "length" in bytes with zero bytes. 55308d359bSDouglas Raillard * 56308d359bSDouglas Raillard * WARNING: This function can only operate on normal memory. This means that 57308d359bSDouglas Raillard * the MMU must be enabled when using this function. Otherwise, use 58308d359bSDouglas Raillard * zeromem. 59308d359bSDouglas Raillard */ 60308d359bSDouglas Raillard void zero_normalmem(void *mem, u_register_t length); 61308d359bSDouglas Raillard 62308d359bSDouglas Raillard /* 63308d359bSDouglas Raillard * Fill a region of memory of size "length" in bytes with null bytes. 64308d359bSDouglas Raillard * 65308d359bSDouglas Raillard * Unlike zero_normalmem, this function has no restriction on the type of 66308d359bSDouglas Raillard * memory targeted and can be used for any device memory as well as normal 67308d359bSDouglas Raillard * memory. This function must be used instead of zero_normalmem when MMU is 68308d359bSDouglas Raillard * disabled. 69308d359bSDouglas Raillard * 70308d359bSDouglas Raillard * NOTE: When data cache and MMU are enabled, prefer zero_normalmem for faster 71308d359bSDouglas Raillard * zeroing. 72308d359bSDouglas Raillard */ 73308d359bSDouglas Raillard void zeromem(void *mem, u_register_t length); 74308d359bSDouglas Raillard #endif /* !(defined(__LINKER__) || defined(__ASSEMBLY__)) */ 75308d359bSDouglas Raillard 76ed81f3ebSSandrine Bailleux #endif /* __UTILS_H__ */ 77