xref: /linux/drivers/remoteproc/remoteproc_virtio.c (revision fb5e31d970ce8b4941f03ed765d7dbefc39f22d9)
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 */
3346f9c2b9SHeinz 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);
4246f9c2b9SHeinz 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,
72f145928dSAnna, Suman 				    unsigned int 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;
82a863af5dSBjorn Andersson 	int len, size;
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 	rvring = &rvdev->vring[id];
927a186941SOhad Ben-Cohen 	addr = rvring->va;
937a186941SOhad Ben-Cohen 	len = rvring->len;
9404a9016eSOhad Ben-Cohen 
957a186941SOhad Ben-Cohen 	/* zero vring */
967a186941SOhad Ben-Cohen 	size = vring_size(len, rvring->align);
977a186941SOhad Ben-Cohen 	memset(addr, 0, size);
987a186941SOhad Ben-Cohen 
99b5ab5e24SOhad Ben-Cohen 	dev_dbg(dev, "vring%d: va %p qsz %d notifyid %d\n",
1007a186941SOhad Ben-Cohen 		id, addr, len, rvring->notifyid);
10104a9016eSOhad Ben-Cohen 
10204a9016eSOhad Ben-Cohen 	/*
10304a9016eSOhad Ben-Cohen 	 * Create the new vq, and tell virtio we're not interested in
10404a9016eSOhad Ben-Cohen 	 * the 'weak' smp barriers, since we're talking with a real device.
10504a9016eSOhad Ben-Cohen 	 */
10617bb6d40SJason Wang 	vq = vring_new_virtqueue(id, len, rvring->align, vdev, false, addr,
10704a9016eSOhad Ben-Cohen 				 rproc_virtio_notify, callback, name);
10804a9016eSOhad Ben-Cohen 	if (!vq) {
109b5ab5e24SOhad Ben-Cohen 		dev_err(dev, "vring_new_virtqueue %s failed\n", name);
1106db20ea8SOhad Ben-Cohen 		rproc_free_vring(rvring);
1117a186941SOhad Ben-Cohen 		return ERR_PTR(-ENOMEM);
11204a9016eSOhad Ben-Cohen 	}
11304a9016eSOhad Ben-Cohen 
1147a186941SOhad Ben-Cohen 	rvring->vq = vq;
1157a186941SOhad Ben-Cohen 	vq->priv = rvring;
11604a9016eSOhad Ben-Cohen 
11704a9016eSOhad Ben-Cohen 	return vq;
11804a9016eSOhad Ben-Cohen }
11904a9016eSOhad Ben-Cohen 
120dab55bbaSOhad Ben-Cohen static void __rproc_virtio_del_vqs(struct virtio_device *vdev)
12104a9016eSOhad Ben-Cohen {
12204a9016eSOhad Ben-Cohen 	struct virtqueue *vq, *n;
1237a186941SOhad Ben-Cohen 	struct rproc_vring *rvring;
12404a9016eSOhad Ben-Cohen 
12504a9016eSOhad Ben-Cohen 	list_for_each_entry_safe(vq, n, &vdev->vqs, list) {
1267a186941SOhad Ben-Cohen 		rvring = vq->priv;
1277a186941SOhad Ben-Cohen 		rvring->vq = NULL;
12804a9016eSOhad Ben-Cohen 		vring_del_virtqueue(vq);
12904a9016eSOhad Ben-Cohen 	}
13004a9016eSOhad Ben-Cohen }
13104a9016eSOhad Ben-Cohen 
132dab55bbaSOhad Ben-Cohen static void rproc_virtio_del_vqs(struct virtio_device *vdev)
133dab55bbaSOhad Ben-Cohen {
134dab55bbaSOhad Ben-Cohen 	__rproc_virtio_del_vqs(vdev);
135dab55bbaSOhad Ben-Cohen }
136dab55bbaSOhad Ben-Cohen 
137f145928dSAnna, Suman static int rproc_virtio_find_vqs(struct virtio_device *vdev, unsigned int nvqs,
13804a9016eSOhad Ben-Cohen 				 struct virtqueue *vqs[],
13904a9016eSOhad Ben-Cohen 				 vq_callback_t *callbacks[],
140*fb5e31d9SChristoph Hellwig 				 const char * const names[],
141*fb5e31d9SChristoph Hellwig 				 struct irq_affinity *desc)
14204a9016eSOhad Ben-Cohen {
14304a9016eSOhad Ben-Cohen 	int i, ret;
14404a9016eSOhad Ben-Cohen 
14504a9016eSOhad Ben-Cohen 	for (i = 0; i < nvqs; ++i) {
14604a9016eSOhad Ben-Cohen 		vqs[i] = rp_find_vq(vdev, i, callbacks[i], names[i]);
14704a9016eSOhad Ben-Cohen 		if (IS_ERR(vqs[i])) {
14804a9016eSOhad Ben-Cohen 			ret = PTR_ERR(vqs[i]);
14904a9016eSOhad Ben-Cohen 			goto error;
15004a9016eSOhad Ben-Cohen 		}
15104a9016eSOhad Ben-Cohen 	}
15204a9016eSOhad Ben-Cohen 
15304a9016eSOhad Ben-Cohen 	return 0;
15404a9016eSOhad Ben-Cohen 
15504a9016eSOhad Ben-Cohen error:
156dab55bbaSOhad Ben-Cohen 	__rproc_virtio_del_vqs(vdev);
15704a9016eSOhad Ben-Cohen 	return ret;
15804a9016eSOhad Ben-Cohen }
15904a9016eSOhad Ben-Cohen 
16004a9016eSOhad Ben-Cohen static u8 rproc_virtio_get_status(struct virtio_device *vdev)
16104a9016eSOhad Ben-Cohen {
16292b38f85SSjur Brændeland 	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
16392b38f85SSjur Brændeland 	struct fw_rsc_vdev *rsc;
16492b38f85SSjur Brændeland 
16592b38f85SSjur Brændeland 	rsc = (void *)rvdev->rproc->table_ptr + rvdev->rsc_offset;
16692b38f85SSjur Brændeland 
16792b38f85SSjur Brændeland 	return rsc->status;
16804a9016eSOhad Ben-Cohen }
16904a9016eSOhad Ben-Cohen 
17004a9016eSOhad Ben-Cohen static void rproc_virtio_set_status(struct virtio_device *vdev, u8 status)
17104a9016eSOhad Ben-Cohen {
17292b38f85SSjur Brændeland 	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
17392b38f85SSjur Brændeland 	struct fw_rsc_vdev *rsc;
17492b38f85SSjur Brændeland 
17592b38f85SSjur Brændeland 	rsc = (void *)rvdev->rproc->table_ptr + rvdev->rsc_offset;
17692b38f85SSjur Brændeland 
17792b38f85SSjur Brændeland 	rsc->status = status;
1787a186941SOhad Ben-Cohen 	dev_dbg(&vdev->dev, "status: %d\n", status);
17904a9016eSOhad Ben-Cohen }
18004a9016eSOhad Ben-Cohen 
18104a9016eSOhad Ben-Cohen static void rproc_virtio_reset(struct virtio_device *vdev)
18204a9016eSOhad Ben-Cohen {
18392b38f85SSjur Brændeland 	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
18492b38f85SSjur Brændeland 	struct fw_rsc_vdev *rsc;
18592b38f85SSjur Brændeland 
18692b38f85SSjur Brændeland 	rsc = (void *)rvdev->rproc->table_ptr + rvdev->rsc_offset;
18792b38f85SSjur Brændeland 
18892b38f85SSjur Brændeland 	rsc->status = 0;
18904a9016eSOhad Ben-Cohen 	dev_dbg(&vdev->dev, "reset !\n");
19004a9016eSOhad Ben-Cohen }
19104a9016eSOhad Ben-Cohen 
19204a9016eSOhad Ben-Cohen /* provide the vdev features as retrieved from the firmware */
193d0254773SMichael S. Tsirkin static u64 rproc_virtio_get_features(struct virtio_device *vdev)
19404a9016eSOhad Ben-Cohen {
1957a186941SOhad Ben-Cohen 	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
19692b38f85SSjur Brændeland 	struct fw_rsc_vdev *rsc;
19704a9016eSOhad Ben-Cohen 
19892b38f85SSjur Brændeland 	rsc = (void *)rvdev->rproc->table_ptr + rvdev->rsc_offset;
19992b38f85SSjur Brændeland 
20092b38f85SSjur Brændeland 	return rsc->dfeatures;
20104a9016eSOhad Ben-Cohen }
20204a9016eSOhad Ben-Cohen 
2035c609a5eSMichael S. Tsirkin static int rproc_virtio_finalize_features(struct virtio_device *vdev)
20404a9016eSOhad Ben-Cohen {
2057a186941SOhad Ben-Cohen 	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
20692b38f85SSjur Brændeland 	struct fw_rsc_vdev *rsc;
20792b38f85SSjur Brændeland 
20892b38f85SSjur Brændeland 	rsc = (void *)rvdev->rproc->table_ptr + rvdev->rsc_offset;
20904a9016eSOhad Ben-Cohen 
21004a9016eSOhad Ben-Cohen 	/* Give virtio_ring a chance to accept features */
21104a9016eSOhad Ben-Cohen 	vring_transport_features(vdev);
21204a9016eSOhad Ben-Cohen 
21393d389f8SMichael S. Tsirkin 	/* Make sure we don't have any features > 32 bits! */
21493d389f8SMichael S. Tsirkin 	BUG_ON((u32)vdev->features != vdev->features);
21593d389f8SMichael S. Tsirkin 
21604a9016eSOhad Ben-Cohen 	/*
21704a9016eSOhad Ben-Cohen 	 * Remember the finalized features of our vdev, and provide it
21804a9016eSOhad Ben-Cohen 	 * to the remote processor once it is powered on.
21904a9016eSOhad Ben-Cohen 	 */
220e16e12beSMichael S. Tsirkin 	rsc->gfeatures = vdev->features;
2215c609a5eSMichael S. Tsirkin 
2225c609a5eSMichael S. Tsirkin 	return 0;
22392b38f85SSjur Brændeland }
22492b38f85SSjur Brændeland 
225f145928dSAnna, Suman static void rproc_virtio_get(struct virtio_device *vdev, unsigned int offset,
226f145928dSAnna, Suman 			     void *buf, unsigned int len)
22792b38f85SSjur Brændeland {
22892b38f85SSjur Brændeland 	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
22992b38f85SSjur Brændeland 	struct fw_rsc_vdev *rsc;
23092b38f85SSjur Brændeland 	void *cfg;
23192b38f85SSjur Brændeland 
23292b38f85SSjur Brændeland 	rsc = (void *)rvdev->rproc->table_ptr + rvdev->rsc_offset;
23392b38f85SSjur Brændeland 	cfg = &rsc->vring[rsc->num_of_vrings];
23492b38f85SSjur Brændeland 
23592b38f85SSjur Brændeland 	if (offset + len > rsc->config_len || offset + len < len) {
23692b38f85SSjur Brændeland 		dev_err(&vdev->dev, "rproc_virtio_get: access out of bounds\n");
23792b38f85SSjur Brændeland 		return;
23892b38f85SSjur Brændeland 	}
23992b38f85SSjur Brændeland 
24092b38f85SSjur Brændeland 	memcpy(buf, cfg + offset, len);
24192b38f85SSjur Brændeland }
24292b38f85SSjur Brændeland 
243f145928dSAnna, Suman static void rproc_virtio_set(struct virtio_device *vdev, unsigned int offset,
244f145928dSAnna, Suman 			     const void *buf, unsigned int len)
24592b38f85SSjur Brændeland {
24692b38f85SSjur Brændeland 	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
24792b38f85SSjur Brændeland 	struct fw_rsc_vdev *rsc;
24892b38f85SSjur Brændeland 	void *cfg;
24992b38f85SSjur Brændeland 
25092b38f85SSjur Brændeland 	rsc = (void *)rvdev->rproc->table_ptr + rvdev->rsc_offset;
25192b38f85SSjur Brændeland 	cfg = &rsc->vring[rsc->num_of_vrings];
25292b38f85SSjur Brændeland 
25392b38f85SSjur Brændeland 	if (offset + len > rsc->config_len || offset + len < len) {
25492b38f85SSjur Brændeland 		dev_err(&vdev->dev, "rproc_virtio_set: access out of bounds\n");
25592b38f85SSjur Brændeland 		return;
25692b38f85SSjur Brændeland 	}
25792b38f85SSjur Brændeland 
25892b38f85SSjur Brændeland 	memcpy(cfg + offset, buf, len);
25904a9016eSOhad Ben-Cohen }
26004a9016eSOhad Ben-Cohen 
26193503932SStephen Hemminger static const struct virtio_config_ops rproc_virtio_config_ops = {
26204a9016eSOhad Ben-Cohen 	.get_features	= rproc_virtio_get_features,
26304a9016eSOhad Ben-Cohen 	.finalize_features = rproc_virtio_finalize_features,
26404a9016eSOhad Ben-Cohen 	.find_vqs	= rproc_virtio_find_vqs,
26504a9016eSOhad Ben-Cohen 	.del_vqs	= rproc_virtio_del_vqs,
26604a9016eSOhad Ben-Cohen 	.reset		= rproc_virtio_reset,
26704a9016eSOhad Ben-Cohen 	.set_status	= rproc_virtio_set_status,
26804a9016eSOhad Ben-Cohen 	.get_status	= rproc_virtio_get_status,
26992b38f85SSjur Brændeland 	.get		= rproc_virtio_get,
27092b38f85SSjur Brændeland 	.set		= rproc_virtio_set,
27104a9016eSOhad Ben-Cohen };
27204a9016eSOhad Ben-Cohen 
27304a9016eSOhad Ben-Cohen /*
27404a9016eSOhad Ben-Cohen  * This function is called whenever vdev is released, and is responsible
2757183a2a7SOhad Ben-Cohen  * to decrement the remote processor's refcount which was taken when vdev was
27604a9016eSOhad Ben-Cohen  * added.
27704a9016eSOhad Ben-Cohen  *
27804a9016eSOhad Ben-Cohen  * Never call this function directly; it will be called by the driver
27904a9016eSOhad Ben-Cohen  * core when needed.
28004a9016eSOhad Ben-Cohen  */
281aab8d802SBjorn Andersson static void rproc_virtio_dev_release(struct device *dev)
28204a9016eSOhad Ben-Cohen {
28304a9016eSOhad Ben-Cohen 	struct virtio_device *vdev = dev_to_virtio(dev);
2846db20ea8SOhad Ben-Cohen 	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
28504a9016eSOhad Ben-Cohen 	struct rproc *rproc = vdev_to_rproc(vdev);
28604a9016eSOhad Ben-Cohen 
287aab8d802SBjorn Andersson 	kref_put(&rvdev->refcount, rproc_vdev_release);
2886db20ea8SOhad Ben-Cohen 
2897183a2a7SOhad Ben-Cohen 	put_device(&rproc->dev);
29004a9016eSOhad Ben-Cohen }
29104a9016eSOhad Ben-Cohen 
29204a9016eSOhad Ben-Cohen /**
2937a186941SOhad Ben-Cohen  * rproc_add_virtio_dev() - register an rproc-induced virtio device
2947a186941SOhad Ben-Cohen  * @rvdev: the remote vdev
29504a9016eSOhad Ben-Cohen  *
2967a186941SOhad Ben-Cohen  * This function registers a virtio device. This vdev's partent is
2977a186941SOhad Ben-Cohen  * the rproc device.
29804a9016eSOhad Ben-Cohen  *
2997a186941SOhad Ben-Cohen  * Returns 0 on success or an appropriate error value otherwise.
30004a9016eSOhad Ben-Cohen  */
3017a186941SOhad Ben-Cohen int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id)
30204a9016eSOhad Ben-Cohen {
3037a186941SOhad Ben-Cohen 	struct rproc *rproc = rvdev->rproc;
304b5ab5e24SOhad Ben-Cohen 	struct device *dev = &rproc->dev;
3057a186941SOhad Ben-Cohen 	struct virtio_device *vdev = &rvdev->vdev;
30604a9016eSOhad Ben-Cohen 	int ret;
30704a9016eSOhad Ben-Cohen 
3087a186941SOhad Ben-Cohen 	vdev->id.device	= id,
3097a186941SOhad Ben-Cohen 	vdev->config = &rproc_virtio_config_ops,
3107a186941SOhad Ben-Cohen 	vdev->dev.parent = dev;
311aab8d802SBjorn Andersson 	vdev->dev.release = rproc_virtio_dev_release;
31204a9016eSOhad Ben-Cohen 
31304a9016eSOhad Ben-Cohen 	/*
31404a9016eSOhad Ben-Cohen 	 * We're indirectly making a non-temporary copy of the rproc pointer
31504a9016eSOhad Ben-Cohen 	 * here, because drivers probed with this vdev will indirectly
31604a9016eSOhad Ben-Cohen 	 * access the wrapping rproc.
31704a9016eSOhad Ben-Cohen 	 *
31804a9016eSOhad Ben-Cohen 	 * Therefore we must increment the rproc refcount here, and decrement
31904a9016eSOhad Ben-Cohen 	 * it _only_ when the vdev is released.
32004a9016eSOhad Ben-Cohen 	 */
3217183a2a7SOhad Ben-Cohen 	get_device(&rproc->dev);
32204a9016eSOhad Ben-Cohen 
323aab8d802SBjorn Andersson 	/* Reference the vdev and vring allocations */
324aab8d802SBjorn Andersson 	kref_get(&rvdev->refcount);
325aab8d802SBjorn Andersson 
3267a186941SOhad Ben-Cohen 	ret = register_virtio_device(vdev);
32704a9016eSOhad Ben-Cohen 	if (ret) {
3287183a2a7SOhad Ben-Cohen 		put_device(&rproc->dev);
32904a9016eSOhad Ben-Cohen 		dev_err(dev, "failed to register vdev: %d\n", ret);
3307a186941SOhad Ben-Cohen 		goto out;
33104a9016eSOhad Ben-Cohen 	}
33204a9016eSOhad Ben-Cohen 
3337a186941SOhad Ben-Cohen 	dev_info(dev, "registered %s (type %d)\n", dev_name(&vdev->dev), id);
3347a186941SOhad Ben-Cohen 
3357a186941SOhad Ben-Cohen out:
33604a9016eSOhad Ben-Cohen 	return ret;
33704a9016eSOhad Ben-Cohen }
33804a9016eSOhad Ben-Cohen 
33904a9016eSOhad Ben-Cohen /**
3407a186941SOhad Ben-Cohen  * rproc_remove_virtio_dev() - remove an rproc-induced virtio device
3417a186941SOhad Ben-Cohen  * @rvdev: the remote vdev
34204a9016eSOhad Ben-Cohen  *
3437a186941SOhad Ben-Cohen  * This function unregisters an existing virtio device.
34404a9016eSOhad Ben-Cohen  */
3457a186941SOhad Ben-Cohen void rproc_remove_virtio_dev(struct rproc_vdev *rvdev)
34604a9016eSOhad Ben-Cohen {
34704a9016eSOhad Ben-Cohen 	unregister_virtio_device(&rvdev->vdev);
34804a9016eSOhad Ben-Cohen }
349