[PATCH v5 08/28] fpga: dfl: add dfl_fpga_cdev_find_port
From: Wu Hao <hidden>
Date: 2018-05-02 03:07:31
Also in:
linux-fpga, lkml
Subsystem:
fpga dfl drivers, fpga manager framework, the rest · Maintainers:
Xu Yilun, Moritz Fischer, Linus Torvalds
For feature devices, we need a method to find the port dedicated
to the device. This patch adds a function dfl_fpga_cdev_find_port
for this purpose. e.g FPGA Management Engine (FME) Partial
Reconfiguration sub feature, it uses this function to find
dedicated port on the device for PR function implementation.
Signed-off-by: Tim Whisonant <redacted>
Signed-off-by: Enno Luebbers <redacted>
Signed-off-by: Shiva Rao <redacted>
Signed-off-by: Christopher Rauer <redacted>
Signed-off-by: Xiao Guangrong <redacted>
Signed-off-by: Wu Hao <redacted>
Acked-by: Alan Tull <atull@kernel.org>
Acked-by: Moritz Fischer <mdf@kernel.org>
---
v3: s/fpga_for_each_port/fpga_cdev_find_port/
move fpga_cdev_find_port to fpga-dfl module.
v4: improve description in commit message.
add comments to remind user to put_device after use this function.
v5: add "dfl_" prefix to functions.
improve function comments per suggestion from Alan Tull.
add Acked-by from Alan and Moritz.
---
drivers/fpga/dfl.c | 32 ++++++++++++++++++++++++++++++++
drivers/fpga/dfl.h | 21 +++++++++++++++++++++
2 files changed, 53 insertions(+)
diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
index 18aba02..1e06efb 100644
--- a/drivers/fpga/dfl.c
+++ b/drivers/fpga/dfl.c@@ -795,6 +795,38 @@ void dfl_fpga_remove_feature_devs(struct dfl_fpga_cdev *cdev) } EXPORT_SYMBOL_GPL(dfl_fpga_remove_feature_devs); +/** + * __dfl_fpga_cdev_find_port - find a port under given container device + * + * @cdev: container device + * @data: data passed to match function + * @match: match function used to find specific port from the port device list + * + * Find a port device under container device. This function needs to be + * invoked with lock held. + * + * Return: pointer to port's platform device if successful, NULL otherwise. + * + * NOTE: you will need to drop the device reference with put_device() after use. + */ +struct platform_device * +__dfl_fpga_cdev_find_port(struct dfl_fpga_cdev *cdev, void *data, + int (*match)(struct platform_device *, void *)) +{ + struct dfl_feature_platform_data *pdata; + struct platform_device *port_dev; + + list_for_each_entry(pdata, &cdev->port_dev_list, node) { + port_dev = pdata->dev; + + if (match(port_dev, data) && get_device(&port_dev->dev)) + return port_dev; + } + + return NULL; +} +EXPORT_SYMBOL_GPL(__dfl_fpga_cdev_find_port); + static int __init dfl_fpga_init(void) { int ret;
diff --git a/drivers/fpga/dfl.h b/drivers/fpga/dfl.h
index 5fcb1a1..2b6aaef 100644
--- a/drivers/fpga/dfl.h
+++ b/drivers/fpga/dfl.h@@ -290,4 +290,25 @@ struct dfl_fpga_cdev * dfl_fpga_enumerate_feature_devs(struct dfl_fpga_enum_info *info); void dfl_fpga_remove_feature_devs(struct dfl_fpga_cdev *cdev); +/* + * need to drop the device reference with put_device() after use port platform + * device returned by __dfl_fpga_cdev_find_port and dfl_fpga_cdev_find_port + * functions. + */ +struct platform_device * +__dfl_fpga_cdev_find_port(struct dfl_fpga_cdev *cdev, void *data, + int (*match)(struct platform_device *, void *)); + +static inline struct platform_device * +dfl_fpga_cdev_find_port(struct dfl_fpga_cdev *cdev, void *data, + int (*match)(struct platform_device *, void *)) +{ + struct platform_device *pdev; + + mutex_lock(&cdev->lock); + pdev = __dfl_fpga_cdev_find_port(cdev, data, match); + mutex_unlock(&cdev->lock); + + return pdev; +} #endif /* __FPGA_DFL_H */
--
1.8.3.1