summaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/lapic.c
diff options
context:
space:
mode:
authorGregory Haskins <ghaskins@novell.com>2009-06-01 12:54:50 -0400
committerAvi Kivity <avi@redhat.com>2009-09-10 08:32:45 +0300
commitd76685c4a074041ed168e0b04dd604c3df5dcaa5 (patch)
tree828fb3a57b7829530904318a0ad9d006e21408ad /arch/x86/kvm/lapic.c
parent787a660a4f03325a0e00493ac39017e53fd345fa (diff)
downloadblackbird-op-linux-d76685c4a074041ed168e0b04dd604c3df5dcaa5.tar.gz
blackbird-op-linux-d76685c4a074041ed168e0b04dd604c3df5dcaa5.zip
KVM: cleanup io_device code
We modernize the io_device code so that we use container_of() instead of dev->private, and move the vtable to a separate ops structure (theoretically allows better caching for multiple instances of the same ops structure) Signed-off-by: Gregory Haskins <ghaskins@novell.com> Acked-by: Chris Wright <chrisw@sous-sol.org> Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86/kvm/lapic.c')
-rw-r--r--arch/x86/kvm/lapic.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index ae99d83f81a3..4bfd458a4f3e 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -522,10 +522,15 @@ static u32 __apic_read(struct kvm_lapic *apic, unsigned int offset)
return val;
}
+static inline struct kvm_lapic *to_lapic(struct kvm_io_device *dev)
+{
+ return container_of(dev, struct kvm_lapic, dev);
+}
+
static void apic_mmio_read(struct kvm_io_device *this,
gpa_t address, int len, void *data)
{
- struct kvm_lapic *apic = (struct kvm_lapic *)this->private;
+ struct kvm_lapic *apic = to_lapic(this);
unsigned int offset = address - apic->base_address;
unsigned char alignment = offset & 0xf;
u32 result;
@@ -606,7 +611,7 @@ static void apic_manage_nmi_watchdog(struct kvm_lapic *apic, u32 lvt0_val)
static void apic_mmio_write(struct kvm_io_device *this,
gpa_t address, int len, const void *data)
{
- struct kvm_lapic *apic = (struct kvm_lapic *)this->private;
+ struct kvm_lapic *apic = to_lapic(this);
unsigned int offset = address - apic->base_address;
unsigned char alignment = offset & 0xf;
u32 val;
@@ -723,7 +728,7 @@ static void apic_mmio_write(struct kvm_io_device *this,
static int apic_mmio_range(struct kvm_io_device *this, gpa_t addr,
int len, int size)
{
- struct kvm_lapic *apic = (struct kvm_lapic *)this->private;
+ struct kvm_lapic *apic = to_lapic(this);
int ret = 0;
@@ -917,6 +922,12 @@ static struct kvm_timer_ops lapic_timer_ops = {
.is_periodic = lapic_is_periodic,
};
+static const struct kvm_io_device_ops apic_mmio_ops = {
+ .read = apic_mmio_read,
+ .write = apic_mmio_write,
+ .in_range = apic_mmio_range,
+};
+
int kvm_create_lapic(struct kvm_vcpu *vcpu)
{
struct kvm_lapic *apic;
@@ -951,10 +962,7 @@ int kvm_create_lapic(struct kvm_vcpu *vcpu)
vcpu->arch.apic_base = APIC_DEFAULT_PHYS_BASE;
kvm_lapic_reset(vcpu);
- apic->dev.read = apic_mmio_read;
- apic->dev.write = apic_mmio_write;
- apic->dev.in_range = apic_mmio_range;
- apic->dev.private = apic;
+ kvm_iodevice_init(&apic->dev, &apic_mmio_ops);
return 0;
nomem_free_apic:
OpenPOWER on IntegriCloud