xref: /rk3399_ARM-atf/lib/pmf/pmf_smc.c (revision 09d40e0e08283a249e7dce0e106c07c5141f9b7e)
1a31d8983SYatharth Kochar /*
2085e80ecSAntonio Nino Diaz  * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved.
3a31d8983SYatharth Kochar  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
5a31d8983SYatharth Kochar  */
6*09d40e0eSAntonio Nino Diaz 
7a31d8983SYatharth Kochar #include <assert.h>
8*09d40e0eSAntonio Nino Diaz 
9*09d40e0eSAntonio Nino Diaz #include <common/debug.h>
10*09d40e0eSAntonio Nino Diaz #include <lib/pmf/pmf.h>
11*09d40e0eSAntonio 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  */
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 
29a31d8983SYatharth Kochar 	if (((smc_fid >> FUNCID_CC_SHIFT) & FUNCID_CC_MASK) == SMC_32) {
30a31d8983SYatharth Kochar 
31a31d8983SYatharth Kochar 		x1 = (uint32_t)x1;
32a31d8983SYatharth Kochar 		x2 = (uint32_t)x2;
33a31d8983SYatharth Kochar 		x3 = (uint32_t)x3;
34a31d8983SYatharth Kochar 
353eacacc0SJonathan Wright 		if (smc_fid == PMF_SMC_GET_TIMESTAMP_32) {
36a31d8983SYatharth Kochar 			/*
37a31d8983SYatharth Kochar 			 * Return error code and the captured
38a31d8983SYatharth Kochar 			 * time-stamp to the caller.
39a31d8983SYatharth Kochar 			 * x0 --> error code.
40a31d8983SYatharth Kochar 			 * x1 - x2 --> time-stamp value.
41a31d8983SYatharth Kochar 			 */
42195e363fSAntonio Nino Diaz 			rc = pmf_get_timestamp_smc((unsigned int)x1, x2,
43195e363fSAntonio Nino Diaz 					(unsigned int)x3, &ts_value);
44a31d8983SYatharth Kochar 			SMC_RET3(handle, rc, (uint32_t)ts_value,
45a31d8983SYatharth Kochar 					(uint32_t)(ts_value >> 32));
46a31d8983SYatharth Kochar 		}
47a31d8983SYatharth Kochar 	} else {
483eacacc0SJonathan Wright 		if (smc_fid == PMF_SMC_GET_TIMESTAMP_64) {
49a31d8983SYatharth Kochar 			/*
50a31d8983SYatharth Kochar 			 * Return error code and the captured
51a31d8983SYatharth Kochar 			 * time-stamp to the caller.
52a31d8983SYatharth Kochar 			 * x0 --> error code.
53a31d8983SYatharth Kochar 			 * x1 --> time-stamp value.
54a31d8983SYatharth Kochar 			 */
55195e363fSAntonio Nino Diaz 			rc = pmf_get_timestamp_smc((unsigned int)x1, x2,
56195e363fSAntonio Nino Diaz 					(unsigned int)x3, &ts_value);
57a31d8983SYatharth Kochar 			SMC_RET2(handle, rc, ts_value);
58a31d8983SYatharth Kochar 		}
59a31d8983SYatharth Kochar 	}
60a31d8983SYatharth Kochar 
61a31d8983SYatharth Kochar 	WARN("Unimplemented PMF Call: 0x%x \n", smc_fid);
62a31d8983SYatharth Kochar 	SMC_RET1(handle, SMC_UNK);
63a31d8983SYatharth Kochar }
64