mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-12-27 10:01:39 -05:00
virtio-mmio: Remove virtqueue list from mmio device
The MMIO transport implementation creates a list of virtqueues for a virtio device, while the same is already available in the struct virtio_device. Don't create a duplicate list, and use the other one instead. While at it, fix the virtio_device_for_each_vq() macro to accept an argument like "&vm_dev->vdev" (which currently fails to build). Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Message-Id: <3e56c6f74002987e22f364d883cbad177cd9ad9c.1747827066.git.viresh.kumar@linaro.org> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Acked-by: Jason Wang <jasowang@redhat.com>
This commit is contained in:
committed by
Michael S. Tsirkin
parent
482bd84f1f
commit
564a69ad90
@@ -65,7 +65,6 @@
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/pm.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/virtio.h>
|
||||
#include <linux/virtio_config.h>
|
||||
#include <uapi/linux/virtio_mmio.h>
|
||||
@@ -88,22 +87,8 @@ struct virtio_mmio_device {
|
||||
|
||||
void __iomem *base;
|
||||
unsigned long version;
|
||||
|
||||
/* a list of queues so we can dispatch IRQs */
|
||||
spinlock_t lock;
|
||||
struct list_head virtqueues;
|
||||
};
|
||||
|
||||
struct virtio_mmio_vq_info {
|
||||
/* the actual virtqueue */
|
||||
struct virtqueue *vq;
|
||||
|
||||
/* the list node for the virtqueues list */
|
||||
struct list_head node;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* Configuration interface */
|
||||
|
||||
static u64 vm_get_features(struct virtio_device *vdev)
|
||||
@@ -300,9 +285,8 @@ static bool vm_notify_with_data(struct virtqueue *vq)
|
||||
static irqreturn_t vm_interrupt(int irq, void *opaque)
|
||||
{
|
||||
struct virtio_mmio_device *vm_dev = opaque;
|
||||
struct virtio_mmio_vq_info *info;
|
||||
struct virtqueue *vq;
|
||||
unsigned long status;
|
||||
unsigned long flags;
|
||||
irqreturn_t ret = IRQ_NONE;
|
||||
|
||||
/* Read and acknowledge interrupts */
|
||||
@@ -315,10 +299,8 @@ static irqreturn_t vm_interrupt(int irq, void *opaque)
|
||||
}
|
||||
|
||||
if (likely(status & VIRTIO_MMIO_INT_VRING)) {
|
||||
spin_lock_irqsave(&vm_dev->lock, flags);
|
||||
list_for_each_entry(info, &vm_dev->virtqueues, node)
|
||||
ret |= vring_interrupt(irq, info->vq);
|
||||
spin_unlock_irqrestore(&vm_dev->lock, flags);
|
||||
virtio_device_for_each_vq(&vm_dev->vdev, vq)
|
||||
ret |= vring_interrupt(irq, vq);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -329,14 +311,8 @@ static irqreturn_t vm_interrupt(int irq, void *opaque)
|
||||
static void vm_del_vq(struct virtqueue *vq)
|
||||
{
|
||||
struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vq->vdev);
|
||||
struct virtio_mmio_vq_info *info = vq->priv;
|
||||
unsigned long flags;
|
||||
unsigned int index = vq->index;
|
||||
|
||||
spin_lock_irqsave(&vm_dev->lock, flags);
|
||||
list_del(&info->node);
|
||||
spin_unlock_irqrestore(&vm_dev->lock, flags);
|
||||
|
||||
/* Select and deactivate the queue */
|
||||
writel(index, vm_dev->base + VIRTIO_MMIO_QUEUE_SEL);
|
||||
if (vm_dev->version == 1) {
|
||||
@@ -347,8 +323,6 @@ static void vm_del_vq(struct virtqueue *vq)
|
||||
}
|
||||
|
||||
vring_del_virtqueue(vq);
|
||||
|
||||
kfree(info);
|
||||
}
|
||||
|
||||
static void vm_del_vqs(struct virtio_device *vdev)
|
||||
@@ -375,9 +349,7 @@ static struct virtqueue *vm_setup_vq(struct virtio_device *vdev, unsigned int in
|
||||
{
|
||||
struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
|
||||
bool (*notify)(struct virtqueue *vq);
|
||||
struct virtio_mmio_vq_info *info;
|
||||
struct virtqueue *vq;
|
||||
unsigned long flags;
|
||||
unsigned int num;
|
||||
int err;
|
||||
|
||||
@@ -399,13 +371,6 @@ static struct virtqueue *vm_setup_vq(struct virtio_device *vdev, unsigned int in
|
||||
goto error_available;
|
||||
}
|
||||
|
||||
/* Allocate and fill out our active queue description */
|
||||
info = kmalloc(sizeof(*info), GFP_KERNEL);
|
||||
if (!info) {
|
||||
err = -ENOMEM;
|
||||
goto error_kmalloc;
|
||||
}
|
||||
|
||||
num = readl(vm_dev->base + VIRTIO_MMIO_QUEUE_NUM_MAX);
|
||||
if (num == 0) {
|
||||
err = -ENOENT;
|
||||
@@ -463,13 +428,6 @@ static struct virtqueue *vm_setup_vq(struct virtio_device *vdev, unsigned int in
|
||||
writel(1, vm_dev->base + VIRTIO_MMIO_QUEUE_READY);
|
||||
}
|
||||
|
||||
vq->priv = info;
|
||||
info->vq = vq;
|
||||
|
||||
spin_lock_irqsave(&vm_dev->lock, flags);
|
||||
list_add(&info->node, &vm_dev->virtqueues);
|
||||
spin_unlock_irqrestore(&vm_dev->lock, flags);
|
||||
|
||||
return vq;
|
||||
|
||||
error_bad_pfn:
|
||||
@@ -481,8 +439,6 @@ static struct virtqueue *vm_setup_vq(struct virtio_device *vdev, unsigned int in
|
||||
writel(0, vm_dev->base + VIRTIO_MMIO_QUEUE_READY);
|
||||
WARN_ON(readl(vm_dev->base + VIRTIO_MMIO_QUEUE_READY));
|
||||
}
|
||||
kfree(info);
|
||||
error_kmalloc:
|
||||
error_available:
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
@@ -627,8 +583,6 @@ static int virtio_mmio_probe(struct platform_device *pdev)
|
||||
vm_dev->vdev.dev.release = virtio_mmio_release_dev;
|
||||
vm_dev->vdev.config = &virtio_mmio_config_ops;
|
||||
vm_dev->pdev = pdev;
|
||||
INIT_LIST_HEAD(&vm_dev->virtqueues);
|
||||
spin_lock_init(&vm_dev->lock);
|
||||
|
||||
vm_dev->base = devm_platform_ioremap_resource(pdev, 0);
|
||||
if (IS_ERR(vm_dev->base)) {
|
||||
|
||||
@@ -196,7 +196,7 @@ int virtio_device_reset_done(struct virtio_device *dev);
|
||||
size_t virtio_max_dma_size(const struct virtio_device *vdev);
|
||||
|
||||
#define virtio_device_for_each_vq(vdev, vq) \
|
||||
list_for_each_entry(vq, &vdev->vqs, list)
|
||||
list_for_each_entry(vq, &(vdev)->vqs, list)
|
||||
|
||||
/**
|
||||
* struct virtio_driver - operations for a virtio I/O driver
|
||||
|
||||
Reference in New Issue
Block a user