Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 1 | /* |
Antonio Nino Diaz | 83d8c79 | 2018-08-17 14:25:08 +0100 | [diff] [blame] | 2 | * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 7 | #ifndef PLATFORM_DEF_H |
| 8 | #define PLATFORM_DEF_H |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 9 | |
| 10 | #include <arch.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 11 | #include <common/tbbr/tbbr_img_def.h> |
| 12 | #include <lib/utils_def.h> |
| 13 | #include <plat/common/common_def.h> |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 14 | |
Andre Przywara | bb6ef15 | 2019-07-09 11:44:14 +0100 | [diff] [blame] | 15 | #include "rpi_hw.h" |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 16 | |
| 17 | /* Special value used to verify platform parameters from BL2 to BL31 */ |
| 18 | #define RPI3_BL31_PLAT_PARAM_VAL ULL(0x0F1E2D3C4B5A6978) |
| 19 | |
| 20 | #define PLATFORM_STACK_SIZE ULL(0x1000) |
| 21 | |
| 22 | #define PLATFORM_MAX_CPUS_PER_CLUSTER U(4) |
| 23 | #define PLATFORM_CLUSTER_COUNT U(1) |
| 24 | #define PLATFORM_CLUSTER0_CORE_COUNT PLATFORM_MAX_CPUS_PER_CLUSTER |
| 25 | #define PLATFORM_CORE_COUNT PLATFORM_CLUSTER0_CORE_COUNT |
| 26 | |
Andre Przywara | 98e4856 | 2020-03-12 14:20:04 +0000 | [diff] [blame] | 27 | #define RPI_PRIMARY_CPU U(0) |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 28 | |
| 29 | #define PLAT_MAX_PWR_LVL MPIDR_AFFLVL1 |
| 30 | #define PLAT_NUM_PWR_DOMAINS (PLATFORM_CLUSTER_COUNT + \ |
| 31 | PLATFORM_CORE_COUNT) |
| 32 | |
| 33 | #define PLAT_MAX_RET_STATE U(1) |
| 34 | #define PLAT_MAX_OFF_STATE U(2) |
| 35 | |
| 36 | /* Local power state for power domains in Run state. */ |
| 37 | #define PLAT_LOCAL_STATE_RUN U(0) |
| 38 | /* Local power state for retention. Valid only for CPU power domains */ |
| 39 | #define PLAT_LOCAL_STATE_RET U(1) |
| 40 | /* |
| 41 | * Local power state for OFF/power-down. Valid for CPU and cluster power |
| 42 | * domains. |
| 43 | */ |
| 44 | #define PLAT_LOCAL_STATE_OFF U(2) |
| 45 | |
| 46 | /* |
| 47 | * Macros used to parse state information from State-ID if it is using the |
| 48 | * recommended encoding for State-ID. |
| 49 | */ |
| 50 | #define PLAT_LOCAL_PSTATE_WIDTH U(4) |
| 51 | #define PLAT_LOCAL_PSTATE_MASK ((U(1) << PLAT_LOCAL_PSTATE_WIDTH) - 1) |
| 52 | |
| 53 | /* |
| 54 | * Some data must be aligned on the biggest cache line size in the platform. |
| 55 | * This is known only to the platform as it might have a combination of |
| 56 | * integrated and external caches. |
| 57 | */ |
| 58 | #define CACHE_WRITEBACK_SHIFT U(6) |
| 59 | #define CACHE_WRITEBACK_GRANULE (U(1) << CACHE_WRITEBACK_SHIFT) |
| 60 | |
| 61 | /* |
| 62 | * Partition memory into secure ROM, non-secure DRAM, secure "SRAM", and |
| 63 | * secure DRAM. Note that this is all actually DRAM with different names, |
| 64 | * there is no Secure RAM in the Raspberry Pi 3. |
| 65 | */ |
Pete Batard | f820cad | 2018-11-15 22:29:59 +0000 | [diff] [blame] | 66 | #if RPI3_USE_UEFI_MAP |
| 67 | #define SEC_ROM_BASE ULL(0x00000000) |
| 68 | #define SEC_ROM_SIZE ULL(0x00010000) |
| 69 | |
| 70 | /* FIP placed after ROM to append it to BL1 with very little padding. */ |
| 71 | #define PLAT_RPI3_FIP_BASE ULL(0x00020000) |
| 72 | #define PLAT_RPI3_FIP_MAX_SIZE ULL(0x00010000) |
| 73 | |
| 74 | /* Reserve 2M of secure SRAM and DRAM, starting at 2M */ |
| 75 | #define SEC_SRAM_BASE ULL(0x00200000) |
| 76 | #define SEC_SRAM_SIZE ULL(0x00100000) |
| 77 | |
| 78 | #define SEC_DRAM0_BASE ULL(0x00300000) |
| 79 | #define SEC_DRAM0_SIZE ULL(0x00100000) |
| 80 | |
| 81 | /* Windows on ARM requires some RAM at 4M */ |
| 82 | #define NS_DRAM0_BASE ULL(0x00400000) |
| 83 | #define NS_DRAM0_SIZE ULL(0x00C00000) |
| 84 | #else |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 85 | #define SEC_ROM_BASE ULL(0x00000000) |
Ying-Chun Liu (PaulLiu) | 9128df6 | 2018-07-04 02:26:48 +0800 | [diff] [blame] | 86 | #define SEC_ROM_SIZE ULL(0x00020000) |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 87 | |
| 88 | /* FIP placed after ROM to append it to BL1 with very little padding. */ |
Ying-Chun Liu (PaulLiu) | 9128df6 | 2018-07-04 02:26:48 +0800 | [diff] [blame] | 89 | #define PLAT_RPI3_FIP_BASE ULL(0x00020000) |
| 90 | #define PLAT_RPI3_FIP_MAX_SIZE ULL(0x001E0000) |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 91 | |
Antonio Nino Diaz | 50c5a9e | 2018-07-15 11:56:33 +0100 | [diff] [blame] | 92 | /* We have 16M of memory reserved starting at 256M */ |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 93 | #define SEC_SRAM_BASE ULL(0x10000000) |
| 94 | #define SEC_SRAM_SIZE ULL(0x00100000) |
| 95 | |
| 96 | #define SEC_DRAM0_BASE ULL(0x10100000) |
Antonio Nino Diaz | 50c5a9e | 2018-07-15 11:56:33 +0100 | [diff] [blame] | 97 | #define SEC_DRAM0_SIZE ULL(0x00F00000) |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 98 | /* End of reserved memory */ |
| 99 | |
Antonio Nino Diaz | 50c5a9e | 2018-07-15 11:56:33 +0100 | [diff] [blame] | 100 | #define NS_DRAM0_BASE ULL(0x11000000) |
| 101 | #define NS_DRAM0_SIZE ULL(0x01000000) |
Pete Batard | f820cad | 2018-11-15 22:29:59 +0000 | [diff] [blame] | 102 | #endif /* RPI3_USE_UEFI_MAP */ |
Antonio Nino Diaz | 50c5a9e | 2018-07-15 11:56:33 +0100 | [diff] [blame] | 103 | |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 104 | /* |
| 105 | * BL33 entrypoint. |
| 106 | */ |
| 107 | #define PLAT_RPI3_NS_IMAGE_OFFSET NS_DRAM0_BASE |
| 108 | #define PLAT_RPI3_NS_IMAGE_MAX_SIZE NS_DRAM0_SIZE |
| 109 | |
| 110 | /* |
| 111 | * I/O registers. |
| 112 | */ |
Andre Przywara | 4f4f769 | 2019-07-09 15:59:26 +0100 | [diff] [blame] | 113 | #define DEVICE0_BASE RPI_IO_BASE |
| 114 | #define DEVICE0_SIZE RPI_IO_SIZE |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 115 | |
| 116 | /* |
| 117 | * Arm TF lives in SRAM, partition it here |
| 118 | */ |
| 119 | #define SHARED_RAM_BASE SEC_SRAM_BASE |
| 120 | #define SHARED_RAM_SIZE ULL(0x00001000) |
| 121 | |
| 122 | #define BL_RAM_BASE (SHARED_RAM_BASE + SHARED_RAM_SIZE) |
| 123 | #define BL_RAM_SIZE (SEC_SRAM_SIZE - SHARED_RAM_SIZE) |
| 124 | |
| 125 | /* |
| 126 | * Mailbox to control the secondary cores.All secondary cores are held in a wait |
| 127 | * loop in cold boot. To release them perform the following steps (plus any |
| 128 | * additional barriers that may be needed): |
| 129 | * |
| 130 | * uint64_t *entrypoint = (uint64_t *)PLAT_RPI3_TM_ENTRYPOINT; |
| 131 | * *entrypoint = ADDRESS_TO_JUMP_TO; |
| 132 | * |
| 133 | * uint64_t *mbox_entry = (uint64_t *)PLAT_RPI3_TM_HOLD_BASE; |
| 134 | * mbox_entry[cpu_id] = PLAT_RPI3_TM_HOLD_STATE_GO; |
| 135 | * |
| 136 | * sev(); |
| 137 | */ |
| 138 | #define PLAT_RPI3_TRUSTED_MAILBOX_BASE SHARED_RAM_BASE |
| 139 | |
Antonio Nino Diaz | bc29733 | 2018-07-14 01:22:43 +0100 | [diff] [blame] | 140 | /* The secure entry point to be used on warm reset by all CPUs. */ |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 141 | #define PLAT_RPI3_TM_ENTRYPOINT PLAT_RPI3_TRUSTED_MAILBOX_BASE |
| 142 | #define PLAT_RPI3_TM_ENTRYPOINT_SIZE ULL(8) |
| 143 | |
Antonio Nino Diaz | bc29733 | 2018-07-14 01:22:43 +0100 | [diff] [blame] | 144 | /* Hold entries for each CPU. */ |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 145 | #define PLAT_RPI3_TM_HOLD_BASE (PLAT_RPI3_TM_ENTRYPOINT + \ |
| 146 | PLAT_RPI3_TM_ENTRYPOINT_SIZE) |
| 147 | #define PLAT_RPI3_TM_HOLD_ENTRY_SIZE ULL(8) |
| 148 | #define PLAT_RPI3_TM_HOLD_SIZE (PLAT_RPI3_TM_HOLD_ENTRY_SIZE * \ |
| 149 | PLATFORM_CORE_COUNT) |
| 150 | |
| 151 | #define PLAT_RPI3_TRUSTED_MAILBOX_SIZE (PLAT_RPI3_TM_ENTRYPOINT_SIZE + \ |
| 152 | PLAT_RPI3_TM_HOLD_SIZE) |
| 153 | |
| 154 | #define PLAT_RPI3_TM_HOLD_STATE_WAIT ULL(0) |
| 155 | #define PLAT_RPI3_TM_HOLD_STATE_GO ULL(1) |
Andrei Warkentin | c96d430 | 2020-03-11 22:11:06 -0700 | [diff] [blame^] | 156 | #define PLAT_RPI3_TM_HOLD_STATE_BSP_OFF ULL(2) |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 157 | |
| 158 | /* |
| 159 | * BL1 specific defines. |
| 160 | * |
| 161 | * BL1 RW data is relocated from ROM to RAM at runtime so we need 2 sets of |
| 162 | * addresses. |
| 163 | * |
| 164 | * Put BL1 RW at the top of the Secure SRAM. BL1_RW_BASE is calculated using |
| 165 | * the current BL1 RW debug size plus a little space for growth. |
| 166 | */ |
| 167 | #define PLAT_MAX_BL1_RW_SIZE ULL(0x12000) |
| 168 | |
| 169 | #define BL1_RO_BASE SEC_ROM_BASE |
| 170 | #define BL1_RO_LIMIT (SEC_ROM_BASE + SEC_ROM_SIZE) |
| 171 | #define BL1_RW_BASE (BL1_RW_LIMIT - PLAT_MAX_BL1_RW_SIZE) |
| 172 | #define BL1_RW_LIMIT (BL_RAM_BASE + BL_RAM_SIZE) |
| 173 | |
| 174 | /* |
| 175 | * BL2 specific defines. |
| 176 | * |
| 177 | * Put BL2 just below BL31. BL2_BASE is calculated using the current BL2 debug |
| 178 | * size plus a little space for growth. |
| 179 | */ |
| 180 | #define PLAT_MAX_BL2_SIZE ULL(0x2C000) |
| 181 | |
| 182 | #define BL2_BASE (BL2_LIMIT - PLAT_MAX_BL2_SIZE) |
| 183 | #define BL2_LIMIT BL31_BASE |
| 184 | |
| 185 | /* |
| 186 | * BL31 specific defines. |
| 187 | * |
| 188 | * Put BL31 at the top of the Trusted SRAM. BL31_BASE is calculated using the |
| 189 | * current BL31 debug size plus a little space for growth. |
| 190 | */ |
| 191 | #define PLAT_MAX_BL31_SIZE ULL(0x20000) |
| 192 | |
| 193 | #define BL31_BASE (BL31_LIMIT - PLAT_MAX_BL31_SIZE) |
| 194 | #define BL31_LIMIT (BL_RAM_BASE + BL_RAM_SIZE) |
| 195 | #define BL31_PROGBITS_LIMIT BL1_RW_BASE |
| 196 | |
| 197 | /* |
| 198 | * BL32 specific defines. |
| 199 | * |
| 200 | * BL32 can execute from Secure SRAM or Secure DRAM. |
| 201 | */ |
| 202 | #define BL32_SRAM_BASE BL_RAM_BASE |
| 203 | #define BL32_SRAM_LIMIT BL31_BASE |
| 204 | #define BL32_DRAM_BASE SEC_DRAM0_BASE |
| 205 | #define BL32_DRAM_LIMIT (SEC_DRAM0_BASE + SEC_DRAM0_SIZE) |
| 206 | |
Ying-Chun Liu (PaulLiu) | d9f76e6 | 2018-06-10 02:00:27 +0800 | [diff] [blame] | 207 | #ifdef SPD_opteed |
| 208 | /* Load pageable part of OP-TEE at end of allocated DRAM space for BL32 */ |
| 209 | #define RPI3_OPTEE_PAGEABLE_LOAD_SIZE 0x080000 /* 512KB */ |
| 210 | #define RPI3_OPTEE_PAGEABLE_LOAD_BASE (BL32_DRAM_LIMIT - \ |
| 211 | RPI3_OPTEE_PAGEABLE_LOAD_SIZE) |
| 212 | #endif |
| 213 | |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 214 | #define SEC_SRAM_ID 0 |
| 215 | #define SEC_DRAM_ID 1 |
| 216 | |
| 217 | #if RPI3_BL32_RAM_LOCATION_ID == SEC_SRAM_ID |
| 218 | # define BL32_MEM_BASE BL_RAM_BASE |
| 219 | # define BL32_MEM_SIZE BL_RAM_SIZE |
| 220 | # define BL32_BASE BL32_SRAM_BASE |
| 221 | # define BL32_LIMIT BL32_SRAM_LIMIT |
| 222 | #elif RPI3_BL32_RAM_LOCATION_ID == SEC_DRAM_ID |
| 223 | # define BL32_MEM_BASE SEC_DRAM0_BASE |
| 224 | # define BL32_MEM_SIZE SEC_DRAM0_SIZE |
| 225 | # define BL32_BASE BL32_DRAM_BASE |
| 226 | # define BL32_LIMIT BL32_DRAM_LIMIT |
| 227 | #else |
| 228 | # error "Unsupported RPI3_BL32_RAM_LOCATION_ID value" |
| 229 | #endif |
| 230 | #define BL32_SIZE (BL32_LIMIT - BL32_BASE) |
| 231 | |
| 232 | #ifdef SPD_none |
| 233 | #undef BL32_BASE |
| 234 | #endif /* SPD_none */ |
| 235 | |
| 236 | /* |
| 237 | * Other memory-related defines. |
| 238 | */ |
Antonio Nino Diaz | 83d8c79 | 2018-08-17 14:25:08 +0100 | [diff] [blame] | 239 | #define PLAT_PHY_ADDR_SPACE_SIZE (ULL(1) << 32) |
| 240 | #define PLAT_VIRT_ADDR_SPACE_SIZE (ULL(1) << 32) |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 241 | |
Antonio Nino Diaz | 50eb374 | 2018-07-24 10:20:53 +0100 | [diff] [blame] | 242 | #define MAX_MMAP_REGIONS 8 |
| 243 | #define MAX_XLAT_TABLES 4 |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 244 | |
| 245 | #define MAX_IO_DEVICES U(3) |
| 246 | #define MAX_IO_HANDLES U(4) |
| 247 | |
Ying-Chun Liu (PaulLiu) | de6f2f4 | 2019-01-30 04:20:38 +0800 | [diff] [blame] | 248 | #define MAX_IO_BLOCK_DEVICES U(1) |
| 249 | |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 250 | /* |
| 251 | * Serial-related constants. |
| 252 | */ |
Andre Przywara | 57ccecc | 2020-03-10 12:33:16 +0000 | [diff] [blame] | 253 | #define PLAT_RPI_MINI_UART_BASE RPI3_MINI_UART_BASE |
Andre Przywara | 9ba6bb0 | 2020-03-10 12:34:56 +0000 | [diff] [blame] | 254 | #define PLAT_RPI_PL011_UART_BASE RPI3_PL011_UART_BASE |
| 255 | #define PLAT_RPI_PL011_UART_CLOCK RPI3_PL011_UART_CLOCK |
Andre Przywara | 57ccecc | 2020-03-10 12:33:16 +0000 | [diff] [blame] | 256 | #define PLAT_RPI_UART_BAUDRATE ULL(115200) |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 257 | |
| 258 | /* |
| 259 | * System counter |
| 260 | */ |
| 261 | #define SYS_COUNTER_FREQ_IN_TICKS ULL(19200000) |
| 262 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 263 | #endif /* PLATFORM_DEF_H */ |