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