Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 1 | /* |
Soby Mathew | 7c6df5b | 2018-01-15 14:43:42 +0000 | [diff] [blame] | 2 | * Copyright (c) 2015-2018, 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 | |
| 7 | #include <arch.h> |
| 8 | #include <arm_def.h> |
Antonio Nino Diaz | f09d003 | 2017-04-11 14:04:56 +0100 | [diff] [blame] | 9 | #include <arm_xlat_tables.h> |
Roberto Vargas | 2ca18d9 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 10 | #include <bl1.h> |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 11 | #include <bl_common.h> |
Antonio Nino Diaz | b37eba9 | 2018-05-15 13:12:50 +0100 | [diff] [blame] | 12 | #include <console.h> |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 13 | #include <plat_arm.h> |
Roberto Vargas | 2ca18d9 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 14 | #include <platform.h> |
Isla Mitchell | d254879 | 2017-07-14 10:48:25 +0100 | [diff] [blame] | 15 | #include <platform_def.h> |
Juan Castillo | b6132f1 | 2015-10-06 14:01:35 +0100 | [diff] [blame] | 16 | #include <sp805.h> |
Sandrine Bailleux | 28ee10f | 2016-06-15 15:44:27 +0100 | [diff] [blame] | 17 | #include <utils.h> |
Sandrine Bailleux | d7c4750 | 2015-10-02 09:32:35 +0100 | [diff] [blame] | 18 | #include "../../../bl1/bl1_private.h" |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 19 | |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 20 | /* Weak definitions may be overridden in specific ARM standard platform */ |
| 21 | #pragma weak bl1_early_platform_setup |
| 22 | #pragma weak bl1_plat_arch_setup |
| 23 | #pragma weak bl1_platform_setup |
| 24 | #pragma weak bl1_plat_sec_mem_layout |
Yatharth Kochar | ede39cb | 2016-11-14 12:01:04 +0000 | [diff] [blame] | 25 | #pragma weak bl1_plat_prepare_exit |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 26 | |
| 27 | |
| 28 | /* Data structure which holds the extents of the trusted SRAM for BL1*/ |
| 29 | static meminfo_t bl1_tzram_layout; |
| 30 | |
| 31 | meminfo_t *bl1_plat_sec_mem_layout(void) |
| 32 | { |
| 33 | return &bl1_tzram_layout; |
| 34 | } |
| 35 | |
| 36 | /******************************************************************************* |
| 37 | * BL1 specific platform actions shared between ARM standard platforms. |
| 38 | ******************************************************************************/ |
| 39 | void arm_bl1_early_platform_setup(void) |
| 40 | { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 41 | |
Juan Castillo | b6132f1 | 2015-10-06 14:01:35 +0100 | [diff] [blame] | 42 | #if !ARM_DISABLE_TRUSTED_WDOG |
| 43 | /* Enable watchdog */ |
| 44 | sp805_start(ARM_SP805_TWDG_BASE, ARM_TWDG_LOAD_VAL); |
| 45 | #endif |
| 46 | |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 47 | /* Initialize the console to provide early debug support */ |
Antonio Nino Diaz | b37eba9 | 2018-05-15 13:12:50 +0100 | [diff] [blame] | 48 | console_init(PLAT_ARM_BOOT_UART_BASE, PLAT_ARM_BOOT_UART_CLK_IN_HZ, |
| 49 | ARM_CONSOLE_BAUDRATE); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 50 | |
| 51 | /* Allow BL1 to see the whole Trusted RAM */ |
| 52 | bl1_tzram_layout.total_base = ARM_BL_RAM_BASE; |
| 53 | bl1_tzram_layout.total_size = ARM_BL_RAM_SIZE; |
| 54 | |
Yatharth Kochar | f9a0f16 | 2016-09-13 17:07:57 +0100 | [diff] [blame] | 55 | #if !LOAD_IMAGE_V2 |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 56 | /* Calculate how much RAM BL1 is using and how much remains free */ |
| 57 | bl1_tzram_layout.free_base = ARM_BL_RAM_BASE; |
| 58 | bl1_tzram_layout.free_size = ARM_BL_RAM_SIZE; |
| 59 | reserve_mem(&bl1_tzram_layout.free_base, |
| 60 | &bl1_tzram_layout.free_size, |
| 61 | BL1_RAM_BASE, |
Yatharth Kochar | f9a0f16 | 2016-09-13 17:07:57 +0100 | [diff] [blame] | 62 | BL1_RAM_LIMIT - BL1_RAM_BASE); |
| 63 | #endif /* LOAD_IMAGE_V2 */ |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | void bl1_early_platform_setup(void) |
| 67 | { |
| 68 | arm_bl1_early_platform_setup(); |
| 69 | |
| 70 | /* |
Vikram Kanigiri | fbb1301 | 2016-02-15 11:54:14 +0000 | [diff] [blame] | 71 | * Initialize Interconnect for this cluster during cold boot. |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 72 | * No need for locks as no other CPU is active. |
| 73 | */ |
Vikram Kanigiri | fbb1301 | 2016-02-15 11:54:14 +0000 | [diff] [blame] | 74 | plat_arm_interconnect_init(); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 75 | /* |
Vikram Kanigiri | fbb1301 | 2016-02-15 11:54:14 +0000 | [diff] [blame] | 76 | * Enable Interconnect coherency for the primary CPU's cluster. |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 77 | */ |
Vikram Kanigiri | fbb1301 | 2016-02-15 11:54:14 +0000 | [diff] [blame] | 78 | plat_arm_interconnect_enter_coherency(); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | /****************************************************************************** |
| 82 | * Perform the very early platform specific architecture setup shared between |
| 83 | * ARM standard platforms. This only does basic initialization. Later |
| 84 | * architectural setup (bl1_arch_setup()) does not do anything platform |
| 85 | * specific. |
| 86 | *****************************************************************************/ |
| 87 | void arm_bl1_plat_arch_setup(void) |
| 88 | { |
Sandrine Bailleux | 4a1267a | 2016-05-18 16:11:47 +0100 | [diff] [blame] | 89 | arm_setup_page_tables(bl1_tzram_layout.total_base, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 90 | bl1_tzram_layout.total_size, |
Sandrine Bailleux | ecdc4d3 | 2016-07-08 14:38:16 +0100 | [diff] [blame] | 91 | BL_CODE_BASE, |
Masahiro Yamada | 51bef61 | 2017-01-18 02:10:08 +0900 | [diff] [blame] | 92 | BL1_CODE_END, |
Sandrine Bailleux | ecdc4d3 | 2016-07-08 14:38:16 +0100 | [diff] [blame] | 93 | BL1_RO_DATA_BASE, |
Masahiro Yamada | 51bef61 | 2017-01-18 02:10:08 +0900 | [diff] [blame] | 94 | BL1_RO_DATA_END |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 95 | #if USE_COHERENT_MEM |
Masahiro Yamada | 0fac5af | 2016-12-28 16:11:41 +0900 | [diff] [blame] | 96 | , BL_COHERENT_RAM_BASE, |
| 97 | BL_COHERENT_RAM_END |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 98 | #endif |
| 99 | ); |
Yatharth Kochar | 88ac53b | 2016-07-04 11:03:49 +0100 | [diff] [blame] | 100 | #ifdef AARCH32 |
| 101 | enable_mmu_secure(0); |
| 102 | #else |
Sandrine Bailleux | 4a1267a | 2016-05-18 16:11:47 +0100 | [diff] [blame] | 103 | enable_mmu_el3(0); |
Yatharth Kochar | 88ac53b | 2016-07-04 11:03:49 +0100 | [diff] [blame] | 104 | #endif /* AARCH32 */ |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | void bl1_plat_arch_setup(void) |
| 108 | { |
| 109 | arm_bl1_plat_arch_setup(); |
| 110 | } |
| 111 | |
| 112 | /* |
| 113 | * Perform the platform specific architecture setup shared between |
| 114 | * ARM standard platforms. |
| 115 | */ |
| 116 | void arm_bl1_platform_setup(void) |
| 117 | { |
| 118 | /* Initialise the IO layer and register platform IO devices */ |
| 119 | plat_arm_io_setup(); |
Soby Mathew | 7c6df5b | 2018-01-15 14:43:42 +0000 | [diff] [blame] | 120 | #if LOAD_IMAGE_V2 |
| 121 | arm_load_tb_fw_config(); |
| 122 | #endif |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | void bl1_platform_setup(void) |
| 126 | { |
| 127 | arm_bl1_platform_setup(); |
| 128 | } |
| 129 | |
Sandrine Bailleux | 03897bb | 2015-11-26 16:31:34 +0000 | [diff] [blame] | 130 | void bl1_plat_prepare_exit(entry_point_info_t *ep_info) |
| 131 | { |
Juan Castillo | b6132f1 | 2015-10-06 14:01:35 +0100 | [diff] [blame] | 132 | #if !ARM_DISABLE_TRUSTED_WDOG |
| 133 | /* Disable watchdog before leaving BL1 */ |
| 134 | sp805_stop(ARM_SP805_TWDG_BASE); |
| 135 | #endif |
| 136 | |
Sandrine Bailleux | 03897bb | 2015-11-26 16:31:34 +0000 | [diff] [blame] | 137 | #ifdef EL3_PAYLOAD_BASE |
| 138 | /* |
| 139 | * Program the EL3 payload's entry point address into the CPUs mailbox |
| 140 | * in order to release secondary CPUs from their holding pen and make |
| 141 | * them jump there. |
| 142 | */ |
| 143 | arm_program_trusted_mailbox(ep_info->pc); |
| 144 | dsbsy(); |
| 145 | sev(); |
| 146 | #endif |
| 147 | } |
Soby Mathew | 9427357 | 2018-03-07 11:32:04 +0000 | [diff] [blame] | 148 | |
| 149 | /******************************************************************************* |
| 150 | * The following function checks if Firmware update is needed, |
| 151 | * by checking if TOC in FIP image is valid or not. |
| 152 | ******************************************************************************/ |
| 153 | unsigned int bl1_plat_get_next_image_id(void) |
| 154 | { |
| 155 | if (!arm_io_is_toc_valid()) |
| 156 | return NS_BL1U_IMAGE_ID; |
| 157 | |
| 158 | return BL2_IMAGE_ID; |
| 159 | } |