xref: /optee_os/core/arch/arm/tee/svc_cache.c (revision 5a913ee74d3c71af2a2860ce8a4e7aeab2916f9b)
1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3  * Copyright (c) 2014, STMicroelectronics International N.V.
4  * Copyright (c) 2015, Linaro Limited
5  */
6 
7 #include <kernel/tee_ta_manager.h>
8 #include <mm/tee_mmu.h>
9 #include <tee/cache.h>
10 #include <tee/svc_cache.h>
11 
12 TEE_Result syscall_cache_operation(void *va, size_t len, unsigned long op)
13 {
14 	TEE_Result res;
15 	struct tee_ta_session *sess;
16 	struct user_ta_ctx *utc;
17 
18 	res = tee_ta_get_current_session(&sess);
19 	if (res != TEE_SUCCESS)
20 		return res;
21 
22 	if ((sess->ctx->flags & TA_FLAG_CACHE_MAINTENANCE) == 0)
23 		return TEE_ERROR_NOT_SUPPORTED;
24 
25 	utc = to_user_ta_ctx(sess->ctx);
26 
27 	/*
28 	 * TAs are allowed to operate cache maintenance on TA memref parameters
29 	 * only, not on the TA private memory.
30 	 */
31 	if (tee_mmu_is_vbuf_intersect_ta_private(utc, va, len))
32 		return TEE_ERROR_ACCESS_DENIED;
33 
34 	res = tee_mmu_check_access_rights(utc, TEE_MEMORY_ACCESS_READ |
35 					  TEE_MEMORY_ACCESS_ANY_OWNER,
36 					  (uaddr_t)va, len);
37 	if (res != TEE_SUCCESS)
38 		return TEE_ERROR_ACCESS_DENIED;
39 
40 	return cache_operation(op, va, len);
41 }
42