Commit b1728622 authored by Paul Durrant's avatar Paul Durrant Committed by Paolo Bonzini

KVM: x86: PIT: Preserve state of speaker port data bit

Currently the state of the speaker port (0x61) data bit (bit 1) is not
saved in the exported state (kvm_pit_state2) and hence is lost when
re-constructing guest state.

This patch removes the 'speaker_data_port' field from kvm_kpit_state and
instead tracks the state using a new KVM_PIT_FLAGS_SPEAKER_DATA_ON flag
defined in the API.
Signed-off-by: default avatarPaul Durrant <pdurrant@amazon.com>
Message-Id: <20220531124421.1427-1-pdurrant@amazon.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 3dbec44d
...@@ -3006,7 +3006,9 @@ KVM_CREATE_PIT2. The state is returned in the following structure:: ...@@ -3006,7 +3006,9 @@ KVM_CREATE_PIT2. The state is returned in the following structure::
Valid flags are:: Valid flags are::
/* disable PIT in HPET legacy mode */ /* disable PIT in HPET legacy mode */
#define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001 #define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001
/* speaker port data bit enabled */
#define KVM_PIT_FLAGS_SPEAKER_DATA_ON 0x00000002
This IOCTL replaces the obsolete KVM_GET_PIT. This IOCTL replaces the obsolete KVM_GET_PIT.
......
...@@ -306,7 +306,8 @@ struct kvm_pit_state { ...@@ -306,7 +306,8 @@ struct kvm_pit_state {
struct kvm_pit_channel_state channels[3]; struct kvm_pit_channel_state channels[3];
}; };
#define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001 #define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001
#define KVM_PIT_FLAGS_SPEAKER_DATA_ON 0x00000002
struct kvm_pit_state2 { struct kvm_pit_state2 {
struct kvm_pit_channel_state channels[3]; struct kvm_pit_channel_state channels[3];
......
...@@ -591,7 +591,10 @@ static int speaker_ioport_write(struct kvm_vcpu *vcpu, ...@@ -591,7 +591,10 @@ static int speaker_ioport_write(struct kvm_vcpu *vcpu,
return -EOPNOTSUPP; return -EOPNOTSUPP;
mutex_lock(&pit_state->lock); mutex_lock(&pit_state->lock);
pit_state->speaker_data_on = (val >> 1) & 1; if (val & (1 << 1))
pit_state->flags |= KVM_PIT_FLAGS_SPEAKER_DATA_ON;
else
pit_state->flags &= ~KVM_PIT_FLAGS_SPEAKER_DATA_ON;
pit_set_gate(pit, 2, val & 1); pit_set_gate(pit, 2, val & 1);
mutex_unlock(&pit_state->lock); mutex_unlock(&pit_state->lock);
return 0; return 0;
...@@ -612,8 +615,9 @@ static int speaker_ioport_read(struct kvm_vcpu *vcpu, ...@@ -612,8 +615,9 @@ static int speaker_ioport_read(struct kvm_vcpu *vcpu,
refresh_clock = ((unsigned int)ktime_to_ns(ktime_get()) >> 14) & 1; refresh_clock = ((unsigned int)ktime_to_ns(ktime_get()) >> 14) & 1;
mutex_lock(&pit_state->lock); mutex_lock(&pit_state->lock);
ret = ((pit_state->speaker_data_on << 1) | pit_get_gate(pit, 2) | ret = (!!(pit_state->flags & KVM_PIT_FLAGS_SPEAKER_DATA_ON) << 1) |
(pit_get_out(pit, 2) << 5) | (refresh_clock << 4)); pit_get_gate(pit, 2) | (pit_get_out(pit, 2) << 5) |
(refresh_clock << 4);
if (len > sizeof(ret)) if (len > sizeof(ret))
len = sizeof(ret); len = sizeof(ret);
memcpy(data, (char *)&ret, len); memcpy(data, (char *)&ret, len);
......
...@@ -29,7 +29,6 @@ struct kvm_kpit_state { ...@@ -29,7 +29,6 @@ struct kvm_kpit_state {
bool is_periodic; bool is_periodic;
s64 period; /* unit: ns */ s64 period; /* unit: ns */
struct hrtimer timer; struct hrtimer timer;
u32 speaker_data_on;
struct mutex lock; struct mutex lock;
atomic_t reinject; atomic_t reinject;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment