2 * Copyright (c) 2016, Linaro Limited
3 * Copyright (c) 2014, STMicroelectronics International N.V.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
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.
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.
28 #ifndef CORE_MEMPROT_H
29 #define CORE_MEMPROT_H
31 #include <mm/core_mmu.h>
32 #include <types_ext.h>
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.
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'.
46 /* memory atttributes */
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
62 /* Convenience macros */
63 #define tee_pbuf_is_non_sec(buf, len) \
64 core_pbuf_is(CORE_MEM_NON_SEC, (paddr_t)(buf), (len))
66 #define tee_pbuf_is_sec(buf, len) \
67 core_pbuf_is(CORE_MEM_SEC, (paddr_t)(buf), (len))
69 #define tee_vbuf_is_non_sec(buf, len) \
70 core_vbuf_is(CORE_MEM_NON_SEC, (void *)(buf), (len))
72 #define tee_vbuf_is_sec(buf, len) \
73 core_vbuf_is(CORE_MEM_SEC, (void *)(buf), (len))
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.
80 * Note that returning false doesn't guarantee that buf complies with
81 * the complement of the supplied flags.
83 bool core_pbuf_is(uint32_t flags, paddr_t pbuf, size_t len);
86 * Translates the supplied virtual address to a physical address and uses
87 * tee_phys_buf_is() to check the compliance of the buffer.
89 bool core_vbuf_is(uint32_t flags, const void *vbuf, size_t len);
92 * Translate physical address to virtual address using specified mapping
93 * Returns NULL on failure or a valid virtual address on success.
95 void *phys_to_virt(paddr_t pa, enum teecore_memtypes m);
98 * Translate physical address to virtual address trying MEM_AREA_IO_SEC
99 * first then MEM_AREA_IO_NSEC if not found.
100 * Returns NULL on failure or a valid virtual address on success.
102 void *phys_to_virt_io(paddr_t pa);
105 * Translate virtual address to physical address
106 * Returns 0 on failure or a valid physical address on success.
108 paddr_t virt_to_phys(void *va);
110 #endif /* CORE_MEMPROT_H */