Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 1 | /* |
Govindraj Raja | cd29ad5 | 2024-04-15 12:42:13 -0500 | [diff] [blame] | 2 | * Copyright (c) 2016-2024, Arm Limited and Contributors. All rights reserved. |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 5 | */ |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 6 | |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 7 | #include <assert.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | |
| 9 | #include <common/debug.h> |
| 10 | #include <lib/pmf/pmf.h> |
| 11 | #include <plat/common/platform.h> |
Antonio Nino Diaz | 3c817f4 | 2018-03-21 10:49:27 +0000 | [diff] [blame] | 12 | #include <smccc_helpers.h> |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 13 | |
| 14 | /* |
| 15 | * This function is responsible for handling all PMF SMC calls. |
| 16 | */ |
| 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 | |
Manish Pandey | 0b1714f | 2023-10-27 11:45:44 +0100 | [diff] [blame] | 29 | /* Determine if the cpu exists of not */ |
| 30 | if (!is_valid_mpidr(x2)) |
| 31 | return PSCI_E_INVALID_PARAMS; |
| 32 | |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 33 | if (((smc_fid >> FUNCID_CC_SHIFT) & FUNCID_CC_MASK) == SMC_32) { |
| 34 | |
| 35 | x1 = (uint32_t)x1; |
| 36 | x2 = (uint32_t)x2; |
| 37 | x3 = (uint32_t)x3; |
| 38 | |
Govindraj Raja | cd29ad5 | 2024-04-15 12:42:13 -0500 | [diff] [blame] | 39 | if (smc_fid == PMF_SMC_GET_TIMESTAMP_32 || |
| 40 | smc_fid == PMF_SMC_GET_TIMESTAMP_32_DEP) { |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 41 | /* |
| 42 | * Return error code and the captured |
| 43 | * time-stamp to the caller. |
| 44 | * x0 --> error code. |
| 45 | * x1 - x2 --> time-stamp value. |
| 46 | */ |
Antonio Nino Diaz | bf170be | 2018-10-25 17:38:23 +0100 | [diff] [blame] | 47 | rc = pmf_get_timestamp_smc((unsigned int)x1, x2, |
| 48 | (unsigned int)x3, &ts_value); |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 49 | SMC_RET3(handle, rc, (uint32_t)ts_value, |
| 50 | (uint32_t)(ts_value >> 32)); |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 51 | } |
Govindraj Raja | 560537e | 2024-04-23 11:48:48 -0500 | [diff] [blame] | 52 | |
| 53 | if (smc_fid == PMF_SMC_GET_VERSION_32) { |
| 54 | SMC_RET2(handle, SMC_OK, PMF_SMC_VERSION); |
| 55 | } |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 56 | } else { |
Govindraj Raja | cd29ad5 | 2024-04-15 12:42:13 -0500 | [diff] [blame] | 57 | if (smc_fid == PMF_SMC_GET_TIMESTAMP_64 || |
| 58 | smc_fid == PMF_SMC_GET_TIMESTAMP_64_DEP) { |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 59 | /* |
| 60 | * Return error code and the captured |
| 61 | * time-stamp to the caller. |
| 62 | * x0 --> error code. |
| 63 | * x1 --> time-stamp value. |
| 64 | */ |
Antonio Nino Diaz | bf170be | 2018-10-25 17:38:23 +0100 | [diff] [blame] | 65 | rc = pmf_get_timestamp_smc((unsigned int)x1, x2, |
| 66 | (unsigned int)x3, &ts_value); |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 67 | SMC_RET2(handle, rc, ts_value); |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 68 | } |
Govindraj Raja | 560537e | 2024-04-23 11:48:48 -0500 | [diff] [blame] | 69 | |
| 70 | if (smc_fid == PMF_SMC_GET_VERSION_64) { |
| 71 | SMC_RET2(handle, SMC_OK, PMF_SMC_VERSION); |
| 72 | } |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | WARN("Unimplemented PMF Call: 0x%x \n", smc_fid); |
| 76 | SMC_RET1(handle, SMC_UNK); |
| 77 | } |