summary refs log tree commit diff stats
path: root/rust/qemu-api/src/prelude.rs
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2025-01-17 11:21:26 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2025-02-13 12:19:33 +0100
commit201ef001dd40fdb11c83f3e47604219c374590ec (patch)
tree8c636c5744556fa86ee672dc24ae46377a4c3160 /rust/qemu-api/src/prelude.rs
parent66bcc554d27f693f89bf04df24d474463a90a894 (diff)
downloadfocaccia-qemu-201ef001dd40fdb11c83f3e47604219c374590ec.tar.gz
focaccia-qemu-201ef001dd40fdb11c83f3e47604219c374590ec.zip
rust: qdev: add clock creation
Add a Rust version of qdev_init_clock_in, which can be used in
instance_init.  There are a couple differences with the C
version:

- in Rust the object keeps its own reference to the clock (in addition to
  the one embedded in the NamedClockList), and the reference is dropped
  automatically by instance_finalize(); this is encoded in the signature
  of DeviceClassMethods::init_clock_in, which makes the lifetime of the
  clock independent of that of the object it holds.  This goes unnoticed
  in the C version and is due to the existence of aliases.

- also, anything that happens during instance_init uses the pinned_init
  framework to operate on a partially initialized object, and is done
  through class methods (i.e. through DeviceClassMethods rather than
  DeviceMethods) because the device does not exist yet.  Therefore, Rust
  code *must* create clocks from instance_init, which is stricter than C.

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'rust/qemu-api/src/prelude.rs')
-rw-r--r--rust/qemu-api/src/prelude.rs2
1 files changed, 2 insertions, 0 deletions
diff --git a/rust/qemu-api/src/prelude.rs b/rust/qemu-api/src/prelude.rs
index 3df6a5c21e..87e3ce90f2 100644
--- a/rust/qemu-api/src/prelude.rs
+++ b/rust/qemu-api/src/prelude.rs
@@ -7,6 +7,8 @@ pub use crate::bitops::IntegerExt;
 pub use crate::cell::BqlCell;
 pub use crate::cell::BqlRefCell;
 
+pub use crate::qdev::DeviceMethods;
+
 pub use crate::qom::IsA;
 pub use crate::qom::Object;
 pub use crate::qom::ObjectCast;