blob: cfcbf2a2a891bf9749d6240f7b6eae75ae9bc17f [file] [log] [blame]
Soby Mathew96a1c6b2018-01-15 14:45:33 +00001/*
2 * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <assert.h>
8#include <desc_image_load.h>
9#include <fdt_wrappers.h>
10#include <libfdt.h>
Soby Mathewcc364842018-02-21 01:16:39 +000011#include <plat_arm.h>
Soby Mathew96a1c6b2018-01-15 14:45:33 +000012
13/*******************************************************************************
14 * Helper to read the `hw_config` property in config DTB. This function
15 * expects the following properties to be present in the config DTB.
16 * name : hw_config_addr size : 2 cells
17 * name : hw_config_max_size size : 1 cell
18 *
19 * Arguments:
20 * void *dtb - pointer to the TB_FW_CONFIG in memory
21 * int node - The node offset to appropriate node in the
22 * DTB.
23 * uint64_t *hw_config_addr - Returns the `hw_config` load address if read
24 * is successful.
25 * uint32_t *hw_config_size - Returns the `hw_config` size if read is
26 * successful.
27 *
28 * Returns 0 on success and -1 on error.
29 ******************************************************************************/
30int arm_dyn_get_hwconfig_info(void *dtb, int node,
31 uint64_t *hw_config_addr, uint32_t *hw_config_size)
32{
33 int err;
34
Soby Mathewcc364842018-02-21 01:16:39 +000035 assert(dtb != NULL);
36 assert(hw_config_addr != NULL);
37 assert(hw_config_size != NULL);
Soby Mathew96a1c6b2018-01-15 14:45:33 +000038
39 /* Check if the pointer to DT is correct */
40 assert(fdt_check_header(dtb) == 0);
41
42 /* Assert the node offset point to "arm,tb_fw" compatible property */
43 assert(node == fdt_node_offset_by_compatible(dtb, -1, "arm,tb_fw"));
44
45 err = fdtw_read_cells(dtb, node, "hw_config_addr", 2,
46 (void *) hw_config_addr);
47 if (err < 0) {
48 WARN("Read cell failed for hw_config_addr\n");
49 return -1;
50 }
51
52 err = fdtw_read_cells(dtb, node, "hw_config_max_size", 1,
53 (void *) hw_config_size);
54 if (err < 0) {
55 WARN("Read cell failed for hw_config_max_size\n");
56 return -1;
57 }
58
59 VERBOSE("Dyn cfg: Read hw_config address from TB_FW_CONFIG 0x%p %p\n",
60 hw_config_addr, hw_config_size);
61
62 return 0;
63}
64
65/*******************************************************************************
66 * Validate the tb_fw_config is a valid DTB file and returns the node offset
67 * to "arm,tb_fw" property.
68 * Arguments:
69 * void *dtb - pointer to the TB_FW_CONFIG in memory
70 * int *node - Returns the node offset to "arm,tb_fw" property if found.
71 *
72 * Returns 0 on success and -1 on error.
73 ******************************************************************************/
74int arm_dyn_tb_fw_cfg_init(void *dtb, int *node)
75{
Soby Mathewcc364842018-02-21 01:16:39 +000076 assert(dtb != NULL);
77 assert(node != NULL);
Soby Mathew96a1c6b2018-01-15 14:45:33 +000078
79 /* Check if the pointer to DT is correct */
80 if (fdt_check_header(dtb) != 0) {
81 WARN("Invalid DTB file passed as TB_FW_CONFIG\n");
82 return -1;
83 }
84
85 /* Assert the node offset point to "arm,tb_fw" compatible property */
86 *node = fdt_node_offset_by_compatible(dtb, -1, "arm,tb_fw");
87 if (*node < 0) {
88 WARN("The compatible property `arm,tb_fw` not found in the config\n");
89 return -1;
90 }
91
92 VERBOSE("Dyn cfg: Found \"arm,tb_fw\" in the config\n");
93 return 0;
94}