xref: /rk3399_ARM-atf/plat/mediatek/mt8173/aarch64/platform_common.c (revision 7d116dccab2249a692181ba9521a52277e86591c)
1*7d116dccSCC Ma /*
2*7d116dccSCC Ma  * Copyright (c) 2013-2015, ARM Limited and Contributors. All rights reserved.
3*7d116dccSCC Ma  *
4*7d116dccSCC Ma  * Redistribution and use in source and binary forms, with or without
5*7d116dccSCC Ma  * modification, are permitted provided that the following conditions are met:
6*7d116dccSCC Ma  *
7*7d116dccSCC Ma  * Redistributions of source code must retain the above copyright notice, this
8*7d116dccSCC Ma  * list of conditions and the following disclaimer.
9*7d116dccSCC Ma  *
10*7d116dccSCC Ma  * Redistributions in binary form must reproduce the above copyright notice,
11*7d116dccSCC Ma  * this list of conditions and the following disclaimer in the documentation
12*7d116dccSCC Ma  * and/or other materials provided with the distribution.
13*7d116dccSCC Ma  *
14*7d116dccSCC Ma  * Neither the name of ARM nor the names of its contributors may be used
15*7d116dccSCC Ma  * to endorse or promote products derived from this software without specific
16*7d116dccSCC Ma  * prior written permission.
17*7d116dccSCC Ma  *
18*7d116dccSCC Ma  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19*7d116dccSCC Ma  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*7d116dccSCC Ma  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*7d116dccSCC Ma  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22*7d116dccSCC Ma  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23*7d116dccSCC Ma  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24*7d116dccSCC Ma  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25*7d116dccSCC Ma  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26*7d116dccSCC Ma  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27*7d116dccSCC Ma  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28*7d116dccSCC Ma  * POSSIBILITY OF SUCH DAMAGE.
29*7d116dccSCC Ma  */
30*7d116dccSCC Ma #include <arch_helpers.h>
31*7d116dccSCC Ma #include <arm_gic.h>
32*7d116dccSCC Ma #include <bl_common.h>
33*7d116dccSCC Ma #include <cci.h>
34*7d116dccSCC Ma #include <debug.h>
35*7d116dccSCC Ma #include <mt8173_def.h>
36*7d116dccSCC Ma #include <platform_def.h>
37*7d116dccSCC Ma #include <xlat_tables.h>
38*7d116dccSCC Ma 
39*7d116dccSCC Ma static const int cci_map[] = {
40*7d116dccSCC Ma 	PLAT_MT_CCI_CLUSTER0_SL_IFACE_IX,
41*7d116dccSCC Ma 	PLAT_MT_CCI_CLUSTER1_SL_IFACE_IX
42*7d116dccSCC Ma };
43*7d116dccSCC Ma 
44*7d116dccSCC Ma /* Table of regions to map using the MMU.  */
45*7d116dccSCC Ma const mmap_region_t plat_mmap[] = {
46*7d116dccSCC Ma 	/* for TF text, RO, RW */
47*7d116dccSCC Ma 	MAP_REGION_FLAT(TZRAM_BASE, TZRAM_SIZE + TZRAM2_SIZE,
48*7d116dccSCC Ma 			MT_MEMORY | MT_RW | MT_SECURE),
49*7d116dccSCC Ma 	MAP_REGION_FLAT(MTK_DEV_RNG0_BASE, MTK_DEV_RNG0_SIZE,
50*7d116dccSCC Ma 			MT_DEVICE | MT_RW | MT_SECURE),
51*7d116dccSCC Ma 	MAP_REGION_FLAT(MTK_DEV_RNG1_BASE, MTK_DEV_RNG1_SIZE,
52*7d116dccSCC Ma 			MT_DEVICE | MT_RW | MT_SECURE),
53*7d116dccSCC Ma 	{ 0 }
54*7d116dccSCC Ma 
55*7d116dccSCC Ma };
56*7d116dccSCC Ma 
57*7d116dccSCC Ma /*******************************************************************************
58*7d116dccSCC Ma  * Macro generating the code for the function setting up the pagetables as per
59*7d116dccSCC Ma  * the platform memory map & initialize the mmu, for the given exception level
60*7d116dccSCC Ma  ******************************************************************************/
61*7d116dccSCC Ma #define DEFINE_CONFIGURE_MMU_EL(_el)					\
62*7d116dccSCC Ma 	void plat_configure_mmu_el ## _el(unsigned long total_base,	\
63*7d116dccSCC Ma 					  unsigned long total_size,	\
64*7d116dccSCC Ma 					  unsigned long ro_start,	\
65*7d116dccSCC Ma 					  unsigned long ro_limit,	\
66*7d116dccSCC Ma 					  unsigned long coh_start,	\
67*7d116dccSCC Ma 					  unsigned long coh_limit)	\
68*7d116dccSCC Ma 	{								\
69*7d116dccSCC Ma 		mmap_add_region(total_base, total_base,			\
70*7d116dccSCC Ma 				total_size,				\
71*7d116dccSCC Ma 				MT_MEMORY | MT_RW | MT_SECURE);		\
72*7d116dccSCC Ma 		mmap_add_region(ro_start, ro_start,			\
73*7d116dccSCC Ma 				ro_limit - ro_start,			\
74*7d116dccSCC Ma 				MT_MEMORY | MT_RO | MT_SECURE);		\
75*7d116dccSCC Ma 		mmap_add_region(coh_start, coh_start,			\
76*7d116dccSCC Ma 				coh_limit - coh_start,			\
77*7d116dccSCC Ma 				MT_DEVICE | MT_RW | MT_SECURE);		\
78*7d116dccSCC Ma 		mmap_add(plat_mmap);					\
79*7d116dccSCC Ma 		init_xlat_tables();					\
80*7d116dccSCC Ma 									\
81*7d116dccSCC Ma 		enable_mmu_el ## _el(0);				\
82*7d116dccSCC Ma 	}
83*7d116dccSCC Ma 
84*7d116dccSCC Ma /* Define EL3 variants of the function initialising the MMU */
85*7d116dccSCC Ma DEFINE_CONFIGURE_MMU_EL(3)
86*7d116dccSCC Ma 
87*7d116dccSCC Ma uint64_t plat_get_syscnt_freq(void)
88*7d116dccSCC Ma {
89*7d116dccSCC Ma 	return SYS_COUNTER_FREQ_IN_TICKS;
90*7d116dccSCC Ma }
91*7d116dccSCC Ma 
92*7d116dccSCC Ma void plat_cci_init(void)
93*7d116dccSCC Ma {
94*7d116dccSCC Ma 	/* Initialize CCI driver */
95*7d116dccSCC Ma 	cci_init(PLAT_MT_CCI_BASE, cci_map, ARRAY_SIZE(cci_map));
96*7d116dccSCC Ma }
97*7d116dccSCC Ma 
98*7d116dccSCC Ma void plat_cci_enable(void)
99*7d116dccSCC Ma {
100*7d116dccSCC Ma 	/*
101*7d116dccSCC Ma 	 * Enable CCI coherency for this cluster.
102*7d116dccSCC Ma 	 * No need for locks as no other cpu is active at the moment.
103*7d116dccSCC Ma 	 */
104*7d116dccSCC Ma 	cci_enable_snoop_dvm_reqs(MPIDR_AFFLVL1_VAL(read_mpidr()));
105*7d116dccSCC Ma }
106*7d116dccSCC Ma 
107*7d116dccSCC Ma void plat_cci_disable(void)
108*7d116dccSCC Ma {
109*7d116dccSCC Ma 	cci_disable_snoop_dvm_reqs(MPIDR_AFFLVL1_VAL(read_mpidr()));
110*7d116dccSCC Ma }
111