1 // © 2021 Qualcomm Innovation Center, Inc. All rights reserved.
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #include <hyptypes.h>
6 
7 #include <events/smccc.h>
8 
9 #include "event_handlers.h"
10 
11 bool
smccc_version(uint32_t * ret0)12 smccc_version(uint32_t *ret0)
13 {
14 	*ret0 = SMCCC_VERSION;
15 	return true;
16 }
17 
18 bool
smccc_arch_features(uint32_t arg1,uint32_t * ret0)19 smccc_arch_features(uint32_t arg1, uint32_t *ret0)
20 {
21 	smccc_function_id_t fn_id    = smccc_function_id_cast(arg1);
22 	bool		    is_smc64 = smccc_function_id_get_is_smc64(&fn_id);
23 	smccc_function_t    fn	     = smccc_function_id_get_function(&fn_id);
24 	uint32_t	    ret;
25 
26 	if ((smccc_function_id_get_owner_id(&fn_id) == SMCCC_OWNER_ID_ARCH) &&
27 	    smccc_function_id_get_is_fast(&fn_id) &&
28 	    (smccc_function_id_get_res0(&fn_id) == 0U)) {
29 		if (is_smc64) {
30 			ret = trigger_smccc_arch_features_fast64_event(
31 				(smccc_arch_function_t)fn);
32 		} else {
33 			ret = trigger_smccc_arch_features_fast32_event(
34 				(smccc_arch_function_t)fn);
35 		}
36 	} else if ((smccc_function_id_get_owner_id(&fn_id) ==
37 		    SMCCC_OWNER_ID_STANDARD_HYP) &&
38 		   smccc_function_id_get_is_fast(&fn_id) &&
39 		   (smccc_function_id_get_res0(&fn_id) == 0U)) {
40 		if (is_smc64) {
41 			ret = trigger_smccc_standard_hyp_features_fast64_event(
42 				(smccc_standard_hyp_function_t)fn);
43 		} else {
44 			ret = trigger_smccc_standard_hyp_features_fast32_event(
45 				(smccc_standard_hyp_function_t)fn);
46 		}
47 	} else {
48 		ret = SMCCC_UNKNOWN_FUNCTION32;
49 	}
50 
51 	*ret0 = ret;
52 	return true;
53 }
54 
55 bool
smccc_std_hyp_call_uid(uint32_t * ret0,uint32_t * ret1,uint32_t * ret2,uint32_t * ret3)56 smccc_std_hyp_call_uid(uint32_t *ret0, uint32_t *ret1, uint32_t *ret2,
57 		       uint32_t *ret3)
58 {
59 	*ret0 = (uint32_t)SMCCC_GUNYAH_UID0;
60 	*ret1 = (uint32_t)SMCCC_GUNYAH_UID1;
61 	*ret2 = (uint32_t)SMCCC_GUNYAH_UID2;
62 	*ret3 = (uint32_t)SMCCC_GUNYAH_UID3;
63 
64 	return true;
65 }
66 
67 bool
smccc_std_hyp_revision(uint32_t * ret0,uint32_t * ret1)68 smccc_std_hyp_revision(uint32_t *ret0, uint32_t *ret1)
69 {
70 	// From: ARM DEN 0028E
71 	// Incompatible argument changes cannot be made to an
72 	// existing SMC or HVC call. A new call is required.
73 	//
74 	// Major revision numbers must be incremented when:
75 	// - Any SMC or HVC call is removed.
76 	// Minor revision numbers must be incremented when:
77 	// - Any SMC or HVC call is added.
78 	// - Backwards compatible changes are made to existing
79 	//   function arguments.
80 	*ret0 = 1U; // Major Revision
81 	*ret1 = 0U; // Minor Revision
82 
83 	return true;
84 }
85