[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 08/10] rust/timer/hpet: add basic HPET timer and HPETState
From: |
Paolo Bonzini |
Subject: |
Re: [PATCH 08/10] rust/timer/hpet: add basic HPET timer and HPETState |
Date: |
Wed, 29 Jan 2025 11:57:18 +0100 |
User-agent: |
Mozilla Thunderbird |
On Sat, Jan 25, 2025 at 1:32 PM Zhao Liu <zhao1.liu@intel.com> wrote:
+// Register space for each timer block. (HPET_BASE isn't defined here.)
+const HPET_REG_SPACE_LEN: u64 = 0x400; // 1024 bytes
Use doc comments "///"...
+// Timer N FSB Interrupt Route Register (masked by 0x18)
+const HPET_TN_FSB_ROUTE_REG: u64 = 0x010;
... all the way to here.
+/// HPET Timer Abstraction
+#[repr(C)]
+#[derive(Debug, Default, qemu_api_macros::offsets)]
+pub struct HPETTimer {
+ /// timer N index within the timer block (HPETState)
+ #[doc(alias = "tn")]
+ index: usize,
+ qemu_timer: Option<Box<QEMUTimer>>,
+ /// timer block abstraction containing this timer
+ state: Option<NonNull<HPETState>>,
+
+ /// Memory-mapped, software visible timer registers
These "headings" cannot be doc comments, because they would be attached
to the field after. Same below:
- /// Hidden register state
+ // Hidden register state
- /// HPET block Registers: Memory-mapped, software visible registers
+ // HPET block Registers: Memory-mapped, software visible registers
- /// Internal state
+ // Internal state
+ fn get_state(&self) -> &HPETState {
+ // SAFETY:
+ // the pointer is convertible to a reference
+ unsafe { self.state.unwrap().as_ref() }
+ }
Note for the future: I looked briefly into why a NonNull<> is needed
and the reasons are two. First, the offset_of! replacement does not
support lifetime parameters. Second, it's messy to pass a &HPETState
to the &HPETTimer, because the HPETTimer still has to be written into
the HPETState. This may be worth revisiting when QEMU starts using
pinned-init is added, but for now is self-contained.
+ if let Some(timer) = self.qemu_timer.as_mut() {
+ timer.timer_mod(self.last);
+ }
I think this can be just "timer.unwrap().timer_mod(self.last)" (not
sure if it needs an as_ref() too).
Paolo
- Re: [PATCH 03/10] rust/irq: Add a helper to convert [InterruptSource] to [*mut IRQState], (continued)
- [PATCH 04/10] rust: add bindings for gpio_{in|out} initialization, Zhao Liu, 2025/01/25
- [PATCH 05/10] rust: add bindings for memattrs, Zhao Liu, 2025/01/25
- [PATCH 01/10] i386/fw_cfg: move hpet_cfg definition to hpet.c, Zhao Liu, 2025/01/25
- [PATCH 06/10] rust: add bindings for timer, Zhao Liu, 2025/01/25
- [PATCH 07/10] rust/timer/hpet: define hpet_cfg, Zhao Liu, 2025/01/25
- [PATCH 08/10] rust/timer/hpet: add basic HPET timer and HPETState, Zhao Liu, 2025/01/25
- Re: [PATCH 08/10] rust/timer/hpet: add basic HPET timer and HPETState,
Paolo Bonzini <=
- [PATCH 09/10] rust/timer/hpet: add qom and qdev APIs support, Zhao Liu, 2025/01/25
- [PATCH 10/10] i386: enable rust hpet for pc when rust is enabled, Zhao Liu, 2025/01/25