@@ -28,6 +28,8 @@ FPGA_IMAGE_LOAD_WRITE:
Start an image upload with the provided image buffer. This IOCTL returns
immediately after starting a kernel worker thread to process the image
-upload which could take as long as 40 minutes depending on the actual
-device being updated. This is an exclusive operation; an attempt to start
-concurrent image uploads for the same device will fail with EBUSY.
+upload which could take as long as 40 minutes depending on the actual device
+being updated. This is an exclusive operation; an attempt to start
+concurrent image uploads for the same device will fail with EBUSY. An
+eventfd file descriptor parameter is provided to this IOCTL. It will be
+signalled at the completion of the image upload.
@@ -26,6 +26,7 @@ static void fpga_image_prog_complete(struct fpga_image_load *imgld)
{
mutex_lock(&imgld->lock);
imgld->progress = FPGA_IMAGE_PROG_IDLE;
+ eventfd_signal(imgld->finished, 1);
mutex_unlock(&imgld->lock);
}
@@ -96,6 +97,8 @@ static void fpga_image_do_load(struct work_struct *work)
vfree(imgld->data);
imgld->data = NULL;
fpga_image_prog_complete(imgld);
+ eventfd_ctx_put(imgld->finished);
+ imgld->finished = NULL;
}
static int fpga_image_load_ioctl_write(struct fpga_image_load *imgld,
@@ -103,6 +106,7 @@ static int fpga_image_load_ioctl_write(struct fpga_image_load *imgld,
{
struct fpga_image_write wb;
unsigned long minsz;
+ int ret;
u8 *buf;
if (imgld->driver_unload || imgld->progress != FPGA_IMAGE_PROG_IDLE)
@@ -115,13 +119,23 @@ static int fpga_image_load_ioctl_write(struct fpga_image_load *imgld,
if (wb.flags)
return -EINVAL;
+ if (wb.evtfd < 0)
+ return -EINVAL;
+
buf = vzalloc(wb.size);
if (!buf)
return -ENOMEM;
if (copy_from_user(buf, u64_to_user_ptr(wb.buf), wb.size)) {
- vfree(buf);
- return -EFAULT;
+ ret = -EFAULT;
+ goto exit_free;
+ }
+
+ imgld->finished = eventfd_ctx_fdget(wb.evtfd);
+ if (IS_ERR(imgld->finished)) {
+ ret = PTR_ERR(imgld->finished);
+ imgld->finished = NULL;
+ goto exit_free;
}
imgld->data = buf;
@@ -131,6 +145,10 @@ static int fpga_image_load_ioctl_write(struct fpga_image_load *imgld,
queue_work(system_long_wq, &imgld->work);
return 0;
+
+exit_free:
+ vfree(buf);
+ return ret;
}
static long fpga_image_load_ioctl(struct file *filp, unsigned int cmd,
@@ -9,6 +9,7 @@
#include <linux/cdev.h>
#include <linux/device.h>
+#include <linux/eventfd.h>
#include <linux/mutex.h>
#include <linux/types.h>
#include <uapi/linux/fpga-image-load.h>
@@ -50,6 +51,7 @@ struct fpga_image_load {
u32 progress;
u32 err_code; /* image load error code */
bool driver_unload;
+ struct eventfd_ctx *finished;
void *priv;
};
@@ -37,7 +37,7 @@
* struct fpga_image_write)
*
* Upload a data buffer to the target device. The user must provide the
- * data buffer and size.
+ * data buffer, size, and an eventfd file descriptor.
*
* Return: 0 on success, -errno on failure.
*/
@@ -45,6 +45,7 @@ struct fpga_image_write {
/* Input */
__u32 flags; /* Zero for now */
__u32 size; /* Data size (in bytes) to be written */
+ __s32 evtfd; /* File descriptor for completion signal */
__u64 buf; /* User space address of source data */
};
Amend the FPGA_IMAGE_LOAD_WRITE IOCTL implementation to include an eventfd file descriptor as a parameter. The eventfd will be triggered when the image upload completes. Signed-off-by: Russ Weight <russell.h.weight@intel.com> --- v17: - More documentation cleanup. v16: - Some cleanup of documentation for the FPGA_IMAGE_LOAD_WRITE IOCTL. v15: - This patch is new to the patch-set, and adds an eventfd to the FPGA_IMAGE_LOAD_WRITE IOCTL. The eventfd is signalled upon completion of an update. --- Documentation/fpga/fpga-image-load.rst | 8 +++++--- drivers/fpga/fpga-image-load.c | 22 ++++++++++++++++++++-- include/linux/fpga/fpga-image-load.h | 2 ++ include/uapi/linux/fpga-image-load.h | 3 ++- 4 files changed, 29 insertions(+), 6 deletions(-)