xref: /rk3399_ARM-atf/lib/pmf/pmf_smc.c (revision 15dfbdfcae14b5508063e5e0506dc5a7da7a4da1)
1a31d8983SYatharth Kochar /*
2f7679d43SGovindraj Raja  * Copyright (c) 2016-2024, Arm Limited and Contributors. All rights reserved.
3a31d8983SYatharth Kochar  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
5a31d8983SYatharth Kochar  */
609d40e0eSAntonio Nino Diaz 
7a31d8983SYatharth Kochar #include <assert.h>
809d40e0eSAntonio Nino Diaz 
909d40e0eSAntonio Nino Diaz #include <common/debug.h>
1009d40e0eSAntonio Nino Diaz #include <lib/pmf/pmf.h>
1109d40e0eSAntonio Nino Diaz #include <plat/common/platform.h>
12085e80ecSAntonio Nino Diaz #include <smccc_helpers.h>
13a31d8983SYatharth Kochar 
14a31d8983SYatharth Kochar /*
15a31d8983SYatharth Kochar  * This function is responsible for handling all PMF SMC calls.
16a31d8983SYatharth Kochar  */
pmf_smc_handler(unsigned int smc_fid,u_register_t x1,u_register_t x2,u_register_t x3,u_register_t x4,void * cookie,void * handle,u_register_t flags)17a31d8983SYatharth Kochar uintptr_t pmf_smc_handler(unsigned int smc_fid,
18a31d8983SYatharth Kochar 			u_register_t x1,
19a31d8983SYatharth Kochar 			u_register_t x2,
20a31d8983SYatharth Kochar 			u_register_t x3,
21a31d8983SYatharth Kochar 			u_register_t x4,
22a31d8983SYatharth Kochar 			void *cookie,
23a31d8983SYatharth Kochar 			void *handle,
24a31d8983SYatharth Kochar 			u_register_t flags)
25a31d8983SYatharth Kochar {
26a31d8983SYatharth Kochar 	int rc;
27a31d8983SYatharth Kochar 	unsigned long long ts_value;
28a31d8983SYatharth Kochar 
29e60c1847SManish Pandey 	/* Determine if the cpu exists of not */
30e60c1847SManish Pandey 	if (!is_valid_mpidr(x2))
31e60c1847SManish Pandey 		return PSCI_E_INVALID_PARAMS;
32e60c1847SManish Pandey 
33a31d8983SYatharth Kochar 	if (((smc_fid >> FUNCID_CC_SHIFT) & FUNCID_CC_MASK) == SMC_32) {
34a31d8983SYatharth Kochar 
35a31d8983SYatharth Kochar 		x1 = (uint32_t)x1;
36a31d8983SYatharth Kochar 		x2 = (uint32_t)x2;
37a31d8983SYatharth Kochar 		x3 = (uint32_t)x3;
38a31d8983SYatharth Kochar 
39f7679d43SGovindraj Raja 		if (smc_fid == PMF_SMC_GET_TIMESTAMP_32 ||
40f7679d43SGovindraj Raja 		   smc_fid == PMF_SMC_GET_TIMESTAMP_32_DEP) {
41a31d8983SYatharth Kochar 			/*
42a31d8983SYatharth Kochar 			 * Return error code and the captured
43a31d8983SYatharth Kochar 			 * time-stamp to the caller.
44a31d8983SYatharth Kochar 			 * x0 --> error code.
45a31d8983SYatharth Kochar 			 * x1 - x2 --> time-stamp value.
46a31d8983SYatharth Kochar 			 */
47195e363fSAntonio Nino Diaz 			rc = pmf_get_timestamp_smc((unsigned int)x1, x2,
48195e363fSAntonio Nino Diaz 					(unsigned int)x3, &ts_value);
49a31d8983SYatharth Kochar 			SMC_RET3(handle, rc, (uint32_t)ts_value,
50a31d8983SYatharth Kochar 					(uint32_t)(ts_value >> 32));
51a31d8983SYatharth Kochar 		}
52*42cbefc7SGovindraj Raja 
53*42cbefc7SGovindraj Raja 		if (smc_fid == PMF_SMC_GET_VERSION_32) {
54*42cbefc7SGovindraj Raja 			SMC_RET2(handle, SMC_OK, PMF_SMC_VERSION);
55*42cbefc7SGovindraj Raja 		}
56a31d8983SYatharth Kochar 	} else {
57f7679d43SGovindraj Raja 		if (smc_fid == PMF_SMC_GET_TIMESTAMP_64 ||
58f7679d43SGovindraj Raja 		    smc_fid == PMF_SMC_GET_TIMESTAMP_64_DEP) {
59a31d8983SYatharth Kochar 			/*
60a31d8983SYatharth Kochar 			 * Return error code and the captured
61a31d8983SYatharth Kochar 			 * time-stamp to the caller.
62a31d8983SYatharth Kochar 			 * x0 --> error code.
63a31d8983SYatharth Kochar 			 * x1 --> time-stamp value.
64a31d8983SYatharth Kochar 			 */
65195e363fSAntonio Nino Diaz 			rc = pmf_get_timestamp_smc((unsigned int)x1, x2,
66195e363fSAntonio Nino Diaz 					(unsigned int)x3, &ts_value);
67a31d8983SYatharth Kochar 			SMC_RET2(handle, rc, ts_value);
68a31d8983SYatharth Kochar 		}
69*42cbefc7SGovindraj Raja 
70*42cbefc7SGovindraj Raja 		if (smc_fid == PMF_SMC_GET_VERSION_64) {
71*42cbefc7SGovindraj Raja 			SMC_RET2(handle, SMC_OK, PMF_SMC_VERSION);
72*42cbefc7SGovindraj Raja 		}
73a31d8983SYatharth Kochar 	}
74a31d8983SYatharth Kochar 
75a31d8983SYatharth Kochar 	WARN("Unimplemented PMF Call: 0x%x \n", smc_fid);
76a31d8983SYatharth Kochar 	SMC_RET1(handle, SMC_UNK);
77a31d8983SYatharth Kochar }
78