aboutsummaryrefslogtreecommitdiffstats
path: root/virt/kvm/coalesced_mmio.c
diff options
context:
space:
mode:
Diffstat (limited to 'virt/kvm/coalesced_mmio.c')
-rw-r--r--virt/kvm/coalesced_mmio.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/virt/kvm/coalesced_mmio.c b/virt/kvm/coalesced_mmio.c
index 03ea2807b1f2..c4c7ec2f9d30 100644
--- a/virt/kvm/coalesced_mmio.c
+++ b/virt/kvm/coalesced_mmio.c
@@ -14,11 +14,15 @@
14 14
15#include "coalesced_mmio.h" 15#include "coalesced_mmio.h"
16 16
17static inline struct kvm_coalesced_mmio_dev *to_mmio(struct kvm_io_device *dev)
18{
19 return container_of(dev, struct kvm_coalesced_mmio_dev, dev);
20}
21
17static int coalesced_mmio_in_range(struct kvm_io_device *this, 22static int coalesced_mmio_in_range(struct kvm_io_device *this,
18 gpa_t addr, int len, int is_write) 23 gpa_t addr, int len, int is_write)
19{ 24{
20 struct kvm_coalesced_mmio_dev *dev = 25 struct kvm_coalesced_mmio_dev *dev = to_mmio(this);
21 (struct kvm_coalesced_mmio_dev*)this->private;
22 struct kvm_coalesced_mmio_zone *zone; 26 struct kvm_coalesced_mmio_zone *zone;
23 int next; 27 int next;
24 int i; 28 int i;
@@ -63,8 +67,7 @@ static int coalesced_mmio_in_range(struct kvm_io_device *this,
63static void coalesced_mmio_write(struct kvm_io_device *this, 67static void coalesced_mmio_write(struct kvm_io_device *this,
64 gpa_t addr, int len, const void *val) 68 gpa_t addr, int len, const void *val)
65{ 69{
66 struct kvm_coalesced_mmio_dev *dev = 70 struct kvm_coalesced_mmio_dev *dev = to_mmio(this);
67 (struct kvm_coalesced_mmio_dev*)this->private;
68 struct kvm_coalesced_mmio_ring *ring = dev->kvm->coalesced_mmio_ring; 71 struct kvm_coalesced_mmio_ring *ring = dev->kvm->coalesced_mmio_ring;
69 72
70 /* kvm->lock must be taken by caller before call to in_range()*/ 73 /* kvm->lock must be taken by caller before call to in_range()*/
@@ -80,12 +83,17 @@ static void coalesced_mmio_write(struct kvm_io_device *this,
80 83
81static void coalesced_mmio_destructor(struct kvm_io_device *this) 84static void coalesced_mmio_destructor(struct kvm_io_device *this)
82{ 85{
83 struct kvm_coalesced_mmio_dev *dev = 86 struct kvm_coalesced_mmio_dev *dev = to_mmio(this);
84 (struct kvm_coalesced_mmio_dev *)this->private;
85 87
86 kfree(dev); 88 kfree(dev);
87} 89}
88 90
91static const struct kvm_io_device_ops coalesced_mmio_ops = {
92 .write = coalesced_mmio_write,
93 .in_range = coalesced_mmio_in_range,
94 .destructor = coalesced_mmio_destructor,
95};
96
89int kvm_coalesced_mmio_init(struct kvm *kvm) 97int kvm_coalesced_mmio_init(struct kvm *kvm)
90{ 98{
91 struct kvm_coalesced_mmio_dev *dev; 99 struct kvm_coalesced_mmio_dev *dev;
@@ -93,10 +101,7 @@ int kvm_coalesced_mmio_init(struct kvm *kvm)
93 dev = kzalloc(sizeof(struct kvm_coalesced_mmio_dev), GFP_KERNEL); 101 dev = kzalloc(sizeof(struct kvm_coalesced_mmio_dev), GFP_KERNEL);
94 if (!dev) 102 if (!dev)
95 return -ENOMEM; 103 return -ENOMEM;
96 dev->dev.write = coalesced_mmio_write; 104 kvm_iodevice_init(&dev->dev, &coalesced_mmio_ops);
97 dev->dev.in_range = coalesced_mmio_in_range;
98 dev->dev.destructor = coalesced_mmio_destructor;
99 dev->dev.private = dev;
100 dev->kvm = kvm; 105 dev->kvm = kvm;
101 kvm->coalesced_mmio_dev = dev; 106 kvm->coalesced_mmio_dev = dev;
102 kvm_io_bus_register_dev(&kvm->mmio_bus, &dev->dev); 107 kvm_io_bus_register_dev(&kvm->mmio_bus, &dev->dev);