On 2016/8/15 23:23, Lorenzo Pieralisi wrote:
The platform device kernel API does not provide functions to retrieve a platform device through the corresponding struct device fwnode pointer. Implement the fwnode platform_device look-up in drivers core code by using the bus_find_device() API and a corresponding matching function. The OF equivalent (eg of_find_device_by_node()) will reuse the newly introduced function when OF code will take care of setting up the device->fwnode value that is currently left dangling for platform devices instantiated out of device tree nodes. Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@xxxxxxx> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> Cc: "Rafael J. Wysocki" <rjw@xxxxxxxxxxxxx> --- drivers/base/platform.c | 23 +++++++++++++++++++++++ include/linux/platform_device.h | 3 +++ 2 files changed, 26 insertions(+) diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 6482d47..3ef150d 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -760,6 +760,29 @@ err_out: } EXPORT_SYMBOL_GPL(__platform_create_bundle); +static int fwnode_dev_match(struct device *dev, void *data) +{ + return dev->fwnode == data; +} + +/** + * platform_find_device_by_fwnode() - Find the platform_device associated + * with a fwnode + * @fwnode: Pointer to firmware node + * + * Returns platform_device pointer, or NULL if not found + */ +struct platform_device * +platform_find_device_by_fwnode(struct fwnode_handle *fwnode) +{ + struct device *dev; + + dev = bus_find_device(&platform_bus_type, NULL, fwnode, + fwnode_dev_match); + return dev ? to_platform_device(dev) : NULL; +} +EXPORT_SYMBOL(platform_find_device_by_fwnode);
As SMMU is registered as platform devices, I think we need such API to retrieve the platform device with fwnode handle, actually Kefeng introduced a similar patch [1], but your patch is more generic, so this patch make sense to me, Reviewed-by: Hanjun Guo <hanjun.guo@xxxxxxxxxx> Thanks Hanjun [1]: https://patchwork.kernel.org/patch/7743661/ -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html