blob: d4ed44525831d09cf01e2d3cf5818f2a55e10bb7 [file] [log] [blame]
Yann Gautier05be8d82019-01-17 14:51:25 +01001/*
2 * Copyright (c) 2014-2019, 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>
Peng Fan8053e072021-01-20 11:04:08 +080012#include <drivers/scmi-msg.h>
Yann Gautier05be8d82019-01-17 14:51:25 +010013#include <lib/psci/psci.h>
14#include <tools_share/uuid.h>
15
16#include <stm32mp1_smc.h>
17
Yann Gautier52448ab2019-01-17 14:53:24 +010018#include "bsec_svc.h"
19
Yann Gautier05be8d82019-01-17 14:51:25 +010020/* STM32 SiP Service UUID */
21DEFINE_SVC_UUID2(stm32_sip_svc_uid,
22 0xa778aa50, 0xf49b, 0x144a, 0x8a, 0x5e,
23 0x26, 0x4d, 0x59, 0x94, 0xc2, 0x14);
24
25/* Setup STM32MP1 Standard Services */
26static int32_t stm32mp1_svc_setup(void)
27{
28 /*
29 * PSCI is the only specification implemented as a Standard Service.
30 * Invoke PSCI setup from here.
31 */
32 return 0;
33}
34
35/*
36 * Top-level Standard Service SMC handler. This handler will in turn dispatch
37 * calls to PSCI SMC handler.
38 */
39static uintptr_t stm32mp1_svc_smc_handler(uint32_t smc_fid, u_register_t x1,
40 u_register_t x2, u_register_t x3,
41 u_register_t x4, void *cookie,
42 void *handle, u_register_t flags)
43{
44 uint32_t ret1 = 0U, ret2 = 0U;
45 bool ret_uid = false, ret2_enabled = false;
46
47 switch (smc_fid) {
48 case STM32_SIP_SVC_CALL_COUNT:
49 ret1 = STM32_COMMON_SIP_NUM_CALLS;
50 break;
51
52 case STM32_SIP_SVC_UID:
53 /* Return UUID to the caller */
54 ret_uid = true;
55 break;
56
57 case STM32_SIP_SVC_VERSION:
58 /* Return the version of current implementation */
59 ret1 = STM32_SIP_SVC_VERSION_MAJOR;
60 ret2 = STM32_SIP_SVC_VERSION_MINOR;
61 ret2_enabled = true;
62 break;
63
Yann Gautier52448ab2019-01-17 14:53:24 +010064 case STM32_SMC_BSEC:
65 ret1 = bsec_main(x1, x2, x3, &ret2);
66 ret2_enabled = true;
67 break;
68
Etienne Carriere34f0e932020-07-16 17:36:18 +020069 case STM32_SIP_SMC_SCMI_AGENT0:
70 scmi_smt_fastcall_smc_entry(0);
71 break;
72 case STM32_SIP_SMC_SCMI_AGENT1:
73 scmi_smt_fastcall_smc_entry(1);
74 break;
75
Yann Gautier05be8d82019-01-17 14:51:25 +010076 default:
77 WARN("Unimplemented STM32MP1 Service Call: 0x%x\n", smc_fid);
78 ret1 = SMC_UNK;
79 break;
80 }
81
82 if (ret_uid) {
83 SMC_UUID_RET(handle, stm32_sip_svc_uid);
84 }
85
86 if (ret2_enabled) {
87 SMC_RET2(handle, ret1, ret2);
88 }
89
90 SMC_RET1(handle, ret1);
91}
92
93/* Register Standard Service Calls as runtime service */
94DECLARE_RT_SVC(stm32mp1_sip_svc,
95 OEN_SIP_START,
96 OEN_SIP_END,
97 SMC_TYPE_FAST,
98 stm32mp1_svc_setup,
99 stm32mp1_svc_smc_handler
100);