xref: /rk3399_ARM-atf/plat/arm/common/tsp/arm_tsp_setup.c (revision 09d40e0e08283a249e7dce0e106c07c5141f9b7e)
1 /*
2  * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <assert.h>
8 
9 #include <platform_def.h>
10 
11 #include <bl32/tsp/platform_tsp.h>
12 #include <common/bl_common.h>
13 #include <common/debug.h>
14 #include <drivers/arm/pl011.h>
15 #include <drivers/console.h>
16 
17 #include <arm_def.h>
18 #include <plat_arm.h>
19 
20 #define BL32_END (unsigned long)(&__BL32_END__)
21 
22 /* Weak definitions may be overridden in specific ARM standard platform */
23 #pragma weak tsp_early_platform_setup
24 #pragma weak tsp_platform_setup
25 #pragma weak tsp_plat_arch_setup
26 
27 #define MAP_BL_TSP_TOTAL	MAP_REGION_FLAT(			\
28 					BL32_BASE,			\
29 					BL32_END - BL32_BASE,		\
30 					MT_MEMORY | MT_RW | MT_SECURE)
31 
32 /*******************************************************************************
33  * Initialize the UART
34  ******************************************************************************/
35 #if MULTI_CONSOLE_API
36 static console_pl011_t arm_tsp_runtime_console;
37 #endif
38 
39 void arm_tsp_early_platform_setup(void)
40 {
41 #if MULTI_CONSOLE_API
42 	/*
43 	 * Initialize a different console than already in use to display
44 	 * messages from TSP
45 	 */
46 	int rc = console_pl011_register(PLAT_ARM_TSP_UART_BASE,
47 					PLAT_ARM_TSP_UART_CLK_IN_HZ,
48 					ARM_CONSOLE_BAUDRATE,
49 					&arm_tsp_runtime_console);
50 	if (rc == 0)
51 		panic();
52 
53 	console_set_scope(&arm_tsp_runtime_console.console,
54 			  CONSOLE_FLAG_BOOT | CONSOLE_FLAG_RUNTIME);
55 #else
56 	console_init(PLAT_ARM_TSP_UART_BASE, PLAT_ARM_TSP_UART_CLK_IN_HZ,
57 			ARM_CONSOLE_BAUDRATE);
58 #endif /* MULTI_CONSOLE_API */
59 }
60 
61 void tsp_early_platform_setup(void)
62 {
63 	arm_tsp_early_platform_setup();
64 }
65 
66 /*******************************************************************************
67  * Perform platform specific setup placeholder
68  ******************************************************************************/
69 void tsp_platform_setup(void)
70 {
71 	plat_arm_gic_driver_init();
72 }
73 
74 /*******************************************************************************
75  * Perform the very early platform specific architectural setup here. At the
76  * moment this is only intializes the MMU
77  ******************************************************************************/
78 void tsp_plat_arch_setup(void)
79 {
80 #if USE_COHERENT_MEM
81 	/* Ensure ARM platforms dont use coherent memory in TSP */
82 	assert((BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE) == 0U);
83 #endif
84 
85 	const mmap_region_t bl_regions[] = {
86 		MAP_BL_TSP_TOTAL,
87 		ARM_MAP_BL_RO,
88 		{0}
89 	};
90 
91 	setup_page_tables(bl_regions, plat_arm_get_mmap());
92 	enable_mmu_el1(0);
93 }
94