blob: 5181dd5a06a296e8d7241ce072c7ace4f091530c [file] [log] [blame]
Dan Handley9df48042015-03-19 18:58:55 +00001/*
Boyan Karatotev5eefc812025-01-07 11:04:16 +00002 * Copyright (c) 2015-2025, Arm Limited and Contributors. All rights reserved.
Dan Handley9df48042015-03-19 18:58:55 +00003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Dan Handley9df48042015-03-19 18:58:55 +00005 */
6
Daniel Boulby45a2c9e2018-07-06 16:54:44 +01007#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
Dan Handley9df48042015-03-19 18:58:55 +00009#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010
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>
Antonio Nino Diazbd7b7402019-01-25 14:30:04 +000016#include <plat/arm/common/plat_arm.h>
Boyan Karatotev5eefc812025-01-07 11:04:16 +000017#include <plat/common/platform.h>
Dan Handley9df48042015-03-19 18:58:55 +000018
Dan Handley9df48042015-03-19 18:58:55 +000019/* Weak definitions may be overridden in specific ARM standard platform */
20#pragma weak tsp_early_platform_setup
21#pragma weak tsp_platform_setup
22#pragma weak tsp_plat_arch_setup
23
Daniel Boulby45a2c9e2018-07-06 16:54:44 +010024#define MAP_BL_TSP_TOTAL MAP_REGION_FLAT( \
25 BL32_BASE, \
26 BL32_END - BL32_BASE, \
27 MT_MEMORY | MT_RW | MT_SECURE)
Dan Handley9df48042015-03-19 18:58:55 +000028
29/*******************************************************************************
30 * Initialize the UART
31 ******************************************************************************/
Andre Przywara2b1b1a52020-01-25 00:58:35 +000032static console_t arm_tsp_runtime_console;
Antonio Nino Diaz23ede6a2018-06-19 09:29:36 +010033
Harrison Mutai61992542025-03-21 17:26:41 +000034void arm_tsp_early_platform_setup(u_register_t arg0, u_register_t arg1,
35 u_register_t arg2, u_register_t arg3)
Dan Handley9df48042015-03-19 18:58:55 +000036{
37 /*
38 * Initialize a different console than already in use to display
39 * messages from TSP
40 */
Antonio Nino Diaz23ede6a2018-06-19 09:29:36 +010041 int rc = console_pl011_register(PLAT_ARM_TSP_UART_BASE,
42 PLAT_ARM_TSP_UART_CLK_IN_HZ,
43 ARM_CONSOLE_BAUDRATE,
44 &arm_tsp_runtime_console);
Harrison Mutai61992542025-03-21 17:26:41 +000045 if (rc == 0) {
Antonio Nino Diaz23ede6a2018-06-19 09:29:36 +010046 panic();
Harrison Mutai61992542025-03-21 17:26:41 +000047 }
Antonio Nino Diaz23ede6a2018-06-19 09:29:36 +010048
Andre Przywara2b1b1a52020-01-25 00:58:35 +000049 console_set_scope(&arm_tsp_runtime_console,
Antonio Nino Diaz23ede6a2018-06-19 09:29:36 +010050 CONSOLE_FLAG_BOOT | CONSOLE_FLAG_RUNTIME);
Dan Handley9df48042015-03-19 18:58:55 +000051}
52
Harrison Mutai61992542025-03-21 17:26:41 +000053void tsp_early_platform_setup(u_register_t arg0, u_register_t arg1,
54 u_register_t arg2, u_register_t arg3)
Dan Handley9df48042015-03-19 18:58:55 +000055{
Harrison Mutai61992542025-03-21 17:26:41 +000056 arm_tsp_early_platform_setup(arg0, arg1, arg2, arg3);
Dan Handley9df48042015-03-19 18:58:55 +000057}
58
59/*******************************************************************************
60 * Perform platform specific setup placeholder
61 ******************************************************************************/
62void tsp_platform_setup(void)
63{
Boyan Karatotev5eefc812025-01-07 11:04:16 +000064 /*
65 * On GICv2 the driver must be initialised before calling the plat_ic_*
66 * functions as they need the data structures. Higher versions don't.
67 */
68#if USE_GIC_DRIVER == 2
69 gic_init(plat_my_core_pos());
70#endif
Dan Handley9df48042015-03-19 18:58:55 +000071}
72
73/*******************************************************************************
74 * Perform the very early platform specific architectural setup here. At the
Elyes Haouas2be03c02023-02-13 09:14:48 +010075 * moment this is only initializes the MMU
Dan Handley9df48042015-03-19 18:58:55 +000076 ******************************************************************************/
77void tsp_plat_arch_setup(void)
78{
Dan Handley9df48042015-03-19 18:58:55 +000079#if USE_COHERENT_MEM
Paul Beesley1fbc97b2019-01-11 18:26:51 +000080 /* Ensure ARM platforms don't use coherent memory in TSP */
Daniel Boulby45a2c9e2018-07-06 16:54:44 +010081 assert((BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE) == 0U);
Dan Handley9df48042015-03-19 18:58:55 +000082#endif
Daniel Boulby45a2c9e2018-07-06 16:54:44 +010083
84 const mmap_region_t bl_regions[] = {
85 MAP_BL_TSP_TOTAL,
Daniel Boulby4e97abd2018-07-16 14:09:15 +010086 ARM_MAP_BL_RO,
Daniel Boulby45a2c9e2018-07-06 16:54:44 +010087 {0}
88 };
89
Roberto Vargas344ff022018-10-19 16:44:18 +010090 setup_page_tables(bl_regions, plat_arm_get_mmap());
Sandrine Bailleux4a1267a2016-05-18 16:11:47 +010091 enable_mmu_el1(0);
Petre-Ionut Tudore5a6fef2019-11-07 15:18:03 +000092
93#if PLAT_RO_XLAT_TABLES
94 arm_xlat_make_tables_readonly();
95#endif
Dan Handley9df48042015-03-19 18:58:55 +000096}