summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSandrine Bailleux <sandrine.bailleux@arm.com>2020-05-07 08:59:33 +0000
committerTrustedFirmware Code Review <review@review.trustedfirmware.org>2020-05-07 08:59:33 +0000
commit85838f4829331f3fbdec72560f6bd93c991c1f12 (patch)
treef7c1cd435e7bb5bfedccd19b36ab72732be658b4
parentfcfc96d63b90510e83755e81059b47977bcf7073 (diff)
parent7a61114da619f3d0fe0d068f879ad2f7f99ee3c4 (diff)
downloadarm-trusted-firmware-85838f4829331f3fbdec72560f6bd93c991c1f12.tar.gz
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()
-rw-r--r--common/fdt_wrappers.c65
-rw-r--r--drivers/st/spi/stm32_qspi.c5
-rw-r--r--include/common/fdt_wrappers.h3
-rw-r--r--plat/arm/board/fvp/jmptbl.i3
-rw-r--r--plat/arm/board/juno/jmptbl.i4
-rw-r--r--plat/st/common/include/stm32mp_dt.h2
-rw-r--r--plat/st/common/stm32mp_dt.c90
7 files changed, 80 insertions, 92 deletions
diff --git a/common/fdt_wrappers.c b/common/fdt_wrappers.c
index 842d71339..1901a2040 100644
--- a/common/fdt_wrappers.c
+++ b/common/fdt_wrappers.c
@@ -276,3 +276,68 @@ int fdt_get_reg_props_by_index(const void *dtb, int node, int index,
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);
+}
diff --git a/drivers/st/spi/stm32_qspi.c b/drivers/st/spi/stm32_qspi.c
index c5e4ea86e..ff92796e7 100644
--- a/drivers/st/spi/stm32_qspi.c
+++ b/drivers/st/spi/stm32_qspi.c
@@ -9,6 +9,7 @@
#include <platform_def.h>
#include <common/debug.h>
+#include <common/fdt_wrappers.h>
#include <drivers/delay_timer.h>
#include <drivers/spi_mem.h>
#include <drivers/st/stm32_gpio.h>
@@ -465,13 +466,13 @@ int stm32_qspi_init(void)
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);
if (ret != 0) {
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_size);
if (ret != 0) {
diff --git a/include/common/fdt_wrappers.h b/include/common/fdt_wrappers.h
index 7a6b59893..382651e5d 100644
--- a/include/common/fdt_wrappers.h
+++ b/include/common/fdt_wrappers.h
@@ -30,5 +30,8 @@ int fdtw_write_inplace_bytes(void *dtb, int node, const char *prop,
unsigned int length, const void *data);
int fdt_get_reg_props_by_index(const void *dtb, int node, int index,
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 */
diff --git a/plat/arm/board/fvp/jmptbl.i b/plat/arm/board/fvp/jmptbl.i
index 50a5ba4d9..213a9749d 100644
--- a/plat/arm/board/fvp/jmptbl.i
+++ b/plat/arm/board/fvp/jmptbl.i
@@ -24,10 +24,13 @@ fdt fdt_setprop_inplace_namelen_partial
fdt fdt_first_subnode
fdt fdt_next_subnode
fdt fdt_path_offset
+fdt fdt_path_offset_namelen
fdt fdt_subnode_offset
fdt fdt_address_cells
fdt fdt_size_cells
fdt fdt_parent_offset
+fdt fdt_stringlist_search
+fdt fdt_get_alias_namelen
mbedtls mbedtls_asn1_get_alg
mbedtls mbedtls_asn1_get_alg_null
mbedtls mbedtls_asn1_get_bitstring_null
diff --git a/plat/arm/board/juno/jmptbl.i b/plat/arm/board/juno/jmptbl.i
index eb4399ec0..09017acdc 100644
--- a/plat/arm/board/juno/jmptbl.i
+++ b/plat/arm/board/juno/jmptbl.i
@@ -24,6 +24,10 @@ fdt fdt_setprop_inplace_namelen_partial
fdt fdt_first_subnode
fdt fdt_next_subnode
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_null
mbedtls mbedtls_asn1_get_bitstring_null
diff --git a/plat/st/common/include/stm32mp_dt.h b/plat/st/common/include/stm32mp_dt.h
index 91a8d67c8..e79551a31 100644
--- a/plat/st/common/include/stm32mp_dt.h
+++ b/plat/st/common/include/stm32mp_dt.h
@@ -28,8 +28,6 @@ int dt_open_and_check(void);
int fdt_get_address(void **fdt_addr);
bool fdt_check_node(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);
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);
diff --git a/plat/st/common/stm32mp_dt.c b/plat/st/common/stm32mp_dt.c
index c76b03358..155f78404 100644
--- a/plat/st/common/stm32mp_dt.c
+++ b/plat/st/common/stm32mp_dt.c
@@ -136,92 +136,6 @@ static int fdt_get_node_parent_size_cells(int node)
#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.
* And then calls the sub-function to treat it and set GPIO registers.
* Returns 0 on success and a negative FDT error code on failure.
@@ -230,7 +144,7 @@ int dt_set_stdout_pinctrl(void)
{
int node;
- node = dt_get_stdout_node_offset();
+ node = fdt_get_stdout_node_offset(fdt);
if (node < 0) {
return -FDT_ERR_NOTFOUND;
}
@@ -299,7 +213,7 @@ int dt_get_stdout_uart_info(struct dt_node_info *info)
{
int node;
- node = dt_get_stdout_node_offset();
+ node = fdt_get_stdout_node_offset(fdt);
if (node < 0) {
return -FDT_ERR_NOTFOUND;
}