nrd_bl31_setup.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*
  2. * Copyright (c) 2018-2024, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <libfdt.h>
  8. #include <common/bl_common.h>
  9. #include <common/debug.h>
  10. #include <drivers/arm/css/css_mhu_doorbell.h>
  11. #include <drivers/arm/css/scmi.h>
  12. #include <drivers/generic_delay_timer.h>
  13. #include <plat/arm/common/plat_arm.h>
  14. #include <plat/arm/css/common/css_pm.h>
  15. #include <plat/common/platform.h>
  16. #include <nrd_ras.h>
  17. #include <nrd_variant.h>
  18. nrd_platform_info_t nrd_plat_info;
  19. static scmi_channel_plat_info_t sgi575_scmi_plat_info = {
  20. .scmi_mbx_mem = CSS_SCMI_PAYLOAD_BASE,
  21. .db_reg_addr = PLAT_CSS_MHU_BASE + CSS_SCMI_MHU_DB_REG_OFF,
  22. .db_preserve_mask = 0xfffffffe,
  23. .db_modify_mask = 0x1,
  24. .ring_doorbell = &mhu_ring_doorbell,
  25. };
  26. static scmi_channel_plat_info_t plat_rd_scmi_info[] = {
  27. {
  28. .scmi_mbx_mem = CSS_SCMI_PAYLOAD_BASE,
  29. .db_reg_addr = PLAT_CSS_MHU_BASE + SENDER_REG_SET(0),
  30. .db_preserve_mask = 0xfffffffe,
  31. .db_modify_mask = 0x1,
  32. .ring_doorbell = &mhuv2_ring_doorbell,
  33. },
  34. #if (NRD_CHIP_COUNT > 1)
  35. {
  36. .scmi_mbx_mem = CSS_SCMI_PAYLOAD_BASE +
  37. NRD_REMOTE_CHIP_MEM_OFFSET(1),
  38. .db_reg_addr = PLAT_CSS_MHU_BASE
  39. + NRD_REMOTE_CHIP_MEM_OFFSET(1) + SENDER_REG_SET(0),
  40. .db_preserve_mask = 0xfffffffe,
  41. .db_modify_mask = 0x1,
  42. .ring_doorbell = &mhuv2_ring_doorbell,
  43. },
  44. #endif
  45. #if (NRD_CHIP_COUNT > 2)
  46. {
  47. .scmi_mbx_mem = CSS_SCMI_PAYLOAD_BASE +
  48. NRD_REMOTE_CHIP_MEM_OFFSET(2),
  49. .db_reg_addr = PLAT_CSS_MHU_BASE +
  50. NRD_REMOTE_CHIP_MEM_OFFSET(2) + SENDER_REG_SET(0),
  51. .db_preserve_mask = 0xfffffffe,
  52. .db_modify_mask = 0x1,
  53. .ring_doorbell = &mhuv2_ring_doorbell,
  54. },
  55. #endif
  56. #if (NRD_CHIP_COUNT > 3)
  57. {
  58. .scmi_mbx_mem = CSS_SCMI_PAYLOAD_BASE +
  59. NRD_REMOTE_CHIP_MEM_OFFSET(3),
  60. .db_reg_addr = PLAT_CSS_MHU_BASE +
  61. NRD_REMOTE_CHIP_MEM_OFFSET(3) + SENDER_REG_SET(0),
  62. .db_preserve_mask = 0xfffffffe,
  63. .db_modify_mask = 0x1,
  64. .ring_doorbell = &mhuv2_ring_doorbell,
  65. },
  66. #endif
  67. };
  68. static scmi_channel_plat_info_t plat3_rd_scmi_info[] = {
  69. {
  70. .scmi_mbx_mem = CSS_SCMI_PAYLOAD_BASE,
  71. .db_reg_addr = PLAT_CSS_MHU_BASE + MHU_V3_SENDER_REG_SET(0),
  72. .db_preserve_mask = 0xfffffffe,
  73. .db_modify_mask = 0x1,
  74. .ring_doorbell = &mhu_ring_doorbell,
  75. },
  76. #if (NRD_CHIP_COUNT > 1)
  77. {
  78. .scmi_mbx_mem = CSS_SCMI_PAYLOAD_BASE +
  79. NRD_REMOTE_CHIP_MEM_OFFSET(1),
  80. .db_reg_addr = PLAT_CSS_MHU_BASE +
  81. NRD_REMOTE_CHIP_MEM_OFFSET(1) +
  82. MHU_V3_SENDER_REG_SET(0),
  83. .db_preserve_mask = 0xfffffffe,
  84. .db_modify_mask = 0x1,
  85. .ring_doorbell = &mhu_ring_doorbell,
  86. },
  87. #endif
  88. #if (NRD_CHIP_COUNT > 2)
  89. {
  90. .scmi_mbx_mem = CSS_SCMI_PAYLOAD_BASE +
  91. NRD_REMOTE_CHIP_MEM_OFFSET(2),
  92. .db_reg_addr = PLAT_CSS_MHU_BASE +
  93. NRD_REMOTE_CHIP_MEM_OFFSET(2) +
  94. MHU_V3_SENDER_REG_SET(0),
  95. .db_preserve_mask = 0xfffffffe,
  96. .db_modify_mask = 0x1,
  97. .ring_doorbell = &mhu_ring_doorbell,
  98. },
  99. #endif
  100. #if (NRD_CHIP_COUNT > 3)
  101. {
  102. .scmi_mbx_mem = CSS_SCMI_PAYLOAD_BASE +
  103. NRD_REMOTE_CHIP_MEM_OFFSET(3),
  104. .db_reg_addr = PLAT_CSS_MHU_BASE +
  105. NRD_REMOTE_CHIP_MEM_OFFSET(3) +
  106. MHU_V3_SENDER_REG_SET(0),
  107. .db_preserve_mask = 0xfffffffe,
  108. .db_modify_mask = 0x1,
  109. .ring_doorbell = &mhu_ring_doorbell,
  110. },
  111. #endif
  112. };
  113. scmi_channel_plat_info_t *plat_css_get_scmi_info(unsigned int channel_id)
  114. {
  115. if (nrd_plat_info.platform_id == RD_N1E1_EDGE_SID_VER_PART_NUM ||
  116. nrd_plat_info.platform_id == RD_V1_SID_VER_PART_NUM ||
  117. nrd_plat_info.platform_id == RD_N2_SID_VER_PART_NUM ||
  118. nrd_plat_info.platform_id == RD_V2_SID_VER_PART_NUM ||
  119. nrd_plat_info.platform_id == RD_N2_CFG1_SID_VER_PART_NUM ||
  120. nrd_plat_info.platform_id == RD_N2_CFG3_SID_VER_PART_NUM) {
  121. if (channel_id >= ARRAY_SIZE(plat_rd_scmi_info)) {
  122. panic();
  123. }
  124. return &plat_rd_scmi_info[channel_id];
  125. } else if (nrd_plat_info.platform_id == RD_V3_SID_VER_PART_NUM ||
  126. nrd_plat_info.platform_id == RD_V3_CFG1_SID_VER_PART_NUM ||
  127. nrd_plat_info.platform_id == RD_V3_CFG2_SID_VER_PART_NUM) {
  128. if (channel_id >= ARRAY_SIZE(plat3_rd_scmi_info)) {
  129. panic();
  130. }
  131. return &plat3_rd_scmi_info[channel_id];
  132. } else if (nrd_plat_info.platform_id == SGI575_SSC_VER_PART_NUM) {
  133. return &sgi575_scmi_plat_info;
  134. } else {
  135. panic();
  136. }
  137. }
  138. void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
  139. u_register_t arg2, u_register_t arg3)
  140. {
  141. nrd_plat_info.platform_id = plat_arm_nrd_get_platform_id();
  142. nrd_plat_info.config_id = plat_arm_nrd_get_config_id();
  143. nrd_plat_info.multi_chip_mode = plat_arm_nrd_get_multi_chip_mode();
  144. arm_bl31_early_platform_setup((void *)arg0, arg1, arg2, (void *)arg3);
  145. }
  146. /*******************************************************************************
  147. * This function inserts platform information via device tree nodes as,
  148. * system-id {
  149. * platform-id = <0>;
  150. * config-id = <0>;
  151. * }
  152. ******************************************************************************/
  153. #if RESET_TO_BL31
  154. static int append_config_node(uintptr_t fdt_base_addr, uintptr_t fdt_base_size)
  155. {
  156. void *fdt;
  157. int nodeoffset, err;
  158. unsigned int platid = 0, platcfg = 0;
  159. if (fdt_base_addr == 0) {
  160. ERROR("NT_FW CONFIG base address is NULL\n");
  161. return -1;
  162. }
  163. fdt = (void *)fdt_base_addr;
  164. /* Check the validity of the fdt */
  165. if (fdt_check_header(fdt) != 0) {
  166. ERROR("Invalid NT_FW_CONFIG DTB passed\n");
  167. return -1;
  168. }
  169. nodeoffset = fdt_subnode_offset(fdt, 0, "system-id");
  170. if (nodeoffset < 0) {
  171. ERROR("Failed to get system-id node offset\n");
  172. return -1;
  173. }
  174. platid = plat_arm_nrd_get_platform_id();
  175. err = fdt_setprop_u32(fdt, nodeoffset, "platform-id", platid);
  176. if (err < 0) {
  177. ERROR("Failed to set platform-id\n");
  178. return -1;
  179. }
  180. platcfg = plat_arm_nrd_get_config_id();
  181. err = fdt_setprop_u32(fdt, nodeoffset, "config-id", platcfg);
  182. if (err < 0) {
  183. ERROR("Failed to set config-id\n");
  184. return -1;
  185. }
  186. platcfg = plat_arm_nrd_get_multi_chip_mode();
  187. err = fdt_setprop_u32(fdt, nodeoffset, "multi-chip-mode", platcfg);
  188. if (err < 0) {
  189. ERROR("Failed to set multi-chip-mode\n");
  190. return -1;
  191. }
  192. flush_dcache_range((uintptr_t)fdt, fdt_base_size);
  193. return 0;
  194. }
  195. #endif
  196. void nrd_bl31_common_platform_setup(void)
  197. {
  198. generic_delay_timer_init();
  199. arm_bl31_platform_setup();
  200. /* Configure the warm reboot SGI for primary core */
  201. css_setup_cpu_pwr_down_intr();
  202. #if CSS_SYSTEM_GRACEFUL_RESET
  203. /* Register priority level handlers for reboot */
  204. ehf_register_priority_handler(PLAT_REBOOT_PRI,
  205. css_reboot_interrupt_handler);
  206. #endif
  207. #if RESET_TO_BL31
  208. int ret = append_config_node(NRD_CSS_BL31_PRELOAD_DTB_BASE,
  209. NRD_CSS_BL31_PRELOAD_DTB_SIZE);
  210. if (ret != 0) {
  211. panic();
  212. }
  213. #endif
  214. }
  215. const plat_psci_ops_t *plat_arm_psci_override_pm_ops(plat_psci_ops_t *ops)
  216. {
  217. /*
  218. * For RD-E1-Edge, only CPU power ON/OFF, PSCI platform callbacks are
  219. * supported.
  220. */
  221. if (((nrd_plat_info.platform_id == RD_N1E1_EDGE_SID_VER_PART_NUM) &&
  222. (nrd_plat_info.config_id == RD_E1_EDGE_CONFIG_ID))) {
  223. ops->cpu_standby = NULL;
  224. ops->system_off = NULL;
  225. ops->system_reset = NULL;
  226. ops->get_sys_suspend_power_state = NULL;
  227. ops->pwr_domain_suspend = NULL;
  228. ops->pwr_domain_suspend_finish = NULL;
  229. }
  230. return css_scmi_override_pm_ops(ops);
  231. }