2 * Copyright (c) 2013 TRUSTONIC LIMITED
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.
15 #include "DrApiCommon.h"
21 //------------------------------------------------------------------------------
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. */
31 //------------------------------------------------------------------------------
32 /** Maximum number of parameter . */
33 #define MAX_MAR_LIST_LENGTH 8 /**< Maximum list of possible marshaling parameters. */
34 /** Marshaled union. */
36 uint32_t functionId
; /**< Function identifier. */
38 uint32_t parameter
[MAX_MAR_LIST_LENGTH
]; /* untyped parameter list (expands union to 8 entries) */
40 } drApiMarshalingParam_t
, *drApiMarshalingParam_ptr
;
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.
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
52 addr_t
drApiAddrTranslateAndCheck(addr_t addr
);
54 //------------------------------------------------------------------------------
55 #if TBASE_API_LEVEL >= 3
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.
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
66 addr_t
drApiAddrTranslateAndCheckBuffer(addr_t adr
, uint32_t len
);
68 #endif /* TBASE_API_LEVEL */
70 //------------------------------------------------------------------------------
71 /** Maps requesting client and return translated pointer to request parameters
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
78 drApiMarshalingParam_ptr
drApiMapClientAndParams(
79 threadid_t ipcReqClient
,
83 //------------------------------------------------------------------------------
85 /** Maps a physical page to a virtual address.
86 * All addresses and lengths must be multiples of page size (4K).
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)
97 drApiResult_t
drApiMapPhys(
98 const addr_t startVirt
,
100 const addr_t startPhys
,
103 #if TBASE_API_LEVEL >= 3
104 drApiResult_t
drApiMapPhys64(
105 const addr_t startVirt
,
107 const uint64_t startPhys
,
110 #endif /* TBASE_API_LEVEL */
112 /** Removes mapping for virtual pages.
113 * All addresses and lengths must be multiples of page size (4K).
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)
122 drApiResult_t
drApiUnmap(
123 const addr_t startVirt
,
127 //------------------------------------------------------------------------------
128 /** The function removes mapping for a single page.
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)
135 drApiResult_t
drApiUnmapPage4KB(
136 const page4KB_ptr virtPage
139 //------------------------------------------------------------------------------
140 /** Maps a single physical page to a virtual address
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)
149 drApiResult_t
drApiMapPhysPage4KB(
150 const page4KB_ptr virtPage
,
151 const page4KB_ptr physPage
,
154 #if TBASE_API_LEVEL >= 3
155 drApiResult_t
drApiMapPhysPage4KB64(
156 const page4KB_ptr virtPage
,
157 const uint64_t physPage
,
160 #endif /* TBASE_API_LEVEL */
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
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)
173 drApiResult_t
drApiMapPhysPage4KBWithHardware(
174 const page4KB_ptr virtPage
,
175 const page4KB_ptr physPage
177 #if TBASE_API_LEVEL >= 3
178 drApiResult_t
drApiMapPhysPage4KBWithHardware64(
179 const page4KB_ptr virtPage
,
180 const uint64_t physPage
182 #endif /* TBASE_API_LEVEL */
184 //------------------------------------------------------------------------------
185 /** Converts virtual address (in Driver address space) to physical address
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)
193 drApiResult_t
drApiVirt2Phys(
194 const taskid_t taskid
,
195 const addr_t virtAddr
,
198 #if TBASE_API_LEVEL >= 3
199 drApiResult_t
drApiVirt2Phys64(
200 const taskid_t taskid
,
201 const addr_t virtAddr
,
204 #endif /* TBASE_API_LEVEL */
206 //------------------------------------------------------------------------------
207 /** Clean all data cache
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.
215 * @returns DRAPI_OK in case of success
216 * @returns any combination of DRAPI_ERROR_CREATE(Driver specific error code, MTK error code)
218 drApiResult_t
drApiCacheDataCleanAll( void );
221 //------------------------------------------------------------------------------
222 /** Cleans and invalidates all data cache
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.
230 * @returns DRAPI_OK in case of success
231 * @returns any combination of DRAPI_ERROR_CREATE(Driver specific error code, MTK error code)
233 drApiResult_t
drApiCacheDataCleanInvalidateAll( void );
236 //------------------------------------------------------------------------------
237 #if TBASE_API_LEVEL >= 3
239 /** Clean a portion of the data cache by MVA
241 * @param virtAddrStart
243 * @returns DRAPI_OK in case of success
244 * @returns any combination of DRAPI_ERROR_CREATE(Driver specific error code, MTK error code)
246 drApiResult_t
drApiCacheDataCleanRange(
247 addr_t
*virtAddrStart
,
253 //------------------------------------------------------------------------------
254 /** Cleans and invalidates a portion of data cache by MVA
256 * @param virtAddrStart
258 * @returns DRAPI_OK in case of success
259 * @returns any combination of DRAPI_ERROR_CREATE(Driver specific error code, MTK error code)
261 drApiResult_t
drApiCacheDataCleanInvalidateRange(
262 addr_t
*virtAddrStart
,
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 */
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 */
280 /** Returns physical memory type (secure or non-secure)
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
288 drApiResult_t
drApiGetPhysMemType(
293 #if TBASE_API_LEVEL >= 3
294 drApiResult_t
drApiGetPhysMemType64(
299 #endif /* TBASE_API_LEVEL */
305 #endif // __DRAPIMM_H__