181136819SBai Ping /* 281136819SBai Ping * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. 381136819SBai Ping * 481136819SBai Ping * SPDX-License-Identifier: BSD-3-Clause 581136819SBai Ping */ 681136819SBai Ping 781136819SBai Ping #include <assert.h> 8*09d40e0eSAntonio Nino Diaz #include <stdbool.h> 9*09d40e0eSAntonio Nino Diaz 10*09d40e0eSAntonio Nino Diaz #include <platform_def.h> 11*09d40e0eSAntonio Nino Diaz 12*09d40e0eSAntonio Nino Diaz #include <arch_helpers.h> 13*09d40e0eSAntonio Nino Diaz #include <common/bl_common.h> 14*09d40e0eSAntonio Nino Diaz #include <common/debug.h> 1581136819SBai Ping #include <context.h> 16*09d40e0eSAntonio Nino Diaz #include <drivers/arm/tzc380.h> 17*09d40e0eSAntonio Nino Diaz #include <drivers/console.h> 18*09d40e0eSAntonio Nino Diaz #include <lib/el3_runtime/context_mgmt.h> 19*09d40e0eSAntonio Nino Diaz #include <lib/mmio.h> 20*09d40e0eSAntonio Nino Diaz #include <lib/xlat_tables/xlat_tables.h> 21*09d40e0eSAntonio Nino Diaz #include <plat/common/platform.h> 22*09d40e0eSAntonio Nino Diaz 2381136819SBai Ping #include <gpc.h> 2481136819SBai Ping #include <imx_uart.h> 2581136819SBai Ping #include <plat_imx8.h> 2681136819SBai Ping 2781136819SBai Ping IMPORT_SYM(uintptr_t, __COHERENT_RAM_START__, BL31_COHERENT_RAM_START); 2881136819SBai Ping IMPORT_SYM(uintptr_t, __COHERENT_RAM_END__, BL31_COHERENT_RAM_END); 2981136819SBai Ping IMPORT_SYM(uintptr_t, __RO_START__, BL31_RO_START); 3081136819SBai Ping IMPORT_SYM(uintptr_t, __RO_END__, BL31_RO_END); 3181136819SBai Ping IMPORT_SYM(uintptr_t, __RW_START__, BL31_RW_START); 3281136819SBai Ping IMPORT_SYM(uintptr_t, __RW_END__, BL31_RW_END); 3381136819SBai Ping 3481136819SBai Ping static const mmap_region_t imx_mmap[] = { 3581136819SBai Ping MAP_REGION_FLAT(GPV_BASE, GPV_SIZE, MT_DEVICE | MT_RW), /* GPV map */ 3681136819SBai Ping MAP_REGION_FLAT(IMX_AIPS_BASE, IMX_AIPS_SIZE, MT_DEVICE | MT_RW), /* AIPS map */ 3781136819SBai Ping MAP_REGION_FLAT(IMX_GIC_BASE, IMX_GIC_SIZE, MT_DEVICE | MT_RW), /* GIC map */ 3881136819SBai Ping {0}, 3981136819SBai Ping }; 4081136819SBai Ping 4181136819SBai Ping static entry_point_info_t bl32_image_ep_info; 4281136819SBai Ping static entry_point_info_t bl33_image_ep_info; 4381136819SBai Ping 4481136819SBai Ping /* get SPSR for BL33 entry */ 4581136819SBai Ping static uint32_t get_spsr_for_bl33_entry(void) 4681136819SBai Ping { 4781136819SBai Ping unsigned long el_status; 4881136819SBai Ping unsigned long mode; 4981136819SBai Ping uint32_t spsr; 5081136819SBai Ping 5181136819SBai Ping /* figure out what mode we enter the non-secure world */ 5281136819SBai Ping el_status = read_id_aa64pfr0_el1() >> ID_AA64PFR0_EL2_SHIFT; 5381136819SBai Ping el_status &= ID_AA64PFR0_ELX_MASK; 5481136819SBai Ping 5581136819SBai Ping mode = (el_status) ? MODE_EL2 : MODE_EL1; 5681136819SBai Ping 5781136819SBai Ping spsr = SPSR_64(mode, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS); 5881136819SBai Ping return spsr; 5981136819SBai Ping } 6081136819SBai Ping 6181136819SBai Ping static void bl31_tz380_setup(void) 6281136819SBai Ping { 6381136819SBai Ping unsigned int val; 6481136819SBai Ping 6581136819SBai Ping val = mmio_read_32(IMX_IOMUX_GPR_BASE + IOMUXC_GPR10); 6681136819SBai Ping if ((val & GPR_TZASC_EN) != GPR_TZASC_EN) 6781136819SBai Ping return; 6881136819SBai Ping 6981136819SBai Ping tzc380_init(IMX_TZASC_BASE); 7081136819SBai Ping /* 7181136819SBai Ping * Need to substact offset 0x40000000 from CPU address when 7281136819SBai Ping * programming tzasc region for i.mx8mq. Enable 1G-5G S/NS RW 7381136819SBai Ping */ 7481136819SBai Ping tzc380_configure_region(0, 0x00000000, TZC_ATTR_REGION_SIZE(TZC_REGION_SIZE_4G) | 7581136819SBai Ping TZC_ATTR_REGION_EN_MASK | TZC_ATTR_SP_ALL); 7681136819SBai Ping } 7781136819SBai Ping 7881136819SBai Ping void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1, 7981136819SBai Ping u_register_t arg2, u_register_t arg3) 8081136819SBai Ping { 8181136819SBai Ping int i; 8281136819SBai Ping /* enable CSU NS access permission */ 8381136819SBai Ping for (i = 0; i < 64; i++) { 8481136819SBai Ping mmio_write_32(IMX_CSU_BASE + i * 4, 0xffffffff); 8581136819SBai Ping } 8681136819SBai Ping 8781136819SBai Ping #if DEBUG_CONSOLE 8881136819SBai Ping static console_uart_t console; 8981136819SBai Ping 9081136819SBai Ping console_uart_register(IMX_BOOT_UART_BASE, IMX_BOOT_UART_CLK_IN_HZ, 9181136819SBai Ping IMX_CONSOLE_BAUDRATE, &console); 9281136819SBai Ping #endif 9381136819SBai Ping /* 9481136819SBai Ping * tell BL3-1 where the non-secure software image is located 9581136819SBai Ping * and the entry state information. 9681136819SBai Ping */ 9781136819SBai Ping bl33_image_ep_info.pc = PLAT_NS_IMAGE_OFFSET; 9881136819SBai Ping bl33_image_ep_info.spsr = get_spsr_for_bl33_entry(); 9981136819SBai Ping SET_SECURITY_STATE(bl33_image_ep_info.h.attr, NON_SECURE); 10081136819SBai Ping 10181136819SBai Ping bl31_tz380_setup(); 10281136819SBai Ping } 10381136819SBai Ping 10481136819SBai Ping void bl31_plat_arch_setup(void) 10581136819SBai Ping { 10681136819SBai Ping mmap_add_region(BL31_RO_START, BL31_RO_START, (BL31_RO_END - BL31_RO_START), 10781136819SBai Ping MT_MEMORY | MT_RO | MT_SECURE); 10881136819SBai Ping mmap_add_region(BL31_RW_START, BL31_RW_START, (BL31_RW_END - BL31_RW_START), 10981136819SBai Ping MT_MEMORY | MT_RW | MT_SECURE); 11081136819SBai Ping 11181136819SBai Ping mmap_add(imx_mmap); 11281136819SBai Ping 11381136819SBai Ping #if USE_COHERENT_MEM 11481136819SBai Ping mmap_add_region(BL31_COHERENT_RAM_START, BL31_COHERENT_RAM_START, 11581136819SBai Ping BL31_COHERENT_RAM_END - BL31_COHERENT_RAM_START, 11681136819SBai Ping MT_DEVICE | MT_RW | MT_SECURE); 11781136819SBai Ping #endif 11881136819SBai Ping /* setup xlat table */ 11981136819SBai Ping init_xlat_tables(); 12081136819SBai Ping /* enable the MMU */ 12181136819SBai Ping enable_mmu_el3(0); 12281136819SBai Ping } 12381136819SBai Ping 12481136819SBai Ping void bl31_platform_setup(void) 12581136819SBai Ping { 12681136819SBai Ping /* init the GICv3 cpu and distributor interface */ 12781136819SBai Ping plat_gic_driver_init(); 12881136819SBai Ping plat_gic_init(); 12981136819SBai Ping 13081136819SBai Ping /* gpc init */ 13181136819SBai Ping imx_gpc_init(); 13281136819SBai Ping } 13381136819SBai Ping 13481136819SBai Ping entry_point_info_t *bl31_plat_get_next_image_ep_info(unsigned int type) 13581136819SBai Ping { 13681136819SBai Ping if (type == NON_SECURE) 13781136819SBai Ping return &bl33_image_ep_info; 13881136819SBai Ping if (type == SECURE) 13981136819SBai Ping return &bl32_image_ep_info; 14081136819SBai Ping 14181136819SBai Ping return NULL; 14281136819SBai Ping } 14381136819SBai Ping 14481136819SBai Ping unsigned int plat_get_syscnt_freq2(void) 14581136819SBai Ping { 14681136819SBai Ping return COUNTER_FREQUENCY; 14781136819SBai Ping } 14881136819SBai Ping 14981136819SBai Ping void bl31_plat_runtime_setup(void) 15081136819SBai Ping { 15181136819SBai Ping return; 15281136819SBai Ping } 153