14ced5956SRohit Mathew /*
237cc7fa5SNishant Sharma * Copyright (c) 2018-2025, Arm Limited and Contributors. All rights reserved.
34ced5956SRohit Mathew *
44ced5956SRohit Mathew * SPDX-License-Identifier: BSD-3-Clause
54ced5956SRohit Mathew */
64ced5956SRohit Mathew
74ced5956SRohit Mathew #include <assert.h>
84ced5956SRohit Mathew
94ced5956SRohit Mathew #include <libfdt.h>
104ced5956SRohit Mathew
114ced5956SRohit Mathew #include <common/bl_common.h>
124ced5956SRohit Mathew #include <common/debug.h>
134ced5956SRohit Mathew #include <drivers/arm/css/css_mhu_doorbell.h>
144ced5956SRohit Mathew #include <drivers/arm/css/scmi.h>
154ced5956SRohit Mathew #include <drivers/generic_delay_timer.h>
1637cc7fa5SNishant Sharma #include <lib/fconf/fconf.h>
1737cc7fa5SNishant Sharma #include <lib/fconf/fconf_dyn_cfg_getter.h>
184ced5956SRohit Mathew #include <plat/arm/common/plat_arm.h>
194ced5956SRohit Mathew #include <plat/arm/css/common/css_pm.h>
204ced5956SRohit Mathew #include <plat/common/platform.h>
214ced5956SRohit Mathew
224ced5956SRohit Mathew #include <nrd_ras.h>
234ced5956SRohit Mathew #include <nrd_variant.h>
244ced5956SRohit Mathew
2540ea4208SRohit Mathew nrd_platform_info_t nrd_plat_info;
264ced5956SRohit Mathew
274ced5956SRohit Mathew static scmi_channel_plat_info_t plat_rd_scmi_info[] = {
284ced5956SRohit Mathew {
294ced5956SRohit Mathew .scmi_mbx_mem = CSS_SCMI_PAYLOAD_BASE,
304ced5956SRohit Mathew .db_reg_addr = PLAT_CSS_MHU_BASE + SENDER_REG_SET(0),
314ced5956SRohit Mathew .db_preserve_mask = 0xfffffffe,
324ced5956SRohit Mathew .db_modify_mask = 0x1,
334ced5956SRohit Mathew .ring_doorbell = &mhuv2_ring_doorbell,
344ced5956SRohit Mathew },
35a1e6467bSRohit Mathew #if (NRD_CHIP_COUNT > 1)
364ced5956SRohit Mathew {
374ced5956SRohit Mathew .scmi_mbx_mem = CSS_SCMI_PAYLOAD_BASE +
382cd66a44SRohit Mathew NRD_REMOTE_CHIP_MEM_OFFSET(1),
394ced5956SRohit Mathew .db_reg_addr = PLAT_CSS_MHU_BASE
402cd66a44SRohit Mathew + NRD_REMOTE_CHIP_MEM_OFFSET(1) + SENDER_REG_SET(0),
414ced5956SRohit Mathew .db_preserve_mask = 0xfffffffe,
424ced5956SRohit Mathew .db_modify_mask = 0x1,
434ced5956SRohit Mathew .ring_doorbell = &mhuv2_ring_doorbell,
444ced5956SRohit Mathew },
454ced5956SRohit Mathew #endif
46a1e6467bSRohit Mathew #if (NRD_CHIP_COUNT > 2)
474ced5956SRohit Mathew {
484ced5956SRohit Mathew .scmi_mbx_mem = CSS_SCMI_PAYLOAD_BASE +
492cd66a44SRohit Mathew NRD_REMOTE_CHIP_MEM_OFFSET(2),
504ced5956SRohit Mathew .db_reg_addr = PLAT_CSS_MHU_BASE +
512cd66a44SRohit Mathew NRD_REMOTE_CHIP_MEM_OFFSET(2) + SENDER_REG_SET(0),
524ced5956SRohit Mathew .db_preserve_mask = 0xfffffffe,
534ced5956SRohit Mathew .db_modify_mask = 0x1,
544ced5956SRohit Mathew .ring_doorbell = &mhuv2_ring_doorbell,
554ced5956SRohit Mathew },
564ced5956SRohit Mathew #endif
57a1e6467bSRohit Mathew #if (NRD_CHIP_COUNT > 3)
584ced5956SRohit Mathew {
594ced5956SRohit Mathew .scmi_mbx_mem = CSS_SCMI_PAYLOAD_BASE +
602cd66a44SRohit Mathew NRD_REMOTE_CHIP_MEM_OFFSET(3),
614ced5956SRohit Mathew .db_reg_addr = PLAT_CSS_MHU_BASE +
622cd66a44SRohit Mathew NRD_REMOTE_CHIP_MEM_OFFSET(3) + SENDER_REG_SET(0),
634ced5956SRohit Mathew .db_preserve_mask = 0xfffffffe,
644ced5956SRohit Mathew .db_modify_mask = 0x1,
654ced5956SRohit Mathew .ring_doorbell = &mhuv2_ring_doorbell,
664ced5956SRohit Mathew },
674ced5956SRohit Mathew #endif
684ced5956SRohit Mathew };
694ced5956SRohit Mathew
7046d474fcSShriram K static scmi_channel_plat_info_t plat3_rd_scmi_info[] = {
7146d474fcSShriram K {
7246d474fcSShriram K .scmi_mbx_mem = CSS_SCMI_PAYLOAD_BASE,
7346d474fcSShriram K .db_reg_addr = PLAT_CSS_MHU_BASE + MHU_V3_SENDER_REG_SET(0),
7446d474fcSShriram K .db_preserve_mask = 0xfffffffe,
7546d474fcSShriram K .db_modify_mask = 0x1,
7646d474fcSShriram K .ring_doorbell = &mhu_ring_doorbell,
7746d474fcSShriram K },
7847348b1cSRohit Mathew #if (NRD_CHIP_COUNT > 1)
7947348b1cSRohit Mathew {
8047348b1cSRohit Mathew .scmi_mbx_mem = CSS_SCMI_PAYLOAD_BASE +
8147348b1cSRohit Mathew NRD_REMOTE_CHIP_MEM_OFFSET(1),
8247348b1cSRohit Mathew .db_reg_addr = PLAT_CSS_MHU_BASE +
8347348b1cSRohit Mathew NRD_REMOTE_CHIP_MEM_OFFSET(1) +
8447348b1cSRohit Mathew MHU_V3_SENDER_REG_SET(0),
8547348b1cSRohit Mathew .db_preserve_mask = 0xfffffffe,
8647348b1cSRohit Mathew .db_modify_mask = 0x1,
8747348b1cSRohit Mathew .ring_doorbell = &mhu_ring_doorbell,
8847348b1cSRohit Mathew },
8947348b1cSRohit Mathew #endif
9047348b1cSRohit Mathew #if (NRD_CHIP_COUNT > 2)
9147348b1cSRohit Mathew {
9247348b1cSRohit Mathew .scmi_mbx_mem = CSS_SCMI_PAYLOAD_BASE +
9347348b1cSRohit Mathew NRD_REMOTE_CHIP_MEM_OFFSET(2),
9447348b1cSRohit Mathew .db_reg_addr = PLAT_CSS_MHU_BASE +
9547348b1cSRohit Mathew NRD_REMOTE_CHIP_MEM_OFFSET(2) +
9647348b1cSRohit Mathew MHU_V3_SENDER_REG_SET(0),
9747348b1cSRohit Mathew .db_preserve_mask = 0xfffffffe,
9847348b1cSRohit Mathew .db_modify_mask = 0x1,
9947348b1cSRohit Mathew .ring_doorbell = &mhu_ring_doorbell,
10047348b1cSRohit Mathew },
10147348b1cSRohit Mathew #endif
10247348b1cSRohit Mathew #if (NRD_CHIP_COUNT > 3)
10347348b1cSRohit Mathew {
10447348b1cSRohit Mathew .scmi_mbx_mem = CSS_SCMI_PAYLOAD_BASE +
10547348b1cSRohit Mathew NRD_REMOTE_CHIP_MEM_OFFSET(3),
10647348b1cSRohit Mathew .db_reg_addr = PLAT_CSS_MHU_BASE +
10747348b1cSRohit Mathew NRD_REMOTE_CHIP_MEM_OFFSET(3) +
10847348b1cSRohit Mathew MHU_V3_SENDER_REG_SET(0),
10947348b1cSRohit Mathew .db_preserve_mask = 0xfffffffe,
11047348b1cSRohit Mathew .db_modify_mask = 0x1,
11147348b1cSRohit Mathew .ring_doorbell = &mhu_ring_doorbell,
11247348b1cSRohit Mathew },
11347348b1cSRohit Mathew #endif
11446d474fcSShriram K };
11546d474fcSShriram K
plat_css_get_scmi_info(unsigned int channel_id)1164ced5956SRohit Mathew scmi_channel_plat_info_t *plat_css_get_scmi_info(unsigned int channel_id)
1174ced5956SRohit Mathew {
118afb30755SRohit Mathew if (nrd_plat_info.platform_id == RD_N2_SID_VER_PART_NUM ||
11940ea4208SRohit Mathew nrd_plat_info.platform_id == RD_V2_SID_VER_PART_NUM ||
12040ea4208SRohit Mathew nrd_plat_info.platform_id == RD_N2_CFG1_SID_VER_PART_NUM ||
12140ea4208SRohit Mathew nrd_plat_info.platform_id == RD_N2_CFG3_SID_VER_PART_NUM) {
1224ced5956SRohit Mathew if (channel_id >= ARRAY_SIZE(plat_rd_scmi_info)) {
1234ced5956SRohit Mathew panic();
1244ced5956SRohit Mathew }
1254ced5956SRohit Mathew return &plat_rd_scmi_info[channel_id];
126137ab5cbSJerry Wang } else if (nrd_plat_info.platform_id == RD_V3_SID_VER_PART_NUM ||
127137ab5cbSJerry Wang nrd_plat_info.platform_id == RD_V3_CFG1_SID_VER_PART_NUM ||
128137ab5cbSJerry Wang nrd_plat_info.platform_id == RD_V3_CFG2_SID_VER_PART_NUM) {
12946d474fcSShriram K if (channel_id >= ARRAY_SIZE(plat3_rd_scmi_info)) {
13046d474fcSShriram K panic();
13146d474fcSShriram K }
13246d474fcSShriram K return &plat3_rd_scmi_info[channel_id];
1334ced5956SRohit Mathew } else {
1344ced5956SRohit Mathew panic();
1354ced5956SRohit Mathew }
1364ced5956SRohit Mathew }
1374ced5956SRohit Mathew
bl31_early_platform_setup2(u_register_t arg0,u_register_t arg1,u_register_t arg2,u_register_t arg3)1384ced5956SRohit Mathew void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
1394ced5956SRohit Mathew u_register_t arg2, u_register_t arg3)
1404ced5956SRohit Mathew {
141*47fca89dSChris Kay /* Initialize the console to provide early debug support */
142*47fca89dSChris Kay arm_console_boot_init();
143*47fca89dSChris Kay
14440ea4208SRohit Mathew nrd_plat_info.platform_id = plat_arm_nrd_get_platform_id();
14540ea4208SRohit Mathew nrd_plat_info.config_id = plat_arm_nrd_get_config_id();
14640ea4208SRohit Mathew nrd_plat_info.multi_chip_mode = plat_arm_nrd_get_multi_chip_mode();
1474ced5956SRohit Mathew
14894a4383aSLokesh B V #if RESET_TO_BL31
14994a4383aSLokesh B V #if (ARM_ARCH_MAJOR > 7) || defined(ARMV7_SUPPORTS_GENERIC_TIMER)
15094a4383aSLokesh B V /* Set the counter frequency for the generic timer */
15194a4383aSLokesh B V write_cntfrq_el0(plat_get_syscnt_freq2());
15294a4383aSLokesh B V #endif
15394a4383aSLokesh B V #endif /* RESET_TO_BL31 */
15494a4383aSLokesh B V
15564ff172aSSammit Joshi /* Initialize generic timer */
15664ff172aSSammit Joshi generic_delay_timer_init();
15764ff172aSSammit Joshi
15837cc7fa5SNishant Sharma #if SPMD_SPM_AT_SEL2 && !RESET_TO_BL31
15937cc7fa5SNishant Sharma INFO("BL31 FCONF: FW_CONFIG address = 0x%lx\n", (uintptr_t)arg1);
16037cc7fa5SNishant Sharma /* Initialize BL31's copy of the DTB registry because SPMD needs the
16137cc7fa5SNishant Sharma * TOS_FW_CONFIG's addresses to make a copy.
16237cc7fa5SNishant Sharma */
16337cc7fa5SNishant Sharma fconf_populate("FW_CONFIG", arg1);
16437cc7fa5SNishant Sharma
16537cc7fa5SNishant Sharma /* arg1 is supposed to point to SOC_FW_CONFIG */
16637cc7fa5SNishant Sharma const struct dyn_cfg_dtb_info_t *soc_fw_config_info;
16737cc7fa5SNishant Sharma
16837cc7fa5SNishant Sharma soc_fw_config_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, SOC_FW_CONFIG_ID);
16937cc7fa5SNishant Sharma if (soc_fw_config_info != NULL) {
17037cc7fa5SNishant Sharma arg1 = soc_fw_config_info->config_addr;
17137cc7fa5SNishant Sharma }
17237cc7fa5SNishant Sharma #endif /* SPMD_SPM_AT_SEL2 && !RESET_TO_BL31 */
173b6e6e2e6SJayanth Dodderi Chidanand arm_bl31_early_platform_setup(arg0, arg1, arg2, arg3);
1744ced5956SRohit Mathew }
1754ced5956SRohit Mathew
176c6b27c49SRakshit Goyal /*******************************************************************************
177c6b27c49SRakshit Goyal * This function inserts platform information via device tree nodes as,
178c6b27c49SRakshit Goyal * system-id {
179c6b27c49SRakshit Goyal * platform-id = <0>;
180c6b27c49SRakshit Goyal * config-id = <0>;
181c6b27c49SRakshit Goyal * }
182c6b27c49SRakshit Goyal ******************************************************************************/
183c6b27c49SRakshit Goyal #if RESET_TO_BL31
append_config_node(uintptr_t fdt_base_addr,uintptr_t fdt_base_size)184c6b27c49SRakshit Goyal static int append_config_node(uintptr_t fdt_base_addr, uintptr_t fdt_base_size)
185c6b27c49SRakshit Goyal {
186c6b27c49SRakshit Goyal void *fdt;
187c6b27c49SRakshit Goyal int nodeoffset, err;
188c6b27c49SRakshit Goyal unsigned int platid = 0, platcfg = 0;
189c6b27c49SRakshit Goyal
190c6b27c49SRakshit Goyal if (fdt_base_addr == 0) {
191c6b27c49SRakshit Goyal ERROR("NT_FW CONFIG base address is NULL\n");
192c6b27c49SRakshit Goyal return -1;
193c6b27c49SRakshit Goyal }
194c6b27c49SRakshit Goyal
195c6b27c49SRakshit Goyal fdt = (void *)fdt_base_addr;
196c6b27c49SRakshit Goyal
197c6b27c49SRakshit Goyal /* Check the validity of the fdt */
198c6b27c49SRakshit Goyal if (fdt_check_header(fdt) != 0) {
199c6b27c49SRakshit Goyal ERROR("Invalid NT_FW_CONFIG DTB passed\n");
200c6b27c49SRakshit Goyal return -1;
201c6b27c49SRakshit Goyal }
202c6b27c49SRakshit Goyal
203c6b27c49SRakshit Goyal nodeoffset = fdt_subnode_offset(fdt, 0, "system-id");
204c6b27c49SRakshit Goyal if (nodeoffset < 0) {
205c6b27c49SRakshit Goyal ERROR("Failed to get system-id node offset\n");
206c6b27c49SRakshit Goyal return -1;
207c6b27c49SRakshit Goyal }
208c6b27c49SRakshit Goyal
209c6b27c49SRakshit Goyal platid = plat_arm_nrd_get_platform_id();
210c6b27c49SRakshit Goyal err = fdt_setprop_u32(fdt, nodeoffset, "platform-id", platid);
211c6b27c49SRakshit Goyal if (err < 0) {
212c6b27c49SRakshit Goyal ERROR("Failed to set platform-id\n");
213c6b27c49SRakshit Goyal return -1;
214c6b27c49SRakshit Goyal }
215c6b27c49SRakshit Goyal
216c6b27c49SRakshit Goyal platcfg = plat_arm_nrd_get_config_id();
217c6b27c49SRakshit Goyal err = fdt_setprop_u32(fdt, nodeoffset, "config-id", platcfg);
218c6b27c49SRakshit Goyal if (err < 0) {
219c6b27c49SRakshit Goyal ERROR("Failed to set config-id\n");
220c6b27c49SRakshit Goyal return -1;
221c6b27c49SRakshit Goyal }
222c6b27c49SRakshit Goyal
223c6b27c49SRakshit Goyal platcfg = plat_arm_nrd_get_multi_chip_mode();
224c6b27c49SRakshit Goyal err = fdt_setprop_u32(fdt, nodeoffset, "multi-chip-mode", platcfg);
225c6b27c49SRakshit Goyal if (err < 0) {
226c6b27c49SRakshit Goyal ERROR("Failed to set multi-chip-mode\n");
227c6b27c49SRakshit Goyal return -1;
228c6b27c49SRakshit Goyal }
229c6b27c49SRakshit Goyal
230c6b27c49SRakshit Goyal flush_dcache_range((uintptr_t)fdt, fdt_base_size);
231c6b27c49SRakshit Goyal return 0;
232c6b27c49SRakshit Goyal }
233c6b27c49SRakshit Goyal #endif
234c6b27c49SRakshit Goyal
nrd_bl31_common_platform_setup(void)23540ea4208SRohit Mathew void nrd_bl31_common_platform_setup(void)
2364ced5956SRohit Mathew {
2374ced5956SRohit Mathew
2384ced5956SRohit Mathew arm_bl31_platform_setup();
2394ced5956SRohit Mathew
2404ced5956SRohit Mathew /* Configure the warm reboot SGI for primary core */
2414ced5956SRohit Mathew css_setup_cpu_pwr_down_intr();
2424ced5956SRohit Mathew
2434ced5956SRohit Mathew #if CSS_SYSTEM_GRACEFUL_RESET
2444ced5956SRohit Mathew /* Register priority level handlers for reboot */
2454ced5956SRohit Mathew ehf_register_priority_handler(PLAT_REBOOT_PRI,
2464ced5956SRohit Mathew css_reboot_interrupt_handler);
2474ced5956SRohit Mathew #endif
248c6b27c49SRakshit Goyal
249c6b27c49SRakshit Goyal #if RESET_TO_BL31
250c6b27c49SRakshit Goyal int ret = append_config_node(NRD_CSS_BL31_PRELOAD_DTB_BASE,
251c6b27c49SRakshit Goyal NRD_CSS_BL31_PRELOAD_DTB_SIZE);
252c6b27c49SRakshit Goyal
253c6b27c49SRakshit Goyal if (ret != 0) {
254c6b27c49SRakshit Goyal panic();
255c6b27c49SRakshit Goyal }
256c6b27c49SRakshit Goyal #endif
2574ced5956SRohit Mathew }
2584ced5956SRohit Mathew
plat_arm_psci_override_pm_ops(plat_psci_ops_t * ops)2594ced5956SRohit Mathew const plat_psci_ops_t *plat_arm_psci_override_pm_ops(plat_psci_ops_t *ops)
2604ced5956SRohit Mathew {
2614ced5956SRohit Mathew return css_scmi_override_pm_ops(ops);
2624ced5956SRohit Mathew }
263