git: a2bd4cd7863c - stable/13 - bus_if: Add a default implementation of get_property
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 29 Mar 2022 23:00:01 UTC
The branch stable/13 has been updated by mw: URL: https://cgit.FreeBSD.org/src/commit/?id=a2bd4cd7863c2fefe4e91443b84f63468d7138c0 commit a2bd4cd7863c2fefe4e91443b84f63468d7138c0 Author: Kornel Duleba <mindal@semihalf.com> AuthorDate: 2022-01-25 10:10:55 +0000 Commit: Marcin Wojtas <mw@FreeBSD.org> CommitDate: 2022-03-29 22:24:28 +0000 bus_if: Add a default implementation of get_property There are multiple buses that pretend to be ofw compatible, e.g ofw_pci, mii_fdt. We now need to provide an implementation of BUS_GET_PROPERTY for every one of them. Instead of modifying them one by one it's better to just provide a default implementation that simply traverses up the device tree. Remove the now unneeded BUS_GET_PROPERTY implementation in mii_fdt. Reviewed by: andrew, bz Obtained from: Semihalf MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D34031 (cherry picked from commit 206dc82bc3fc5e1d90200e189ce5f2240dfec874) --- sys/dev/mii/mii_fdt.c | 15 --------------- sys/kern/bus_if.m | 9 +-------- sys/kern/subr_bus.c | 17 +++++++++++++++++ sys/sys/bus.h | 3 +++ 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/sys/dev/mii/mii_fdt.c b/sys/dev/mii/mii_fdt.c index 387b02f69504..9cf3fd2fab37 100644 --- a/sys/dev/mii/mii_fdt.c +++ b/sys/dev/mii/mii_fdt.c @@ -326,20 +326,6 @@ miibus_fdt_get_devinfo(device_t bus, device_t child) return (&ma->obd); } -static ssize_t -miibus_fdt_get_property(device_t bus, device_t child, const char *propname, - void *buf, size_t size) -{ - struct mii_attach_args *ma; - - ma = device_get_ivars(child); - - if (ma->obd.obd_node == 0) - return (-1); - - return (OF_getencprop(ma->obd.obd_node, propname, buf, size)); -} - static device_method_t miibus_fdt_methods[] = { DEVMETHOD(device_probe, miibus_fdt_probe), DEVMETHOD(device_attach, miibus_fdt_attach), @@ -362,7 +348,6 @@ static device_method_t miibus_fdt_methods[] = { DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource), DEVMETHOD(bus_set_resource, bus_generic_rl_set_resource), DEVMETHOD(bus_get_resource_list, miibus_fdt_get_resource_list), - DEVMETHOD(bus_get_property, miibus_fdt_get_property), DEVMETHOD_END }; diff --git a/sys/kern/bus_if.m b/sys/kern/bus_if.m index 463d3fe38872..5b6577b963ec 100644 --- a/sys/kern/bus_if.m +++ b/sys/kern/bus_if.m @@ -88,13 +88,6 @@ CODE { *newstart = start; return (0); } - - static ssize_t - null_get_property(device_t dev, device_t child, const char *propname, - void *propvalue, size_t size) - { - return (-1); - } }; /** @@ -962,4 +955,4 @@ METHOD ssize_t get_property { const char *_propname; void *_propvalue; size_t _size; -} DEFAULT null_get_property; +} DEFAULT bus_generic_get_property; diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index 3949e0b29220..0139eb31f976 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -4062,6 +4062,23 @@ bus_generic_write_ivar(device_t dev, device_t child, int index, return (ENOENT); } +/** + * @brief Helper function for implementing BUS_GET_PROPERTY(). + * + * This simply calls the BUS_GET_PROPERTY of the parent of dev, + * until a non-default implementation is found. + */ +ssize_t +bus_generic_get_property(device_t dev, device_t child, const char *propname, + void *propvalue, size_t size) +{ + if (device_get_parent(dev) != NULL) + return (BUS_GET_PROPERTY(device_get_parent(dev), child, + propname, propvalue, size)); + + return (-1); +} + /** * @brief Stub function for implementing BUS_GET_RESOURCE_LIST(). * diff --git a/sys/sys/bus.h b/sys/sys/bus.h index 4c7d094c24b0..6500a283a7f5 100644 --- a/sys/sys/bus.h +++ b/sys/sys/bus.h @@ -441,6 +441,9 @@ bus_dma_tag_t bus_space_tag_t bus_generic_get_bus_tag(device_t dev, device_t child); int bus_generic_get_domain(device_t dev, device_t child, int *domain); +ssize_t bus_generic_get_property(device_t dev, device_t child, + const char *propname, void *propvalue, + size_t size); struct resource_list * bus_generic_get_resource_list (device_t, device_t); int bus_generic_map_resource(device_t dev, device_t child, int type,