b7ccd218b123e7d22437aaa3d99ed5cc104bd4cf
[platform/core/security/tef-optee_os.git] / core / arch / arm / include / mm / core_memprot.h
1 /*
2  * Copyright (c) 2016, Linaro Limited
3  * Copyright (c) 2014, STMicroelectronics International N.V.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 #ifndef CORE_MEMPROT_H
29 #define CORE_MEMPROT_H
30
31 #include <mm/core_mmu.h>
32 #include <types_ext.h>
33
34 /*
35  * "pbuf_is" support.
36  *
37  * core_vbuf_is()/core_pbuf_is() can be used to check if a teecore mapped
38  * virtual address or a physical address is "Secure", "Unsecure", "external
39  * RAM" and some other fancy attributes.
40  *
41  * DO NOT use 'buf_is(Secure, buffer)==false' as a assumption that buffer is
42  * UnSecured ! This is NOT a valid asumption ! A buffer is certified UnSecured
43  * only if 'buf_is(UnSecure, buffer)==true'.
44  */
45
46 /* memory atttributes */
47 enum buf_is_attr {
48         CORE_MEM_SEC,
49         CORE_MEM_NON_SEC,
50         CORE_MEM_TEE_RAM,
51         CORE_MEM_TA_RAM,
52         CORE_MEM_NSEC_SHM,
53         CORE_MEM_EXTRAM,
54         CORE_MEM_INTRAM,
55         CORE_MEM_CACHED,
56 };
57
58 /* redirect legacy tee_vbuf_is() and tee_pbuf_is() to our routines */
59 #define tee_pbuf_is     core_pbuf_is
60 #define tee_vbuf_is     core_vbuf_is
61
62 /* Convenience macros */
63 #define tee_pbuf_is_non_sec(buf, len) \
64                 core_pbuf_is(CORE_MEM_NON_SEC, (paddr_t)(buf), (len))
65
66 #define tee_pbuf_is_sec(buf, len) \
67                 core_pbuf_is(CORE_MEM_SEC, (paddr_t)(buf), (len))
68
69 #define tee_vbuf_is_non_sec(buf, len) \
70                 core_vbuf_is(CORE_MEM_NON_SEC, (void *)(buf), (len))
71
72 #define tee_vbuf_is_sec(buf, len) \
73                 core_vbuf_is(CORE_MEM_SEC, (void *)(buf), (len))
74
75 /*
76  * This function return true if the buf complies with supplied flags.
77  * If this function returns false buf doesn't comply with supplied flags
78  * or something went wrong.
79  *
80  * Note that returning false doesn't guarantee that buf complies with
81  * the complement of the supplied flags.
82  */
83 bool core_pbuf_is(uint32_t flags, paddr_t pbuf, size_t len);
84
85 /*
86  * Translates the supplied virtual address to a physical address and uses
87  * tee_phys_buf_is() to check the compliance of the buffer.
88  */
89 bool core_vbuf_is(uint32_t flags, const void *vbuf, size_t len);
90
91 /*
92  * Translate physical address to virtual address using specified mapping
93  * Returns NULL on failure or a valid virtual address on success.
94  */
95 void *phys_to_virt(paddr_t pa, enum teecore_memtypes m);
96
97 /*
98  * Translate virtual address to physical address
99  * Returns 0 on failure or a valid physical address on success.
100  */
101 paddr_t virt_to_phys(void *va);
102
103 #endif /* CORE_MEMPROT_H */