xref: /arm-trusted-firmware/plat/nxp/soc-ls1028a/soc.c (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu /*
2*91f16700Schasinglulu  * Copyright 2018-2021 NXP
3*91f16700Schasinglulu  *
4*91f16700Schasinglulu  * SPDX-License-Identifier: BSD-3-Clause
5*91f16700Schasinglulu  */
6*91f16700Schasinglulu 
7*91f16700Schasinglulu #include <endian.h>
8*91f16700Schasinglulu 
9*91f16700Schasinglulu #include <arch.h>
10*91f16700Schasinglulu #include <caam.h>
11*91f16700Schasinglulu #include <cassert.h>
12*91f16700Schasinglulu #include <cci.h>
13*91f16700Schasinglulu #include <common/debug.h>
14*91f16700Schasinglulu #include <dcfg.h>
15*91f16700Schasinglulu #include <i2c.h>
16*91f16700Schasinglulu #include <lib/xlat_tables/xlat_tables_v2.h>
17*91f16700Schasinglulu #include <ls_interconnect.h>
18*91f16700Schasinglulu #include <mmio.h>
19*91f16700Schasinglulu #ifdef POLICY_FUSE_PROVISION
20*91f16700Schasinglulu #include <nxp_gpio.h>
21*91f16700Schasinglulu #endif
22*91f16700Schasinglulu #if TRUSTED_BOARD_BOOT
23*91f16700Schasinglulu #include <nxp_smmu.h>
24*91f16700Schasinglulu #endif
25*91f16700Schasinglulu #include <nxp_timer.h>
26*91f16700Schasinglulu #include <plat_console.h>
27*91f16700Schasinglulu #include <plat_gic.h>
28*91f16700Schasinglulu #include <plat_tzc400.h>
29*91f16700Schasinglulu #include <pmu.h>
30*91f16700Schasinglulu #include <scfg.h>
31*91f16700Schasinglulu #if defined(NXP_SFP_ENABLED)
32*91f16700Schasinglulu #include <sfp.h>
33*91f16700Schasinglulu #endif
34*91f16700Schasinglulu 
35*91f16700Schasinglulu #include <errata.h>
36*91f16700Schasinglulu #ifdef CONFIG_OCRAM_ECC_EN
37*91f16700Schasinglulu #include <ocram.h>
38*91f16700Schasinglulu #endif
39*91f16700Schasinglulu #include "plat_common.h"
40*91f16700Schasinglulu #include "platform_def.h"
41*91f16700Schasinglulu #include "soc.h"
42*91f16700Schasinglulu 
43*91f16700Schasinglulu static dcfg_init_info_t dcfg_init_data = {
44*91f16700Schasinglulu 	.g_nxp_dcfg_addr = NXP_DCFG_ADDR,
45*91f16700Schasinglulu 	.nxp_sysclk_freq = NXP_SYSCLK_FREQ,
46*91f16700Schasinglulu 	.nxp_ddrclk_freq = NXP_DDRCLK_FREQ,
47*91f16700Schasinglulu 	.nxp_plat_clk_divider = NXP_PLATFORM_CLK_DIVIDER,
48*91f16700Schasinglulu };
49*91f16700Schasinglulu 
50*91f16700Schasinglulu static struct soc_type soc_list[] =  {
51*91f16700Schasinglulu 	SOC_ENTRY(LS1017AN, LS1017AN, 1, 1),
52*91f16700Schasinglulu 	SOC_ENTRY(LS1017AE, LS1017AE, 1, 1),
53*91f16700Schasinglulu 	SOC_ENTRY(LS1018AN, LS1018AN, 1, 1),
54*91f16700Schasinglulu 	SOC_ENTRY(LS1018AE, LS1018AE, 1, 1),
55*91f16700Schasinglulu 	SOC_ENTRY(LS1027AN, LS1027AN, 1, 2),
56*91f16700Schasinglulu 	SOC_ENTRY(LS1027AE, LS1027AE, 1, 2),
57*91f16700Schasinglulu 	SOC_ENTRY(LS1028AN, LS1028AN, 1, 2),
58*91f16700Schasinglulu 	SOC_ENTRY(LS1028AE, LS1028AE, 1, 2),
59*91f16700Schasinglulu };
60*91f16700Schasinglulu 
61*91f16700Schasinglulu CASSERT(NUMBER_OF_CLUSTERS && NUMBER_OF_CLUSTERS <= 256,
62*91f16700Schasinglulu 	assert_invalid_ls1028a_cluster_count);
63*91f16700Schasinglulu 
64*91f16700Schasinglulu /*
65*91f16700Schasinglulu  * Function returns the base counter frequency
66*91f16700Schasinglulu  * after reading the first entry at CNTFID0 (0x20 offset).
67*91f16700Schasinglulu  *
68*91f16700Schasinglulu  * Function is used by:
69*91f16700Schasinglulu  *   1. ARM common code for PSCI management.
70*91f16700Schasinglulu  *   2. ARM Generic Timer init.
71*91f16700Schasinglulu  *
72*91f16700Schasinglulu  */
73*91f16700Schasinglulu unsigned int plat_get_syscnt_freq2(void)
74*91f16700Schasinglulu {
75*91f16700Schasinglulu 	unsigned int counter_base_frequency;
76*91f16700Schasinglulu 	/*
77*91f16700Schasinglulu 	 * Below register specifies the base frequency of the system counter.
78*91f16700Schasinglulu 	 * As per NXP Board Manuals:
79*91f16700Schasinglulu 	 * The system counter always works with SYS_REF_CLK/4 frequency clock.
80*91f16700Schasinglulu 	 */
81*91f16700Schasinglulu 	counter_base_frequency = mmio_read_32(NXP_TIMER_ADDR + CNTFID_OFF);
82*91f16700Schasinglulu 
83*91f16700Schasinglulu 	return counter_base_frequency;
84*91f16700Schasinglulu }
85*91f16700Schasinglulu 
86*91f16700Schasinglulu #ifdef IMAGE_BL2
87*91f16700Schasinglulu 
88*91f16700Schasinglulu #ifdef POLICY_FUSE_PROVISION
89*91f16700Schasinglulu static gpio_init_info_t gpio_init_data = {
90*91f16700Schasinglulu 	.gpio1_base_addr = NXP_GPIO1_ADDR,
91*91f16700Schasinglulu 	.gpio2_base_addr = NXP_GPIO2_ADDR,
92*91f16700Schasinglulu 	.gpio3_base_addr = NXP_GPIO3_ADDR,
93*91f16700Schasinglulu };
94*91f16700Schasinglulu #endif
95*91f16700Schasinglulu 
96*91f16700Schasinglulu void soc_preload_setup(void)
97*91f16700Schasinglulu {
98*91f16700Schasinglulu }
99*91f16700Schasinglulu 
100*91f16700Schasinglulu void soc_early_init(void)
101*91f16700Schasinglulu {
102*91f16700Schasinglulu 	uint8_t num_clusters, cores_per_cluster;
103*91f16700Schasinglulu 
104*91f16700Schasinglulu #ifdef CONFIG_OCRAM_ECC_EN
105*91f16700Schasinglulu 	ocram_init(NXP_OCRAM_ADDR, NXP_OCRAM_SIZE);
106*91f16700Schasinglulu #endif
107*91f16700Schasinglulu 	dcfg_init(&dcfg_init_data);
108*91f16700Schasinglulu 	enable_timer_base_to_cluster(NXP_PMU_ADDR);
109*91f16700Schasinglulu 	enable_core_tb(NXP_PMU_ADDR);
110*91f16700Schasinglulu 	dram_regions_info_t *dram_regions_info = get_dram_regions_info();
111*91f16700Schasinglulu 
112*91f16700Schasinglulu #ifdef POLICY_FUSE_PROVISION
113*91f16700Schasinglulu 	gpio_init(&gpio_init_data);
114*91f16700Schasinglulu 	sec_init(NXP_CAAM_ADDR);
115*91f16700Schasinglulu #endif
116*91f16700Schasinglulu 
117*91f16700Schasinglulu #if LOG_LEVEL > 0
118*91f16700Schasinglulu 	/* Initialize the console to provide early debug support */
119*91f16700Schasinglulu 	plat_console_init(NXP_CONSOLE_ADDR,
120*91f16700Schasinglulu 				NXP_UART_CLK_DIVIDER, NXP_CONSOLE_BAUDRATE);
121*91f16700Schasinglulu #endif
122*91f16700Schasinglulu 	enum  boot_device dev = get_boot_dev();
123*91f16700Schasinglulu 	/*
124*91f16700Schasinglulu 	 * Mark the buffer for SD in OCRAM as non secure.
125*91f16700Schasinglulu 	 * The buffer is assumed to be at end of OCRAM for
126*91f16700Schasinglulu 	 * the logic below to calculate TZPC programming
127*91f16700Schasinglulu 	 */
128*91f16700Schasinglulu 	if (dev == BOOT_DEVICE_EMMC || dev == BOOT_DEVICE_SDHC2_EMMC) {
129*91f16700Schasinglulu 		/*
130*91f16700Schasinglulu 		 * Calculate the region in OCRAM which is secure
131*91f16700Schasinglulu 		 * The buffer for SD needs to be marked non-secure
132*91f16700Schasinglulu 		 * to allow SD to do DMA operations on it
133*91f16700Schasinglulu 		 */
134*91f16700Schasinglulu 		uint32_t secure_region = (NXP_OCRAM_SIZE - NXP_SD_BLOCK_BUF_SIZE);
135*91f16700Schasinglulu 		uint32_t mask = secure_region/TZPC_BLOCK_SIZE;
136*91f16700Schasinglulu 
137*91f16700Schasinglulu 		mmio_write_32(NXP_OCRAM_TZPC_ADDR, mask);
138*91f16700Schasinglulu 
139*91f16700Schasinglulu 		/* Add the entry for buffer in MMU Table */
140*91f16700Schasinglulu 		mmap_add_region(NXP_SD_BLOCK_BUF_ADDR, NXP_SD_BLOCK_BUF_ADDR,
141*91f16700Schasinglulu 				NXP_SD_BLOCK_BUF_SIZE, MT_DEVICE | MT_RW | MT_NS);
142*91f16700Schasinglulu 	}
143*91f16700Schasinglulu 
144*91f16700Schasinglulu #if TRUSTED_BOARD_BOOT
145*91f16700Schasinglulu 	uint32_t mode;
146*91f16700Schasinglulu 
147*91f16700Schasinglulu 	sfp_init(NXP_SFP_ADDR);
148*91f16700Schasinglulu 
149*91f16700Schasinglulu 	/*
150*91f16700Schasinglulu 	 * For secure boot disable SMMU.
151*91f16700Schasinglulu 	 * Later when platform security policy comes in picture,
152*91f16700Schasinglulu 	 * this might get modified based on the policy
153*91f16700Schasinglulu 	 */
154*91f16700Schasinglulu 	if (check_boot_mode_secure(&mode) == true) {
155*91f16700Schasinglulu 		bypass_smmu(NXP_SMMU_ADDR);
156*91f16700Schasinglulu 	}
157*91f16700Schasinglulu 
158*91f16700Schasinglulu 	/*
159*91f16700Schasinglulu 	 * For Mbedtls currently crypto is not supported via CAAM
160*91f16700Schasinglulu 	 * enable it when that support is there. In tbbr.mk
161*91f16700Schasinglulu 	 * the CAAM_INTEG is set as 0.
162*91f16700Schasinglulu 	 */
163*91f16700Schasinglulu #ifndef MBEDTLS_X509
164*91f16700Schasinglulu 	/* Initialize the crypto accelerator if enabled */
165*91f16700Schasinglulu 	if (is_sec_enabled()) {
166*91f16700Schasinglulu 		sec_init(NXP_CAAM_ADDR);
167*91f16700Schasinglulu 	} else {
168*91f16700Schasinglulu 		INFO("SEC is disabled.\n");
169*91f16700Schasinglulu 	}
170*91f16700Schasinglulu #endif
171*91f16700Schasinglulu #endif
172*91f16700Schasinglulu 
173*91f16700Schasinglulu 	/* Set eDDRTQ for DDR performance */
174*91f16700Schasinglulu 	scfg_setbits32((void *)(NXP_SCFG_ADDR + 0x210), 0x1f1f1f1f);
175*91f16700Schasinglulu 
176*91f16700Schasinglulu 	soc_errata();
177*91f16700Schasinglulu 
178*91f16700Schasinglulu 	/*
179*91f16700Schasinglulu 	 * Initialize Interconnect for this cluster during cold boot.
180*91f16700Schasinglulu 	 * No need for locks as no other CPU is active.
181*91f16700Schasinglulu 	 */
182*91f16700Schasinglulu 	cci_init(NXP_CCI_ADDR, cci_map, ARRAY_SIZE(cci_map));
183*91f16700Schasinglulu 
184*91f16700Schasinglulu 	/*
185*91f16700Schasinglulu 	 * Enable Interconnect coherency for the primary CPU's cluster.
186*91f16700Schasinglulu 	 */
187*91f16700Schasinglulu 	get_cluster_info(soc_list, ARRAY_SIZE(soc_list), &num_clusters, &cores_per_cluster);
188*91f16700Schasinglulu 	plat_ls_interconnect_enter_coherency(num_clusters);
189*91f16700Schasinglulu 
190*91f16700Schasinglulu 	delay_timer_init(NXP_TIMER_ADDR);
191*91f16700Schasinglulu 	i2c_init(NXP_I2C_ADDR);
192*91f16700Schasinglulu 	dram_regions_info->total_dram_size = init_ddr();
193*91f16700Schasinglulu }
194*91f16700Schasinglulu 
195*91f16700Schasinglulu void soc_bl2_prepare_exit(void)
196*91f16700Schasinglulu {
197*91f16700Schasinglulu #if defined(NXP_SFP_ENABLED) && defined(DISABLE_FUSE_WRITE)
198*91f16700Schasinglulu 	set_sfp_wr_disable();
199*91f16700Schasinglulu #endif
200*91f16700Schasinglulu }
201*91f16700Schasinglulu 
202*91f16700Schasinglulu /*
203*91f16700Schasinglulu  * This function returns the boot device based on RCW_SRC
204*91f16700Schasinglulu  */
205*91f16700Schasinglulu enum boot_device get_boot_dev(void)
206*91f16700Schasinglulu {
207*91f16700Schasinglulu 	enum boot_device src = BOOT_DEVICE_NONE;
208*91f16700Schasinglulu 	uint32_t porsr1;
209*91f16700Schasinglulu 	uint32_t rcw_src;
210*91f16700Schasinglulu 
211*91f16700Schasinglulu 	porsr1 = read_reg_porsr1();
212*91f16700Schasinglulu 
213*91f16700Schasinglulu 	rcw_src = (porsr1 & PORSR1_RCW_MASK) >> PORSR1_RCW_SHIFT;
214*91f16700Schasinglulu 	switch (rcw_src) {
215*91f16700Schasinglulu 	case FLEXSPI_NOR:
216*91f16700Schasinglulu 		src = BOOT_DEVICE_FLEXSPI_NOR;
217*91f16700Schasinglulu 		INFO("RCW BOOT SRC is FLEXSPI NOR\n");
218*91f16700Schasinglulu 		break;
219*91f16700Schasinglulu 	case FLEXSPI_NAND2K_VAL:
220*91f16700Schasinglulu 	case FLEXSPI_NAND4K_VAL:
221*91f16700Schasinglulu 		INFO("RCW BOOT SRC is FLEXSPI NAND\n");
222*91f16700Schasinglulu 		src = BOOT_DEVICE_FLEXSPI_NAND;
223*91f16700Schasinglulu 		break;
224*91f16700Schasinglulu 	case SDHC1_VAL:
225*91f16700Schasinglulu 		src = BOOT_DEVICE_EMMC;
226*91f16700Schasinglulu 		INFO("RCW BOOT SRC is SD\n");
227*91f16700Schasinglulu 		break;
228*91f16700Schasinglulu 	case SDHC2_VAL:
229*91f16700Schasinglulu 		src = BOOT_DEVICE_SDHC2_EMMC;
230*91f16700Schasinglulu 		INFO("RCW BOOT SRC is EMMC\n");
231*91f16700Schasinglulu 		break;
232*91f16700Schasinglulu 	default:
233*91f16700Schasinglulu 		break;
234*91f16700Schasinglulu 	}
235*91f16700Schasinglulu 
236*91f16700Schasinglulu 	return src;
237*91f16700Schasinglulu }
238*91f16700Schasinglulu 
239*91f16700Schasinglulu /*
240*91f16700Schasinglulu  * This function sets up access permissions on memory regions
241*91f16700Schasinglulu  ****************************************************************************/
242*91f16700Schasinglulu void soc_mem_access(void)
243*91f16700Schasinglulu {
244*91f16700Schasinglulu 	dram_regions_info_t *info_dram_regions = get_dram_regions_info();
245*91f16700Schasinglulu 	struct tzc400_reg tzc400_reg_list[MAX_NUM_TZC_REGION];
246*91f16700Schasinglulu 	int dram_idx = 0;
247*91f16700Schasinglulu 	/* index 0 is reserved for region-0 */
248*91f16700Schasinglulu 	int index = 1;
249*91f16700Schasinglulu 
250*91f16700Schasinglulu 	for (dram_idx = 0; dram_idx < info_dram_regions->num_dram_regions;
251*91f16700Schasinglulu 	     dram_idx++) {
252*91f16700Schasinglulu 		if (info_dram_regions->region[dram_idx].size == 0) {
253*91f16700Schasinglulu 			ERROR("DDR init failure, or");
254*91f16700Schasinglulu 			ERROR("DRAM regions not populated correctly.\n");
255*91f16700Schasinglulu 			break;
256*91f16700Schasinglulu 		}
257*91f16700Schasinglulu 
258*91f16700Schasinglulu 		index = populate_tzc400_reg_list(tzc400_reg_list,
259*91f16700Schasinglulu 				dram_idx, index,
260*91f16700Schasinglulu 				info_dram_regions->region[dram_idx].addr,
261*91f16700Schasinglulu 				info_dram_regions->region[dram_idx].size,
262*91f16700Schasinglulu 				NXP_SECURE_DRAM_SIZE, NXP_SP_SHRD_DRAM_SIZE);
263*91f16700Schasinglulu 	}
264*91f16700Schasinglulu 
265*91f16700Schasinglulu 	mem_access_setup(NXP_TZC_ADDR, index, tzc400_reg_list);
266*91f16700Schasinglulu }
267*91f16700Schasinglulu 
268*91f16700Schasinglulu #else
269*91f16700Schasinglulu 
270*91f16700Schasinglulu static unsigned char _power_domain_tree_desc[NUMBER_OF_CLUSTERS + 2];
271*91f16700Schasinglulu /*
272*91f16700Schasinglulu  * This function dynamically constructs the topology according to
273*91f16700Schasinglulu  *  SoC Flavor and returns it.
274*91f16700Schasinglulu  */
275*91f16700Schasinglulu const unsigned char *plat_get_power_domain_tree_desc(void)
276*91f16700Schasinglulu {
277*91f16700Schasinglulu 	uint8_t num_clusters, cores_per_cluster;
278*91f16700Schasinglulu 	unsigned int i;
279*91f16700Schasinglulu 
280*91f16700Schasinglulu 	get_cluster_info(soc_list, ARRAY_SIZE(soc_list), &num_clusters, &cores_per_cluster);
281*91f16700Schasinglulu 	/*
282*91f16700Schasinglulu 	 * The highest level is the system level. The next level is constituted
283*91f16700Schasinglulu 	 * by clusters and then cores in clusters.
284*91f16700Schasinglulu 	 */
285*91f16700Schasinglulu 	_power_domain_tree_desc[0] = 1;
286*91f16700Schasinglulu 	_power_domain_tree_desc[1] = num_clusters;
287*91f16700Schasinglulu 
288*91f16700Schasinglulu 	for (i = 0; i < _power_domain_tree_desc[1]; i++)
289*91f16700Schasinglulu 		_power_domain_tree_desc[i + 2] = cores_per_cluster;
290*91f16700Schasinglulu 
291*91f16700Schasinglulu 	return _power_domain_tree_desc;
292*91f16700Schasinglulu }
293*91f16700Schasinglulu 
294*91f16700Schasinglulu /*
295*91f16700Schasinglulu  * This function returns the core count within the cluster corresponding to
296*91f16700Schasinglulu  * `mpidr`.
297*91f16700Schasinglulu  */
298*91f16700Schasinglulu unsigned int plat_ls_get_cluster_core_count(u_register_t mpidr)
299*91f16700Schasinglulu {
300*91f16700Schasinglulu 	uint8_t num_clusters, cores_per_cluster;
301*91f16700Schasinglulu 
302*91f16700Schasinglulu 	get_cluster_info(soc_list, ARRAY_SIZE(soc_list), &num_clusters, &cores_per_cluster);
303*91f16700Schasinglulu 	return num_clusters;
304*91f16700Schasinglulu }
305*91f16700Schasinglulu 
306*91f16700Schasinglulu void soc_early_platform_setup2(void)
307*91f16700Schasinglulu {
308*91f16700Schasinglulu 	dcfg_init(&dcfg_init_data);
309*91f16700Schasinglulu 	/* Initialize system level generic timer for Socs */
310*91f16700Schasinglulu 	delay_timer_init(NXP_TIMER_ADDR);
311*91f16700Schasinglulu 
312*91f16700Schasinglulu #if LOG_LEVEL > 0
313*91f16700Schasinglulu 	/* Initialize the console to provide early debug support */
314*91f16700Schasinglulu 	plat_console_init(NXP_CONSOLE_ADDR,
315*91f16700Schasinglulu 				NXP_UART_CLK_DIVIDER, NXP_CONSOLE_BAUDRATE);
316*91f16700Schasinglulu #endif
317*91f16700Schasinglulu }
318*91f16700Schasinglulu 
319*91f16700Schasinglulu void soc_platform_setup(void)
320*91f16700Schasinglulu {
321*91f16700Schasinglulu 	/* Initialize the GIC driver, cpu and distributor interfaces */
322*91f16700Schasinglulu 	static uintptr_t target_mask_array[PLATFORM_CORE_COUNT];
323*91f16700Schasinglulu 	static interrupt_prop_t ls_interrupt_props[] = {
324*91f16700Schasinglulu 		PLAT_LS_G1S_IRQ_PROPS(INTR_GROUP1S),
325*91f16700Schasinglulu 		PLAT_LS_G0_IRQ_PROPS(INTR_GROUP0)
326*91f16700Schasinglulu 	};
327*91f16700Schasinglulu 
328*91f16700Schasinglulu 	plat_ls_gic_driver_init(NXP_GICD_ADDR, NXP_GICR_ADDR,
329*91f16700Schasinglulu 				PLATFORM_CORE_COUNT,
330*91f16700Schasinglulu 				ls_interrupt_props,
331*91f16700Schasinglulu 				ARRAY_SIZE(ls_interrupt_props),
332*91f16700Schasinglulu 				target_mask_array,
333*91f16700Schasinglulu 				plat_core_pos);
334*91f16700Schasinglulu 
335*91f16700Schasinglulu 	plat_ls_gic_init();
336*91f16700Schasinglulu 	enable_init_timer();
337*91f16700Schasinglulu }
338*91f16700Schasinglulu 
339*91f16700Schasinglulu /* This function initializes the soc from the BL31 module */
340*91f16700Schasinglulu void soc_init(void)
341*91f16700Schasinglulu {
342*91f16700Schasinglulu 	uint8_t num_clusters, cores_per_cluster;
343*91f16700Schasinglulu 
344*91f16700Schasinglulu 	get_cluster_info(soc_list, ARRAY_SIZE(soc_list), &num_clusters, &cores_per_cluster);
345*91f16700Schasinglulu 
346*91f16700Schasinglulu 	/* Low-level init of the soc */
347*91f16700Schasinglulu 	soc_init_lowlevel();
348*91f16700Schasinglulu 	_init_global_data();
349*91f16700Schasinglulu 	soc_init_percpu();
350*91f16700Schasinglulu 	_initialize_psci();
351*91f16700Schasinglulu 
352*91f16700Schasinglulu 	/*
353*91f16700Schasinglulu 	 * Initialize Interconnect for this cluster during cold boot.
354*91f16700Schasinglulu 	 * No need for locks as no other CPU is active.
355*91f16700Schasinglulu 	 */
356*91f16700Schasinglulu 	cci_init(NXP_CCI_ADDR, cci_map, ARRAY_SIZE(cci_map));
357*91f16700Schasinglulu 
358*91f16700Schasinglulu 	/* Enable Interconnect coherency for the primary CPU's cluster. */
359*91f16700Schasinglulu 	plat_ls_interconnect_enter_coherency(num_clusters);
360*91f16700Schasinglulu 
361*91f16700Schasinglulu 	/* Set platform security policies */
362*91f16700Schasinglulu 	_set_platform_security();
363*91f16700Schasinglulu 
364*91f16700Schasinglulu 	/* Init SEC Engine which will be used by SiP */
365*91f16700Schasinglulu 	if (is_sec_enabled()) {
366*91f16700Schasinglulu 		sec_init(NXP_CAAM_ADDR);
367*91f16700Schasinglulu 	} else {
368*91f16700Schasinglulu 		INFO("SEC is disabled.\n");
369*91f16700Schasinglulu 	}
370*91f16700Schasinglulu }
371*91f16700Schasinglulu 
372*91f16700Schasinglulu #ifdef NXP_WDOG_RESTART
373*91f16700Schasinglulu static uint64_t wdog_interrupt_handler(uint32_t id, uint32_t flags,
374*91f16700Schasinglulu 					  void *handle, void *cookie)
375*91f16700Schasinglulu {
376*91f16700Schasinglulu 	uint8_t data = WDOG_RESET_FLAG;
377*91f16700Schasinglulu 
378*91f16700Schasinglulu 	wr_nv_app_data(WDT_RESET_FLAG_OFFSET,
379*91f16700Schasinglulu 			(uint8_t *)&data, sizeof(data));
380*91f16700Schasinglulu 
381*91f16700Schasinglulu 	mmio_write_32(NXP_RST_ADDR + RSTCNTL_OFFSET, SW_RST_REQ_INIT);
382*91f16700Schasinglulu 
383*91f16700Schasinglulu 	return 0;
384*91f16700Schasinglulu }
385*91f16700Schasinglulu #endif
386*91f16700Schasinglulu 
387*91f16700Schasinglulu void soc_runtime_setup(void)
388*91f16700Schasinglulu {
389*91f16700Schasinglulu #ifdef NXP_WDOG_RESTART
390*91f16700Schasinglulu 	request_intr_type_el3(BL31_NS_WDOG_WS1, wdog_interrupt_handler);
391*91f16700Schasinglulu #endif
392*91f16700Schasinglulu }
393*91f16700Schasinglulu 
394*91f16700Schasinglulu /* This function returns the total number of cores in the SoC. */
395*91f16700Schasinglulu unsigned int get_tot_num_cores(void)
396*91f16700Schasinglulu {
397*91f16700Schasinglulu 	uint8_t num_clusters, cores_per_cluster;
398*91f16700Schasinglulu 
399*91f16700Schasinglulu 	get_cluster_info(soc_list, ARRAY_SIZE(soc_list), &num_clusters, &cores_per_cluster);
400*91f16700Schasinglulu 	return (num_clusters * cores_per_cluster);
401*91f16700Schasinglulu }
402*91f16700Schasinglulu 
403*91f16700Schasinglulu /* This function returns the PMU IDLE Cluster mask. */
404*91f16700Schasinglulu unsigned int get_pmu_idle_cluster_mask(void)
405*91f16700Schasinglulu {
406*91f16700Schasinglulu 	uint8_t num_clusters, cores_per_cluster;
407*91f16700Schasinglulu 
408*91f16700Schasinglulu 	get_cluster_info(soc_list, ARRAY_SIZE(soc_list), &num_clusters, &cores_per_cluster);
409*91f16700Schasinglulu 	return ((1 << num_clusters) - 2);
410*91f16700Schasinglulu }
411*91f16700Schasinglulu 
412*91f16700Schasinglulu /* This function returns the PMU Flush Cluster mask. */
413*91f16700Schasinglulu unsigned int get_pmu_flush_cluster_mask(void)
414*91f16700Schasinglulu {
415*91f16700Schasinglulu 	uint8_t num_clusters, cores_per_cluster;
416*91f16700Schasinglulu 
417*91f16700Schasinglulu 	get_cluster_info(soc_list, ARRAY_SIZE(soc_list), &num_clusters, &cores_per_cluster);
418*91f16700Schasinglulu 	return ((1 << num_clusters) - 2);
419*91f16700Schasinglulu }
420*91f16700Schasinglulu 
421*91f16700Schasinglulu /* This function returns the PMU idle core mask. */
422*91f16700Schasinglulu unsigned int get_pmu_idle_core_mask(void)
423*91f16700Schasinglulu {
424*91f16700Schasinglulu 	return ((1 << get_tot_num_cores()) - 2);
425*91f16700Schasinglulu }
426*91f16700Schasinglulu 
427*91f16700Schasinglulu /* Function to return the SoC SYS CLK */
428*91f16700Schasinglulu unsigned int get_sys_clk(void)
429*91f16700Schasinglulu {
430*91f16700Schasinglulu 	return NXP_SYSCLK_FREQ;
431*91f16700Schasinglulu }
432*91f16700Schasinglulu #endif
433