xref: /rk3399_ARM-atf/plat/rockchip/rk3399/drivers/secure/secure.h (revision ccdc044acfced5ae754d865b41e3064ff96f2d0c)
1e3525114SXing Zheng /*
2e3525114SXing Zheng  * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
3e3525114SXing Zheng  *
4e3525114SXing Zheng  * Redistribution and use in source and binary forms, with or without
5e3525114SXing Zheng  * modification, are permitted provided that the following conditions are met:
6e3525114SXing Zheng  *
7e3525114SXing Zheng  * Redistributions of source code must retain the above copyright notice, this
8e3525114SXing Zheng  * list of conditions and the following disclaimer.
9e3525114SXing Zheng  *
10e3525114SXing Zheng  * Redistributions in binary form must reproduce the above copyright notice,
11e3525114SXing Zheng  * this list of conditions and the following disclaimer in the documentation
12e3525114SXing Zheng  * and/or other materials provided with the distribution.
13e3525114SXing Zheng  *
14e3525114SXing Zheng  * Neither the name of ARM nor the names of its contributors may be used
15e3525114SXing Zheng  * to endorse or promote products derived from this software without specific
16e3525114SXing Zheng  * prior written permission.
17e3525114SXing Zheng  *
18e3525114SXing Zheng  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19e3525114SXing Zheng  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20e3525114SXing Zheng  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21e3525114SXing Zheng  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22e3525114SXing Zheng  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23e3525114SXing Zheng  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24e3525114SXing Zheng  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25e3525114SXing Zheng  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26e3525114SXing Zheng  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27e3525114SXing Zheng  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28e3525114SXing Zheng  * POSSIBILITY OF SUCH DAMAGE.
29e3525114SXing Zheng  */
30e3525114SXing Zheng 
31e3525114SXing Zheng #ifndef __PLAT_ROCKCHIP_RK3399_DRIVER_SECURE_H__
32e3525114SXing Zheng #define __PLAT_ROCKCHIP_RK3399_DRIVER_SECURE_H__
33e3525114SXing Zheng 
34e3525114SXing Zheng /**************************************************
35e3525114SXing Zheng  * sgrf reg, offset
36e3525114SXing Zheng  **************************************************/
37e3525114SXing Zheng #define SGRF_SOC_CON0_1(n)		(0xc000 + (n) * 4)
38e3525114SXing Zheng #define SGRF_SOC_CON3_7(n)		(0xe00c + ((n) - 3) * 4)
39e3525114SXing Zheng #define SGRF_SOC_CON8_15(n)		(0x8020 + ((n) - 8) * 4)
40e3525114SXing Zheng #define SGRF_SOC_CON(n) 		(n < 3 ? SGRF_SOC_CON0_1(n) :\
41e3525114SXing Zheng 						(n < 8 ? SGRF_SOC_CON3_7(n) :\
42e3525114SXing Zheng 							 SGRF_SOC_CON8_15(n)))
43e3525114SXing Zheng 
44e3525114SXing Zheng #define SGRF_PMU_SLV_CON0_1(n)		(0xc240 + ((n) - 0) * 4)
45e3525114SXing Zheng #define SGRF_SLV_SECURE_CON0_4(n)	(0xe3c0 + ((n) - 0) * 4)
46e3525114SXing Zheng #define SGRF_DDRRGN_CON0_16(n)		((n) * 4)
47e3525114SXing Zheng #define SGRF_DDRRGN_CON20_34(n)		(0x50 + ((n) - 20) * 4)
48e3525114SXing Zheng 
49e3525114SXing Zheng /* All of master in ns */
50e3525114SXing Zheng #define SGRF_SOC_ALLMST_NS		0xffff
51e3525114SXing Zheng 
52e3525114SXing Zheng /* security config for slave */
53e3525114SXing Zheng #define SGRF_SLV_S_WMSK			0xffff0000
54e3525114SXing Zheng #define SGRF_SLV_S_ALL_NS		0x0
55e3525114SXing Zheng 
56e3525114SXing Zheng /* security config pmu slave ip */
57e3525114SXing Zheng /* All of slaves  is ns */
58e3525114SXing Zheng #define SGRF_PMU_SLV_S_NS		BIT_WITH_WMSK(0)
59e3525114SXing Zheng /* slaves secure attr is configed */
60e3525114SXing Zheng #define SGRF_PMU_SLV_S_CFGED		WMSK_BIT(0)
61e3525114SXing Zheng #define SGRF_PMU_SLV_CRYPTO1_NS		WMSK_BIT(1)
62e3525114SXing Zheng 
63e3525114SXing Zheng #define SGRF_PMUSRAM_S			BIT(8)
64e3525114SXing Zheng 
65*ccdc044aSXing Zheng #define SGRF_INTSRAM_S			BIT(13)
66*ccdc044aSXing Zheng 
67e3525114SXing Zheng /* ddr region */
68e3525114SXing Zheng #define SGRF_DDR_RGN_0_16_WMSK		0x0fff  /* DDR RGN 0~16 size mask */
69e3525114SXing Zheng 
70e3525114SXing Zheng #define SGRF_DDR_RGN_DPLL_CLK		BIT_WITH_WMSK(15) /* DDR PLL output clock */
71e3525114SXing Zheng #define SGRF_DDR_RGN_RTC_CLK		BIT_WITH_WMSK(14) /* 32K clock for DDR PLL */
72e3525114SXing Zheng 
73e3525114SXing Zheng /* All security of the DDR RGNs are bypass */
74e3525114SXing Zheng #define SGRF_DDR_RGN_BYPS		BIT_WITH_WMSK(9)
75e3525114SXing Zheng /* All security of the DDR RGNs are not bypass */
76e3525114SXing Zheng #define SGRF_DDR_RGN_NO_BYPS		WMSK_BIT(9)
77e3525114SXing Zheng 
78e3525114SXing Zheng /* The MST access the ddr rgn n with secure attribution */
79e3525114SXing Zheng #define SGRF_L_MST_S_DDR_RGN(n)		BIT_WITH_WMSK((n))
80e3525114SXing Zheng /* bits[16:8]*/
81e3525114SXing Zheng #define SGRF_H_MST_S_DDR_RGN(n)		BIT_WITH_WMSK((n) + 8)
82e3525114SXing Zheng 
83e3525114SXing Zheng #define SGRF_PMU_CON0			0x0c100
84e3525114SXing Zheng #define SGRF_PMU_CON(n)   		(SGRF_PMU_CON0 + (n) * 4)
85e3525114SXing Zheng 
86e3525114SXing Zheng /**************************************************
87e3525114SXing Zheng  * secure timer
88e3525114SXing Zheng  **************************************************/
89e3525114SXing Zheng /* chanal0~5 */
90e3525114SXing Zheng #define STIMER0_CHN_BASE(n)		(STIME_BASE + 0x20 * (n))
91e3525114SXing Zheng /* chanal6~11 */
92e3525114SXing Zheng #define STIMER1_CHN_BASE(n)		(STIME_BASE + 0x8000 + 0x20 * (n))
93e3525114SXing Zheng 
94e3525114SXing Zheng  /* low 32 bits */
95e3525114SXing Zheng #define TIMER_END_COUNT0		0x00
96e3525114SXing Zheng  /* high 32 bits */
97e3525114SXing Zheng #define TIMER_END_COUNT1		0x04
98e3525114SXing Zheng 
99e3525114SXing Zheng #define TIMER_CURRENT_VALUE0		0x08
100e3525114SXing Zheng #define TIMER_CURRENT_VALUE1		0x0C
101e3525114SXing Zheng 
102e3525114SXing Zheng  /* low 32 bits */
103e3525114SXing Zheng #define TIMER_INIT_COUNT0		0x10
104e3525114SXing Zheng  /* high 32 bits */
105e3525114SXing Zheng #define TIMER_INIT_COUNT1		0x14
106e3525114SXing Zheng 
107e3525114SXing Zheng #define TIMER_INTSTATUS			0x18
108e3525114SXing Zheng #define TIMER_CONTROL_REG		0x1c
109e3525114SXing Zheng 
110e3525114SXing Zheng #define TIMER_EN			0x1
111e3525114SXing Zheng 
112e3525114SXing Zheng #define TIMER_FMODE			(0x0 << 1)
113e3525114SXing Zheng #define TIMER_RMODE			(0x1 << 1)
114e3525114SXing Zheng 
115e3525114SXing Zheng /**************************************************
116e3525114SXing Zheng  * secure WDT
117e3525114SXing Zheng  **************************************************/
118e3525114SXing Zheng #define PCLK_WDT_CA53_GATE_SHIFT	8
119e3525114SXing Zheng #define PCLK_WDT_CM0_GATE_SHIFT		10
120e3525114SXing Zheng 
121e3525114SXing Zheng /* export secure operating APIs */
122e3525114SXing Zheng void secure_watchdog_disable(void);
123e3525114SXing Zheng void secure_watchdog_enable(void);
124e3525114SXing Zheng void secure_timer_init(void);
125e3525114SXing Zheng void secure_sgrf_init(void);
126e3525114SXing Zheng void secure_sgrf_ddr_rgn_init(void);
127e3525114SXing Zheng 
128e3525114SXing Zheng #endif /* __PLAT_ROCKCHIP_RK3399_DRIVER_SECURE_H__ */
129