diff options
-rw-r--r-- | arch/x86/kvm/i8254.c | 40 | ||||
-rw-r--r-- | arch/x86/kvm/i8259.c | 20 | ||||
-rw-r--r-- | arch/x86/kvm/lapic.c | 22 | ||||
-rw-r--r-- | arch/x86/kvm/x86.c | 2 | ||||
-rw-r--r-- | virt/kvm/coalesced_mmio.c | 25 | ||||
-rw-r--r-- | virt/kvm/ioapic.c | 22 | ||||
-rw-r--r-- | virt/kvm/iodev.h | 29 | ||||
-rw-r--r-- | virt/kvm/kvm_main.c | 2 |
8 files changed, 109 insertions, 53 deletions
diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c index 0990bc9aac1f..e800d2d66266 100644 --- a/arch/x86/kvm/i8254.c +++ b/arch/x86/kvm/i8254.c | |||
@@ -350,10 +350,20 @@ void kvm_pit_load_count(struct kvm *kvm, int channel, u32 val) | |||
350 | mutex_unlock(&kvm->arch.vpit->pit_state.lock); | 350 | mutex_unlock(&kvm->arch.vpit->pit_state.lock); |
351 | } | 351 | } |
352 | 352 | ||
353 | static inline struct kvm_pit *dev_to_pit(struct kvm_io_device *dev) | ||
354 | { | ||
355 | return container_of(dev, struct kvm_pit, dev); | ||
356 | } | ||
357 | |||
358 | static inline struct kvm_pit *speaker_to_pit(struct kvm_io_device *dev) | ||
359 | { | ||
360 | return container_of(dev, struct kvm_pit, speaker_dev); | ||
361 | } | ||
362 | |||
353 | static void pit_ioport_write(struct kvm_io_device *this, | 363 | static void pit_ioport_write(struct kvm_io_device *this, |
354 | gpa_t addr, int len, const void *data) | 364 | gpa_t addr, int len, const void *data) |
355 | { | 365 | { |
356 | struct kvm_pit *pit = (struct kvm_pit *)this->private; | 366 | struct kvm_pit *pit = dev_to_pit(this); |
357 | struct kvm_kpit_state *pit_state = &pit->pit_state; | 367 | struct kvm_kpit_state *pit_state = &pit->pit_state; |
358 | struct kvm *kvm = pit->kvm; | 368 | struct kvm *kvm = pit->kvm; |
359 | int channel, access; | 369 | int channel, access; |
@@ -426,7 +436,7 @@ static void pit_ioport_write(struct kvm_io_device *this, | |||
426 | static void pit_ioport_read(struct kvm_io_device *this, | 436 | static void pit_ioport_read(struct kvm_io_device *this, |
427 | gpa_t addr, int len, void *data) | 437 | gpa_t addr, int len, void *data) |
428 | { | 438 | { |
429 | struct kvm_pit *pit = (struct kvm_pit *)this->private; | 439 | struct kvm_pit *pit = dev_to_pit(this); |
430 | struct kvm_kpit_state *pit_state = &pit->pit_state; | 440 | struct kvm_kpit_state *pit_state = &pit->pit_state; |
431 | struct kvm *kvm = pit->kvm; | 441 | struct kvm *kvm = pit->kvm; |
432 | int ret, count; | 442 | int ret, count; |
@@ -497,7 +507,7 @@ static int pit_in_range(struct kvm_io_device *this, gpa_t addr, | |||
497 | static void speaker_ioport_write(struct kvm_io_device *this, | 507 | static void speaker_ioport_write(struct kvm_io_device *this, |
498 | gpa_t addr, int len, const void *data) | 508 | gpa_t addr, int len, const void *data) |
499 | { | 509 | { |
500 | struct kvm_pit *pit = (struct kvm_pit *)this->private; | 510 | struct kvm_pit *pit = speaker_to_pit(this); |
501 | struct kvm_kpit_state *pit_state = &pit->pit_state; | 511 | struct kvm_kpit_state *pit_state = &pit->pit_state; |
502 | struct kvm *kvm = pit->kvm; | 512 | struct kvm *kvm = pit->kvm; |
503 | u32 val = *(u32 *) data; | 513 | u32 val = *(u32 *) data; |
@@ -511,7 +521,7 @@ static void speaker_ioport_write(struct kvm_io_device *this, | |||
511 | static void speaker_ioport_read(struct kvm_io_device *this, | 521 | static void speaker_ioport_read(struct kvm_io_device *this, |
512 | gpa_t addr, int len, void *data) | 522 | gpa_t addr, int len, void *data) |
513 | { | 523 | { |
514 | struct kvm_pit *pit = (struct kvm_pit *)this->private; | 524 | struct kvm_pit *pit = speaker_to_pit(this); |
515 | struct kvm_kpit_state *pit_state = &pit->pit_state; | 525 | struct kvm_kpit_state *pit_state = &pit->pit_state; |
516 | struct kvm *kvm = pit->kvm; | 526 | struct kvm *kvm = pit->kvm; |
517 | unsigned int refresh_clock; | 527 | unsigned int refresh_clock; |
@@ -563,6 +573,18 @@ static void pit_mask_notifer(struct kvm_irq_mask_notifier *kimn, bool mask) | |||
563 | } | 573 | } |
564 | } | 574 | } |
565 | 575 | ||
576 | static const struct kvm_io_device_ops pit_dev_ops = { | ||
577 | .read = pit_ioport_read, | ||
578 | .write = pit_ioport_write, | ||
579 | .in_range = pit_in_range, | ||
580 | }; | ||
581 | |||
582 | static const struct kvm_io_device_ops speaker_dev_ops = { | ||
583 | .read = speaker_ioport_read, | ||
584 | .write = speaker_ioport_write, | ||
585 | .in_range = speaker_in_range, | ||
586 | }; | ||
587 | |||
566 | struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags) | 588 | struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags) |
567 | { | 589 | { |
568 | struct kvm_pit *pit; | 590 | struct kvm_pit *pit; |
@@ -583,17 +605,11 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags) | |||
583 | spin_lock_init(&pit->pit_state.inject_lock); | 605 | spin_lock_init(&pit->pit_state.inject_lock); |
584 | 606 | ||
585 | /* Initialize PIO device */ | 607 | /* Initialize PIO device */ |
586 | pit->dev.read = pit_ioport_read; | 608 | kvm_iodevice_init(&pit->dev, &pit_dev_ops); |
587 | pit->dev.write = pit_ioport_write; | ||
588 | pit->dev.in_range = pit_in_range; | ||
589 | pit->dev.private = pit; | ||
590 | kvm_io_bus_register_dev(&kvm->pio_bus, &pit->dev); | 609 | kvm_io_bus_register_dev(&kvm->pio_bus, &pit->dev); |
591 | 610 | ||
592 | if (flags & KVM_PIT_SPEAKER_DUMMY) { | 611 | if (flags & KVM_PIT_SPEAKER_DUMMY) { |
593 | pit->speaker_dev.read = speaker_ioport_read; | 612 | kvm_iodevice_init(&pit->speaker_dev, &speaker_dev_ops); |
594 | pit->speaker_dev.write = speaker_ioport_write; | ||
595 | pit->speaker_dev.in_range = speaker_in_range; | ||
596 | pit->speaker_dev.private = pit; | ||
597 | kvm_io_bus_register_dev(&kvm->pio_bus, &pit->speaker_dev); | 613 | kvm_io_bus_register_dev(&kvm->pio_bus, &pit->speaker_dev); |
598 | } | 614 | } |
599 | 615 | ||
diff --git a/arch/x86/kvm/i8259.c b/arch/x86/kvm/i8259.c index 1ccb50c74f18..2520922282d5 100644 --- a/arch/x86/kvm/i8259.c +++ b/arch/x86/kvm/i8259.c | |||
@@ -444,10 +444,15 @@ static int picdev_in_range(struct kvm_io_device *this, gpa_t addr, | |||
444 | } | 444 | } |
445 | } | 445 | } |
446 | 446 | ||
447 | static inline struct kvm_pic *to_pic(struct kvm_io_device *dev) | ||
448 | { | ||
449 | return container_of(dev, struct kvm_pic, dev); | ||
450 | } | ||
451 | |||
447 | static void picdev_write(struct kvm_io_device *this, | 452 | static void picdev_write(struct kvm_io_device *this, |
448 | gpa_t addr, int len, const void *val) | 453 | gpa_t addr, int len, const void *val) |
449 | { | 454 | { |
450 | struct kvm_pic *s = this->private; | 455 | struct kvm_pic *s = to_pic(this); |
451 | unsigned char data = *(unsigned char *)val; | 456 | unsigned char data = *(unsigned char *)val; |
452 | 457 | ||
453 | if (len != 1) { | 458 | if (len != 1) { |
@@ -474,7 +479,7 @@ static void picdev_write(struct kvm_io_device *this, | |||
474 | static void picdev_read(struct kvm_io_device *this, | 479 | static void picdev_read(struct kvm_io_device *this, |
475 | gpa_t addr, int len, void *val) | 480 | gpa_t addr, int len, void *val) |
476 | { | 481 | { |
477 | struct kvm_pic *s = this->private; | 482 | struct kvm_pic *s = to_pic(this); |
478 | unsigned char data = 0; | 483 | unsigned char data = 0; |
479 | 484 | ||
480 | if (len != 1) { | 485 | if (len != 1) { |
@@ -516,6 +521,12 @@ static void pic_irq_request(void *opaque, int level) | |||
516 | } | 521 | } |
517 | } | 522 | } |
518 | 523 | ||
524 | static const struct kvm_io_device_ops picdev_ops = { | ||
525 | .read = picdev_read, | ||
526 | .write = picdev_write, | ||
527 | .in_range = picdev_in_range, | ||
528 | }; | ||
529 | |||
519 | struct kvm_pic *kvm_create_pic(struct kvm *kvm) | 530 | struct kvm_pic *kvm_create_pic(struct kvm *kvm) |
520 | { | 531 | { |
521 | struct kvm_pic *s; | 532 | struct kvm_pic *s; |
@@ -534,10 +545,7 @@ struct kvm_pic *kvm_create_pic(struct kvm *kvm) | |||
534 | /* | 545 | /* |
535 | * Initialize PIO device | 546 | * Initialize PIO device |
536 | */ | 547 | */ |
537 | s->dev.read = picdev_read; | 548 | kvm_iodevice_init(&s->dev, &picdev_ops); |
538 | s->dev.write = picdev_write; | ||
539 | s->dev.in_range = picdev_in_range; | ||
540 | s->dev.private = s; | ||
541 | kvm_io_bus_register_dev(&kvm->pio_bus, &s->dev); | 549 | kvm_io_bus_register_dev(&kvm->pio_bus, &s->dev); |
542 | return s; | 550 | return s; |
543 | } | 551 | } |
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: |
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 5eb3b8dd74b8..75e9df097845 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
@@ -2264,7 +2264,7 @@ static struct kvm_io_device *vcpu_find_pervcpu_dev(struct kvm_vcpu *vcpu, | |||
2264 | 2264 | ||
2265 | if (vcpu->arch.apic) { | 2265 | if (vcpu->arch.apic) { |
2266 | dev = &vcpu->arch.apic->dev; | 2266 | dev = &vcpu->arch.apic->dev; |
2267 | if (dev->in_range(dev, addr, len, is_write)) | 2267 | if (kvm_iodevice_in_range(dev, addr, len, is_write)) |
2268 | return dev; | 2268 | return dev; |
2269 | } | 2269 | } |
2270 | return NULL; | 2270 | return NULL; |
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 | ||
17 | static 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 | |||
17 | static int coalesced_mmio_in_range(struct kvm_io_device *this, | 22 | static 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, | |||
63 | static void coalesced_mmio_write(struct kvm_io_device *this, | 67 | static 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 | ||
81 | static void coalesced_mmio_destructor(struct kvm_io_device *this) | 84 | static 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 | ||
91 | static 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 | |||
89 | int kvm_coalesced_mmio_init(struct kvm *kvm) | 97 | int 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); |
diff --git a/virt/kvm/ioapic.c b/virt/kvm/ioapic.c index 1150c6d5c7b8..469b9faae665 100644 --- a/virt/kvm/ioapic.c +++ b/virt/kvm/ioapic.c | |||
@@ -220,10 +220,15 @@ void kvm_ioapic_update_eoi(struct kvm *kvm, int vector, int trigger_mode) | |||
220 | __kvm_ioapic_update_eoi(ioapic, i, trigger_mode); | 220 | __kvm_ioapic_update_eoi(ioapic, i, trigger_mode); |
221 | } | 221 | } |
222 | 222 | ||
223 | static inline struct kvm_ioapic *to_ioapic(struct kvm_io_device *dev) | ||
224 | { | ||
225 | return container_of(dev, struct kvm_ioapic, dev); | ||
226 | } | ||
227 | |||
223 | static int ioapic_in_range(struct kvm_io_device *this, gpa_t addr, | 228 | static int ioapic_in_range(struct kvm_io_device *this, gpa_t addr, |
224 | int len, int is_write) | 229 | int len, int is_write) |
225 | { | 230 | { |
226 | struct kvm_ioapic *ioapic = (struct kvm_ioapic *)this->private; | 231 | struct kvm_ioapic *ioapic = to_ioapic(this); |
227 | 232 | ||
228 | return ((addr >= ioapic->base_address && | 233 | return ((addr >= ioapic->base_address && |
229 | (addr < ioapic->base_address + IOAPIC_MEM_LENGTH))); | 234 | (addr < ioapic->base_address + IOAPIC_MEM_LENGTH))); |
@@ -232,7 +237,7 @@ static int ioapic_in_range(struct kvm_io_device *this, gpa_t addr, | |||
232 | static void ioapic_mmio_read(struct kvm_io_device *this, gpa_t addr, int len, | 237 | static void ioapic_mmio_read(struct kvm_io_device *this, gpa_t addr, int len, |
233 | void *val) | 238 | void *val) |
234 | { | 239 | { |
235 | struct kvm_ioapic *ioapic = (struct kvm_ioapic *)this->private; | 240 | struct kvm_ioapic *ioapic = to_ioapic(this); |
236 | u32 result; | 241 | u32 result; |
237 | 242 | ||
238 | ioapic_debug("addr %lx\n", (unsigned long)addr); | 243 | ioapic_debug("addr %lx\n", (unsigned long)addr); |
@@ -269,7 +274,7 @@ static void ioapic_mmio_read(struct kvm_io_device *this, gpa_t addr, int len, | |||
269 | static void ioapic_mmio_write(struct kvm_io_device *this, gpa_t addr, int len, | 274 | static void ioapic_mmio_write(struct kvm_io_device *this, gpa_t addr, int len, |
270 | const void *val) | 275 | const void *val) |
271 | { | 276 | { |
272 | struct kvm_ioapic *ioapic = (struct kvm_ioapic *)this->private; | 277 | struct kvm_ioapic *ioapic = to_ioapic(this); |
273 | u32 data; | 278 | u32 data; |
274 | 279 | ||
275 | ioapic_debug("ioapic_mmio_write addr=%p len=%d val=%p\n", | 280 | ioapic_debug("ioapic_mmio_write addr=%p len=%d val=%p\n", |
@@ -314,6 +319,12 @@ void kvm_ioapic_reset(struct kvm_ioapic *ioapic) | |||
314 | ioapic->id = 0; | 319 | ioapic->id = 0; |
315 | } | 320 | } |
316 | 321 | ||
322 | static const struct kvm_io_device_ops ioapic_mmio_ops = { | ||
323 | .read = ioapic_mmio_read, | ||
324 | .write = ioapic_mmio_write, | ||
325 | .in_range = ioapic_in_range, | ||
326 | }; | ||
327 | |||
317 | int kvm_ioapic_init(struct kvm *kvm) | 328 | int kvm_ioapic_init(struct kvm *kvm) |
318 | { | 329 | { |
319 | struct kvm_ioapic *ioapic; | 330 | struct kvm_ioapic *ioapic; |
@@ -323,10 +334,7 @@ int kvm_ioapic_init(struct kvm *kvm) | |||
323 | return -ENOMEM; | 334 | return -ENOMEM; |
324 | kvm->arch.vioapic = ioapic; | 335 | kvm->arch.vioapic = ioapic; |
325 | kvm_ioapic_reset(ioapic); | 336 | kvm_ioapic_reset(ioapic); |
326 | ioapic->dev.read = ioapic_mmio_read; | 337 | kvm_iodevice_init(&ioapic->dev, &ioapic_mmio_ops); |
327 | ioapic->dev.write = ioapic_mmio_write; | ||
328 | ioapic->dev.in_range = ioapic_in_range; | ||
329 | ioapic->dev.private = ioapic; | ||
330 | ioapic->kvm = kvm; | 338 | ioapic->kvm = kvm; |
331 | kvm_io_bus_register_dev(&kvm->mmio_bus, &ioapic->dev); | 339 | kvm_io_bus_register_dev(&kvm->mmio_bus, &ioapic->dev); |
332 | return 0; | 340 | return 0; |
diff --git a/virt/kvm/iodev.h b/virt/kvm/iodev.h index 55e8846ac3a6..2c67f5acd6db 100644 --- a/virt/kvm/iodev.h +++ b/virt/kvm/iodev.h | |||
@@ -18,7 +18,9 @@ | |||
18 | 18 | ||
19 | #include <linux/kvm_types.h> | 19 | #include <linux/kvm_types.h> |
20 | 20 | ||
21 | struct kvm_io_device { | 21 | struct kvm_io_device; |
22 | |||
23 | struct kvm_io_device_ops { | ||
22 | void (*read)(struct kvm_io_device *this, | 24 | void (*read)(struct kvm_io_device *this, |
23 | gpa_t addr, | 25 | gpa_t addr, |
24 | int len, | 26 | int len, |
@@ -30,16 +32,25 @@ struct kvm_io_device { | |||
30 | int (*in_range)(struct kvm_io_device *this, gpa_t addr, int len, | 32 | int (*in_range)(struct kvm_io_device *this, gpa_t addr, int len, |
31 | int is_write); | 33 | int is_write); |
32 | void (*destructor)(struct kvm_io_device *this); | 34 | void (*destructor)(struct kvm_io_device *this); |
35 | }; | ||
36 | |||
33 | 37 | ||
34 | void *private; | 38 | struct kvm_io_device { |
39 | const struct kvm_io_device_ops *ops; | ||
35 | }; | 40 | }; |
36 | 41 | ||
42 | static inline void kvm_iodevice_init(struct kvm_io_device *dev, | ||
43 | const struct kvm_io_device_ops *ops) | ||
44 | { | ||
45 | dev->ops = ops; | ||
46 | } | ||
47 | |||
37 | static inline void kvm_iodevice_read(struct kvm_io_device *dev, | 48 | static inline void kvm_iodevice_read(struct kvm_io_device *dev, |
38 | gpa_t addr, | 49 | gpa_t addr, |
39 | int len, | 50 | int len, |
40 | void *val) | 51 | void *val) |
41 | { | 52 | { |
42 | dev->read(dev, addr, len, val); | 53 | dev->ops->read(dev, addr, len, val); |
43 | } | 54 | } |
44 | 55 | ||
45 | static inline void kvm_iodevice_write(struct kvm_io_device *dev, | 56 | static inline void kvm_iodevice_write(struct kvm_io_device *dev, |
@@ -47,19 +58,19 @@ static inline void kvm_iodevice_write(struct kvm_io_device *dev, | |||
47 | int len, | 58 | int len, |
48 | const void *val) | 59 | const void *val) |
49 | { | 60 | { |
50 | dev->write(dev, addr, len, val); | 61 | dev->ops->write(dev, addr, len, val); |
51 | } | 62 | } |
52 | 63 | ||
53 | static inline int kvm_iodevice_inrange(struct kvm_io_device *dev, | 64 | static inline int kvm_iodevice_in_range(struct kvm_io_device *dev, |
54 | gpa_t addr, int len, int is_write) | 65 | gpa_t addr, int len, int is_write) |
55 | { | 66 | { |
56 | return dev->in_range(dev, addr, len, is_write); | 67 | return dev->ops->in_range(dev, addr, len, is_write); |
57 | } | 68 | } |
58 | 69 | ||
59 | static inline void kvm_iodevice_destructor(struct kvm_io_device *dev) | 70 | static inline void kvm_iodevice_destructor(struct kvm_io_device *dev) |
60 | { | 71 | { |
61 | if (dev->destructor) | 72 | if (dev->ops->destructor) |
62 | dev->destructor(dev); | 73 | dev->ops->destructor(dev); |
63 | } | 74 | } |
64 | 75 | ||
65 | #endif /* __KVM_IODEV_H__ */ | 76 | #endif /* __KVM_IODEV_H__ */ |
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 2d9bc439d9a9..d1f9c87daa87 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c | |||
@@ -2463,7 +2463,7 @@ struct kvm_io_device *kvm_io_bus_find_dev(struct kvm_io_bus *bus, | |||
2463 | for (i = 0; i < bus->dev_count; i++) { | 2463 | for (i = 0; i < bus->dev_count; i++) { |
2464 | struct kvm_io_device *pos = bus->devs[i]; | 2464 | struct kvm_io_device *pos = bus->devs[i]; |
2465 | 2465 | ||
2466 | if (pos->in_range(pos, addr, len, is_write)) | 2466 | if (kvm_iodevice_in_range(pos, addr, len, is_write)) |
2467 | return pos; | 2467 | return pos; |
2468 | } | 2468 | } |
2469 | 2469 | ||