blob: 684f95108155c7779ab4898a02f006ce05b91607 [file] [log] [blame]
developer8c327e82022-05-29 22:25:44 +08001/*
developer12872762022-12-06 15:20:31 +08002 * Copyright (c) 2022-2023, ARM Limited and Contributors. All rights reserved.
developer8c327e82022-05-29 22:25:44 +08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef MTK_SIP_SVC_H
8#define MTK_SIP_SVC_H
9
10#include <stdint.h>
11#include <lib/smccc.h>
12#include <mtk_sip_def.h>
13
14/* SMC function IDs for SiP Service queries */
15#define SIP_SVC_CALL_COUNT U(0x8200ff00)
16#define SIP_SVC_UID U(0x8200ff01)
17/* 0x8200ff02 is reserved */
18#define SIP_SVC_VERSION U(0x8200ff03)
19
20/* MediaTek SiP Service Calls version numbers */
21#define MTK_SIP_SVC_VERSION_MAJOR U(0x0)
22#define MTK_SIP_SVC_VERSION_MINOR U(0x1)
23
24/* Number of MediaTek SiP Calls implemented */
25#define MTK_COMMON_SIP_NUM_CALLS U(4)
26
27/* MediaTek SiP Service Calls function IDs */
28#define MTK_SIP_SET_AUTHORIZED_SECURE_REG U(0x82000001)
29
30#define SMC_ID_EXPAND_AS_ENUM(_smc_id, _smc_num) \
31 _smc_id##_AARCH32 = ((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT) | \
32 ((0) << FUNCID_CC_SHIFT) | \
33 (OEN_SIP_START << FUNCID_OEN_SHIFT) | \
34 ((_smc_num) << FUNCID_NUM_SHIFT)), \
35 _smc_id##_AARCH64 = ((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT) | \
36 ((1) << FUNCID_CC_SHIFT) | \
37 (OEN_SIP_START << FUNCID_OEN_SHIFT) | \
38 ((_smc_num) << FUNCID_NUM_SHIFT)),
39
40#define SMC_ID_EXPAND_AS_EXTERN_SMC_INDEX(_smc_id, _smc_num) \
41 extern short _smc_id##_descriptor_index;
42
43/* Bind SMC handler with SMC ID */
44#define DECLARE_SMC_HANDLER(_smc_id, _smc_handler) \
45 const struct smc_descriptor _smc_id##_descriptor \
46 __used \
47 __aligned(sizeof(void *)) \
48 __section(".mtk_smc_descriptor_pool") = { \
49 .smc_handler = _smc_handler, \
50 .smc_name = #_smc_id, \
51 .smc_id_aarch32 = _smc_id##_AARCH32, \
52 .smc_id_aarch64 = _smc_id##_AARCH64, \
53 .smc_descriptor_index = &_smc_id##_descriptor_index \
54 }
55
56MTK_SIP_SMC_FROM_BL33_TABLE(SMC_ID_EXPAND_AS_EXTERN_SMC_INDEX);
57MTK_SIP_SMC_FROM_NS_EL1_TABLE(SMC_ID_EXPAND_AS_EXTERN_SMC_INDEX);
developer12872762022-12-06 15:20:31 +080058MTK_SIP_SMC_FROM_S_EL1_TABLE(SMC_ID_EXPAND_AS_EXTERN_SMC_INDEX);
developer8c327e82022-05-29 22:25:44 +080059
60/* Expand SiP SMC ID table as enum */
61enum {
62 MTK_SIP_SMC_FROM_BL33_TABLE(SMC_ID_EXPAND_AS_ENUM)
63 MTK_SIP_SMC_FROM_NS_EL1_TABLE(SMC_ID_EXPAND_AS_ENUM)
developer12872762022-12-06 15:20:31 +080064 MTK_SIP_SMC_FROM_S_EL1_TABLE(SMC_ID_EXPAND_AS_ENUM)
developer8c327e82022-05-29 22:25:44 +080065 MTK_SIP_SMC_MAX_NUMBER
66};
67
68/* MediaTek SiP Calls error code */
69enum {
70 MTK_SIP_E_SUCCESS = 0,
71 MTK_SIP_E_INVALID_PARAM = -1,
72 MTK_SIP_E_NOT_SUPPORTED = -2,
73 MTK_SIP_E_INVALID_RANGE = -3,
74 MTK_SIP_E_PERMISSION_DENY = -4,
75 MTK_SIP_E_LOCK_FAIL = -5,
76};
77
78struct smccc_res {
79 uint64_t a1;
80 uint64_t a2;
81 uint64_t a3;
82};
83
84typedef uintptr_t (*smc_handler_t)(u_register_t,
85 u_register_t,
86 u_register_t,
87 u_register_t,
88 void *,
89 struct smccc_res *);
90
91struct smc_descriptor {
92 smc_handler_t smc_handler;
93 const uint32_t smc_id_aarch32;
94 const uint32_t smc_id_aarch64;
95 const char *smc_name;
96 short *const smc_descriptor_index;
97};
98
99/*
Elyes Haouas2be03c02023-02-13 09:14:48 +0100100 * This function should be implemented in MediaTek SOC directory. It fulfills
developer8c327e82022-05-29 22:25:44 +0800101 * MTK_SIP_SET_AUTHORIZED_SECURE_REG SiP call by checking the sreg with the
102 * predefined secure register list, if a match was found, set val to sreg.
103 *
104 * Return MTK_SIP_E_SUCCESS on success, and MTK_SIP_E_INVALID_PARAM on failure.
105 */
106uint64_t mt_sip_set_authorized_sreg(uint32_t sreg, uint32_t val);
107
108#endif /* MTK_SIP_SVC_H */