1 /*
2 * Copyright (c) 2014-2024, STMicroelectronics - All Rights Reserved
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #include <stdbool.h>
8 #include <stdint.h>
9
10 #include <common/debug.h>
11 #include <common/runtime_svc.h>
12 #include <drivers/scmi-msg.h>
13 #include <lib/psci/psci.h>
14 #include <platform_def.h>
15 #include <tools_share/uuid.h>
16
17 #include <stm32mp_svc_setup.h>
18
19 /* STM32 SiP Service UUID */
20 DEFINE_SVC_UUID2(stm32_sip_svc_uid,
21 0xa778aa50, 0xf49b, 0x144a, 0x8a, 0x5e,
22 0x26, 0x4d, 0x59, 0x94, 0xc2, 0x14);
23
24 /* Setup STM32MP Standard Services */
stm32mp_svc_setup(void)25 static int32_t stm32mp_svc_setup(void)
26 {
27 /*
28 * PSCI is the only specification implemented as a Standard Service.
29 * Invoke PSCI setup from here.
30 */
31 return 0;
32 }
33
34 /*
35 * Top-level Standard Service SMC handler. This handler will dispatch the SMC
36 * to the correct feature handler or default call a platform handler
37 */
stm32mp_svc_smc_handler(uint32_t smc_fid,u_register_t x1,u_register_t x2,u_register_t x3,u_register_t x4,void * cookie,void * handle,u_register_t flags)38 static uintptr_t stm32mp_svc_smc_handler(uint32_t smc_fid, u_register_t x1,
39 u_register_t x2, u_register_t x3,
40 u_register_t x4, void *cookie,
41 void *handle, u_register_t flags)
42 {
43 uint32_t ret1 = 0U, ret2 = 0U;
44 bool ret_uid = false, ret2_enabled = false;
45
46 switch (smc_fid) {
47 case STM32_SIP_SVC_UID:
48 /* Return UUID to the caller */
49 ret_uid = true;
50 break;
51
52 case STM32_SIP_SVC_VERSION:
53 /* Return the version of current implementation */
54 ret1 = STM32_SIP_SVC_VERSION_MAJOR;
55 ret2 = STM32_SIP_SVC_VERSION_MINOR;
56 ret2_enabled = true;
57 break;
58 default:
59 plat_svc_smc_handler(smc_fid, x1, x2, x3, x4, &ret1, &ret2, &ret2_enabled, flags);
60 break;
61 }
62
63 if (ret_uid) {
64 SMC_UUID_RET(handle, stm32_sip_svc_uid);
65 }
66
67 if (ret2_enabled) {
68 SMC_RET2(handle, ret1, ret2);
69 }
70
71 SMC_RET1(handle, ret1);
72 }
73
74 /* Register Standard Service Calls as runtime service */
75 DECLARE_RT_SVC(stm32mp_sip_svc,
76 OEN_SIP_START,
77 OEN_SIP_END,
78 SMC_TYPE_FAST,
79 stm32mp_svc_setup,
80 stm32mp_svc_smc_handler
81 );
82