Skip to content

Commit

Permalink
remoteproc: Add support for peek from remote and acking kick from remote
Browse files Browse the repository at this point in the history
Add support for checking if remote has kicked and acking the
remote's kick in include/linux/remoteproc. Update
remoteproc_internal to indicate if the driver allows to kick
remoteproc from sysfs. Add remoteproc_sysfs support for kicking
remote, storing remote kick and checking if remote has kicked.

Signed-off-by: Wendy Liang <wendy.liang@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
State: pending
  • Loading branch information
Wendy Liang authored and Michal Simek committed Mar 22, 2021
1 parent dc7ae04 commit a324889
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 1 deletion.
23 changes: 23 additions & 0 deletions drivers/remoteproc/remoteproc_internal.h
Expand Up @@ -186,4 +186,27 @@ bool rproc_u64_fit_in_size_t(u64 val)
return (val <= (size_t) -1);
}

static inline
bool rproc_allow_sysfs_kick(struct rproc *rproc)
{
return (rproc->sysfs_kick) ? true : false;
}

static inline
bool rproc_peek_remote_kick(struct rproc *rproc)
{
if (rproc->ops->peek_remote_kick)
return rproc->ops->peek_remote_kick(rproc);
else
return false;
}

static inline
void rproc_ack_remote_kick(struct rproc *rproc)
{
if (rproc->ops->ack_remote_kick)
rproc->ops->ack_remote_kick(rproc);
}

int rproc_create_kick_sysfs(struct rproc *rproc);
#endif /* REMOTEPROC_INTERNAL_H */
104 changes: 104 additions & 0 deletions drivers/remoteproc/remoteproc_sysfs.c
Expand Up @@ -244,6 +244,82 @@ static ssize_t state_store(struct device *dev,
}
static DEVICE_ATTR_RW(state);

/**
* kick_store() - Kick remote from sysfs.
* @dev: remoteproc device
* @attr: sysfs device attribute
* @buf: sysfs buffer
* @count: size of the contents in buf
*
* It will just raise a signal, no content is expected for now.
*
* Return: the input count if it allows kick from sysfs,
* as it is always expected to succeed.
*/
static ssize_t kick_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct rproc *rproc = to_rproc(dev);

(void)attr;
(void)buf;

if (rproc->ops->kick)
rproc->ops->kick(rproc, 0);
else
count = -EINVAL;
return count;
}
static DEVICE_ATTR_WO(kick);

/**
* remote_kick_show() - Check if remote has kicked
* @dev: remoteproc device
* @attr: sysfs device attribute
* @buf: sysfs buffer
*
* It will check if the remote has kicked.
*
* Return: always 2, and the value in the sysfs buffer
* shows if the remote has kicked. '0' - not kicked, '1' - kicked.
*/
static ssize_t remote_kick_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct rproc *rproc = to_rproc(dev);

buf[0] = '0';
buf[1] = '\n';
if (rproc_peek_remote_kick(rproc))
buf[0] = '1';
return 2;
}

/**
* remote_kick_store() - Ack the kick from remote
* @dev: remoteproc device
* @attr: sysfs device attribute
* @buf: sysfs buffer
* @count: size of the contents in buf
*
* It will ack the remote, no response contents is expected.
*
* Return: the input count if it allows kick from sysfs,
* as it is always expected to succeed.
*/
static ssize_t remote_kick_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct rproc *rproc = to_rproc(dev);

rproc_ack_remote_kick(rproc);
return count;
}
static DEVICE_ATTR_RW(remote_kick);

/* Expose the name of the remote processor via sysfs */
static ssize_t name_show(struct device *dev, struct device_attribute *attr,
char *buf)
Expand Down Expand Up @@ -277,6 +353,34 @@ struct class rproc_class = {
.dev_groups = rproc_devgroups,
};

/**
* rproc_create_kick_sysfs() - create kick remote sysfs entry
* @rproc: remoteproc
*
* It will create kick remote sysfs entry if kick remote
* from sysfs is allowed.
*
* Return: 0 for success, and negative value for failure.
*/
int rproc_create_kick_sysfs(struct rproc *rproc)
{
struct device *dev = &rproc->dev;
int ret;

if (!rproc_allow_sysfs_kick(rproc))
return -EINVAL;
ret = sysfs_create_file(&dev->kobj, &dev_attr_kick.attr);
if (ret) {
dev_err(dev, "failed to create sysfs for kick.\n");
return ret;
}
ret = sysfs_create_file(&dev->kobj, &dev_attr_remote_kick.attr);
if (ret)
dev_err(dev, "failed to create sysfs for remote kick.\n");
return ret;
}
EXPORT_SYMBOL(rproc_create_kick_sysfs);

int __init rproc_init_sysfs(void)
{
/* create remoteproc device class for sysfs */
Expand Down
8 changes: 7 additions & 1 deletion include/linux/remoteproc.h
Expand Up @@ -362,6 +362,8 @@ enum rsc_handling_status {
* @stop: power off the device
* @attach: attach to a device that his already powered up
* @kick: kick a virtqueue (virtqueue id given as a parameter)
* @peek_remote_kick: check if remote has kicked
* @ack_remote_kick: ack remote kick
* @da_to_va: optional platform hook to perform address translations
* @parse_fw: parse firmware to extract information (e.g. resource table)
* @handle_rsc: optional platform hook to handle vendor resources. Should return
Expand All @@ -383,7 +385,9 @@ struct rproc_ops {
int (*stop)(struct rproc *rproc);
int (*attach)(struct rproc *rproc);
void (*kick)(struct rproc *rproc, int vqid);
void * (*da_to_va)(struct rproc *rproc, u64 da, size_t len);
bool (*peek_remote_kick)(struct rproc *rproc);
void (*ack_remote_kick)(struct rproc *rproc);
void * (*da_to_va)(struct rproc *rproc, u64 da, int len);
int (*parse_fw)(struct rproc *rproc, const struct firmware *fw);
int (*handle_rsc)(struct rproc *rproc, u32 rsc_type, void *rsc,
int offset, int avail);
Expand Down Expand Up @@ -510,6 +514,7 @@ struct rproc_dump_segment {
* @autonomous: true if an external entity has booted the remote processor
* @dump_segments: list of segments in the firmware
* @nb_vdev: number of vdev currently handled by rproc
* @sysfs_kick: allow kick remoteproc from sysfs
* @char_dev: character device of the rproc
* @cdev_put_on_release: flag to indicate if remoteproc should be shutdown on @char_dev release
*/
Expand Down Expand Up @@ -547,6 +552,7 @@ struct rproc {
bool autonomous;
struct list_head dump_segments;
int nb_vdev;
int sysfs_kick;
u8 elf_class;
u16 elf_machine;
struct cdev cdev;
Expand Down

0 comments on commit a324889

Please sign in to comment.