xref: /rk3399_ARM-atf/plat/nvidia/tegra/soc/t194/plat_setup.c (revision 416125595367ac426f45093e78f030bb2787ab61)
1 /*
2  * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <arch_helpers.h>
8 #include <assert.h>
9 #include <bl31/bl31.h>
10 #include <common/bl_common.h>
11 #include <common/interrupt_props.h>
12 #include <drivers/console.h>
13 #include <context.h>
14 #include <lib/el3_runtime/context_mgmt.h>
15 #include <cortex_a57.h>
16 #include <common/debug.h>
17 #include <denver.h>
18 #include <drivers/arm/gic_common.h>
19 #include <drivers/arm/gicv2.h>
20 #include <bl31/interrupt_mgmt.h>
21 #include <mce.h>
22 #include <plat/common/platform.h>
23 #include <tegra_def.h>
24 #include <tegra_platform.h>
25 #include <tegra_private.h>
26 #include <lib/xlat_tables/xlat_tables_v2.h>
27 
28 DEFINE_RENAME_SYSREG_RW_FUNCS(l2ctlr_el1, L2CTLR_EL1)
29 extern uint64_t tegra_enable_l2_ecc_parity_prot;
30 
31 /*******************************************************************************
32  * The Tegra power domain tree has a single system level power domain i.e. a
33  * single root node. The first entry in the power domain descriptor specifies
34  * the number of power domains at the highest power level.
35  *******************************************************************************
36  */
37 const unsigned char tegra_power_domain_tree_desc[] = {
38 	/* No of root nodes */
39 	1,
40 	/* No of clusters */
41 	PLATFORM_CLUSTER_COUNT,
42 	/* No of CPU cores - cluster0 */
43 	PLATFORM_MAX_CPUS_PER_CLUSTER,
44 	/* No of CPU cores - cluster1 */
45 	PLATFORM_MAX_CPUS_PER_CLUSTER
46 };
47 
48 /*
49  * Table of regions to map using the MMU.
50  */
51 static const mmap_region_t tegra_mmap[] = {
52 	MAP_REGION_FLAT(TEGRA_MISC_BASE, 0x10000, /* 64KB */
53 			MT_DEVICE | MT_RW | MT_SECURE),
54 	MAP_REGION_FLAT(TEGRA_TSA_BASE, 0x20000, /* 128KB */
55 			MT_DEVICE | MT_RW | MT_SECURE),
56 	MAP_REGION_FLAT(TEGRA_MC_STREAMID_BASE, 0x10000, /* 64KB */
57 			MT_DEVICE | MT_RW | MT_SECURE),
58 	MAP_REGION_FLAT(TEGRA_MC_BASE, 0x10000, /* 64KB */
59 			MT_DEVICE | MT_RW | MT_SECURE),
60 	MAP_REGION_FLAT(TEGRA_UARTA_BASE, 0x20000, /* 128KB - UART A, B*/
61 			MT_DEVICE | MT_RW | MT_SECURE),
62 	MAP_REGION_FLAT(TEGRA_UARTC_BASE, 0x20000, /* 128KB - UART C, G */
63 			MT_DEVICE | MT_RW | MT_SECURE),
64 	MAP_REGION_FLAT(TEGRA_UARTD_BASE, 0x30000, /* 192KB - UART D, E, F */
65 			MT_DEVICE | MT_RW | MT_SECURE),
66 	MAP_REGION_FLAT(TEGRA_FUSE_BASE, 0x10000, /* 64KB */
67 			MT_DEVICE | MT_RW | MT_SECURE),
68 	MAP_REGION_FLAT(TEGRA_GICD_BASE, 0x20000, /* 128KB */
69 			MT_DEVICE | MT_RW | MT_SECURE),
70 	MAP_REGION_FLAT(TEGRA_SE0_BASE, 0x10000, /* 64KB */
71 			MT_DEVICE | MT_RW | MT_SECURE),
72 	MAP_REGION_FLAT(TEGRA_PKA1_BASE, 0x10000, /* 64KB */
73 			MT_DEVICE | MT_RW | MT_SECURE),
74 	MAP_REGION_FLAT(TEGRA_RNG1_BASE, 0x10000, /* 64KB */
75 			MT_DEVICE | MT_RW | MT_SECURE),
76 	MAP_REGION_FLAT(TEGRA_CAR_RESET_BASE, 0x10000, /* 64KB */
77 			MT_DEVICE | MT_RW | MT_SECURE),
78 	MAP_REGION_FLAT(TEGRA_PMC_BASE, 0x40000, /* 256KB */
79 			MT_DEVICE | MT_RW | MT_SECURE),
80 	MAP_REGION_FLAT(TEGRA_SCRATCH_BASE, 0x10000, /* 64KB */
81 			MT_DEVICE | MT_RW | MT_SECURE),
82 	MAP_REGION_FLAT(TEGRA_MMCRAB_BASE, 0x60000, /* 384KB */
83 			MT_DEVICE | MT_RW | MT_SECURE),
84 	MAP_REGION_FLAT(TEGRA_SMMU_BASE, 0x1000000, /* 64KB */
85 			MT_DEVICE | MT_RW | MT_SECURE),
86 	{0}
87 };
88 
89 /*******************************************************************************
90  * Set up the pagetables as per the platform memory map & initialize the MMU
91  ******************************************************************************/
92 const mmap_region_t *plat_get_mmio_map(void)
93 {
94 	/* MMIO space */
95 	return tegra_mmap;
96 }
97 
98 /*******************************************************************************
99  * Handler to get the System Counter Frequency
100  ******************************************************************************/
101 unsigned int plat_get_syscnt_freq2(void)
102 {
103 	return 31250000;
104 }
105 
106 /*******************************************************************************
107  * Maximum supported UART controllers
108  ******************************************************************************/
109 #define TEGRA186_MAX_UART_PORTS		7
110 
111 /*******************************************************************************
112  * This variable holds the UART port base addresses
113  ******************************************************************************/
114 static uint32_t tegra186_uart_addresses[TEGRA186_MAX_UART_PORTS + 1] = {
115 	0,	/* undefined - treated as an error case */
116 	TEGRA_UARTA_BASE,
117 	TEGRA_UARTB_BASE,
118 	TEGRA_UARTC_BASE,
119 	TEGRA_UARTD_BASE,
120 	TEGRA_UARTE_BASE,
121 	TEGRA_UARTF_BASE,
122 	TEGRA_UARTG_BASE,
123 };
124 
125 /*******************************************************************************
126  * Retrieve the UART controller base to be used as the console
127  ******************************************************************************/
128 uint32_t plat_get_console_from_id(int id)
129 {
130 	if (id > TEGRA186_MAX_UART_PORTS)
131 		return 0;
132 
133 	return tegra186_uart_addresses[id];
134 }
135 
136 /* represent chip-version as concatenation of major (15:12), minor (11:8) and subrev (7:0) */
137 #define TEGRA186_VER_A02P	0x1201
138 
139 /*******************************************************************************
140  * Handler for early platform setup
141  ******************************************************************************/
142 void plat_early_platform_setup(void)
143 {
144 	int impl = (read_midr() >> MIDR_IMPL_SHIFT) & MIDR_IMPL_MASK;
145 	uint32_t chip_subrev, val;
146 
147 	/* sanity check MCE firmware compatibility */
148 	mce_verify_firmware_version();
149 
150 	/*
151 	 * Enable ECC and Parity Protection for Cortex-A57 CPUs
152 	 * for Tegra A02p SKUs
153 	 */
154 	if (impl != DENVER_IMPL) {
155 
156 		/* get the major, minor and sub-version values */
157 		chip_subrev = mmio_read_32(TEGRA_FUSE_BASE + OPT_SUBREVISION) &
158 			      SUBREVISION_MASK;
159 
160 		/* prepare chip version number */
161 		val = (tegra_get_chipid_major() << 12) |
162 		      (tegra_get_chipid_minor() << 8) |
163 		       chip_subrev;
164 
165 		/* enable L2 ECC for Tegra186 A02P and beyond */
166 		if (val >= TEGRA186_VER_A02P) {
167 
168 			val = read_l2ctlr_el1();
169 			val |= L2_ECC_PARITY_PROTECTION_BIT;
170 			write_l2ctlr_el1(val);
171 
172 			/*
173 			 * Set the flag to enable ECC/Parity Protection
174 			 * when we exit System Suspend or Cluster Powerdn
175 			 */
176 			tegra_enable_l2_ecc_parity_prot = 1;
177 		}
178 	}
179 }
180 
181 /* Secure IRQs for Tegra186 */
182 static const irq_sec_cfg_t tegra186_sec_irqs[] = {
183 	[0] = {
184 		TEGRA186_BPMP_WDT_IRQ,
185 		TEGRA186_SEC_IRQ_TARGET_MASK,
186 		INTR_TYPE_EL3,
187 	},
188 	[1] = {
189 		TEGRA186_BPMP_WDT_IRQ,
190 		TEGRA186_SEC_IRQ_TARGET_MASK,
191 		INTR_TYPE_EL3,
192 	},
193 	[2] = {
194 		TEGRA186_SPE_WDT_IRQ,
195 		TEGRA186_SEC_IRQ_TARGET_MASK,
196 		INTR_TYPE_EL3,
197 	},
198 	[3] = {
199 		TEGRA186_SCE_WDT_IRQ,
200 		TEGRA186_SEC_IRQ_TARGET_MASK,
201 		INTR_TYPE_EL3,
202 	},
203 	[4] = {
204 		TEGRA186_TOP_WDT_IRQ,
205 		TEGRA186_SEC_IRQ_TARGET_MASK,
206 		INTR_TYPE_EL3,
207 	},
208 	[5] = {
209 		TEGRA186_AON_WDT_IRQ,
210 		TEGRA186_SEC_IRQ_TARGET_MASK,
211 		INTR_TYPE_EL3,
212 	},
213 };
214 
215 /*******************************************************************************
216  * Initialize the GIC and SGIs
217  ******************************************************************************/
218 void plat_gic_setup(void)
219 {
220 	tegra_gic_setup(tegra186_sec_irqs,
221 		sizeof(tegra186_sec_irqs) / sizeof(tegra186_sec_irqs[0]));
222 
223 	/*
224 	 * Initialize the FIQ handler only if the platform supports any
225 	 * FIQ interrupt sources.
226 	 */
227 	if (sizeof(tegra186_sec_irqs) > 0)
228 		tegra_fiq_handler_setup();
229 }
230 
231 /*******************************************************************************
232  * Return pointer to the BL31 params from previous bootloader
233  ******************************************************************************/
234 struct tegra_bl31_params *plat_get_bl31_params(void)
235 {
236 	uint32_t val;
237 
238 	val = mmio_read_32(TEGRA_SCRATCH_BASE + SECURE_SCRATCH_RSV53_LO);
239 
240 	return (struct tegra_bl31_params *)(uintptr_t)val;
241 }
242 
243 /*******************************************************************************
244  * Return pointer to the BL31 platform params from previous bootloader
245  ******************************************************************************/
246 plat_params_from_bl2_t *plat_get_bl31_plat_params(void)
247 {
248 	uint32_t val;
249 
250 	val = mmio_read_32(TEGRA_SCRATCH_BASE + SECURE_SCRATCH_RSV53_HI);
251 
252 	return (plat_params_from_bl2_t *)(uintptr_t)val;
253 }
254