mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-09-21 15:12:04 +00:00
fdt: Add a function to return PCI BDF triplet
The fdtdec_pci_get_bdf() function returns the bus, device, function triplet of a PCI device by parsing the "reg" property according to the PCI device tree binding. Acked-by: Simon Glass <sjg@chromium.org> Signed-off-by: Thierry Reding <treding@nvidia.com>
This commit is contained in:
parent
56f42242f0
commit
9f85eee72a
2 changed files with 25 additions and 0 deletions
|
@ -649,4 +649,15 @@ int fdt_get_named_resource(const void *fdt, int node, const char *property,
|
||||||
const char *prop_names, const char *name,
|
const char *prop_names, const char *name,
|
||||||
struct fdt_resource *res);
|
struct fdt_resource *res);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Look at the reg property of a device node that represents a PCI device
|
||||||
|
* and parse the bus, device and function number from it.
|
||||||
|
*
|
||||||
|
* @param fdt FDT blob
|
||||||
|
* @param node node to examine
|
||||||
|
* @param bdf returns bus, device, function triplet
|
||||||
|
* @return 0 if ok, negative on error
|
||||||
|
*/
|
||||||
|
int fdtdec_pci_get_bdf(const void *fdt, int node, int *bdf);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
14
lib/fdtdec.c
14
lib/fdtdec.c
|
@ -765,4 +765,18 @@ int fdt_get_named_resource(const void *fdt, int node, const char *property,
|
||||||
|
|
||||||
return fdt_get_resource(fdt, node, property, index, res);
|
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
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue