morello_image_load.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * Copyright (c) 2021-2024, Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <arch_helpers.h>
  7. #include <common/build_message.h>
  8. #include <common/debug.h>
  9. #include <common/desc_image_load.h>
  10. #include <drivers/arm/css/sds.h>
  11. #include <libfdt.h>
  12. #include "morello_def.h"
  13. #include <plat/arm/common/plat_arm.h>
  14. #include <plat/common/platform.h>
  15. #include <platform_def.h>
  16. /* In client mode, a part of the DDR memory is reserved for Tag bits.
  17. * Calculate the usable memory size after subtracting the Tag memory.
  18. */
  19. static inline uint64_t get_mem_client_mode(uint64_t size)
  20. {
  21. return (size - (size / 128ULL));
  22. }
  23. /*******************************************************************************
  24. * This function inserts Platform information and firmware versions
  25. * via device tree nodes as,
  26. * platform-info {
  27. * local-ddr-size = <0x0 0x0>;
  28. *#ifdef TARGET_PLATFORM_SOC
  29. * remote-ddr-size = <0x0 0x0>;
  30. * remote-chip-count = <0x0>;
  31. * multichip-mode = <0x0>;
  32. * scc-config = <0x0>;
  33. *#endif
  34. * };
  35. * firmware-version {
  36. *#ifdef TARGET_PLATFORM_SOC
  37. * mcc-fw-version = <0x0>;
  38. * pcc-fw-version = <0x0>;
  39. *#endif
  40. * scp-fw-version = <0x0>;
  41. * scp-fw-commit = <0x0>;
  42. * tfa-fw-version = "unknown-dirty_00000000";
  43. * };
  44. ******************************************************************************/
  45. static int plat_morello_append_config_node(struct morello_plat_info *plat_info,
  46. struct morello_firmware_version *fw_version)
  47. {
  48. bl_mem_params_node_t *mem_params;
  49. void *fdt;
  50. int nodeoffset_plat, nodeoffset_fw, err;
  51. uint64_t usable_mem_size;
  52. usable_mem_size = plat_info->local_ddr_size;
  53. mem_params = get_bl_mem_params_node(NT_FW_CONFIG_ID);
  54. if (mem_params == NULL) {
  55. ERROR("NT_FW CONFIG base address is NULL\n");
  56. return -1;
  57. }
  58. fdt = (void *)(mem_params->image_info.image_base);
  59. /* Check the validity of the fdt */
  60. if (fdt_check_header(fdt) != 0) {
  61. ERROR("Invalid NT_FW_CONFIG DTB passed\n");
  62. return -1;
  63. }
  64. nodeoffset_plat = fdt_subnode_offset(fdt, 0, "platform-info");
  65. if (nodeoffset_plat < 0) {
  66. ERROR("NT_FW_CONFIG: Failed to get platform-info node offset\n");
  67. return -1;
  68. }
  69. nodeoffset_fw = fdt_subnode_offset(fdt, 0, "firmware-version");
  70. if (nodeoffset_fw < 0) {
  71. ERROR("NT_FW_CONFIG: Failed to get firmware-version node offset\n");
  72. return -1;
  73. }
  74. #ifdef TARGET_PLATFORM_SOC
  75. err = fdt_setprop_u64(fdt, nodeoffset_plat, "remote-ddr-size",
  76. plat_info->remote_ddr_size);
  77. if (err < 0) {
  78. ERROR("NT_FW_CONFIG: Failed to set remote-ddr-size\n");
  79. return -1;
  80. }
  81. err = fdt_setprop_u32(fdt, nodeoffset_plat, "remote-chip-count",
  82. plat_info->remote_chip_count);
  83. if (err < 0) {
  84. ERROR("NT_FW_CONFIG: Failed to set remote-chip-count\n");
  85. return -1;
  86. }
  87. err = fdt_setprop_u32(fdt, nodeoffset_plat, "multichip-mode",
  88. plat_info->multichip_mode);
  89. if (err < 0) {
  90. ERROR("NT_FW_CONFIG: Failed to set multichip-mode\n");
  91. return -1;
  92. }
  93. err = fdt_setprop_u32(fdt, nodeoffset_plat, "scc-config",
  94. plat_info->scc_config);
  95. if (err < 0) {
  96. ERROR("NT_FW_CONFIG: Failed to set scc-config\n");
  97. return -1;
  98. }
  99. if (plat_info->scc_config & MORELLO_SCC_CLIENT_MODE_MASK) {
  100. usable_mem_size = get_mem_client_mode(plat_info->local_ddr_size);
  101. }
  102. err = fdt_setprop_u32(fdt, nodeoffset_fw, "mcc-fw-version",
  103. fw_version->mcc_fw_ver);
  104. if (err < 0) {
  105. ERROR("NT_FW_CONFIG: Failed to set mcc-fw-version\n");
  106. return -1;
  107. }
  108. err = fdt_setprop_u32(fdt, nodeoffset_fw, "pcc-fw-version",
  109. fw_version->pcc_fw_ver);
  110. if (err < 0) {
  111. ERROR("NT_FW_CONFIG: Failed to set pcc-fw-version\n");
  112. return -1;
  113. }
  114. #endif
  115. err = fdt_setprop_u32(fdt, nodeoffset_fw, "scp-fw-version",
  116. fw_version->scp_fw_ver);
  117. if (err < 0) {
  118. ERROR("NT_FW_CONFIG: Failed to set scp-fw-version\n");
  119. return -1;
  120. }
  121. err = fdt_setprop_u32(fdt, nodeoffset_fw, "scp-fw-commit",
  122. fw_version->scp_fw_commit);
  123. if (err < 0) {
  124. ERROR("NT_FW_CONFIG: Failed to set scp-fw-commit\n");
  125. return -1;
  126. }
  127. err = fdt_setprop_string(fdt, nodeoffset_fw, "tfa-fw-version", build_version_string);
  128. if (err < 0) {
  129. WARN("NT_FW_CONFIG: Unable to set tfa-fw-version\n");
  130. }
  131. err = fdt_setprop_u64(fdt, nodeoffset_plat, "local-ddr-size",
  132. usable_mem_size);
  133. if (err < 0) {
  134. ERROR("NT_FW_CONFIG: Failed to set local-ddr-size\n");
  135. return -1;
  136. }
  137. flush_dcache_range((uintptr_t)fdt, mem_params->image_info.image_size);
  138. return 0;
  139. }
  140. /*******************************************************************************
  141. * This function returns the list of executable images.
  142. ******************************************************************************/
  143. bl_params_t *plat_get_next_bl_params(void)
  144. {
  145. int ret;
  146. struct morello_plat_info plat_info;
  147. struct morello_firmware_version fw_version;
  148. ret = sds_init(SDS_SCP_AP_REGION_ID);
  149. if (ret != SDS_OK) {
  150. ERROR("SDS initialization failed. ret:%d\n", ret);
  151. panic();
  152. }
  153. ret = sds_struct_read(SDS_SCP_AP_REGION_ID,
  154. MORELLO_SDS_PLATFORM_INFO_STRUCT_ID,
  155. MORELLO_SDS_PLATFORM_INFO_OFFSET,
  156. &plat_info,
  157. MORELLO_SDS_PLATFORM_INFO_SIZE,
  158. SDS_ACCESS_MODE_NON_CACHED);
  159. if (ret != SDS_OK) {
  160. ERROR("Error getting platform info from SDS. ret:%d\n", ret);
  161. panic();
  162. }
  163. ret = sds_struct_read(SDS_SCP_AP_REGION_ID,
  164. MORELLO_SDS_FIRMWARE_VERSION_STRUCT_ID,
  165. MORELLO_SDS_FIRMWARE_VERSION_OFFSET,
  166. &fw_version,
  167. MORELLO_SDS_FIRMWARE_VERSION_SIZE,
  168. SDS_ACCESS_MODE_NON_CACHED);
  169. if (ret != SDS_OK) {
  170. ERROR("Error getting firmware version from SDS. ret:%d\n", ret);
  171. panic();
  172. }
  173. /* Validate plat_info SDS */
  174. #ifdef TARGET_PLATFORM_FVP
  175. if (plat_info.local_ddr_size == 0U) {
  176. #else
  177. if ((plat_info.local_ddr_size == 0U)
  178. || (plat_info.local_ddr_size > MORELLO_MAX_DDR_CAPACITY)
  179. || (plat_info.remote_ddr_size > MORELLO_MAX_DDR_CAPACITY)
  180. || (plat_info.remote_chip_count > MORELLO_MAX_REMOTE_CHIP_COUNT)
  181. ){
  182. #endif
  183. ERROR("platform info SDS is corrupted\n");
  184. panic();
  185. }
  186. ret = plat_morello_append_config_node(&plat_info, &fw_version);
  187. if (ret != 0) {
  188. panic();
  189. }
  190. return arm_get_next_bl_params();
  191. }