Skip to content

Commit

Permalink
remoteproc: core: Task sync during rproc_fw_boot()
Browse files Browse the repository at this point in the history
By default, rproc_fw_boot() needs to wait for rproc to be configured,
but a race may occur when using rpmsg/virtio.  In this case, it can
be called locally in a safe manor.

This patch represents two usecases:

 - External call (via exported rproc_boot()), which waits
 - Internal call can use 'nowait' version of rproc_boot()

Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
  • Loading branch information
Lee Jones authored and Bjorn Andersson committed May 6, 2016
1 parent 9735a22 commit 3d87fa1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
29 changes: 27 additions & 2 deletions drivers/remoteproc/remoteproc_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1030,8 +1030,9 @@ static void rproc_crash_handler_work(struct work_struct *work)
}

/**
* rproc_boot() - boot a remote processor
* __rproc_boot() - boot a remote processor
* @rproc: handle of a remote processor
* @wait: wait for rproc registration completion
*
* Boot a remote processor (i.e. load its firmware, power it on, ...).
*
Expand All @@ -1040,7 +1041,7 @@ static void rproc_crash_handler_work(struct work_struct *work)
*
* Returns 0 on success, and an appropriate error value otherwise.
*/
int rproc_boot(struct rproc *rproc)
static int __rproc_boot(struct rproc *rproc, bool wait)
{
const struct firmware *firmware_p;
struct device *dev;
Expand Down Expand Up @@ -1088,6 +1089,10 @@ int rproc_boot(struct rproc *rproc)
goto downref_rproc;
}

/* if rproc virtio is not yet configured, wait */
if (wait)
wait_for_completion(&rproc->firmware_loading_complete);

ret = rproc_fw_boot(rproc, firmware_p);

release_firmware(firmware_p);
Expand All @@ -1101,8 +1106,28 @@ int rproc_boot(struct rproc *rproc)
mutex_unlock(&rproc->lock);
return ret;
}

/**
* rproc_boot() - boot a remote processor
* @rproc: handle of a remote processor
*/
int rproc_boot(struct rproc *rproc)
{
return __rproc_boot(rproc, true);
}
EXPORT_SYMBOL(rproc_boot);

/**
* rproc_boot_nowait() - boot a remote processor
* @rproc: handle of a remote processor
*
* Same as rproc_boot() but don't wait for rproc registration completion
*/
int rproc_boot_nowait(struct rproc *rproc)
{
return __rproc_boot(rproc, false);
}

/**
* rproc_shutdown() - power off the remote processor
* @rproc: the remote processor
Expand Down
1 change: 1 addition & 0 deletions drivers/remoteproc/remoteproc_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct rproc_fw_ops {
/* from remoteproc_core.c */
void rproc_release(struct kref *kref);
irqreturn_t rproc_vq_interrupt(struct rproc *rproc, int vq_id);
int rproc_boot_nowait(struct rproc *rproc);

/* from remoteproc_virtio.c */
int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id);
Expand Down
2 changes: 1 addition & 1 deletion drivers/remoteproc/remoteproc_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ static int rproc_virtio_find_vqs(struct virtio_device *vdev, unsigned nvqs,
}

/* now that the vqs are all set, boot the remote processor */
ret = rproc_boot(rproc);
ret = rproc_boot_nowait(rproc);
if (ret) {
dev_err(&rproc->dev, "rproc_boot() failed %d\n", ret);
goto error;
Expand Down

0 comments on commit 3d87fa1

Please sign in to comment.