[PATCH 00/13] drivers: Introduce generic device lookup helpers

Suzuki K Poulose suzuki.poulose at arm.com
Wed Jun 5 15:13:37 UTC 2019


We have device iterators to find a particular device matching a criteria
for a given bus/class/driver. i.e, {bus,class,driver}_find_device() APIs.
The matching criteria is a function pointer for the APIs. Often the lookup
is based on a generic property of a device (e.g, name, fwnode, of node pointer
or device type) rather than a driver specific information. However, each driver
writes up its own "match" function, spilling the similar match functions all
over the driver subsystems.

Additionally the prototype for the "match" functions accepted by the above APIs
have a minute difference which prevents us otherwise sharing the match functions.
i.e,
	int (*match)(struct device *dev, void *data) for {bus/driver}_find_device()
	  vs
	int (*match)(struct device *dev, const void *) for class_find_device()

If we promote the former to accept a "const void*" parameter, we could share one
single match function for all the helpers. This series achieves the following:

 1) Unify the prototype for "match" functions accepted by the device lookup APIs.
 2) Introduce generic match functions to match devices by the generic attributes
    of a device (e.g, name, fwnode, of_node and devt).

Also, in order to prevent creation of such match functions in the future,
we introduce wrapper functions for the look up APIs, which automatically
uses the appropriate match functions.

i.e,
	{bus/class/driver}_find_device_by_name
	{bus/class/driver}_find_device_by_of_node
	{bus/class/driver}_find_device_by_fwnode
	{bus/class/driver}_find_device_by_devt

Additionally, this series also adds wrapper for finding a device by matching
a device driver for platform bus devices - platform_find_device_by_driver() to
avoid a few drivers hard coding the platform bus specific details.

This is part 1 of revised version of the series posted here [0], to allow for better
management of the merging. Part 2 of the series, where these new helpers are consumed
by the individual driver subsystems will be posted once this is series is merged.
The entire tree with both the parts in is available at [1]

[0] https://marc.info/?i=1559577023-558-1-git-send-email-suzuki.poulose@arm.com
[1] git://linux-arm.org/linux-skp.git driver-cleanup/v1

Cc: Alan Tull <atull at kernel.org>
Cc: Alessandro Zummo <a.zummo at towertech.it>
Cc: Alexander Aring <alex.aring at gmail.com>
Cc: Alexander Shishkin <alexander.shishkin at linux.intel.com>
Cc: Alexandre Belloni <alexandre.belloni at bootlin.com>
Cc: Andreas Noever <andreas.noever at gmail.com>
Cc: Andrew Lunn <andrew at lunn.ch>
Cc: Arnd Bergmann <arnd at arndb.de>
Cc: Bjorn Helgaas <bhelgaas at google.com>
Cc: Corey Minyard <minyard at acm.org>
Cc: Daniel Vetter <daniel at ffwll.ch>
Cc: Dan Murphy <dmurphy at ti.com>
Cc: David Airlie <airlied at linux.ie>
Cc: David Kershner <david.kershner at unisys.com>
Cc: "David S. Miller" <davem at davemloft.net>
Cc: Doug Ledford <dledford at redhat.com>
Cc: dri-devel at lists.freedesktop.org
Cc: Elie Morisse <syniurge at gmail.com>
Cc: Eric Anholt <eric at anholt.net>
Cc: Felipe Balbi <balbi at kernel.org>
Cc: Florian Fainelli <f.fainelli at gmail.com>
Cc: Frank Rowand <frowand.list at gmail.com>
Cc: Grant Likely <grant.likely at arm.com>
Cc: Greg Kroah-Hartman <gregkh at linuxfoundation.org>
Cc: Grygorii Strashko <grygorii.strashko at ti.com>
Cc: Harald Freudenberger <freude at linux.ibm.com>
Cc: Hartmut Knaack <knaack.h at gmx.de>
Cc: Heikki Krogerus <heikki.krogerus at linux.intel.com>
Cc: Heiko Carstens <heiko.carstens at de.ibm.com>
Cc: "Heiko Stübner" <heiko at sntech.de>
Cc: Heiko Stuebner <heiko at sntech.de>
Cc: Heiner Kallweit <hkallweit1 at gmail.com>
Cc: Inki Dae <inki.dae at samsung.com>
Cc: Jacek Anaszewski <jacek.anaszewski at gmail.com>
Cc: "James E.J. Bottomley" <jejb at linux.ibm.com>
Cc: Jason Gunthorpe <jgg at ziepe.ca>
Cc: Jiri Slaby <jslaby at suse.com>
Cc: Joe Perches <joe at perches.com>
Cc: Joerg Roedel <joro at 8bytes.org>
Cc: Jonathan Cameron <jic23 at kernel.org>
Cc: Jonathan Hunter <jonathanh at nvidia.com>
Cc: Lee Jones <lee.jones at linaro.org>
Cc: Len Brown <lenb at kernel.org
Cc: Liam Girdwood <lgirdwood at gmail.com>
Cc: Maarten Lankhorst <maarten.lankhorst at linux.intel.com>
Cc: Mark Brown <broonie at kernel.org>
Cc: "Martin K. Petersen" <martin.petersen at oracle.com>
Cc: Mathieu Poirier <mathieu.poirier at linaro.org>
Cc: Maxime Coquelin <mcoquelin.stm32 at gmail.com>
Cc: Maxime Ripard <maxime.ripard at bootlin.com>
Cc: Michael Jamet <michael.jamet at intel.com>
Cc: Mika Westerberg <mika.westerberg at linux.intel.com>
Cc: Moritz Fischer <mdf at kernel.org>
Cc: Nehal Shah <nehal-bakulchandra.shah at amd.com>
Cc: Oliver Neukum <oneukum at suse.com>
Cc: Pavel Machek <pavel at ucw.cz>
Cc: Peter Oberparleiter <oberpar at linux.ibm.com>
Cc: Peter Rosin <peda at axentia.se>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki at intel.com>
Cc: "Rafael J. Wysocki" <rafael at kernel.org>
Cc: Rafael J. Wysocki" <rjw at rjwysocki.net>
Cc: Rob Herring <robh+dt at kernel.org>
Cc: Robin Murphy <robin.murphy at arm.com>
Cc: Russell King <linux at armlinux.org.uk>
Cc: Sandy Huang <hjc at rock-chips.com>
Cc: Sebastian Andrzej Siewior <bigeasy at linutronix.de>
Cc: Sebastian Ott <sebott at linux.ibm.com>
Cc: Seung-Woo Kim <sw0312.kim at samsung.com>
Cc: Shyam Sundar S K <shyam-sundar.s-k at amd.com>
Cc: Srinivas Kandagatla <srinivas.kandagatla at linaro.org>
Cc: Stefan Schmidt <stefan at datenfreihafen.org>
Cc: Takashi Iwai <tiwai at suse.com>
Cc: Thierry Reding <thierry.reding at gmail.com>
Cc: Thor Thayer <thor.thayer at linux.intel.com>
Cc: Tomas Winkler <tomas.winkler at intel.com>
Cc: Ulf Hansson <ulf.hansson at linaro.org>
Cc: Will Deacon <will.deacon at arm.com>
Cc: Wolfram Sang <wsa at the-dreams.de>
Cc: devicetree at vger.kernel.org
Cc: linux-acpi at vger.kernel.org
Cc: linux-fpga at vger.kernel.org
Cc: linux-i2c at vger.kernel.org
Cc: linux-leds at vger.kernel.org
Cc: linux-rockchip at lists.infradead.org
Cc: linux-rtc at vger.kernel.org
Cc: linux-spi at vger.kernel.org
Cc: linux-usb at vger.kernel.org
Cc: linux-wpan at vger.kernel.org

Suzuki K Poulose (13):
  acpi: utils: Cleanup acpi_dev_match_cb
  bus_find_device: Unify the match callback with class_find_device
  driver_find_device: Unify the match function with class_find_device()
  drivers: Add generic helper to match by of_node
  drivers: Add generic helper to match by fwnode
  drivers: Add generic helper to match by devt
  drivers: Add generic match helper by ACPI_COMPANION device
  drivers: Add generic helper to match by name
  drivers: Add generic helper to match any device
  drivers: Introduce variants of class_find_device()
  drivers: Introduce variants for bus_find_device()
  drivers: Introduce variants of driver_find_device()
  platform: Add platform_find_device_by_driver() helper

 arch/powerpc/platforms/pseries/ibmebus.c           |   4 +-
 drivers/acpi/acpi_lpss.c                           |   4 +-
 drivers/acpi/sleep.c                               |   2 +-
 drivers/acpi/utils.c                               |  11 +-
 drivers/amba/tegra-ahb.c                           |   4 +-
 drivers/base/bus.c                                 |  28 +--
 drivers/base/core.c                                |  36 ++++
 drivers/base/devcon.c                              |   2 +-
 drivers/base/driver.c                              |   4 +-
 drivers/base/platform.c                            |  14 ++
 drivers/char/ipmi/ipmi_msghandler.c                |   8 +-
 drivers/char/ipmi/ipmi_si_platform.c               |   2 +-
 drivers/firmware/efi/dev-path-parser.c             |   4 +-
 drivers/gpu/drm/drm_mipi_dsi.c                     |   2 +-
 drivers/gpu/drm/tegra/dc.c                         |   4 +-
 drivers/hwtracing/coresight/coresight.c            |   6 +-
 drivers/hwtracing/coresight/of_coresight.c         |   2 +-
 drivers/hwtracing/intel_th/core.c                  |   5 +-
 drivers/i2c/busses/i2c-amd-mp2-pci.c               |   2 +-
 drivers/i2c/i2c-core-acpi.c                        |   4 +-
 drivers/i2c/i2c-core-of.c                          |   4 +-
 drivers/iio/inkern.c                               |   2 +-
 drivers/infiniband/hw/hns/hns_roce_hw_v1.c         |   2 +-
 drivers/iommu/arm-smmu-v3.c                        |   2 +-
 drivers/iommu/arm-smmu.c                           |   2 +-
 drivers/mfd/altera-sysmgr.c                        |   4 +-
 drivers/mfd/syscon.c                               |   2 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c |   2 +-
 drivers/net/ethernet/ti/cpsw-phy-sel.c             |   4 +-
 drivers/net/ethernet/ti/davinci_emac.c             |   2 +-
 drivers/net/ethernet/toshiba/tc35815.c             |   4 +-
 drivers/nvmem/core.c                               |   2 +-
 drivers/of/of_mdio.c                               |   2 +-
 drivers/of/platform.c                              |   2 +-
 drivers/pci/probe.c                                |   2 +-
 drivers/pci/search.c                               |   4 +-
 drivers/s390/cio/ccwgroup.c                        |   2 +-
 drivers/s390/cio/chsc_sch.c                        |   2 +-
 drivers/s390/cio/css.c                             |   4 +-
 drivers/s390/cio/device.c                          |   6 +-
 drivers/s390/cio/scm.c                             |   4 +-
 drivers/s390/crypto/ap_bus.c                       |   8 +-
 drivers/scsi/scsi_proc.c                           |   2 +-
 drivers/spi/spi.c                                  |   4 +-
 drivers/staging/most/core.c                        |   4 +-
 drivers/thunderbolt/switch.c                       |   4 +-
 drivers/usb/core/devio.c                           |   4 +-
 drivers/usb/core/usb.c                             |   4 +-
 drivers/usb/phy/phy-am335x-control.c               |   4 +-
 drivers/usb/phy/phy-isp1301.c                      |   4 +-
 drivers/visorbus/visorbus_main.c                   |   4 +-
 include/linux/device.h                             | 188 ++++++++++++++++++++-
 include/linux/platform_device.h                    |   3 +
 sound/soc/rockchip/rk3399_gru_sound.c              |   2 +-
 54 files changed, 320 insertions(+), 123 deletions(-)

-- 
2.7.4



More information about the dri-devel mailing list