firmware: rockchip: update sip interface
[firefly-linux-kernel-4.4.55.git] / include / linux / rockchip / rockchip_sip.h
1 /* Copyright (c) 2016, Fuzhou Rockchip Electronics Co., Ltd
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 and
5  * only version 2 as published by the Free Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  */
12 #ifndef __ROCKCHIP_SIP_H
13 #define __ROCKCHIP_SIP_H
14
15 #include <linux/arm-smccc.h>
16 #include <linux/io.h>
17
18 /* SMC function IDs for SiP Service queries, compatible with kernel-3.10 */
19 #define SIP_ATF_VERSION                 0x82000001
20 #define SIP_ACCESS_REG                  0x82000002
21 #define SIP_SUSPEND_MODE                0x82000003
22 #define SIP_PENDING_CPUS                0x82000004
23 #define SIP_UARTDBG_CFG                 0x82000005
24 #define SIP_UARTDBG_CFG64               0xc2000005
25 #define SIP_MCU_EL3FIQ_CFG              0x82000006
26 #define SIP_ACCESS_CHIP_STATE64         0xc2000006
27 #define SIP_SECURE_MEM_CONFIG           0x82000007
28 #define SIP_ACCESS_CHIP_EXTRA_STATE64   0xc2000007
29 #define SIP_DDR_CFG                     0x82000008
30 #define SIP_SHARE_MEM                   0x82000009
31 #define SIP_SIP_VERSION                 0x8200000a
32 #define SIP_REMOTECTL_CFG               0x8200000b
33
34 /* Trust firmware version */
35 #define ATF_VER_MAJOR(ver)              (((ver) >> 16) & 0xffff)
36 #define ATF_VER_MINOR(ver)              (((ver) >> 0) & 0xffff)
37
38 /* SIP_ACCESS_REG: read or write */
39 #define SECURE_REG_RD                   0x0
40 #define SECURE_REG_WR                   0x1
41
42 /* Fiq debugger share memory: 8KB enough */
43 #define FIQ_UARTDBG_PAGE_NUMS           2
44 #define FIQ_UARTDBG_SHARE_MEM_SIZE      ((FIQ_UARTDBG_PAGE_NUMS) * 4096)
45
46 /* Error return code */
47 #define IS_SIP_ERROR(x)                 (!!(x))
48
49 #define SIP_RET_SUCCESS                 0
50 #define SIP_RET_SMC_UNKNOWN             -1
51 #define SIP_RET_NOT_SUPPORTED           -2
52 #define SIP_RET_INVALID_PARAMS          -3
53 #define SIP_RET_INVALID_ADDRESS         -4
54 #define SIP_RET_DENIED                  -5
55
56 /* SIP_UARTDBG_CFG64 call types */
57 #define UARTDBG_CFG_INIT                0xf0
58 #define UARTDBG_CFG_OSHDL_TO_OS         0xf1
59 #define UARTDBG_CFG_OSHDL_CPUSW         0xf3
60 #define UARTDBG_CFG_OSHDL_DEBUG_ENABLE  0xf4
61 #define UARTDBG_CFG_OSHDL_DEBUG_DISABLE 0xf5
62 #define UARTDBG_CFG_PRINT_PORT          0xf7
63 #define UARTDBG_CFG_FIQ_ENABEL          0xf8
64 #define UARTDBG_CFG_FIQ_DISABEL         0xf9
65
66 /* SIP_SUSPEND_MODE32 call types */
67 #define SUSPEND_MODE_CONFIG             0x01
68 #define WKUP_SOURCE_CONFIG              0x02
69 #define PWM_REGULATOR_CONFIG            0x03
70 #define GPIO_POWER_CONFIG               0x04
71 #define SUSPEND_DEBUG_ENABLE            0x05
72 #define APIOS_SUSPEND_CONFIG            0x06
73 #define VIRTUAL_POWEROFF                0x07
74
75 /* SIP_REMOTECTL_CFG call types */
76 #define REMOTECTL_SET_IRQ               0xf0
77 #define REMOTECTL_SET_PWM_CH            0xf1
78 #define REMOTECTL_SET_PWRKEY            0xf2
79 #define REMOTECTL_GET_WAKEUP_STATE      0xf3
80 #define REMOTECTL_ENABLE                0xf4
81 /* wakeup state */
82 #define REMOTECTL_PWRKEY_WAKEUP         0xdeadbeaf
83
84 /* Share mem page types */
85 typedef enum {
86         SHARE_PAGE_TYPE_INVALID = 0,
87         SHARE_PAGE_TYPE_UARTDBG,
88         SHARE_PAGE_TYPE_MAX,
89 } share_page_type_t;
90
91 /*
92  * Rules: struct arm_smccc_res contains result and data, details:
93  *
94  * a0: error code(0: success, !0: error);
95  * a1~a3: data
96  */
97 struct arm_smccc_res sip_smc_get_atf_version(void);
98 struct arm_smccc_res sip_smc_get_sip_version(void);
99 struct arm_smccc_res sip_smc_ddr_cfg(u32 arg0, u32 arg1, u32 arg2);
100 struct arm_smccc_res sip_smc_request_share_mem(u32 page_num,
101                                                share_page_type_t page_type);
102 struct arm_smccc_res sip_smc_mcu_el3fiq(u32 arg0, u32 arg1, u32 arg2);
103
104 int sip_smc_set_suspend_mode(u32 ctrl, u32 config1, u32 config2);
105 int sip_smc_virtual_poweroff(void);
106 #ifdef CONFIG_ROCKCHIP_SIP
107 int sip_smc_secure_reg_write(u32 addr_phy, u32 val);
108 u32 sip_smc_secure_reg_read(u32 addr_phy);
109 #else
110 u32 sip_smc_secure_reg_read(u32 addr_phy) { return 0; }
111 int sip_smc_secure_reg_write(u32 addr_phy, u32 val) { return 0; }
112 #endif
113 /***************************fiq debugger **************************************/
114 void sip_fiq_debugger_enable_fiq(bool enable, uint32_t tgt_cpu);
115 void sip_fiq_debugger_enable_debug(bool enable);
116 int sip_fiq_debugger_uart_irq_tf_init(u32 irq_id, void *callback_fn);
117 int sip_fiq_debugger_set_print_port(u32 port_phyaddr, u32 baudrate);
118 int sip_fiq_debugger_request_share_memory(void);
119 int sip_fiq_debugger_get_target_cpu(void);
120 int sip_fiq_debugger_switch_cpu(u32 cpu);
121 int sip_fiq_debugger_is_enabled(void);
122
123 /* optee cpu_context */
124 struct sm_nsec_ctx {
125         u32 usr_sp;
126         u32 usr_lr;
127         u32 irq_spsr;
128         u32 irq_sp;
129         u32 irq_lr;
130         u32 svc_spsr;
131         u32 svc_sp;
132         u32 svc_lr;
133         u32 abt_spsr;
134         u32 abt_sp;
135         u32 abt_lr;
136         u32 und_spsr;
137         u32 und_sp;
138         u32 und_lr;
139         u32 mon_lr;
140         u32 mon_spsr;
141         u32 r4;
142         u32 r5;
143         u32 r6;
144         u32 r7;
145         u32 r8;
146         u32 r9;
147         u32 r10;
148         u32 r11;
149         u32 r12;
150         u32 r0;
151         u32 r1;
152         u32 r2;
153         u32 r3;
154 };
155
156 #endif