blob: 8655156ca99c1e4a84204f1b889742d56d2d64a7 [file] [log] [blame]
Olivier Deprez93df21f2020-01-23 11:24:33 +01001/*
Olivier Deprez71ce2d32024-01-08 20:57:36 +01002 * Copyright (c) 2020-2024, ARM Limited and Contributors. All rights reserved.
Olivier Deprez93df21f2020-01-23 11:24:33 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <assert.h>
Olivier Deprez71ce2d32024-01-08 20:57:36 +01008#include <string.h>
Olivier Deprez93df21f2020-01-23 11:24:33 +01009
10#include <common/debug.h>
Manish Pandey1fa6ecb2020-02-25 11:38:19 +000011#include <common/desc_image_load.h>
Olivier Deprez93df21f2020-01-23 11:24:33 +010012#include <common/fdt_wrappers.h>
13#include <drivers/io/io_storage.h>
14#include <lib/object_pool.h>
15#include <libfdt.h>
16#include <plat/arm/common/arm_fconf_getter.h>
17#include <plat/arm/common/arm_fconf_io_storage.h>
18#include <plat/arm/common/fconf_arm_sp_getter.h>
19#include <platform_def.h>
20#include <tools_share/firmware_image_package.h>
21
22#ifdef IMAGE_BL2
23
Manish Pandey1fa6ecb2020-02-25 11:38:19 +000024bl_mem_params_node_t sp_mem_params_descs[MAX_SP_IDS];
25
Olivier Deprez93df21f2020-01-23 11:24:33 +010026struct arm_sp_t arm_sp;
27
28int fconf_populate_arm_sp(uintptr_t config)
29{
30 int sp_node, node, err;
Olivier Deprez71ce2d32024-01-08 20:57:36 +010031 struct uuid uuid;
Manish Pandey1fa6ecb2020-02-25 11:38:19 +000032 unsigned int index = 0;
Andre Przywarafe5bdf52020-03-26 11:22:37 +000033 uint32_t val32;
Manish Pandeyaff80752020-07-31 16:15:16 +010034 const unsigned int sip_start = SP_PKG1_ID;
35 unsigned int sip_index = sip_start;
Imre Kis36286f62022-02-09 16:33:07 +010036#if defined(ARM_COT_dualroot)
Manish Pandeyaff80752020-07-31 16:15:16 +010037 const unsigned int sip_end = sip_start + MAX_SP_IDS / 2;
Imre Kis36286f62022-02-09 16:33:07 +010038 /* Allocating index range for platform SPs */
Manish Pandeyaff80752020-07-31 16:15:16 +010039 const unsigned int plat_start = SP_PKG5_ID;
40 unsigned int plat_index = plat_start;
41 const unsigned int plat_end = plat_start + MAX_SP_IDS / 2;
Imre Kis36286f62022-02-09 16:33:07 +010042 bool is_plat_owned = false;
43#endif /* ARM_COT_dualroot */
Olivier Deprez93df21f2020-01-23 11:24:33 +010044
45 /* As libfdt use void *, we can't avoid this cast */
46 const void *dtb = (void *)config;
47
48 /* Assert the node offset point to "arm,sp" compatible property */
49 const char *compatible_str = "arm,sp";
50
51 node = fdt_node_offset_by_compatible(dtb, -1, compatible_str);
52 if (node < 0) {
53 ERROR("FCONF: Can't find %s in dtb\n", compatible_str);
54 return node;
55 }
56
57 fdt_for_each_subnode(sp_node, dtb, node) {
Imre Kis36286f62022-02-09 16:33:07 +010058 if (index == MAX_SP_IDS) {
Manish Pandey61ff7172020-07-27 13:00:38 +010059 ERROR("FCONF: Reached max number of SPs\n");
60 return -1;
61 }
62
Imre Kis36286f62022-02-09 16:33:07 +010063#if defined(ARM_COT_dualroot)
64 if ((sip_index == sip_end) || (plat_index == plat_end)) {
65 ERROR("FCONF: Reached max number of plat/SiP SPs\n");
66 return -1;
67 }
68#endif /* ARM_COT_dualroot */
69
Manish Pandeyaff80752020-07-31 16:15:16 +010070 /* Read UUID */
David Horstmannb2df4c12021-04-08 14:50:21 +010071 err = fdtw_read_uuid(dtb, sp_node, "uuid", 16,
Olivier Deprez71ce2d32024-01-08 20:57:36 +010072 (uint8_t *)&uuid);
Olivier Deprez93df21f2020-01-23 11:24:33 +010073 if (err < 0) {
74 ERROR("FCONF: cannot read SP uuid\n");
75 return -1;
76 }
Ruari Phipps57d48a02020-08-10 15:53:45 +010077
Olivier Deprez71ce2d32024-01-08 20:57:36 +010078 memcpy_s(&arm_sp.uuids[index].uuid_struct, sizeof(struct uuid),
79 &uuid, sizeof(struct uuid));
Sandrine Bailleux649d19b2021-10-22 14:44:42 +020080
81 /* Read Load address */
82 err = fdt_read_uint32(dtb, sp_node, "load-address", &val32);
83 if (err < 0) {
84 ERROR("FCONF: cannot read SP load address\n");
85 return -1;
86 }
87 arm_sp.load_addr[index] = val32;
88
David Horstmannb2df4c12021-04-08 14:50:21 +010089 VERBOSE("FCONF: %s UUID"
90 " %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x"
91 " load_addr=%lx\n",
Olivier Deprez93df21f2020-01-23 11:24:33 +010092 __func__,
Olivier Deprez71ce2d32024-01-08 20:57:36 +010093 uuid.time_low[0], uuid.time_low[1],
94 uuid.time_low[2], uuid.time_low[3],
95 uuid.time_mid[0], uuid.time_mid[1],
96 uuid.time_hi_and_version[0],
97 uuid.time_hi_and_version[1],
98 uuid.clock_seq_hi_and_reserved,
99 uuid.clock_seq_low,
100 uuid.node[0], uuid.node[1],
101 uuid.node[2], uuid.node[3],
102 uuid.node[4], uuid.node[5],
Manish Pandey1fa6ecb2020-02-25 11:38:19 +0000103 arm_sp.load_addr[index]);
104
Manish Pandeyaff80752020-07-31 16:15:16 +0100105 /* Read owner field only for dualroot CoT */
106#if defined(ARM_COT_dualroot)
107 /* Owner is an optional field, no need to catch error */
108 fdtw_read_string(dtb, sp_node, "owner",
109 arm_sp.owner[index], ARM_SP_OWNER_NAME_LEN);
Imre Kis36286f62022-02-09 16:33:07 +0100110
Manish Pandeyaff80752020-07-31 16:15:16 +0100111 /* If owner is empty mark it as SiP owned */
112 if ((strncmp(arm_sp.owner[index], "SiP",
113 ARM_SP_OWNER_NAME_LEN) == 0) ||
114 (strncmp(arm_sp.owner[index], "",
115 ARM_SP_OWNER_NAME_LEN) == 0)) {
116 is_plat_owned = false;
117 } else if (strcmp(arm_sp.owner[index], "Plat") == 0) {
118 is_plat_owned = true;
119 } else {
120 ERROR("FCONF: %s is not a valid SP owner\n",
121 arm_sp.owner[index]);
122 return -1;
123 }
124 /*
125 * Add SP information in mem param descriptor and IO policies
126 * structure.
127 */
128 if (is_plat_owned) {
129 sp_mem_params_descs[index].image_id = plat_index;
130 policies[plat_index].image_spec =
131 (uintptr_t)&arm_sp.uuids[index];
132 policies[plat_index].dev_handle = &fip_dev_handle;
133 policies[plat_index].check = open_fip;
134 plat_index++;
Imre Kis36286f62022-02-09 16:33:07 +0100135 } else
136#endif /* ARM_COT_dualroot */
137 {
Manish Pandeyaff80752020-07-31 16:15:16 +0100138 sp_mem_params_descs[index].image_id = sip_index;
139 policies[sip_index].image_spec =
140 (uintptr_t)&arm_sp.uuids[index];
141 policies[sip_index].dev_handle = &fip_dev_handle;
142 policies[sip_index].check = open_fip;
143 sip_index++;
144 }
Manish Pandey1fa6ecb2020-02-25 11:38:19 +0000145 SET_PARAM_HEAD(&sp_mem_params_descs[index].image_info,
146 PARAM_IMAGE_BINARY, VERSION_2, 0);
147 sp_mem_params_descs[index].image_info.image_max_size =
148 ARM_SP_MAX_SIZE;
149 sp_mem_params_descs[index].next_handoff_image_id =
150 INVALID_IMAGE_ID;
151 sp_mem_params_descs[index].image_info.image_base =
152 arm_sp.load_addr[index];
Manish Pandey1fa6ecb2020-02-25 11:38:19 +0000153 index++;
Olivier Deprez93df21f2020-01-23 11:24:33 +0100154 }
155
156 if ((sp_node < 0) && (sp_node != -FDT_ERR_NOTFOUND)) {
Manish Pandey61ff7172020-07-27 13:00:38 +0100157 ERROR("%u: fdt_for_each_subnode(): %d\n", __LINE__, node);
Olivier Deprez93df21f2020-01-23 11:24:33 +0100158 return sp_node;
159 }
160
Manish Pandey1fa6ecb2020-02-25 11:38:19 +0000161 arm_sp.number_of_sp = index;
Olivier Deprez93df21f2020-01-23 11:24:33 +0100162 return 0;
163}
164
Madhukar Pappireddy81519692019-12-06 15:46:42 -0600165FCONF_REGISTER_POPULATOR(TB_FW, arm_sp, fconf_populate_arm_sp);
Olivier Deprez93df21f2020-01-23 11:24:33 +0100166
167#endif /* IMAGE_BL2 */