mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-21 00:53:27 -06:00
rust/hpet: change type of num_timers to usize
Remove the need to convert after every read of the BqlCell. Because the vmstate uses a u8 as the size of the VARRAY, this requires switching the VARRAY to use num_timers_save; which in turn requires ensuring that the num_timers_save is always there. For simplicity do this by removing support for version 1, which QEMU has not been producing for ~15 years. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
4b66abead9
commit
b3bf86b893
1 changed files with 12 additions and 12 deletions
|
@ -12,7 +12,7 @@ use std::{
|
||||||
use qemu_api::{
|
use qemu_api::{
|
||||||
bindings::{
|
bindings::{
|
||||||
address_space_memory, address_space_stl_le, qdev_prop_bit, qdev_prop_bool,
|
address_space_memory, address_space_stl_le, qdev_prop_bit, qdev_prop_bool,
|
||||||
qdev_prop_uint32, qdev_prop_uint8,
|
qdev_prop_uint32, qdev_prop_usize,
|
||||||
},
|
},
|
||||||
cell::{BqlCell, BqlRefCell},
|
cell::{BqlCell, BqlRefCell},
|
||||||
irq::InterruptSource,
|
irq::InterruptSource,
|
||||||
|
@ -36,9 +36,9 @@ use crate::fw_cfg::HPETFwConfig;
|
||||||
const HPET_REG_SPACE_LEN: u64 = 0x400; // 1024 bytes
|
const HPET_REG_SPACE_LEN: u64 = 0x400; // 1024 bytes
|
||||||
|
|
||||||
/// Minimum recommended hardware implementation.
|
/// Minimum recommended hardware implementation.
|
||||||
const HPET_MIN_TIMERS: u8 = 3;
|
const HPET_MIN_TIMERS: usize = 3;
|
||||||
/// Maximum timers in each timer block.
|
/// Maximum timers in each timer block.
|
||||||
const HPET_MAX_TIMERS: u8 = 32;
|
const HPET_MAX_TIMERS: usize = 32;
|
||||||
|
|
||||||
/// Flags that HPETState.flags supports.
|
/// Flags that HPETState.flags supports.
|
||||||
const HPET_FLAG_MSI_SUPPORT_SHIFT: usize = 0;
|
const HPET_FLAG_MSI_SUPPORT_SHIFT: usize = 0;
|
||||||
|
@ -561,8 +561,8 @@ pub struct HPETState {
|
||||||
|
|
||||||
/// HPET timer array managed by this timer block.
|
/// HPET timer array managed by this timer block.
|
||||||
#[doc(alias = "timer")]
|
#[doc(alias = "timer")]
|
||||||
timers: [BqlRefCell<HPETTimer>; HPET_MAX_TIMERS as usize],
|
timers: [BqlRefCell<HPETTimer>; HPET_MAX_TIMERS],
|
||||||
num_timers: BqlCell<u8>,
|
num_timers: BqlCell<usize>,
|
||||||
num_timers_save: BqlCell<u8>,
|
num_timers_save: BqlCell<u8>,
|
||||||
|
|
||||||
/// Instance id (HPET timer block ID).
|
/// Instance id (HPET timer block ID).
|
||||||
|
@ -572,7 +572,7 @@ pub struct HPETState {
|
||||||
impl HPETState {
|
impl HPETState {
|
||||||
// Get num_timers with `usize` type, which is useful to play with array index.
|
// Get num_timers with `usize` type, which is useful to play with array index.
|
||||||
fn get_num_timers(&self) -> usize {
|
fn get_num_timers(&self) -> usize {
|
||||||
self.num_timers.get().into()
|
self.num_timers.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
const fn has_msi_flag(&self) -> bool {
|
const fn has_msi_flag(&self) -> bool {
|
||||||
|
@ -854,7 +854,7 @@ impl HPETState {
|
||||||
* also added to the migration stream. Check that it matches the value
|
* also added to the migration stream. Check that it matches the value
|
||||||
* that was configured.
|
* that was configured.
|
||||||
*/
|
*/
|
||||||
self.num_timers_save.set(self.num_timers.get());
|
self.num_timers_save.set(self.num_timers.get() as u8);
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -884,7 +884,7 @@ impl HPETState {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn validate_num_timers(&self, _version_id: u8) -> bool {
|
fn validate_num_timers(&self, _version_id: u8) -> bool {
|
||||||
self.num_timers.get() == self.num_timers_save.get()
|
self.num_timers.get() == self.num_timers_save.get().into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -911,7 +911,7 @@ qemu_api::declare_properties! {
|
||||||
c"timers",
|
c"timers",
|
||||||
HPETState,
|
HPETState,
|
||||||
num_timers,
|
num_timers,
|
||||||
unsafe { &qdev_prop_uint8 },
|
unsafe { &qdev_prop_usize },
|
||||||
u8,
|
u8,
|
||||||
default = HPET_MIN_TIMERS
|
default = HPET_MIN_TIMERS
|
||||||
),
|
),
|
||||||
|
@ -1016,16 +1016,16 @@ const VALIDATE_TIMERS_NAME: &CStr = c"num_timers must match";
|
||||||
static VMSTATE_HPET: VMStateDescription = VMStateDescription {
|
static VMSTATE_HPET: VMStateDescription = VMStateDescription {
|
||||||
name: c"hpet".as_ptr(),
|
name: c"hpet".as_ptr(),
|
||||||
version_id: 2,
|
version_id: 2,
|
||||||
minimum_version_id: 1,
|
minimum_version_id: 2,
|
||||||
pre_save: Some(hpet_pre_save),
|
pre_save: Some(hpet_pre_save),
|
||||||
post_load: Some(hpet_post_load),
|
post_load: Some(hpet_post_load),
|
||||||
fields: vmstate_fields! {
|
fields: vmstate_fields! {
|
||||||
vmstate_of!(HPETState, config),
|
vmstate_of!(HPETState, config),
|
||||||
vmstate_of!(HPETState, int_status),
|
vmstate_of!(HPETState, int_status),
|
||||||
vmstate_of!(HPETState, counter),
|
vmstate_of!(HPETState, counter),
|
||||||
vmstate_of!(HPETState, num_timers_save).with_version_id(2),
|
vmstate_of!(HPETState, num_timers_save),
|
||||||
vmstate_validate!(HPETState, VALIDATE_TIMERS_NAME, HPETState::validate_num_timers),
|
vmstate_validate!(HPETState, VALIDATE_TIMERS_NAME, HPETState::validate_num_timers),
|
||||||
vmstate_struct!(HPETState, timers[0 .. num_timers], &VMSTATE_HPET_TIMER, BqlRefCell<HPETTimer>, HPETState::validate_num_timers).with_version_id(0),
|
vmstate_struct!(HPETState, timers[0 .. num_timers_save], &VMSTATE_HPET_TIMER, BqlRefCell<HPETTimer>, HPETState::validate_num_timers).with_version_id(0),
|
||||||
},
|
},
|
||||||
subsections: vmstate_subsections! {
|
subsections: vmstate_subsections! {
|
||||||
VMSTATE_HPET_RTC_IRQ_LEVEL,
|
VMSTATE_HPET_RTC_IRQ_LEVEL,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue