1 /*
2  * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef PLATFORM_DEF_H
8 #define PLATFORM_DEF_H
9 
10 #include <common/tbbr/tbbr_img_def.h>
11 #include <lib/utils_def.h>
12 #include <lib/xlat_tables/xlat_tables_defs.h>
13 #include <plat/arm/board/common/v2m_def.h>
14 #include <plat/arm/common/smccc_def.h>
15 #include <plat/common/common_def.h>
16 
17 /* Memory location options for TSP */
18 #define ARM_DRAM_ID			2
19 
20 #define ARM_DRAM1_BASE			UL(0x80000000)
21 #define ARM_DRAM1_SIZE			UL(0x80000000)
22 #define ARM_DRAM1_END			(ARM_DRAM1_BASE +		\
23 					 ARM_DRAM1_SIZE - 1)
24 
25 #define SRAM_BASE	0x2000000
26 #define SRAM_SIZE	0x200000
27 
28 /* The first 4KB of NS DRAM1 are used as shared memory */
29 #define A5DS_SHARED_RAM_BASE		SRAM_BASE
30 #define A5DS_SHARED_RAM_SIZE		UL(0x00001000)	/* 4 KB */
31 
32 /* The next 252 kB of NS DRAM is used to load the BL images */
33 #define ARM_BL_RAM_BASE	(A5DS_SHARED_RAM_BASE +	\
34 					 A5DS_SHARED_RAM_SIZE)
35 #define ARM_BL_RAM_SIZE	(PLAT_ARM_BL_PLUS_SHARED_RAM_SIZE -	\
36 					 A5DS_SHARED_RAM_SIZE)
37 
38 #define PERIPHBASE 0x1a000000
39 #define PERIPH_SIZE  0x00240000
40 #define A5_PERIPHERALS_BASE 0x1c000000
41 #define A5_PERIPHERALS_SIZE  0x10000
42 
43 #define ARM_CACHE_WRITEBACK_SHIFT	5
44 
45 #define ARM_IRQ_SEC_PHY_TIMER		29
46 
47 #define ARM_IRQ_SEC_SGI_0		8
48 #define ARM_IRQ_SEC_SGI_1		9
49 #define ARM_IRQ_SEC_SGI_2		10
50 #define ARM_IRQ_SEC_SGI_3		11
51 #define ARM_IRQ_SEC_SGI_4		12
52 #define ARM_IRQ_SEC_SGI_5		13
53 #define ARM_IRQ_SEC_SGI_6		14
54 #define ARM_IRQ_SEC_SGI_7		15
55 
56 /*
57  * Define a list of Group 1 Secure and Group 0 interrupt properties as per GICv3
58  * terminology. On a GICv2 system or mode, the lists will be merged and treated
59  * as Group 0 interrupts.
60  */
61 #define ARM_G1S_IRQ_PROPS(grp) \
62 	INTR_PROP_DESC(ARM_IRQ_SEC_PHY_TIMER, GIC_HIGHEST_SEC_PRIORITY, (grp), \
63 			GIC_INTR_CFG_LEVEL), \
64 	INTR_PROP_DESC(ARM_IRQ_SEC_SGI_1, GIC_HIGHEST_SEC_PRIORITY, (grp), \
65 			GIC_INTR_CFG_EDGE), \
66 	INTR_PROP_DESC(ARM_IRQ_SEC_SGI_2, GIC_HIGHEST_SEC_PRIORITY, (grp), \
67 			GIC_INTR_CFG_EDGE), \
68 	INTR_PROP_DESC(ARM_IRQ_SEC_SGI_3, GIC_HIGHEST_SEC_PRIORITY, (grp), \
69 			GIC_INTR_CFG_EDGE), \
70 	INTR_PROP_DESC(ARM_IRQ_SEC_SGI_4, GIC_HIGHEST_SEC_PRIORITY, (grp), \
71 			GIC_INTR_CFG_EDGE), \
72 	INTR_PROP_DESC(ARM_IRQ_SEC_SGI_5, GIC_HIGHEST_SEC_PRIORITY, (grp), \
73 			GIC_INTR_CFG_EDGE), \
74 	INTR_PROP_DESC(ARM_IRQ_SEC_SGI_7, GIC_HIGHEST_SEC_PRIORITY, (grp), \
75 			GIC_INTR_CFG_EDGE)
76 
77 #define ARM_G0_IRQ_PROPS(grp) \
78 	INTR_PROP_DESC(ARM_IRQ_SEC_SGI_6, GIC_HIGHEST_SEC_PRIORITY, (grp), \
79 			GIC_INTR_CFG_EDGE)
80 
81 #define A5DS_IRQ_TZ_WDOG			56
82 #define A5DS_IRQ_SEC_SYS_TIMER		57
83 
84 /* Default cluster count for A5DS */
85 #define A5DS_CLUSTER_COUNT	U(1)
86 
87 /* Default number of CPUs per cluster on A5DS */
88 #define A5DS_MAX_CPUS_PER_CLUSTER	U(4)
89 
90 /* Default number of threads per CPU on A5DS */
91 #define A5DS_MAX_PE_PER_CPU	U(1)
92 
93 #define A5DS_CORE_COUNT		U(4)
94 
95 #define A5DS_PRIMARY_CPU	0x0
96 
97 #define BOOT_BASE			ARM_DRAM1_BASE
98 #define BOOT_SIZE			UL(0x2800000)
99 
100 #define ARM_NS_DRAM1_BASE		(ARM_DRAM1_BASE + BOOT_SIZE)
101 /*
102  * The last 2MB is meant to be NOLOAD and will not be zero
103  * initialized.
104  */
105 #define ARM_NS_DRAM1_SIZE		(ARM_DRAM1_SIZE -		\
106 					 BOOT_SIZE -			\
107 					 0x00200000)
108 
109 #define MAP_BOOT_RW          		MAP_REGION_FLAT(		\
110 						BOOT_BASE,		\
111 						BOOT_SIZE,    		\
112 						MT_DEVICE | MT_RW | MT_SECURE)
113 
114 #define ARM_MAP_SHARED_RAM		MAP_REGION_FLAT(		\
115 						A5DS_SHARED_RAM_BASE,	\
116 						A5DS_SHARED_RAM_SIZE,	\
117 						MT_MEMORY | MT_RW | MT_SECURE)
118 
119 #define ARM_MAP_NS_DRAM1		MAP_REGION_FLAT(		\
120 						ARM_NS_DRAM1_BASE,	\
121 						ARM_NS_DRAM1_SIZE,	\
122 						MT_MEMORY | MT_RW | MT_NS)
123 
124 #define ARM_MAP_SRAM			MAP_REGION_FLAT(		\
125 						SRAM_BASE,		\
126 						SRAM_SIZE,		\
127 						MT_MEMORY | MT_RW | MT_NS)
128 
129 /*
130  * Mapping for the BL1 RW region. This mapping is needed by BL2 in order to
131  * share the Mbed TLS heap. Since the heap is allocated inside BL1, it resides
132  * in the BL1 RW region. Hence, BL2 needs access to the BL1 RW region in order
133  * to be able to access the heap.
134  */
135 
136 #define ARM_MAP_BL_RO	MAP_REGION_FLAT(\
137 						BL_CODE_BASE,\
138 						BL_CODE_END - BL_CODE_BASE,\
139 						MT_CODE | MT_SECURE),\
140 					MAP_REGION_FLAT(\
141 						BL_RO_DATA_BASE,\
142 						BL_RO_DATA_END\
143 						- BL_RO_DATA_BASE,	\
144 						MT_RO_DATA | MT_SECURE)
145 
146 #if USE_COHERENT_MEM
147 #define ARM_MAP_BL_COHERENT_RAM		MAP_REGION_FLAT(\
148 						BL_COHERENT_RAM_BASE,\
149 						BL_COHERENT_RAM_END	\
150 						- BL_COHERENT_RAM_BASE, \
151 						MT_DEVICE | MT_RW | MT_SECURE)
152 #endif
153 
154 /*
155  * Map the region for device tree configuration with read and write permissions
156  */
157 #define ARM_MAP_BL_CONFIG_REGION	MAP_REGION_FLAT(ARM_BL_RAM_BASE,	\
158 						(ARM_FW_CONFIGS_LIMIT		\
159 							- ARM_BL_RAM_BASE),	\
160 						MT_MEMORY | MT_RW | MT_SECURE)
161 
162 /*
163  * The max number of regions like RO(code), coherent and data required by
164  * different BL stages which need to be mapped in the MMU.
165  */
166 #define ARM_BL_REGIONS			6
167 
168 #define MAX_MMAP_REGIONS		(PLAT_ARM_MMAP_ENTRIES +	\
169 					 ARM_BL_REGIONS)
170 
171 /* Memory mapped Generic timer interfaces  */
172 #define A5DS_TIMER_BASE_FREQUENCY		UL(7500000)
173 
174 #define ARM_CONSOLE_BAUDRATE		115200
175 
176 #define PLAT_PHY_ADDR_SPACE_SIZE			(1ULL << 32)
177 #define PLAT_VIRT_ADDR_SPACE_SIZE			(1ULL << 32)
178 
179 /*
180  * This macro defines the deepest retention state possible. A higher state
181  * id will represent an invalid or a power down state.
182  */
183 #define PLAT_MAX_RET_STATE		1
184 
185 /*
186  * This macro defines the deepest power down states possible. Any state ID
187  * higher than this is invalid.
188  */
189 #define PLAT_MAX_OFF_STATE		2
190 
191 /*
192  * Some data must be aligned on the biggest cache line size in the platform.
193  * This is known only to the platform as it might have a combination of
194  * integrated and external caches.
195  */
196 #define CACHE_WRITEBACK_GRANULE		(U(1) << ARM_CACHE_WRITEBACK_SHIFT)
197 
198 /*
199  * To enable FW_CONFIG to be loaded by BL1, define the corresponding base
200  * and limit. Leave enough space of BL2 meminfo.
201  */
202 #define ARM_FW_CONFIG_BASE		(ARM_BL_RAM_BASE + sizeof(meminfo_t))
203 #define ARM_FW_CONFIG_LIMIT		(ARM_BL_RAM_BASE + PAGE_SIZE)
204 
205 /*
206  * Define limit of firmware configuration memory:
207  * ARM_FW_CONFIG + ARM_BL2_MEM_DESC memory
208  */
209 #define ARM_FW_CONFIGS_LIMIT		(ARM_BL_RAM_BASE + (PAGE_SIZE * 2))
210 
211 /*******************************************************************************
212  * BL1 specific defines.
213  * BL1 RW data is relocated from ROM to RAM at runtime so we need 2 sets of
214  * addresses.
215  ******************************************************************************/
216 #define BL1_RO_BASE			0x00000000
217 #define BL1_RO_LIMIT			PLAT_ARM_TRUSTED_ROM_SIZE
218 /*
219  * Put BL1 RW at the top of the memory allocated for BL images in NS DRAM.
220  */
221 #define BL1_RW_BASE	(ARM_BL_RAM_BASE + \
222 						ARM_BL_RAM_SIZE - \
223 						(PLAT_ARM_MAX_BL1_RW_SIZE))
224 #define BL1_RW_LIMIT (ARM_BL_RAM_BASE + \
225 					    (ARM_BL_RAM_SIZE))
226 /*******************************************************************************
227  * BL2 specific defines.
228  ******************************************************************************/
229 
230 /*
231  * Put BL2 just below BL1.
232  */
233 #define BL2_BASE			(BL1_RW_BASE - A5DS_MAX_BL2_SIZE)
234 #define BL2_LIMIT			BL1_RW_BASE
235 
236 /* Put BL32 below BL2 in NS DRAM.*/
237 #define ARM_BL2_MEM_DESC_BASE		ARM_FW_CONFIG_LIMIT
238 #define ARM_BL2_MEM_DESC_LIMIT		(ARM_BL2_MEM_DESC_BASE \
239 					+ (PAGE_SIZE / 2U))
240 
241 #define BL32_BASE			((ARM_BL_RAM_BASE + ARM_BL_RAM_SIZE)\
242 						- PLAT_ARM_MAX_BL32_SIZE)
243 #define BL32_PROGBITS_LIMIT		BL2_BASE
244 #define BL32_LIMIT			(ARM_BL_RAM_BASE + ARM_BL_RAM_SIZE)
245 
246 /* Required platform porting definitions */
247 #define PLATFORM_CORE_COUNT	A5DS_CORE_COUNT
248 #define PLAT_NUM_PWR_DOMAINS	(A5DS_CLUSTER_COUNT + \
249 				PLATFORM_CORE_COUNT) + U(1)
250 
251 #define PLAT_MAX_PWR_LVL	2
252 
253 /*
254  * Other platform porting definitions are provided by included headers
255  */
256 
257 /*
258  * Required ARM standard platform porting definitions
259  */
260 
261 #define PLAT_ARM_BL_PLUS_SHARED_RAM_SIZE	0x00040000	/* 256 KB */
262 
263 #define PLAT_ARM_TRUSTED_ROM_BASE	0x00000000
264 #define PLAT_ARM_TRUSTED_ROM_SIZE	0x10000	/* 64KB */
265 
266 #define PLAT_ARM_DRAM2_SIZE		ULL(0x80000000)
267 
268 /*
269  * Load address of BL33 for this platform port
270  */
271 #define PLAT_ARM_NS_IMAGE_BASE	(ARM_DRAM1_BASE + U(0x8000000))
272 
273 /*
274  * PLAT_ARM_MMAP_ENTRIES depends on the number of entries in the
275  * plat_arm_mmap array defined for each BL stage.
276  */
277 #if defined(IMAGE_BL32)
278 # define PLAT_ARM_MMAP_ENTRIES		8
279 # define MAX_XLAT_TABLES		6
280 #else
281 # define PLAT_ARM_MMAP_ENTRIES		12
282 # define MAX_XLAT_TABLES		6
283 #endif
284 
285 /*
286  * PLAT_ARM_MAX_BL1_RW_SIZE is calculated using the current BL1 RW debug size
287  * plus a little space for growth.
288  */
289 #define PLAT_ARM_MAX_BL1_RW_SIZE	0xB000
290 
291 /*
292  * A5DS_MAX_BL2_SIZE is calculated using the current BL2 debug size plus a
293  * little space for growth.
294  */
295 #define A5DS_MAX_BL2_SIZE		0x11000
296 
297 /*
298  * Since BL32 NOBITS overlays BL2 and BL1-RW, PLAT_ARM_MAX_BL32_SIZE is
299  * calculated using the current SP_MIN PROGBITS debug size plus the sizes of
300  * BL2 and BL1-RW
301  */
302 #define PLAT_ARM_MAX_BL32_SIZE		0x3B000
303 /*
304  * Size of cacheable stacks
305  */
306 #if defined(IMAGE_BL1)
307 #  define PLATFORM_STACK_SIZE 0x440
308 #elif defined(IMAGE_BL2)
309 #  define PLATFORM_STACK_SIZE 0x400
310 #elif defined(IMAGE_BL32)
311 # define PLATFORM_STACK_SIZE 0x440
312 #endif
313 
314 #define MAX_IO_DEVICES			3
315 #define MAX_IO_HANDLES			4
316 
317 /* Reserve the last block of flash for PSCI MEM PROTECT flag */
318 #define PLAT_ARM_FLASH_IMAGE_BASE	BOOT_BASE
319 #define PLAT_ARM_FLASH_IMAGE_MAX_SIZE	(BOOT_SIZE - V2M_FLASH_BLOCK_SIZE)
320 
321 #define PLAT_ARM_NVM_BASE		BOOT_BASE
322 #define PLAT_ARM_NVM_SIZE		(BOOT_SIZE - V2M_FLASH_BLOCK_SIZE)
323 
324 /*
325  * PL011 related constants
326  */
327 #define PLAT_ARM_BOOT_UART_BASE		0x1A200000
328 #define PLAT_ARM_BOOT_UART_CLK_IN_HZ	UL(7500000)
329 
330 #define PLAT_ARM_RUN_UART_BASE		0x1A210000
331 #define PLAT_ARM_RUN_UART_CLK_IN_HZ	UL(7500000)
332 
333 #define PLAT_ARM_CRASH_UART_BASE	PLAT_ARM_RUN_UART_BASE
334 #define PLAT_ARM_CRASH_UART_CLK_IN_HZ	PLAT_ARM_RUN_UART_CLK_IN_HZ
335 
336 #define A5DS_TIMER_BASE_FREQUENCY	UL(7500000)
337 
338 /* System timer related constants */
339 #define PLAT_ARM_NSTIMER_FRAME_ID		1
340 
341 /* Mailbox base address */
342 #define A5DS_TRUSTED_MAILBOX_BASE	A5DS_SHARED_RAM_BASE
343 #define A5DS_TRUSTED_MAILBOX_SIZE	(8 + A5DS_HOLD_SIZE)
344 #define A5DS_HOLD_BASE		(A5DS_TRUSTED_MAILBOX_BASE + 8)
345 #define A5DS_HOLD_SIZE		(PLATFORM_CORE_COUNT * \
346 					 A5DS_HOLD_ENTRY_SIZE)
347 #define A5DS_HOLD_ENTRY_SHIFT	3
348 #define A5DS_HOLD_ENTRY_SIZE	(1 << A5DS_HOLD_ENTRY_SHIFT)
349 #define A5DS_HOLD_STATE_WAIT	0
350 #define A5DS_HOLD_STATE_GO	1
351 
352 /* Snoop Control Unit base address */
353 #define A5DS_SCU_BASE			0x1C000000
354 
355 /*
356  * GIC related constants to cater for GICv2
357  */
358 #define PLAT_ARM_GICD_BASE		0x1C001000
359 #define PLAT_ARM_GICC_BASE		0x1C000100
360 
361 /*
362  * Define a list of Group 1 Secure and Group 0 interrupts as per GICv3
363  * terminology. On a GICv2 system or mode, the lists will be merged and treated
364  * as Group 0 interrupts.
365  */
366 #define PLAT_ARM_G1S_IRQ_PROPS(grp) \
367 	ARM_G1S_IRQ_PROPS(grp), \
368 	INTR_PROP_DESC(A5DS_IRQ_TZ_WDOG, GIC_HIGHEST_SEC_PRIORITY, (grp), \
369 			GIC_INTR_CFG_LEVEL), \
370 	INTR_PROP_DESC(A5DS_IRQ_SEC_SYS_TIMER,\
371 		 GIC_HIGHEST_SEC_PRIORITY, (grp), \
372 			GIC_INTR_CFG_LEVEL)
373 
374 #define PLAT_ARM_G0_IRQ_PROPS(grp)	ARM_G0_IRQ_PROPS(grp)
375 
376 #endif /* PLATFORM_DEF_H */
377