xref: /rk3399_rockchip-uboot/arch/arm/include/asm/arch-rockchip/rockchip_smccc.h (revision a47be44dca4e168635e6f4dd8302a2cac0aa3495)
1 /*
2  * (C) Copyright 2017 Rockchip Electronics Co., Ltd
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6 
7 #ifndef __ROCKCHIP_SMCCC_H__
8 #define __ROCKCHIP_SMCCC_H__
9 
10 #include <linux/arm-smccc.h>
11 
12 /* Rockchip platform SiP call ID */
13 #define SIP_ATF_VERSION			0x82000001
14 #define SIP_ACCESS_REG			0x82000002
15 #define SIP_SUSPEND_MODE		0x82000003
16 #define SIP_PENDING_CPUS		0x82000004
17 #define SIP_UARTDBG_CFG			0x82000005
18 #define SIP_UARTDBG_CFG64		0xc2000005
19 #define SIP_MCU_EL3FIQ_CFG		0x82000006
20 #define SIP_ACCESS_CHIP_STATE64		0xc2000006
21 #define SIP_SECURE_MEM_CONFIG		0x82000007
22 #define SIP_ACCESS_CHIP_EXTRA_STATE64	0xc2000007
23 #define SIP_DRAM_CONFIG			0x82000008
24 #define SIP_SHARE_MEM			0x82000009
25 #define SIP_SIP_VERSION			0x8200000a
26 #define SIP_REMOTECTL_CFG		0x8200000b
27 #define SIP_VPU_RESET			0x8200000c
28 #define SIP_SOC_BUS_DIV			0x8200000d
29 #define SIP_LAST_LOG			0x8200000e
30 #define SIP_ACCESS_MEM_OS_REG		0x8200000f
31 #define SIP_AMP_CFG			0x82000022
32 #define SIP_HDCP_CONFIG			0x82000025
33 #define SIP_MCU_CFG			0x82000028
34 
35 #define ROCKCHIP_SIP_CONFIG_DRAM_INIT		0x00
36 #define ROCKCHIP_SIP_CONFIG_DRAM_SET_RATE	0x01
37 #define ROCKCHIP_SIP_CONFIG_DRAM_ROUND_RATE	0x02
38 #define ROCKCHIP_SIP_CONFIG_DRAM_SET_AT_SR	0x03
39 #define ROCKCHIP_SIP_CONFIG_DRAM_GET_BW		0x04
40 #define ROCKCHIP_SIP_CONFIG_DRAM_GET_RATE	0x05
41 #define ROCKCHIP_SIP_CONFIG_DRAM_CLR_IRQ	0x06
42 #define ROCKCHIP_SIP_CONFIG_DRAM_SET_PARAM	0x07
43 #define ROCKCHIP_SIP_CONFIG_DRAM_GET_VERSION	0x08
44 #define ROCKCHIP_SIP_CONFIG_DRAM_POST_SET_RATE	0x09
45 #define ROCKCHIP_SIP_CONFIG_DRAM_SET_NOC_RL	0x0a
46 #define ROCKCHIP_SIP_CONFIG_DRAM_DEBUG		0x0b
47 #define ROCKCHIP_SIP_CONFIG_DRAM_MCU_START	0x0c
48 #define ROCKCHIP_SIP_CONFIG_DRAM_ECC		0x0d
49 #define ROCKCHIP_SIP_CONFIG_DRAM_GET_FREQ_INFO	0x0e
50 #define ROCKCHIP_SIP_CONFIG_DRAM_FSP_INIT	0x0f
51 
52 /* SIP_ACCESS_MEM_OS_REG child configs */
53 enum {
54 	RK_MEM_OS_REG_READ = 0,
55 	RK_MEM_OS_REG_WRITE,
56 };
57 
58 /* RK_SIP_MCU_CFG child configs, MCU ID */
59 #define ROCKCHIP_SIP_CONFIG_BUSMCU_0_ID		0x00
60 #define ROCKCHIP_SIP_CONFIG_BUSMCU_1_ID		0x01
61 #define ROCKCHIP_SIP_CONFIG_PMUMCU_0_ID		0x10
62 #define ROCKCHIP_SIP_CONFIG_DDRMCU_0_ID		0x20
63 #define ROCKCHIP_SIP_CONFIG_NPUMCU_0_ID		0x30
64 
65 /* RK_SIP_MCU_CFG child configs */
66 #define ROCKCHIP_SIP_CONFIG_MCU_CODE_START_ADDR		0x01
67 #define ROCKCHIP_SIP_CONFIG_MCU_EXPERI_START_ADDR	0x02
68 #define ROCKCHIP_SIP_CONFIG_MCU_SRAM_START_ADDR		0x03
69 #define ROCKCHIP_SIP_CONFIG_MCU_EXSRAM_START_ADDR	0x04
70 
71 /* Rockchip Sip version */
72 #define SIP_IMPLEMENT_V1                (1)
73 #define SIP_IMPLEMENT_V2                (2)
74 
75 /* Error return code */
76 #define IS_SIP_ERROR(x)			(!!(x))
77 
78 #define SIP_RET_SUCCESS			0
79 #define SIP_RET_SMC_UNKNOWN		-1
80 #define SIP_RET_NOT_SUPPORTED		-2
81 #define SIP_RET_INVALID_PARAMS		-3
82 #define SIP_RET_INVALID_ADDRESS		-4
83 #define SIP_RET_DENIED			-5
84 
85 /* SIP_ACCESS_REG: read or write */
86 #define SECURE_REG_RD			0x0
87 #define SECURE_REG_WR			0x1
88 
89 /* SIP_AMP_CFG */
90 #define AMP_PE_STATE			0x0
91 #define AMP_BOOT_ARG01			0x1
92 #define AMP_BOOT_ARG23			0x2
93 
94 /* Share mem page types */
95 typedef enum {
96 	SHARE_PAGE_TYPE_INVALID = 0,
97 	SHARE_PAGE_TYPE_UARTDBG,
98 	SHARE_PAGE_TYPE_DDR,
99 	SHARE_PAGE_TYPE_DDRDBG,
100 	SHARE_PAGE_TYPE_DDRECC,
101 	SHARE_PAGE_TYPE_DDRFSP,
102 	SHARE_PAGE_TYPE_DDR_ADDRMAP,
103 	SHARE_PAGE_TYPE_LAST_LOG,
104 	SHARE_PAGE_TYPE_HDCP,
105 	SHARE_PAGE_TYPE_SLEEP,
106 	SHARE_PAGE_TYPE_MAX,
107 } share_page_type_t;
108 
109 /* hdcp config func */
110 typedef enum {
111 	HDCP_FUNC_STORAGE_ENCRYPT = 1,
112 	HDCP_FUNC_KEY_DECRYPT,
113 	HDCP_FUNC_KEY_LOAD,
114 	HDCP_FUNC_ENCRYPT_MODE
115 } sip_hdcp_func_t;
116 
117 /*
118  * sip_smc_set_suspend_mode() - Set U-Boot system suspend state before trap to trust.
119  *
120  * see kernel-4.4: drivers/soc/rockchip/rockchip_pm_config.c
121  */
122 int sip_smc_set_suspend_mode(unsigned long ctrl,
123 			     unsigned long config1,
124 			     unsigned long config2);
125 
126 int sip_smc_remotectl_config(unsigned long func, unsigned long data);
127 
128 /*
129  * sip_smc_access_mem_os_reg() - access mem os reg
130  */
131 int sip_smc_access_mem_os_reg(unsigned long func, unsigned long id,
132 			      unsigned long *val);
133 
134 /*
135  * sip_smc_amp_cfg() - config AMP
136  */
137 int sip_smc_amp_cfg(unsigned long func, unsigned long arg0, unsigned long arg1,
138 		    unsigned long arg2);
139 
140 /*
141  * sip_smc_dram() - Set dram configure for trust.
142  *
143  * see: ./drivers/ram/rockchip/rockchip_dmc.c
144  */
145 struct arm_smccc_res sip_smc_dram(unsigned long arg0,
146 				  unsigned long arg1,
147 				  unsigned long arg2);
148 
149 /*
150  * sip_smc_request_share_mem() - Request share memory from trust.
151  *
152  * @page_num:	page numbers
153  * @page_type:  page type, see: share_page_type_t
154  *
155  * @return arm_smccc_res structure, res.a0 equals 0 on success(res.a1 contains
156  *  share memory base address), otherwise failed.
157  */
158 struct arm_smccc_res sip_smc_request_share_mem(unsigned long page_num,
159 					       share_page_type_t page_type);
160 
161 /*
162  * sip_smc_secure_reg_read() - Read secure info(ddr/register...) from trust.
163  *
164  * @addr_phy:	address to read
165  *
166  * @return arm_smccc_res structure, res.a0 equals 0 on success(res.a1 contains
167  *  valid data), otherwise failed.
168  */
169 struct arm_smccc_res sip_smc_secure_reg_read(unsigned long addr_phy);
170 
171 /*
172  * sip_smc_secure_reg_write() - Write data to trust secure info(ddr/register...).
173  *
174  * @addr_phy:	address to write
175  * @val:	value to write
176  *
177  * @return 0 on success, otherwise failed.
178  */
179 int sip_smc_secure_reg_write(unsigned long addr_phy, unsigned long val);
180 
181 /*
182  * sip_smc_set_sip_version() - Set sip version to trust.
183  *
184  * @return 0 on success, otherwise failed.
185  */
186 int sip_smc_set_sip_version(unsigned long version);
187 
188 /*
189  * sip_smc_get_sip_version() - Get sip version to trust.
190  *
191  * @return arm_smccc_res structure, res.a0 equals 0 on success(res.a1 contains
192  *  sip version), otherwise failed.
193  */
194 struct arm_smccc_res sip_smc_get_sip_version(void);
195 
196 /*
197  * sip_smc_hdcp_config() - handle hdcp.
198  *
199  * @return  0 on success, otherwise failed.
200  */
201 int sip_smc_hdcp_config(unsigned long func,
202 			unsigned long arg1, unsigned long arg2);
203 
204 /*
205  * sip_smc_mcu_config() - handle mcu.
206  *
207  * @return  0 on success, otherwise failed.
208  */
209 int sip_smc_mcu_config(unsigned long mcu_id, unsigned long func, unsigned long arg2);
210 
211 /*
212  * psci_cpu_on() - Standard ARM PSCI cpu on call.
213  *
214  * @cpuid:		cpu id
215  * @entry_point:	boot entry point
216  *
217  * @return 0 on success, otherwise failed.
218  */
219 int psci_cpu_on(unsigned long cpuid, unsigned long entry_point);
220 
221 /*
222  * psci_cpu_off() - Standard ARM PSCI cpu off call.
223  *
224  * @state:		dummy, set 0 by default.
225  *
226  * @return 0 on success, otherwise failed.
227  */
228 int psci_cpu_off(uint32_t state);
229 
230 #ifdef CONFIG_ARM_CPU_SUSPEND
231 /*
232  * psci_system_suspend() - Standard ARM PSCI system suspend call.
233  *
234  * @unused:		unused now, always 0 recommend
235  *
236  * @return 0 on success, otherwise failed.
237  */
238 int psci_system_suspend(unsigned long unused);
239 #endif
240 
241 #endif
242