aboutsummaryrefslogtreecommitdiff
path: root/drivers/fpga/fpga-mgr.c
AgeCommit message (Collapse)AuthorFilesLines
2022-06-29fpga: fpga-mgr: Fix spelling mistake "bitsream" -> "bitstream"Colin Ian King1-1/+1
There is an spelling mistake in a dev_err message. Fix it. Fixes: 3cc624beba63 ("fpga: fpga-mgr: support bitstream offset in image buffer") Signed-off-by: Colin Ian King <[email protected]> Link: https://lore.kernel.org/r/[email protected] [[email protected]: add the Fixes tag] Signed-off-by: Xu Yilun <[email protected]>
2022-06-24fpga: fpga-mgr: support bitstream offset in image bufferIvan Bornyakov1-25/+198
At the moment FPGA manager core loads to the device entire image provided to fpga_mgr_load(). But it is not always whole FPGA image buffer meant to be written to the device. In particular, .dat formatted image for Microchip MPF contains meta info in the header that is not meant to be written to the device. This is issue for those low level drivers that loads data to the device with write() fpga_manager_ops callback, since write() can be called in iterator over scatter-gather table, not only linear image buffer. On the other hand, write_sg() callback is provided with whole image in scatter-gather form and can decide itself which part should be sent to the device. Add header_size and data_size to the fpga_image_info struct, add skip_header to the fpga_manager_ops struct and adjust fpga_mgr_write() callers with respect to them. * info->header_size indicates part at the beginning of image buffer that contains some meta info. It is optional and can be 0, initialized with mops->initial_header_size. * mops->skip_header tells fpga-mgr core whether write should start from the beginning of image buffer or at the offset of header_size. * info->data_size is the size of bitstream data that is meant to be written to the device. It is also optional and can be 0, which means bitstream data is up to the end of image buffer. Also add parse_header() callback to fpga_manager_ops, which purpose is to set info->header_size and info->data_size. At least initial_header_size bytes of image buffer will be passed into parse_header() first time. If it is not enough, parse_header() should set desired size into info->header_size and return -EAGAIN, then it will be called again with greater part of image buffer on the input. Suggested-by: Xu Yilun <[email protected]> Signed-off-by: Ivan Bornyakov <[email protected]> Acked-by: Xu Yilun <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Xu Yilun <[email protected]>
2022-06-08fpga: Directly use ida_alloc()/free()keliu1-3/+3
Use ida_alloc()/ida_free() instead of deprecated ida_simple_get()/ida_simple_remove() . Signed-off-by: keliu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Xu Yilun <[email protected]>
2022-05-10fpga: fpga-mgr: fix kernel-doc warningsNava kishore Manne1-0/+4
warnings: No description found for return value of 'xxx' In-order to fix the above kernel-doc warnings added the 'Return' description for 'devm_fpga_mgr_register_full()' and 'devm_fpga_mgr_register()' APIs. Signed-off-by: Nava kishore Manne <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Xu Yilun <[email protected]>
2022-05-10fpga: fix for coding style issuesNava kishore Manne1-4/+5
fixes the below checks reported by checkpatch.pl: - Lines should not end with a '(' - Alignment should match open parenthesis Signed-off-by: Nava kishore Manne <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Xu Yilun <[email protected]>
2021-11-28fpga: mgr: Use standard dev_release for class driverRuss Weight1-124/+91
The FPGA manager class driver data structure is being treated as a managed resource instead of using the standard dev_release call-back function to release the class data structure. This change removes the managed resource code for the freeing of the class data structure and combines the create() and register() functions into a single register() or register_full() function. The register_full() function accepts an info data structure to provide flexibility in passing optional parameters. The register() function supports the current parameter list for users that don't require the use of optional parameters. The devm_fpga_mgr_register() function is retained, and the devm_fpga_mgr_register_full() function is added. Signed-off-by: Russ Weight <[email protected]> Reviewed-by: Xu Yilun <[email protected]> Acked-by: Xu Yilun <[email protected]> Signed-off-by: Moritz Fischer <[email protected]>
2021-07-24fpga: fpga-mgr: wrap the write_sg() opTom Rix1-1/+9
An FPGA manager should not be required to provide a write_sg function. Move the op check to the wrapper. Default to -EOPNOTSUP so its users will fail gracefully. [[email protected]: Reworded first line] Signed-off-by: Tom Rix <[email protected]> Signed-off-by: Moritz Fischer <[email protected]>
2021-07-24fpga: fpga-mgr: wrap the fpga_remove() opTom Rix1-2/+7
An FPGA manager is not required to provide a fpga_remove() op. Add a wrapper consistent with the other op wrappers. Move op check to wrapper. [[email protected]: Reworded first line] Signed-off-by: Tom Rix <[email protected]> Signed-off-by: Moritz Fischer <[email protected]>
2021-07-24fpga: fpga-mgr: wrap the state() opTom Rix1-2/+9
An FPGA manager should not be required to provide a state() op. Add a wrapper consistent with the other op wrappers. Move op check to wrapper. Default to FPGA_MGR_STATE_UNKNOWN, what noop state() ops use. Remove unneeded noop state() ops [[email protected]: Reworded first line] Signed-off-by: Tom Rix <[email protected]> Signed-off-by: Moritz Fischer <[email protected]>
2021-07-24fpga: fpga-mgr: wrap the status() opTom Rix1-4/+8
An FPGA manager is not required to provide a status() op. Add a wrapper consistent with the other op wrappers. Move the op check to the wrapper. Default to 0, no errors to report. [[email protected]: Reworded first line] Signed-off-by: Tom Rix <[email protected]> Signed-off-by: Moritz Fischer <[email protected]>
2021-07-24fpga: fpga-mgr: wrap the write() opTom Rix1-5/+10
An FPGA manager should not be required to provide a write function. Move the op check to the wrapper. Default to -EOPNOTSUP so its users will fail gracefully. [[email protected]: Reworded message] Signed-off-by: Tom Rix <[email protected]> Signed-off-by: Moritz Fischer <[email protected]>
2021-07-24fpga: fpga-mgr: make write_complete() op optionalTom Rix1-22/+23
An FPGA manager should not be required to provide a write_complete function if there is nothing. Move the op check to the existing wrapper. Default to success and remove noop function. [[email protected]: Reworded message] Signed-off-by: Tom Rix <[email protected]> Signed-off-by: Moritz Fischer <[email protected]>
2021-07-24fpga: fpga-mgr: wrap the write_init() opTom Rix1-3/+12
An FPGA manager should not be required to provide a write_init() op if there is nothing for it do. So add a wrapper and move the op checking. Default to success. [[email protected]: Reworded first line] Signed-off-by: Tom Rix <[email protected]> Signed-off-by: Moritz Fischer <[email protected]>
2021-06-15fpga: mgr: Rename dev to parent for parent deviceRuss Weight1-10/+10
Rename variable "dev" to "parent" in cases where it represents the parent device. Signed-off-by: Russ Weight <[email protected]> Reviewed-by: Xu Yilun <[email protected]> Signed-off-by: Moritz Fischer <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
2021-06-09fpga-mgr: change FPGA indirect article to anTom Rix1-11/+11
Change use of 'a fpga' to 'an fpga' Signed-off-by: Tom Rix <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
2020-12-01fpga: fpga-mgr: Add devm_fpga_mgr_register() APIMoritz Fischer1-12/+69
Add a devm_fpga_mgr_register() API that can be used to register a FPGA Manager that was created using devm_fpga_mgr_create(). Introduce a struct fpga_mgr_devres that makes the devres allocation a little bit more readable and gets reused for devm_fpga_mgr_create() devm_fpga_mgr_register(). Reviewed-by: Tom Rix <[email protected]> Signed-off-by: Moritz Fischer <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
2020-06-18fpga: Fix dead store fpga-mgr.cTom Rix1-3/+1
Using clang's scan-build/view this issue was flagged in fpga-mgr.c drivers/fpga/fpga-mgr.c:585:3: warning: Value stored to 'ret' is never read [deadcode.DeadStores] ret = id; Signed-off-by: Tom Rix <[email protected]> Signed-off-by: Moritz Fischer <[email protected]>
2019-07-30drivers: Introduce device lookup variants by of_nodeSuzuki K Poulose1-7/+1
Introduce wrappers for {bus/driver/class}_find_device() to locate devices by its of_node. Cc: Maarten Lankhorst <[email protected]> Cc: Maxime Ripard <[email protected]> Cc: [email protected] Cc: David Airlie <[email protected]> Cc: Daniel Vetter <[email protected]> Cc: [email protected] Cc: Florian Fainelli <[email protected]> Cc: Frank Rowand <[email protected]> Cc: Heiko Stuebner <[email protected]> Cc: Liam Girdwood <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: Mathieu Poirier <[email protected]> Cc: Rob Herring <[email protected]> Cc: Srinivas Kandagatla <[email protected]> Cc: Takashi Iwai <[email protected]> Cc: Alan Tull <[email protected]> Cc: [email protected] Cc: Peter Rosin <[email protected]> Cc: Florian Fainelli <[email protected]> Cc: Heiner Kallweit <[email protected]> Cc: "David S. Miller" <[email protected]> Cc: Andrew Lunn <[email protected]> Cc: Liam Girdwood <[email protected]> Cc: "Rafael J. Wysocki" <[email protected]> Cc: Thor Thayer <[email protected]> Cc: Jiri Slaby <[email protected]> Cc: Andrew Lunn <[email protected]> Cc: Peter Rosin <[email protected]> Signed-off-by: Suzuki K Poulose <[email protected]> Acked-by: Lee Jones <[email protected]> Acked-by: Wolfram Sang <[email protected]> # I2C part Acked-by: Moritz Fischer <[email protected]> # For FPGA part Acked-by: Mark Brown <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
2018-10-16fpga: mgr: add devm_fpga_mgr_createAlan Tull1-8/+56
Add devm_fpga_mgr_create() which is the managed version of fpga_mgr_create(). Change current FPGA manager drivers to use devm_fpga_mgr_create() Signed-off-by: Alan Tull <[email protected]> Suggested-by: Federico Vaga <[email protected]> Acked-by: Moritz Fischer <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
2018-07-15fpga: mgr: add status for fpga-managerWu Hao1-0/+28
This patch adds status sysfs interface for fpga manager, it's a read only interface which allows user to get fpga manager status, including full/partial reconfiguration error and other status information. It adds a status callback to fpga_manager_ops too, allows each fpga_manager driver to define its own method to collect latest status from hardware. The following sysfs file is created: * /sys/class/fpga_manager/<fpga>/status Return status of fpga manager, including reconfiguration errors. 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]>
2018-05-25fpga: clarify that unregister functions also freeAlan Tull1-1/+1
The following functions also free the struct. Add that fact to the function documentation. - fpga_mgr_free - fpga_bridge_free - fpga_region_free Signed-off-by: Alan Tull <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
2018-05-25fpga: mgr: kernel-doc fixesAlan Tull1-9/+29
Clean up the kernel-doc documentation in fpga-mgr.c and fix the following warnings when documentation is built: ./drivers/fpga/fpga-mgr.c:252: warning: Function parameter or member 'info' not described in 'fpga_mgr_buf_load' ./drivers/fpga/fpga-mgr.c:252: warning: Excess function parameter 'flags' description in 'fpga_mgr_buf_load' Signed-off-by: Alan Tull <[email protected]> Acked-by: Moritz Fischer <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
2018-05-25fpga: use SPDXAlan Tull1-12/+1
Replace GPLv2 boilerplate with SPDX in FPGA code that came from me or from Altera. Signed-off-by: Alan Tull <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
2018-05-25fpga: manager: change api, don't use drvdataAlan Tull1-26/+52
Change fpga_mgr_register to not set or use drvdata. This supports the case where a PCIe device has more than one manager. Add fpga_mgr_create/free functions. Change fpga_mgr_register and fpga_mgr_unregister functions to take the mgr struct as their only parameter. struct fpga_manager *fpga_mgr_create(struct device *dev, const char *name, const struct fpga_manager_ops *mops, void *priv); void fpga_mgr_free(struct fpga_manager *mgr); int fpga_mgr_register(struct fpga_manager *mgr); void fpga_mgr_unregister(struct fpga_manager *mgr); Update the drivers that call fpga_mgr_register with the new API. Signed-off-by: Alan Tull <[email protected]> [Moritz: Fixup whitespace issue] Reported-by: Jiuyue Ma <[email protected]> Signed-off-by: Moritz Fischer <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
2017-11-28fpga: fpga-mgr: remove unnecessary code in __fpga_mgr_getGustavo A. R. Silva1-2/+0
Notice that mgr = to_fpga_manager(dev); expands to: mgr = container_of(dev, struct fpga_manager, dev); and container_of is never null, so this null check is unnecessary. Addresses-Coverity-ID: 1397916 Signed-off-by: Gustavo A. R. Silva <[email protected]> Signed-off-by: Alan Tull <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
2017-11-28fpga: add attribute groupsAlan Tull1-0/+1
Make it easy to add attributes to low level FPGA drivers the right way. Add attribute groups pointers to structures that are used when registering a manager, bridge, or group. When the low level driver registers, set the device attribute group. The attributes are created in device_add. Signed-off-by: Alan Tull <[email protected]> Acked-by: Moritz Fischer <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
2017-11-28fpga: mgr: separate getting/locking FPGA managerAlan Tull1-16/+36
Previously when the user gets a FPGA manager, it was locked and nobody else could use it for programming. This commit makes it straightforward to save a reference to an FPGA manager and only lock it when programming the FPGA. Add functions that get an FPGA manager's mutex for exclusive use: * fpga_mgr_lock * fpga_mgr_unlock The following functions no longer lock an FPGA manager's mutex: * of_fpga_mgr_get * fpga_mgr_get * fpga_mgr_put Signed-off-by: Alan Tull <[email protected]> Acked-by: Moritz Fischer <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
2017-11-28fpga: mgr: API change to replace fpga load functions with single functionAlan Tull1-11/+57
fpga-mgr has three methods for programming FPGAs, depending on whether the image is in a scatter gather list, a contiguous buffer, or a firmware file. This makes it difficult to write upper layers as the caller has to assume whether the FPGA image is in a sg table, as a single buffer, or a firmware file. This commit moves these parameters to struct fpga_image_info and adds a single function for programming fpgas. New functions: * fpga_mgr_load - given fpga manager and struct fpga_image_info, program the fpga. * fpga_image_info_alloc - alloc a struct fpga_image_info. * fpga_image_info_free - free a struct fpga_image_info. These three functions are unexported: * fpga_mgr_buf_load_sg * fpga_mgr_buf_load * fpga_mgr_firmware_load Also use devm_kstrdup to copy firmware_name so we aren't making assumptions about where it comes from when allocing/freeing the struct fpga_image_info. API documentation has been updated and a new document for FPGA region has been added. Signed-off-by: Alan Tull <[email protected]> Acked-by: Moritz Fischer <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
2017-03-17fpga: fix sparse warnings in fpga-mgr and fpga-bridgeDinh Nguyen1-1/+1
Fix up these sparse warnings: drivers/fpga/fpga-mgr.c:189:21: warning: symbol '__fpga_mgr_get' was not declared. Should it be static? drivers/fpga/fpga-bridge.c:30:12: warning: symbol 'bridge_list_lock' was not declared. Should it be static? Signed-off-by: Dinh Nguyen <[email protected]> Acked-by: Moritz Fischer <[email protected]> Signed-off-by: Alan Tull <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
2017-02-10fpga: Add scatterlist based programmingJason Gunthorpe1-30/+206
Requiring contiguous kernel memory is not a good idea, this is a limited resource and allocation can fail under normal work loads. This introduces a .write_sg op that supporting drivers can provide to DMA directly from dis-contiguous memory and a new entry point fpga_mgr_buf_load_sg that users can call to directly provide page lists. The full matrix of compatibility is provided, either the linear or sg interface can be used by the user with a driver supporting either interface. A notable change for drivers is that the .write op can now be called multiple times. Signed-off-by: Jason Gunthorpe <[email protected]> Acked-by: Alan Tull <[email protected]> Acked-by: Moritz Fischer <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
2016-11-29fpga: Clarify how write_init works streaming modesJason Gunthorpe1-2/+4
This interface was designed for streaming, but write_init's buf argument has an unclear purpose. Define it to be the first bytes of the bitstream. Each driver gets to set how many bytes (at most) it wants to see. Short bitstreams will be passed through as-is, while long ones will be truncated. The intent is to allow drivers to peek at the header before the transfer actually starts. Signed-off-by: Jason Gunthorpe <[email protected]> Acked-by: Alan Tull <[email protected]>
2016-11-10fpga-mgr: add fpga image information structAlan Tull1-8/+9
This patch adds a minor change in the FPGA Manager API to hold information that is specific to an FPGA image file. This change is expected to bring little, if any, pain. The socfpga and zynq drivers are fixed up in this patch. An FPGA image file will have particulars that affect how the image is programmed to the FPGA. One example is that current 'flags' currently has one bit which shows whether the FPGA image was built for full reconfiguration or partial reconfiguration. Another example is timeout values for enabling or disabling the bridges in the FPGA. As the complexity of the FPGA design increases, the bridges in the FPGA may take longer times to enable or disable. This patch adds a new 'struct fpga_image_info', moves the current 'u32 flags' to it. Two other image-specific u32's are added for the bridge enable/disable timeouts. The FPGA Manager API functions are changed, replacing the 'u32 flag' parameter with a pointer to struct fpga_image_info. Subsequent patches fix the existing low level FPGA manager drivers. Signed-off-by: Alan Tull <[email protected]> Acked-by: Moritz Fischer <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
2016-11-10fpga: add method to get fpga manager from deviceAlan Tull1-22/+54
The intent is to provide a non-DT method of getting ahold of a FPGA manager to do some FPGA programming. This patch refactors of_fpga_mgr_get() to reuse most of it while adding a new method fpga_mgr_get() for getting a pointer to a fpga manager struct, given the device. Signed-off-by: Alan Tull <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
2015-11-24fpga manager: Fix firmware resource leak on errorTobias Klauser1-3/+1
If fpga_mgr_buf_load() fails, the firmware resource previously allocated by request_firmware() is leaked. Fix it by calling release_firmware() regardless of the return value of fpga_mgr_buf_load(). Found by the Coverity scanner (CID 1339653). Fixes: 6a8c3be7ec8e ("add FPGA manager core") Signed-off-by: Tobias Klauser <[email protected]> Acked-by: Alan Tull <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
2015-11-24fpga manager: remove labelAlan Tull1-6/+3
Remove implementation of 'label' DT binding. Signed-off-by: Alan Tull <[email protected]> Reviewed-by: Moritz Fischer <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
2015-10-23fpga manager: remove unnecessary null pointer checksAlan Tull1-8/+4
Remove unnecessary null pointer checks. We want the caller of these functions to do their own pointer checks. Add some comments to document this. Signed-off-by: Alan Tull <[email protected]> Reviewed-by: Moritz Fischer <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
2015-10-23fpga manager: ensure lifetime with of_fpga_mgr_getAlan Tull1-15/+17
Ensure device and driver lifetime from of_fpga_mgr_get() to fpga_mgr_put(). * Don't put_device() in of_fpga_mgr_get, do it in fpga_mgr_put(). (still do put_device if there is an error). * Do module_get on the low level driver. * Don't need to module_get(THIS_MODULE) since we won't be allowed to unload the fpga manager core without unloading low level driver first. * Remove unnedessary null check for node pointer. Signed-off-by: Alan Tull <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
2015-10-07add FPGA manager coreAlan Tull1-0/+382
API to support programming FPGA's. The following functions are exported as GPL: * fpga_mgr_buf_load Load fpga from image in buffer * fpga_mgr_firmware_load Request firmware and load it to the FPGA. * fpga_mgr_register * fpga_mgr_unregister FPGA device drivers can be added by calling fpga_mgr_register() to register a set of fpga_manager_ops to do device specific stuff. * of_fpga_mgr_get * fpga_mgr_put Get/put a reference to a fpga manager. The following sysfs files are created: * /sys/class/fpga_manager/<fpga>/name Name of low level driver. * /sys/class/fpga_manager/<fpga>/state State of fpga manager Signed-off-by: Alan Tull <[email protected]> Acked-by: Michal Simek <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>