xref: /rk3399_ARM-atf/plat/arm/common/tsp/arm_tsp_setup.c (revision 09d40e0e08283a249e7dce0e106c07c5141f9b7e)
1b4315306SDan Handley /*
288a0523eSAntonio Nino Diaz  * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
3b4315306SDan Handley  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
5b4315306SDan Handley  */
6b4315306SDan Handley 
7d323af9eSDaniel Boulby #include <assert.h>
8*09d40e0eSAntonio Nino Diaz 
9b4315306SDan Handley #include <platform_def.h>
10*09d40e0eSAntonio Nino Diaz 
11*09d40e0eSAntonio Nino Diaz #include <bl32/tsp/platform_tsp.h>
12*09d40e0eSAntonio Nino Diaz #include <common/bl_common.h>
13*09d40e0eSAntonio Nino Diaz #include <common/debug.h>
14*09d40e0eSAntonio Nino Diaz #include <drivers/arm/pl011.h>
15*09d40e0eSAntonio Nino Diaz #include <drivers/console.h>
16*09d40e0eSAntonio Nino Diaz 
17*09d40e0eSAntonio Nino Diaz #include <arm_def.h>
18*09d40e0eSAntonio Nino Diaz #include <plat_arm.h>
19b4315306SDan Handley 
20b4315306SDan Handley #define BL32_END (unsigned long)(&__BL32_END__)
21b4315306SDan Handley 
22b4315306SDan Handley /* Weak definitions may be overridden in specific ARM standard platform */
23b4315306SDan Handley #pragma weak tsp_early_platform_setup
24b4315306SDan Handley #pragma weak tsp_platform_setup
25b4315306SDan Handley #pragma weak tsp_plat_arch_setup
26b4315306SDan Handley 
27d323af9eSDaniel Boulby #define MAP_BL_TSP_TOTAL	MAP_REGION_FLAT(			\
28d323af9eSDaniel Boulby 					BL32_BASE,			\
29d323af9eSDaniel Boulby 					BL32_END - BL32_BASE,		\
30d323af9eSDaniel Boulby 					MT_MEMORY | MT_RW | MT_SECURE)
31b4315306SDan Handley 
32b4315306SDan Handley /*******************************************************************************
33b4315306SDan Handley  * Initialize the UART
34b4315306SDan Handley  ******************************************************************************/
3588a0523eSAntonio Nino Diaz #if MULTI_CONSOLE_API
3688a0523eSAntonio Nino Diaz static console_pl011_t arm_tsp_runtime_console;
3788a0523eSAntonio Nino Diaz #endif
3888a0523eSAntonio Nino Diaz 
39b4315306SDan Handley void arm_tsp_early_platform_setup(void)
40b4315306SDan Handley {
4188a0523eSAntonio Nino Diaz #if MULTI_CONSOLE_API
42b4315306SDan Handley 	/*
43b4315306SDan Handley 	 * Initialize a different console than already in use to display
44b4315306SDan Handley 	 * messages from TSP
45b4315306SDan Handley 	 */
4688a0523eSAntonio Nino Diaz 	int rc = console_pl011_register(PLAT_ARM_TSP_UART_BASE,
4788a0523eSAntonio Nino Diaz 					PLAT_ARM_TSP_UART_CLK_IN_HZ,
4888a0523eSAntonio Nino Diaz 					ARM_CONSOLE_BAUDRATE,
4988a0523eSAntonio Nino Diaz 					&arm_tsp_runtime_console);
5088a0523eSAntonio Nino Diaz 	if (rc == 0)
5188a0523eSAntonio Nino Diaz 		panic();
5288a0523eSAntonio Nino Diaz 
5388a0523eSAntonio Nino Diaz 	console_set_scope(&arm_tsp_runtime_console.console,
5488a0523eSAntonio Nino Diaz 			  CONSOLE_FLAG_BOOT | CONSOLE_FLAG_RUNTIME);
5588a0523eSAntonio Nino Diaz #else
56b4315306SDan Handley 	console_init(PLAT_ARM_TSP_UART_BASE, PLAT_ARM_TSP_UART_CLK_IN_HZ,
57b4315306SDan Handley 			ARM_CONSOLE_BAUDRATE);
5888a0523eSAntonio Nino Diaz #endif /* MULTI_CONSOLE_API */
59b4315306SDan Handley }
60b4315306SDan Handley 
61b4315306SDan Handley void tsp_early_platform_setup(void)
62b4315306SDan Handley {
63b4315306SDan Handley 	arm_tsp_early_platform_setup();
64b4315306SDan Handley }
65b4315306SDan Handley 
66b4315306SDan Handley /*******************************************************************************
67b4315306SDan Handley  * Perform platform specific setup placeholder
68b4315306SDan Handley  ******************************************************************************/
69b4315306SDan Handley void tsp_platform_setup(void)
70b4315306SDan Handley {
7127573c59SAchin Gupta 	plat_arm_gic_driver_init();
72b4315306SDan Handley }
73b4315306SDan Handley 
74b4315306SDan Handley /*******************************************************************************
75b4315306SDan Handley  * Perform the very early platform specific architectural setup here. At the
76b4315306SDan Handley  * moment this is only intializes the MMU
77b4315306SDan Handley  ******************************************************************************/
78b4315306SDan Handley void tsp_plat_arch_setup(void)
79b4315306SDan Handley {
80b4315306SDan Handley #if USE_COHERENT_MEM
81d323af9eSDaniel Boulby 	/* Ensure ARM platforms dont use coherent memory in TSP */
82d323af9eSDaniel Boulby 	assert((BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE) == 0U);
83b4315306SDan Handley #endif
84d323af9eSDaniel Boulby 
85d323af9eSDaniel Boulby 	const mmap_region_t bl_regions[] = {
86d323af9eSDaniel Boulby 		MAP_BL_TSP_TOTAL,
872ecaafd2SDaniel Boulby 		ARM_MAP_BL_RO,
88d323af9eSDaniel Boulby 		{0}
89d323af9eSDaniel Boulby 	};
90d323af9eSDaniel Boulby 
910916c38dSRoberto Vargas 	setup_page_tables(bl_regions, plat_arm_get_mmap());
92b5fa6563SSandrine Bailleux 	enable_mmu_el1(0);
93b4315306SDan Handley }
94