Louis Mayencourt | 6d2b573 | 2019-12-17 13:17:25 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 18 | static struct dyn_cfg_dtb_info_t dtb_infos[MAX_DTB_INFO]; |
| 19 | static OBJECT_POOL_ARRAY(dtb_info_pool, dtb_infos); |
| 20 | |
| 21 | struct 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 | |
| 42 | int 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 Mayencourt | b26fafa | 2020-04-20 14:17:21 +0100 | [diff] [blame] | 51 | /* Find the node offset point to "fconf,dyn_cfg-dtb_registry" compatible property */ |
| 52 | const char *compatible_str = "fconf,dyn_cfg-dtb_registry"; |
Louis Mayencourt | 6d2b573 | 2019-12-17 13:17:25 +0000 | [diff] [blame] | 53 | 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 Przywara | fe5bdf5 | 2020-03-26 11:22:37 +0000 | [diff] [blame] | 60 | uint32_t val32; |
| 61 | uint64_t val64; |
| 62 | |
Louis Mayencourt | 6d2b573 | 2019-12-17 13:17:25 +0000 | [diff] [blame] | 63 | dtb_info = pool_alloc(&dtb_info_pool); |
| 64 | |
| 65 | /* Read configuration dtb information */ |
Andre Przywara | fe5bdf5 | 2020-03-26 11:22:37 +0000 | [diff] [blame] | 66 | rc = fdt_read_uint64(dtb, child, "load-address", &val64); |
Louis Mayencourt | 6d2b573 | 2019-12-17 13:17:25 +0000 | [diff] [blame] | 67 | if (rc < 0) { |
| 68 | ERROR("FCONF: Incomplete configuration property in dtb-registry.\n"); |
| 69 | return rc; |
| 70 | } |
Andre Przywara | fe5bdf5 | 2020-03-26 11:22:37 +0000 | [diff] [blame] | 71 | dtb_info->config_addr = (uintptr_t)val64; |
Louis Mayencourt | 6d2b573 | 2019-12-17 13:17:25 +0000 | [diff] [blame] | 72 | |
Andre Przywara | fe5bdf5 | 2020-03-26 11:22:37 +0000 | [diff] [blame] | 73 | rc = fdt_read_uint32(dtb, child, "max-size", &val32); |
Louis Mayencourt | 6d2b573 | 2019-12-17 13:17:25 +0000 | [diff] [blame] | 74 | if (rc < 0) { |
| 75 | ERROR("FCONF: Incomplete configuration property in dtb-registry.\n"); |
| 76 | return rc; |
| 77 | } |
Andre Przywara | fe5bdf5 | 2020-03-26 11:22:37 +0000 | [diff] [blame] | 78 | dtb_info->config_max_size = val32; |
Louis Mayencourt | 6d2b573 | 2019-12-17 13:17:25 +0000 | [diff] [blame] | 79 | |
Andre Przywara | fe5bdf5 | 2020-03-26 11:22:37 +0000 | [diff] [blame] | 80 | rc = fdt_read_uint32(dtb, child, "id", &val32); |
Louis Mayencourt | 6d2b573 | 2019-12-17 13:17:25 +0000 | [diff] [blame] | 81 | if (rc < 0) { |
| 82 | ERROR("FCONF: Incomplete configuration property in dtb-registry.\n"); |
| 83 | return rc; |
| 84 | } |
Andre Przywara | fe5bdf5 | 2020-03-26 11:22:37 +0000 | [diff] [blame] | 85 | dtb_info->config_id = val32; |
Louis Mayencourt | 6d2b573 | 2019-12-17 13:17:25 +0000 | [diff] [blame] | 86 | |
| 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 Pappireddy | 8151969 | 2019-12-06 15:46:42 -0600 | [diff] [blame] | 101 | FCONF_REGISTER_POPULATOR(TB_FW, dyn_cfg, fconf_populate_dtb_registry); |