Andre Przywara | 1381547 | 2018-06-01 02:01:39 +0100 | [diff] [blame] | 1 | /* |
Samuel Holland | f93a9ab | 2020-12-13 21:56:15 -0600 | [diff] [blame] | 2 | * Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved. |
Andre Przywara | 1381547 | 2018-06-01 02:01:39 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 7 | #include <common/debug.h> |
| 8 | #include <lib/mmio.h> |
| 9 | |
Samuel Holland | f1be840 | 2020-12-13 21:44:54 -0600 | [diff] [blame] | 10 | #include <sunxi_ccu.h> |
Andre Przywara | 1381547 | 2018-06-01 02:01:39 +0100 | [diff] [blame] | 11 | #include <sunxi_mmap.h> |
Andre Przywara | 456208a | 2018-10-14 12:02:02 +0100 | [diff] [blame] | 12 | #include <sunxi_private.h> |
Samuel Holland | f93a9ab | 2020-12-13 21:56:15 -0600 | [diff] [blame] | 13 | #include <sunxi_spc.h> |
Andre Przywara | 1381547 | 2018-06-01 02:01:39 +0100 | [diff] [blame] | 14 | |
Andre Przywara | 1381547 | 2018-06-01 02:01:39 +0100 | [diff] [blame] | 15 | #define DMA_SEC_REG 0x20 |
| 16 | |
| 17 | /* |
| 18 | * Setup the peripherals to be accessible by non-secure world. |
| 19 | * This will not work for the Secure Peripherals Controller (SPC) unless |
| 20 | * a fuse it burnt (seems to be an erratum), but we do it nevertheless, |
| 21 | * to allow booting on boards using secure boot. |
| 22 | */ |
| 23 | void sunxi_security_setup(void) |
| 24 | { |
| 25 | int i; |
| 26 | |
Andre Przywara | 1381547 | 2018-06-01 02:01:39 +0100 | [diff] [blame] | 27 | INFO("Configuring SPC Controller\n"); |
| 28 | /* SPC setup: set all devices to non-secure */ |
Samuel Holland | f93a9ab | 2020-12-13 21:56:15 -0600 | [diff] [blame] | 29 | for (i = 0; i < SUNXI_SPC_NUM_PORTS; i++) |
| 30 | mmio_write_32(SUNXI_SPC_DECPORT_SET_REG(i), 0xffffffff); |
Andre Przywara | 1381547 | 2018-06-01 02:01:39 +0100 | [diff] [blame] | 31 | |
| 32 | /* set MBUS clocks, bus clocks (AXI/AHB/APB) and PLLs to non-secure */ |
| 33 | mmio_write_32(SUNXI_CCU_SEC_SWITCH_REG, 0x7); |
| 34 | |
Samuel Holland | 62d401a | 2019-12-29 16:12:12 -0600 | [diff] [blame] | 35 | /* Set R_PRCM bus clocks to non-secure */ |
Samuel Holland | f1be840 | 2020-12-13 21:44:54 -0600 | [diff] [blame] | 36 | mmio_write_32(SUNXI_R_PRCM_SEC_SWITCH_REG, 0x1); |
Andre Przywara | 1381547 | 2018-06-01 02:01:39 +0100 | [diff] [blame] | 37 | |
| 38 | /* Set all DMA channels (16 max.) to non-secure */ |
| 39 | mmio_write_32(SUNXI_DMA_BASE + DMA_SEC_REG, 0xffff); |
| 40 | } |