2 * QEMU 8253/8254 interval timer emulation
4 * Copyright (c) 2003-2004 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 #include "qemu-timer.h"
31 extern VMStateDescription vmstate_pit
;
33 static void kvm_pit_pre_save(void *opaque
)
35 PITState
*s
= (void *)opaque
;
36 struct kvm_pit_state2 pit2
;
37 struct kvm_pit_channel_state
*c
;
38 struct PITChannelState
*sc
;
41 if (kvm_has_pit_state2()) {
42 kvm_get_pit2(kvm_state
, &pit2
);
43 s
->flags
= pit2
.flags
;
45 /* pit2 is superset of pit struct so just cast it and use it */
46 kvm_get_pit(kvm_state
, (struct kvm_pit_state
*)&pit2
);
48 for (i
= 0; i
< 3; i
++) {
49 c
= &pit2
.channels
[i
];
52 sc
->latched_count
= c
->latched_count
;
53 sc
->count_latched
= c
->count_latched
;
54 sc
->status_latched
= c
->status_latched
;
55 sc
->status
= c
->status
;
56 sc
->read_state
= c
->read_state
;
57 sc
->write_state
= c
->write_state
;
58 sc
->write_latch
= c
->write_latch
;
59 sc
->rw_mode
= c
->rw_mode
;
63 sc
->count_load_time
= c
->count_load_time
;
67 static int kvm_pit_post_load(void *opaque
, int version_id
)
70 struct kvm_pit_state2 pit2
;
71 struct kvm_pit_channel_state
*c
;
72 struct PITChannelState
*sc
;
75 pit2
.flags
= s
->flags
;
76 for (i
= 0; i
< 3; i
++) {
77 c
= &pit2
.channels
[i
];
80 c
->latched_count
= sc
->latched_count
;
81 c
->count_latched
= sc
->count_latched
;
82 c
->status_latched
= sc
->status_latched
;
83 c
->status
= sc
->status
;
84 c
->read_state
= sc
->read_state
;
85 c
->write_state
= sc
->write_state
;
86 c
->write_latch
= sc
->write_latch
;
87 c
->rw_mode
= sc
->rw_mode
;
91 c
->count_load_time
= sc
->count_load_time
;
94 if (kvm_has_pit_state2()) {
95 kvm_set_pit2(kvm_state
, &pit2
);
97 kvm_set_pit(kvm_state
, (struct kvm_pit_state
*)&pit2
);
102 static void dummy_timer(void *opaque
)
106 void kvm_pit_init(PITState
*pit
)
110 s
= &pit
->channels
[0];
111 s
->irq_timer
= qemu_new_timer_ns(vm_clock
, dummy_timer
, s
);
112 vmstate_pit
.pre_save
= kvm_pit_pre_save
;
113 vmstate_pit
.post_load
= kvm_pit_post_load
;