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