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