remoteproc: Decouple vdev resources and devices

Represent the virtio device part of the vdev resources as remoteproc
subdevices to finalize the decoupling of the virtio resource and device
handling.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
This commit is contained in:
Bjorn Andersson 2016-10-19 19:40:09 -07:00
parent 2b45cef586
commit f5bcb35387
2 changed files with 25 additions and 15 deletions

View File

@ -296,6 +296,20 @@ void rproc_free_vring(struct rproc_vring *rvring)
rsc->vring[idx].notifyid = -1; rsc->vring[idx].notifyid = -1;
} }
static int rproc_vdev_do_probe(struct rproc_subdev *subdev)
{
struct rproc_vdev *rvdev = container_of(subdev, struct rproc_vdev, subdev);
return rproc_add_virtio_dev(rvdev, rvdev->id);
}
static void rproc_vdev_do_remove(struct rproc_subdev *subdev)
{
struct rproc_vdev *rvdev = container_of(subdev, struct rproc_vdev, subdev);
rproc_remove_virtio_dev(rvdev);
}
/** /**
* rproc_handle_vdev() - handle a vdev fw resource * rproc_handle_vdev() - handle a vdev fw resource
* @rproc: the remote processor * @rproc: the remote processor
@ -358,6 +372,7 @@ static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc,
kref_init(&rvdev->refcount); kref_init(&rvdev->refcount);
rvdev->id = rsc->id;
rvdev->rproc = rproc; rvdev->rproc = rproc;
/* parse the vrings */ /* parse the vrings */
@ -382,18 +397,14 @@ static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc,
list_add_tail(&rvdev->node, &rproc->rvdevs); list_add_tail(&rvdev->node, &rproc->rvdevs);
/* it is now safe to add the virtio device */ rproc_add_subdev(rproc, &rvdev->subdev,
ret = rproc_add_virtio_dev(rvdev, rsc->id); rproc_vdev_do_probe, rproc_vdev_do_remove);
if (ret)
goto remove_rvdev;
return 0; return 0;
unwind_vring_allocations: unwind_vring_allocations:
for (i--; i >= 0; i--) for (i--; i >= 0; i--)
rproc_free_vring(&rvdev->vring[i]); rproc_free_vring(&rvdev->vring[i]);
remove_rvdev:
list_del(&rvdev->node);
free_rvdev: free_rvdev:
kfree(rvdev); kfree(rvdev);
return ret; return ret;
@ -403,6 +414,7 @@ void rproc_vdev_release(struct kref *ref)
{ {
struct rproc_vdev *rvdev = container_of(ref, struct rproc_vdev, refcount); struct rproc_vdev *rvdev = container_of(ref, struct rproc_vdev, refcount);
struct rproc_vring *rvring; struct rproc_vring *rvring;
struct rproc *rproc = rvdev->rproc;
int id; int id;
for (id = 0; id < ARRAY_SIZE(rvdev->vring); id++) { for (id = 0; id < ARRAY_SIZE(rvdev->vring); id++) {
@ -413,6 +425,7 @@ void rproc_vdev_release(struct kref *ref)
rproc_free_vring(rvring); rproc_free_vring(rvring);
} }
rproc_remove_subdev(rproc, &rvdev->subdev);
list_del(&rvdev->node); list_del(&rvdev->node);
kfree(rvdev); kfree(rvdev);
} }
@ -842,10 +855,8 @@ static void rproc_resource_cleanup(struct rproc *rproc)
} }
/* clean up remote vdev entries */ /* clean up remote vdev entries */
list_for_each_entry_safe(rvdev, rvtmp, &rproc->rvdevs, node) { list_for_each_entry_safe(rvdev, rvtmp, &rproc->rvdevs, node)
rproc_remove_virtio_dev(rvdev);
kref_put(&rvdev->refcount, rproc_vdev_release); kref_put(&rvdev->refcount, rproc_vdev_release);
}
} }
/* /*
@ -1507,8 +1518,6 @@ EXPORT_SYMBOL(rproc_put);
*/ */
int rproc_del(struct rproc *rproc) int rproc_del(struct rproc *rproc)
{ {
struct rproc_vdev *rvdev, *tmp;
if (!rproc) if (!rproc)
return -EINVAL; return -EINVAL;
@ -1520,10 +1529,6 @@ int rproc_del(struct rproc *rproc)
if (rproc->auto_boot) if (rproc->auto_boot)
rproc_shutdown(rproc); rproc_shutdown(rproc);
/* clean up remote vdev entries */
list_for_each_entry_safe(rvdev, tmp, &rproc->rvdevs, node)
rproc_remove_virtio_dev(rvdev);
/* the rproc is downref'ed as soon as it's removed from the klist */ /* the rproc is downref'ed as soon as it's removed from the klist */
mutex_lock(&rproc_list_mutex); mutex_lock(&rproc_list_mutex);
list_del(&rproc->node); list_del(&rproc->node);

View File

@ -488,6 +488,8 @@ struct rproc_vring {
/** /**
* struct rproc_vdev - remoteproc state for a supported virtio device * struct rproc_vdev - remoteproc state for a supported virtio device
* @refcount: reference counter for the vdev and vring allocations * @refcount: reference counter for the vdev and vring allocations
* @subdev: handle for registering the vdev as a rproc subdevice
* @id: virtio device id (as in virtio_ids.h)
* @node: list node * @node: list node
* @rproc: the rproc handle * @rproc: the rproc handle
* @vdev: the virio device * @vdev: the virio device
@ -497,6 +499,9 @@ struct rproc_vring {
struct rproc_vdev { struct rproc_vdev {
struct kref refcount; struct kref refcount;
struct rproc_subdev subdev;
unsigned int id;
struct list_head node; struct list_head node;
struct rproc *rproc; struct rproc *rproc;
struct virtio_device vdev; struct virtio_device vdev;