xref: /rk3399_ARM-atf/plat/allwinner/common/sunxi_security.c (revision 4ec1a2399cf6e182ba2828a40795912d20eca1ab)
1acb8b3caSAndre Przywara /*
2acb8b3caSAndre Przywara  * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
3acb8b3caSAndre Przywara  *
4acb8b3caSAndre Przywara  * SPDX-License-Identifier: BSD-3-Clause
5acb8b3caSAndre Przywara  */
6acb8b3caSAndre Przywara 
7acb8b3caSAndre Przywara #include <debug.h>
8acb8b3caSAndre Przywara #include <mmio.h>
9acb8b3caSAndre Przywara #include <sunxi_mmap.h>
10*4ec1a239SAndre Przywara #include <sunxi_private.h>
11acb8b3caSAndre Przywara 
12acb8b3caSAndre Przywara #ifdef SUNXI_SPC_BASE
13acb8b3caSAndre Przywara #define SPC_DECPORT_STA_REG(p)	(SUNXI_SPC_BASE + ((p) * 0x0c) + 0x4)
14acb8b3caSAndre Przywara #define SPC_DECPORT_SET_REG(p)	(SUNXI_SPC_BASE + ((p) * 0x0c) + 0x8)
15acb8b3caSAndre Przywara #define SPC_DECPORT_CLR_REG(p)	(SUNXI_SPC_BASE + ((p) * 0x0c) + 0xc)
16acb8b3caSAndre Przywara #endif
17acb8b3caSAndre Przywara 
18acb8b3caSAndre Przywara #define R_PRCM_SEC_SWITCH_REG	0x1d0
19acb8b3caSAndre Przywara #define DMA_SEC_REG		0x20
20acb8b3caSAndre Przywara 
21acb8b3caSAndre Przywara /*
22acb8b3caSAndre Przywara  * Setup the peripherals to be accessible by non-secure world.
23acb8b3caSAndre Przywara  * This will not work for the Secure Peripherals Controller (SPC) unless
24acb8b3caSAndre Przywara  * a fuse it burnt (seems to be an erratum), but we do it nevertheless,
25acb8b3caSAndre Przywara  * to allow booting on boards using secure boot.
26acb8b3caSAndre Przywara  */
27acb8b3caSAndre Przywara void sunxi_security_setup(void)
28acb8b3caSAndre Przywara {
2988aa5c43SAndre Przywara #ifdef SUNXI_SPC_BASE
30acb8b3caSAndre Przywara 	int i;
31acb8b3caSAndre Przywara 
32acb8b3caSAndre Przywara 	INFO("Configuring SPC Controller\n");
33acb8b3caSAndre Przywara 	/* SPC setup: set all devices to non-secure */
34acb8b3caSAndre Przywara 	for (i = 0; i < 6; i++)
35acb8b3caSAndre Przywara 		mmio_write_32(SPC_DECPORT_SET_REG(i), 0xff);
36acb8b3caSAndre Przywara #endif
37acb8b3caSAndre Przywara 
38acb8b3caSAndre Przywara 	/* set MBUS clocks, bus clocks (AXI/AHB/APB) and PLLs to non-secure */
39acb8b3caSAndre Przywara 	mmio_write_32(SUNXI_CCU_SEC_SWITCH_REG, 0x7);
40acb8b3caSAndre Przywara 
41acb8b3caSAndre Przywara 	/* set R_PRCM clocks to non-secure */
42acb8b3caSAndre Przywara 	mmio_write_32(SUNXI_R_PRCM_BASE + R_PRCM_SEC_SWITCH_REG, 0x7);
43acb8b3caSAndre Przywara 
44acb8b3caSAndre Przywara 	/* Set all DMA channels (16 max.) to non-secure */
45acb8b3caSAndre Przywara 	mmio_write_32(SUNXI_DMA_BASE + DMA_SEC_REG, 0xffff);
46acb8b3caSAndre Przywara }
47