mirror of
https://xff.cz/git/u-boot/
synced 2025-09-01 16:52:14 +02:00
fdt: Add fdtdec_get_addr_size() to read reg properties
It is common to have a "reg = <address size>" property in the FDT. Add a function to handle this, similar to the existing fdtdec_get_addr(); Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -38,11 +38,13 @@
|
|||||||
*/
|
*/
|
||||||
#ifdef CONFIG_PHYS_64BIT
|
#ifdef CONFIG_PHYS_64BIT
|
||||||
typedef u64 fdt_addr_t;
|
typedef u64 fdt_addr_t;
|
||||||
|
typedef u64 fdt_size_t;
|
||||||
#define FDT_ADDR_T_NONE (-1ULL)
|
#define FDT_ADDR_T_NONE (-1ULL)
|
||||||
#define fdt_addr_to_cpu(reg) be64_to_cpu(reg)
|
#define fdt_addr_to_cpu(reg) be64_to_cpu(reg)
|
||||||
#define fdt_size_to_cpu(reg) be64_to_cpu(reg)
|
#define fdt_size_to_cpu(reg) be64_to_cpu(reg)
|
||||||
#else
|
#else
|
||||||
typedef u32 fdt_addr_t;
|
typedef u32 fdt_addr_t;
|
||||||
|
typedef u32 fdt_size_t;
|
||||||
#define FDT_ADDR_T_NONE (-1U)
|
#define FDT_ADDR_T_NONE (-1U)
|
||||||
#define fdt_addr_to_cpu(reg) be32_to_cpu(reg)
|
#define fdt_addr_to_cpu(reg) be32_to_cpu(reg)
|
||||||
#define fdt_size_to_cpu(reg) be32_to_cpu(reg)
|
#define fdt_size_to_cpu(reg) be32_to_cpu(reg)
|
||||||
@@ -199,6 +201,19 @@ int fdtdec_next_compatible_subnode(const void *blob, int node,
|
|||||||
fdt_addr_t fdtdec_get_addr(const void *blob, int node,
|
fdt_addr_t fdtdec_get_addr(const void *blob, int node,
|
||||||
const char *prop_name);
|
const char *prop_name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Look up an address property in a node and return it as an address.
|
||||||
|
* The property must hold one address with a length. This is only tested
|
||||||
|
* on 32-bit machines.
|
||||||
|
*
|
||||||
|
* @param blob FDT blob
|
||||||
|
* @param node node to examine
|
||||||
|
* @param prop_name name of property to find
|
||||||
|
* @return address, if found, or FDT_ADDR_T_NONE if not
|
||||||
|
*/
|
||||||
|
fdt_addr_t fdtdec_get_addr_size(const void *blob, int node,
|
||||||
|
const char *prop_name, fdt_size_t *sizep);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Look up a 32-bit integer property in a node and return it. The property
|
* Look up a 32-bit integer property in a node and return it. The property
|
||||||
* must have at least 4 bytes of data. The value of the first cell is
|
* must have at least 4 bytes of data. The value of the first cell is
|
||||||
|
25
lib/fdtdec.c
25
lib/fdtdec.c
@@ -68,25 +68,40 @@ const char *fdtdec_get_compatible(enum fdt_compat_id id)
|
|||||||
return compat_names[id];
|
return compat_names[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
fdt_addr_t fdtdec_get_addr(const void *blob, int node,
|
fdt_addr_t fdtdec_get_addr_size(const void *blob, int node,
|
||||||
const char *prop_name)
|
const char *prop_name, fdt_size_t *sizep)
|
||||||
{
|
{
|
||||||
const fdt_addr_t *cell;
|
const fdt_addr_t *cell;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
debug("%s: %s: ", __func__, prop_name);
|
debug("%s: %s: ", __func__, prop_name);
|
||||||
cell = fdt_getprop(blob, node, prop_name, &len);
|
cell = fdt_getprop(blob, node, prop_name, &len);
|
||||||
if (cell && (len == sizeof(fdt_addr_t) ||
|
if (cell && ((!sizep && len == sizeof(fdt_addr_t)) ||
|
||||||
len == sizeof(fdt_addr_t) * 2)) {
|
len == sizeof(fdt_addr_t) * 2)) {
|
||||||
fdt_addr_t addr = fdt_addr_to_cpu(*cell);
|
fdt_addr_t addr = fdt_addr_to_cpu(*cell);
|
||||||
|
if (sizep) {
|
||||||
|
const fdt_size_t *size;
|
||||||
|
|
||||||
debug("%p\n", (void *)addr);
|
size = (fdt_size_t *)((char *)cell +
|
||||||
|
sizeof(fdt_addr_t));
|
||||||
|
*sizep = fdt_size_to_cpu(*size);
|
||||||
|
debug("addr=%p, size=%p\n", (void *)addr,
|
||||||
|
(void *)*sizep);
|
||||||
|
} else {
|
||||||
|
debug("%p\n", (void *)addr);
|
||||||
|
}
|
||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
debug("(not found)\n");
|
debug("(not found)\n");
|
||||||
return FDT_ADDR_T_NONE;
|
return FDT_ADDR_T_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fdt_addr_t fdtdec_get_addr(const void *blob, int node,
|
||||||
|
const char *prop_name)
|
||||||
|
{
|
||||||
|
return fdtdec_get_addr_size(blob, node, prop_name, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
s32 fdtdec_get_int(const void *blob, int node, const char *prop_name,
|
s32 fdtdec_get_int(const void *blob, int node, const char *prop_name,
|
||||||
s32 default_val)
|
s32 default_val)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user