1b4315306SDan Handley /*
2c5c54e20SBoyan Karatotev * Copyright (c) 2015-2025, 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>
809d40e0eSAntonio Nino Diaz
9b4315306SDan Handley #include <platform_def.h>
1009d40e0eSAntonio Nino Diaz
1109d40e0eSAntonio Nino Diaz #include <bl32/tsp/platform_tsp.h>
1209d40e0eSAntonio Nino Diaz #include <common/bl_common.h>
1309d40e0eSAntonio Nino Diaz #include <common/debug.h>
1409d40e0eSAntonio Nino Diaz #include <drivers/arm/pl011.h>
1509d40e0eSAntonio Nino Diaz #include <drivers/console.h>
16a852fa1dSHarrison Mutai #if TRANSFER_LIST && MEASURED_BOOT
17*b67e9846SHarrison Mutai #include <event_measure.h>
18*b67e9846SHarrison Mutai #include <event_print.h>
19a852fa1dSHarrison Mutai #endif
20bd9344f6SAntonio Nino Diaz #include <plat/arm/common/plat_arm.h>
21c5c54e20SBoyan Karatotev #include <plat/common/platform.h>
22b4315306SDan Handley
23b4315306SDan Handley /* Weak definitions may be overridden in specific ARM standard platform */
24b4315306SDan Handley #pragma weak tsp_early_platform_setup
25b4315306SDan Handley #pragma weak tsp_platform_setup
26b4315306SDan Handley #pragma weak tsp_plat_arch_setup
27b4315306SDan Handley
28d323af9eSDaniel Boulby #define MAP_BL_TSP_TOTAL MAP_REGION_FLAT( \
29d323af9eSDaniel Boulby BL32_BASE, \
30d323af9eSDaniel Boulby BL32_END - BL32_BASE, \
31d323af9eSDaniel Boulby MT_MEMORY | MT_RW | MT_SECURE)
32b4315306SDan Handley
33a852fa1dSHarrison Mutai #define MAP_FW_HANDOFF MAP_REGION_FLAT( \
34a852fa1dSHarrison Mutai PLAT_ARM_EL3_FW_HANDOFF_BASE, \
35a852fa1dSHarrison Mutai PLAT_ARM_FW_HANDOFF_SIZE, \
36a852fa1dSHarrison Mutai MT_MEMORY | MT_RO | MT_SECURE)
37a852fa1dSHarrison Mutai
38a852fa1dSHarrison Mutai struct transfer_list_header *secure_tl __unused;
39a852fa1dSHarrison Mutai
40b4315306SDan Handley /*******************************************************************************
41b4315306SDan Handley * Initialize the UART
42b4315306SDan Handley ******************************************************************************/
43f695e1e0SAndre Przywara static console_t arm_tsp_runtime_console;
4488a0523eSAntonio Nino Diaz
arm_tsp_early_platform_setup(u_register_t arg0,u_register_t arg1,u_register_t arg2,u_register_t arg3)459018b7b8SHarrison Mutai void arm_tsp_early_platform_setup(u_register_t arg0, u_register_t arg1,
469018b7b8SHarrison Mutai u_register_t arg2, u_register_t arg3)
47b4315306SDan Handley {
48a852fa1dSHarrison Mutai #if TRANSFER_LIST
49a852fa1dSHarrison Mutai secure_tl = (struct transfer_list_header *)arg3;
50a852fa1dSHarrison Mutai assert(secure_tl != NULL);
51a852fa1dSHarrison Mutai
52a852fa1dSHarrison Mutai if (transfer_list_check_header(secure_tl) == TL_OPS_NON) {
53a852fa1dSHarrison Mutai ERROR("Invalid transfer list received");
54a852fa1dSHarrison Mutai transfer_list_dump(secure_tl);
55a852fa1dSHarrison Mutai panic();
56a852fa1dSHarrison Mutai }
57a852fa1dSHarrison Mutai #endif
58a852fa1dSHarrison Mutai
59b4315306SDan Handley /*
60b4315306SDan Handley * Initialize a different console than already in use to display
61b4315306SDan Handley * messages from TSP
62b4315306SDan Handley */
6388a0523eSAntonio Nino Diaz int rc = console_pl011_register(PLAT_ARM_TSP_UART_BASE,
6488a0523eSAntonio Nino Diaz PLAT_ARM_TSP_UART_CLK_IN_HZ,
6588a0523eSAntonio Nino Diaz ARM_CONSOLE_BAUDRATE,
6688a0523eSAntonio Nino Diaz &arm_tsp_runtime_console);
679018b7b8SHarrison Mutai if (rc == 0) {
6888a0523eSAntonio Nino Diaz panic();
699018b7b8SHarrison Mutai }
7088a0523eSAntonio Nino Diaz
71f695e1e0SAndre Przywara console_set_scope(&arm_tsp_runtime_console,
7288a0523eSAntonio Nino Diaz CONSOLE_FLAG_BOOT | CONSOLE_FLAG_RUNTIME);
73b4315306SDan Handley }
74b4315306SDan Handley
tsp_early_platform_setup(u_register_t arg0,u_register_t arg1,u_register_t arg2,u_register_t arg3)759018b7b8SHarrison Mutai void tsp_early_platform_setup(u_register_t arg0, u_register_t arg1,
769018b7b8SHarrison Mutai u_register_t arg2, u_register_t arg3)
77b4315306SDan Handley {
789018b7b8SHarrison Mutai arm_tsp_early_platform_setup(arg0, arg1, arg2, arg3);
79b4315306SDan Handley }
80b4315306SDan Handley
81b4315306SDan Handley /*******************************************************************************
82b4315306SDan Handley * Perform platform specific setup placeholder
83b4315306SDan Handley ******************************************************************************/
tsp_platform_setup(void)84b4315306SDan Handley void tsp_platform_setup(void)
85b4315306SDan Handley {
86a852fa1dSHarrison Mutai struct transfer_list_entry *te __unused;
87a852fa1dSHarrison Mutai
88c5c54e20SBoyan Karatotev /*
89c5c54e20SBoyan Karatotev * On GICv2 the driver must be initialised before calling the plat_ic_*
90c5c54e20SBoyan Karatotev * functions as they need the data structures. Higher versions don't.
91c5c54e20SBoyan Karatotev */
92c5c54e20SBoyan Karatotev #if USE_GIC_DRIVER == 2
93c5c54e20SBoyan Karatotev gic_init(plat_my_core_pos());
94c5c54e20SBoyan Karatotev #endif
95a852fa1dSHarrison Mutai
96a852fa1dSHarrison Mutai #if TRANSFER_LIST && MEASURED_BOOT
97a852fa1dSHarrison Mutai te = transfer_list_find(secure_tl, TL_TAG_TPM_EVLOG);
98a852fa1dSHarrison Mutai assert(te != NULL);
99a852fa1dSHarrison Mutai
100a852fa1dSHarrison Mutai /*
101a852fa1dSHarrison Mutai * Note the actual log is offset 4-bytes from the start of entry data, the
102a852fa1dSHarrison Mutai * first bytes are reserved.
103a852fa1dSHarrison Mutai */
104a852fa1dSHarrison Mutai event_log_dump(transfer_list_entry_data(te) + U(4), te->data_size - U(4));
105a852fa1dSHarrison Mutai #endif
106b4315306SDan Handley }
107b4315306SDan Handley
108b4315306SDan Handley /*******************************************************************************
109b4315306SDan Handley * Perform the very early platform specific architectural setup here. At the
1101b491eeaSElyes Haouas * moment this is only initializes the MMU
111b4315306SDan Handley ******************************************************************************/
tsp_plat_arch_setup(void)112b4315306SDan Handley void tsp_plat_arch_setup(void)
113b4315306SDan Handley {
114b4315306SDan Handley #if USE_COHERENT_MEM
1158aabea33SPaul Beesley /* Ensure ARM platforms don't use coherent memory in TSP */
116d323af9eSDaniel Boulby assert((BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE) == 0U);
117b4315306SDan Handley #endif
118d323af9eSDaniel Boulby
119d323af9eSDaniel Boulby const mmap_region_t bl_regions[] = {
120d323af9eSDaniel Boulby MAP_BL_TSP_TOTAL,
1212ecaafd2SDaniel Boulby ARM_MAP_BL_RO,
122a852fa1dSHarrison Mutai #if TRANSFER_LIST
123a852fa1dSHarrison Mutai MAP_FW_HANDOFF,
124a852fa1dSHarrison Mutai #endif
125d323af9eSDaniel Boulby {0}
126d323af9eSDaniel Boulby };
127d323af9eSDaniel Boulby
1280916c38dSRoberto Vargas setup_page_tables(bl_regions, plat_arm_get_mmap());
129b5fa6563SSandrine Bailleux enable_mmu_el1(0);
13060e8f3cfSPetre-Ionut Tudor
13160e8f3cfSPetre-Ionut Tudor #if PLAT_RO_XLAT_TABLES
13260e8f3cfSPetre-Ionut Tudor arm_xlat_make_tables_readonly();
13360e8f3cfSPetre-Ionut Tudor #endif
134b4315306SDan Handley }
135