From a90192210c7a3851787ad7c595cffca6055455b7 Mon Sep 17 00:00:00 2001 From: Michal Simek Date: Tue, 31 Dec 2019 15:11:46 +0530 Subject: [PATCH] fpga: Add firmware store function For testing purpose. Signed-off-by: Michal Simek Acked-by: Nava kishore Manne Signed-off-by: Nava kishore Manne Signed-off-by: Radhey Shyam Pandey State: not-upstreamable --- drivers/fpga/fpga-mgr.c | 30 ++++++++++++++++++++++++++++++ include/linux/fpga/fpga-mgr.h | 2 ++ 2 files changed, 32 insertions(+) diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c index aa30889e23208..67f3ed738becb 100644 --- a/drivers/fpga/fpga-mgr.c +++ b/drivers/fpga/fpga-mgr.c @@ -377,6 +377,9 @@ static int fpga_mgr_firmware_load(struct fpga_manager *mgr, mgr->state = FPGA_MGR_STATE_FIRMWARE_REQ; + /* flags indicates whether to do full or partial reconfiguration */ + info->flags = mgr->flags; + ret = request_firmware(&fw, image_name, dev); if (ret) { mgr->state = FPGA_MGR_STATE_FIRMWARE_REQ_ERR; @@ -478,14 +481,41 @@ static ssize_t status_show(struct device *dev, return len; } +static ssize_t firmware_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct fpga_manager *mgr = to_fpga_manager(dev); + unsigned int len; + char image_name[NAME_MAX]; + int ret; + + /* struct with information about the FPGA image to program. */ + struct fpga_image_info info = {0}; + + /* lose terminating \n */ + strcpy(image_name, buf); + len = strlen(image_name); + if (image_name[len - 1] == '\n') + image_name[len - 1] = 0; + + ret = fpga_mgr_firmware_load(mgr, &info, image_name); + if (ret) + return ret; + + return count; +} + static DEVICE_ATTR_RO(name); static DEVICE_ATTR_RO(state); static DEVICE_ATTR_RO(status); +static DEVICE_ATTR_WO(firmware); static struct attribute *fpga_mgr_attrs[] = { &dev_attr_name.attr, &dev_attr_state.attr, &dev_attr_status.attr, + &dev_attr_firmware.attr, NULL, }; ATTRIBUTE_GROUPS(fpga_mgr); diff --git a/include/linux/fpga/fpga-mgr.h b/include/linux/fpga/fpga-mgr.h index 474c1f5063070..9b97c520e3f7e 100644 --- a/include/linux/fpga/fpga-mgr.h +++ b/include/linux/fpga/fpga-mgr.h @@ -157,6 +157,7 @@ struct fpga_compat_id { /** * struct fpga_manager - fpga manager structure * @name: name of low level fpga manager + * @flags: flags determines the type of Bitstream * @dev: fpga manager device * @ref_mutex: only allows one reference to fpga manager * @state: state of fpga manager @@ -166,6 +167,7 @@ struct fpga_compat_id { */ struct fpga_manager { const char *name; + unsigned long flags; struct device dev; struct mutex ref_mutex; enum fpga_mgr_states state;