sunxi_security.c 1.1 KB
Newer Older
Andre Przywara's avatar
Andre Przywara committed
1
/*
2
 * Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
Andre Przywara's avatar
Andre Przywara committed
3
4
5
6
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

7
8
9
#include <common/debug.h>
#include <lib/mmio.h>

10
#include <sunxi_ccu.h>
Andre Przywara's avatar
Andre Przywara committed
11
#include <sunxi_mmap.h>
12
#include <sunxi_private.h>
13
#include <sunxi_spc.h>
Andre Przywara's avatar
Andre Przywara committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

#define DMA_SEC_REG		0x20

/*
 * Setup the peripherals to be accessible by non-secure world.
 * This will not work for the Secure Peripherals Controller (SPC) unless
 * a fuse it burnt (seems to be an erratum), but we do it nevertheless,
 * to allow booting on boards using secure boot.
 */
void sunxi_security_setup(void)
{
	int i;

	INFO("Configuring SPC Controller\n");
	/* SPC setup: set all devices to non-secure */
29
30
	for (i = 0; i < SUNXI_SPC_NUM_PORTS; i++)
		mmio_write_32(SUNXI_SPC_DECPORT_SET_REG(i), 0xffffffff);
Andre Przywara's avatar
Andre Przywara committed
31
32
33
34

	/* set MBUS clocks, bus clocks (AXI/AHB/APB) and PLLs to non-secure */
	mmio_write_32(SUNXI_CCU_SEC_SWITCH_REG, 0x7);

35
	/* Set R_PRCM bus clocks to non-secure */
36
	mmio_write_32(SUNXI_R_PRCM_SEC_SWITCH_REG, 0x1);
Andre Przywara's avatar
Andre Przywara committed
37
38
39
40

	/* Set all DMA channels (16 max.) to non-secure */
	mmio_write_32(SUNXI_DMA_BASE + DMA_SEC_REG, 0xffff);
}