Commit 85838f48 authored by Sandrine Bailleux's avatar Sandrine Bailleux Committed by TrustedFirmware Code Review
Browse files

Merge changes from topic "fdt_wrappers_rework" into integration

* changes:
  plat/stm32: Use generic fdt_get_stdout_node_offset()
  fdt/wrappers: Introduce code to find UART DT node
  plat/stm32: Use generic fdt_get_reg_props_by_name()
parents fcfc96d6 7a61114d
...@@ -276,3 +276,68 @@ int fdt_get_reg_props_by_index(const void *dtb, int node, int index, ...@@ -276,3 +276,68 @@ int fdt_get_reg_props_by_index(const void *dtb, int node, int index,
return 0; return 0;
} }
/*******************************************************************************
* This function fills reg node info (base & size) with an index found by
* checking the reg-names node.
* Returns 0 on success and a negative FDT error code on failure.
******************************************************************************/
int fdt_get_reg_props_by_name(const void *dtb, int node, const char *name,
uintptr_t *base, size_t *size)
{
int index;
index = fdt_stringlist_search(dtb, node, "reg-names", name);
if (index < 0) {
return index;
}
return fdt_get_reg_props_by_index(dtb, node, index, base, size);
}
/*******************************************************************************
* This function gets the stdout path node.
* It reads the value indicated inside the device tree.
* Returns node offset on success and a negative FDT error code on failure.
******************************************************************************/
int fdt_get_stdout_node_offset(const void *dtb)
{
int node;
const char *prop, *path;
int len;
/* The /secure-chosen node takes precedence over the standard one. */
node = fdt_path_offset(dtb, "/secure-chosen");
if (node < 0) {
node = fdt_path_offset(dtb, "/chosen");
if (node < 0) {
return -FDT_ERR_NOTFOUND;
}
}
prop = fdt_getprop(dtb, node, "stdout-path", NULL);
if (prop == NULL) {
return -FDT_ERR_NOTFOUND;
}
/* Determine the actual path length, as a colon terminates the path. */
path = strchr(prop, ':');
if (path == NULL) {
len = strlen(prop);
} else {
len = path - prop;
}
/* Aliases cannot start with a '/', so it must be the actual path. */
if (prop[0] == '/') {
return fdt_path_offset_namelen(dtb, prop, len);
}
/* Lookup the alias, as this contains the actual path. */
path = fdt_get_alias_namelen(dtb, prop, len);
if (path == NULL) {
return -FDT_ERR_NOTFOUND;
}
return fdt_path_offset(dtb, path);
}
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <platform_def.h> #include <platform_def.h>
#include <common/debug.h> #include <common/debug.h>
#include <common/fdt_wrappers.h>
#include <drivers/delay_timer.h> #include <drivers/delay_timer.h>
#include <drivers/spi_mem.h> #include <drivers/spi_mem.h>
#include <drivers/st/stm32_gpio.h> #include <drivers/st/stm32_gpio.h>
...@@ -465,13 +466,13 @@ int stm32_qspi_init(void) ...@@ -465,13 +466,13 @@ int stm32_qspi_init(void)
return -FDT_ERR_NOTFOUND; return -FDT_ERR_NOTFOUND;
} }
ret = fdt_get_reg_props_by_name(qspi_node, "qspi", ret = fdt_get_reg_props_by_name(fdt, qspi_node, "qspi",
&stm32_qspi.reg_base, &size); &stm32_qspi.reg_base, &size);
if (ret != 0) { if (ret != 0) {
return ret; return ret;
} }
ret = fdt_get_reg_props_by_name(qspi_node, "qspi_mm", ret = fdt_get_reg_props_by_name(fdt, qspi_node, "qspi_mm",
&stm32_qspi.mm_base, &stm32_qspi.mm_base,
&stm32_qspi.mm_size); &stm32_qspi.mm_size);
if (ret != 0) { if (ret != 0) {
......
...@@ -30,5 +30,8 @@ int fdtw_write_inplace_bytes(void *dtb, int node, const char *prop, ...@@ -30,5 +30,8 @@ int fdtw_write_inplace_bytes(void *dtb, int node, const char *prop,
unsigned int length, const void *data); unsigned int length, const void *data);
int fdt_get_reg_props_by_index(const void *dtb, int node, int index, int fdt_get_reg_props_by_index(const void *dtb, int node, int index,
uintptr_t *base, size_t *size); uintptr_t *base, size_t *size);
int fdt_get_reg_props_by_name(const void *dtb, int node, const char *name,
uintptr_t *base, size_t *size);
int fdt_get_stdout_node_offset(const void *dtb);
#endif /* FDT_WRAPPERS_H */ #endif /* FDT_WRAPPERS_H */
...@@ -24,10 +24,13 @@ fdt fdt_setprop_inplace_namelen_partial ...@@ -24,10 +24,13 @@ fdt fdt_setprop_inplace_namelen_partial
fdt fdt_first_subnode fdt fdt_first_subnode
fdt fdt_next_subnode fdt fdt_next_subnode
fdt fdt_path_offset fdt fdt_path_offset
fdt fdt_path_offset_namelen
fdt fdt_subnode_offset fdt fdt_subnode_offset
fdt fdt_address_cells fdt fdt_address_cells
fdt fdt_size_cells fdt fdt_size_cells
fdt fdt_parent_offset fdt fdt_parent_offset
fdt fdt_stringlist_search
fdt fdt_get_alias_namelen
mbedtls mbedtls_asn1_get_alg mbedtls mbedtls_asn1_get_alg
mbedtls mbedtls_asn1_get_alg_null mbedtls mbedtls_asn1_get_alg_null
mbedtls mbedtls_asn1_get_bitstring_null mbedtls mbedtls_asn1_get_bitstring_null
......
...@@ -24,6 +24,10 @@ fdt fdt_setprop_inplace_namelen_partial ...@@ -24,6 +24,10 @@ fdt fdt_setprop_inplace_namelen_partial
fdt fdt_first_subnode fdt fdt_first_subnode
fdt fdt_next_subnode fdt fdt_next_subnode
fdt fdt_parent_offset fdt fdt_parent_offset
fdt fdt_stringlist_search
fdt fdt_get_alias_namelen
fdt fdt_path_offset
fdt fdt_path_offset_namelen
mbedtls mbedtls_asn1_get_alg mbedtls mbedtls_asn1_get_alg
mbedtls mbedtls_asn1_get_alg_null mbedtls mbedtls_asn1_get_alg_null
mbedtls mbedtls_asn1_get_bitstring_null mbedtls mbedtls_asn1_get_bitstring_null
......
...@@ -28,8 +28,6 @@ int dt_open_and_check(void); ...@@ -28,8 +28,6 @@ int dt_open_and_check(void);
int fdt_get_address(void **fdt_addr); int fdt_get_address(void **fdt_addr);
bool fdt_check_node(int node); bool fdt_check_node(int node);
uint8_t fdt_get_status(int node); uint8_t fdt_get_status(int node);
int fdt_get_reg_props_by_name(int node, const char *name, uintptr_t *base,
size_t *size);
int dt_set_stdout_pinctrl(void); int dt_set_stdout_pinctrl(void);
void dt_fill_device_info(struct dt_node_info *info, int node); void dt_fill_device_info(struct dt_node_info *info, int node);
int dt_get_node(struct dt_node_info *info, int offset, const char *compat); int dt_get_node(struct dt_node_info *info, int offset, const char *compat);
......
...@@ -135,92 +135,6 @@ static int fdt_get_node_parent_size_cells(int node) ...@@ -135,92 +135,6 @@ static int fdt_get_node_parent_size_cells(int node)
} }
#endif #endif
/*******************************************************************************
* This function fills reg node info (base & size) with an index found by
* checking the reg-names node.
* Returns 0 on success and a negative FDT error code on failure.
******************************************************************************/
int fdt_get_reg_props_by_name(int node, const char *name, uintptr_t *base,
size_t *size)
{
const fdt32_t *cuint;
int index, len;
assert((fdt_get_node_parent_address_cells(node) == 1) &&
(fdt_get_node_parent_size_cells(node) == 1));
index = fdt_stringlist_search(fdt, node, "reg-names", name);
if (index < 0) {
return index;
}
cuint = fdt_getprop(fdt, node, "reg", &len);
if (cuint == NULL) {
return -FDT_ERR_NOTFOUND;
}
if ((index * (int)sizeof(uint32_t)) > len) {
return -FDT_ERR_BADVALUE;
}
cuint += index << 1;
if (base != NULL) {
*base = fdt32_to_cpu(*cuint);
}
cuint++;
if (size != NULL) {
*size = fdt32_to_cpu(*cuint);
}
return 0;
}
/*******************************************************************************
* This function gets the stdout path node.
* It reads the value indicated inside the device tree.
* Returns node offset on success and a negative FDT error code on failure.
******************************************************************************/
static int dt_get_stdout_node_offset(void)
{
int node;
const char *cchar;
node = fdt_path_offset(fdt, "/secure-chosen");
if (node < 0) {
node = fdt_path_offset(fdt, "/chosen");
if (node < 0) {
return -FDT_ERR_NOTFOUND;
}
}
cchar = fdt_getprop(fdt, node, "stdout-path", NULL);
if (cchar == NULL) {
return -FDT_ERR_NOTFOUND;
}
node = -FDT_ERR_NOTFOUND;
if (strchr(cchar, (int)':') != NULL) {
const char *name;
char *str = (char *)cchar;
int len = 0;
while (strncmp(":", str, 1)) {
len++;
str++;
}
name = fdt_get_alias_namelen(fdt, cchar, len);
if (name != NULL) {
node = fdt_path_offset(fdt, name);
}
} else {
node = fdt_path_offset(fdt, cchar);
}
return node;
}
/******************************************************************************* /*******************************************************************************
* This function gets the stdout pin configuration information from the DT. * This function gets the stdout pin configuration information from the DT.
* And then calls the sub-function to treat it and set GPIO registers. * And then calls the sub-function to treat it and set GPIO registers.
...@@ -230,7 +144,7 @@ int dt_set_stdout_pinctrl(void) ...@@ -230,7 +144,7 @@ int dt_set_stdout_pinctrl(void)
{ {
int node; int node;
node = dt_get_stdout_node_offset(); node = fdt_get_stdout_node_offset(fdt);
if (node < 0) { if (node < 0) {
return -FDT_ERR_NOTFOUND; return -FDT_ERR_NOTFOUND;
} }
...@@ -299,7 +213,7 @@ int dt_get_stdout_uart_info(struct dt_node_info *info) ...@@ -299,7 +213,7 @@ int dt_get_stdout_uart_info(struct dt_node_info *info)
{ {
int node; int node;
node = dt_get_stdout_node_offset(); node = fdt_get_stdout_node_offset(fdt);
if (node < 0) { if (node < 0) {
return -FDT_ERR_NOTFOUND; return -FDT_ERR_NOTFOUND;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment