Date: Thu, 10 Mar 2022 11:29:35 GMT From: Marcin Wojtas <mw@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 206dc82bc3fc - main - bus_if: Add a default implementation of get_property Message-ID: <202203101129.22ABTZEx031925@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by mw: URL: https://cgit.FreeBSD.org/src/commit/?id=206dc82bc3fc5e1d90200e189ce5f2240dfec874 commit 206dc82bc3fc5e1d90200e189ce5f2240dfec874 Author: Kornel Duleba <mindal@semihalf.com> AuthorDate: 2022-01-25 10:10:55 +0000 Commit: Marcin Wojtas <mw@FreeBSD.org> CommitDate: 2022-03-10 11:11:32 +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 --- sys/dev/mii/mii_fdt.c | 15 --------------- sys/kern/bus_if.m | 8 +------- sys/kern/subr_bus.c | 17 +++++++++++++++++ sys/sys/bus.h | 3 +++ 4 files changed, 21 insertions(+), 22 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 ef0f5e9eb65a..cf6470c220ef 100644 --- a/sys/kern/bus_if.m +++ b/sys/kern/bus_if.m @@ -77,12 +77,6 @@ CODE { return (0); } - static ssize_t - null_get_property(device_t dev, device_t child, const char *propname, - void *propvalue, size_t size) - { - return (-1); - } }; /** @@ -944,7 +938,7 @@ METHOD ssize_t get_property { const char *_propname; void *_propvalue; size_t _size; -} DEFAULT null_get_property; +} DEFAULT bus_generic_get_property; /** * @brief Gets a child's full path to the device diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index 5e6cfa162f4c..8a05c28c96b1 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -4125,6 +4125,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 d31eb31a362a..0b4f85a7fd0d 100644 --- a/sys/sys/bus.h +++ b/sys/sys/bus.h @@ -444,6 +444,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,
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202203101129.22ABTZEx031925>