blob: 5a7e20ac8e2cd52af8abd541be6c7fa37428ddc3 [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
Roberto Vargas3c98ce42018-02-12 12:36:17 +00007#include <arm_dyn_cfg_helpers.h>
Soby Mathew96a1c6b2018-01-15 14:45:33 +00008#include <assert.h>
9#include <desc_image_load.h>
10#include <fdt_wrappers.h>
11#include <libfdt.h>
Soby Mathewcc364842018-02-21 01:16:39 +000012#include <plat_arm.h>
Soby Mathew96a1c6b2018-01-15 14:45:33 +000013
Soby Mathewb6814842018-04-04 09:40:32 +010014
15typedef struct config_load_info_prop {
16 unsigned int config_id;
17 const char *config_addr;
18 const char *config_max_size;
19} config_load_info_prop_t;
20
21static const config_load_info_prop_t prop_names[] = {
22 {HW_CONFIG_ID, "hw_config_addr", "hw_config_max_size"},
23 {SOC_FW_CONFIG_ID, "soc_fw_config_addr", "soc_fw_config_max_size"},
24 {TOS_FW_CONFIG_ID, "tos_fw_config_addr", "tos_fw_config_max_size"},
25 {NT_FW_CONFIG_ID, "nt_fw_config_addr", "nt_fw_config_max_size"}
26};
27
Soby Mathew96a1c6b2018-01-15 14:45:33 +000028/*******************************************************************************
Soby Mathewb6814842018-04-04 09:40:32 +010029 * Helper to read the load information corresponding to the `config_id` in
30 * TB_FW_CONFIG. This function expects the following properties to be defined :
31 * <config>_addr size : 2 cells
32 * <config>_max_size size : 1 cell
Soby Mathew96a1c6b2018-01-15 14:45:33 +000033 *
34 * Arguments:
35 * void *dtb - pointer to the TB_FW_CONFIG in memory
36 * int node - The node offset to appropriate node in the
37 * DTB.
Soby Mathewb6814842018-04-04 09:40:32 +010038 * unsigned int config_id - The configuration id
39 * uint64_t *config_addr - Returns the `config` load address if read
Soby Mathew96a1c6b2018-01-15 14:45:33 +000040 * is successful.
Soby Mathewb6814842018-04-04 09:40:32 +010041 * uint32_t *config_size - Returns the `config` size if read is
Soby Mathew96a1c6b2018-01-15 14:45:33 +000042 * successful.
43 *
44 * Returns 0 on success and -1 on error.
45 ******************************************************************************/
Soby Mathewb6814842018-04-04 09:40:32 +010046int arm_dyn_get_config_load_info(void *dtb, int node, unsigned int config_id,
47 uint64_t *config_addr, uint32_t *config_size)
Soby Mathew96a1c6b2018-01-15 14:45:33 +000048{
49 int err;
Soby Mathewb6814842018-04-04 09:40:32 +010050 unsigned int i;
Soby Mathew96a1c6b2018-01-15 14:45:33 +000051
Soby Mathewcc364842018-02-21 01:16:39 +000052 assert(dtb != NULL);
Soby Mathewb6814842018-04-04 09:40:32 +010053 assert(config_addr != NULL);
54 assert(config_size != NULL);
55
56 for (i = 0; i < ARRAY_SIZE(prop_names); i++) {
57 if (prop_names[i].config_id == config_id)
58 break;
59 }
60
61 if (i == ARRAY_SIZE(prop_names)) {
62 WARN("Invalid config id %d\n", config_id);
63 return -1;
64 }
Soby Mathew96a1c6b2018-01-15 14:45:33 +000065
66 /* Check if the pointer to DT is correct */
67 assert(fdt_check_header(dtb) == 0);
68
69 /* Assert the node offset point to "arm,tb_fw" compatible property */
70 assert(node == fdt_node_offset_by_compatible(dtb, -1, "arm,tb_fw"));
71
Soby Mathewb6814842018-04-04 09:40:32 +010072 err = fdtw_read_cells(dtb, node, prop_names[i].config_addr, 2,
73 (void *) config_addr);
Soby Mathew96a1c6b2018-01-15 14:45:33 +000074 if (err < 0) {
Soby Mathewb6814842018-04-04 09:40:32 +010075 WARN("Read cell failed for %s\n", prop_names[i].config_addr);
Soby Mathew96a1c6b2018-01-15 14:45:33 +000076 return -1;
77 }
78
Soby Mathewb6814842018-04-04 09:40:32 +010079 err = fdtw_read_cells(dtb, node, prop_names[i].config_max_size, 1,
80 (void *) config_size);
Soby Mathew96a1c6b2018-01-15 14:45:33 +000081 if (err < 0) {
Soby Mathewb6814842018-04-04 09:40:32 +010082 WARN("Read cell failed for %s\n", prop_names[i].config_max_size);
Soby Mathew96a1c6b2018-01-15 14:45:33 +000083 return -1;
84 }
85
Soby Mathewb6814842018-04-04 09:40:32 +010086 VERBOSE("Dyn cfg: Read config_id %d load info from TB_FW_CONFIG 0x%llx 0x%x\n",
87 config_id, (unsigned long long)*config_addr, *config_size);
Soby Mathew96a1c6b2018-01-15 14:45:33 +000088
89 return 0;
90}
91
92/*******************************************************************************
Soby Mathew45e39e22018-03-26 15:16:46 +010093 * Helper to read the `disable_auth` property in config DTB. This function
94 * expects the following properties to be present in the config DTB.
95 * name : disable_auth size : 1 cell
96 *
97 * Arguments:
98 * void *dtb - pointer to the TB_FW_CONFIG in memory
99 * int node - The node offset to appropriate node in the
100 * DTB.
101 * uint64_t *disable_auth - The value of `disable_auth` property on
102 * successful read. Must be 0 or 1.
103 *
104 * Returns 0 on success and -1 on error.
105 ******************************************************************************/
106int arm_dyn_get_disable_auth(void *dtb, int node, uint32_t *disable_auth)
107{
108 int err;
109
110 assert(dtb != NULL);
111 assert(disable_auth != NULL);
112
113 /* Check if the pointer to DT is correct */
114 assert(fdt_check_header(dtb) == 0);
115
116 /* Assert the node offset point to "arm,tb_fw" compatible property */
117 assert(node == fdt_node_offset_by_compatible(dtb, -1, "arm,tb_fw"));
118
119 /* Locate the disable_auth cell and read the value */
120 err = fdtw_read_cells(dtb, node, "disable_auth", 1, disable_auth);
121 if (err < 0) {
122 WARN("Read cell failed for `disable_auth`\n");
123 return -1;
124 }
125
126 /* Check if the value is boolean */
Soby Mathewb6814842018-04-04 09:40:32 +0100127 if ((*disable_auth != 0U) && (*disable_auth != 1U)) {
Soby Mathew45e39e22018-03-26 15:16:46 +0100128 WARN("Invalid value for `disable_auth` cell %d\n", *disable_auth);
129 return -1;
130 }
131
132 VERBOSE("Dyn cfg: `disable_auth` cell found with value = %d\n",
133 *disable_auth);
134 return 0;
135}
136
137/*******************************************************************************
Soby Mathew96a1c6b2018-01-15 14:45:33 +0000138 * Validate the tb_fw_config is a valid DTB file and returns the node offset
139 * to "arm,tb_fw" property.
140 * Arguments:
141 * void *dtb - pointer to the TB_FW_CONFIG in memory
142 * int *node - Returns the node offset to "arm,tb_fw" property if found.
143 *
144 * Returns 0 on success and -1 on error.
145 ******************************************************************************/
146int arm_dyn_tb_fw_cfg_init(void *dtb, int *node)
147{
Soby Mathewcc364842018-02-21 01:16:39 +0000148 assert(dtb != NULL);
149 assert(node != NULL);
Soby Mathew96a1c6b2018-01-15 14:45:33 +0000150
151 /* Check if the pointer to DT is correct */
152 if (fdt_check_header(dtb) != 0) {
153 WARN("Invalid DTB file passed as TB_FW_CONFIG\n");
154 return -1;
155 }
156
157 /* Assert the node offset point to "arm,tb_fw" compatible property */
158 *node = fdt_node_offset_by_compatible(dtb, -1, "arm,tb_fw");
159 if (*node < 0) {
160 WARN("The compatible property `arm,tb_fw` not found in the config\n");
161 return -1;
162 }
163
164 VERBOSE("Dyn cfg: Found \"arm,tb_fw\" in the config\n");
165 return 0;
166}