xref: /rk3399_ARM-atf/plat/hisilicon/poplar/aarch64/platform_common.c (revision 1dcc28cfbac5dae3992ad9581f9ea68f6cb339c1)
1 /*
2  * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <arch_helpers.h>
8 #include <assert.h>
9 #include <bl_common.h>
10 #include <debug.h>
11 #include <delay_timer.h>
12 #include <errno.h>
13 #include <mmio.h>
14 #include <platform.h>
15 #include <xlat_tables.h>
16 #include "hi3798cv200.h"
17 #include "platform_def.h"
18 
19 #define MAP_DDR		MAP_REGION_FLAT(DDR_BASE,			\
20 					DDR_SIZE,			\
21 					MT_MEMORY | MT_RW | MT_NS)
22 
23 #define MAP_DEVICE	MAP_REGION_FLAT(DEVICE_BASE,			\
24 					DEVICE_SIZE,			\
25 					MT_DEVICE | MT_RW | MT_SECURE)
26 
27 #define MAP_TSP_MEM	MAP_REGION_FLAT(TSP_SEC_MEM_BASE,		\
28 					TSP_SEC_MEM_SIZE,		\
29 					MT_MEMORY | MT_RW | MT_SECURE)
30 
31 #ifdef SPD_opteed
32 #define MAP_OPTEE_PAGEABLE	MAP_REGION_FLAT(		\
33 				POPLAR_OPTEE_PAGEABLE_LOAD_BASE,	\
34 				POPLAR_OPTEE_PAGEABLE_LOAD_SIZE,	\
35 				MT_MEMORY | MT_RW | MT_SECURE)
36 #endif
37 
38 static const mmap_region_t poplar_mmap[] = {
39 	MAP_DDR,
40 	MAP_DEVICE,
41 	MAP_TSP_MEM,
42 #ifdef SPD_opteed
43 	MAP_OPTEE_PAGEABLE,
44 #endif
45 	{0}
46 };
47 
48 #define DEFINE_CONFIGURE_MMU_EL(_el)					\
49 	void plat_configure_mmu_el##_el(unsigned long total_base,	\
50 				  unsigned long total_size,		\
51 				  unsigned long ro_start,		\
52 				  unsigned long ro_limit,		\
53 				  unsigned long coh_start,		\
54 				  unsigned long coh_limit)		\
55 	{								\
56 		mmap_add_region(total_base, total_base,			\
57 				total_size,				\
58 				MT_MEMORY | MT_RW | MT_SECURE);		\
59 		mmap_add_region(ro_start, ro_start,			\
60 				ro_limit - ro_start,			\
61 				MT_MEMORY | MT_RO | MT_SECURE);		\
62 		mmap_add_region(coh_start, coh_start,			\
63 				coh_limit - coh_start,			\
64 				MT_DEVICE | MT_RW | MT_SECURE);		\
65 		mmap_add(poplar_mmap);					\
66 		init_xlat_tables();					\
67 									\
68 		enable_mmu_el##_el(0);					\
69 	}
70 
71 DEFINE_CONFIGURE_MMU_EL(3)
72 DEFINE_CONFIGURE_MMU_EL(1)
73 
74 unsigned int plat_get_syscnt_freq2(void)
75 {
76 	return SYS_COUNTER_FREQ_IN_TICKS;
77 }
78