blob: 552393c9bf6f7b080c346a080aed4d94299efdc6 [file] [log] [blame]
Olivier Deprez93df21f2020-01-23 11:24:33 +01001/*
David Horstmannb2df4c12021-04-08 14:50:21 +01002 * Copyright (c) 2020-2021, 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>
8
9#include <common/debug.h>
Manish Pandey1fa6ecb2020-02-25 11:38:19 +000010#include <common/desc_image_load.h>
Olivier Deprez93df21f2020-01-23 11:24:33 +010011#include <common/fdt_wrappers.h>
12#include <drivers/io/io_storage.h>
13#include <lib/object_pool.h>
14#include <libfdt.h>
15#include <plat/arm/common/arm_fconf_getter.h>
16#include <plat/arm/common/arm_fconf_io_storage.h>
17#include <plat/arm/common/fconf_arm_sp_getter.h>
18#include <platform_def.h>
19#include <tools_share/firmware_image_package.h>
20
21#ifdef IMAGE_BL2
22
Manish Pandey1fa6ecb2020-02-25 11:38:19 +000023bl_mem_params_node_t sp_mem_params_descs[MAX_SP_IDS];
24
Olivier Deprez93df21f2020-01-23 11:24:33 +010025struct arm_sp_t arm_sp;
26
27int fconf_populate_arm_sp(uintptr_t config)
28{
29 int sp_node, node, err;
30 union uuid_helper_t uuid_helper;
Manish Pandey1fa6ecb2020-02-25 11:38:19 +000031 unsigned int index = 0;
Andre Przywarafe5bdf52020-03-26 11:22:37 +000032 uint32_t val32;
Manish Pandeyaff80752020-07-31 16:15:16 +010033 bool is_plat_owned = false;
34 const unsigned int sip_start = SP_PKG1_ID;
35 unsigned int sip_index = sip_start;
36 const unsigned int sip_end = sip_start + MAX_SP_IDS / 2;
37 const unsigned int plat_start = SP_PKG5_ID;
38 unsigned int plat_index = plat_start;
39 const unsigned int plat_end = plat_start + MAX_SP_IDS / 2;
Olivier Deprez93df21f2020-01-23 11:24:33 +010040
41 /* As libfdt use void *, we can't avoid this cast */
42 const void *dtb = (void *)config;
43
44 /* Assert the node offset point to "arm,sp" compatible property */
45 const char *compatible_str = "arm,sp";
46
47 node = fdt_node_offset_by_compatible(dtb, -1, compatible_str);
48 if (node < 0) {
49 ERROR("FCONF: Can't find %s in dtb\n", compatible_str);
50 return node;
51 }
52
53 fdt_for_each_subnode(sp_node, dtb, node) {
Manish Pandeyaff80752020-07-31 16:15:16 +010054 if ((index == MAX_SP_IDS) || (sip_index == sip_end)
55 || (plat_index == plat_end)) {
Manish Pandey61ff7172020-07-27 13:00:38 +010056 ERROR("FCONF: Reached max number of SPs\n");
57 return -1;
58 }
59
Manish Pandeyaff80752020-07-31 16:15:16 +010060 /* Read UUID */
David Horstmannb2df4c12021-04-08 14:50:21 +010061 err = fdtw_read_uuid(dtb, sp_node, "uuid", 16,
62 (uint8_t *)&uuid_helper);
Olivier Deprez93df21f2020-01-23 11:24:33 +010063 if (err < 0) {
64 ERROR("FCONF: cannot read SP uuid\n");
65 return -1;
66 }
Ruari Phipps57d48a02020-08-10 15:53:45 +010067
Manish Pandey1fa6ecb2020-02-25 11:38:19 +000068 arm_sp.uuids[index] = uuid_helper;
David Horstmannb2df4c12021-04-08 14:50:21 +010069 VERBOSE("FCONF: %s UUID"
70 " %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x"
71 " load_addr=%lx\n",
Olivier Deprez93df21f2020-01-23 11:24:33 +010072 __func__,
David Horstmannb2df4c12021-04-08 14:50:21 +010073 uuid_helper.uuid_struct.time_low[0], uuid_helper.uuid_struct.time_low[1],
74 uuid_helper.uuid_struct.time_low[2], uuid_helper.uuid_struct.time_low[3],
75 uuid_helper.uuid_struct.time_mid[0], uuid_helper.uuid_struct.time_mid[1],
76 uuid_helper.uuid_struct.time_hi_and_version[0],
77 uuid_helper.uuid_struct.time_hi_and_version[1],
78 uuid_helper.uuid_struct.clock_seq_hi_and_reserved,
79 uuid_helper.uuid_struct.clock_seq_low,
80 uuid_helper.uuid_struct.node[0], uuid_helper.uuid_struct.node[1],
81 uuid_helper.uuid_struct.node[2], uuid_helper.uuid_struct.node[3],
82 uuid_helper.uuid_struct.node[4], uuid_helper.uuid_struct.node[5],
Manish Pandey1fa6ecb2020-02-25 11:38:19 +000083 arm_sp.load_addr[index]);
84
Manish Pandeyaff80752020-07-31 16:15:16 +010085 /* Read Load address */
86 err = fdt_read_uint32(dtb, sp_node, "load-address", &val32);
87 if (err < 0) {
88 ERROR("FCONF: cannot read SP load address\n");
89 return -1;
90 }
91 arm_sp.load_addr[index] = val32;
92
93 /* Read owner field only for dualroot CoT */
94#if defined(ARM_COT_dualroot)
95 /* Owner is an optional field, no need to catch error */
96 fdtw_read_string(dtb, sp_node, "owner",
97 arm_sp.owner[index], ARM_SP_OWNER_NAME_LEN);
98#endif
99 /* If owner is empty mark it as SiP owned */
100 if ((strncmp(arm_sp.owner[index], "SiP",
101 ARM_SP_OWNER_NAME_LEN) == 0) ||
102 (strncmp(arm_sp.owner[index], "",
103 ARM_SP_OWNER_NAME_LEN) == 0)) {
104 is_plat_owned = false;
105 } else if (strcmp(arm_sp.owner[index], "Plat") == 0) {
106 is_plat_owned = true;
107 } else {
108 ERROR("FCONF: %s is not a valid SP owner\n",
109 arm_sp.owner[index]);
110 return -1;
111 }
112 /*
113 * Add SP information in mem param descriptor and IO policies
114 * structure.
115 */
116 if (is_plat_owned) {
117 sp_mem_params_descs[index].image_id = plat_index;
118 policies[plat_index].image_spec =
119 (uintptr_t)&arm_sp.uuids[index];
120 policies[plat_index].dev_handle = &fip_dev_handle;
121 policies[plat_index].check = open_fip;
122 plat_index++;
123 } else {
124 sp_mem_params_descs[index].image_id = sip_index;
125 policies[sip_index].image_spec =
126 (uintptr_t)&arm_sp.uuids[index];
127 policies[sip_index].dev_handle = &fip_dev_handle;
128 policies[sip_index].check = open_fip;
129 sip_index++;
130 }
Manish Pandey1fa6ecb2020-02-25 11:38:19 +0000131 SET_PARAM_HEAD(&sp_mem_params_descs[index].image_info,
132 PARAM_IMAGE_BINARY, VERSION_2, 0);
133 sp_mem_params_descs[index].image_info.image_max_size =
134 ARM_SP_MAX_SIZE;
135 sp_mem_params_descs[index].next_handoff_image_id =
136 INVALID_IMAGE_ID;
137 sp_mem_params_descs[index].image_info.image_base =
138 arm_sp.load_addr[index];
Manish Pandey1fa6ecb2020-02-25 11:38:19 +0000139 index++;
Olivier Deprez93df21f2020-01-23 11:24:33 +0100140 }
141
142 if ((sp_node < 0) && (sp_node != -FDT_ERR_NOTFOUND)) {
Manish Pandey61ff7172020-07-27 13:00:38 +0100143 ERROR("%u: fdt_for_each_subnode(): %d\n", __LINE__, node);
Olivier Deprez93df21f2020-01-23 11:24:33 +0100144 return sp_node;
145 }
146
Manish Pandey1fa6ecb2020-02-25 11:38:19 +0000147 arm_sp.number_of_sp = index;
Olivier Deprez93df21f2020-01-23 11:24:33 +0100148 return 0;
149}
150
Madhukar Pappireddy81519692019-12-06 15:46:42 -0600151FCONF_REGISTER_POPULATOR(TB_FW, arm_sp, fconf_populate_arm_sp);
Olivier Deprez93df21f2020-01-23 11:24:33 +0100152
153#endif /* IMAGE_BL2 */