blob: 7b5bd6ec959dd8ab7ee714b75d1da2eb0ca7a158 [file] [log] [blame]
Louis Mayencourt6d2b5732019-12-17 13:17:25 +00001/*
2 * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <assert.h>
8
9#include <common/debug.h>
10#include <common/fdt_wrappers.h>
11#include <lib/fconf/fconf_dyn_cfg_getter.h>
12#include <lib/object_pool.h>
13#include <libfdt.h>
14
15/* We currently use TB_FW, SOC_FW, TOS_FW, NS_fw and HW configs */
16#define MAX_DTB_INFO U(5)
17
18static struct dyn_cfg_dtb_info_t dtb_infos[MAX_DTB_INFO];
19static OBJECT_POOL_ARRAY(dtb_info_pool, dtb_infos);
20
21struct dyn_cfg_dtb_info_t *dyn_cfg_dtb_info_getter(unsigned int config_id)
22{
23 unsigned int index;
24 struct dyn_cfg_dtb_info_t *info;
25
26 /* Positions index to the proper config-id */
27 for (index = 0; index < MAX_DTB_INFO; index++) {
28 if (dtb_infos[index].config_id == config_id) {
29 info = &dtb_infos[index];
30 break;
31 }
32 }
33
34 if (index == MAX_DTB_INFO) {
35 WARN("FCONF: Invalid config id %u\n", config_id);
36 info = NULL;
37 }
38
39 return info;
40}
41
42int fconf_populate_dtb_registry(uintptr_t config)
43{
44 int rc;
45 int node, child;
46 struct dyn_cfg_dtb_info_t *dtb_info;
47
48 /* As libfdt use void *, we can't avoid this cast */
49 const void *dtb = (void *)config;
50
Louis Mayencourtb26fafa2020-04-20 14:17:21 +010051 /* Find the node offset point to "fconf,dyn_cfg-dtb_registry" compatible property */
52 const char *compatible_str = "fconf,dyn_cfg-dtb_registry";
Louis Mayencourt6d2b5732019-12-17 13:17:25 +000053 node = fdt_node_offset_by_compatible(dtb, -1, compatible_str);
54 if (node < 0) {
55 ERROR("FCONF: Can't find %s compatible in dtb\n", compatible_str);
56 return node;
57 }
58
59 fdt_for_each_subnode(child, dtb, node) {
Andre Przywarafe5bdf52020-03-26 11:22:37 +000060 uint32_t val32;
61 uint64_t val64;
62
Louis Mayencourt6d2b5732019-12-17 13:17:25 +000063 dtb_info = pool_alloc(&dtb_info_pool);
64
65 /* Read configuration dtb information */
Andre Przywarafe5bdf52020-03-26 11:22:37 +000066 rc = fdt_read_uint64(dtb, child, "load-address", &val64);
Louis Mayencourt6d2b5732019-12-17 13:17:25 +000067 if (rc < 0) {
68 ERROR("FCONF: Incomplete configuration property in dtb-registry.\n");
69 return rc;
70 }
Andre Przywarafe5bdf52020-03-26 11:22:37 +000071 dtb_info->config_addr = (uintptr_t)val64;
Louis Mayencourt6d2b5732019-12-17 13:17:25 +000072
Andre Przywarafe5bdf52020-03-26 11:22:37 +000073 rc = fdt_read_uint32(dtb, child, "max-size", &val32);
Louis Mayencourt6d2b5732019-12-17 13:17:25 +000074 if (rc < 0) {
75 ERROR("FCONF: Incomplete configuration property in dtb-registry.\n");
76 return rc;
77 }
Andre Przywarafe5bdf52020-03-26 11:22:37 +000078 dtb_info->config_max_size = val32;
Louis Mayencourt6d2b5732019-12-17 13:17:25 +000079
Andre Przywarafe5bdf52020-03-26 11:22:37 +000080 rc = fdt_read_uint32(dtb, child, "id", &val32);
Louis Mayencourt6d2b5732019-12-17 13:17:25 +000081 if (rc < 0) {
82 ERROR("FCONF: Incomplete configuration property in dtb-registry.\n");
83 return rc;
84 }
Andre Przywarafe5bdf52020-03-26 11:22:37 +000085 dtb_info->config_id = val32;
Louis Mayencourt6d2b5732019-12-17 13:17:25 +000086
87 VERBOSE("FCONF: dyn_cfg.dtb_registry cell found with:\n");
88 VERBOSE("\tload-address = %lx\n", dtb_info->config_addr);
89 VERBOSE("\tmax-size = 0x%zx\n", dtb_info->config_max_size);
90 VERBOSE("\tconfig-id = %u\n", dtb_info->config_id);
91 }
92
93 if ((child < 0) && (child != -FDT_ERR_NOTFOUND)) {
94 ERROR("%d: fdt_for_each_subnode(): %d\n", __LINE__, node);
95 return child;
96 }
97
98 return 0;
99}
100
Madhukar Pappireddy81519692019-12-06 15:46:42 -0600101FCONF_REGISTER_POPULATOR(TB_FW, dyn_cfg, fconf_populate_dtb_registry);