nrd_image_load.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Copyright (c) 2018-2024, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <libfdt.h>
  7. #include <arch_helpers.h>
  8. #include <common/debug.h>
  9. #include <common/desc_image_load.h>
  10. #include <drivers/arm/css/sds.h>
  11. #include <plat/arm/common/plat_arm.h>
  12. #include <plat/common/platform.h>
  13. #include <platform_def.h>
  14. #include <nrd_variant.h>
  15. /*
  16. * Information about the isolated CPUs obtained from SDS.
  17. */
  18. struct isolated_cpu_mpid_list {
  19. uint64_t num_entries; /* Number of entries in the list */
  20. uint64_t mpid_list[PLATFORM_CORE_COUNT]; /* List of isolated CPU MPIDs */
  21. };
  22. /* Function to read isolated CPU MPID list from SDS. */
  23. void plat_arm_nrd_get_isolated_cpu_list(struct isolated_cpu_mpid_list *list)
  24. {
  25. int ret;
  26. ret = sds_init(SDS_SCP_AP_REGION_ID);
  27. if (ret != SDS_OK) {
  28. ERROR("SDS initialization failed, error: %d\n", ret);
  29. panic();
  30. }
  31. ret = sds_struct_read(SDS_SCP_AP_REGION_ID,
  32. SDS_ISOLATED_CPU_LIST_ID, 0, &list->num_entries,
  33. sizeof(list->num_entries), SDS_ACCESS_MODE_CACHED);
  34. if (ret != SDS_OK) {
  35. INFO("SDS CPU num elements read failed, error: %d\n", ret);
  36. list->num_entries = 0;
  37. return;
  38. }
  39. if (list->num_entries > PLATFORM_CORE_COUNT) {
  40. ERROR("Isolated CPU list count %ld greater than max"
  41. " number supported %d\n",
  42. list->num_entries, PLATFORM_CORE_COUNT);
  43. panic();
  44. } else if (list->num_entries == 0) {
  45. INFO("SDS isolated CPU list is empty\n");
  46. return;
  47. }
  48. ret = sds_struct_read(SDS_SCP_AP_REGION_ID,
  49. SDS_ISOLATED_CPU_LIST_ID,
  50. sizeof(list->num_entries),
  51. &list->mpid_list,
  52. sizeof(list->mpid_list[0]) * list->num_entries,
  53. SDS_ACCESS_MODE_CACHED);
  54. if (ret != SDS_OK) {
  55. ERROR("SDS CPU list read failed. error: %d\n", ret);
  56. panic();
  57. }
  58. }
  59. /*******************************************************************************
  60. * This function inserts Platform information via device tree nodes as,
  61. * system-id {
  62. * platform-id = <0>;
  63. * config-id = <0>;
  64. * isolated-cpu-list = <0>
  65. * }
  66. ******************************************************************************/
  67. static int plat_nrd_append_config_node(void)
  68. {
  69. bl_mem_params_node_t *mem_params;
  70. void *fdt;
  71. int nodeoffset, err;
  72. unsigned int platid = 0, platcfg = 0;
  73. struct isolated_cpu_mpid_list cpu_mpid_list = {0};
  74. mem_params = get_bl_mem_params_node(NT_FW_CONFIG_ID);
  75. if (mem_params == NULL) {
  76. ERROR("NT_FW CONFIG base address is NULL");
  77. return -1;
  78. }
  79. fdt = (void *)(mem_params->image_info.image_base);
  80. /* Check the validity of the fdt */
  81. if (fdt_check_header(fdt) != 0) {
  82. ERROR("Invalid NT_FW_CONFIG DTB passed\n");
  83. return -1;
  84. }
  85. nodeoffset = fdt_subnode_offset(fdt, 0, "system-id");
  86. if (nodeoffset < 0) {
  87. ERROR("Failed to get system-id node offset\n");
  88. return -1;
  89. }
  90. platid = plat_arm_nrd_get_platform_id();
  91. err = fdt_setprop_u32(fdt, nodeoffset, "platform-id", platid);
  92. if (err < 0) {
  93. ERROR("Failed to set platform-id\n");
  94. return -1;
  95. }
  96. platcfg = plat_arm_nrd_get_config_id();
  97. err = fdt_setprop_u32(fdt, nodeoffset, "config-id", platcfg);
  98. if (err < 0) {
  99. ERROR("Failed to set config-id\n");
  100. return -1;
  101. }
  102. platcfg = plat_arm_nrd_get_multi_chip_mode();
  103. err = fdt_setprop_u32(fdt, nodeoffset, "multi-chip-mode", platcfg);
  104. if (err < 0) {
  105. ERROR("Failed to set multi-chip-mode\n");
  106. return -1;
  107. }
  108. plat_arm_nrd_get_isolated_cpu_list(&cpu_mpid_list);
  109. if (cpu_mpid_list.num_entries > 0) {
  110. err = fdt_setprop(fdt, nodeoffset, "isolated-cpu-list",
  111. &cpu_mpid_list,
  112. (sizeof(cpu_mpid_list.num_entries) *
  113. (cpu_mpid_list.num_entries + 1)));
  114. if (err < 0) {
  115. ERROR("Failed to set isolated-cpu-list, error: %d\n",
  116. err);
  117. }
  118. }
  119. flush_dcache_range((uintptr_t)fdt, mem_params->image_info.image_size);
  120. return 0;
  121. }
  122. /*******************************************************************************
  123. * This function returns the list of executable images.
  124. ******************************************************************************/
  125. bl_params_t *plat_get_next_bl_params(void)
  126. {
  127. int ret;
  128. ret = plat_nrd_append_config_node();
  129. if (ret != 0)
  130. panic();
  131. return arm_get_next_bl_params();
  132. }