Skip to content

Commit 5d56e11

Browse files
WuHao270gregkh
authored andcommitted
fpga: dfl: add dfl_fpga_cdev_find_port
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 <[email protected]> Signed-off-by: Enno Luebbers <[email protected]> Signed-off-by: Shiva Rao <[email protected]> Signed-off-by: Christopher Rauer <[email protected]> Signed-off-by: Xiao Guangrong <[email protected]> Signed-off-by: Wu Hao <[email protected]> Acked-by: Alan Tull <[email protected]> Acked-by: Moritz Fischer <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent b16c514 commit 5d56e11

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

drivers/fpga/dfl.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,38 @@ void dfl_fpga_feature_devs_remove(struct dfl_fpga_cdev *cdev)
813813
}
814814
EXPORT_SYMBOL_GPL(dfl_fpga_feature_devs_remove);
815815

816+
/**
817+
* __dfl_fpga_cdev_find_port - find a port under given container device
818+
*
819+
* @cdev: container device
820+
* @data: data passed to match function
821+
* @match: match function used to find specific port from the port device list
822+
*
823+
* Find a port device under container device. This function needs to be
824+
* invoked with lock held.
825+
*
826+
* Return: pointer to port's platform device if successful, NULL otherwise.
827+
*
828+
* NOTE: you will need to drop the device reference with put_device() after use.
829+
*/
830+
struct platform_device *
831+
__dfl_fpga_cdev_find_port(struct dfl_fpga_cdev *cdev, void *data,
832+
int (*match)(struct platform_device *, void *))
833+
{
834+
struct dfl_feature_platform_data *pdata;
835+
struct platform_device *port_dev;
836+
837+
list_for_each_entry(pdata, &cdev->port_dev_list, node) {
838+
port_dev = pdata->dev;
839+
840+
if (match(port_dev, data) && get_device(&port_dev->dev))
841+
return port_dev;
842+
}
843+
844+
return NULL;
845+
}
846+
EXPORT_SYMBOL_GPL(__dfl_fpga_cdev_find_port);
847+
816848
static int __init dfl_fpga_init(void)
817849
{
818850
int ret;

drivers/fpga/dfl.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,25 @@ struct dfl_fpga_cdev *
284284
dfl_fpga_feature_devs_enumerate(struct dfl_fpga_enum_info *info);
285285
void dfl_fpga_feature_devs_remove(struct dfl_fpga_cdev *cdev);
286286

287+
/*
288+
* need to drop the device reference with put_device() after use port platform
289+
* device returned by __dfl_fpga_cdev_find_port and dfl_fpga_cdev_find_port
290+
* functions.
291+
*/
292+
struct platform_device *
293+
__dfl_fpga_cdev_find_port(struct dfl_fpga_cdev *cdev, void *data,
294+
int (*match)(struct platform_device *, void *));
295+
296+
static inline struct platform_device *
297+
dfl_fpga_cdev_find_port(struct dfl_fpga_cdev *cdev, void *data,
298+
int (*match)(struct platform_device *, void *))
299+
{
300+
struct platform_device *pdev;
301+
302+
mutex_lock(&cdev->lock);
303+
pdev = __dfl_fpga_cdev_find_port(cdev, data, match);
304+
mutex_unlock(&cdev->lock);
305+
306+
return pdev;
307+
}
287308
#endif /* __FPGA_DFL_H */

0 commit comments

Comments
 (0)