From: Alan Tull <atull@kernel.org>
To: Moritz Fischer <moritz.fischer@ettus.com>
Cc: Alan Tull <atull@kernel.org>,
linux-kernel@vger.kernel.org, linux-fpga@vger.kernel.org
Subject: [PATCH v2 14/16] fpga: region: add register/unregister functions
Date: Thu, 20 Apr 2017 09:09:59 -0500 [thread overview]
Message-ID: <1492697401-11211-15-git-send-email-atull@kernel.org> (raw)
In-Reply-To: <1492697401-11211-1-git-send-email-atull@kernel.org>
Another step in separating common code from device tree specific
code for FPGA regions.
* add FPGA region register/unregister functions.
* add the register/unregister functions to the header
* use devm_kzalloc to alloc the region.
* add a method for getting bridges to the region struct
* add priv to the region struct
Signed-off-by: Alan Tull <atull@kernel.org>
---
v2: split out from another patch
---
drivers/fpga/fpga-region.c | 99 +++++++++++++++++++++++++---------------
include/linux/fpga/fpga-region.h | 8 ++++
2 files changed, 70 insertions(+), 37 deletions(-)
diff --git a/drivers/fpga/fpga-region.c b/drivers/fpga/fpga-region.c
index e87e9a9..e2a3fe6 100644
--- a/drivers/fpga/fpga-region.c
+++ b/drivers/fpga/fpga-region.c
@@ -235,10 +235,16 @@ int fpga_region_program_fpga(struct fpga_region *region,
goto err_put_region;
}
- ret = of_fpga_region_get_bridges(region, info);
- if (ret) {
- dev_err(dev, "failed to get FPGA bridges\n");
- goto err_unlock_mgr;
+ /*
+ * In some cases, we already have a list of bridges in the
+ * fpga region struct. Or we don't have any bridges.
+ */
+ if (region->get_bridges) {
+ ret = region->get_bridges(region, info);
+ if (ret) {
+ dev_err(dev, "failed to get fpga region bridges\n");
+ goto err_unlock_mgr;
+ }
}
ret = fpga_bridges_disable(®ion->bridge_list);
@@ -267,7 +273,8 @@ int fpga_region_program_fpga(struct fpga_region *region,
return 0;
err_put_br:
- fpga_bridges_put(®ion->bridge_list);
+ if (region->get_bridges)
+ fpga_bridges_put(®ion->bridge_list);
err_unlock_mgr:
fpga_mgr_unlock(region->mgr);
err_put_region:
@@ -527,39 +534,20 @@ static struct notifier_block fpga_region_of_nb = {
.notifier_call = of_fpga_region_notify,
};
-static int of_fpga_region_probe(struct platform_device *pdev)
+int fpga_region_register(struct device *dev, struct fpga_region *region)
{
- struct device *dev = &pdev->dev;
- struct device_node *np = dev->of_node;
- struct fpga_region *region;
- struct fpga_manager *mgr;
int id, ret = 0;
- mgr = of_fpga_region_get_mgr(np);
- if (IS_ERR(mgr))
- return -EPROBE_DEFER;
-
- region = kzalloc(sizeof(*region), GFP_KERNEL);
- if (!region) {
- ret = -ENOMEM;
- goto err_put_mgr;
- }
-
- region->mgr = mgr;
-
id = ida_simple_get(&fpga_region_ida, 0, 0, GFP_KERNEL);
- if (id < 0) {
- ret = id;
- goto err_kfree;
- }
+ if (id < 0)
+ return id;
mutex_init(®ion->mutex);
INIT_LIST_HEAD(®ion->bridge_list);
-
device_initialize(®ion->dev);
region->dev.class = fpga_region_class;
region->dev.parent = dev;
- region->dev.of_node = np;
+ region->dev.of_node = dev->of_node;
region->dev.id = id;
dev_set_drvdata(dev, region);
@@ -571,19 +559,58 @@ static int of_fpga_region_probe(struct platform_device *pdev)
if (ret)
goto err_remove;
+ return 0;
+
+err_remove:
+ ida_simple_remove(&fpga_region_ida, id);
+ return ret;
+}
+EXPORT_SYMBOL_GPL(fpga_region_register);
+
+int fpga_region_unregister(struct fpga_region *region)
+{
+ device_unregister(®ion->dev);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(fpga_region_unregister);
+
+static int of_fpga_region_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct device_node *np = dev->of_node;
+ struct fpga_region *region;
+ struct fpga_manager *mgr;
+ int ret;
+
+ /* Find the FPGA mgr specified by region or parent region. */
+ mgr = of_fpga_region_get_mgr(np);
+ if (IS_ERR(mgr))
+ return -EPROBE_DEFER;
+
+ region = devm_kzalloc(dev, sizeof(*region), GFP_KERNEL);
+ if (!region) {
+ ret = -ENOMEM;
+ goto eprobe_mgr_put;
+ }
+
+ region->mgr = mgr;
+
+ /* Specify how to get bridges for this type of region. */
+ region->get_bridges = of_fpga_region_get_bridges;
+
+ ret = fpga_region_register(dev, region);
+ if (ret)
+ goto eprobe_mgr_put;
+
of_platform_populate(np, fpga_region_of_match, NULL, ®ion->dev);
dev_info(dev, "FPGA Region probed\n");
return 0;
-err_remove:
- ida_simple_remove(&fpga_region_ida, id);
-err_kfree:
- kfree(region);
-err_put_mgr:
+eprobe_mgr_put:
fpga_mgr_put(mgr);
-
return ret;
}
@@ -591,8 +618,7 @@ static int of_fpga_region_remove(struct platform_device *pdev)
{
struct fpga_region *region = platform_get_drvdata(pdev);
- device_unregister(®ion->dev);
- fpga_mgr_put(region->mgr);
+ fpga_region_unregister(region);
return 0;
}
@@ -611,7 +637,6 @@ static void fpga_region_dev_release(struct device *dev)
struct fpga_region *region = to_fpga_region(dev);
ida_simple_remove(&fpga_region_ida, region->dev.id);
- kfree(region);
}
/**
diff --git a/include/linux/fpga/fpga-region.h b/include/linux/fpga/fpga-region.h
index 1075f94..35e7e09 100644
--- a/include/linux/fpga/fpga-region.h
+++ b/include/linux/fpga/fpga-region.h
@@ -12,6 +12,8 @@
* @bridge_list: list of FPGA bridges specified in region
* @mgr: FPGA manager
* @info: FPGA image info
+ * @priv: private data
+ * @get_bridges: optional function to get bridges to a list
*/
struct fpga_region {
struct device dev;
@@ -19,6 +21,9 @@ struct fpga_region {
struct list_head bridge_list;
struct fpga_manager *mgr;
struct fpga_image_info *info;
+ void *priv;
+ int (*get_bridges)(struct fpga_region *region,
+ struct fpga_image_info *image_info);
};
#define to_fpga_region(d) container_of(d, struct fpga_region, dev)
@@ -26,4 +31,7 @@ struct fpga_region {
int fpga_region_program_fpga(struct fpga_region *region,
struct fpga_image_info *image_info);
+int fpga_region_register(struct device *dev, struct fpga_region *region);
+int fpga_region_unregister(struct fpga_region *region);
+
#endif /* _FPGA_REGION_H */
--
2.7.4
next prev parent reply other threads:[~2017-04-20 14:11 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-20 14:09 [PATCH v2 00/16] Enable upper layers using FPGA region w/o device tree Alan Tull
2017-04-20 14:09 ` [PATCH v2 01/16] doc: fpga: update documents for the FPGA API Alan Tull
2017-04-20 14:09 ` [PATCH v2 02/16] fpga: bridge: support getting bridge from device Alan Tull
2017-05-03 11:58 ` Wu Hao
2017-05-03 20:07 ` Alan Tull
2017-05-04 9:20 ` Wu Hao
2017-05-04 21:31 ` Alan Tull
2017-05-08 8:44 ` Wu, Hao
2017-05-08 20:44 ` Alan Tull
2017-05-08 20:52 ` Moritz Fischer
2017-05-08 21:02 ` Alan Tull
2017-05-08 21:11 ` Moritz Fischer
2017-05-08 21:20 ` Alan Tull
2017-05-08 21:55 ` Moritz Fischer
2017-05-09 7:16 ` Wu Hao
2017-04-20 14:09 ` [PATCH v2 03/16] fpga: mgr: API change to replace fpga load functions with single function Alan Tull
2017-04-21 20:08 ` Alan Tull
2017-04-20 14:09 ` [PATCH v2 04/16] fpga: mgr: separate getting/locking FPGA manager Alan Tull
2017-04-20 14:09 ` [PATCH v2 05/16] fpga: region: use dev_err instead of pr_err Alan Tull
2017-04-20 14:09 ` [PATCH v2 06/16] fpga: region: remove unneeded of_node_get and put Alan Tull
2017-05-05 17:08 ` Moritz Fischer
2017-04-20 14:09 ` [PATCH v2 07/16] fpga: region: get mgr early on Alan Tull
2017-04-20 14:09 ` [PATCH v2 08/16] fpga: region: check for child regions before allocing image info Alan Tull
2017-05-05 20:59 ` Moritz Fischer
2017-05-08 21:03 ` Alan Tull
2017-04-20 14:09 ` [PATCH v2 09/16] fpga: region: fix slow warning with more than one overlay Alan Tull
2017-04-20 14:09 ` [PATCH v2 10/16] fpga: region: use image info as parameter for programming region Alan Tull
2017-05-09 15:25 ` Alan Tull
2017-04-20 14:09 ` [PATCH v2 11/16] fpga: region: separate out code that parses the overlay Alan Tull
2017-04-20 14:09 ` [PATCH v2 12/16] fpga: region: add fpga-region.h header Alan Tull
2017-04-20 14:09 ` [PATCH v2 13/16] fpga: region: rename some functions prior to moving Alan Tull
2017-04-20 14:09 ` Alan Tull [this message]
2017-04-20 14:10 ` [PATCH v2 15/16] fpga: region: add fpga_region_class_find Alan Tull
2017-05-03 15:44 ` Moritz Fischer
2017-05-03 20:08 ` Alan Tull
2017-04-20 14:10 ` [PATCH v2 16/16] fpga: region: move device tree support to of-fpga-region.c Alan Tull
2017-04-28 6:38 ` Wu Hao
2017-04-28 17:37 ` Alan Tull
2017-04-20 14:16 ` [PATCH v2 00/16] Enable upper layers using FPGA region w/o device tree Alan Tull
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1492697401-11211-15-git-send-email-atull@kernel.org \
--to=atull@kernel.org \
--cc=linux-fpga@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=moritz.fischer@ettus.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).