xref: /rk3399_ARM-atf/services/std_svc/drtm/drtm_main.c (revision e62748e3f1f16934f0ef2d5742f3ca0b125eaea2)
1*e62748e3SManish V Badarkhe /*
2*e62748e3SManish V Badarkhe  * Copyright (c) 2022 Arm Limited. All rights reserved.
3*e62748e3SManish V Badarkhe  *
4*e62748e3SManish V Badarkhe  * SPDX-License-Identifier:    BSD-3-Clause
5*e62748e3SManish V Badarkhe  *
6*e62748e3SManish V Badarkhe  * DRTM service
7*e62748e3SManish V Badarkhe  *
8*e62748e3SManish V Badarkhe  * Authors:
9*e62748e3SManish V Badarkhe  *	Lucian Paul-Trifu <lucian.paultrifu@gmail.com>
10*e62748e3SManish V Badarkhe  *	Brian Nezvadovitz <brinez@microsoft.com> 2021-02-01
11*e62748e3SManish V Badarkhe  */
12*e62748e3SManish V Badarkhe 
13*e62748e3SManish V Badarkhe #include <stdint.h>
14*e62748e3SManish V Badarkhe 
15*e62748e3SManish V Badarkhe #include <common/debug.h>
16*e62748e3SManish V Badarkhe #include <common/runtime_svc.h>
17*e62748e3SManish V Badarkhe #include "drtm_main.h"
18*e62748e3SManish V Badarkhe #include <services/drtm_svc.h>
19*e62748e3SManish V Badarkhe 
20*e62748e3SManish V Badarkhe int drtm_setup(void)
21*e62748e3SManish V Badarkhe {
22*e62748e3SManish V Badarkhe 	INFO("DRTM service setup\n");
23*e62748e3SManish V Badarkhe 
24*e62748e3SManish V Badarkhe 	return 0;
25*e62748e3SManish V Badarkhe }
26*e62748e3SManish V Badarkhe 
27*e62748e3SManish V Badarkhe uint64_t drtm_smc_handler(uint32_t smc_fid,
28*e62748e3SManish V Badarkhe 			  uint64_t x1,
29*e62748e3SManish V Badarkhe 			  uint64_t x2,
30*e62748e3SManish V Badarkhe 			  uint64_t x3,
31*e62748e3SManish V Badarkhe 			  uint64_t x4,
32*e62748e3SManish V Badarkhe 			  void *cookie,
33*e62748e3SManish V Badarkhe 			  void *handle,
34*e62748e3SManish V Badarkhe 			  uint64_t flags)
35*e62748e3SManish V Badarkhe {
36*e62748e3SManish V Badarkhe 	/* Check that the SMC call is from the Normal World. */
37*e62748e3SManish V Badarkhe 	if (!is_caller_non_secure(flags)) {
38*e62748e3SManish V Badarkhe 		SMC_RET1(handle, NOT_SUPPORTED);
39*e62748e3SManish V Badarkhe 	}
40*e62748e3SManish V Badarkhe 
41*e62748e3SManish V Badarkhe 	switch (smc_fid) {
42*e62748e3SManish V Badarkhe 	case ARM_DRTM_SVC_VERSION:
43*e62748e3SManish V Badarkhe 		INFO("DRTM service handler: version\n");
44*e62748e3SManish V Badarkhe 		/* Return the version of current implementation */
45*e62748e3SManish V Badarkhe 		SMC_RET1(handle, ARM_DRTM_VERSION);
46*e62748e3SManish V Badarkhe 		break;	/* not reached */
47*e62748e3SManish V Badarkhe 
48*e62748e3SManish V Badarkhe 	case ARM_DRTM_SVC_FEATURES:
49*e62748e3SManish V Badarkhe 		if (((x1 >> ARM_DRTM_FUNC_SHIFT) & ARM_DRTM_FUNC_MASK) ==
50*e62748e3SManish V Badarkhe 		    ARM_DRTM_FUNC_ID) {
51*e62748e3SManish V Badarkhe 			/* Dispatch function-based queries. */
52*e62748e3SManish V Badarkhe 			switch (x1 & FUNCID_MASK) {
53*e62748e3SManish V Badarkhe 			case ARM_DRTM_SVC_VERSION:
54*e62748e3SManish V Badarkhe 				SMC_RET1(handle, SUCCESS);
55*e62748e3SManish V Badarkhe 				break;	/* not reached */
56*e62748e3SManish V Badarkhe 
57*e62748e3SManish V Badarkhe 			case ARM_DRTM_SVC_FEATURES:
58*e62748e3SManish V Badarkhe 				SMC_RET1(handle, SUCCESS);
59*e62748e3SManish V Badarkhe 				break;	/* not reached */
60*e62748e3SManish V Badarkhe 
61*e62748e3SManish V Badarkhe 			case ARM_DRTM_SVC_UNPROTECT_MEM:
62*e62748e3SManish V Badarkhe 				SMC_RET1(handle, SUCCESS);
63*e62748e3SManish V Badarkhe 				break;	/* not reached */
64*e62748e3SManish V Badarkhe 
65*e62748e3SManish V Badarkhe 			case ARM_DRTM_SVC_DYNAMIC_LAUNCH:
66*e62748e3SManish V Badarkhe 				SMC_RET1(handle, SUCCESS);
67*e62748e3SManish V Badarkhe 				break;	/* not reached */
68*e62748e3SManish V Badarkhe 
69*e62748e3SManish V Badarkhe 			case ARM_DRTM_SVC_CLOSE_LOCALITY:
70*e62748e3SManish V Badarkhe 				WARN("ARM_DRTM_SVC_CLOSE_LOCALITY feature %s",
71*e62748e3SManish V Badarkhe 				     "is not supported\n");
72*e62748e3SManish V Badarkhe 				SMC_RET1(handle, NOT_SUPPORTED);
73*e62748e3SManish V Badarkhe 				break;	/* not reached */
74*e62748e3SManish V Badarkhe 
75*e62748e3SManish V Badarkhe 			case ARM_DRTM_SVC_GET_ERROR:
76*e62748e3SManish V Badarkhe 				SMC_RET1(handle, SUCCESS);
77*e62748e3SManish V Badarkhe 				break;	/* not reached */
78*e62748e3SManish V Badarkhe 
79*e62748e3SManish V Badarkhe 			case ARM_DRTM_SVC_SET_ERROR:
80*e62748e3SManish V Badarkhe 				SMC_RET1(handle, SUCCESS);
81*e62748e3SManish V Badarkhe 				break;	/* not reached */
82*e62748e3SManish V Badarkhe 
83*e62748e3SManish V Badarkhe 			case ARM_DRTM_SVC_SET_TCB_HASH:
84*e62748e3SManish V Badarkhe 				WARN("ARM_DRTM_SVC_TCB_HASH feature %s",
85*e62748e3SManish V Badarkhe 				     "is not supported\n");
86*e62748e3SManish V Badarkhe 				SMC_RET1(handle, NOT_SUPPORTED);
87*e62748e3SManish V Badarkhe 				break;	/* not reached */
88*e62748e3SManish V Badarkhe 
89*e62748e3SManish V Badarkhe 			case ARM_DRTM_SVC_LOCK_TCB_HASH:
90*e62748e3SManish V Badarkhe 				WARN("ARM_DRTM_SVC_LOCK_TCB_HASH feature %s",
91*e62748e3SManish V Badarkhe 				     "is not supported\n");
92*e62748e3SManish V Badarkhe 				SMC_RET1(handle, NOT_SUPPORTED);
93*e62748e3SManish V Badarkhe 				break;	/* not reached */
94*e62748e3SManish V Badarkhe 
95*e62748e3SManish V Badarkhe 			default:
96*e62748e3SManish V Badarkhe 				ERROR("Unknown DRTM service function\n");
97*e62748e3SManish V Badarkhe 				SMC_RET1(handle, NOT_SUPPORTED);
98*e62748e3SManish V Badarkhe 				break;	/* not reached */
99*e62748e3SManish V Badarkhe 			}
100*e62748e3SManish V Badarkhe 		}
101*e62748e3SManish V Badarkhe 
102*e62748e3SManish V Badarkhe 	case ARM_DRTM_SVC_UNPROTECT_MEM:
103*e62748e3SManish V Badarkhe 		INFO("DRTM service handler: unprotect mem\n");
104*e62748e3SManish V Badarkhe 		SMC_RET1(handle, SMC_OK);
105*e62748e3SManish V Badarkhe 		break;	/* not reached */
106*e62748e3SManish V Badarkhe 
107*e62748e3SManish V Badarkhe 	case ARM_DRTM_SVC_DYNAMIC_LAUNCH:
108*e62748e3SManish V Badarkhe 		INFO("DRTM service handler: dynamic launch\n");
109*e62748e3SManish V Badarkhe 		SMC_RET1(handle, SMC_OK);
110*e62748e3SManish V Badarkhe 		break;	/* not reached */
111*e62748e3SManish V Badarkhe 
112*e62748e3SManish V Badarkhe 	case ARM_DRTM_SVC_CLOSE_LOCALITY:
113*e62748e3SManish V Badarkhe 		WARN("DRTM service handler: close locality %s\n",
114*e62748e3SManish V Badarkhe 		     "is not supported");
115*e62748e3SManish V Badarkhe 		SMC_RET1(handle, NOT_SUPPORTED);
116*e62748e3SManish V Badarkhe 		break;	/* not reached */
117*e62748e3SManish V Badarkhe 
118*e62748e3SManish V Badarkhe 	case ARM_DRTM_SVC_GET_ERROR:
119*e62748e3SManish V Badarkhe 		INFO("DRTM service handler: get error\n");
120*e62748e3SManish V Badarkhe 		SMC_RET2(handle, SMC_OK, 0);
121*e62748e3SManish V Badarkhe 		break;	/* not reached */
122*e62748e3SManish V Badarkhe 
123*e62748e3SManish V Badarkhe 	case ARM_DRTM_SVC_SET_ERROR:
124*e62748e3SManish V Badarkhe 		INFO("DRTM service handler: set error\n");
125*e62748e3SManish V Badarkhe 		SMC_RET1(handle, SMC_OK);
126*e62748e3SManish V Badarkhe 		break;	/* not reached */
127*e62748e3SManish V Badarkhe 
128*e62748e3SManish V Badarkhe 	case ARM_DRTM_SVC_SET_TCB_HASH:
129*e62748e3SManish V Badarkhe 		WARN("DRTM service handler: set TCB hash %s\n",
130*e62748e3SManish V Badarkhe 		     "is not supported");
131*e62748e3SManish V Badarkhe 		SMC_RET1(handle, NOT_SUPPORTED);
132*e62748e3SManish V Badarkhe 		break;  /* not reached */
133*e62748e3SManish V Badarkhe 
134*e62748e3SManish V Badarkhe 	case ARM_DRTM_SVC_LOCK_TCB_HASH:
135*e62748e3SManish V Badarkhe 		WARN("DRTM service handler: lock TCB hash %s\n",
136*e62748e3SManish V Badarkhe 		     "is not supported");
137*e62748e3SManish V Badarkhe 		SMC_RET1(handle, NOT_SUPPORTED);
138*e62748e3SManish V Badarkhe 		break;  /* not reached */
139*e62748e3SManish V Badarkhe 
140*e62748e3SManish V Badarkhe 	default:
141*e62748e3SManish V Badarkhe 		ERROR("Unknown DRTM service function: 0x%x\n", smc_fid);
142*e62748e3SManish V Badarkhe 		SMC_RET1(handle, SMC_UNK);
143*e62748e3SManish V Badarkhe 		break;	/* not reached */
144*e62748e3SManish V Badarkhe 	}
145*e62748e3SManish V Badarkhe 
146*e62748e3SManish V Badarkhe 	/* not reached */
147*e62748e3SManish V Badarkhe 	SMC_RET1(handle, SMC_UNK);
148*e62748e3SManish V Badarkhe }
149