blob: 4459264c71368d392dd039cf5a0df632cc0a6541 [file] [log] [blame]
Olivier Deprez93df21f2020-01-23 11:24:33 +01001/*
2 * Copyright (c) 2020, ARM Limited and Contributors. All rights reserved.
3 *
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 Pandeyd07d0172020-07-23 16:54:30 +010033 const unsigned int sp_start_index = SP_PKG1_ID;
Olivier Deprez93df21f2020-01-23 11:24:33 +010034
35 /* As libfdt use void *, we can't avoid this cast */
36 const void *dtb = (void *)config;
37
38 /* Assert the node offset point to "arm,sp" compatible property */
39 const char *compatible_str = "arm,sp";
40
41 node = fdt_node_offset_by_compatible(dtb, -1, compatible_str);
42 if (node < 0) {
43 ERROR("FCONF: Can't find %s in dtb\n", compatible_str);
44 return node;
45 }
46
47 fdt_for_each_subnode(sp_node, dtb, node) {
Manish Pandey61ff7172020-07-27 13:00:38 +010048 if (index == MAX_SP_IDS) {
49 ERROR("FCONF: Reached max number of SPs\n");
50 return -1;
51 }
52
Andre Przywara6cf6a1b2020-03-30 23:21:13 +010053 err = fdt_read_uint32_array(dtb, sp_node, "uuid", 4,
54 uuid_helper.word);
Olivier Deprez93df21f2020-01-23 11:24:33 +010055 if (err < 0) {
56 ERROR("FCONF: cannot read SP uuid\n");
57 return -1;
58 }
59
Manish Pandey1fa6ecb2020-02-25 11:38:19 +000060 arm_sp.uuids[index] = uuid_helper;
Olivier Deprez93df21f2020-01-23 11:24:33 +010061
Andre Przywarafe5bdf52020-03-26 11:22:37 +000062 err = fdt_read_uint32(dtb, sp_node, "load-address", &val32);
Olivier Deprez93df21f2020-01-23 11:24:33 +010063 if (err < 0) {
64 ERROR("FCONF: cannot read SP load address\n");
65 return -1;
66 }
Andre Przywarafe5bdf52020-03-26 11:22:37 +000067 arm_sp.load_addr[index] = val32;
Olivier Deprez93df21f2020-01-23 11:24:33 +010068
69 VERBOSE("FCONF: %s UUID %x-%x-%x-%x load_addr=%lx\n",
70 __func__,
71 uuid_helper.word[0],
72 uuid_helper.word[1],
73 uuid_helper.word[2],
74 uuid_helper.word[3],
Manish Pandey1fa6ecb2020-02-25 11:38:19 +000075 arm_sp.load_addr[index]);
76
77 /* Add SP information in mem param descriptor */
78 sp_mem_params_descs[index].image_id = sp_start_index + index;
79 SET_PARAM_HEAD(&sp_mem_params_descs[index].image_info,
80 PARAM_IMAGE_BINARY, VERSION_2, 0);
81 sp_mem_params_descs[index].image_info.image_max_size =
82 ARM_SP_MAX_SIZE;
83 sp_mem_params_descs[index].next_handoff_image_id =
84 INVALID_IMAGE_ID;
85 sp_mem_params_descs[index].image_info.image_base =
86 arm_sp.load_addr[index];
Olivier Deprez93df21f2020-01-23 11:24:33 +010087
Manish Pandey1fa6ecb2020-02-25 11:38:19 +000088 /* Add SP information in IO policies structure */
89 policies[sp_start_index + index].image_spec =
90 (uintptr_t)&arm_sp.uuids[index];
91 policies[sp_start_index + index].dev_handle = &fip_dev_handle;
92 policies[sp_start_index + index].check = open_fip;
Olivier Deprez93df21f2020-01-23 11:24:33 +010093
Manish Pandey1fa6ecb2020-02-25 11:38:19 +000094 index++;
Olivier Deprez93df21f2020-01-23 11:24:33 +010095 }
96
97 if ((sp_node < 0) && (sp_node != -FDT_ERR_NOTFOUND)) {
Manish Pandey61ff7172020-07-27 13:00:38 +010098 ERROR("%u: fdt_for_each_subnode(): %d\n", __LINE__, node);
Olivier Deprez93df21f2020-01-23 11:24:33 +010099 return sp_node;
100 }
101
Manish Pandey1fa6ecb2020-02-25 11:38:19 +0000102 arm_sp.number_of_sp = index;
Olivier Deprez93df21f2020-01-23 11:24:33 +0100103 return 0;
104}
105
Madhukar Pappireddy81519692019-12-06 15:46:42 -0600106FCONF_REGISTER_POPULATOR(TB_FW, arm_sp, fconf_populate_arm_sp);
Olivier Deprez93df21f2020-01-23 11:24:33 +0100107
108#endif /* IMAGE_BL2 */