summaryrefslogtreecommitdiff
path: root/lib/fdtdec.c
diff options
context:
space:
mode:
authorTom Rini <trini@ti.com>2014-10-23 06:51:46 -0400
committerTom Rini <trini@ti.com>2014-10-23 06:51:46 -0400
commit21109577635a871d038cfd53dd75e264d0e636bf (patch)
tree52794ad871923cc6bb1944c3f3a9dde5a5365be9 /lib/fdtdec.c
parent68e80fdda1336068f40915388bbdacfd2b75233a (diff)
parent2f3760428ff3c4d5d1a087d016da5943921f0980 (diff)
downloadu-boot-imx-21109577635a871d038cfd53dd75e264d0e636bf.zip
u-boot-imx-21109577635a871d038cfd53dd75e264d0e636bf.tar.gz
u-boot-imx-21109577635a871d038cfd53dd75e264d0e636bf.tar.bz2
Merge git://git.denx.de/u-boot-fdt
Diffstat (limited to 'lib/fdtdec.c')
-rw-r--r--lib/fdtdec.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 06d4542..4f66ae1 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -708,4 +708,75 @@ int fdtdec_read_fmap_entry(const void *blob, int node, const char *name,
return 0;
}
+
+static u64 fdtdec_get_number(const fdt32_t *ptr, unsigned int cells)
+{
+ u64 number = 0;
+
+ while (cells--)
+ number = (number << 32) | fdt32_to_cpu(*ptr++);
+
+ return number;
+}
+
+int fdt_get_resource(const void *fdt, int node, const char *property,
+ unsigned int index, struct fdt_resource *res)
+{
+ const fdt32_t *ptr, *end;
+ int na, ns, len, parent;
+ unsigned int i = 0;
+
+ parent = fdt_parent_offset(fdt, node);
+ if (parent < 0)
+ return parent;
+
+ na = fdt_address_cells(fdt, parent);
+ ns = fdt_size_cells(fdt, parent);
+
+ ptr = fdt_getprop(fdt, node, property, &len);
+ if (!ptr)
+ return len;
+
+ end = ptr + len / sizeof(*ptr);
+
+ while (ptr + na + ns <= end) {
+ if (i == index) {
+ res->start = res->end = fdtdec_get_number(ptr, na);
+ res->end += fdtdec_get_number(&ptr[na], ns) - 1;
+ return 0;
+ }
+
+ ptr += na + ns;
+ i++;
+ }
+
+ return -FDT_ERR_NOTFOUND;
+}
+
+int fdt_get_named_resource(const void *fdt, int node, const char *property,
+ const char *prop_names, const char *name,
+ struct fdt_resource *res)
+{
+ int index;
+
+ index = fdt_find_string(fdt, node, prop_names, name);
+ if (index < 0)
+ return index;
+
+ return fdt_get_resource(fdt, node, property, index, res);
+}
+
+int fdtdec_pci_get_bdf(const void *fdt, int node, int *bdf)
+{
+ const fdt32_t *prop;
+ int len;
+
+ prop = fdt_getprop(fdt, node, "reg", &len);
+ if (!prop)
+ return len;
+
+ *bdf = fdt32_to_cpu(*prop) & 0xffffff;
+
+ return 0;
+}
#endif