xref: /rk3399_ARM-atf/lib/pmf/pmf_smc.c (revision e60c18471fc7488cc0bf1dc7eae3b43be77045a4)
1a31d8983SYatharth Kochar /*
24c700c15SGovindraj Raja  * Copyright (c) 2016-2018, 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  */
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 
29*e60c1847SManish Pandey 	/* Determine if the cpu exists of not */
30*e60c1847SManish Pandey 	if (!is_valid_mpidr(x2))
31*e60c1847SManish Pandey 		return PSCI_E_INVALID_PARAMS;
32*e60c1847SManish 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 
393eacacc0SJonathan Wright 		if (smc_fid == PMF_SMC_GET_TIMESTAMP_32) {
40a31d8983SYatharth Kochar 			/*
41a31d8983SYatharth Kochar 			 * Return error code and the captured
42a31d8983SYatharth Kochar 			 * time-stamp to the caller.
43a31d8983SYatharth Kochar 			 * x0 --> error code.
44a31d8983SYatharth Kochar 			 * x1 - x2 --> time-stamp value.
45a31d8983SYatharth Kochar 			 */
46195e363fSAntonio Nino Diaz 			rc = pmf_get_timestamp_smc((unsigned int)x1, x2,
47195e363fSAntonio Nino Diaz 					(unsigned int)x3, &ts_value);
48a31d8983SYatharth Kochar 			SMC_RET3(handle, rc, (uint32_t)ts_value,
49a31d8983SYatharth Kochar 					(uint32_t)(ts_value >> 32));
50a31d8983SYatharth Kochar 		}
51a31d8983SYatharth Kochar 	} else {
523eacacc0SJonathan Wright 		if (smc_fid == PMF_SMC_GET_TIMESTAMP_64) {
53a31d8983SYatharth Kochar 			/*
54a31d8983SYatharth Kochar 			 * Return error code and the captured
55a31d8983SYatharth Kochar 			 * time-stamp to the caller.
56a31d8983SYatharth Kochar 			 * x0 --> error code.
57a31d8983SYatharth Kochar 			 * x1 --> time-stamp value.
58a31d8983SYatharth Kochar 			 */
59195e363fSAntonio Nino Diaz 			rc = pmf_get_timestamp_smc((unsigned int)x1, x2,
60195e363fSAntonio Nino Diaz 					(unsigned int)x3, &ts_value);
61a31d8983SYatharth Kochar 			SMC_RET2(handle, rc, ts_value);
62a31d8983SYatharth Kochar 		}
63a31d8983SYatharth Kochar 	}
64a31d8983SYatharth Kochar 
65a31d8983SYatharth Kochar 	WARN("Unimplemented PMF Call: 0x%x \n", smc_fid);
66a31d8983SYatharth Kochar 	SMC_RET1(handle, SMC_UNK);
67a31d8983SYatharth Kochar }
68