dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 1 | /* |
Bence Szépkúti | 16362c6 | 2019-10-24 15:53:23 +0200 | [diff] [blame] | 2 | * Copyright (c) 2016-2019, 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> |
Ambroise Vincent | 9660dc1 | 2019-07-12 13:47:03 +0100 | [diff] [blame] | 11 | #include <lib/debugfs.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 12 | #include <lib/pmf/pmf.h> |
Antonio Nino Diaz | bd7b740 | 2019-01-25 14:30:04 +0000 | [diff] [blame] | 13 | #include <plat/arm/common/arm_sip_svc.h> |
| 14 | #include <plat/arm/common/plat_arm.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 15 | #include <tools_share/uuid.h> |
| 16 | |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 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 | { |
Ambroise Vincent | 9660dc1 | 2019-07-12 13:47:03 +0100 | [diff] [blame] | 24 | if (pmf_setup() != 0) { |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 25 | return 1; |
Ambroise Vincent | 9660dc1 | 2019-07-12 13:47:03 +0100 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | #if USE_DEBUGFS |
| 29 | |
| 30 | if (debugfs_smc_setup() != 0) { |
| 31 | return 1; |
| 32 | } |
| 33 | |
| 34 | #endif /* USE_DEBUGFS */ |
| 35 | |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 36 | return 0; |
| 37 | } |
| 38 | |
| 39 | /* |
| 40 | * This function handles ARM defined SiP Calls |
| 41 | */ |
| 42 | static uintptr_t arm_sip_handler(unsigned int smc_fid, |
| 43 | u_register_t x1, |
| 44 | u_register_t x2, |
| 45 | u_register_t x3, |
| 46 | u_register_t x4, |
| 47 | void *cookie, |
| 48 | void *handle, |
| 49 | u_register_t flags) |
| 50 | { |
Jeenu Viswambharan | bc1a929 | 2017-02-16 14:55:15 +0000 | [diff] [blame] | 51 | int call_count = 0; |
| 52 | |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 53 | /* |
| 54 | * Dispatch PMF calls to PMF SMC handler and return its return |
| 55 | * value |
| 56 | */ |
| 57 | if (is_pmf_fid(smc_fid)) { |
| 58 | return pmf_smc_handler(smc_fid, x1, x2, x3, x4, cookie, |
| 59 | handle, flags); |
| 60 | } |
| 61 | |
Ambroise Vincent | 9660dc1 | 2019-07-12 13:47:03 +0100 | [diff] [blame] | 62 | #if USE_DEBUGFS |
| 63 | |
| 64 | if (is_debugfs_fid(smc_fid)) { |
| 65 | return debugfs_smc_handler(smc_fid, x1, x2, x3, x4, cookie, |
| 66 | handle, flags); |
| 67 | } |
| 68 | |
| 69 | #endif /* USE_DEBUGFS */ |
| 70 | |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 71 | switch (smc_fid) { |
Jeenu Viswambharan | bc1a929 | 2017-02-16 14:55:15 +0000 | [diff] [blame] | 72 | case ARM_SIP_SVC_EXE_STATE_SWITCH: { |
Bence Szépkúti | 16362c6 | 2019-10-24 15:53:23 +0200 | [diff] [blame] | 73 | /* Execution state can be switched only if EL3 is AArch64 */ |
| 74 | #ifdef __aarch64__ |
Jeenu Viswambharan | bc1a929 | 2017-02-16 14:55:15 +0000 | [diff] [blame] | 75 | /* Allow calls from non-secure only */ |
| 76 | if (!is_caller_non_secure(flags)) |
| 77 | SMC_RET1(handle, STATE_SW_E_DENIED); |
| 78 | |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 79 | /* |
Jeenu Viswambharan | bc1a929 | 2017-02-16 14:55:15 +0000 | [diff] [blame] | 80 | * Pointers used in execution state switch are all 32 bits wide |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 81 | */ |
Jeenu Viswambharan | 210f0a8 | 2018-08-02 10:14:12 +0100 | [diff] [blame] | 82 | return (uintptr_t) arm_execution_state_switch(smc_fid, |
| 83 | (uint32_t) x1, (uint32_t) x2, (uint32_t) x3, |
| 84 | (uint32_t) x4, handle); |
Bence Szépkúti | 16362c6 | 2019-10-24 15:53:23 +0200 | [diff] [blame] | 85 | #else |
| 86 | /* State switch denied */ |
| 87 | SMC_RET1(handle, STATE_SW_E_DENIED); |
| 88 | #endif /* __aarch64__ */ |
Jeenu Viswambharan | bc1a929 | 2017-02-16 14:55:15 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | case ARM_SIP_SVC_CALL_COUNT: |
| 92 | /* PMF calls */ |
| 93 | call_count += PMF_NUM_SMC_CALLS; |
| 94 | |
| 95 | /* State switch call */ |
| 96 | call_count += 1; |
| 97 | |
| 98 | SMC_RET1(handle, call_count); |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 99 | |
| 100 | case ARM_SIP_SVC_UID: |
| 101 | /* Return UID to the caller */ |
| 102 | SMC_UUID_RET(handle, arm_sip_svc_uid); |
| 103 | |
| 104 | case ARM_SIP_SVC_VERSION: |
| 105 | /* Return the version of current implementation */ |
| 106 | SMC_RET2(handle, ARM_SIP_SVC_VERSION_MAJOR, ARM_SIP_SVC_VERSION_MINOR); |
| 107 | |
| 108 | default: |
| 109 | WARN("Unimplemented ARM SiP Service Call: 0x%x \n", smc_fid); |
| 110 | SMC_RET1(handle, SMC_UNK); |
| 111 | } |
| 112 | |
| 113 | } |
| 114 | |
| 115 | |
| 116 | /* Define a runtime service descriptor for fast SMC calls */ |
| 117 | DECLARE_RT_SVC( |
| 118 | arm_sip_svc, |
| 119 | OEN_SIP_START, |
| 120 | OEN_SIP_END, |
| 121 | SMC_TYPE_FAST, |
| 122 | arm_sip_setup, |
| 123 | arm_sip_handler |
| 124 | ); |