import old mobicore
[GitHub/LineageOS/android_hardware_samsung_slsi_exynos7580.git] / mobicore / common / MobiCore / inc / DrApi / DrApiMm.h
CommitLineData
15e8442f
JA
1/*
2 * Copyright (c) 2013 TRUSTONIC LIMITED
3 * All rights reserved
4 *
5 * The present software is the confidential and proprietary information of
6 * TRUSTONIC LIMITED. You shall not disclose the present software and shall
7 * use it only in accordance with the terms of the license agreement you
8 * entered into with TRUSTONIC LIMITED. This software may be subject to
9 * export or import laws in certain countries.
10 */
11
12#ifndef __DRAPIMM_H__
13#define __DRAPIMM_H__
14
15#include "DrApiCommon.h"
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21//------------------------------------------------------------------------------
22/** Definitions */
23
24/** Memory mapping attributes. */
25#define MAP_READABLE (1U << 0) /**< mapping gives have the ability to do read access. */
26#define MAP_WRITABLE (1U << 1) /**< mapping gives have the ability to do write access. */
27#define MAP_EXECUTABLE (1U << 2) /**< mapping gives have the ability to do program execution. */
28#define MAP_UNCACHED (1U << 3) /**< mapping gives have uncached memory access. */
29#define MAP_IO (1U << 4) /**< mapping gives have memory mapped I/O access. Will ignore MAP_UNCACHED, as this would be implied anyway. */
30
31//------------------------------------------------------------------------------
32/** Maximum number of parameter . */
33#define MAX_MAR_LIST_LENGTH 8 /**< Maximum list of possible marshaling parameters. */
34/** Marshaled union. */
35typedef struct {
36 uint32_t functionId; /**< Function identifier. */
37 union {
38 uint32_t parameter[MAX_MAR_LIST_LENGTH]; /* untyped parameter list (expands union to 8 entries) */
39 } payload;
40} drApiMarshalingParam_t, *drApiMarshalingParam_ptr;
41
42
43//------------------------------------------------------------------------------
44/** Address translation from trustlet to Driver address space.
45 * Translates an address/pointer given by a Trustlet to the Driver mapping.
46 * Checks correct address range and null pointer.
47 *
48 * @param addr Address in trustlet address space.
49 * @returns address in Driver virtual space
50 * @returns NULL if address is equal to NULL or if address is out of D3-D8 address space
51 */
52addr_t drApiAddrTranslateAndCheck(addr_t addr);
53
54//------------------------------------------------------------------------------
55#if TBASE_API_LEVEL >= 3
56
57/** Addresses translation for a buffer from trustlet to driver address space.
58 * Checks that the buffer given by its start address and its length fits correct address range.
59 * Translate the start address/pointer given by a trustlet to the driver's mapping.
60 *
61 * @param addr Start address of the buffer in trustlet address space.
62 * @param len Length of the buffer
63 * @returns start address in Driver virtual space
64 * @returns NULL if address is equal to NULL or if the buffer is out of D3-D8 address space
65 */
66addr_t drApiAddrTranslateAndCheckBuffer(addr_t adr, uint32_t len);
67
68#endif /* TBASE_API_LEVEL */
69
70//------------------------------------------------------------------------------
71/** Maps requesting client and return translated pointer to request parameters
72 *
73 * @param ipcReqClient client requesting a service
74 * @param params pointer to marshaled parameter in client address space
75 * @returns pointer to parameter for request in the current address space
76 * @returns NULL in case of error
77 */
78drApiMarshalingParam_ptr drApiMapClientAndParams(
79 threadid_t ipcReqClient,
80 uint32_t params
81);
82
83//------------------------------------------------------------------------------
84
85/** Maps a physical page to a virtual address.
86 * All addresses and lengths must be multiples of page size (4K).
87 *
88 * @param startVirt virtual address in Driver address space
89 * @param len Length of area
90 * @param startPhys physical address of hardware
91 * @param attr mapping attributes
92 * @returns DRAPI_OK in case of success
93 * @returns E_DRAPI_INVALID_PARAMETER in case any input parameter is not page size aligned or designated virtual memory area does not fit into D1-D2 address range
94 * @returns any combination of DRAPI_ERROR_CREATE(Driver specific error code, MTK error code)
95 */
96
97drApiResult_t drApiMapPhys(
98 const addr_t startVirt,
99 const uint32_t len,
100 const addr_t startPhys,
101 const uint32_t attr
102);
103#if TBASE_API_LEVEL >= 3
104drApiResult_t drApiMapPhys64(
105 const addr_t startVirt,
106 const uint32_t len,
107 const uint64_t startPhys,
108 const uint32_t attr
109);
110#endif /* TBASE_API_LEVEL */
111
112/** Removes mapping for virtual pages.
113 * All addresses and lengths must be multiples of page size (4K).
114 *
115 * @param startVirt virtual address in Driver address space
116 * @param len Length of area
117 * @returns DRAPI_OK in case of success
118 * @returns E_DRAPI_INVALID_PARAMETER in case any input parameter is not page size aligned or designated virtual memory area does not fit into D1-D2 address range
119 * @returns any combination of DRAPI_ERROR_CREATE(Driver specific error code, MTK error code)
120 */
121
122drApiResult_t drApiUnmap(
123 const addr_t startVirt,
124 const uint32_t len
125);
126
127//------------------------------------------------------------------------------
128/** The function removes mapping for a single page.
129 *
130 * @param startVirt virtual address in Driver address space
131 * @returns DRAPI_OK in case of success
132 * @returns E_DRAPI_INVALID_PARAMETER in case any input parameter is not page size aligned or designated virtual memory area does not fit into D1-D2 address range
133 * @returns any combination of DRAPI_ERROR_CREATE(Driver specific error code, MTK error code)
134 */
135drApiResult_t drApiUnmapPage4KB(
136 const page4KB_ptr virtPage
137);
138
139//------------------------------------------------------------------------------
140/** Maps a single physical page to a virtual address
141 *
142 * @param physPage virtual address in Driver address space
143 * @param startPhys physical address of hardware
144 * @param attr mapping attributes
145 * @returns DRAPI_OK in case of success
146 * @returns E_DRAPI_INVALID_PARAMETER in case any input parameter is not page size aligned or designated virtual memory area does not fit into D1-D2 address range
147 * @returns any combination of DRAPI_ERROR_CREATE(Driver specific error code, MTK error code)
148 */
149drApiResult_t drApiMapPhysPage4KB(
150 const page4KB_ptr virtPage,
151 const page4KB_ptr physPage,
152 const uint32_t attr
153);
154#if TBASE_API_LEVEL >= 3
155drApiResult_t drApiMapPhysPage4KB64(
156 const page4KB_ptr virtPage,
157 const uint64_t physPage,
158 const uint32_t attr
159);
160#endif /* TBASE_API_LEVEL */
161
162//------------------------------------------------------------------------------
163/** Maps a physical page with hardware interface
164 * This is prepared auxiliary function that at first removes mapping of the virtPage (if present)
165 * and then maps it with MAP_READABLE | MAP_WRITABLE | MAP_IO attributes
166 *
167 * @param physPage virtual address in Driver address space
168 * @param startPhys physical address of hardware
169 * @returns DRAPI_OK in case of success
170 * @returns E_DRAPI_INVALID_PARAMETER in case any input parameter is not page size aligned or designated virtual memory area does not fit into D1-D2 address range
171 * @returns any combination of DRAPI_ERROR_CREATE(Driver specific error code, MTK error code)
172 */
173drApiResult_t drApiMapPhysPage4KBWithHardware(
174 const page4KB_ptr virtPage,
175 const page4KB_ptr physPage
176);
177#if TBASE_API_LEVEL >= 3
178drApiResult_t drApiMapPhysPage4KBWithHardware64(
179 const page4KB_ptr virtPage,
180 const uint64_t physPage
181);
182#endif /* TBASE_API_LEVEL */
183
184//------------------------------------------------------------------------------
185/** Converts virtual address (in Driver address space) to physical address
186 *
187 * @param taskid Reserved for Future Use. It must be set to zero.
188 * @param virtAddr virtual address in Driver address space
189 * @param physAddr physical address
190 * @returns DRAPI_OK in case of success
191 * @returns any combination of DRAPI_ERROR_CREATE(Driver specific error code, MTK error code)
192 */
193drApiResult_t drApiVirt2Phys(
194 const taskid_t taskid,
195 const addr_t virtAddr,
196 addr_t * physAddr
197);
198#if TBASE_API_LEVEL >= 3
199drApiResult_t drApiVirt2Phys64(
200 const taskid_t taskid,
201 const addr_t virtAddr,
202 uint64_t * physAddr
203);
204#endif /* TBASE_API_LEVEL */
205
206//------------------------------------------------------------------------------
207/** Clean all data cache
208 *
209 * NOTE: Currently addr is always NULL.
210 * When extending this for not-clean-all, one can assume that there is
211 * more parameters ONLY if addr is non-NULL.
212 * Also this ensures that more specific cleans are mapped to cleanall, if specific clean is not supported.
213 *
214 * @param none
215 * @returns DRAPI_OK in case of success
216 * @returns any combination of DRAPI_ERROR_CREATE(Driver specific error code, MTK error code)
217 */
218drApiResult_t drApiCacheDataCleanAll( void );
219
220
221//------------------------------------------------------------------------------
222/** Cleans and invalidates all data cache
223 *
224 * NOTE: Currently addr is always NULL.
225 * When extending this for not-clean-invalidate-all, one can assume that there is
226 * more parameters ONLY if addr is non-NULL.
227 * Also this ensures that more specific cleans are mapped to cleanall, if specific clean is not supported.
228 *
229 * @param none
230 * @returns DRAPI_OK in case of success
231 * @returns any combination of DRAPI_ERROR_CREATE(Driver specific error code, MTK error code)
232 */
233drApiResult_t drApiCacheDataCleanInvalidateAll( void );
234
235
236//------------------------------------------------------------------------------
237#if TBASE_API_LEVEL >= 3
238
239/** Clean a portion of the data cache by MVA
240 *
241 * @param virtAddrStart
242 * @param virtAddrEnd
243 * @returns DRAPI_OK in case of success
244 * @returns any combination of DRAPI_ERROR_CREATE(Driver specific error code, MTK error code)
245 */
246drApiResult_t drApiCacheDataCleanRange(
247 addr_t *virtAddrStart,
248 uint32_t len,
249 uint32_t flags
250);
251
252
253//------------------------------------------------------------------------------
254/** Cleans and invalidates a portion of data cache by MVA
255 *
256 * @param virtAddrStart
257 * @param virtAddrEnd
258 * @returns DRAPI_OK in case of success
259 * @returns any combination of DRAPI_ERROR_CREATE(Driver specific error code, MTK error code)
260 */
261drApiResult_t drApiCacheDataCleanInvalidateRange(
262 addr_t *virtAddrStart,
263 uint32_t len,
264 uint32_t flags
265);
266
267//------------------------------------------------------------------------------
268/** Cache clean attributes */
269#define DRAPI_CACHE_ALL (0xff)
270#define DRAPI_CACHE_L1_ONLY (0x1)
271#define DRAPI_CACHE_L1_L2 (0x2)
272#endif /* TBASE_API_LEVEL */
273
274//------------------------------------------------------------------------------
275/** Memory type attributes */
276#define DRAPI_PHYS_MEM_TYPE_HIGH_SECURE (1U<<0) /**< High secure memory. (Typically iRam) */
277#define DRAPI_PHYS_MEM_TYPE_SECURE (1U<<1) /**< Secure memory in Dram */
278#define DRAPI_PHYS_MEM_TYPE_NON_SECURE (1U<<2) /**< NonSecure memory in Dram. Accessible from NonSecure world */
279
280/** Returns physical memory type (secure or non-secure)
281 *
282 * @param type pointer to address where type is returned
283 * @param addr start address of checked memory
284 * @param size size checked memory
285 * @returns E_OK in case of success
286 */
287
288drApiResult_t drApiGetPhysMemType(
289 uint32_t *type,
290 addr_t addr,
291 uint32_t size
292 );
293#if TBASE_API_LEVEL >= 3
294drApiResult_t drApiGetPhysMemType64(
295 uint32_t *type,
296 uint64_t addr,
297 uint32_t size
298 );
299#endif /* TBASE_API_LEVEL */
300
301#ifdef __cplusplus
302}
303#endif
304
305#endif // __DRAPIMM_H__