1 // SPDX-License-Identifier: BSD-2-Clause 2 /* 3 * Copyright (C) 2017, Fuzhou Rockchip Electronics Co., Ltd. 4 */ 5 6 #include <initcall.h> 7 #include <io.h> 8 #include <mm/core_memprot.h> 9 #include <platform_config.h> 10 #include <stdint.h> 11 12 #if defined(PLATFORM_FLAVOR_rk322x) 13 14 register_phys_mem_pgdir(MEM_AREA_IO_SEC, SGRF_BASE, SGRF_SIZE); 15 register_phys_mem_pgdir(MEM_AREA_IO_SEC, DDRSGRF_BASE, DDRSGRF_SIZE); 16 17 #define SGRF_SOC_CON(n) ((n) * 4) 18 #define DDR_SGRF_DDR_CON(n) ((n) * 4) 19 #define DDR_RGN0_NS BIT32(30) 20 #define SLAVE_ALL_NS 0xffff0000 21 22 static TEE_Result platform_init(void) 23 { 24 vaddr_t sgrf_base = (vaddr_t)phys_to_virt_io(SGRF_BASE); 25 vaddr_t ddrsgrf_base = (vaddr_t)phys_to_virt_io(DDRSGRF_BASE); 26 27 /* Set rgn0 non-secure */ 28 io_write32(ddrsgrf_base + DDR_SGRF_DDR_CON(0), DDR_RGN0_NS); 29 30 /* Initialize all slave non-secure */ 31 io_write32(sgrf_base + SGRF_SOC_CON(7), SLAVE_ALL_NS); 32 io_write32(sgrf_base + SGRF_SOC_CON(8), SLAVE_ALL_NS); 33 io_write32(sgrf_base + SGRF_SOC_CON(9), SLAVE_ALL_NS); 34 io_write32(sgrf_base + SGRF_SOC_CON(10), SLAVE_ALL_NS); 35 36 return TEE_SUCCESS; 37 } 38 39 #endif 40 41 service_init(platform_init); 42