blob: 3d215c321033be50855ffea30fed141b3c68bdf4 [file] [log] [blame]
Sandrine Bailleux7659a262016-07-05 09:55:03 +01001/*
David Cunado2e36de82017-01-19 10:26:16 +00002 * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved.
Sandrine Bailleux7659a262016-07-05 09:55:03 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Sandrine Bailleux7659a262016-07-05 09:55:03 +01005 */
6
7#ifndef __UTILS_H__
8#define __UTILS_H__
9
Scott Brandenbf404c02017-04-10 11:45:52 -070010#if !ERROR_DEPRECATED
11#include <utils_def.h>
David Cunado2e36de82017-01-19 10:26:16 +000012#endif
13
Douglas Raillard21362a92016-12-02 13:51:54 +000014/*
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 Yamadaff3ecb62018-01-16 23:15:38 +090022typedef struct mem_region {
Roberto Vargasc5907702017-08-03 08:56:38 +010023 uintptr_t base;
24 size_t nbytes;
25} mem_region_t;
26
27/*
28 * zero_normalmem all the regions defined in tbl.
29 */
30void clear_mem_regions(mem_region_t *tbl, size_t nregions);
31
32
33/*
34 * checks that a region (addr + nbytes-1) of memory is totally covered by
35 * one of the regions defined in tbl. Caller must ensure that (addr+nbytes-1)
36 * doesn't overflow.
37 */
38int mem_region_in_array_chk(mem_region_t *tbl, size_t nregions,
39 uintptr_t addr, size_t nbytes);
40
Douglas Raillard21362a92016-12-02 13:51:54 +000041/*
42 * Fill a region of normal memory of size "length" in bytes with zero bytes.
43 *
44 * WARNING: This function can only operate on normal memory. This means that
45 * the MMU must be enabled when using this function. Otherwise, use
46 * zeromem.
47 */
48void zero_normalmem(void *mem, u_register_t length);
49
50/*
51 * Fill a region of memory of size "length" in bytes with null bytes.
52 *
53 * Unlike zero_normalmem, this function has no restriction on the type of
54 * memory targeted and can be used for any device memory as well as normal
55 * memory. This function must be used instead of zero_normalmem when MMU is
56 * disabled.
57 *
58 * NOTE: When data cache and MMU are enabled, prefer zero_normalmem for faster
59 * zeroing.
60 */
61void zeromem(void *mem, u_register_t length);
62#endif /* !(defined(__LINKER__) || defined(__ASSEMBLY__)) */
63
Sandrine Bailleux7659a262016-07-05 09:55:03 +010064#endif /* __UTILS_H__ */