Sandrine Bailleux | 7659a26 | 2016-07-05 09:55:03 +0100 | [diff] [blame] | 1 | /* |
Roberto Vargas | 550eb08 | 2018-01-05 16:00:05 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved. |
Sandrine Bailleux | 7659a26 | 2016-07-05 09:55:03 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Sandrine Bailleux | 7659a26 | 2016-07-05 09:55:03 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __UTILS_H__ |
| 8 | #define __UTILS_H__ |
| 9 | |
Scott Branden | bf404c0 | 2017-04-10 11:45:52 -0700 | [diff] [blame] | 10 | #if !ERROR_DEPRECATED |
| 11 | #include <utils_def.h> |
David Cunado | 2e36de8 | 2017-01-19 10:26:16 +0000 | [diff] [blame] | 12 | #endif |
| 13 | |
Douglas Raillard | 21362a9 | 2016-12-02 13:51:54 +0000 | [diff] [blame] | 14 | /* |
| 15 | * C code should be put in this part of the header to avoid breaking ASM files |
| 16 | * or linker scripts including it. |
| 17 | */ |
| 18 | #if !(defined(__LINKER__) || defined(__ASSEMBLY__)) |
| 19 | |
| 20 | #include <types.h> |
| 21 | |
Masahiro Yamada | ff3ecb6 | 2018-01-16 23:15:38 +0900 | [diff] [blame] | 22 | typedef struct mem_region { |
Roberto Vargas | c590770 | 2017-08-03 08:56:38 +0100 | [diff] [blame] | 23 | uintptr_t base; |
| 24 | size_t nbytes; |
| 25 | } mem_region_t; |
| 26 | |
| 27 | /* |
| 28 | * zero_normalmem all the regions defined in tbl. |
| 29 | */ |
| 30 | void clear_mem_regions(mem_region_t *tbl, size_t nregions); |
| 31 | |
Roberto Vargas | 550eb08 | 2018-01-05 16:00:05 +0000 | [diff] [blame] | 32 | /* |
| 33 | * zero_normalmem all the regions defined in region. It dynamically |
| 34 | * maps chunks of 'chunk_size' in 'va' virtual address and clears them. |
| 35 | * For this reason memory regions must be multiple of chunk_size and |
| 36 | * must be aligned to it as well. chunk_size and va can be selected |
| 37 | * in a way that they minimize the number of entries used in the |
| 38 | * translation tables. |
| 39 | */ |
Roberto Vargas | 85664f5 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 40 | void clear_map_dyn_mem_regions(struct mem_region *regions, |
Roberto Vargas | 550eb08 | 2018-01-05 16:00:05 +0000 | [diff] [blame] | 41 | size_t nregions, |
| 42 | uintptr_t va, |
Roberto Vargas | 85664f5 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 43 | size_t chunk); |
Roberto Vargas | c590770 | 2017-08-03 08:56:38 +0100 | [diff] [blame] | 44 | |
| 45 | /* |
| 46 | * checks that a region (addr + nbytes-1) of memory is totally covered by |
| 47 | * one of the regions defined in tbl. Caller must ensure that (addr+nbytes-1) |
| 48 | * doesn't overflow. |
| 49 | */ |
| 50 | int mem_region_in_array_chk(mem_region_t *tbl, size_t nregions, |
| 51 | uintptr_t addr, size_t nbytes); |
| 52 | |
Douglas Raillard | 21362a9 | 2016-12-02 13:51:54 +0000 | [diff] [blame] | 53 | /* |
| 54 | * Fill a region of normal memory of size "length" in bytes with zero bytes. |
| 55 | * |
| 56 | * WARNING: This function can only operate on normal memory. This means that |
| 57 | * the MMU must be enabled when using this function. Otherwise, use |
| 58 | * zeromem. |
| 59 | */ |
| 60 | void zero_normalmem(void *mem, u_register_t length); |
| 61 | |
| 62 | /* |
| 63 | * Fill a region of memory of size "length" in bytes with null bytes. |
| 64 | * |
| 65 | * Unlike zero_normalmem, this function has no restriction on the type of |
| 66 | * memory targeted and can be used for any device memory as well as normal |
| 67 | * memory. This function must be used instead of zero_normalmem when MMU is |
| 68 | * disabled. |
| 69 | * |
| 70 | * NOTE: When data cache and MMU are enabled, prefer zero_normalmem for faster |
| 71 | * zeroing. |
| 72 | */ |
| 73 | void zeromem(void *mem, u_register_t length); |
| 74 | #endif /* !(defined(__LINKER__) || defined(__ASSEMBLY__)) */ |
| 75 | |
Sandrine Bailleux | 7659a26 | 2016-07-05 09:55:03 +0100 | [diff] [blame] | 76 | #endif /* __UTILS_H__ */ |