fpga: Add managed create in FPGA API
Subsystems (5)
cover fpga: Add managed create in FPGA API
Fix one functional FPGA bug.
Implement managed devm_fpga_(mgr|bridge|region)_create() functions.
More documentation cleanup to make the documentation more helpful and to emphasize the use of FPGA regions for FPGA programming.
Fix a few minor documentation corrections.
Alan Tull (8):
fpga: do not access region struct after fpga_region_unregister
fpga: mgr: add devm_fpga_mgr_create
fpga: bridge: add devm_fpga_bridge_create
fpga: add devm_fpga_region_create
dt-bindings: fpga: fix freeze controller compatible in region doc
fpga: bridge: fix obvious function documentation error
docs: fpga: document fpga manager flags
docs: fpga: document programming fpgas using regions
.../devicetree/bindings/fpga/fpga-region.txt | 4 +- Documentation/driver-api/fpga/fpga-bridge.rst | 37 ++----- Documentation/driver-api/fpga/fpga-mgr.rst | 121 +++------------------ Documentation/driver-api/fpga/fpga-programming.rst | 103 ++++++++++++++++++ Documentation/driver-api/fpga/fpga-region.rst | 91 ++++++++-------- Documentation/driver-api/fpga/index.rst | 2 + drivers/fpga/altera-cvp.c | 8 +- drivers/fpga/altera-fpga2sdram.c | 8 +- drivers/fpga/altera-freeze-bridge.c | 13 +-- drivers/fpga/altera-hps2fpga.c | 7 +- drivers/fpga/altera-pr-ip-core.c | 9 +- drivers/fpga/altera-ps-spi.c | 11 +- drivers/fpga/dfl-fme-br.c | 11 +- drivers/fpga/dfl-fme-mgr.c | 11 +- drivers/fpga/dfl-fme-region.c | 10 +- drivers/fpga/dfl.c | 6 +- drivers/fpga/fpga-bridge.c | 74 +++++++++++-- drivers/fpga/fpga-mgr.c | 67 ++++++++++-- drivers/fpga/fpga-region.c | 68 ++++++++++-- drivers/fpga/ice40-spi.c | 10 +- drivers/fpga/machxo2-spi.c | 11 +- drivers/fpga/of-fpga-region.c | 9 +- drivers/fpga/socfpga-a10.c | 5 +- drivers/fpga/socfpga.c | 10 +- drivers/fpga/ts73xx-fpga.c | 11 +- drivers/fpga/xilinx-pr-decoupler.c | 4 +- drivers/fpga/xilinx-spi.c | 12 +- drivers/fpga/zynq-fpga.c | 5 +- include/linux/fpga/fpga-bridge.h | 4 + include/linux/fpga/fpga-mgr.h | 22 +++- include/linux/fpga/fpga-region.h | 4 + 31 files changed, 437 insertions(+), 331 deletions(-) create mode 100644 Documentation/driver-api/fpga/fpga-programming.rst
Signature · 1 line
2.7.4
PATCH 1/8 fpga: do not access region struct after fpga_region_unregister
A couple drivers were accessing the region struct after it had been freed. Save off the pointer to the mgr before the region struct gets freed.
--- drivers/fpga/dfl-fme-region.c | 4 +++- drivers/fpga/of-fpga-region.c | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/fpga/dfl-fme-region.c +3 -1
@@ -14,6 +14,7 @@*/ #include <linux/module.h> +#include <linux/fpga/fpga-mgr.h> #include <linux/fpga/fpga-region.h> #include "dfl-fme-pr.h"
@@ -66,9 +67,10 @@ static int fme_region_probe(struct platform_device *pdev)static int fme_region_remove (struct platform_device *pdev) {struct fpga_region *region =dev_get_drvdata (&pdev->dev); +struct fpga_manager *mgr = region->mgr;fpga_region_unregister (region); -fpga_mgr_put (region->mgr); +fpga_mgr_put (mgr);return 0 ; }
drivers/fpga/of-fpga-region.c +2 -1
@@ -437,9 +437,10 @@ static int of_fpga_region_probe(struct platform_device *pdev)static int of_fpga_region_remove (struct platform_device *pdev) {struct fpga_region *region =platform_get_drvdata (pdev); +struct fpga_manager *mgr = region->mgr;fpga_region_unregister (region); -fpga_mgr_put (region->mgr); +fpga_mgr_put (mgr);return 0 ; }
Signature · 1 line
2.7.4
PATCH 2/8 fpga: mgr: add devm_fpga_mgr_create
In reply to Alan TullAdd devm_fpga_mgr_create() which is the managed
version of fpga_mgr_create().
Change current FPGA manager drivers to usedevm_fpga_mgr_create()
--- Documentation/driver-api/fpga/fpga-mgr.rst | 13 +++--- drivers/fpga/altera-cvp.c | 8 ++-- drivers/fpga/altera-pr-ip-core.c | 9 +--- drivers/fpga/altera-ps-spi.c | 11 ++--- drivers/fpga/dfl-fme-mgr.c | 11 ++--- drivers/fpga/fpga-mgr.c | 67 ++++++++++++++++++++++++++---- drivers/fpga/ice40-spi.c | 10 ++--- drivers/fpga/machxo2-spi.c | 11 ++--- drivers/fpga/socfpga-a10.c | 5 +-- drivers/fpga/socfpga.c | 10 ++--- drivers/fpga/ts73xx-fpga.c | 11 ++--- drivers/fpga/xilinx-spi.c | 12 ++---- drivers/fpga/zynq-fpga.c | 5 +-- include/linux/fpga/fpga-mgr.h | 4 ++ 14 files changed, 100 insertions(+), 87 deletions(-)
Documentation/driver-api/fpga/fpga-mgr.rst +6 -7
@@ -49,18 +49,14 @@ probe function calls fpga_mgr_register(), such as:: * them in priv */ - mgr = fpga_mgr_create(dev, "Altera SOCFPGA FPGA Manager", - &socfpga_fpga_ops, priv); + mgr = devm_fpga_mgr_create(dev, "Altera SOCFPGA FPGA Manager", + &socfpga_fpga_ops, priv); if (!mgr) return -ENOMEM; platform_set_drvdata(pdev, mgr); - ret = fpga_mgr_register(mgr); - if (ret) - fpga_mgr_free(mgr); - - return ret; + return fpga_mgr_register(mgr); } static int socfpga_fpga_remove(struct platform_device *pdev)
@@ -170,6 +166,9 @@ API for implementing a new FPGA Manager driver :functions: fpga_manager_ops .. kernel-doc:: drivers/fpga/fpga-mgr.c + :functions: devm_fpga_mgr_create + +.. kernel-doc:: drivers/fpga/fpga-mgr.c :functions: fpga_mgr_create .. kernel-doc:: drivers/fpga/fpga-mgr.c
drivers/fpga/altera-cvp.c +3 -5
@@ -453,8 +453,8 @@ static int altera_cvp_probe(struct pci_dev *pdev,snprintf (conf->mgr_name,sizeof (conf->mgr_name),"%s @%s" ,ALTERA_CVP_MGR_NAME ,pci_name (pdev)); - mgr =fpga_mgr_create (&pdev->dev, conf->mgr_name, - &altera_cvp_ops, conf); + mgr =devm_fpga_mgr_create (&pdev->dev, conf->mgr_name, + &altera_cvp_ops, conf);if (!mgr) { ret = -ENOMEM ; goto err_unmap;
@@ -463,10 +463,8 @@ static int altera_cvp_probe(struct pci_dev *pdev,pci_set_drvdata (pdev, mgr); ret =fpga_mgr_register (mgr); -if (ret) { -fpga_mgr_free (mgr); +if (ret) goto err_unmap; - } ret =driver_create_file (&altera_cvp_driver.driver, &driver_attr_chkcfg);
drivers/fpga/altera-pr-ip-core.c +2 -7
@@ -177,7 +177,6 @@ int alt_pr_register(struct device *dev, void __iomem *reg_base) {struct alt_pr_priv *priv;struct fpga_manager *mgr; -int ret;u32 val; priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL );
@@ -192,17 +191,13 @@ int alt_pr_register(struct device *dev, void __iomem *reg_base) (val &ALT_PR_CSR_STATUS_MSK ) >>ALT_PR_CSR_STATUS_SFT , (int)(val & ALT_PR_CSR_PR_START)); - mgr =fpga_mgr_create (dev,dev_name (dev), &alt_pr_ops, priv); + mgr =devm_fpga_mgr_create (dev,dev_name (dev), &alt_pr_ops, priv);if (!mgr)return -ENOMEM ;dev_set_drvdata (dev, mgr); - ret =fpga_mgr_register (mgr); -if (ret) -fpga_mgr_free (mgr); - -return ret; +return fpga_mgr_register (mgr); }EXPORT_SYMBOL_GPL (alt_pr_register);
drivers/fpga/altera-ps-spi.c +3 -8
@@ -239,7 +239,6 @@ static int altera_ps_probe(struct spi_device *spi)struct altera_ps_conf *conf;const struct of_device_id *of_id;struct fpga_manager *mgr; -int ret; conf =devm_kzalloc (&spi->dev,sizeof (*conf),GFP_KERNEL );if (!conf)
@@ -275,18 +274,14 @@ static int altera_ps_probe(struct spi_device *spi)snprintf (conf->mgr_name,sizeof (conf->mgr_name),"%s %s" ,dev_driver_string (&spi->dev),dev_name (&spi->dev)); - mgr =fpga_mgr_create (&spi->dev, conf->mgr_name, - &altera_ps_ops, conf); + mgr =devm_fpga_mgr_create (&spi->dev, conf->mgr_name, + &altera_ps_ops, conf);if (!mgr)return -ENOMEM ;spi_set_drvdata (spi, mgr); - ret =fpga_mgr_register (mgr); -if (ret) -fpga_mgr_free (mgr); - -return ret; +return fpga_mgr_register (mgr); }static int altera_ps_remove (struct spi_device *spi)
drivers/fpga/dfl-fme-mgr.c +3 -8
@@ -287,7 +287,6 @@ static int fme_mgr_probe(struct platform_device *pdev)struct fme_mgr_priv *priv;struct fpga_manager *mgr;struct resource *res; -int ret; priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL );if (!priv)
@@ -309,19 +308,15 @@ static int fme_mgr_probe(struct platform_device *pdev)fme_mgr_get_compat_id (priv->ioaddr, compat_id); - mgr =fpga_mgr_create (dev,"DFL FME FPGA Manager" , - &fme_mgr_ops, priv); + mgr =devm_fpga_mgr_create (dev,"DFL FME FPGA Manager" , + &fme_mgr_ops, priv);if (!mgr)return -ENOMEM ; mgr->compat_id = compat_id;platform_set_drvdata (pdev, mgr); - ret =fpga_mgr_register (mgr); -if (ret) -fpga_mgr_free (mgr); - -return ret; +return fpga_mgr_register (mgr); }static int fme_mgr_remove (struct platform_device *pdev)
drivers/fpga/fpga-mgr.c +59 -8
99 lines not on this page · raw message
drivers/fpga/ice40-spi.c +3 -7
@@ -175,18 +175,14 @@ static int ice40_fpga_probe(struct spi_device *spi)return ret; } - mgr =fpga_mgr_create (dev,"Lattice iCE40 FPGA Manager" , - &ice40_fpga_ops, priv); + mgr =devm_fpga_mgr_create (dev,"Lattice iCE40 FPGA Manager" , + &ice40_fpga_ops, priv);if (!mgr)return -ENOMEM ;spi_set_drvdata (spi, mgr); - ret =fpga_mgr_register (mgr); -if (ret) -fpga_mgr_free (mgr); - -return ret; +return fpga_mgr_register (mgr); }static int ice40_fpga_remove (struct spi_device *spi)
drivers/fpga/machxo2-spi.c +3 -8
@@ -356,25 +356,20 @@ static int machxo2_spi_probe(struct spi_device *spi) {struct device *dev = &spi->dev;struct fpga_manager *mgr; -int ret;if (spi->max_speed_hz >MACHXO2_MAX_SPEED ) {dev_err (dev,"Speed is too high\n" );return -EINVAL ; } - mgr =fpga_mgr_create (dev,"Lattice MachXO2 SPI FPGA Manager" , - &machxo2_ops, spi); + mgr =devm_fpga_mgr_create (dev,"Lattice MachXO2 SPI FPGA Manager" , + &machxo2_ops, spi);if (!mgr)return -ENOMEM ;spi_set_drvdata (spi, mgr); - ret =fpga_mgr_register (mgr); -if (ret) -fpga_mgr_free (mgr); - -return ret; +return fpga_mgr_register (mgr); }static int machxo2_spi_remove (struct spi_device *spi)
drivers/fpga/socfpga-a10.c +2 -3
@@ -508,8 +508,8 @@ static int socfpga_a10_fpga_probe(struct platform_device *pdev)return -EBUSY ; } - mgr =fpga_mgr_create (dev,"SoCFPGA Arria10 FPGA Manager" , - &socfpga_a10_fpga_mgr_ops, priv); + mgr =devm_fpga_mgr_create (dev,"SoCFPGA Arria10 FPGA Manager" , + &socfpga_a10_fpga_mgr_ops, priv);if (!mgr)return -ENOMEM ;
@@ -517,7 +517,6 @@ static int socfpga_a10_fpga_probe(struct platform_device *pdev) ret =fpga_mgr_register (mgr);if (ret) { -fpga_mgr_free (mgr);clk_disable_unprepare (priv->clk);return ret; }
drivers/fpga/socfpga.c +3 -7
@@ -571,18 +571,14 @@ static int socfpga_fpga_probe(struct platform_device *pdev)if (ret)return ret; - mgr =fpga_mgr_create (dev,"Altera SOCFPGA FPGA Manager" , - &socfpga_fpga_ops, priv); + mgr =devm_fpga_mgr_create (dev,"Altera SOCFPGA FPGA Manager" , + &socfpga_fpga_ops, priv);if (!mgr)return -ENOMEM ;platform_set_drvdata (pdev, mgr); - ret =fpga_mgr_register (mgr); -if (ret) -fpga_mgr_free (mgr); - -return ret; +return fpga_mgr_register (mgr); }static int socfpga_fpga_remove (struct platform_device *pdev)
drivers/fpga/ts73xx-fpga.c +3 -8
@@ -118,7 +118,6 @@ static int ts73xx_fpga_probe(struct platform_device *pdev)struct ts73xx_fpga_priv *priv;struct fpga_manager *mgr;struct resource *res; -int ret; priv =devm_kzalloc (kdev,sizeof (*priv),GFP_KERNEL );if (!priv)
@@ -133,18 +132,14 @@ static int ts73xx_fpga_probe(struct platform_device *pdev)return PTR_ERR (priv->io_base); } - mgr =fpga_mgr_create (kdev,"TS-73xx FPGA Manager" , - &ts73xx_fpga_ops, priv); + mgr =devm_fpga_mgr_create (kdev,"TS-73xx FPGA Manager" , + &ts73xx_fpga_ops, priv);if (!mgr)return -ENOMEM ;platform_set_drvdata (pdev, mgr); - ret =fpga_mgr_register (mgr); -if (ret) -fpga_mgr_free (mgr); - -return ret; +return fpga_mgr_register (mgr); }static int ts73xx_fpga_remove (struct platform_device *pdev)
drivers/fpga/xilinx-spi.c +4 -8
@@ -144,7 +144,6 @@ static int xilinx_spi_probe(struct spi_device *spi) {struct xilinx_spi_conf *conf;struct fpga_manager *mgr; -int ret; conf =devm_kzalloc (&spi->dev,sizeof (*conf),GFP_KERNEL );if (!conf)
@@ -167,18 +166,15 @@ static int xilinx_spi_probe(struct spi_device *spi)return PTR_ERR (conf->done); } - mgr =fpga_mgr_create (&spi->dev,"Xilinx Slave Serial FPGA Manager" , - &xilinx_spi_ops, conf); + mgr =devm_fpga_mgr_create (&spi->dev, +"Xilinx Slave Serial FPGA Manager" , + &xilinx_spi_ops, conf);if (!mgr)return -ENOMEM ;spi_set_drvdata (spi, mgr); - ret =fpga_mgr_register (mgr); -if (ret) -fpga_mgr_free (mgr); - -return ret; +return fpga_mgr_register (mgr); }static int xilinx_spi_remove (struct spi_device *spi)
drivers/fpga/zynq-fpga.c +2 -3
@@ -614,8 +614,8 @@ static int zynq_fpga_probe(struct platform_device *pdev)clk_disable (priv->clk); - mgr =fpga_mgr_create (dev,"Xilinx Zynq FPGA Manager" , - &zynq_fpga_ops, priv); + mgr =devm_fpga_mgr_create (dev,"Xilinx Zynq FPGA Manager" , + &zynq_fpga_ops, priv);if (!mgr)return -ENOMEM ;
@@ -624,7 +624,6 @@ static int zynq_fpga_probe(struct platform_device *pdev) err =fpga_mgr_register (mgr);if (err) {dev_err (dev,"unable to register FPGA manager\n" ); -fpga_mgr_free (mgr);clk_unprepare (priv->clk);return err; }
include/linux/fpga/fpga-mgr.h +4 -0
@@ -190,4 +190,8 @@ void fpga_mgr_free(struct fpga_manager *mgr);int fpga_mgr_register (struct fpga_manager *mgr);void fpga_mgr_unregister (struct fpga_manager *mgr); +struct fpga_manager *devm_fpga_mgr_create (struct device *dev,const char *name, +const struct fpga_manager_ops *mops, +void *priv); +#endif /*_LINUX_FPGA_MGR_H */
Signature · 1 line
2.7.4
PATCH 3/8 fpga: bridge: add devm_fpga_bridge_create
In reply to Alan TullAdd devm_fpga_bridge_create() which is the managed version of fpga_bridge_create().
Change current bridge drivers to usedevm_fpga_bridge_create().
--- Documentation/driver-api/fpga/fpga-bridge.rst | 3 ++ drivers/fpga/altera-fpga2sdram.c | 8 ++- drivers/fpga/altera-freeze-bridge.c | 13 ++--- drivers/fpga/altera-hps2fpga.c | 7 ++- drivers/fpga/dfl-fme-br.c | 11 ++-- drivers/fpga/fpga-bridge.c | 72 +++++++++++++++++++++++---- drivers/fpga/xilinx-pr-decoupler.c | 4 +- include/linux/fpga/fpga-bridge.h | 4 ++ 8 files changed, 84 insertions(+), 38 deletions(-)
Documentation/driver-api/fpga/fpga-bridge.rst +3 -0
@@ -11,6 +11,9 @@ API to implement a new FPGA bridge :functions: fpga_bridge_ops .. kernel-doc:: drivers/fpga/fpga-bridge.c + :functions: devm_fpga_bridge_create + +.. kernel-doc:: drivers/fpga/fpga-bridge.c :functions: fpga_bridge_create .. kernel-doc:: drivers/fpga/fpga-bridge.c
drivers/fpga/altera-fpga2sdram.c +3 -5
@@ -121,18 +121,16 @@ static int alt_fpga_bridge_probe(struct platform_device *pdev)/* Get f2s bridge configuration saved in handoff register */ regmap_read (sysmgr,SYSMGR_ISWGRP_HANDOFF3 , &priv->mask); - br =fpga_bridge_create (dev,F2S_BRIDGE_NAME , - &altera_fpga2sdram_br_ops, priv); + br =devm_fpga_bridge_create (dev,F2S_BRIDGE_NAME , + &altera_fpga2sdram_br_ops, priv);if (!br)return -ENOMEM ;platform_set_drvdata (pdev, br); ret =fpga_bridge_register (br); -if (ret) { -fpga_bridge_free (br); +if (ret)return ret; - }dev_info (dev,"driver initialized with handoff %08x\n" , priv->mask);
drivers/fpga/altera-freeze-bridge.c +3 -10
@@ -213,7 +213,6 @@ static int altera_freeze_br_probe(struct platform_device *pdev)struct fpga_bridge *br;struct resource *res;u32 status, revision; -int ret;if (!np)return -ENODEV ;
@@ -245,20 +244,14 @@ static int altera_freeze_br_probe(struct platform_device *pdev) priv->base_addr = base_addr; - br =fpga_bridge_create (dev,FREEZE_BRIDGE_NAME , - &altera_freeze_br_br_ops, priv); + br =devm_fpga_bridge_create (dev,FREEZE_BRIDGE_NAME , + &altera_freeze_br_br_ops, priv);if (!br)return -ENOMEM ;platform_set_drvdata (pdev, br); - ret =fpga_bridge_register (br); -if (ret) { -fpga_bridge_free (br); -return ret; - } - -return 0 ; +return fpga_bridge_register (br); }static int altera_freeze_br_remove (struct platform_device *pdev)
drivers/fpga/altera-hps2fpga.c +3 -4
@@ -180,7 +180,8 @@ static int alt_fpga_bridge_probe(struct platform_device *pdev) } } - br =fpga_bridge_create (dev, priv->name, &altera_hps2fpga_br_ops, priv); + br =devm_fpga_bridge_create (dev, priv->name, + &altera_hps2fpga_br_ops, priv);if (!br) { ret = -ENOMEM ; goto err;
@@ -190,12 +191,10 @@ static int alt_fpga_bridge_probe(struct platform_device *pdev) ret =fpga_bridge_register (br);if (ret) - goto err_free; + goto err;return 0 ; -err_free: -fpga_bridge_free (br); err:clk_disable_unprepare (priv->clk);
drivers/fpga/dfl-fme-br.c +3 -8
@@ -61,7 +61,6 @@ static int fme_br_probe(struct platform_device *pdev)struct device *dev = &pdev->dev;struct fme_br_priv *priv;struct fpga_bridge *br; -int ret; priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL );if (!priv)
@@ -69,18 +68,14 @@ static int fme_br_probe(struct platform_device *pdev) priv->pdata =dev_get_platdata (dev); - br =fpga_bridge_create (dev,"DFL FPGA FME Bridge" , - &fme_bridge_ops, priv); + br =devm_fpga_bridge_create (dev,"DFL FPGA FME Bridge" , + &fme_bridge_ops, priv);if (!br)return -ENOMEM ;platform_set_drvdata (pdev, br); - ret =fpga_bridge_register (br); -if (ret) -fpga_bridge_free (br); - -return ret; +return fpga_bridge_register (br); }static int fme_br_remove (struct platform_device *pdev)
drivers/fpga/fpga-bridge.c +63 -9
103 lines not on this page · raw message
drivers/fpga/xilinx-pr-decoupler.c +2 -2
@@ -121,8 +121,8 @@ static int xlnx_pr_decoupler_probe(struct platform_device *pdev)clk_disable (priv->clk); - br =fpga_bridge_create (&pdev->dev,"Xilinx PR Decoupler" , - &xlnx_pr_decoupler_br_ops, priv); + br =devm_fpga_bridge_create (&pdev->dev,"Xilinx PR Decoupler" , + &xlnx_pr_decoupler_br_ops, priv);if (!br) { err = -ENOMEM ; goto err_clk;
include/linux/fpga/fpga-bridge.h +4 -0
@@ -69,4 +69,8 @@ void fpga_bridge_free(struct fpga_bridge *br);int fpga_bridge_register (struct fpga_bridge *br);void fpga_bridge_unregister (struct fpga_bridge *br); +struct fpga_bridge +*devm_fpga_bridge_create (struct device *dev,const char *name, +const struct fpga_bridge_ops *br_ops,void *priv); +#endif /* _LINUX_FPGA_BRIDGE_H */
Signature · 1 line
2.7.4
PATCH 4/8 fpga: add devm_fpga_region_create
In reply to Alan TullAdd devm_fpga_region_create() which is the
managed version of fpga_region_create().
Change current region drivers to usedevm_fpga_region_create().
--- Documentation/driver-api/fpga/fpga-region.rst | 3 ++ drivers/fpga/dfl-fme-region.c | 6 +-- drivers/fpga/dfl.c | 6 +-- drivers/fpga/fpga-region.c | 68 +++++++++++++++++++++++---- drivers/fpga/of-fpga-region.c | 6 +-- include/linux/fpga/fpga-region.h | 4 ++ 6 files changed, 73 insertions(+), 20 deletions(-)
Documentation/driver-api/fpga/fpga-region.rst +3 -0
@@ -90,6 +90,9 @@ API to add a new FPGA region :functions: fpga_region .. kernel-doc:: drivers/fpga/fpga-region.c + :functions: devm_fpga_region_create + +.. kernel-doc:: drivers/fpga/fpga-region.c :functions: fpga_region_create .. kernel-doc:: drivers/fpga/fpga-region.c
drivers/fpga/dfl-fme-region.c +2 -4
@@ -39,7 +39,7 @@ static int fme_region_probe(struct platform_device *pdev)if (IS_ERR (mgr))return -EPROBE_DEFER ; - region =fpga_region_create (dev, mgr, fme_region_get_bridges); + region =devm_fpga_region_create (dev, mgr, fme_region_get_bridges);if (!region) { ret = -ENOMEM ; goto eprobe_mgr_put;
@@ -51,14 +51,12 @@ static int fme_region_probe(struct platform_device *pdev) ret =fpga_region_register (region);if (ret) - goto region_free; + goto eprobe_mgr_put;dev_dbg (dev,"DFL FME FPGA Region probed\n" );return 0 ; -region_free: -fpga_region_free (region); eprobe_mgr_put:fpga_mgr_put (mgr);return ret;
drivers/fpga/dfl.c +2 -4
@@ -899,7 +899,7 @@ dfl_fpga_feature_devs_enumerate(struct dfl_fpga_enum_info *info)if (!cdev)return ERR_PTR (-ENOMEM ); - cdev->region =fpga_region_create (info->dev,NULL ,NULL ); + cdev->region =devm_fpga_region_create (info->dev,NULL ,NULL );if (!cdev->region) { ret = -ENOMEM ; goto free_cdev_exit;
@@ -911,7 +911,7 @@ dfl_fpga_feature_devs_enumerate(struct dfl_fpga_enum_info *info) ret =fpga_region_register (cdev->region);if (ret) - goto free_region_exit; + goto free_cdev_exit;/* create and init build info for enumeration */ binfo =devm_kzalloc (info->dev,sizeof (*binfo),GFP_KERNEL );
@@ -942,8 +942,6 @@ dfl_fpga_feature_devs_enumerate(struct dfl_fpga_enum_info *info) unregister_region_exit:fpga_region_unregister (cdev->region); -free_region_exit: -fpga_region_free (cdev->region); free_cdev_exit:devm_kfree (info->dev, cdev);return ERR_PTR (ret);
drivers/fpga/fpga-region.c +60 -8
104 lines not on this page · raw message
drivers/fpga/of-fpga-region.c +2 -4
@@ -410,7 +410,7 @@ static int of_fpga_region_probe(struct platform_device *pdev)if (IS_ERR (mgr))return -EPROBE_DEFER ; - region =fpga_region_create (dev, mgr, of_fpga_region_get_bridges); + region =devm_fpga_region_create (dev, mgr, of_fpga_region_get_bridges);if (!region) { ret = -ENOMEM ; goto eprobe_mgr_put;
@@ -418,7 +418,7 @@ static int of_fpga_region_probe(struct platform_device *pdev) ret =fpga_region_register (region);if (ret) - goto eprobe_free; + goto eprobe_mgr_put;of_platform_populate (np, fpga_region_of_match,NULL , ®ion->dev);dev_set_drvdata (dev, region);
@@ -427,8 +427,6 @@ static int of_fpga_region_probe(struct platform_device *pdev)return 0 ; -eprobe_free: -fpga_region_free (region); eprobe_mgr_put:fpga_mgr_put (mgr);return ret;
include/linux/fpga/fpga-region.h +4 -0
@@ -44,4 +44,8 @@ void fpga_region_free(struct fpga_region *region);int fpga_region_register (struct fpga_region *region);void fpga_region_unregister (struct fpga_region *region); +struct fpga_region +*devm_fpga_region_create (struct device *dev,struct fpga_manager *mgr, +int (*get_bridges)(struct fpga_region *)); +#endif /* _FPGA_REGION_H */
Signature · 1 line
2.7.4
PATCH 5/8 dt-bindings: fpga: fix freeze controller compatible in region doc
In reply to Alan TullDocumentation/devicetree/bindings/fpga/fpga-region.txt has an error regarding the freeze controller bridge, secifically:
compatible = "altr,freeze-bridge";
The compatibility string should be "altr,freeze-bridge-controller" as set forth in altera-freeze-bridge.txt.
--- Documentation/devicetree/bindings/fpga/fpga-region.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/fpga/fpga-region.txt +2 -2
@@ -415,7 +415,7 @@ DT Overlay contains: firmware-name = "base.rbf"; fpga-bridge@4400 { - compatible = "altr,freeze-bridge"; + compatible = "altr,freeze-bridge-controller"; reg = <0x4400 0x10>; fpga_region1: fpga-region1 {
@@ -427,7 +427,7 @@ DT Overlay contains: }; fpga-bridge@4420 { - compatible = "altr,freeze-bridge"; + compatible = "altr,freeze-bridge-controller"; reg = <0x4420 0x10>; fpga_region2: fpga-region2 {
Signature · 1 line
2.7.4
PATCH 6/8 fpga: bridge: fix obvious function documentation error
In reply to Alan Tullfpga_bridge_dev_match() returns a FPGA bridge struct, not a FPGA manager struct so s/manager/bridge/.
--- drivers/fpga/fpga-bridge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/fpga/fpga-bridge.c +1 -1
@@ -125,7 +125,7 @@ static int fpga_bridge_dev_match(struct device *dev, const void *data)* * Given a device, get an exclusive reference to a fpga bridge. * -* Return: fpga manager struct or IS_ERR() condition containing error code. +* Return: fpga bridge struct or IS_ERR() condition containing error code. */ struct fpga_bridge *fpga_bridge_get (struct device *dev,struct fpga_image_info *info)
Signature · 1 line
2.7.4
PATCH 7/8 docs: fpga: document fpga manager flags
In reply to Alan TullAdd flags #defines to kerneldoc documentation in a useful place.
--- Documentation/driver-api/fpga/fpga-mgr.rst | 5 +++++ include/linux/fpga/fpga-mgr.h | 18 ++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-)
Documentation/driver-api/fpga/fpga-mgr.rst +5 -0
@@ -183,6 +183,11 @@ API for implementing a new FPGA Manager driver API for programming an FPGA --------------------------- +FPGA Manager flags + +.. kernel-doc:: include/linux/fpga/fpga-mgr.h + :doc: FPGA Manager flags + .. kernel-doc:: include/linux/fpga/fpga-mgr.h :functions: fpga_image_info
include/linux/fpga/fpga-mgr.h +12 -6
@@ -53,12 +53,18 @@ enum fpga_mgr_states { FPGA_MGR_STATE_OPERATING, }; -/* -* FPGA Manager flags -* FPGA_MGR_PARTIAL_RECONFIG: do partial reconfiguration if supported -* FPGA_MGR_EXTERNAL_CONFIG: FPGA has been configured prior to Linux booting -* FPGA_MGR_BITSTREAM_LSB_FIRST: SPI bitstream bit order is LSB first -* FPGA_MGR_COMPRESSED_BITSTREAM: FPGA bitstream is compressed +/** +* DOC: FPGA Manager flags +* +* Flags used in the &fpga_image_info->flags field +* +* %FPGA_MGR_PARTIAL_RECONFIG: do partial reconfiguration if supported +* +* %FPGA_MGR_EXTERNAL_CONFIG: FPGA has been configured prior to Linux booting +* +* %FPGA_MGR_BITSTREAM_LSB_FIRST: SPI bitstream bit order is LSB first +* +* %FPGA_MGR_COMPRESSED_BITSTREAM: FPGA bitstream is compressed */ #define FPGA_MGR_PARTIAL_RECONFIG BIT(0)#define FPGA_MGR_EXTERNAL_CONFIG BIT(1)
Signature · 1 line
2.7.4
PATCH 8/8 docs: fpga: document programming fpgas using regions
In reply to Alan TullClarify the intention that interfaces and upper layers use regions rather than managers directly.
Rearrange API documentation to better group the API functions used to create FPGA mgr/bridge/regions and the API used for programming FPGAs.
--- Documentation/driver-api/fpga/fpga-bridge.rst | 38 ++----- Documentation/driver-api/fpga/fpga-mgr.rst | 117 ++------------------- Documentation/driver-api/fpga/fpga-programming.rst | 103 ++++++++++++++++++ Documentation/driver-api/fpga/fpga-region.rst | 92 ++++++++-------- Documentation/driver-api/fpga/index.rst | 2 + 5 files changed, 166 insertions(+), 186 deletions(-) create mode 100644 Documentation/driver-api/fpga/fpga-programming.rst
Documentation/driver-api/fpga/fpga-bridge.rst +6 -32
@@ -4,6 +4,12 @@ FPGA Bridge API to implement a new FPGA bridge ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* struct :c:type:`fpga_bridge` — The FPGA Bridge structure +* struct :c:type:`fpga_bridge_ops` — Low level Bridge driver ops +* :c:func:`devm_fpga_bridge_create()` — Allocate and init a bridge struct +* :c:func:`fpga_bridge_register()` — Register a bridge +* :c:func:`fpga_bridge_unregister()` — Unregister a bridge + .. kernel-doc:: include/linux/fpga/fpga-bridge.h :functions: fpga_bridge
@@ -14,39 +20,7 @@ API to implement a new FPGA bridge :functions: devm_fpga_bridge_create .. kernel-doc:: drivers/fpga/fpga-bridge.c - :functions: fpga_bridge_create - -.. kernel-doc:: drivers/fpga/fpga-bridge.c - :functions: fpga_bridge_free - -.. kernel-doc:: drivers/fpga/fpga-bridge.c :functions: fpga_bridge_register .. kernel-doc:: drivers/fpga/fpga-bridge.c :functions: fpga_bridge_unregister - -API to control an FPGA bridge -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -You probably won't need these directly. FPGA regions should handle this. - -.. kernel-doc:: drivers/fpga/fpga-bridge.c - :functions: of_fpga_bridge_get - -.. kernel-doc:: drivers/fpga/fpga-bridge.c - :functions: fpga_bridge_get - -.. kernel-doc:: drivers/fpga/fpga-bridge.c - :functions: fpga_bridge_put - -.. kernel-doc:: drivers/fpga/fpga-bridge.c - :functions: fpga_bridge_get_to_list - -.. kernel-doc:: drivers/fpga/fpga-bridge.c - :functions: of_fpga_bridge_get_to_list - -.. kernel-doc:: drivers/fpga/fpga-bridge.c - :functions: fpga_bridge_enable - -.. kernel-doc:: drivers/fpga/fpga-bridge.c - :functions: fpga_bridge_disable
Documentation/driver-api/fpga/fpga-mgr.rst +10 -107
133 lines not on this page · raw message
Documentation/driver-api/fpga/fpga-programming.rst new file +103 -0
103 lines not on this page · raw message
Documentation/driver-api/fpga/fpga-region.rst +45 -47
114 lines not on this page · raw message
Documentation/driver-api/fpga/index.rst +2 -0
@@ -11,3 +11,5 @@ FPGA Subsystem fpga-mgr fpga-bridge fpga-region + fpga-programming +
Signature · 1 line
2.7.4
Hi Alan,
I think you forgot to add:
on patches 2,3,4 which were suggested here
https://lkml.org/lkml/2018/7/26/145
and patch 8 here:
https://lkml.org/lkml/2018/7/18/959
Quoted 53 lines · CEST Alan Tull
Fix one functional FPGA bug.
Implement managed devm_fpga_(mgr|bridge|region)_create() functions.
More documentation cleanup to make the documentation more helpful and to emphasize the use of FPGA regions for FPGA programming.
Fix a few minor documentation corrections.
Alan Tull (8):
fpga: do not access region struct afterfpga_region_unregister
fpga: mgr: adddevm_fpga_mgr_create
fpga: bridge: adddevm_fpga_bridge_create
fpga: adddevm_fpga_region_create
dt-bindings: fpga: fix freeze controller compatible in region doc
fpga: bridge: fix obvious function documentation error
docs: fpga: document fpga manager flags
docs: fpga: document programming fpgas using regions.../devicetree/bindings/fpga/fpga-region.txt | 4 +- Documentation/driver-api/fpga/fpga-bridge.rst | 37 ++----- Documentation/driver-api/fpga/fpga-mgr.rst | 121 +++------------------ Documentation/driver-api/fpga/fpga-programming.rst | 103 ++++++++++++++++++ Documentation/driver-api/fpga/fpga-region.rst | 91 ++++++++-------- Documentation/driver-api/fpga/index.rst | 2 + drivers/fpga/altera-cvp.c | 8 +- drivers/fpga/altera-fpga2sdram.c | 8 +- drivers/fpga/altera-freeze-bridge.c | 13 +-- drivers/fpga/altera-hps2fpga.c | 7 +- drivers/fpga/altera-pr-ip-core.c | 9 +- drivers/fpga/altera-ps-spi.c | 11 +- drivers/fpga/dfl-fme-br.c | 11 +- drivers/fpga/dfl-fme-mgr.c | 11 +- drivers/fpga/dfl-fme-region.c | 10 +- drivers/fpga/dfl.c | 6 +- drivers/fpga/fpga-bridge.c | 74 +++++++++++-- drivers/fpga/fpga-mgr.c | 67 ++++++++++-- drivers/fpga/fpga-region.c | 68 ++++++++++-- drivers/fpga/ice40-spi.c | 10 +- drivers/fpga/machxo2-spi.c | 11 +- drivers/fpga/of-fpga-region.c | 9 +- drivers/fpga/socfpga-a10.c | 5 +- drivers/fpga/socfpga.c | 10 +- drivers/fpga/ts73xx-fpga.c | 11 +- drivers/fpga/xilinx-pr-decoupler.c | 4 +- drivers/fpga/xilinx-spi.c | 12 +- drivers/fpga/zynq-fpga.c | 5 +- include/linux/fpga/fpga-bridge.h | 4 + include/linux/fpga/fpga-mgr.h | 22 +++- include/linux/fpga/fpga-region.h | 4 + 31 files changed, 437 insertions(+), 331 deletions(-) create mode 100644 Documentation/driver-api/fpga/fpga-programming.rst
Signature · 2 lines
Federico Vaga [BE-CO-HT]
Quoted 6 lines · Federico Vaga
Hi Alan,
I think you forgot to add:
Suggested-by Federico Vaga <[email protected]>
Quoted 7 lines
on patches 2,3,4 which were suggested here
https://lkml.org/lkml/2018/7/26/145
and patch 8 here:
You are right and I appreciate the suggestions. I credited you on the patch that this replaces [1]. I'll fix this in v2.
Alan
[1] https://lkml.org/lkml/2018/7/25/721
Quoted 62 lines · CEST Alan Tull
Quoted 45 lines
Fix one functional FPGA bug.
Implement managed devm_fpga_(mgr|bridge|region)_create() functions.
More documentation cleanup to make the documentation more helpful and to emphasize the use of FPGA regions for FPGA programming.
Fix a few minor documentation corrections.
Alan Tull (8):
fpga: do not access region struct afterfpga_region_unregister
fpga: mgr: adddevm_fpga_mgr_create
fpga: bridge: adddevm_fpga_bridge_create
fpga: adddevm_fpga_region_create
dt-bindings: fpga: fix freeze controller compatible in region doc
fpga: bridge: fix obvious function documentation error
docs: fpga: document fpga manager flags
docs: fpga: document programming fpgas using regions.../devicetree/bindings/fpga/fpga-region.txt | 4 +- Documentation/driver-api/fpga/fpga-bridge.rst | 37 ++----- Documentation/driver-api/fpga/fpga-mgr.rst | 121 +++------------------ Documentation/driver-api/fpga/fpga-programming.rst | 103 ++++++++++++++++++ Documentation/driver-api/fpga/fpga-region.rst | 91 ++++++++-------- Documentation/driver-api/fpga/index.rst | 2 + drivers/fpga/altera-cvp.c | 8 +- drivers/fpga/altera-fpga2sdram.c | 8 +- drivers/fpga/altera-freeze-bridge.c | 13 +-- drivers/fpga/altera-hps2fpga.c | 7 +- drivers/fpga/altera-pr-ip-core.c | 9 +- drivers/fpga/altera-ps-spi.c | 11 +- drivers/fpga/dfl-fme-br.c | 11 +- drivers/fpga/dfl-fme-mgr.c | 11 +- drivers/fpga/dfl-fme-region.c | 10 +- drivers/fpga/dfl.c | 6 +- drivers/fpga/fpga-bridge.c | 74 +++++++++++-- drivers/fpga/fpga-mgr.c | 67 ++++++++++-- drivers/fpga/fpga-region.c | 68 ++++++++++-- drivers/fpga/ice40-spi.c | 10 +- drivers/fpga/machxo2-spi.c | 11 +- drivers/fpga/of-fpga-region.c | 9 +- drivers/fpga/socfpga-a10.c | 5 +- drivers/fpga/socfpga.c | 10 +- drivers/fpga/ts73xx-fpga.c | 11 +-Quoted 8 lines
drivers/fpga/xilinx-pr-decoupler.c | 4 +- drivers/fpga/xilinx-spi.c | 12 +- drivers/fpga/zynq-fpga.c | 5 +- include/linux/fpga/fpga-bridge.h | 4 + include/linux/fpga/fpga-mgr.h | 22 +++- include/linux/fpga/fpga-region.h | 4 + 31 files changed, 437 insertions(+), 331 deletions(-) create mode 100644 Documentation/driver-api/fpga/fpga-programming.rst--
Federico Vaga
[BE-CO-HT]
Randy Dunlap
reviewerRe: [PATCH 8/8] docs: fpga: document programming fpgas using regions
In reply to Alan TullQuoted 8 lines · Alan Tull
Clarify the intention that interfaces and upper layers use regions rather than managers directly.
Rearrange API documentation to better group the API functions used to create FPGA mgr/bridge/regions and the API used for programming FPGAs.
Signed-off-by Alan Tull <[email protected]>
Quoted 9 lines
--- Documentation/driver-api/fpga/fpga-bridge.rst | 38 ++----- Documentation/driver-api/fpga/fpga-mgr.rst | 117 ++------------------- Documentation/driver-api/fpga/fpga-programming.rst | 103 ++++++++++++++++++ Documentation/driver-api/fpga/fpga-region.rst | 92 ++++++++-------- Documentation/driver-api/fpga/index.rst | 2 + 5 files changed, 166 insertions(+), 186 deletions(-) create mode 100644 Documentation/driver-api/fpga/fpga-programming.rst
Hi,
A few comments below...
Quoted 23 lines
Documentation/driver-api/fpga/fpga-programming.rst new file +17
-0@@ -0,0 +1,103 @@ +In-kernel API for FPGA Programming +================================== + +Overview +-------- + +The in-kernel API for FPGA programming is a combination of APIs from +FPGA manager, bridge, and regions. The actual function used to +trigger FPGA programming is :c:func:`fpga_region_program_fpga()`. + +:c:func:`fpga_region_program_fpga()` uses functionality supplied by +the FPGA manager and bridges. It will: + + * lock the region's mutex + * lock the mutex of the region's FPGA manager + * build a list of FPGA bridges if a method has been specified to do so + * disable the bridges
Documentation/driver-api/fpga/fpga-programming.rst line 27
Quoted 10 lines
Documentation/driver-api/fpga/fpga-programming.rst new file +10
-0+ * program the FPGA using info passed in :c:member:`fpga_region->info`. + * re-enable the bridges + * release the locks + +The struct fpga_image_info specifies what FPGA image to program. It is allocated/freed by :c:func:`fpga_image_info_alloc()` and freed with :c:func:`fpga_image_info_free()` + +How to program an FPGA using a region +------------------------------------- + +When the FPGA region driver probed, it was given a pointer to a FPGA manager
to an FPGA
Quoted 37 lines
Documentation/driver-api/fpga/fpga-programming.rst new file +37
-0+driver so it knows which manager to use. The region also either has a list of +bridges to control during programming or it has a pointer to a function that +will generate that list. Here's some sample code of what to do next:: + + #include <linux/fpga/fpga-mgr.h> + #include <linux/fpga/fpga-region.h> + + struct fpga_image_info *info; + int ret; + + /* + * First, alloc the struct with information about the FPGA image to + * program. + */ + info = fpga_image_info_alloc(dev); + if (!info) + return -ENOMEM; + + /* Set flags as needed, such as: */ + info->flags = FPGA_MGR_PARTIAL_RECONFIG; + + /* + * Indicate where the FPGA image is. This is pseudo-code; you're + * going to use one of these three. + */ + if (image is in a scatter gather table) { + + info->sgt = [your scatter gather table] + + } else if (image is in a buffer) { + + info->buf = [your image buffer] + info->count = [image buffer size] + + } else if (image is in a firmware file) { + + info->firmware_name = devm_kstrdup(dev, firmware_name,
Documentation/driver-api/fpga/fpga-programming.rst line 74
Quoted 10 lines
Documentation/driver-api/fpga/fpga-programming.rst new file +10
-0+ GFP_KERNEL); + + } + + /* Add info to region and do the programming */ + region->info = info; + ret = fpga_region_program_fpga(region); + if (ret) + return ret; +
always deallocate and then do:
if (ret) return ret;
?
Quoted 29 lines
Documentation/driver-api/fpga/fpga-programming.rst new file +29
-0+ /* Deallocate the image info if you're done with it */ + fpga_image_info_free(info); + + /* Now enumerate whatever hardware has appeared in the FPGA. */ + +API for programming an FPGA +--------------------------- + +* :c:func:`fpga_region_program_fpga` — Program a FPGA +* :c:type:`fpga_image_info` — Specifies what FPGA image to program +* :c:func:`fpga_image_info_alloc()` — Allocate a FPGA image info struct +* :c:func:`fpga_image_info_free()` — Free a FPGA image info struct + +.. kernel-doc:: drivers/fpga/fpga-region.c + :functions: fpga_region_program_fpga + +FPGA Manager flags + +.. kernel-doc:: include/linux/fpga/fpga-mgr.h + :doc: FPGA Manager flags + +.. kernel-doc:: include/linux/fpga/fpga-mgr.h + :functions: fpga_image_info + +.. kernel-doc:: drivers/fpga/fpga-mgr.c + :functions: fpga_image_info_alloc + +.. kernel-doc:: drivers/fpga/fpga-mgr.c + :functions: fpga_image_info_free
[snip]
Documentation/driver-api/fpga/fpga-programming.rst
Quoted 6 lines
API to add a new FPGA region
----------------------------Documentation/driver-api/fpga/fpga-programming.rst new file +3
-0+* struct :c:type:`fpga_region` — The FPGA region struct +* :c:func:`devm_fpga_region_create` — Allocate and init a region struct +* :c:func:`fpga_region_register` — Register a FPGA region
an FPGA
Quoted 1 line
+* :c:func:
fpga_region_unregister— Unregister a FPGA region
an FPGA
Documentation/driver-api/fpga/fpga-programming.rst
Quoted 6 lines
Documentation/driver-api/fpga/fpga-programming.rst new file +6
-0+ +The FPGA region's probe function will need to get a reference to the FPGA +Manager it will be using to do the programming. This usually would happen +during the region's probe function. + +* :c:func:`fpga_mgr_get` — Get a reference to a FPGA manager, raise ref count
an FPGA
Quoted 1 line
+* :c:func:
of_fpga_mgr_get— Get a reference to a FPGA manager, raise ref count,
an FPGA
Documentation/driver-api/fpga/fpga-programming.rst
Quoted 2 lines
Documentation/driver-api/fpga/fpga-programming.rst new file +2
-0+ given a device node. +* :c:func:`fpga_mgr_put` — Put a FPGA manager
an FPGA
Quoted 17 lines
Documentation/driver-api/fpga/fpga-programming.rst new file +14
-0+ +The FPGA region will need to specify which bridges to control while programming +the FPGA. The region driver can build a list of bridges during probe time +(:c:member:`fpga_region->bridge_list`) or it can have a function that creates +the list of bridges to program just before programming +(:c:member:`fpga_region->get_bridges`). The FPGA bridge framework supplies the +following APIs to handle building or tearing down that list. + +* :c:func:`fpga_bridge_get_to_list` — Get a ref of a FPGA bridge, add it to a + list +* :c:func:`of_fpga_bridge_get_to_list` — Get a ref of a FPGA bridge, add it to a + list, given a device node +* :c:func:`fpga_bridges_put` — Given a list of bridges, put them + .. kernel-doc:: include/linux/fpga/fpga-region.h :functions: fpga_region
Signature · 1 line
~Randy
Re: [PATCH 8/8] docs: fpga: document programming fpgas using regions
On Tue, Aug 14, 2018 at 9:40 PM, Randy Dunlap <[email protected]> wrote:
Hi Randy,
Quoted 50 lines · Alan Tull
Quoted 8 lines
Clarify the intention that interfaces and upper layers use regions rather than managers directly.
Rearrange API documentation to better group the API functions used to create FPGA mgr/bridge/regions and the API used for programming FPGAs.
Signed-off-by Alan Tull <[email protected]>Quoted 9 lines
--- Documentation/driver-api/fpga/fpga-bridge.rst | 38 ++----- Documentation/driver-api/fpga/fpga-mgr.rst | 117 ++------------------- Documentation/driver-api/fpga/fpga-programming.rst | 103 ++++++++++++++++++ Documentation/driver-api/fpga/fpga-region.rst | 92 ++++++++-------- Documentation/driver-api/fpga/index.rst | 2 + 5 files changed, 166 insertions(+), 186 deletions(-) create mode 100644 Documentation/driver-api/fpga/fpga-programming.rstHi,
A few comments below...Quoted 27 lines
Documentation/driver-api/fpga/fpga-programming.rst new file +21
-0@@ -0,0 +1,103 @@ +In-kernel API for FPGA Programming +================================== + +Overview +-------- + +The in-kernel API for FPGA programming is a combination of APIs from +FPGA manager, bridge, and regions. The actual function used to +trigger FPGA programming is :c:func:`fpga_region_program_fpga()`. + +:c:func:`fpga_region_program_fpga()` uses functionality supplied by +the FPGA manager and bridges. It will: + + * lock the region's mutex + * lock the mutex of the region's FPGA manager + * build a list of FPGA bridges if a method has been specified to do so + * disable the bridges + * program the FPGA using info passed in :c:member:`fpga_region->info`. + * re-enable the bridges + * release the locks +
Quoted 8 lines
Documentation/driver-api/fpga/fpga-programming.rst line 27
Quoted 6 lines
Documentation/driver-api/fpga/fpga-programming.rst new file +6
-0+The struct fpga_image_info specifies what FPGA image to program. It is allocated/freed by :c:func:`fpga_image_info_alloc()` and freed with :c:func:`fpga_image_info_free()` + +How to program an FPGA using a region +------------------------------------- + +When the FPGA region driver probed, it was given a pointer to a FPGA managerto an FPGA
Yes
Quoted 50 lines
Quoted 38 lines
Documentation/driver-api/fpga/fpga-programming.rst new file +37
-0+driver so it knows which manager to use. The region also either has a list of +bridges to control during programming or it has a pointer to a function that +will generate that list. Here's some sample code of what to do next:: + + #include <linux/fpga/fpga-mgr.h> + #include <linux/fpga/fpga-region.h> + + struct fpga_image_info *info; + int ret; + + /* + * First, alloc the struct with information about the FPGA image to + * program. + */ + info = fpga_image_info_alloc(dev); + if (!info) + return -ENOMEM; + + /* Set flags as needed, such as: */ + info->flags = FPGA_MGR_PARTIAL_RECONFIG; + + /* + * Indicate where the FPGA image is. This is pseudo-code; you're + * going to use one of these three. + */ + if (image is in a scatter gather table) { + + info->sgt = [your scatter gather table] + + } else if (image is in a buffer) { + + info->buf = [your image buffer] + info->count = [image buffer size] + + } else if (image is in a firmware file) { + + info->firmware_name = devm_kstrdup(dev, firmware_name,Documentation/driver-api/fpga/fpga-programming.rst line 74
Quoted 10 lines
Documentation/driver-api/fpga/fpga-programming.rst new file +10
-0+ GFP_KERNEL); + + } + + /* Add info to region and do the programming */ + region->info = info; + ret = fpga_region_program_fpga(region); + if (ret) + return ret; +always deallocate and then do:
Quoted 3 lines
if (ret) return ret;?
Yep, I'll fix it.
Quoted 55 lines
Quoted 30 lines
Documentation/driver-api/fpga/fpga-programming.rst new file +29
-0+ /* Deallocate the image info if you're done with it */ + fpga_image_info_free(info); + + /* Now enumerate whatever hardware has appeared in the FPGA. */ + +API for programming an FPGA +--------------------------- + +* :c:func:`fpga_region_program_fpga` — Program a FPGA +* :c:type:`fpga_image_info` — Specifies what FPGA image to program +* :c:func:`fpga_image_info_alloc()` — Allocate a FPGA image info struct +* :c:func:`fpga_image_info_free()` — Free a FPGA image info struct + +.. kernel-doc:: drivers/fpga/fpga-region.c + :functions: fpga_region_program_fpga + +FPGA Manager flags + +.. kernel-doc:: include/linux/fpga/fpga-mgr.h + :doc: FPGA Manager flags + +.. kernel-doc:: include/linux/fpga/fpga-mgr.h + :functions: fpga_image_info + +.. kernel-doc:: drivers/fpga/fpga-mgr.c + :functions: fpga_image_info_alloc + +.. kernel-doc:: drivers/fpga/fpga-mgr.c + :functions: fpga_image_info_free[snip]
Documentation/driver-api/fpga/fpga-programming.rst
Quoted 6 lines
API to add a new FPGA region
----------------------------Documentation/driver-api/fpga/fpga-programming.rst new file +3
-0+* struct :c:type:`fpga_region` — The FPGA region struct +* :c:func:`devm_fpga_region_create` — Allocate and init a region struct +* :c:func:`fpga_region_register` — Register a FPGA regionan FPGA
Quoted 1 line
+* :c:func:
fpga_region_unregister— Unregister a FPGA regionan FPGA
Documentation/driver-api/fpga/fpga-programming.rst
Quoted 6 lines
Documentation/driver-api/fpga/fpga-programming.rst new file +6
-0+ +The FPGA region's probe function will need to get a reference to the FPGA +Manager it will be using to do the programming. This usually would happen +during the region's probe function. + +* :c:func:`fpga_mgr_get` — Get a reference to a FPGA manager, raise ref countan FPGA
Quoted 8 lines
Quoted 1 line
+* :c:func:
of_fpga_mgr_get— Get a reference to a FPGA manager, raise ref count,an FPGA
Documentation/driver-api/fpga/fpga-programming.rst
Quoted 2 lines
Documentation/driver-api/fpga/fpga-programming.rst new file +2
-0+ given a device node. +* :c:func:`fpga_mgr_put` — Put a FPGA manageran FPGA
I'll fix these too; I'll go through this folder and s/a FPGA/an FPGA/g
Quoted 15 lines
Quoted 15 lines
Documentation/driver-api/fpga/fpga-programming.rst new file +14
-0+ +The FPGA region will need to specify which bridges to control while programming +the FPGA. The region driver can build a list of bridges during probe time +(:c:member:`fpga_region->bridge_list`) or it can have a function that creates +the list of bridges to program just before programming +(:c:member:`fpga_region->get_bridges`). The FPGA bridge framework supplies the +following APIs to handle building or tearing down that list. + +* :c:func:`fpga_bridge_get_to_list` — Get a ref of a FPGA bridge, add it to a + list +* :c:func:`of_fpga_bridge_get_to_list` — Get a ref of a FPGA bridge, add it to a + list, given a device node +* :c:func:`fpga_bridges_put` — Given a list of bridges, put them +
Quoted 8 lines
Quoted 3 lines
.. kernel-doc::
include/linux/fpga/fpga-region.h
:functions:fpga_region--
~Randy
Thanks for the review!
Alan
Moritz Fischer
maintainerRe: [PATCH 7/8] docs: fpga: document fpga manager flags
In reply to Alan TullHi Alan,
Quoted 30 lines · Alan Tull
Add flags #defines to kerneldoc documentation in a useful place.
Signed-off-by Alan Tull <[email protected]>--- Documentation/driver-api/fpga/fpga-mgr.rst | 5 +++++ include/linux/fpga/fpga-mgr.h | 18 ++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-)Documentation/driver-api/fpga/fpga-mgr.rst +5
-0@@ -183,6 +183,11 @@ API for implementing a new FPGA Manager driver API for programming an FPGA --------------------------- +FPGA Manager flags + +.. kernel-doc:: include/linux/fpga/fpga-mgr.h + :doc: FPGA Manager flags + .. kernel-doc:: include/linux/fpga/fpga-mgr.h :functions: fpga_image_infoinclude/linux/fpga/fpga-mgr.h +0
-0
include/linux/fpga/fpga-mgr.h enum fpga_mgr_states { · line 60
Quoted 8 lines
include/linux/fpga/fpga-mgr.h +0
-5@@ -53,12 +53,18 @@ enum fpga_mgr_states { FPGA_MGR_STATE_OPERATING, }; -/* -* FPGA Manager flags -* FPGA_MGR_PARTIAL_RECONFIG: do partial reconfiguration if supported -* FPGA_MGR_EXTERNAL_CONFIG: FPGA has been configured prior to Linux booting -* FPGA_MGR_BITSTREAM_LSB_FIRST: SPI bitstream bit order is LSB first
We are actually missing the ENCRYPTED flag here, can you add that while we're at it? I must've forgotten to add that back then ... derp.
Quoted 19 lines
include/linux/fpga/fpga-mgr.h +12
-1-* FPGA_MGR_COMPRESSED_BITSTREAM: FPGA bitstream is compressed +/** +* DOC: FPGA Manager flags +* +* Flags used in the &fpga_image_info->flags field +* +* %FPGA_MGR_PARTIAL_RECONFIG: do partial reconfiguration if supported +* +* %FPGA_MGR_EXTERNAL_CONFIG: FPGA has been configured prior to Linux booting +* +* %FPGA_MGR_BITSTREAM_LSB_FIRST: SPI bitstream bit order is LSB first +* +* %FPGA_MGR_COMPRESSED_BITSTREAM: FPGA bitstream is compressed */ #define FPGA_MGR_PARTIAL_RECONFIG BIT(0)#define FPGA_MGR_EXTERNAL_CONFIG BIT(1)Signature · 1 line
2.7.4
Thanks,
Moritz
Re: [PATCH 7/8] docs: fpga: document fpga manager flags
On Thu, Aug 16, 2018 at 2:02 PM, Moritz Fischer <[email protected]> wrote:
Hi Moritz,
Quoted 36 lines
Hi Alan,
Quoted 33 lines · Alan Tull
Add flags #defines to kerneldoc documentation in a useful place.
Signed-off-by Alan Tull <[email protected]>--- Documentation/driver-api/fpga/fpga-mgr.rst | 5 +++++ include/linux/fpga/fpga-mgr.h | 18 ++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-)Documentation/driver-api/fpga/fpga-mgr.rst +5
-0@@ -183,6 +183,11 @@ API for implementing a new FPGA Manager driver API for programming an FPGA --------------------------- +FPGA Manager flags + +.. kernel-doc:: include/linux/fpga/fpga-mgr.h + :doc: FPGA Manager flags + .. kernel-doc:: include/linux/fpga/fpga-mgr.h :functions: fpga_image_infoinclude/linux/fpga/fpga-mgr.h +0
-0@@ -53,12 +53,18 @@ enum fpga_mgr_states { FPGA_MGR_STATE_OPERATING, };
Quoted 8 lines
include/linux/fpga/fpga-mgr.h enum fpga_mgr_states { · line 60
Quoted 5 lines
include/linux/fpga/fpga-mgr.h +0
-5-/* -* FPGA Manager flags -* FPGA_MGR_PARTIAL_RECONFIG: do partial reconfiguration if supported -* FPGA_MGR_EXTERNAL_CONFIG: FPGA has been configured prior to Linux booting -* FPGA_MGR_BITSTREAM_LSB_FIRST: SPI bitstream bit order is LSB first We are actually missing the ENCRYPTED flag here, can you add that while we're at it? I must've forgotten to add that back then ... derp.
Sure!
Quoted 10 lines
include/linux/fpga/fpga-mgr.h enum fpga_mgr_states { · line 63
Quoted 10 lines
include/linux/fpga/fpga-mgr.h +8
-1-* FPGA_MGR_COMPRESSED_BITSTREAM: FPGA bitstream is compressed +/** +* DOC: FPGA Manager flags +* +* Flags used in the &fpga_image_info->flags field +* +* %FPGA_MGR_PARTIAL_RECONFIG: do partial reconfiguration if supported +* +* %FPGA_MGR_EXTERNAL_CONFIG: FPGA has been configured prior to Linux booting
How about this description?
+ *
+ * %FPGA_MGR_ENCRYPTED_BITSTREAM: indicates bitstream is encrypted
Quoted 11 lines
Quoted 10 lines
include/linux/fpga/fpga-mgr.h +4
-1+* +* %FPGA_MGR_BITSTREAM_LSB_FIRST: SPI bitstream bit order is LSB first +* +* %FPGA_MGR_COMPRESSED_BITSTREAM: FPGA bitstream is compressed */ #define FPGA_MGR_PARTIAL_RECONFIG BIT(0)#define FPGA_MGR_EXTERNAL_CONFIG BIT(1) --2.7.4
Quoted 2 lines
Thanks,
Moritz
Thanks,
Alan
Moritz Fischer
maintainerRe: [PATCH 7/8] docs: fpga: document fpga manager flags
Quoted 61 lines · Alan Tull
On Thu, Aug 16, 2018 at 2:02 PM, Moritz Fischer <[email protected]> wrote:
Hi Moritz,Quoted 36 lines
Hi Alan,
Quoted 33 lines · Alan Tull
Add flags #defines to kerneldoc documentation in a useful place.
Signed-off-by Alan Tull <[email protected]>--- Documentation/driver-api/fpga/fpga-mgr.rst | 5 +++++ include/linux/fpga/fpga-mgr.h | 18 ++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-)Documentation/driver-api/fpga/fpga-mgr.rst +5
-0@@ -183,6 +183,11 @@ API for implementing a new FPGA Manager driver API for programming an FPGA --------------------------- +FPGA Manager flags + +.. kernel-doc:: include/linux/fpga/fpga-mgr.h + :doc: FPGA Manager flags + .. kernel-doc:: include/linux/fpga/fpga-mgr.h :functions: fpga_image_infoinclude/linux/fpga/fpga-mgr.h +0
-0@@ -53,12 +53,18 @@ enum fpga_mgr_states { FPGA_MGR_STATE_OPERATING, };Quoted 8 lines
include/linux/fpga/fpga-mgr.h enum fpga_mgr_states { · line 60
Quoted 5 lines
include/linux/fpga/fpga-mgr.h +0
-5-/* -* FPGA Manager flags -* FPGA_MGR_PARTIAL_RECONFIG: do partial reconfiguration if supported -* FPGA_MGR_EXTERNAL_CONFIG: FPGA has been configured prior to Linux booting -* FPGA_MGR_BITSTREAM_LSB_FIRST: SPI bitstream bit order is LSB first We are actually missing the ENCRYPTED flag here, can you add that while we're at it? I must've forgotten to add that back then ... derp.
Sure!
Quoted 10 lines
include/linux/fpga/fpga-mgr.h enum fpga_mgr_states { · line 63
Quoted 10 lines
include/linux/fpga/fpga-mgr.h +8
-1-* FPGA_MGR_COMPRESSED_BITSTREAM: FPGA bitstream is compressed +/** +* DOC: FPGA Manager flags +* +* Flags used in the &fpga_image_info->flags field +* +* %FPGA_MGR_PARTIAL_RECONFIG: do partial reconfiguration if supported +* +* %FPGA_MGR_EXTERNAL_CONFIG: FPGA has been configured prior to Linux booting
Quoted 4 lines
How about this description?
+ *
+ * %FPGA_MGR_ENCRYPTED_BITSTREAM: indicates bitstream is encrypted
Works for me :)
Quoted 17 lines
Quoted 12 lines
Quoted 11 lines
include/linux/fpga/fpga-mgr.h +4
-1+* +* %FPGA_MGR_BITSTREAM_LSB_FIRST: SPI bitstream bit order is LSB first +* +* %FPGA_MGR_COMPRESSED_BITSTREAM: FPGA bitstream is compressed */ #define FPGA_MGR_PARTIAL_RECONFIG BIT(0)#define FPGA_MGR_EXTERNAL_CONFIG BIT(1) --2.7.4
Quoted 2 lines
Thanks,
MoritzThanks,
Alan