2 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
4 * SPDX-License-Identifier: BSD-3-Clause
12 * All the regions defined in mem_region_t must have the following properties
14 * - Any contiguous regions must be merged into a single entry.
15 * - The number of bytes of each region must be greater than zero.
16 * - The calculation of the highest address within the region (base + nbytes-1)
17 * doesn't produce an overflow.
19 * These conditions must be fulfilled by the caller and they aren't checked
24 * zero_normalmem all the regions defined in tbl.
25 * It assumes that MMU is enabled and the memory is Normal memory.
26 * tbl must be a valid pointer to a memory mem_region_t array,
27 * nregions is the size of the array.
29 void clear_mem_regions(mem_region_t
*tbl
, size_t nregions
)
36 for (i
= 0; i
< nregions
; i
++) {
37 assert(tbl
->nbytes
> 0);
38 assert(!check_uptr_overflow(tbl
->base
, tbl
->nbytes
-1));
39 zero_normalmem((void *) (tbl
->base
), tbl
->nbytes
);
44 #if defined(PLAT_XLAT_TABLES_DYNAMIC)
46 * zero_normalmem all the regions defined in regions.
47 * It assumes that MMU is enabled and the memory is Normal memory.
48 * regions must be a valid pointer to a memory mem_region_t array,
49 * nregions is the size of the array. va is the virtual address
50 * where we want to map the physical pages that are going to
51 * be cleared, and chunk is the amount of memory mapped and
52 * cleared in every iteration.
54 void clear_map_dyn_mem_regions(struct mem_region
*regions
,
62 const unsigned int attr
= MT_MEMORY
| MT_RW
| MT_NS
;
64 assert(regions
!= NULL
);
65 assert(nregions
> 0 && chunk
> 0);
67 for ( ; nregions
--; regions
++) {
68 begin
= regions
->base
;
69 size
= regions
->nbytes
;
70 if ((begin
& (chunk
-1)) != 0 || (size
& (chunk
-1)) != 0) {
71 INFO("PSCI: Not correctly aligned region\n");
76 r
= mmap_add_dynamic_region(begin
, va
, chunk
, attr
);
78 INFO("PSCI: mmap_add_dynamic_region failed with %d\n", r
);
82 zero_normalmem((void *) va
, chunk
);
84 r
= mmap_remove_dynamic_region(va
, chunk
);
86 INFO("PSCI: mmap_remove_dynamic_region failed with %d\n", r
);
98 * This function checks that a region (addr + nbytes-1) of memory is totally
99 * covered by one of the regions defined in tbl.
100 * tbl must be a valid pointer to a memory mem_region_t array, nregions
101 * is the size of the array and the region described by addr and nbytes must
102 * not generate an overflow.
104 * -1 means that the region is not covered by any of the regions
106 * 0 the region (addr + nbytes-1) is covered by one of the regions described
109 int mem_region_in_array_chk(mem_region_t
*tbl
, size_t nregions
,
110 uintptr_t addr
, size_t nbytes
)
112 uintptr_t region_start
, region_end
, start
, end
;
117 assert(!check_uptr_overflow(addr
, nbytes
-1));
120 region_end
= addr
+ (nbytes
- 1);
121 for (i
= 0; i
< nregions
; i
++) {
122 assert(tbl
->nbytes
> 0);
123 assert(!check_uptr_overflow(tbl
->base
, tbl
->nbytes
-1));
125 end
= start
+ (tbl
->nbytes
- 1);
126 if (region_start
>= start
&& region_end
<= end
)