1 /*
2  * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <assert.h>
8 
9 #include <common/debug.h>
10 #include <lib/pmf/pmf.h>
11 #include <plat/common/platform.h>
12 #include <smccc_helpers.h>
13 
14 /*
15  * This function is responsible for handling all PMF SMC calls.
16  */
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)17 uintptr_t pmf_smc_handler(unsigned int smc_fid,
18 			u_register_t x1,
19 			u_register_t x2,
20 			u_register_t x3,
21 			u_register_t x4,
22 			void *cookie,
23 			void *handle,
24 			u_register_t flags)
25 {
26 	int rc;
27 	unsigned long long ts_value;
28 
29 	if (((smc_fid >> FUNCID_CC_SHIFT) & FUNCID_CC_MASK) == SMC_32) {
30 
31 		x1 = (uint32_t)x1;
32 		x2 = (uint32_t)x2;
33 		x3 = (uint32_t)x3;
34 
35 		if (smc_fid == PMF_SMC_GET_TIMESTAMP_32) {
36 			/*
37 			 * Return error code and the captured
38 			 * time-stamp to the caller.
39 			 * x0 --> error code.
40 			 * x1 - x2 --> time-stamp value.
41 			 */
42 			rc = pmf_get_timestamp_smc((unsigned int)x1, x2,
43 					(unsigned int)x3, &ts_value);
44 			SMC_RET3(handle, rc, (uint32_t)ts_value,
45 					(uint32_t)(ts_value >> 32));
46 		}
47 	} else {
48 		if (smc_fid == PMF_SMC_GET_TIMESTAMP_64) {
49 			/*
50 			 * Return error code and the captured
51 			 * time-stamp to the caller.
52 			 * x0 --> error code.
53 			 * x1 --> time-stamp value.
54 			 */
55 			rc = pmf_get_timestamp_smc((unsigned int)x1, x2,
56 					(unsigned int)x3, &ts_value);
57 			SMC_RET2(handle, rc, ts_value);
58 		}
59 	}
60 
61 	WARN("Unimplemented PMF Call: 0x%x \n", smc_fid);
62 	SMC_RET1(handle, SMC_UNK);
63 }
64