]> Git Repo - linux.git/commitdiff
fpga: dfl: add dfl_fpga_cdev_find_port
authorWu Hao <[email protected]>
Sat, 30 Jun 2018 00:53:15 +0000 (08:53 +0800)
committerGreg Kroah-Hartman <[email protected]>
Sun, 15 Jul 2018 11:55:45 +0000 (13:55 +0200)
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]>
drivers/fpga/dfl.c
drivers/fpga/dfl.h

index b56933c643717776849e39906e294332652c522f..68e0b45617b2dbc42f6ab9ec34e50c15df6991a6 100644 (file)
@@ -813,6 +813,38 @@ void dfl_fpga_feature_devs_remove(struct dfl_fpga_cdev *cdev)
 }
 EXPORT_SYMBOL_GPL(dfl_fpga_feature_devs_remove);
 
+/**
+ * __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;
index 66c2ade5a06bc1c4a56a2cff2665601e7a099564..b4f65250a29ccd11f9af0c8433158652edc2b6e8 100644 (file)
@@ -284,4 +284,25 @@ struct dfl_fpga_cdev *
 dfl_fpga_feature_devs_enumerate(struct dfl_fpga_enum_info *info);
 void dfl_fpga_feature_devs_remove(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 */
This page took 0.051877 seconds and 4 git commands to generate.