1 /*
2  * Copyright (c) 2022 Arm Limited (or its affiliates). All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #include <zephyr/ztest.h>
7 
8 #include <zephyr/arch/arm64/arm-smccc.h>
9 
10 /* SMC function IDs for Standard Service queries */
11 #define ARM_STD_SMC_CALL_COUNT		0x8400ff00UL
12 #define ARM_STD_SMC_VERSION		0x8400ff03UL
13 #define ARM_STD_SMC_UNKNOWN		0xffffffffUL
14 
15 #define SMC_UNK				-1
16 
17 typedef void (*smc_call_method_t)(unsigned long, unsigned long,
18 				  unsigned long, unsigned long,
19 				  unsigned long, unsigned long,
20 				  unsigned long, unsigned long,
21 				  struct arm_smccc_res *);
22 
23 #ifdef CONFIG_SMC_CALL_USE_HVC
24 	smc_call_method_t smc_call = arm_smccc_hvc;
25 #else
26 	smc_call_method_t smc_call = arm_smccc_smc;
27 #endif
28 
ZTEST(arm64_smc_call,test_smc_call_func)29 ZTEST(arm64_smc_call, test_smc_call_func)
30 {
31 	struct arm_smccc_res res;
32 
33 	smc_call(ARM_STD_SMC_CALL_COUNT, 0, 0, 0, 0, 0, 0, 0, &res);
34 	zassert_true(res.a0 > 0, "Wrong smc call count");
35 
36 	smc_call(ARM_STD_SMC_VERSION, 0, 0, 0, 0, 0, 0, 0, &res);
37 	zassert_true((res.a0 >= 0 && res.a1 >= 0),
38 		"Wrong smc call version");
39 
40 	smc_call(ARM_STD_SMC_UNKNOWN, 0, 0, 0, 0, 0, 0, 0, &res);
41 	zassert_true(res.a0 == SMC_UNK, "Wrong return code from smc call");
42 }
43 
44 ZTEST_SUITE(arm64_smc_call, NULL, NULL, NULL, NULL, NULL);
45