Skip to content

Commit

Permalink
fpga: Add firmware store function
Browse files Browse the repository at this point in the history
For testing purpose.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Acked-by: Nava kishore Manne <navam@xilinx.com>
Signed-off-by: Nava kishore Manne <nava.manne@xilinx.com>
Signed-off-by: Radhey Shyam Pandey <radhey.shyam.pandey@xilinx.com>
State: not-upstreamable
  • Loading branch information
Michal Simek committed Jan 31, 2022
1 parent 3edc2fd commit a901922
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
30 changes: 30 additions & 0 deletions drivers/fpga/fpga-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions include/linux/fpga/fpga-mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit a901922

Please sign in to comment.