blob: c8f480f18d1c7f8b548f7f3a0afa377a421d11af [file] [log] [blame]
dp-arm1cebefd2016-09-19 11:21:03 +01001/*
Ambroise Vincent9660dc12019-07-12 13:47:03 +01002 * Copyright (c) 2016-2019, ARM Limited and Contributors. All rights reserved.
dp-arm1cebefd2016-09-19 11:21:03 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
dp-arm1cebefd2016-09-19 11:21:03 +01005 */
6
dp-arm1cebefd2016-09-19 11:21:03 +01007#include <stdint.h>
dp-arm1cebefd2016-09-19 11:21:03 +01008
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009#include <common/debug.h>
10#include <common/runtime_svc.h>
Ambroise Vincent9660dc12019-07-12 13:47:03 +010011#include <lib/debugfs.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000012#include <lib/pmf/pmf.h>
Antonio Nino Diazbd7b7402019-01-25 14:30:04 +000013#include <plat/arm/common/arm_sip_svc.h>
14#include <plat/arm/common/plat_arm.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000015#include <tools_share/uuid.h>
16
dp-arm1cebefd2016-09-19 11:21:03 +010017/* ARM SiP Service UUID */
Roberto Vargaseace8f12018-04-26 13:36:53 +010018DEFINE_SVC_UUID2(arm_sip_svc_uid,
19 0x556d75e2, 0x6033, 0xb54b, 0xb5, 0x75,
20 0x62, 0x79, 0xfd, 0x11, 0x37, 0xff);
dp-arm1cebefd2016-09-19 11:21:03 +010021
22static int arm_sip_setup(void)
23{
Ambroise Vincent9660dc12019-07-12 13:47:03 +010024 if (pmf_setup() != 0) {
dp-arm1cebefd2016-09-19 11:21:03 +010025 return 1;
Ambroise Vincent9660dc12019-07-12 13:47:03 +010026 }
27
28#if USE_DEBUGFS
29
30 if (debugfs_smc_setup() != 0) {
31 return 1;
32 }
33
34#endif /* USE_DEBUGFS */
35
dp-arm1cebefd2016-09-19 11:21:03 +010036 return 0;
37}
38
39/*
40 * This function handles ARM defined SiP Calls
41 */
42static 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 Viswambharanbc1a9292017-02-16 14:55:15 +000051 int call_count = 0;
52
dp-arm1cebefd2016-09-19 11:21:03 +010053 /*
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 Vincent9660dc12019-07-12 13:47:03 +010062#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-arm1cebefd2016-09-19 11:21:03 +010071 switch (smc_fid) {
Jeenu Viswambharanbc1a9292017-02-16 14:55:15 +000072 case ARM_SIP_SVC_EXE_STATE_SWITCH: {
73 u_register_t pc;
74
75 /* Allow calls from non-secure only */
76 if (!is_caller_non_secure(flags))
77 SMC_RET1(handle, STATE_SW_E_DENIED);
78
79 /* Validate supplied entry point */
80 pc = (u_register_t) ((x1 << 32) | (uint32_t) x2);
Antonio Nino Diaz05fdb832018-10-25 16:53:04 +010081 if (arm_validate_ns_entrypoint(pc) != 0)
Jeenu Viswambharanbc1a9292017-02-16 14:55:15 +000082 SMC_RET1(handle, STATE_SW_E_PARAM);
83
dp-arm1cebefd2016-09-19 11:21:03 +010084 /*
Jeenu Viswambharanbc1a9292017-02-16 14:55:15 +000085 * Pointers used in execution state switch are all 32 bits wide
dp-arm1cebefd2016-09-19 11:21:03 +010086 */
Jeenu Viswambharan210f0a82018-08-02 10:14:12 +010087 return (uintptr_t) arm_execution_state_switch(smc_fid,
88 (uint32_t) x1, (uint32_t) x2, (uint32_t) x3,
89 (uint32_t) x4, handle);
Jeenu Viswambharanbc1a9292017-02-16 14:55:15 +000090 }
91
92 case ARM_SIP_SVC_CALL_COUNT:
93 /* PMF calls */
94 call_count += PMF_NUM_SMC_CALLS;
95
96 /* State switch call */
97 call_count += 1;
98
99 SMC_RET1(handle, call_count);
dp-arm1cebefd2016-09-19 11:21:03 +0100100
101 case ARM_SIP_SVC_UID:
102 /* Return UID to the caller */
103 SMC_UUID_RET(handle, arm_sip_svc_uid);
104
105 case ARM_SIP_SVC_VERSION:
106 /* Return the version of current implementation */
107 SMC_RET2(handle, ARM_SIP_SVC_VERSION_MAJOR, ARM_SIP_SVC_VERSION_MINOR);
108
109 default:
110 WARN("Unimplemented ARM SiP Service Call: 0x%x \n", smc_fid);
111 SMC_RET1(handle, SMC_UNK);
112 }
113
114}
115
116
117/* Define a runtime service descriptor for fast SMC calls */
118DECLARE_RT_SVC(
119 arm_sip_svc,
120 OEN_SIP_START,
121 OEN_SIP_END,
122 SMC_TYPE_FAST,
123 arm_sip_setup,
124 arm_sip_handler
125);