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