rutigl@gmail.com | defbeed | 2023-03-19 09:19:05 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015-2023, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * Copyright (c) 2017-2023 Nuvoton Technology Corp. |
| 5 | * |
| 6 | * SPDX-License-Identifier: BSD-3-Clause |
| 7 | */ |
| 8 | |
| 9 | #ifndef PLATFORM_DEF_H |
| 10 | #define PLATFORM_DEF_H |
| 11 | |
| 12 | #include <arch.h> |
| 13 | #include <common/interrupt_props.h> |
| 14 | #include <common/tbbr/tbbr_img_def.h> |
| 15 | #include <drivers/arm/gic_common.h> |
| 16 | #include <lib/utils_def.h> |
| 17 | #include <lib/xlat_tables/xlat_tables_defs.h> |
| 18 | #include <npcm845x_arm_def.h> |
| 19 | #include <plat/arm/common/smccc_def.h> |
| 20 | #include <plat/common/common_def.h> |
| 21 | |
| 22 | #define VALUE_TO_STRING(x) #x |
| 23 | #define VALUE(x) VALUE_TO_STRING(x) |
| 24 | #define VAR_NAME_VALUE(var) #var "=" VALUE(var) |
| 25 | |
| 26 | #define PLATFORM_LINKER_FORMAT "elf64-littleaarch64" |
| 27 | #define PLATFORM_LINKER_ARCH aarch64 |
| 28 | |
| 29 | #define PLATFORM_STACK_SIZE 0x400 |
| 30 | |
| 31 | #define PLATFORM_CORE_COUNT NPCM845x_PLATFORM_CORE_COUNT |
| 32 | #define PLATFORM_CLUSTER_COUNT NPCM845x_CLUSTER_COUNT |
| 33 | #define PLATFORM_MAX_CPU_PER_CLUSTER NPCM845x_MAX_CPU_PER_CLUSTER |
| 34 | #define PLAT_PRIMARY_CPU NPCM845x_PLAT_PRIMARY_CPU |
| 35 | #define PLATFORM_SYSTEM_COUNT NPCM845x_SYSTEM_COUNT |
| 36 | |
| 37 | /* Local power state for power domains in Run state. */ |
| 38 | #define PLAT_LOCAL_STATE_RUN U(0) |
| 39 | /* Local power state for retention. Valid only for CPU power domains */ |
| 40 | #define PLAT_LOCAL_STATE_RET U(1) |
| 41 | /* |
| 42 | * Local power state for OFF/power-down. Valid for CPU and cluster power |
| 43 | * domains. |
| 44 | */ |
| 45 | #define PLAT_LOCAL_STATE_OFF U(2) |
| 46 | |
| 47 | /* |
| 48 | * This macro defines the deepest power down states possible. Any state ID |
| 49 | * higher than this is invalid. |
| 50 | */ |
| 51 | #define PLAT_MAX_OFF_STATE PLAT_LOCAL_STATE_OFF |
| 52 | #define PLAT_MAX_RET_STATE PLAT_LOCAL_STATE_RET |
| 53 | |
| 54 | #define PLAT_NUM_PWR_DOMAINS (PLATFORM_CLUSTER_COUNT + PLATFORM_CORE_COUNT) |
| 55 | #define NPCM845x_MAX_PWR_LVL ARM_PWR_LVL1 |
| 56 | |
| 57 | /* |
| 58 | * Macros used to parse state information from State-ID if it is using the |
| 59 | * recommended encoding for State-ID. |
| 60 | */ |
| 61 | #define PLAT_LOCAL_PSTATE_WIDTH 4 |
| 62 | #define PLAT_LOCAL_PSTATE_MASK ((1 << PLAT_LOCAL_PSTATE_WIDTH) - 1) |
| 63 | |
| 64 | /* |
| 65 | * Required ARM standard platform porting definitions |
| 66 | */ |
| 67 | #define PLAT_ARM_CLUSTER_COUNT PLATFORM_CLUSTER_COUNT |
| 68 | |
| 69 | #define PLAT_NUM_PWR_DOMAINS (PLATFORM_CLUSTER_COUNT + PLATFORM_CORE_COUNT) |
| 70 | #define PLAT_MAX_PWR_LVL NPCM845x_MAX_PWR_LVL |
| 71 | |
| 72 | #define PLAT_LOCAL_PSTATE_WIDTH 4 |
| 73 | #define PLAT_LOCAL_PSTATE_MASK ((1 << PLAT_LOCAL_PSTATE_WIDTH) - 1) |
| 74 | |
| 75 | #ifdef BL32_BASE |
| 76 | |
| 77 | #ifndef CONFIG_TARGET_ARBEL_PALLADIUM |
| 78 | #define PLAT_ARM_TRUSTED_DRAM_BASE BL32_BASE |
| 79 | #else |
| 80 | #define PLAT_ARM_TRUSTED_DRAM_BASE BL32_BASE |
| 81 | #endif /* CONFIG_TARGET_ARBEL_PALLADIUM */ |
| 82 | |
| 83 | #define PLAT_ARM_TRUSTED_DRAM_SIZE UL(0x02000000) /* 32 MB */ |
| 84 | #endif /* BL32_BASE */ |
| 85 | |
| 86 | #define PWR_DOMAIN_AT_MAX_LVL U(1) |
| 87 | |
| 88 | #define PLAT_VIRT_ADDR_SPACE_SIZE (1ull << 32) |
| 89 | #define PLAT_PHY_ADDR_SPACE_SIZE (1ull << 32) |
| 90 | #define MAX_XLAT_TABLES 16 |
| 91 | #define PLAT_ARM_MMAP_ENTRIES 17 |
| 92 | |
| 93 | #ifdef NPCM845X_DEBUG |
| 94 | #define MAX_MMAP_REGIONS 8 |
| 95 | #define NPCM845X_TZ1_BASE 0xFFFB0000 |
| 96 | #endif /* NPCM845X_DEBUG */ |
| 97 | |
| 98 | #define FIQ_SMP_CALL_SGI 10 |
| 99 | |
| 100 | /* (0x00040000) 128 KB, the rest 128K if it is non secured */ |
| 101 | #define PLAT_ARM_TRUSTED_SRAM_SIZE UL(0x00020000) |
| 102 | |
| 103 | #define ARM_SHARED_RAM_SIZE UL(0x00001000) /* 4 KB */ |
| 104 | |
| 105 | /* UL(0xfffCE000) add calc ARM_TRUSTED_SRAM_BASE */ |
| 106 | #define ARM_SHARED_RAM_BASE (BL31_BASE + 0x00020000 - ARM_SHARED_RAM_SIZE) |
| 107 | |
| 108 | /* The remaining Trusted SRAM is used to load the BL images */ |
| 109 | #define ARM_BL_RAM_BASE (ARM_SHARED_RAM_BASE + ARM_SHARED_RAM_SIZE) |
| 110 | |
| 111 | /* |
| 112 | * PLAT_ARM_TRUSTED_SRAM_SIZE is taken from platform_def.h 0x20000 |
| 113 | * because only half is secured in this specific implementation |
| 114 | */ |
| 115 | #define ARM_BL_RAM_SIZE (PLAT_ARM_TRUSTED_SRAM_SIZE - ARM_SHARED_RAM_SIZE) |
| 116 | |
| 117 | #if RESET_TO_BL31 |
| 118 | /* Size of Trusted SRAM - the first 4KB of shared memory */ |
| 119 | #define PLAT_ARM_MAX_BL31_SIZE \ |
| 120 | (PLAT_ARM_TRUSTED_SRAM_SIZE - ARM_SHARED_RAM_SIZE) |
| 121 | #else |
| 122 | /* |
| 123 | * Since BL31 NOBITS overlays BL2 and BL1-RW, PLAT_ARM_MAX_BL31_SIZE |
| 124 | * is calculated using the current BL31 PROGBITS debug size plus the sizes |
| 125 | * of BL2 and BL1-RW |
| 126 | */ |
| 127 | #define PLAT_ARM_MAX_BL31_SIZE \ |
| 128 | (PLAT_ARM_TRUSTED_SRAM_SIZE - ARM_SHARED_RAM_SIZE) |
| 129 | #endif /* RESET_TO_BL31 */ |
| 130 | /* |
| 131 | * Load address of BL33 for this platform port |
| 132 | */ |
| 133 | #define PLAT_ARM_NS_IMAGE_BASE (ARM_DRAM1_BASE + UL(0x6208000)) |
| 134 | |
| 135 | #ifdef NPCM845X_DEBUG |
| 136 | #define COUNTER_FREQUENCY 0x07735940 /* f/4 = 125MHz */ |
| 137 | #endif /* NPCM845X_DEBUG */ |
| 138 | |
| 139 | #define COUNTER_FREQUENCY 0x0EE6B280 /* f/2 = 250MHz */ |
| 140 | #define PLAT_ARM_NSTIMER_FRAME_ID U(1) |
| 141 | |
| 142 | /* GIC parameters */ |
| 143 | |
| 144 | /* Base compatible GIC memory map */ |
| 145 | #define NT_GIC_BASE (0xDFFF8000) |
| 146 | #define BASE_GICD_BASE (NT_GIC_BASE + 0x1000) |
| 147 | #define BASE_GICC_BASE (NT_GIC_BASE + 0x2000) |
| 148 | #define BASE_GICR_BASE (NT_GIC_BASE + 0x200000) |
| 149 | #define BASE_GICH_BASE (NT_GIC_BASE + 0x4000) |
| 150 | #define BASE_GICV_BASE (NT_GIC_BASE + 0x6000) |
| 151 | |
| 152 | #define DEVICE1_BASE BASE_GICD_BASE |
| 153 | #define DEVICE1_SIZE 0x7000 |
| 154 | |
| 155 | #ifdef NPCM845X_DEBUG |
| 156 | /* ((BASE_GICR_BASE - BASE_GICD_BASE) + (PLATFORM_CORE_COUNT * 0x20000)) */ |
| 157 | #define ARM_CPU_START_ADDRESS(m) UL(0xf0800e00 + 0x10 + m * 4) |
| 158 | #endif /* NPCM845X_DEBUG */ |
| 159 | |
| 160 | #define PLAT_REG_BASE NPCM845x_REG_BASE |
| 161 | #define PLAT_REG_SIZE NPCM845x_REG_SIZE |
| 162 | |
| 163 | /* MMU entry for internal (register) space access */ |
| 164 | #define MAP_DEVICE0 \ |
| 165 | MAP_REGION_FLAT(PLAT_REG_BASE, PLAT_REG_SIZE, MT_DEVICE | MT_RW | MT_NS) |
| 166 | |
| 167 | #define MAP_DEVICE1 \ |
| 168 | MAP_REGION_FLAT(DEVICE1_BASE, DEVICE1_SIZE, \ |
| 169 | MT_DEVICE | MT_RW | MT_SECURE) |
| 170 | |
| 171 | /* |
| 172 | * Define a list of Group 1 Secure and Group 0 interrupt properties |
| 173 | * as per GICv3 terminology. On a GICv2 system or mode, |
| 174 | * the lists will be merged and treated as Group 0 interrupts. |
| 175 | */ |
| 176 | #define PLAT_ARM_GICD_BASE BASE_GICD_BASE |
| 177 | #define PLAT_ARM_GICC_BASE BASE_GICC_BASE |
| 178 | |
| 179 | #define PLAT_ARM_G1S_IRQ_PROPS(grp) \ |
| 180 | INTR_PROP_DESC(ARM_IRQ_SEC_PHY_TIMER, GIC_HIGHEST_SEC_PRIORITY, grp, \ |
| 181 | GIC_INTR_CFG_LEVEL), \ |
| 182 | INTR_PROP_DESC(ARM_IRQ_SEC_SGI_0, GIC_HIGHEST_SEC_PRIORITY, \ |
| 183 | grp, GIC_INTR_CFG_EDGE), \ |
| 184 | INTR_PROP_DESC(ARM_IRQ_SEC_SGI_1, GIC_HIGHEST_SEC_PRIORITY, \ |
| 185 | grp, GIC_INTR_CFG_EDGE), \ |
| 186 | INTR_PROP_DESC(ARM_IRQ_SEC_SGI_2, GIC_HIGHEST_SEC_PRIORITY, \ |
| 187 | grp, GIC_INTR_CFG_EDGE), \ |
| 188 | INTR_PROP_DESC(ARM_IRQ_SEC_SGI_3, GIC_HIGHEST_SEC_PRIORITY, \ |
| 189 | grp, GIC_INTR_CFG_EDGE), \ |
| 190 | INTR_PROP_DESC(ARM_IRQ_SEC_SGI_4, GIC_HIGHEST_SEC_PRIORITY, \ |
| 191 | grp, GIC_INTR_CFG_EDGE), \ |
| 192 | INTR_PROP_DESC(ARM_IRQ_SEC_SGI_5, GIC_HIGHEST_SEC_PRIORITY, \ |
| 193 | grp, GIC_INTR_CFG_EDGE), \ |
| 194 | INTR_PROP_DESC(ARM_IRQ_SEC_SGI_6, GIC_HIGHEST_SEC_PRIORITY, \ |
| 195 | grp, GIC_INTR_CFG_EDGE), \ |
| 196 | INTR_PROP_DESC(ARM_IRQ_SEC_SGI_7, GIC_HIGHEST_SEC_PRIORITY, \ |
| 197 | grp, GIC_INTR_CFG_EDGE) |
| 198 | |
| 199 | #define PLAT_ARM_G0_IRQ_PROPS(grp) |
| 200 | |
| 201 | /* Required for compilation: */ |
| 202 | |
| 203 | /* |
| 204 | * PLAT_ARM_MAX_BL1_RW_SIZE is calculated using the current BL1 RW debug size |
| 205 | * plus a little space for growth. |
| 206 | */ |
| 207 | #define PLAT_ARM_MAX_BL1_RW_SIZE 0 /* UL(0xB000) */ |
| 208 | #if USE_ROMLIB |
| 209 | #define PLAT_ARM_MAX_ROMLIB_RW_SIZE UL(0x1000) |
| 210 | #define PLAT_ARM_MAX_ROMLIB_RO_SIZE UL(0xe000) |
| 211 | #define FVP_BL2_ROMLIB_OPTIMIZATION UL(0x6000) |
| 212 | #else |
| 213 | #define PLAT_ARM_MAX_ROMLIB_RW_SIZE UL(0) |
| 214 | #define PLAT_ARM_MAX_ROMLIB_RO_SIZE UL(0) |
| 215 | #define FVP_BL2_ROMLIB_OPTIMIZATION UL(0) |
| 216 | #endif /* USE_ROMLIB */ |
| 217 | |
| 218 | /* |
| 219 | * PLAT_ARM_MAX_BL2_SIZE is calculated using the current BL2 debug size |
| 220 | * plus a little space for growth. |
| 221 | */ |
| 222 | #if TRUSTED_BOARD_BOOT |
| 223 | #define PLAT_ARM_MAX_BL2_SIZE (UL(0x1D000) * FVP_BL2_ROMLIB_OPTIMIZATION) |
| 224 | #else |
| 225 | /* (UL(0x13000) - FVP_BL2_ROMLIB_OPTIMIZATION) */ |
| 226 | #define PLAT_ARM_MAX_BL2_SIZE 0 |
| 227 | #endif /* TRUSTED_BOARD_BOOT */ |
| 228 | |
| 229 | #undef NPCM_PRINT_ONCE |
| 230 | #ifdef NPCM_PRINT_ONCE |
| 231 | #define PRINT_ONLY_ONCE |
| 232 | #pragma message(VAR_NAME_VALUE(ARM_AP_TZC_DRAM1_BASE)) |
| 233 | #pragma message(VAR_NAME_VALUE(BL31_BASE)) |
| 234 | #pragma message(VAR_NAME_VALUE(BL31_LIMIT)) |
| 235 | #pragma message(VAR_NAME_VALUE(PLAT_ARM_MAX_BL31_SIZE)) |
| 236 | #pragma message(VAR_NAME_VALUE(BL32_BASE)) |
| 237 | #pragma message(VAR_NAME_VALUE(BL32_LIMIT)) |
| 238 | #pragma message(VAR_NAME_VALUE(PLAT_ARM_MAX_BL32_SIZE) |
| 239 | #pragma message(VAR_NAME_VALUE(SPMD_SPM_AT_SEL2_KKO)) |
| 240 | #endif /* NPCM_PRINT_ONCE */ |
| 241 | |
| 242 | #define MAX_IO_DEVICES 4 |
| 243 | #define MAX_IO_HANDLES 4 |
| 244 | |
| 245 | #define PLAT_ARM_FIP_BASE 0x0 |
| 246 | #define PLAT_ARM_FIP_MAX_SIZE PLAT_ARM_MAX_BL31_SIZE |
| 247 | |
| 248 | #define PLAT_ARM_BOOT_UART_BASE 0xF0000000 |
| 249 | #define PLAT_ARM_BOOT_UART_CLK_IN_HZ 115200 |
| 250 | #define PLAT_ARM_RUN_UART_BASE 0xF0000000 |
| 251 | #define PLAT_ARM_RUN_UART_CLK_IN_HZ 115200 |
| 252 | #define PLAT_ARM_CRASH_UART_BASE 0xF0000000 |
| 253 | #define PLAT_ARM_CRASH_UART_CLK_IN_HZ 115200 |
| 254 | |
| 255 | /* |
| 256 | * Mailbox to control the secondary cores.All secondary cores are held in a wait |
| 257 | * loop in cold boot. To release them perform the following steps (plus any |
| 258 | * additional barriers that may be needed): |
| 259 | * |
| 260 | * uint64_t *entrypoint = (uint64_t *)PLAT_NPCM_TM_ENTRYPOINT; |
| 261 | * *entrypoint = ADDRESS_TO_JUMP_TO; |
| 262 | * |
| 263 | * uint64_t *mbox_entry = (uint64_t *)PLAT_NPCM_TM_HOLD_BASE; |
| 264 | * mbox_entry[cpu_id] = PLAT_NPCM_TM_HOLD_BASE; |
| 265 | * |
| 266 | * sev(); |
| 267 | */ |
| 268 | #define PLAT_NPCM_TRUSTED_MAILBOX_BASE ARM_SHARED_RAM_BASE |
| 269 | |
| 270 | /* The secure entry point to be used on warm reset by all CPUs. */ |
| 271 | #define PLAT_NPCM_TM_ENTRYPOINT PLAT_NPCM_TRUSTED_MAILBOX_BASE |
| 272 | #define PLAT_NPCM_TM_ENTRYPOINT_SIZE ULL(8) |
| 273 | |
| 274 | /* Hold entries for each CPU. */ |
| 275 | #define PLAT_NPCM_TM_HOLD_BASE \ |
| 276 | (PLAT_NPCM_TM_ENTRYPOINT + PLAT_NPCM_TM_ENTRYPOINT_SIZE) |
| 277 | #define PLAT_NPCM_TM_HOLD_ENTRY_SIZE ULL(8) |
| 278 | #define PLAT_NPCM_TM_HOLD_SIZE \ |
| 279 | (PLAT_NPCM_TM_HOLD_ENTRY_SIZE * PLATFORM_CORE_COUNT) |
| 280 | #define PLAT_NPCM_TRUSTED_NOTIFICATION_BASE \ |
| 281 | (PLAT_NPCM_TM_ENTRYPOINT_SIZE + PLAT_NPCM_TM_HOLD_SIZE) |
| 282 | |
| 283 | #define PLAT_NPCM_TRUSTED_NOTIFICATION_ENTRY_SIZE ULL(8) |
| 284 | |
| 285 | #define PLAT_NPCM_TRUSTED_NOTIFICATION_SIZE \ |
| 286 | (PLAT_NPCM_TRUSTED_NOTIFICATION_ENTRY_SIZE * PLATFORM_CORE_COUNT) |
| 287 | |
| 288 | #define PLAT_NPCM_TRUSTED_MAILBOX_SIZE \ |
| 289 | (PLAT_NPCM_TM_ENTRYPOINT_SIZE + PLAT_NPCM_TM_HOLD_SIZE + \ |
| 290 | PLAT_NPCM_TRUSTED_NOTIFICATION_ENTRY_SIZE) |
| 291 | |
| 292 | #define PLAT_NPCM_TM_HOLD_STATE_WAIT ULL(0) |
| 293 | #define PLAT_NPCM_TM_HOLD_STATE_GO ULL(1) |
| 294 | #define PLAT_NPCM_TM_HOLD_STATE_BSP_OFF ULL(2) |
| 295 | |
| 296 | #define PLAT_NPCM_TM_NOTIFICATION_START ULL(0xAA) |
| 297 | #define PLAT_NPCM_TM_NOTIFICATION_BR ULL(0xCC) |
| 298 | |
| 299 | #ifdef NPCM845X_DEBUG |
| 300 | #define PLAT_ARM_TRUSTED_MAILBOX_BASE 0xfffB0000 |
| 301 | #endif /* NPCM845X_DEBUG */ |
| 302 | |
| 303 | #endif /* PLATFORM_DEF_H */ |