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