diff options
Diffstat (limited to 'arch/x86/kvm/lapic.c')
-rw-r--r-- | arch/x86/kvm/lapic.c | 22 |
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) | |||
522 | return val; | 522 | return val; |
523 | } | 523 | } |
524 | 524 | ||
525 | static inline struct kvm_lapic *to_lapic(struct kvm_io_device *dev) | ||
526 | { | ||
527 | return container_of(dev, struct kvm_lapic, dev); | ||
528 | } | ||
529 | |||
525 | static void apic_mmio_read(struct kvm_io_device *this, | 530 | static void apic_mmio_read(struct kvm_io_device *this, |
526 | gpa_t address, int len, void *data) | 531 | gpa_t address, int len, void *data) |
527 | { | 532 | { |
528 | struct kvm_lapic *apic = (struct kvm_lapic *)this->private; | 533 | struct kvm_lapic *apic = to_lapic(this); |
529 | unsigned int offset = address - apic->base_address; | 534 | unsigned int offset = address - apic->base_address; |
530 | unsigned char alignment = offset & 0xf; | 535 | unsigned char alignment = offset & 0xf; |
531 | u32 result; | 536 | u32 result; |
@@ -606,7 +611,7 @@ static void apic_manage_nmi_watchdog(struct kvm_lapic *apic, u32 lvt0_val) | |||
606 | static void apic_mmio_write(struct kvm_io_device *this, | 611 | static void apic_mmio_write(struct kvm_io_device *this, |
607 | gpa_t address, int len, const void *data) | 612 | gpa_t address, int len, const void *data) |
608 | { | 613 | { |
609 | struct kvm_lapic *apic = (struct kvm_lapic *)this->private; | 614 | struct kvm_lapic *apic = to_lapic(this); |
610 | unsigned int offset = address - apic->base_address; | 615 | unsigned int offset = address - apic->base_address; |
611 | unsigned char alignment = offset & 0xf; | 616 | unsigned char alignment = offset & 0xf; |
612 | u32 val; | 617 | u32 val; |
@@ -723,7 +728,7 @@ static void apic_mmio_write(struct kvm_io_device *this, | |||
723 | static int apic_mmio_range(struct kvm_io_device *this, gpa_t addr, | 728 | static int apic_mmio_range(struct kvm_io_device *this, gpa_t addr, |
724 | int len, int size) | 729 | int len, int size) |
725 | { | 730 | { |
726 | struct kvm_lapic *apic = (struct kvm_lapic *)this->private; | 731 | struct kvm_lapic *apic = to_lapic(this); |
727 | int ret = 0; | 732 | int ret = 0; |
728 | 733 | ||
729 | 734 | ||
@@ -917,6 +922,12 @@ static struct kvm_timer_ops lapic_timer_ops = { | |||
917 | .is_periodic = lapic_is_periodic, | 922 | .is_periodic = lapic_is_periodic, |
918 | }; | 923 | }; |
919 | 924 | ||
925 | static const struct kvm_io_device_ops apic_mmio_ops = { | ||
926 | .read = apic_mmio_read, | ||
927 | .write = apic_mmio_write, | ||
928 | .in_range = apic_mmio_range, | ||
929 | }; | ||
930 | |||
920 | int kvm_create_lapic(struct kvm_vcpu *vcpu) | 931 | int kvm_create_lapic(struct kvm_vcpu *vcpu) |
921 | { | 932 | { |
922 | struct kvm_lapic *apic; | 933 | struct kvm_lapic *apic; |
@@ -951,10 +962,7 @@ int kvm_create_lapic(struct kvm_vcpu *vcpu) | |||
951 | vcpu->arch.apic_base = APIC_DEFAULT_PHYS_BASE; | 962 | vcpu->arch.apic_base = APIC_DEFAULT_PHYS_BASE; |
952 | 963 | ||
953 | kvm_lapic_reset(vcpu); | 964 | kvm_lapic_reset(vcpu); |
954 | apic->dev.read = apic_mmio_read; | 965 | kvm_iodevice_init(&apic->dev, &apic_mmio_ops); |
955 | apic->dev.write = apic_mmio_write; | ||
956 | apic->dev.in_range = apic_mmio_range; | ||
957 | apic->dev.private = apic; | ||
958 | 966 | ||
959 | return 0; | 967 | return 0; |
960 | nomem_free_apic: | 968 | nomem_free_apic: |