Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 1 | /* |
Varun Wadekar | 4538bfc | 2019-01-02 17:53:15 -0800 | [diff] [blame] | 2 | * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 5 | */ |
| 6 | |
Varun Wadekar | b7b4575 | 2015-12-28 14:55:41 -0800 | [diff] [blame] | 7 | #include <arch_helpers.h> |
Varun Wadekar | f07d6de | 2018-02-27 14:33:57 -0800 | [diff] [blame] | 8 | #include <assert.h> |
Sam Payne | 71ce6ed | 2017-05-08 12:42:49 -0700 | [diff] [blame] | 9 | #include <cortex_a57.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 10 | #include <common/bl_common.h> |
Varun Wadekar | 4538bfc | 2019-01-02 17:53:15 -0800 | [diff] [blame] | 11 | #include <common/debug.h> |
| 12 | #include <common/interrupt_props.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 13 | #include <drivers/console.h> |
| 14 | #include <lib/xlat_tables/xlat_tables_v2.h> |
Varun Wadekar | 4538bfc | 2019-01-02 17:53:15 -0800 | [diff] [blame] | 15 | #include <drivers/arm/gic_common.h> |
| 16 | #include <drivers/arm/gicv2.h> |
| 17 | #include <bl31/interrupt_mgmt.h> |
| 18 | |
| 19 | #include <bpmp.h> |
| 20 | #include <flowctrl.h> |
Varun Wadekar | e34bc3d | 2017-04-28 08:43:33 -0700 | [diff] [blame] | 21 | #include <platform.h> |
Marvin Hsu | 21eea97 | 2017-04-11 11:00:48 +0800 | [diff] [blame] | 22 | #include <security_engine.h> |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 23 | #include <tegra_def.h> |
Marvin Hsu | 21eea97 | 2017-04-11 11:00:48 +0800 | [diff] [blame] | 24 | #include <tegra_platform.h> |
Varun Wadekar | b7b4575 | 2015-12-28 14:55:41 -0800 | [diff] [blame] | 25 | #include <tegra_private.h> |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 26 | |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 27 | /* sets of MMIO ranges setup */ |
| 28 | #define MMIO_RANGE_0_ADDR 0x50000000 |
| 29 | #define MMIO_RANGE_1_ADDR 0x60000000 |
| 30 | #define MMIO_RANGE_2_ADDR 0x70000000 |
| 31 | #define MMIO_RANGE_SIZE 0x200000 |
| 32 | |
| 33 | /* |
| 34 | * Table of regions to map using the MMU. |
| 35 | */ |
| 36 | static const mmap_region_t tegra_mmap[] = { |
Varun Wadekar | 08554a6 | 2017-06-12 16:47:16 -0700 | [diff] [blame] | 37 | MAP_REGION_FLAT(TEGRA_IRAM_BASE, 0x40000, /* 256KB */ |
Varun Wadekar | a6a357f | 2017-05-05 09:20:59 -0700 | [diff] [blame] | 38 | MT_DEVICE | MT_RW | MT_SECURE), |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 39 | MAP_REGION_FLAT(MMIO_RANGE_0_ADDR, MMIO_RANGE_SIZE, |
| 40 | MT_DEVICE | MT_RW | MT_SECURE), |
| 41 | MAP_REGION_FLAT(MMIO_RANGE_1_ADDR, MMIO_RANGE_SIZE, |
| 42 | MT_DEVICE | MT_RW | MT_SECURE), |
| 43 | MAP_REGION_FLAT(MMIO_RANGE_2_ADDR, MMIO_RANGE_SIZE, |
| 44 | MT_DEVICE | MT_RW | MT_SECURE), |
| 45 | {0} |
| 46 | }; |
| 47 | |
| 48 | /******************************************************************************* |
| 49 | * Set up the pagetables as per the platform memory map & initialize the MMU |
| 50 | ******************************************************************************/ |
| 51 | const mmap_region_t *plat_get_mmio_map(void) |
| 52 | { |
Marvin Hsu | 21eea97 | 2017-04-11 11:00:48 +0800 | [diff] [blame] | 53 | /* Add the map region for security engine SE2 */ |
| 54 | if (tegra_chipid_is_t210_b01()) { |
| 55 | mmap_add_region((uint64_t)TEGRA_SE2_BASE, |
| 56 | (uint64_t)TEGRA_SE2_BASE, |
| 57 | (uint64_t)TEGRA_SE2_RANGE_SIZE, |
| 58 | MT_DEVICE | MT_RW | MT_SECURE); |
| 59 | } |
| 60 | |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 61 | /* MMIO space */ |
| 62 | return tegra_mmap; |
| 63 | } |
| 64 | |
| 65 | /******************************************************************************* |
Varun Wadekar | e34bc3d | 2017-04-28 08:43:33 -0700 | [diff] [blame] | 66 | * The Tegra power domain tree has a single system level power domain i.e. a |
| 67 | * single root node. The first entry in the power domain descriptor specifies |
| 68 | * the number of power domains at the highest power level. |
| 69 | ******************************************************************************* |
| 70 | */ |
| 71 | const unsigned char tegra_power_domain_tree_desc[] = { |
| 72 | /* No of root nodes */ |
| 73 | 1, |
| 74 | /* No of clusters */ |
| 75 | PLATFORM_CLUSTER_COUNT, |
| 76 | /* No of CPU cores - cluster0 */ |
| 77 | PLATFORM_MAX_CPUS_PER_CLUSTER, |
| 78 | /* No of CPU cores - cluster1 */ |
| 79 | PLATFORM_MAX_CPUS_PER_CLUSTER |
| 80 | }; |
| 81 | |
| 82 | /******************************************************************************* |
| 83 | * This function returns the Tegra default topology tree information. |
| 84 | ******************************************************************************/ |
| 85 | const unsigned char *plat_get_power_domain_tree_desc(void) |
| 86 | { |
| 87 | return tegra_power_domain_tree_desc; |
| 88 | } |
| 89 | |
| 90 | /******************************************************************************* |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 91 | * Handler to get the System Counter Frequency |
| 92 | ******************************************************************************/ |
Antonio Nino Diaz | e82e29c | 2016-05-19 10:00:28 +0100 | [diff] [blame] | 93 | unsigned int plat_get_syscnt_freq2(void) |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 94 | { |
| 95 | return 19200000; |
| 96 | } |
Varun Wadekar | d2014c6 | 2015-10-29 10:37:28 +0530 | [diff] [blame] | 97 | |
| 98 | /******************************************************************************* |
| 99 | * Maximum supported UART controllers |
| 100 | ******************************************************************************/ |
| 101 | #define TEGRA210_MAX_UART_PORTS 5 |
| 102 | |
| 103 | /******************************************************************************* |
| 104 | * This variable holds the UART port base addresses |
| 105 | ******************************************************************************/ |
| 106 | static uint32_t tegra210_uart_addresses[TEGRA210_MAX_UART_PORTS + 1] = { |
| 107 | 0, /* undefined - treated as an error case */ |
| 108 | TEGRA_UARTA_BASE, |
| 109 | TEGRA_UARTB_BASE, |
| 110 | TEGRA_UARTC_BASE, |
| 111 | TEGRA_UARTD_BASE, |
| 112 | TEGRA_UARTE_BASE, |
| 113 | }; |
| 114 | |
| 115 | /******************************************************************************* |
| 116 | * Retrieve the UART controller base to be used as the console |
| 117 | ******************************************************************************/ |
| 118 | uint32_t plat_get_console_from_id(int id) |
| 119 | { |
| 120 | if (id > TEGRA210_MAX_UART_PORTS) |
| 121 | return 0; |
| 122 | |
| 123 | return tegra210_uart_addresses[id]; |
| 124 | } |
Varun Wadekar | b7b4575 | 2015-12-28 14:55:41 -0800 | [diff] [blame] | 125 | |
| 126 | /******************************************************************************* |
Marvin Hsu | 21eea97 | 2017-04-11 11:00:48 +0800 | [diff] [blame] | 127 | * Handler for early platform setup |
| 128 | ******************************************************************************/ |
| 129 | void plat_early_platform_setup(void) |
| 130 | { |
Sam Payne | 71ce6ed | 2017-05-08 12:42:49 -0700 | [diff] [blame] | 131 | const plat_params_from_bl2_t *plat_params = bl31_get_plat_params(); |
| 132 | uint64_t val; |
| 133 | |
| 134 | /* platform parameter passed by the previous bootloader */ |
| 135 | if (plat_params->l2_ecc_parity_prot_dis != 1) { |
| 136 | /* Enable ECC Parity Protection for Cortex-A57 CPUs */ |
| 137 | val = read_l2ctlr_el1(); |
| 138 | val |= (uint64_t)CORTEX_A57_L2_ECC_PARITY_PROTECTION_BIT; |
| 139 | write_l2ctlr_el1(val); |
| 140 | } |
| 141 | |
Marvin Hsu | 21eea97 | 2017-04-11 11:00:48 +0800 | [diff] [blame] | 142 | /* Initialize security engine driver */ |
| 143 | if (tegra_chipid_is_t210_b01()) { |
| 144 | tegra_se_init(); |
| 145 | } |
| 146 | } |
| 147 | |
Varun Wadekar | 4538bfc | 2019-01-02 17:53:15 -0800 | [diff] [blame] | 148 | /* Secure IRQs for Tegra186 */ |
| 149 | static const interrupt_prop_t tegra210_interrupt_props[] = { |
| 150 | INTR_PROP_DESC(TEGRA210_WDT_CPU_LEGACY_FIQ, GIC_HIGHEST_SEC_PRIORITY, |
| 151 | GICV2_INTR_GROUP0, GIC_INTR_CFG_EDGE), |
| 152 | }; |
| 153 | |
Varun Wadekar | f07d6de | 2018-02-27 14:33:57 -0800 | [diff] [blame] | 154 | void plat_late_platform_setup(void) |
| 155 | { |
| 156 | const plat_params_from_bl2_t *plat_params = bl31_get_plat_params(); |
| 157 | uint64_t tzdram_start, tzdram_end, sc7entry_end; |
| 158 | int ret; |
| 159 | |
| 160 | /* memmap TZDRAM area containing the SC7 Entry Firmware */ |
| 161 | if (plat_params->sc7entry_fw_base && plat_params->sc7entry_fw_size) { |
| 162 | |
| 163 | assert(plat_params->sc7entry_fw_size <= TEGRA_IRAM_SIZE); |
| 164 | |
| 165 | /* |
| 166 | * Verify that the SC7 entry firmware resides inside the TZDRAM |
| 167 | * aperture, _after_ the BL31 code. |
| 168 | */ |
| 169 | tzdram_start = plat_params->tzdram_base; |
| 170 | tzdram_end = plat_params->tzdram_base + plat_params->tzdram_size; |
| 171 | sc7entry_end = plat_params->sc7entry_fw_base + |
| 172 | plat_params->sc7entry_fw_size; |
| 173 | if ((plat_params->sc7entry_fw_base < (tzdram_start + BL31_SIZE)) || |
| 174 | (sc7entry_end > tzdram_end)) { |
| 175 | panic(); |
| 176 | } |
| 177 | |
| 178 | /* power off BPMP processor until SC7 entry */ |
| 179 | tegra_fc_bpmp_off(); |
| 180 | |
| 181 | /* memmap SC7 entry firmware code */ |
| 182 | ret = mmap_add_dynamic_region(plat_params->sc7entry_fw_base, |
| 183 | plat_params->sc7entry_fw_base, |
| 184 | plat_params->sc7entry_fw_size, |
| 185 | MT_NS | MT_RO | MT_EXECUTE_NEVER); |
| 186 | assert(ret == 0); |
| 187 | } |
| 188 | } |
| 189 | |
Marvin Hsu | 21eea97 | 2017-04-11 11:00:48 +0800 | [diff] [blame] | 190 | /******************************************************************************* |
Varun Wadekar | b7b4575 | 2015-12-28 14:55:41 -0800 | [diff] [blame] | 191 | * Initialize the GIC and SGIs |
| 192 | ******************************************************************************/ |
| 193 | void plat_gic_setup(void) |
| 194 | { |
Varun Wadekar | 4538bfc | 2019-01-02 17:53:15 -0800 | [diff] [blame] | 195 | tegra_gic_setup(tegra210_interrupt_props, ARRAY_SIZE(tegra210_interrupt_props)); |
| 196 | |
| 197 | /* Enable handling for FIQs */ |
| 198 | tegra_fiq_handler_setup(); |
| 199 | |
| 200 | /* |
| 201 | * Enable routing watchdog FIQs from the flow controller to |
| 202 | * the GICD. |
| 203 | */ |
| 204 | tegra_fc_enable_fiq_to_ccplex_routing(); |
Varun Wadekar | b7b4575 | 2015-12-28 14:55:41 -0800 | [diff] [blame] | 205 | } |