blob: 84710240da9b6ca2ec523852089ed8f4b75ec4a6 [file] [log] [blame]
Radoslaw Biernacki1201aba2018-05-17 22:52:49 +02001/* SPDX-License-Identifier: BSD-3-Clause
2 *
Masahisa Kojima099064b2020-06-11 21:46:44 +09003 * Copyright (c) 2019-2020, Linaro Limited and Contributors.
4 * All rights reserved.
Radoslaw Biernacki1201aba2018-05-17 22:52:49 +02005 */
6
Masahisa Kojima099064b2020-06-11 21:46:44 +09007#ifndef PLATFORM_DEF_H
8#define PLATFORM_DEF_H
Radoslaw Biernacki1201aba2018-05-17 22:52:49 +02009
10#include <arch.h>
11#include <plat/common/common_def.h>
12#include <tbbr_img_def.h>
13
14/* Special value used to verify platform parameters from BL2 to BL3-1 */
15#define QEMU_BL31_PLAT_PARAM_VAL 0x0f1e2d3c4b5a6978ULL
16
17#define PLATFORM_STACK_SIZE 0x1000
18
Deepika Bhavnani9b27dfb2019-12-13 10:52:14 -060019#define PLATFORM_MAX_CPUS_PER_CLUSTER U(4)
Graeme Gregory0a15c7f2020-12-16 14:13:07 +000020/*
21 * Define the number of cores per cluster used in calculating core position.
22 * The cluster number is shifted by this value and added to the core ID,
23 * so its value represents log2(cores/cluster).
24 * Default is 2**(2) = 4 cores per cluster.
25 */
26#define PLATFORM_CPU_PER_CLUSTER_SHIFT U(2)
Deepika Bhavnani9b27dfb2019-12-13 10:52:14 -060027#define PLATFORM_CLUSTER_COUNT U(2)
Radoslaw Biernacki1201aba2018-05-17 22:52:49 +020028#define PLATFORM_CLUSTER0_CORE_COUNT PLATFORM_MAX_CPUS_PER_CLUSTER
29#define PLATFORM_CLUSTER1_CORE_COUNT PLATFORM_MAX_CPUS_PER_CLUSTER
30#define PLATFORM_CORE_COUNT (PLATFORM_CLUSTER0_CORE_COUNT + \
31 PLATFORM_CLUSTER1_CORE_COUNT)
32
Deepika Bhavnani9b27dfb2019-12-13 10:52:14 -060033#define QEMU_PRIMARY_CPU U(0)
Radoslaw Biernacki1201aba2018-05-17 22:52:49 +020034
35#define PLAT_NUM_PWR_DOMAINS (PLATFORM_CLUSTER_COUNT + \
36 PLATFORM_CORE_COUNT)
37#define PLAT_MAX_PWR_LVL MPIDR_AFFLVL1
38
39#define PLAT_MAX_RET_STATE 1
40#define PLAT_MAX_OFF_STATE 2
41
42/* Local power state for power domains in Run state. */
43#define PLAT_LOCAL_STATE_RUN 0
44/* Local power state for retention. Valid only for CPU power domains */
45#define PLAT_LOCAL_STATE_RET 1
46/*
47 * Local power state for OFF/power-down. Valid for CPU and cluster power
48 * domains.
49 */
50#define PLAT_LOCAL_STATE_OFF 2
51
52/*
53 * Macros used to parse state information from State-ID if it is using the
54 * recommended encoding for State-ID.
55 */
56#define PLAT_LOCAL_PSTATE_WIDTH 4
57#define PLAT_LOCAL_PSTATE_MASK ((1 << PLAT_LOCAL_PSTATE_WIDTH) - 1)
58
59/*
60 * Some data must be aligned on the biggest cache line size in the platform.
61 * This is known only to the platform as it might have a combination of
62 * integrated and external caches.
63 */
64#define CACHE_WRITEBACK_SHIFT 6
65#define CACHE_WRITEBACK_GRANULE (1 << CACHE_WRITEBACK_SHIFT)
66
67/*
68 * Partition memory into secure ROM, non-secure DRAM, secure "SRAM",
69 * and secure DRAM.
70 */
71#define SEC_ROM_BASE 0x00000000
72#define SEC_ROM_SIZE 0x00020000
73
74#define NS_DRAM0_BASE 0x10000000000ULL
75#define NS_DRAM0_SIZE 0x00020000000
76
77#define SEC_SRAM_BASE 0x20000000
78#define SEC_SRAM_SIZE 0x20000000
79
80/*
81 * RAD just placeholders, need to be chosen after finalizing mem map
82 */
83#define SEC_DRAM_BASE 0x1000
84#define SEC_DRAM_SIZE 0x1000
85
86/* Load pageable part of OP-TEE 2MB above secure DRAM base */
87#define QEMU_OPTEE_PAGEABLE_LOAD_BASE (SEC_DRAM_BASE + 0x00200000)
88#define QEMU_OPTEE_PAGEABLE_LOAD_SIZE 0x00400000
89
90/*
91 * ARM-TF lives in SRAM, partition it here
92 */
93
94#define SHARED_RAM_BASE SEC_SRAM_BASE
Masato Fukumori0a4fac82020-12-01 22:17:27 +090095#define SHARED_RAM_SIZE 0x00002000
Radoslaw Biernacki1201aba2018-05-17 22:52:49 +020096
97#define PLAT_QEMU_TRUSTED_MAILBOX_BASE SHARED_RAM_BASE
98#define PLAT_QEMU_TRUSTED_MAILBOX_SIZE (8 + PLAT_QEMU_HOLD_SIZE)
99#define PLAT_QEMU_HOLD_BASE (PLAT_QEMU_TRUSTED_MAILBOX_BASE + 8)
100#define PLAT_QEMU_HOLD_SIZE (PLATFORM_CORE_COUNT * \
101 PLAT_QEMU_HOLD_ENTRY_SIZE)
102#define PLAT_QEMU_HOLD_ENTRY_SHIFT 3
103#define PLAT_QEMU_HOLD_ENTRY_SIZE (1 << PLAT_QEMU_HOLD_ENTRY_SHIFT)
104#define PLAT_QEMU_HOLD_STATE_WAIT 0
105#define PLAT_QEMU_HOLD_STATE_GO 1
106
107#define BL_RAM_BASE (SHARED_RAM_BASE + SHARED_RAM_SIZE)
108#define BL_RAM_SIZE (SEC_SRAM_SIZE - SHARED_RAM_SIZE)
109
110/*
111 * BL1 specific defines.
112 *
113 * BL1 RW data is relocated from ROM to RAM at runtime so we need 2 sets of
114 * addresses.
115 * Put BL1 RW at the top of the Secure SRAM. BL1_RW_BASE is calculated using
116 * the current BL1 RW debug size plus a little space for growth.
117 */
Masahisa Kojima099064b2020-06-11 21:46:44 +0900118#define BL1_SIZE 0x12000
Radoslaw Biernacki1201aba2018-05-17 22:52:49 +0200119#define BL1_RO_BASE SEC_ROM_BASE
120#define BL1_RO_LIMIT (SEC_ROM_BASE + SEC_ROM_SIZE)
Masahisa Kojima099064b2020-06-11 21:46:44 +0900121#define BL1_RW_BASE (BL1_RW_LIMIT - BL1_SIZE)
Radoslaw Biernacki1201aba2018-05-17 22:52:49 +0200122#define BL1_RW_LIMIT (BL_RAM_BASE + BL_RAM_SIZE)
123
124/*
125 * BL2 specific defines.
126 *
127 * Put BL2 just below BL3-1. BL2_BASE is calculated using the current BL2 debug
128 * size plus a little space for growth.
129 */
Masahisa Kojima099064b2020-06-11 21:46:44 +0900130#define BL2_SIZE 0x1D000
131#define BL2_BASE (BL31_BASE - BL2_SIZE)
Radoslaw Biernacki1201aba2018-05-17 22:52:49 +0200132#define BL2_LIMIT BL31_BASE
133
134/*
135 * BL3-1 specific defines.
136 *
137 * Put BL3-1 at the top of the Trusted SRAM. BL31_BASE is calculated using the
138 * current BL3-1 debug size plus a little space for growth.
139 */
Masahisa Kojima099064b2020-06-11 21:46:44 +0900140#define BL31_SIZE 0x50000
141#define BL31_BASE (BL31_LIMIT - BL31_SIZE)
142#define BL31_LIMIT (BL1_RW_BASE)
Radoslaw Biernacki1201aba2018-05-17 22:52:49 +0200143#define BL31_PROGBITS_LIMIT BL1_RW_BASE
144
145
146/*
147 * BL3-2 specific defines.
148 *
149 * BL3-2 can execute from Secure SRAM, or Secure DRAM.
150 */
151#define BL32_SRAM_BASE BL_RAM_BASE
Masahisa Kojima099064b2020-06-11 21:46:44 +0900152#define BL32_SRAM_LIMIT BL2_BASE
Radoslaw Biernacki1201aba2018-05-17 22:52:49 +0200153
154#define BL32_MEM_BASE BL_RAM_BASE
Masahisa Kojima099064b2020-06-11 21:46:44 +0900155#define BL32_MEM_SIZE (BL_RAM_SIZE - BL1_SIZE - \
156 BL2_SIZE - BL31_SIZE)
Radoslaw Biernacki1201aba2018-05-17 22:52:49 +0200157#define BL32_BASE BL32_SRAM_BASE
158#define BL32_LIMIT BL32_SRAM_LIMIT
159
160#define NS_IMAGE_OFFSET (NS_DRAM0_BASE + 0x20000000)
161#define NS_IMAGE_MAX_SIZE (NS_DRAM0_SIZE - 0x20000000)
162
163#define PLAT_PHY_ADDR_SPACE_SIZE (1ull << 42)
164#define PLAT_VIRT_ADDR_SPACE_SIZE (1ull << 42)
Masahisa Kojima099064b2020-06-11 21:46:44 +0900165#if SPM_MM
166#define MAX_MMAP_REGIONS 12
167#define MAX_XLAT_TABLES 11
168#else
Radoslaw Biernacki1201aba2018-05-17 22:52:49 +0200169#define MAX_MMAP_REGIONS 11
170#define MAX_XLAT_TABLES 10
Masahisa Kojima099064b2020-06-11 21:46:44 +0900171#endif
Radoslaw Biernacki1201aba2018-05-17 22:52:49 +0200172#define MAX_IO_DEVICES 3
173#define MAX_IO_HANDLES 4
174
Masahisa Kojima099064b2020-06-11 21:46:44 +0900175#if SPM_MM && defined(IMAGE_BL31)
176# define PLAT_SP_IMAGE_MMAP_REGIONS 30
177# define PLAT_SP_IMAGE_MAX_XLAT_TABLES 20
178#endif
179
Radoslaw Biernacki1201aba2018-05-17 22:52:49 +0200180/*
181 * PL011 related constants
182 */
183#define UART0_BASE 0x60000000
184#define UART1_BASE 0x60030000
185#define UART0_CLK_IN_HZ 1
186#define UART1_CLK_IN_HZ 1
187
Masahisa Kojima099064b2020-06-11 21:46:44 +0900188/* Secure UART */
189#define UART2_BASE 0x60040000
190#define UART2_CLK_IN_HZ 1
191
Radoslaw Biernacki1201aba2018-05-17 22:52:49 +0200192#define PLAT_QEMU_BOOT_UART_BASE UART0_BASE
193#define PLAT_QEMU_BOOT_UART_CLK_IN_HZ UART0_CLK_IN_HZ
194
195#define PLAT_QEMU_CRASH_UART_BASE UART1_BASE
196#define PLAT_QEMU_CRASH_UART_CLK_IN_HZ UART1_CLK_IN_HZ
197
198#define PLAT_QEMU_CONSOLE_BAUDRATE 115200
199
200#define QEMU_FLASH0_BASE 0x00000000
201#define QEMU_FLASH0_SIZE 0x10000000
202#define QEMU_FLASH1_BASE 0x10000000
203#define QEMU_FLASH1_SIZE 0x10000000
204
Radoslaw Biernacki7ed5e122018-06-07 20:14:36 +0200205#define PLAT_QEMU_FIP_BASE 0x00008000
Masahisa Kojima099064b2020-06-11 21:46:44 +0900206#define PLAT_QEMU_FIP_MAX_SIZE 0x00400000
Radoslaw Biernacki1201aba2018-05-17 22:52:49 +0200207
208/* This is map from GIC_DIST up to last CPU (255) GIC_REDISTR */
209#define DEVICE0_BASE 0x40000000
210#define DEVICE0_SIZE 0x04080000
211/* This is map from NORMAL_UART up to SECURE_UART_MM */
212#define DEVICE1_BASE 0x60000000
213#define DEVICE1_SIZE 0x00041000
214
215/*
216 * GIC related constants
217 * We use GICv3 where CPU Interface registers are not memory mapped
218 */
219#define GICD_BASE 0x40060000
220#define GICR_BASE 0x40080000
221#define GICC_BASE 0x0
222
223#define QEMU_IRQ_SEC_SGI_0 8
224#define QEMU_IRQ_SEC_SGI_1 9
225#define QEMU_IRQ_SEC_SGI_2 10
226#define QEMU_IRQ_SEC_SGI_3 11
227#define QEMU_IRQ_SEC_SGI_4 12
228#define QEMU_IRQ_SEC_SGI_5 13
229#define QEMU_IRQ_SEC_SGI_6 14
230#define QEMU_IRQ_SEC_SGI_7 15
231
232/******************************************************************************
233 * On a GICv2 system, the Group 1 secure interrupts are treated as Group 0
234 * interrupts.
235 *****************************************************************************/
236#define PLATFORM_G1S_PROPS(grp) \
237 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_0, GIC_HIGHEST_SEC_PRIORITY, \
238 grp, GIC_INTR_CFG_EDGE), \
239 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_1, GIC_HIGHEST_SEC_PRIORITY, \
240 grp, GIC_INTR_CFG_EDGE), \
241 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_2, GIC_HIGHEST_SEC_PRIORITY, \
242 grp, GIC_INTR_CFG_EDGE), \
243 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_3, GIC_HIGHEST_SEC_PRIORITY, \
244 grp, GIC_INTR_CFG_EDGE), \
245 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_4, GIC_HIGHEST_SEC_PRIORITY, \
246 grp, GIC_INTR_CFG_EDGE), \
247 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_5, GIC_HIGHEST_SEC_PRIORITY, \
248 grp, GIC_INTR_CFG_EDGE), \
249 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_6, GIC_HIGHEST_SEC_PRIORITY, \
250 grp, GIC_INTR_CFG_EDGE), \
251 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_7, GIC_HIGHEST_SEC_PRIORITY, \
252 grp, GIC_INTR_CFG_EDGE)
253
254#define PLATFORM_G0_PROPS(grp)
255
256/*
257 * DT related constants
258 */
259#define PLAT_QEMU_DT_BASE NS_DRAM0_BASE
Masahisa Kojimacbeb7e52020-05-19 19:49:36 +0900260#define PLAT_QEMU_DT_MAX_SIZE 0x100000
Radoslaw Biernacki1201aba2018-05-17 22:52:49 +0200261
262/*
263 * System counter
264 */
265#define SYS_COUNTER_FREQ_IN_TICKS ((1000 * 1000 * 1000) / 16)
266
Masahisa Kojima099064b2020-06-11 21:46:44 +0900267#if SPM_MM
268#define PLAT_QEMU_SP_IMAGE_BASE BL_RAM_BASE
269#define PLAT_QEMU_SP_IMAGE_SIZE ULL(0x300000)
270
271#ifdef IMAGE_BL2
272/* In BL2 all memory allocated to the SPM Payload image is marked as RW. */
273# define QEMU_SP_IMAGE_MMAP MAP_REGION_FLAT( \
274 PLAT_QEMU_SP_IMAGE_BASE, \
275 PLAT_QEMU_SP_IMAGE_SIZE, \
276 MT_MEMORY | MT_RW | \
277 MT_SECURE)
278#elif IMAGE_BL31
279/* All SPM Payload memory is marked as code in S-EL0 */
280# define QEMU_SP_IMAGE_MMAP MAP_REGION2(PLAT_QEMU_SP_IMAGE_BASE, \
281 PLAT_QEMU_SP_IMAGE_BASE, \
282 PLAT_QEMU_SP_IMAGE_SIZE, \
283 MT_CODE | MT_SECURE | \
284 MT_USER, \
285 PAGE_SIZE)
286#endif
287
288/*
289 * EL3 -> S-EL0 secure shared memory
290 */
291#define PLAT_SPM_BUF_PCPU_SIZE ULL(0x10000)
292#define PLAT_SPM_BUF_SIZE (PLATFORM_CORE_COUNT * \
293 PLAT_SPM_BUF_PCPU_SIZE)
294#define PLAT_SPM_BUF_BASE (BL32_LIMIT - PLAT_SPM_BUF_SIZE)
295
296#define QEMU_SPM_BUF_EL3_MMAP MAP_REGION_FLAT(PLAT_SPM_BUF_BASE, \
297 PLAT_SPM_BUF_SIZE, \
298 MT_RW_DATA | MT_SECURE)
299
300#define QEMU_SPM_BUF_EL0_MMAP MAP_REGION2(PLAT_SPM_BUF_BASE, \
301 PLAT_SPM_BUF_BASE, \
302 PLAT_SPM_BUF_SIZE, \
303 MT_RO_DATA | MT_SECURE | \
304 MT_USER, \
305 PAGE_SIZE)
306
307/*
308 * Shared memory between Normal world and S-EL0 for
309 * passing data during service requests. It will be marked as RW and NS.
Masahisa Kojima7e917dc2020-09-23 16:52:59 +0900310 * This buffer is allocated at the top of NS_DRAM, the base address is
311 * overridden in SPM initialization.
Masahisa Kojima099064b2020-06-11 21:46:44 +0900312 */
313#define PLAT_QEMU_SP_IMAGE_NS_BUF_BASE (PLAT_QEMU_DT_BASE + \
314 PLAT_QEMU_DT_MAX_SIZE)
Masahisa Kojima7e917dc2020-09-23 16:52:59 +0900315#define PLAT_QEMU_SP_IMAGE_NS_BUF_SIZE ULL(0x200000)
316
Masahisa Kojima099064b2020-06-11 21:46:44 +0900317#define QEMU_SP_IMAGE_NS_BUF_MMAP MAP_REGION2( \
318 PLAT_QEMU_SP_IMAGE_NS_BUF_BASE, \
319 PLAT_QEMU_SP_IMAGE_NS_BUF_BASE, \
320 PLAT_QEMU_SP_IMAGE_NS_BUF_SIZE, \
321 MT_RW_DATA | MT_NS | \
322 MT_USER, \
323 PAGE_SIZE)
324
325#define PLAT_SP_IMAGE_NS_BUF_BASE PLAT_QEMU_SP_IMAGE_NS_BUF_BASE
326#define PLAT_SP_IMAGE_NS_BUF_SIZE PLAT_QEMU_SP_IMAGE_NS_BUF_SIZE
327
328#define PLAT_QEMU_SP_IMAGE_HEAP_BASE (PLAT_QEMU_SP_IMAGE_BASE + \
329 PLAT_QEMU_SP_IMAGE_SIZE)
330#define PLAT_QEMU_SP_IMAGE_HEAP_SIZE ULL(0x800000)
331
332#define PLAT_SP_IMAGE_STACK_BASE (PLAT_QEMU_SP_IMAGE_HEAP_BASE + \
333 PLAT_QEMU_SP_IMAGE_HEAP_SIZE)
334#define PLAT_SP_IMAGE_STACK_PCPU_SIZE ULL(0x10000)
335#define QEMU_SP_IMAGE_STACK_TOTAL_SIZE (PLATFORM_CORE_COUNT * \
336 PLAT_SP_IMAGE_STACK_PCPU_SIZE)
337
338#define QEMU_SP_IMAGE_RW_MMAP MAP_REGION2( \
339 PLAT_QEMU_SP_IMAGE_HEAP_BASE, \
340 PLAT_QEMU_SP_IMAGE_HEAP_BASE, \
341 (QEMU_SP_IMAGE_STACK_TOTAL_SIZE + \
342 PLAT_QEMU_SP_IMAGE_HEAP_SIZE), \
343 MT_RW_DATA | MT_SECURE | \
344 MT_USER, \
345 PAGE_SIZE)
346
Masahisa Kojima7e917dc2020-09-23 16:52:59 +0900347/*
348 * Secure variable storage is located at Secure Flash.
349 */
350#if SPM_MM
351#define QEMU_SECURE_VARSTORE_BASE 0x01000000
352#define QEMU_SECURE_VARSTORE_SIZE 0x00100000
353#define MAP_SECURE_VARSTORE MAP_REGION_FLAT( \
354 QEMU_SECURE_VARSTORE_BASE, \
355 QEMU_SECURE_VARSTORE_SIZE, \
356 MT_MEMORY | MT_RW | \
357 MT_SECURE | MT_USER)
358#endif
359
Masahisa Kojima099064b2020-06-11 21:46:44 +0900360/* Total number of memory regions with distinct properties */
361#define PLAT_QEMU_SP_IMAGE_NUM_MEM_REGIONS 6
362
363/*
364 * Name of the section to put the translation tables used by the S-EL1/S-EL0
365 * context of a Secure Partition.
366 */
367#define PLAT_SP_IMAGE_XLAT_SECTION_NAME "qemu_sp_xlat_table"
368#define PLAT_SP_IMAGE_BASE_XLAT_SECTION_NAME "qemu_sp_xlat_table"
369
370/* Cookies passed to the Secure Partition at boot. Not used by QEMU platforms.*/
371#define PLAT_SPM_COOKIE_0 ULL(0)
372#define PLAT_SPM_COOKIE_1 ULL(0)
373#endif
374
375#define QEMU_PRI_BITS 2
376#define PLAT_SP_PRI 0x20
377
378#endif /* PLATFORM_DEF_H */