dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 1 | /* |
Jeenu Viswambharan | bc1a929 | 2017-02-16 14:55:15 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved. |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <arm_sip_svc.h> |
| 8 | #include <debug.h> |
Jeenu Viswambharan | bc1a929 | 2017-02-16 14:55:15 +0000 | [diff] [blame] | 9 | #include <plat_arm.h> |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 10 | #include <pmf.h> |
| 11 | #include <runtime_svc.h> |
| 12 | #include <stdint.h> |
| 13 | #include <uuid.h> |
| 14 | |
| 15 | |
| 16 | /* ARM SiP Service UUID */ |
| 17 | DEFINE_SVC_UUID(arm_sip_svc_uid, |
| 18 | 0xe2756d55, 0x3360, 0x4bb5, 0xbf, 0xf3, |
| 19 | 0x62, 0x79, 0xfd, 0x11, 0x37, 0xff); |
| 20 | |
| 21 | static int arm_sip_setup(void) |
| 22 | { |
| 23 | if (pmf_setup() != 0) |
| 24 | return 1; |
| 25 | return 0; |
| 26 | } |
| 27 | |
| 28 | /* |
| 29 | * This function handles ARM defined SiP Calls |
| 30 | */ |
| 31 | static uintptr_t arm_sip_handler(unsigned int smc_fid, |
| 32 | u_register_t x1, |
| 33 | u_register_t x2, |
| 34 | u_register_t x3, |
| 35 | u_register_t x4, |
| 36 | void *cookie, |
| 37 | void *handle, |
| 38 | u_register_t flags) |
| 39 | { |
Jeenu Viswambharan | bc1a929 | 2017-02-16 14:55:15 +0000 | [diff] [blame] | 40 | int call_count = 0; |
| 41 | |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 42 | /* |
| 43 | * Dispatch PMF calls to PMF SMC handler and return its return |
| 44 | * value |
| 45 | */ |
| 46 | if (is_pmf_fid(smc_fid)) { |
| 47 | return pmf_smc_handler(smc_fid, x1, x2, x3, x4, cookie, |
| 48 | handle, flags); |
| 49 | } |
| 50 | |
| 51 | switch (smc_fid) { |
Jeenu Viswambharan | bc1a929 | 2017-02-16 14:55:15 +0000 | [diff] [blame] | 52 | case ARM_SIP_SVC_EXE_STATE_SWITCH: { |
| 53 | u_register_t pc; |
| 54 | |
| 55 | /* Allow calls from non-secure only */ |
| 56 | if (!is_caller_non_secure(flags)) |
| 57 | SMC_RET1(handle, STATE_SW_E_DENIED); |
| 58 | |
| 59 | /* Validate supplied entry point */ |
| 60 | pc = (u_register_t) ((x1 << 32) | (uint32_t) x2); |
| 61 | if (arm_validate_ns_entrypoint(pc)) |
| 62 | SMC_RET1(handle, STATE_SW_E_PARAM); |
| 63 | |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 64 | /* |
Jeenu Viswambharan | bc1a929 | 2017-02-16 14:55:15 +0000 | [diff] [blame] | 65 | * Pointers used in execution state switch are all 32 bits wide |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 66 | */ |
Jeenu Viswambharan | bc1a929 | 2017-02-16 14:55:15 +0000 | [diff] [blame] | 67 | return arm_execution_state_switch(smc_fid, (uint32_t) x1, |
| 68 | (uint32_t) x2, (uint32_t) x3, (uint32_t) x4, |
| 69 | handle); |
| 70 | } |
| 71 | |
| 72 | case ARM_SIP_SVC_CALL_COUNT: |
| 73 | /* PMF calls */ |
| 74 | call_count += PMF_NUM_SMC_CALLS; |
| 75 | |
| 76 | /* State switch call */ |
| 77 | call_count += 1; |
| 78 | |
| 79 | SMC_RET1(handle, call_count); |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 80 | |
| 81 | case ARM_SIP_SVC_UID: |
| 82 | /* Return UID to the caller */ |
| 83 | SMC_UUID_RET(handle, arm_sip_svc_uid); |
| 84 | |
| 85 | case ARM_SIP_SVC_VERSION: |
| 86 | /* Return the version of current implementation */ |
| 87 | SMC_RET2(handle, ARM_SIP_SVC_VERSION_MAJOR, ARM_SIP_SVC_VERSION_MINOR); |
| 88 | |
| 89 | default: |
| 90 | WARN("Unimplemented ARM SiP Service Call: 0x%x \n", smc_fid); |
| 91 | SMC_RET1(handle, SMC_UNK); |
| 92 | } |
| 93 | |
| 94 | } |
| 95 | |
| 96 | |
| 97 | /* Define a runtime service descriptor for fast SMC calls */ |
| 98 | DECLARE_RT_SVC( |
| 99 | arm_sip_svc, |
| 100 | OEN_SIP_START, |
| 101 | OEN_SIP_END, |
| 102 | SMC_TYPE_FAST, |
| 103 | arm_sip_setup, |
| 104 | arm_sip_handler |
| 105 | ); |