mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-05 00:33:55 -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::{
|
||||
bindings::{
|
||||
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},
|
||||
irq::InterruptSource,
|
||||
|
@ -36,9 +36,9 @@ use crate::fw_cfg::HPETFwConfig;
|
|||
const HPET_REG_SPACE_LEN: u64 = 0x400; // 1024 bytes
|
||||
|
||||
/// Minimum recommended hardware implementation.
|
||||
const HPET_MIN_TIMERS: u8 = 3;
|
||||
const HPET_MIN_TIMERS: usize = 3;
|
||||
/// Maximum timers in each timer block.
|
||||
const HPET_MAX_TIMERS: u8 = 32;
|
||||
const HPET_MAX_TIMERS: usize = 32;
|
||||
|
||||
/// Flags that HPETState.flags supports.
|
||||
const HPET_FLAG_MSI_SUPPORT_SHIFT: usize = 0;
|
||||
|
@ -561,8 +561,8 @@ pub struct HPETState {
|
|||
|
||||
/// HPET timer array managed by this timer block.
|
||||
#[doc(alias = "timer")]
|
||||
timers: [BqlRefCell<HPETTimer>; HPET_MAX_TIMERS as usize],
|
||||
num_timers: BqlCell<u8>,
|
||||
timers: [BqlRefCell<HPETTimer>; HPET_MAX_TIMERS],
|
||||
num_timers: BqlCell<usize>,
|
||||
num_timers_save: BqlCell<u8>,
|
||||
|
||||
/// Instance id (HPET timer block ID).
|
||||
|
@ -572,7 +572,7 @@ pub struct HPETState {
|
|||
impl HPETState {
|
||||
// Get num_timers with `usize` type, which is useful to play with array index.
|
||||
fn get_num_timers(&self) -> usize {
|
||||
self.num_timers.get().into()
|
||||
self.num_timers.get()
|
||||
}
|
||||
|
||||
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
|
||||
* that was configured.
|
||||
*/
|
||||
self.num_timers_save.set(self.num_timers.get());
|
||||
self.num_timers_save.set(self.num_timers.get() as u8);
|
||||
0
|
||||
}
|
||||
|
||||
|
@ -884,7 +884,7 @@ impl HPETState {
|
|||
}
|
||||
|
||||
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",
|
||||
HPETState,
|
||||
num_timers,
|
||||
unsafe { &qdev_prop_uint8 },
|
||||
unsafe { &qdev_prop_usize },
|
||||
u8,
|
||||
default = HPET_MIN_TIMERS
|
||||
),
|
||||
|
@ -1016,16 +1016,16 @@ const VALIDATE_TIMERS_NAME: &CStr = c"num_timers must match";
|
|||
static VMSTATE_HPET: VMStateDescription = VMStateDescription {
|
||||
name: c"hpet".as_ptr(),
|
||||
version_id: 2,
|
||||
minimum_version_id: 1,
|
||||
minimum_version_id: 2,
|
||||
pre_save: Some(hpet_pre_save),
|
||||
post_load: Some(hpet_post_load),
|
||||
fields: vmstate_fields! {
|
||||
vmstate_of!(HPETState, config),
|
||||
vmstate_of!(HPETState, int_status),
|
||||
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_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! {
|
||||
VMSTATE_HPET_RTC_IRQ_LEVEL,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue