Message ID | 20191029210821.1954-4-suneelglinux@gmail.com |
---|---|
State | RFC |
Delegated to: | Tom Rini |
Headers | show |
Series | arm: Introduce Marvell/Cavium OcteonTX | expand |
Hi Suneel, On Tue, 29 Oct 2019 at 14:08, Suneel Garapati <suneelglinux@gmail.com> wrote: > > From: Suneel Garapati <sgarapati@marvell.com> > > Add fdtdec_get_pci_bus_range to read bus-range property > values. > > Signed-off-by: Suneel Garapati <sgarapati@marvell.com> > --- > include/fdtdec.h | 12 ++++++++++++ > lib/fdtdec.c | 16 ++++++++++++++++ > 2 files changed, 28 insertions(+) > > diff --git a/include/fdtdec.h b/include/fdtdec.h > index f1e58f9732..afbd22b25a 100644 > --- a/include/fdtdec.h > +++ b/include/fdtdec.h > @@ -441,6 +441,18 @@ int fdtdec_get_pci_vendev(const void *blob, int node, > int fdtdec_get_pci_bar32(struct udevice *dev, struct fdt_pci_addr *addr, > u32 *bar); > > +/** > + * Look at the bus range property of a device node and return the pci bus > + * range for this node. > + * The property must hold one fdt_pci_addr with a length. > + * @param blob FDT blob > + * @param node node to examine > + * @param res the resource structure to return the bus range @return > + */ > + > +int fdtdec_get_pci_bus_range(const void *blob, int node, > + struct fdt_resource *res); > + > /** > * 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 > diff --git a/lib/fdtdec.c b/lib/fdtdec.c > index 17736ce665..fb61eda1fd 100644 > --- a/lib/fdtdec.c > +++ b/lib/fdtdec.c > @@ -237,6 +237,22 @@ int fdtdec_get_pci_bar32(struct udevice *dev, struct fdt_pci_addr *addr, > > return 0; > } > + > +int fdtdec_get_pci_bus_range(const void *blob, int node, > + struct fdt_resource *res) This should have a livetree version too I think and a test. > +{ > + const u32 *values; > + int len; > + > + values = fdt_getprop(blob, node, "bus-range", &len); > + if (!values || len < sizeof(*values) * 2) > + return -EINVAL; > + > + res->start = be32_to_cpup(values++); I think these should use fdt32_ld() > + res->end = be32_to_cpup(values); > + > + return 0; > +} > #endif > > uint64_t fdtdec_get_uint64(const void *blob, int node, const char *prop_name, > -- > 2.23.0 > Regards, Simon
diff --git a/include/fdtdec.h b/include/fdtdec.h index f1e58f9732..afbd22b25a 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -441,6 +441,18 @@ int fdtdec_get_pci_vendev(const void *blob, int node, int fdtdec_get_pci_bar32(struct udevice *dev, struct fdt_pci_addr *addr, u32 *bar); +/** + * Look at the bus range property of a device node and return the pci bus + * range for this node. + * The property must hold one fdt_pci_addr with a length. + * @param blob FDT blob + * @param node node to examine + * @param res the resource structure to return the bus range + */ + +int fdtdec_get_pci_bus_range(const void *blob, int node, + struct fdt_resource *res); + /** * 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 diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 17736ce665..fb61eda1fd 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -237,6 +237,22 @@ int fdtdec_get_pci_bar32(struct udevice *dev, struct fdt_pci_addr *addr, return 0; } + +int fdtdec_get_pci_bus_range(const void *blob, int node, + struct fdt_resource *res) +{ + const u32 *values; + int len; + + values = fdt_getprop(blob, node, "bus-range", &len); + if (!values || len < sizeof(*values) * 2) + return -EINVAL; + + res->start = be32_to_cpup(values++); + res->end = be32_to_cpup(values); + + return 0; +} #endif uint64_t fdtdec_get_uint64(const void *blob, int node, const char *prop_name,