From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Zhao Liu <zhao1.liu@intel.com>
Subject: [PULL 29/34] rust/hpet: convert num_timers to u8 type
Date: Wed, 23 Apr 2025 11:40:59 +0200 [thread overview]
Message-ID: <20250423094105.40692-30-pbonzini@redhat.com> (raw)
In-Reply-To: <20250423094105.40692-1-pbonzini@redhat.com>
From: Zhao Liu <zhao1.liu@intel.com>
The C version of HPET uses the uint8_t type for num_timers, and usize
type in Rust version will break migration between the C and Rust
versions.
So convert num_timers' type to u8 (consistent with the C version of
HPET) to make it friendly for vmstate support.
Note the commit 7bda68e8e2b0 ("qdev, rust/hpet: fix type of HPET
'timers property") supports the usize type property, but the uint8
property has to be re-supported now.
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
Link: https://lore.kernel.org/r/20250414144943.1112885-7-zhao1.liu@intel.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
rust/hw/timer/hpet/src/hpet.rs | 31 ++++++++++++++++++-------------
1 file changed, 18 insertions(+), 13 deletions(-)
diff --git a/rust/hw/timer/hpet/src/hpet.rs b/rust/hw/timer/hpet/src/hpet.rs
index 3ae3ec25f17..1afa891362f 100644
--- a/rust/hw/timer/hpet/src/hpet.rs
+++ b/rust/hw/timer/hpet/src/hpet.rs
@@ -12,7 +12,7 @@
use qemu_api::{
bindings::{
address_space_memory, address_space_stl_le, qdev_prop_bit, qdev_prop_bool,
- qdev_prop_uint32, qdev_prop_usize,
+ qdev_prop_uint32, qdev_prop_uint8,
},
c_str,
cell::{BqlCell, BqlRefCell},
@@ -34,9 +34,9 @@
const HPET_REG_SPACE_LEN: u64 = 0x400; // 1024 bytes
/// Minimum recommended hardware implementation.
-const HPET_MIN_TIMERS: usize = 3;
+const HPET_MIN_TIMERS: u8 = 3;
/// Maximum timers in each timer block.
-const HPET_MAX_TIMERS: usize = 32;
+const HPET_MAX_TIMERS: u8 = 32;
/// Flags that HPETState.flags supports.
const HPET_FLAG_MSI_SUPPORT_SHIFT: usize = 0;
@@ -559,14 +559,19 @@ pub struct HPETState {
/// HPET timer array managed by this timer block.
#[doc(alias = "timer")]
- timers: [BqlRefCell<HPETTimer>; HPET_MAX_TIMERS],
- num_timers: BqlCell<usize>,
+ timers: [BqlRefCell<HPETTimer>; HPET_MAX_TIMERS as usize],
+ num_timers: BqlCell<u8>,
/// Instance id (HPET timer block ID).
hpet_id: BqlCell<usize>,
}
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()
+ }
+
const fn has_msi_flag(&self) -> bool {
self.flags & (1 << HPET_FLAG_MSI_SUPPORT_SHIFT) != 0
}
@@ -628,7 +633,7 @@ fn set_cfg_reg(&self, shift: u32, len: u32, val: u64) {
self.hpet_offset
.set(ticks_to_ns(self.counter.get()) - CLOCK_VIRTUAL.get_ns());
- for timer in self.timers.iter().take(self.num_timers.get()) {
+ for timer in self.timers.iter().take(self.get_num_timers()) {
let mut t = timer.borrow_mut();
if t.is_int_enabled() && t.is_int_active() {
@@ -640,7 +645,7 @@ fn set_cfg_reg(&self, shift: u32, len: u32, val: u64) {
// Halt main counter and disable interrupt generation.
self.counter.set(self.get_ticks());
- for timer in self.timers.iter().take(self.num_timers.get()) {
+ for timer in self.timers.iter().take(self.get_num_timers()) {
timer.borrow_mut().del_timer();
}
}
@@ -663,7 +668,7 @@ fn set_int_status_reg(&self, shift: u32, _len: u32, val: u64) {
let new_val = val << shift;
let cleared = new_val & self.int_status.get();
- for (index, timer) in self.timers.iter().take(self.num_timers.get()).enumerate() {
+ for (index, timer) in self.timers.iter().take(self.get_num_timers()).enumerate() {
if cleared & (1 << index) != 0 {
timer.borrow_mut().update_irq(false);
}
@@ -737,7 +742,7 @@ fn realize(&self) {
1 << HPET_CAP_COUNT_SIZE_CAP_SHIFT |
1 << HPET_CAP_LEG_RT_CAP_SHIFT |
HPET_CAP_VENDER_ID_VALUE << HPET_CAP_VENDER_ID_SHIFT |
- ((self.num_timers.get() - 1) as u64) << HPET_CAP_NUM_TIM_SHIFT | // indicate the last timer
+ ((self.get_num_timers() - 1) as u64) << HPET_CAP_NUM_TIM_SHIFT | // indicate the last timer
(HPET_CLK_PERIOD * FS_PER_NS) << HPET_CAP_CNT_CLK_PERIOD_SHIFT, // 10 ns
);
@@ -746,7 +751,7 @@ fn realize(&self) {
}
fn reset_hold(&self, _type: ResetType) {
- for timer in self.timers.iter().take(self.num_timers.get()) {
+ for timer in self.timers.iter().take(self.get_num_timers()) {
timer.borrow_mut().reset();
}
@@ -774,7 +779,7 @@ fn decode(&self, mut addr: hwaddr, size: u32) -> HPETAddrDecode {
GlobalRegister::try_from(addr).map(HPETRegister::Global)
} else {
let timer_id: usize = ((addr - 0x100) / 0x20) as usize;
- if timer_id <= self.num_timers.get() {
+ if timer_id <= self.get_num_timers() {
// TODO: Add trace point - trace_hpet_ram_[read|write]_timer_id(timer_id)
TimerRegister::try_from(addr & 0x18)
.map(|reg| HPETRegister::Timer(&self.timers[timer_id], reg))
@@ -859,8 +864,8 @@ impl ObjectImpl for HPETState {
c_str!("timers"),
HPETState,
num_timers,
- unsafe { &qdev_prop_usize },
- usize,
+ unsafe { &qdev_prop_uint8 },
+ u8,
default = HPET_MIN_TIMERS
),
qemu_api::define_property!(
--
2.49.0
next prev parent reply other threads:[~2025-04-23 9:43 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-23 9:40 [PULL 00/34] i386, Rust, SCSI changes for 2025-04-23 Paolo Bonzini
2025-04-23 9:40 ` [PULL 01/34] scsi: add conversion from ENODEV to sense Paolo Bonzini
2025-04-23 9:40 ` [PULL 02/34] target/i386: Fix model number of Zhaoxin YongFeng vCPU template Paolo Bonzini
2025-04-23 9:40 ` [PULL 03/34] target/i386: Reset parked vCPUs together with the online ones Paolo Bonzini
2025-04-23 9:40 ` [PULL 04/34] target/i386/hvf: fix lflags_to_rflags Paolo Bonzini
2025-04-23 9:40 ` [PULL 05/34] target/i386: special case ADC/SBB x,0 and SBB x,x Paolo Bonzini
2025-04-23 9:40 ` [PULL 06/34] target/i386: tcg: remove tmp0 and tmp4 from SHLD/SHRD Paolo Bonzini
2025-04-23 9:40 ` [PULL 07/34] target/i386: tcg: remove subf from SHLD/SHRD expansion Paolo Bonzini
2025-04-23 9:40 ` [PULL 08/34] target/i386: tcg: remove tmp0 Paolo Bonzini
2025-04-23 9:40 ` [PULL 09/34] target/i386: tcg: remove some more uses of temporaries Paolo Bonzini
2025-04-23 9:40 ` [PULL 10/34] target/i386: tcg: simplify computation of AF after INC/DEC Paolo Bonzini
2025-04-23 9:40 ` [PULL 11/34] target/i386: emulate: microoptimize and explain ADD_COUT_VEC/SUB_COUT_VEC Paolo Bonzini
2025-04-23 9:40 ` [PULL 12/34] target/i386: tcg: use cout to commonize add/adc/sub/sbb cases Paolo Bonzini
2025-04-23 9:40 ` [PULL 13/34] target/i386/hvf: introduce x86_emul_ops Paolo Bonzini
2025-04-23 9:40 ` [PULL 14/34] target/i386/hvf: remove HVF specific calls from x86_decode.c Paolo Bonzini
2025-04-23 9:40 ` [PULL 15/34] target/i386/hvf: provide and use handle_io in emul_ops Paolo Bonzini
2025-04-23 9:40 ` [PULL 16/34] target/i386: rename hvf_mmio_buf to emu_mmio_buf Paolo Bonzini
2025-04-23 9:40 ` [PULL 17/34] target/i386/hvf: use emul_ops->read_mem in x86_emu.c Paolo Bonzini
2025-04-23 9:40 ` [PULL 18/34] target/i386/hvf: provide and use write_mem in emul_ops Paolo Bonzini
2025-04-23 9:40 ` [PULL 19/34] target/i386/hvf: provide and use simulate_{wrmsr, rdmsr} " Paolo Bonzini
2025-04-23 9:40 ` [PULL 20/34] target/i386: rename lazy flags field and its type Paolo Bonzini
2025-04-23 9:40 ` [PULL 21/34] target/i386/hvf: drop unused headers Paolo Bonzini
2025-04-23 9:40 ` [PULL 22/34] target/i386/hvf: rename some include guards Paolo Bonzini
2025-04-23 9:40 ` [PULL 23/34] target/i386: add a directory for x86 instruction emulator Paolo Bonzini
2025-04-23 9:40 ` [PULL 24/34] target/i386/emulate: add a panic.h Paolo Bonzini
2025-04-23 9:40 ` [PULL 25/34] target/i386: move x86 instruction emulator out of hvf Paolo Bonzini
2025-04-23 9:40 ` [PULL 26/34] MAINTAINERS: add an entry for the x86 instruction emulator Paolo Bonzini
2025-04-23 9:40 ` [PULL 27/34] target/i386/emulate: remove flags_mask Paolo Bonzini
2025-04-23 9:40 ` [PULL 28/34] i386/cpu: Consolidate the helper to get Host's vendor Paolo Bonzini
2025-04-23 9:40 ` Paolo Bonzini [this message]
2025-04-23 9:41 ` [PULL 30/34] rust/hpet: convert HPETTimer index to u8 type Paolo Bonzini
2025-04-23 9:41 ` [PULL 31/34] rust/hpet: Fix a clippy error Paolo Bonzini
2025-04-23 9:41 ` [PULL 32/34] rust/vmstate_test: Fix typo in test_vmstate_macro_array_of_pointer_wrapped() Paolo Bonzini
2025-04-23 9:41 ` [PULL 33/34] rust/hw/char/pl011: Extract extract DR read logic into separate function Paolo Bonzini
2025-04-23 9:41 ` [PULL 34/34] rust/hw/char/pl011: Extract DR write " Paolo Bonzini
2025-04-23 17:58 ` [PULL 00/34] i386, Rust, SCSI changes for 2025-04-23 Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250423094105.40692-30-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=zhao1.liu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).