Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 1 | /* |
Boyan Karatotev | 5eefc81 | 2025-01-07 11:04:16 +0000 | [diff] [blame] | 2 | * Copyright (c) 2015-2025, Arm Limited and Contributors. All rights reserved. |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Daniel Boulby | 45a2c9e | 2018-07-06 16:54:44 +0100 | [diff] [blame] | 7 | #include <assert.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 9 | #include <platform_def.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 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> |
Harrison Mutai | 64461f7 | 2025-02-21 11:52:48 +0000 | [diff] [blame] | 16 | #if TRANSFER_LIST && MEASURED_BOOT |
| 17 | #include <drivers/measured_boot/event_log/event_log.h> |
| 18 | #endif |
Antonio Nino Diaz | bd7b740 | 2019-01-25 14:30:04 +0000 | [diff] [blame] | 19 | #include <plat/arm/common/plat_arm.h> |
Boyan Karatotev | 5eefc81 | 2025-01-07 11:04:16 +0000 | [diff] [blame] | 20 | #include <plat/common/platform.h> |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 21 | |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 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 | |
Daniel Boulby | 45a2c9e | 2018-07-06 16:54:44 +0100 | [diff] [blame] | 27 | #define MAP_BL_TSP_TOTAL MAP_REGION_FLAT( \ |
| 28 | BL32_BASE, \ |
| 29 | BL32_END - BL32_BASE, \ |
| 30 | MT_MEMORY | MT_RW | MT_SECURE) |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 31 | |
Harrison Mutai | 64461f7 | 2025-02-21 11:52:48 +0000 | [diff] [blame] | 32 | #define MAP_FW_HANDOFF MAP_REGION_FLAT( \ |
| 33 | PLAT_ARM_EL3_FW_HANDOFF_BASE, \ |
| 34 | PLAT_ARM_FW_HANDOFF_SIZE, \ |
| 35 | MT_MEMORY | MT_RO | MT_SECURE) |
| 36 | |
| 37 | struct transfer_list_header *secure_tl __unused; |
| 38 | |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 39 | /******************************************************************************* |
| 40 | * Initialize the UART |
| 41 | ******************************************************************************/ |
Andre Przywara | 2b1b1a5 | 2020-01-25 00:58:35 +0000 | [diff] [blame] | 42 | static console_t arm_tsp_runtime_console; |
Antonio Nino Diaz | 23ede6a | 2018-06-19 09:29:36 +0100 | [diff] [blame] | 43 | |
Harrison Mutai | 6199254 | 2025-03-21 17:26:41 +0000 | [diff] [blame] | 44 | void arm_tsp_early_platform_setup(u_register_t arg0, u_register_t arg1, |
| 45 | u_register_t arg2, u_register_t arg3) |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 46 | { |
Harrison Mutai | 64461f7 | 2025-02-21 11:52:48 +0000 | [diff] [blame] | 47 | #if TRANSFER_LIST |
| 48 | secure_tl = (struct transfer_list_header *)arg3; |
| 49 | assert(secure_tl != NULL); |
| 50 | |
| 51 | if (transfer_list_check_header(secure_tl) == TL_OPS_NON) { |
| 52 | ERROR("Invalid transfer list received"); |
| 53 | transfer_list_dump(secure_tl); |
| 54 | panic(); |
| 55 | } |
| 56 | #endif |
| 57 | |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 58 | /* |
| 59 | * Initialize a different console than already in use to display |
| 60 | * messages from TSP |
| 61 | */ |
Antonio Nino Diaz | 23ede6a | 2018-06-19 09:29:36 +0100 | [diff] [blame] | 62 | int rc = console_pl011_register(PLAT_ARM_TSP_UART_BASE, |
| 63 | PLAT_ARM_TSP_UART_CLK_IN_HZ, |
| 64 | ARM_CONSOLE_BAUDRATE, |
| 65 | &arm_tsp_runtime_console); |
Harrison Mutai | 6199254 | 2025-03-21 17:26:41 +0000 | [diff] [blame] | 66 | if (rc == 0) { |
Antonio Nino Diaz | 23ede6a | 2018-06-19 09:29:36 +0100 | [diff] [blame] | 67 | panic(); |
Harrison Mutai | 6199254 | 2025-03-21 17:26:41 +0000 | [diff] [blame] | 68 | } |
Antonio Nino Diaz | 23ede6a | 2018-06-19 09:29:36 +0100 | [diff] [blame] | 69 | |
Andre Przywara | 2b1b1a5 | 2020-01-25 00:58:35 +0000 | [diff] [blame] | 70 | console_set_scope(&arm_tsp_runtime_console, |
Antonio Nino Diaz | 23ede6a | 2018-06-19 09:29:36 +0100 | [diff] [blame] | 71 | CONSOLE_FLAG_BOOT | CONSOLE_FLAG_RUNTIME); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Harrison Mutai | 6199254 | 2025-03-21 17:26:41 +0000 | [diff] [blame] | 74 | void tsp_early_platform_setup(u_register_t arg0, u_register_t arg1, |
| 75 | u_register_t arg2, u_register_t arg3) |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 76 | { |
Harrison Mutai | 6199254 | 2025-03-21 17:26:41 +0000 | [diff] [blame] | 77 | arm_tsp_early_platform_setup(arg0, arg1, arg2, arg3); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | /******************************************************************************* |
| 81 | * Perform platform specific setup placeholder |
| 82 | ******************************************************************************/ |
| 83 | void tsp_platform_setup(void) |
| 84 | { |
Harrison Mutai | 64461f7 | 2025-02-21 11:52:48 +0000 | [diff] [blame] | 85 | struct transfer_list_entry *te __unused; |
| 86 | |
Boyan Karatotev | 5eefc81 | 2025-01-07 11:04:16 +0000 | [diff] [blame] | 87 | /* |
| 88 | * On GICv2 the driver must be initialised before calling the plat_ic_* |
| 89 | * functions as they need the data structures. Higher versions don't. |
| 90 | */ |
| 91 | #if USE_GIC_DRIVER == 2 |
| 92 | gic_init(plat_my_core_pos()); |
| 93 | #endif |
Harrison Mutai | 64461f7 | 2025-02-21 11:52:48 +0000 | [diff] [blame] | 94 | |
| 95 | #if TRANSFER_LIST && MEASURED_BOOT |
| 96 | te = transfer_list_find(secure_tl, TL_TAG_TPM_EVLOG); |
| 97 | assert(te != NULL); |
| 98 | |
| 99 | /* |
| 100 | * Note the actual log is offset 4-bytes from the start of entry data, the |
| 101 | * first bytes are reserved. |
| 102 | */ |
| 103 | event_log_dump(transfer_list_entry_data(te) + U(4), te->data_size - U(4)); |
| 104 | #endif |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | /******************************************************************************* |
| 108 | * Perform the very early platform specific architectural setup here. At the |
Elyes Haouas | 2be03c0 | 2023-02-13 09:14:48 +0100 | [diff] [blame] | 109 | * moment this is only initializes the MMU |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 110 | ******************************************************************************/ |
| 111 | void tsp_plat_arch_setup(void) |
| 112 | { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 113 | #if USE_COHERENT_MEM |
Paul Beesley | 1fbc97b | 2019-01-11 18:26:51 +0000 | [diff] [blame] | 114 | /* Ensure ARM platforms don't use coherent memory in TSP */ |
Daniel Boulby | 45a2c9e | 2018-07-06 16:54:44 +0100 | [diff] [blame] | 115 | assert((BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE) == 0U); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 116 | #endif |
Daniel Boulby | 45a2c9e | 2018-07-06 16:54:44 +0100 | [diff] [blame] | 117 | |
| 118 | const mmap_region_t bl_regions[] = { |
| 119 | MAP_BL_TSP_TOTAL, |
Daniel Boulby | 4e97abd | 2018-07-16 14:09:15 +0100 | [diff] [blame] | 120 | ARM_MAP_BL_RO, |
Harrison Mutai | 64461f7 | 2025-02-21 11:52:48 +0000 | [diff] [blame] | 121 | #if TRANSFER_LIST |
| 122 | MAP_FW_HANDOFF, |
| 123 | #endif |
Daniel Boulby | 45a2c9e | 2018-07-06 16:54:44 +0100 | [diff] [blame] | 124 | {0} |
| 125 | }; |
| 126 | |
Roberto Vargas | 344ff02 | 2018-10-19 16:44:18 +0100 | [diff] [blame] | 127 | setup_page_tables(bl_regions, plat_arm_get_mmap()); |
Sandrine Bailleux | 4a1267a | 2016-05-18 16:11:47 +0100 | [diff] [blame] | 128 | enable_mmu_el1(0); |
Petre-Ionut Tudor | e5a6fef | 2019-11-07 15:18:03 +0000 | [diff] [blame] | 129 | |
| 130 | #if PLAT_RO_XLAT_TABLES |
| 131 | arm_xlat_make_tables_readonly(); |
| 132 | #endif |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 133 | } |