diff options
Diffstat (limited to 'arch/x86/kvm/i8254.c')
-rw-r--r-- | arch/x86/kvm/i8254.c | 40 |
1 files changed, 28 insertions, 12 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 | ||