Lines Matching refs:pit
54 static void pit_set_gate(struct kvm_pit *pit, int channel, u32 val) in pit_set_gate() argument
56 struct kvm_kpit_channel_state *c = &pit->pit_state.channels[channel]; in pit_set_gate()
77 static int pit_get_gate(struct kvm_pit *pit, int channel) in pit_get_gate() argument
79 return pit->pit_state.channels[channel].gate; in pit_get_gate()
82 static s64 __kpit_elapsed(struct kvm_pit *pit) in __kpit_elapsed() argument
86 struct kvm_kpit_state *ps = &pit->pit_state; in __kpit_elapsed()
106 static s64 kpit_elapsed(struct kvm_pit *pit, struct kvm_kpit_channel_state *c, in kpit_elapsed() argument
110 return __kpit_elapsed(pit); in kpit_elapsed()
115 static int pit_get_count(struct kvm_pit *pit, int channel) in pit_get_count() argument
117 struct kvm_kpit_channel_state *c = &pit->pit_state.channels[channel]; in pit_get_count()
121 t = kpit_elapsed(pit, c, channel); in pit_get_count()
142 static int pit_get_out(struct kvm_pit *pit, int channel) in pit_get_out() argument
144 struct kvm_kpit_channel_state *c = &pit->pit_state.channels[channel]; in pit_get_out()
148 t = kpit_elapsed(pit, c, channel); in pit_get_out()
174 static void pit_latch_count(struct kvm_pit *pit, int channel) in pit_latch_count() argument
176 struct kvm_kpit_channel_state *c = &pit->pit_state.channels[channel]; in pit_latch_count()
179 c->latched_count = pit_get_count(pit, channel); in pit_latch_count()
184 static void pit_latch_status(struct kvm_pit *pit, int channel) in pit_latch_status() argument
186 struct kvm_kpit_channel_state *c = &pit->pit_state.channels[channel]; in pit_latch_status()
190 c->status = ((pit_get_out(pit, channel) << 7) | in pit_latch_status()
207 struct kvm_pit *pit = pit_state_to_pit(ps); in kvm_pit_ack_irq() local
215 kthread_queue_work(pit->worker, &pit->expired); in kvm_pit_ack_irq()
220 struct kvm_pit *pit = vcpu->kvm->arch.vpit; in __kvm_migrate_pit_timer() local
223 if (!kvm_vcpu_is_bsp(vcpu) || !pit) in __kvm_migrate_pit_timer()
226 timer = &pit->pit_state.timer; in __kvm_migrate_pit_timer()
227 mutex_lock(&pit->pit_state.lock); in __kvm_migrate_pit_timer()
230 mutex_unlock(&pit->pit_state.lock); in __kvm_migrate_pit_timer()
233 static void destroy_pit_timer(struct kvm_pit *pit) in destroy_pit_timer() argument
235 hrtimer_cancel(&pit->pit_state.timer); in destroy_pit_timer()
236 kthread_flush_work(&pit->expired); in destroy_pit_timer()
241 struct kvm_pit *pit = container_of(work, struct kvm_pit, expired); in pit_do_work() local
242 struct kvm *kvm = pit->kvm; in pit_do_work()
245 struct kvm_kpit_state *ps = &pit->pit_state; in pit_do_work()
250 kvm_set_irq(kvm, pit->irq_source_id, 0, 1, false); in pit_do_work()
251 kvm_set_irq(kvm, pit->irq_source_id, 0, 0, false); in pit_do_work()
284 static inline void kvm_pit_reset_reinject(struct kvm_pit *pit) in kvm_pit_reset_reinject() argument
286 atomic_set(&pit->pit_state.pending, 0); in kvm_pit_reset_reinject()
287 atomic_set(&pit->pit_state.irq_ack, 1); in kvm_pit_reset_reinject()
290 void kvm_pit_set_reinject(struct kvm_pit *pit, bool reinject) in kvm_pit_set_reinject() argument
292 struct kvm_kpit_state *ps = &pit->pit_state; in kvm_pit_set_reinject()
293 struct kvm *kvm = pit->kvm; in kvm_pit_set_reinject()
310 kvm_pit_reset_reinject(pit); in kvm_pit_set_reinject()
312 kvm_register_irq_mask_notifier(kvm, 0, &pit->mask_notifier); in kvm_pit_set_reinject()
317 kvm_unregister_irq_mask_notifier(kvm, 0, &pit->mask_notifier); in kvm_pit_set_reinject()
323 static void create_pit_timer(struct kvm_pit *pit, u32 val, int is_period) in create_pit_timer() argument
325 struct kvm_kpit_state *ps = &pit->pit_state; in create_pit_timer()
326 struct kvm *kvm = pit->kvm; in create_pit_timer()
339 kthread_flush_work(&pit->expired); in create_pit_timer()
343 kvm_pit_reset_reinject(pit); in create_pit_timer()
366 static void pit_load_count(struct kvm_pit *pit, int channel, u32 val) in pit_load_count() argument
368 struct kvm_kpit_state *ps = &pit->pit_state; in pit_load_count()
393 create_pit_timer(pit, val, 0); in pit_load_count()
397 create_pit_timer(pit, val, 1); in pit_load_count()
400 destroy_pit_timer(pit); in pit_load_count()
404 void kvm_pit_load_count(struct kvm_pit *pit, int channel, u32 val, in kvm_pit_load_count() argument
409 WARN_ON_ONCE(!mutex_is_locked(&pit->pit_state.lock)); in kvm_pit_load_count()
414 saved_mode = pit->pit_state.channels[0].mode; in kvm_pit_load_count()
415 pit->pit_state.channels[0].mode = 0xff; /* disable timer */ in kvm_pit_load_count()
416 pit_load_count(pit, channel, val); in kvm_pit_load_count()
417 pit->pit_state.channels[0].mode = saved_mode; in kvm_pit_load_count()
419 pit_load_count(pit, channel, val); in kvm_pit_load_count()
443 struct kvm_pit *pit = dev_to_pit(this); in pit_ioport_write() local
444 struct kvm_kpit_state *pit_state = &pit->pit_state; in pit_ioport_write()
467 pit_latch_count(pit, channel); in pit_ioport_write()
469 pit_latch_status(pit, channel); in pit_ioport_write()
477 pit_latch_count(pit, channel); in pit_ioport_write()
494 pit_load_count(pit, addr, val); in pit_ioport_write()
497 pit_load_count(pit, addr, val << 8); in pit_ioport_write()
504 pit_load_count(pit, addr, s->write_latch | (val << 8)); in pit_ioport_write()
518 struct kvm_pit *pit = dev_to_pit(this); in pit_ioport_read() local
519 struct kvm_kpit_state *pit_state = &pit->pit_state; in pit_ioport_read()
556 count = pit_get_count(pit, addr); in pit_ioport_read()
560 count = pit_get_count(pit, addr); in pit_ioport_read()
564 count = pit_get_count(pit, addr); in pit_ioport_read()
569 count = pit_get_count(pit, addr); in pit_ioport_read()
588 struct kvm_pit *pit = speaker_to_pit(this); in speaker_ioport_write() local
589 struct kvm_kpit_state *pit_state = &pit->pit_state; in speaker_ioport_write()
596 pit_set_gate(pit, 2, val & 1); in speaker_ioport_write()
605 struct kvm_pit *pit = speaker_to_pit(this); in speaker_ioport_read() local
606 struct kvm_kpit_state *pit_state = &pit->pit_state; in speaker_ioport_read()
616 ret = ((pit_state->speaker_data_on << 1) | pit_get_gate(pit, 2) | in speaker_ioport_read()
617 (pit_get_out(pit, 2) << 5) | (refresh_clock << 4)); in speaker_ioport_read()
625 static void kvm_pit_reset(struct kvm_pit *pit) in kvm_pit_reset() argument
630 pit->pit_state.flags = 0; in kvm_pit_reset()
632 c = &pit->pit_state.channels[i]; in kvm_pit_reset()
635 pit_load_count(pit, i, 0); in kvm_pit_reset()
638 kvm_pit_reset_reinject(pit); in kvm_pit_reset()
643 struct kvm_pit *pit = container_of(kimn, struct kvm_pit, mask_notifier); in pit_mask_notifer() local
646 kvm_pit_reset_reinject(pit); in pit_mask_notifer()
661 struct kvm_pit *pit; in kvm_create_pit() local
667 pit = kzalloc(sizeof(struct kvm_pit), GFP_KERNEL_ACCOUNT); in kvm_create_pit()
668 if (!pit) in kvm_create_pit()
671 pit->irq_source_id = kvm_request_irq_source_id(kvm); in kvm_create_pit()
672 if (pit->irq_source_id < 0) in kvm_create_pit()
675 mutex_init(&pit->pit_state.lock); in kvm_create_pit()
681 pit->worker = kthread_create_worker(0, "kvm-pit/%d", pid_nr); in kvm_create_pit()
682 if (IS_ERR(pit->worker)) in kvm_create_pit()
685 kthread_init_work(&pit->expired, pit_do_work); in kvm_create_pit()
687 pit->kvm = kvm; in kvm_create_pit()
689 pit_state = &pit->pit_state; in kvm_create_pit()
695 pit->mask_notifier.func = pit_mask_notifer; in kvm_create_pit()
697 kvm_pit_reset(pit); in kvm_create_pit()
699 kvm_pit_set_reinject(pit, true); in kvm_create_pit()
702 kvm_iodevice_init(&pit->dev, &pit_dev_ops); in kvm_create_pit()
704 KVM_PIT_MEM_LENGTH, &pit->dev); in kvm_create_pit()
709 kvm_iodevice_init(&pit->speaker_dev, &speaker_dev_ops); in kvm_create_pit()
712 &pit->speaker_dev); in kvm_create_pit()
718 return pit; in kvm_create_pit()
721 kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS, &pit->dev); in kvm_create_pit()
724 kvm_pit_set_reinject(pit, false); in kvm_create_pit()
725 kthread_destroy_worker(pit->worker); in kvm_create_pit()
727 kvm_free_irq_source_id(kvm, pit->irq_source_id); in kvm_create_pit()
729 kfree(pit); in kvm_create_pit()
735 struct kvm_pit *pit = kvm->arch.vpit; in kvm_free_pit() local
737 if (pit) { in kvm_free_pit()
739 kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS, &pit->dev); in kvm_free_pit()
740 kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS, &pit->speaker_dev); in kvm_free_pit()
742 kvm_pit_set_reinject(pit, false); in kvm_free_pit()
743 hrtimer_cancel(&pit->pit_state.timer); in kvm_free_pit()
744 kthread_destroy_worker(pit->worker); in kvm_free_pit()
745 kvm_free_irq_source_id(kvm, pit->irq_source_id); in kvm_free_pit()
746 kfree(pit); in kvm_free_pit()