xref: /linux/drivers/remoteproc/remoteproc_virtio.c (revision 46f9c2b925ac12e5ad8b8b7c90c71dacc9d5db37)
104a9016eSOhad Ben-Cohen /*
204a9016eSOhad Ben-Cohen  * Remote processor messaging transport (OMAP platform-specific bits)
304a9016eSOhad Ben-Cohen  *
404a9016eSOhad Ben-Cohen  * Copyright (C) 2011 Texas Instruments, Inc.
504a9016eSOhad Ben-Cohen  * Copyright (C) 2011 Google, Inc.
604a9016eSOhad Ben-Cohen  *
704a9016eSOhad Ben-Cohen  * Ohad Ben-Cohen <ohad@wizery.com>
804a9016eSOhad Ben-Cohen  * Brian Swetland <swetland@google.com>
904a9016eSOhad Ben-Cohen  *
1004a9016eSOhad Ben-Cohen  * This software is licensed under the terms of the GNU General Public
1104a9016eSOhad Ben-Cohen  * License version 2, as published by the Free Software Foundation, and
1204a9016eSOhad Ben-Cohen  * may be copied, distributed, and modified under those terms.
1304a9016eSOhad Ben-Cohen  *
1404a9016eSOhad Ben-Cohen  * This program is distributed in the hope that it will be useful,
1504a9016eSOhad Ben-Cohen  * but WITHOUT ANY WARRANTY; without even the implied warranty of
1604a9016eSOhad Ben-Cohen  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1704a9016eSOhad Ben-Cohen  * GNU General Public License for more details.
1804a9016eSOhad Ben-Cohen  */
1904a9016eSOhad Ben-Cohen 
2004a9016eSOhad Ben-Cohen #include <linux/export.h>
2104a9016eSOhad Ben-Cohen #include <linux/remoteproc.h>
2204a9016eSOhad Ben-Cohen #include <linux/virtio.h>
2304a9016eSOhad Ben-Cohen #include <linux/virtio_config.h>
2404a9016eSOhad Ben-Cohen #include <linux/virtio_ids.h>
2504a9016eSOhad Ben-Cohen #include <linux/virtio_ring.h>
2604a9016eSOhad Ben-Cohen #include <linux/err.h>
2704a9016eSOhad Ben-Cohen #include <linux/kref.h>
2804a9016eSOhad Ben-Cohen #include <linux/slab.h>
2904a9016eSOhad Ben-Cohen 
3004a9016eSOhad Ben-Cohen #include "remoteproc_internal.h"
3104a9016eSOhad Ben-Cohen 
3204a9016eSOhad Ben-Cohen /* kick the remote processor, and let it know which virtqueue to poke at */
33*46f9c2b9SHeinz Graalfs static bool rproc_virtio_notify(struct virtqueue *vq)
3404a9016eSOhad Ben-Cohen {
357a186941SOhad Ben-Cohen 	struct rproc_vring *rvring = vq->priv;
367a186941SOhad Ben-Cohen 	struct rproc *rproc = rvring->rvdev->rproc;
377a186941SOhad Ben-Cohen 	int notifyid = rvring->notifyid;
3804a9016eSOhad Ben-Cohen 
39b5ab5e24SOhad Ben-Cohen 	dev_dbg(&rproc->dev, "kicking vq index: %d\n", notifyid);
4004a9016eSOhad Ben-Cohen 
417a186941SOhad Ben-Cohen 	rproc->ops->kick(rproc, notifyid);
42*46f9c2b9SHeinz Graalfs 	return true;
4304a9016eSOhad Ben-Cohen }
4404a9016eSOhad Ben-Cohen 
4504a9016eSOhad Ben-Cohen /**
4604a9016eSOhad Ben-Cohen  * rproc_vq_interrupt() - tell remoteproc that a virtqueue is interrupted
4704a9016eSOhad Ben-Cohen  * @rproc: handle to the remote processor
487a186941SOhad Ben-Cohen  * @notifyid: index of the signalled virtqueue (unique per this @rproc)
4904a9016eSOhad Ben-Cohen  *
5004a9016eSOhad Ben-Cohen  * This function should be called by the platform-specific rproc driver,
5104a9016eSOhad Ben-Cohen  * when the remote processor signals that a specific virtqueue has pending
5204a9016eSOhad Ben-Cohen  * messages available.
5304a9016eSOhad Ben-Cohen  *
547a186941SOhad Ben-Cohen  * Returns IRQ_NONE if no message was found in the @notifyid virtqueue,
5504a9016eSOhad Ben-Cohen  * and otherwise returns IRQ_HANDLED.
5604a9016eSOhad Ben-Cohen  */
577a186941SOhad Ben-Cohen irqreturn_t rproc_vq_interrupt(struct rproc *rproc, int notifyid)
5804a9016eSOhad Ben-Cohen {
597a186941SOhad Ben-Cohen 	struct rproc_vring *rvring;
607a186941SOhad Ben-Cohen 
61b5ab5e24SOhad Ben-Cohen 	dev_dbg(&rproc->dev, "vq index %d is interrupted\n", notifyid);
627a186941SOhad Ben-Cohen 
637a186941SOhad Ben-Cohen 	rvring = idr_find(&rproc->notifyids, notifyid);
647a186941SOhad Ben-Cohen 	if (!rvring || !rvring->vq)
657a186941SOhad Ben-Cohen 		return IRQ_NONE;
667a186941SOhad Ben-Cohen 
677a186941SOhad Ben-Cohen 	return vring_interrupt(0, rvring->vq);
6804a9016eSOhad Ben-Cohen }
6904a9016eSOhad Ben-Cohen EXPORT_SYMBOL(rproc_vq_interrupt);
7004a9016eSOhad Ben-Cohen 
7104a9016eSOhad Ben-Cohen static struct virtqueue *rp_find_vq(struct virtio_device *vdev,
7204a9016eSOhad Ben-Cohen 				    unsigned id,
7304a9016eSOhad Ben-Cohen 				    void (*callback)(struct virtqueue *vq),
7404a9016eSOhad Ben-Cohen 				    const char *name)
7504a9016eSOhad Ben-Cohen {
767a186941SOhad Ben-Cohen 	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
7704a9016eSOhad Ben-Cohen 	struct rproc *rproc = vdev_to_rproc(vdev);
78b5ab5e24SOhad Ben-Cohen 	struct device *dev = &rproc->dev;
797a186941SOhad Ben-Cohen 	struct rproc_vring *rvring;
8004a9016eSOhad Ben-Cohen 	struct virtqueue *vq;
8104a9016eSOhad Ben-Cohen 	void *addr;
826db20ea8SOhad Ben-Cohen 	int len, size, ret;
8304a9016eSOhad Ben-Cohen 
847a186941SOhad Ben-Cohen 	/* we're temporarily limited to two virtqueues per rvdev */
857a186941SOhad Ben-Cohen 	if (id >= ARRAY_SIZE(rvdev->vring))
867a186941SOhad Ben-Cohen 		return ERR_PTR(-EINVAL);
8704a9016eSOhad Ben-Cohen 
886457f126SMichael S. Tsirkin 	if (!name)
896457f126SMichael S. Tsirkin 		return NULL;
906457f126SMichael S. Tsirkin 
916db20ea8SOhad Ben-Cohen 	ret = rproc_alloc_vring(rvdev, id);
926db20ea8SOhad Ben-Cohen 	if (ret)
936db20ea8SOhad Ben-Cohen 		return ERR_PTR(ret);
9404a9016eSOhad Ben-Cohen 
956db20ea8SOhad Ben-Cohen 	rvring = &rvdev->vring[id];
967a186941SOhad Ben-Cohen 	addr = rvring->va;
977a186941SOhad Ben-Cohen 	len = rvring->len;
9804a9016eSOhad Ben-Cohen 
997a186941SOhad Ben-Cohen 	/* zero vring */
1007a186941SOhad Ben-Cohen 	size = vring_size(len, rvring->align);
1017a186941SOhad Ben-Cohen 	memset(addr, 0, size);
1027a186941SOhad Ben-Cohen 
103b5ab5e24SOhad Ben-Cohen 	dev_dbg(dev, "vring%d: va %p qsz %d notifyid %d\n",
1047a186941SOhad Ben-Cohen 					id, addr, len, rvring->notifyid);
10504a9016eSOhad Ben-Cohen 
10604a9016eSOhad Ben-Cohen 	/*
10704a9016eSOhad Ben-Cohen 	 * Create the new vq, and tell virtio we're not interested in
10804a9016eSOhad Ben-Cohen 	 * the 'weak' smp barriers, since we're talking with a real device.
10904a9016eSOhad Ben-Cohen 	 */
11017bb6d40SJason Wang 	vq = vring_new_virtqueue(id, len, rvring->align, vdev, false, addr,
11104a9016eSOhad Ben-Cohen 					rproc_virtio_notify, callback, name);
11204a9016eSOhad Ben-Cohen 	if (!vq) {
113b5ab5e24SOhad Ben-Cohen 		dev_err(dev, "vring_new_virtqueue %s failed\n", name);
1146db20ea8SOhad Ben-Cohen 		rproc_free_vring(rvring);
1157a186941SOhad Ben-Cohen 		return ERR_PTR(-ENOMEM);
11604a9016eSOhad Ben-Cohen 	}
11704a9016eSOhad Ben-Cohen 
1187a186941SOhad Ben-Cohen 	rvring->vq = vq;
1197a186941SOhad Ben-Cohen 	vq->priv = rvring;
12004a9016eSOhad Ben-Cohen 
12104a9016eSOhad Ben-Cohen 	return vq;
12204a9016eSOhad Ben-Cohen }
12304a9016eSOhad Ben-Cohen 
124dab55bbaSOhad Ben-Cohen static void __rproc_virtio_del_vqs(struct virtio_device *vdev)
12504a9016eSOhad Ben-Cohen {
12604a9016eSOhad Ben-Cohen 	struct virtqueue *vq, *n;
1277a186941SOhad Ben-Cohen 	struct rproc_vring *rvring;
12804a9016eSOhad Ben-Cohen 
12904a9016eSOhad Ben-Cohen 	list_for_each_entry_safe(vq, n, &vdev->vqs, list) {
1307a186941SOhad Ben-Cohen 		rvring = vq->priv;
1317a186941SOhad Ben-Cohen 		rvring->vq = NULL;
13204a9016eSOhad Ben-Cohen 		vring_del_virtqueue(vq);
1336db20ea8SOhad Ben-Cohen 		rproc_free_vring(rvring);
13404a9016eSOhad Ben-Cohen 	}
13504a9016eSOhad Ben-Cohen }
13604a9016eSOhad Ben-Cohen 
137dab55bbaSOhad Ben-Cohen static void rproc_virtio_del_vqs(struct virtio_device *vdev)
138dab55bbaSOhad Ben-Cohen {
139dab55bbaSOhad Ben-Cohen 	struct rproc *rproc = vdev_to_rproc(vdev);
140dab55bbaSOhad Ben-Cohen 
141dab55bbaSOhad Ben-Cohen 	/* power down the remote processor before deleting vqs */
142dab55bbaSOhad Ben-Cohen 	rproc_shutdown(rproc);
143dab55bbaSOhad Ben-Cohen 
144dab55bbaSOhad Ben-Cohen 	__rproc_virtio_del_vqs(vdev);
145dab55bbaSOhad Ben-Cohen }
146dab55bbaSOhad Ben-Cohen 
14704a9016eSOhad Ben-Cohen static int rproc_virtio_find_vqs(struct virtio_device *vdev, unsigned nvqs,
14804a9016eSOhad Ben-Cohen 		       struct virtqueue *vqs[],
14904a9016eSOhad Ben-Cohen 		       vq_callback_t *callbacks[],
15004a9016eSOhad Ben-Cohen 		       const char *names[])
15104a9016eSOhad Ben-Cohen {
15204a9016eSOhad Ben-Cohen 	struct rproc *rproc = vdev_to_rproc(vdev);
15304a9016eSOhad Ben-Cohen 	int i, ret;
15404a9016eSOhad Ben-Cohen 
15504a9016eSOhad Ben-Cohen 	for (i = 0; i < nvqs; ++i) {
15604a9016eSOhad Ben-Cohen 		vqs[i] = rp_find_vq(vdev, i, callbacks[i], names[i]);
15704a9016eSOhad Ben-Cohen 		if (IS_ERR(vqs[i])) {
15804a9016eSOhad Ben-Cohen 			ret = PTR_ERR(vqs[i]);
15904a9016eSOhad Ben-Cohen 			goto error;
16004a9016eSOhad Ben-Cohen 		}
16104a9016eSOhad Ben-Cohen 	}
16204a9016eSOhad Ben-Cohen 
16341a6ee09SOhad Ben-Cohen 	/* now that the vqs are all set, boot the remote processor */
16441a6ee09SOhad Ben-Cohen 	ret = rproc_boot(rproc);
16541a6ee09SOhad Ben-Cohen 	if (ret) {
166b5ab5e24SOhad Ben-Cohen 		dev_err(&rproc->dev, "rproc_boot() failed %d\n", ret);
16741a6ee09SOhad Ben-Cohen 		goto error;
16841a6ee09SOhad Ben-Cohen 	}
16941a6ee09SOhad Ben-Cohen 
17004a9016eSOhad Ben-Cohen 	return 0;
17104a9016eSOhad Ben-Cohen 
17204a9016eSOhad Ben-Cohen error:
173dab55bbaSOhad Ben-Cohen 	__rproc_virtio_del_vqs(vdev);
17404a9016eSOhad Ben-Cohen 	return ret;
17504a9016eSOhad Ben-Cohen }
17604a9016eSOhad Ben-Cohen 
17704a9016eSOhad Ben-Cohen static u8 rproc_virtio_get_status(struct virtio_device *vdev)
17804a9016eSOhad Ben-Cohen {
17992b38f85SSjur Brændeland 	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
18092b38f85SSjur Brændeland 	struct fw_rsc_vdev *rsc;
18192b38f85SSjur Brændeland 
18292b38f85SSjur Brændeland 	rsc = (void *)rvdev->rproc->table_ptr + rvdev->rsc_offset;
18392b38f85SSjur Brændeland 
18492b38f85SSjur Brændeland 	return rsc->status;
18504a9016eSOhad Ben-Cohen }
18604a9016eSOhad Ben-Cohen 
18704a9016eSOhad Ben-Cohen static void rproc_virtio_set_status(struct virtio_device *vdev, u8 status)
18804a9016eSOhad Ben-Cohen {
18992b38f85SSjur Brændeland 	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
19092b38f85SSjur Brændeland 	struct fw_rsc_vdev *rsc;
19192b38f85SSjur Brændeland 
19292b38f85SSjur Brændeland 	rsc = (void *)rvdev->rproc->table_ptr + rvdev->rsc_offset;
19392b38f85SSjur Brændeland 
19492b38f85SSjur Brændeland 	rsc->status = status;
1957a186941SOhad Ben-Cohen 	dev_dbg(&vdev->dev, "status: %d\n", status);
19604a9016eSOhad Ben-Cohen }
19704a9016eSOhad Ben-Cohen 
19804a9016eSOhad Ben-Cohen static void rproc_virtio_reset(struct virtio_device *vdev)
19904a9016eSOhad Ben-Cohen {
20092b38f85SSjur Brændeland 	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
20192b38f85SSjur Brændeland 	struct fw_rsc_vdev *rsc;
20292b38f85SSjur Brændeland 
20392b38f85SSjur Brændeland 	rsc = (void *)rvdev->rproc->table_ptr + rvdev->rsc_offset;
20492b38f85SSjur Brændeland 
20592b38f85SSjur Brændeland 	rsc->status = 0;
20604a9016eSOhad Ben-Cohen 	dev_dbg(&vdev->dev, "reset !\n");
20704a9016eSOhad Ben-Cohen }
20804a9016eSOhad Ben-Cohen 
20904a9016eSOhad Ben-Cohen /* provide the vdev features as retrieved from the firmware */
21004a9016eSOhad Ben-Cohen static u32 rproc_virtio_get_features(struct virtio_device *vdev)
21104a9016eSOhad Ben-Cohen {
2127a186941SOhad Ben-Cohen 	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
21392b38f85SSjur Brændeland 	struct fw_rsc_vdev *rsc;
21404a9016eSOhad Ben-Cohen 
21592b38f85SSjur Brændeland 	rsc = (void *)rvdev->rproc->table_ptr + rvdev->rsc_offset;
21692b38f85SSjur Brændeland 
21792b38f85SSjur Brændeland 	return rsc->dfeatures;
21804a9016eSOhad Ben-Cohen }
21904a9016eSOhad Ben-Cohen 
22004a9016eSOhad Ben-Cohen static void rproc_virtio_finalize_features(struct virtio_device *vdev)
22104a9016eSOhad Ben-Cohen {
2227a186941SOhad Ben-Cohen 	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
22392b38f85SSjur Brændeland 	struct fw_rsc_vdev *rsc;
22492b38f85SSjur Brændeland 
22592b38f85SSjur Brændeland 	rsc = (void *)rvdev->rproc->table_ptr + rvdev->rsc_offset;
22604a9016eSOhad Ben-Cohen 
22704a9016eSOhad Ben-Cohen 	/* Give virtio_ring a chance to accept features */
22804a9016eSOhad Ben-Cohen 	vring_transport_features(vdev);
22904a9016eSOhad Ben-Cohen 
23004a9016eSOhad Ben-Cohen 	/*
23104a9016eSOhad Ben-Cohen 	 * Remember the finalized features of our vdev, and provide it
23204a9016eSOhad Ben-Cohen 	 * to the remote processor once it is powered on.
23304a9016eSOhad Ben-Cohen 	 */
23492b38f85SSjur Brændeland 	rsc->gfeatures = vdev->features[0];
23592b38f85SSjur Brændeland }
23692b38f85SSjur Brændeland 
23792b38f85SSjur Brændeland static void rproc_virtio_get(struct virtio_device *vdev, unsigned offset,
23892b38f85SSjur Brændeland 							void *buf, unsigned len)
23992b38f85SSjur Brændeland {
24092b38f85SSjur Brændeland 	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
24192b38f85SSjur Brændeland 	struct fw_rsc_vdev *rsc;
24292b38f85SSjur Brændeland 	void *cfg;
24392b38f85SSjur Brændeland 
24492b38f85SSjur Brændeland 	rsc = (void *)rvdev->rproc->table_ptr + rvdev->rsc_offset;
24592b38f85SSjur Brændeland 	cfg = &rsc->vring[rsc->num_of_vrings];
24692b38f85SSjur Brændeland 
24792b38f85SSjur Brændeland 	if (offset + len > rsc->config_len || offset + len < len) {
24892b38f85SSjur Brændeland 		dev_err(&vdev->dev, "rproc_virtio_get: access out of bounds\n");
24992b38f85SSjur Brændeland 		return;
25092b38f85SSjur Brændeland 	}
25192b38f85SSjur Brændeland 
25292b38f85SSjur Brændeland 	memcpy(buf, cfg + offset, len);
25392b38f85SSjur Brændeland }
25492b38f85SSjur Brændeland 
25592b38f85SSjur Brændeland static void rproc_virtio_set(struct virtio_device *vdev, unsigned offset,
25692b38f85SSjur Brændeland 		      const void *buf, unsigned len)
25792b38f85SSjur Brændeland {
25892b38f85SSjur Brændeland 	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
25992b38f85SSjur Brændeland 	struct fw_rsc_vdev *rsc;
26092b38f85SSjur Brændeland 	void *cfg;
26192b38f85SSjur Brændeland 
26292b38f85SSjur Brændeland 	rsc = (void *)rvdev->rproc->table_ptr + rvdev->rsc_offset;
26392b38f85SSjur Brændeland 	cfg = &rsc->vring[rsc->num_of_vrings];
26492b38f85SSjur Brændeland 
26592b38f85SSjur Brændeland 	if (offset + len > rsc->config_len || offset + len < len) {
26692b38f85SSjur Brændeland 		dev_err(&vdev->dev, "rproc_virtio_set: access out of bounds\n");
26792b38f85SSjur Brændeland 		return;
26892b38f85SSjur Brændeland 	}
26992b38f85SSjur Brændeland 
27092b38f85SSjur Brændeland 	memcpy(cfg + offset, buf, len);
27104a9016eSOhad Ben-Cohen }
27204a9016eSOhad Ben-Cohen 
27393503932SStephen Hemminger static const struct virtio_config_ops rproc_virtio_config_ops = {
27404a9016eSOhad Ben-Cohen 	.get_features	= rproc_virtio_get_features,
27504a9016eSOhad Ben-Cohen 	.finalize_features = rproc_virtio_finalize_features,
27604a9016eSOhad Ben-Cohen 	.find_vqs	= rproc_virtio_find_vqs,
27704a9016eSOhad Ben-Cohen 	.del_vqs	= rproc_virtio_del_vqs,
27804a9016eSOhad Ben-Cohen 	.reset		= rproc_virtio_reset,
27904a9016eSOhad Ben-Cohen 	.set_status	= rproc_virtio_set_status,
28004a9016eSOhad Ben-Cohen 	.get_status	= rproc_virtio_get_status,
28192b38f85SSjur Brændeland 	.get		= rproc_virtio_get,
28292b38f85SSjur Brændeland 	.set		= rproc_virtio_set,
28304a9016eSOhad Ben-Cohen };
28404a9016eSOhad Ben-Cohen 
28504a9016eSOhad Ben-Cohen /*
28604a9016eSOhad Ben-Cohen  * This function is called whenever vdev is released, and is responsible
2877183a2a7SOhad Ben-Cohen  * to decrement the remote processor's refcount which was taken when vdev was
28804a9016eSOhad Ben-Cohen  * added.
28904a9016eSOhad Ben-Cohen  *
29004a9016eSOhad Ben-Cohen  * Never call this function directly; it will be called by the driver
29104a9016eSOhad Ben-Cohen  * core when needed.
29204a9016eSOhad Ben-Cohen  */
29304a9016eSOhad Ben-Cohen static void rproc_vdev_release(struct device *dev)
29404a9016eSOhad Ben-Cohen {
29504a9016eSOhad Ben-Cohen 	struct virtio_device *vdev = dev_to_virtio(dev);
2966db20ea8SOhad Ben-Cohen 	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
29704a9016eSOhad Ben-Cohen 	struct rproc *rproc = vdev_to_rproc(vdev);
29804a9016eSOhad Ben-Cohen 
2996db20ea8SOhad Ben-Cohen 	list_del(&rvdev->node);
3006db20ea8SOhad Ben-Cohen 	kfree(rvdev);
3016db20ea8SOhad Ben-Cohen 
3027183a2a7SOhad Ben-Cohen 	put_device(&rproc->dev);
30304a9016eSOhad Ben-Cohen }
30404a9016eSOhad Ben-Cohen 
30504a9016eSOhad Ben-Cohen /**
3067a186941SOhad Ben-Cohen  * rproc_add_virtio_dev() - register an rproc-induced virtio device
3077a186941SOhad Ben-Cohen  * @rvdev: the remote vdev
30804a9016eSOhad Ben-Cohen  *
3097a186941SOhad Ben-Cohen  * This function registers a virtio device. This vdev's partent is
3107a186941SOhad Ben-Cohen  * the rproc device.
31104a9016eSOhad Ben-Cohen  *
3127a186941SOhad Ben-Cohen  * Returns 0 on success or an appropriate error value otherwise.
31304a9016eSOhad Ben-Cohen  */
3147a186941SOhad Ben-Cohen int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id)
31504a9016eSOhad Ben-Cohen {
3167a186941SOhad Ben-Cohen 	struct rproc *rproc = rvdev->rproc;
317b5ab5e24SOhad Ben-Cohen 	struct device *dev = &rproc->dev;
3187a186941SOhad Ben-Cohen 	struct virtio_device *vdev = &rvdev->vdev;
31904a9016eSOhad Ben-Cohen 	int ret;
32004a9016eSOhad Ben-Cohen 
3217a186941SOhad Ben-Cohen 	vdev->id.device	= id,
3227a186941SOhad Ben-Cohen 	vdev->config = &rproc_virtio_config_ops,
3237a186941SOhad Ben-Cohen 	vdev->dev.parent = dev;
3247a186941SOhad Ben-Cohen 	vdev->dev.release = rproc_vdev_release;
32504a9016eSOhad Ben-Cohen 
32604a9016eSOhad Ben-Cohen 	/*
32704a9016eSOhad Ben-Cohen 	 * We're indirectly making a non-temporary copy of the rproc pointer
32804a9016eSOhad Ben-Cohen 	 * here, because drivers probed with this vdev will indirectly
32904a9016eSOhad Ben-Cohen 	 * access the wrapping rproc.
33004a9016eSOhad Ben-Cohen 	 *
33104a9016eSOhad Ben-Cohen 	 * Therefore we must increment the rproc refcount here, and decrement
33204a9016eSOhad Ben-Cohen 	 * it _only_ when the vdev is released.
33304a9016eSOhad Ben-Cohen 	 */
3347183a2a7SOhad Ben-Cohen 	get_device(&rproc->dev);
33504a9016eSOhad Ben-Cohen 
3367a186941SOhad Ben-Cohen 	ret = register_virtio_device(vdev);
33704a9016eSOhad Ben-Cohen 	if (ret) {
3387183a2a7SOhad Ben-Cohen 		put_device(&rproc->dev);
33904a9016eSOhad Ben-Cohen 		dev_err(dev, "failed to register vdev: %d\n", ret);
3407a186941SOhad Ben-Cohen 		goto out;
34104a9016eSOhad Ben-Cohen 	}
34204a9016eSOhad Ben-Cohen 
3437a186941SOhad Ben-Cohen 	dev_info(dev, "registered %s (type %d)\n", dev_name(&vdev->dev), id);
3447a186941SOhad Ben-Cohen 
3457a186941SOhad Ben-Cohen out:
34604a9016eSOhad Ben-Cohen 	return ret;
34704a9016eSOhad Ben-Cohen }
34804a9016eSOhad Ben-Cohen 
34904a9016eSOhad Ben-Cohen /**
3507a186941SOhad Ben-Cohen  * rproc_remove_virtio_dev() - remove an rproc-induced virtio device
3517a186941SOhad Ben-Cohen  * @rvdev: the remote vdev
35204a9016eSOhad Ben-Cohen  *
3537a186941SOhad Ben-Cohen  * This function unregisters an existing virtio device.
35404a9016eSOhad Ben-Cohen  */
3557a186941SOhad Ben-Cohen void rproc_remove_virtio_dev(struct rproc_vdev *rvdev)
35604a9016eSOhad Ben-Cohen {
35704a9016eSOhad Ben-Cohen 	unregister_virtio_device(&rvdev->vdev);
35804a9016eSOhad Ben-Cohen }
359