arm_fconf_sp.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Copyright (c) 2020-2024, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <string.h>
  8. #include <common/debug.h>
  9. #include <common/desc_image_load.h>
  10. #include <common/fdt_wrappers.h>
  11. #include <drivers/io/io_storage.h>
  12. #include <lib/object_pool.h>
  13. #include <libfdt.h>
  14. #include <plat/arm/common/arm_fconf_getter.h>
  15. #include <plat/arm/common/arm_fconf_io_storage.h>
  16. #include <plat/arm/common/fconf_arm_sp_getter.h>
  17. #include <platform_def.h>
  18. #include <tools_share/firmware_image_package.h>
  19. #ifdef IMAGE_BL2
  20. bl_mem_params_node_t sp_mem_params_descs[MAX_SP_IDS];
  21. struct arm_sp_t arm_sp;
  22. int fconf_populate_arm_sp(uintptr_t config)
  23. {
  24. int sp_node, node, err;
  25. struct uuid uuid;
  26. unsigned int index = 0;
  27. uint32_t val32;
  28. const unsigned int sip_start = SP_PKG1_ID;
  29. unsigned int sip_index = sip_start;
  30. #if defined(ARM_COT_dualroot)
  31. const unsigned int sip_end = sip_start + MAX_SP_IDS / 2;
  32. /* Allocating index range for platform SPs */
  33. const unsigned int plat_start = SP_PKG5_ID;
  34. unsigned int plat_index = plat_start;
  35. const unsigned int plat_end = plat_start + MAX_SP_IDS / 2;
  36. bool is_plat_owned = false;
  37. #endif /* ARM_COT_dualroot */
  38. /* As libfdt use void *, we can't avoid this cast */
  39. const void *dtb = (void *)config;
  40. /* Assert the node offset point to "arm,sp" compatible property */
  41. const char *compatible_str = "arm,sp";
  42. node = fdt_node_offset_by_compatible(dtb, -1, compatible_str);
  43. if (node < 0) {
  44. ERROR("FCONF: Can't find %s in dtb\n", compatible_str);
  45. return node;
  46. }
  47. fdt_for_each_subnode(sp_node, dtb, node) {
  48. if (index == MAX_SP_IDS) {
  49. ERROR("FCONF: Reached max number of SPs\n");
  50. return -1;
  51. }
  52. #if defined(ARM_COT_dualroot)
  53. if ((sip_index == sip_end) || (plat_index == plat_end)) {
  54. ERROR("FCONF: Reached max number of plat/SiP SPs\n");
  55. return -1;
  56. }
  57. #endif /* ARM_COT_dualroot */
  58. /* Read UUID */
  59. err = fdtw_read_uuid(dtb, sp_node, "uuid", 16,
  60. (uint8_t *)&uuid);
  61. if (err < 0) {
  62. ERROR("FCONF: cannot read SP uuid\n");
  63. return -1;
  64. }
  65. memcpy_s(&arm_sp.uuids[index].uuid_struct, sizeof(struct uuid),
  66. &uuid, sizeof(struct uuid));
  67. /* Read Load address */
  68. err = fdt_read_uint32(dtb, sp_node, "load-address", &val32);
  69. if (err < 0) {
  70. ERROR("FCONF: cannot read SP load address\n");
  71. return -1;
  72. }
  73. arm_sp.load_addr[index] = val32;
  74. VERBOSE("FCONF: %s UUID"
  75. " %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x"
  76. " load_addr=%lx\n",
  77. __func__,
  78. uuid.time_low[0], uuid.time_low[1],
  79. uuid.time_low[2], uuid.time_low[3],
  80. uuid.time_mid[0], uuid.time_mid[1],
  81. uuid.time_hi_and_version[0],
  82. uuid.time_hi_and_version[1],
  83. uuid.clock_seq_hi_and_reserved,
  84. uuid.clock_seq_low,
  85. uuid.node[0], uuid.node[1],
  86. uuid.node[2], uuid.node[3],
  87. uuid.node[4], uuid.node[5],
  88. arm_sp.load_addr[index]);
  89. /* Read owner field only for dualroot CoT */
  90. #if defined(ARM_COT_dualroot)
  91. /* Owner is an optional field, no need to catch error */
  92. fdtw_read_string(dtb, sp_node, "owner",
  93. arm_sp.owner[index], ARM_SP_OWNER_NAME_LEN);
  94. /* If owner is empty mark it as SiP owned */
  95. if ((strncmp(arm_sp.owner[index], "SiP",
  96. ARM_SP_OWNER_NAME_LEN) == 0) ||
  97. (strncmp(arm_sp.owner[index], "",
  98. ARM_SP_OWNER_NAME_LEN) == 0)) {
  99. is_plat_owned = false;
  100. } else if (strcmp(arm_sp.owner[index], "Plat") == 0) {
  101. is_plat_owned = true;
  102. } else {
  103. ERROR("FCONF: %s is not a valid SP owner\n",
  104. arm_sp.owner[index]);
  105. return -1;
  106. }
  107. /*
  108. * Add SP information in mem param descriptor and IO policies
  109. * structure.
  110. */
  111. if (is_plat_owned) {
  112. sp_mem_params_descs[index].image_id = plat_index;
  113. policies[plat_index].image_spec =
  114. (uintptr_t)&arm_sp.uuids[index];
  115. policies[plat_index].dev_handle = &fip_dev_handle;
  116. policies[plat_index].check = open_fip;
  117. plat_index++;
  118. } else
  119. #endif /* ARM_COT_dualroot */
  120. {
  121. sp_mem_params_descs[index].image_id = sip_index;
  122. policies[sip_index].image_spec =
  123. (uintptr_t)&arm_sp.uuids[index];
  124. policies[sip_index].dev_handle = &fip_dev_handle;
  125. policies[sip_index].check = open_fip;
  126. sip_index++;
  127. }
  128. SET_PARAM_HEAD(&sp_mem_params_descs[index].image_info,
  129. PARAM_IMAGE_BINARY, VERSION_2, 0);
  130. sp_mem_params_descs[index].image_info.image_max_size =
  131. ARM_SP_MAX_SIZE;
  132. sp_mem_params_descs[index].next_handoff_image_id =
  133. INVALID_IMAGE_ID;
  134. sp_mem_params_descs[index].image_info.image_base =
  135. arm_sp.load_addr[index];
  136. index++;
  137. }
  138. if ((sp_node < 0) && (sp_node != -FDT_ERR_NOTFOUND)) {
  139. ERROR("%u: fdt_for_each_subnode(): %d\n", __LINE__, node);
  140. return sp_node;
  141. }
  142. arm_sp.number_of_sp = index;
  143. return 0;
  144. }
  145. FCONF_REGISTER_POPULATOR(TB_FW, arm_sp, fconf_populate_arm_sp);
  146. #endif /* IMAGE_BL2 */