rust: miscellaneous cleanup & HPET #property conversion
cover rust: miscellaneous cleanup & HPET #property conversion
Hi,
This series include:
* cleanup for .gitignore of subproject.
* cleanup for clippy error & warnings based on v1.83.
* support bit property in #property.
* HPET #property conversion.
* get rid of the legacy declare_properties & define_property.
And this series is based on the commit 355ce1d4fbaa of Paolo's rust-ci branch (since I understand that branch includes the latest rust PR patches.)
Thanks and Best Regards,
Zhao
---
Manos Pitsidianakis (2):
rust/qdev: use addr_of! in QDevProp rust/qdev: Refine the documentation for QDevProp trait
Zhao Liu (10):
subprojects: Update .gitignore for proc-macro2 and syn
subprojects: Ignore .wraplock file generated by meson v1.9.0 rust/qemu-macros: Fix Clippy's complaints about lambda parameter
naming
rust/common/uninit: Fix Clippy's complaints about lifetime rust/qdev: Rename PropertyInfo field from VALUE to BASE_INFO rust/qdev: Support property info for more common types rust/qdev: Support bit property in #property macro rust/hpet: Clean up type mismatch for num_timers property rust/hpet: Convert qdev properties to #property macro rust/qdev: Drop declare_properties & define_property macros
rust/common/src/uninit.rs | 4 +- rust/hw/core/src/qdev.rs | 105 ++++++++++--------------------- rust/hw/timer/hpet/src/device.rs | 55 +++------------- rust/qemu-macros/src/lib.rs | 81 ++++++++++++++++-------- subprojects/.gitignore | 7 ++- 5 files changed, 102 insertions(+), 150 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/12 subprojects: Update .gitignore for proc-macro2 and syn
--- subprojects/.gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
subprojects/.gitignore +2 -2
@@ -16,7 +16,7 @@ /libc-0.2.162 /proc-macro-error-1.0.4 /proc-macro-error-attr-1.0.4 -/proc-macro2-1.0.84 +/proc-macro2-1.0.95 /quote-1.0.36 -/syn-2.0.66 +/syn-2.0.104 /unicode-ident-1.0.12
Signature · 1 line
2.34.1
Re: [PATCH 01/12] subprojects: Update .gitignore for proc-macro2 and syn
Quoted 21 lines · Zhao Liu
Signed-off-by Zhao Liu <[email protected]>--- subprojects/.gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)subprojects/.gitignore +2
-3@@ -16,7 +16,7 @@ /libc-0.2.162 /proc-macro-error-1.0.4 /proc-macro-error-attr-1.0.4 -/proc-macro2-1.0.84 +/proc-macro2-1.0.95 /quote-1.0.36 -/syn-2.0.66 +/syn-2.0.104 /unicode-ident-1.0.12 --
Quoted 2 lines
2.34.1
Maybe we could change the entries to match any directory with a version, e.g.
/proc-macro2-[0-9.]*/
Re: [PATCH 01/12] subprojects: Update .gitignore for proc-macro2 and syn
Quoted 23 lines · Manos Pitsidianakis
Date: Tue, 16 Sep 2025 12:58:24 +0300
From: Manos Pitsidianakis <[email protected]>
Subject: Re: [PATCH 01/12] subprojects: Update .gitignore for proc-macro2
and synQuoted 17 lines · Zhao Liu
Signed-off-by Zhao Liu <[email protected]>--- subprojects/.gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)subprojects/.gitignore +1
-1@@ -16,7 +16,7 @@ /libc-0.2.162 /proc-macro-error-1.0.4 /proc-macro-error-attr-1.0.4 -/proc-macro2-1.0.84 +/proc-macro2-1.0.95 /quote-1.0.36
Quoted 8 lines
Quoted 6 lines
subprojects/.gitignore +1
-2-/syn-2.0.66 +/syn-2.0.104 /unicode-ident-1.0.12 --2.34.1
Reviewed-by Manos Pitsidianakis <[email protected]>
Thanks!
Quoted 3 lines
Maybe we could change the entries to match any directory with a version, e.g.
/proc-macro2-[0-9.]*/
Here I prefer exact matching, as it allows for timely cleanup of outdated subprojects.
Regards,
Zhao
PATCH 2/12 subprojects: Ignore .wraplock file generated by meson v1.9.0
In reply to Zhao LiuThe .wraplock file is automatically generated by meson v1.9.0 (the related issue: https://github.com/mesonbuild/meson/issues/14948).
Ignore it for now.
--- subprojects/.gitignore | 3 +++ 1 file changed, 3 insertions(+)
subprojects/.gitignore +3 -0
@@ -20,3 +20,6 @@ /quote-1.0.36 /syn-2.0.104 /unicode-ident-1.0.12 + +# Workaround for Meson v1.9.0 https://github.com/mesonbuild/meson/issues/14948 +/.wraplock
Signature · 1 line
2.34.1
Re: [PATCH 02/12] subprojects: Ignore .wraplock file generated by meson v1.9.0
Quoted 8 lines · Zhao Liu
The .wraplock file is automatically generated by meson v1.9.0 (the related issue: https://github.com/mesonbuild/meson/issues/14948).
Ignore it for now.
Signed-off-by Zhao Liu <[email protected]>---
Quoted 17 lines
subprojects/.gitignore | 3 +++ 1 file changed, 3 insertions(+)subprojects/.gitignore +3
-1@@ -20,3 +20,6 @@ /quote-1.0.36 /syn-2.0.104 /unicode-ident-1.0.12 + +# Workaround for Meson v1.9.0 https://github.com/mesonbuild/meson/issues/14948 +/.wraplock --2.34.1
PATCH 3/12 rust/qemu-macros: Fix Clippy's complaints about lambda parameter naming
In reply to Zhao Liuerror: rename shadows a previous, unrelated binding
--> qemu-macros/src/lib.rs:265:14
|
265 | |rename| -> Result<proc_macro2::TokenStream, Error> {
| ^^^^^^
|
note: previous binding is here
--> qemu-macros/src/lib.rs:245:30
|
245 | let DeviceProperty { rename, defval } = prop;
| ^^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#shadow_unrelated
= note: requested on the command line with -D clippy::shadow-unrelated
Rename the lambda parameter to "prop_rename" to fix the above clippy error.
--- rust/qemu-macros/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
rust/qemu-macros/src/lib.rs +2 -2
@@ -262,8 +262,8 @@ macro_rules! str_to_c_str { let prop_name = rename.map_or_else( || str_to_c_str!(field_name.to_string(), field_name.span()), - |rename| -> Result<proc_macro2::TokenStream, Error> { - match rename { + |prop_rename| -> Result<proc_macro2::TokenStream, Error> { + match prop_rename { DevicePropertyName::CStr(cstr_lit) => Ok(quote! { #cstr_lit }), DevicePropertyName::Str(str_lit) => { str_to_c_str!(str_lit.value(), str_lit.span())
Signature · 1 line
2.34.1
Re: [PATCH 03/12] rust/qemu-macros: Fix Clippy's complaints about lambda parameter naming
Quoted 12 lines · Zhao Liu
error:
renameshadows a previous, unrelated binding
-->qemu-macros/src/lib.rs:265:14| 265 | |rename| -> Result<proc_macro2::TokenStream, Error> { | ^^^^^^ | note: previous binding is here --> qemu-macros/src/lib.rs:245:30 | 245 | let DeviceProperty { rename, defval } = prop; | ^^^^^^
Quoted 8 lines
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#shadow_unrelated
= note: requested on the command line with-D clippy::shadow-unrelatedRename the lambda parameter to "
prop_rename" to fix the above clippy error.Signed-off-by Zhao Liu <[email protected]>---
Quoted 21 lines
rust/qemu-macros/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)rust/qemu-macros/src/lib.rs +2
-3@@ -262,8 +262,8 @@ macro_rules! str_to_c_str { let prop_name = rename.map_or_else( || str_to_c_str!(field_name.to_string(), field_name.span()), - |rename| -> Result<proc_macro2::TokenStream, Error> { - match rename { + |prop_rename| -> Result<proc_macro2::TokenStream, Error> { + match prop_rename { DevicePropertyName::CStr(cstr_lit) => Ok(quote! { #cstr_lit }), DevicePropertyName::Str(str_lit) => { str_to_c_str!(str_lit.value(), str_lit.span()) --2.34.1
PATCH 4/12 rust/common/uninit: Fix Clippy's complaints about lifetime
In reply to Zhao LiuClippy complains about the following cases and following its suggestion to fix these warnings.
warning: the following explicit lifetimes could be elided: 'a
--> common/src/uninit.rs:38:6
|
38 | impl<'a, T, U> Deref for MaybeUninitField<'a, T, U> {
| ^^ ^^
| = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
= note: #[warn(clippy::needless_lifetimes)] on by default
help: elide the lifetimes
|
38 - impl<'a, T, U> Deref for MaybeUninitField<'a, T, U> {
38 + impl<T, U> Deref for MaybeUninitField<'_, T, U> {
|
warning: the following explicit lifetimes could be elided: 'a
--> common/src/uninit.rs:49:6
|
49 | impl<'a, T, U> DerefMut for MaybeUninitField<'a, T, U> {
| ^^ ^^
| = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
help: elide the lifetimes
|
49 - impl<'a, T, U> DerefMut for MaybeUninitField<'a, T, U> {
49 + impl<T, U> DerefMut for MaybeUninitField<'_, T, U> {
|
warning: common (lib) generated 2 warnings (run cargo clippy --fix --lib -p common to apply 2 suggestions)
--- rust/common/src/uninit.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
rust/common/src/uninit.rs +2 -2
@@ -35,7 +35,7 @@ pub const fn parent_mut(f: &mut Self) -> *mut T { } } -impl <'a,T ,U >Deref for MaybeUninitField <'a,T ,U > { +impl <T ,U >Deref for MaybeUninitField <'_,T ,U > {type Target =MaybeUninit <U >;fn deref (&self) -> &MaybeUninit <U > {
@@ -46,7 +46,7 @@ fn deref(&self) -> &MaybeUninit<U> { } } -impl <'a,T ,U >DerefMut for MaybeUninitField <'a,T ,U > { +impl <T ,U >DerefMut for MaybeUninitField <'_,T ,U > {fn deref_mut (&mut self) -> &mut MaybeUninit <U > {// SAFETY: self.child was obtained by dereferencing a valid mutable // reference; the content of the memory may be invalid or uninitialized
Signature · 1 line
2.34.1
Re: [PATCH 04/12] rust/common/uninit: Fix Clippy's complaints about lifetime
Quoted 28 lines · Zhao Liu
Clippy complains about the following cases and following its suggestion to fix these warnings.
warning: the following explicit lifetimes could be elided: 'a
-->common/src/uninit.rs:38:6| 38 | impl<'a, T, U> Deref for MaybeUninitField<'a, T, U> { | ^^ ^^ |= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
= note:#[warn(clippy::needless_lifetimes)]on by default
help: elide the lifetimes
|
38 - impl<'a, T, U> Deref for MaybeUninitField<'a, T, U> {38 + impl<T, U> Deref for MaybeUninitField<'_, T, U> { |warning: the following explicit lifetimes could be elided: 'a
-->common/src/uninit.rs:49:6| 49 | impl<'a, T, U> DerefMut for MaybeUninitField<'a, T, U> { | ^^ ^^ |= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
help: elide the lifetimes
|
49 - impl<'a, T, U> DerefMut for MaybeUninitField<'a, T, U> {
Quoted 7 lines
49 + impl<T, U> DerefMut for MaybeUninitField<'_, T, U> { |warning:
common(lib) generated 2 warnings (runcargo clippy --fix --lib -p commonto apply 2 suggestions)Signed-off-by Zhao Liu <[email protected]>---
Quoted 28 lines
rust/common/src/uninit.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)rust/common/src/uninit.rs +2
-3@@ -35,7 +35,7 @@ pub const fn parent_mut(f: &mut Self) -> *mut T { } } -impl <'a,T ,U >Deref for MaybeUninitField <'a,T ,U > { +impl <T ,U >Deref for MaybeUninitField <'_,T ,U > {type Target =MaybeUninit <U >;fn deref (&self) -> &MaybeUninit <U > {@@ -46,7 +46,7 @@ fn deref(&self) -> &MaybeUninit<U> { } } -impl <'a,T ,U >DerefMut for MaybeUninitField <'a,T ,U > { +impl <T ,U >DerefMut for MaybeUninitField <'_,T ,U > {fn deref_mut (&mut self) -> &mut MaybeUninit <U > {// SAFETY: self.child was obtained by dereferencing a valid mutable // reference; the content of the memory may be invalid or uninitialized --2.34.1
PATCH 5/12 rust/qdev: use addr_of! in QDevProp
In reply to Zhao LiuFrom: Manos Pitsidianakis <[email protected]>
We want a &raw pointer, so unsafe { &_ } is not needed.
--- rust/hw/core/src/qdev.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
rust/hw/core/src/qdev.rs +4 -4
@@ -6,7 +6,7 @@use std::{ ffi::{c_int, c_void,CStr ,CString }, - ptr::NonNull , + ptr::{addr_of,NonNull }, };use chardev::Chardev ;
@@ -129,17 +129,17 @@ pub unsafe trait QDevProp {/// Use [`bindings::qdev_prop_bool`] for `bool`. unsafe impl QDevProp for bool { -const VALUE : *const bindings::PropertyInfo =unsafe { &bindings::qdev_prop_bool }; +const VALUE : *const bindings::PropertyInfo =addr_of! (bindings::qdev_prop_bool); }/// Use [`bindings::qdev_prop_uint64`] for `u64`. unsafe impl QDevProp for u64 { -const VALUE : *const bindings::PropertyInfo =unsafe { &bindings::qdev_prop_uint64 }; +const VALUE : *const bindings::PropertyInfo =addr_of! (bindings::qdev_prop_uint64); }/// Use [`bindings::qdev_prop_chr`] for [`chardev::CharBackend`]. unsafe impl QDevProp for chardev::CharBackend { -const VALUE : *const bindings::PropertyInfo =unsafe { &bindings::qdev_prop_chr }; +const VALUE : *const bindings::PropertyInfo =addr_of! (bindings::qdev_prop_chr); }/// Trait to define device properties.
Signature · 1 line
2.34.1
PATCH 6/12 rust/qdev: Refine the documentation for QDevProp trait
In reply to Zhao LiuFrom: Manos Pitsidianakis <[email protected]>
Refine the documentation to clarify:
* unsfae requires that VALUE must be valid.
* using *const instead of & because the latter will cause compiler error.
--- rust/hw/core/src/qdev.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
rust/hw/core/src/qdev.rs +11 -4
@@ -109,9 +109,16 @@ pub trait ResettablePhasesImpl {/// /// # Safety /// -/// This trait is marked as `unsafe` because currently having a `const` refer to -/// an `extern static` as a reference instead of a raw pointer results in this -/// compiler error: +/// This trait is marked as `unsafe` because `VALUE` must be a valid raw +/// reference to a [`bindings::PropertyInfo`]. +/// +/// Note we could not use a regular reference: +/// +/// ```text +/// const VALUE: &bindings::PropertyInfo = ... +/// ``` +/// +/// because this results in the following compiler error: /// /// ```text /// constructing invalid value: encountered reference to `extern` static in `const`
@@ -119,7 +126,7 @@ pub trait ResettablePhasesImpl {/// /// This is because the compiler generally might dereference a normal reference /// during const evaluation, but not in this case (if it did, it'd need to -/// dereference the raw pointer so this would fail to compile). +/// dereference the raw pointer so using a `*const` would also fail to compile). /// /// It is the implementer's responsibility to provide a valid /// [`bindings::PropertyInfo`] pointer for the trait implementation to be safe.
Signature · 1 line
2.34.1
PATCH 7/12 rust/qdev: Rename PropertyInfo field from VALUE to BASE_INFO
In reply to Zhao LiuBit property info will added next. To distinguish different info fields, rename VALUE to BASE_INFO, then it can better reflect that it represents the basic property info.
--- rust/hw/core/src/qdev.rs | 12 ++++++------ rust/qemu-macros/src/lib.rs | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-)
rust/hw/core/src/qdev.rs +6 -6
@@ -109,13 +109,13 @@ pub trait ResettablePhasesImpl {/// /// # Safety /// -/// This trait is marked as `unsafe` because `VALUE` must be a valid raw +/// This trait is marked as `unsafe` because `BASE_INFO` must be a valid raw /// reference to a [`bindings::PropertyInfo`]. /// /// Note we could not use a regular reference: /// /// ```text -/// const VALUE: &bindings::PropertyInfo = ... +/// const BASE_INFO: &bindings::PropertyInfo = ... /// ``` /// /// because this results in the following compiler error:
@@ -131,22 +131,22 @@ pub trait ResettablePhasesImpl {/// It is the implementer's responsibility to provide a valid /// [`bindings::PropertyInfo`] pointer for the trait implementation to be safe. pub unsafe trait QDevProp { -const VALUE : *const bindings::PropertyInfo ; +const BASE_INFO : *const bindings::PropertyInfo ; }/// Use [`bindings::qdev_prop_bool`] for `bool`. unsafe impl QDevProp for bool { -const VALUE : *const bindings::PropertyInfo =addr_of! (bindings::qdev_prop_bool); +const BASE_INFO : *const bindings::PropertyInfo =addr_of! (bindings::qdev_prop_bool); }/// Use [`bindings::qdev_prop_uint64`] for `u64`. unsafe impl QDevProp for u64 { -const VALUE : *const bindings::PropertyInfo =addr_of! (bindings::qdev_prop_uint64); +const BASE_INFO : *const bindings::PropertyInfo =addr_of! (bindings::qdev_prop_uint64); }/// Use [`bindings::qdev_prop_chr`] for [`chardev::CharBackend`]. unsafe impl QDevProp for chardev::CharBackend { -const VALUE : *const bindings::PropertyInfo =addr_of! (bindings::qdev_prop_chr); +const BASE_INFO : *const bindings::PropertyInfo =addr_of! (bindings::qdev_prop_chr); }/// Trait to define device properties.
rust/qemu-macros/src/lib.rs +1 -1
@@ -272,7 +272,7 @@ macro_rules! str_to_c_str { }, )?;let field_ty = field.ty.clone (); -let qdev_prop =quote! { <#field_ty as ::hwcore::QDevProp >::VALUE }; +let qdev_prop =quote! { <#field_ty as ::hwcore::QDevProp >::BASE_INFO };let set_default = defval.is_some ();let defval = defval.unwrap_or (syn::Expr ::Verbatim (quote! {0 })); properties_expanded.push (quote! {
Signature · 1 line
2.34.1
Re: [PATCH 07/12] rust/qdev: Rename PropertyInfo field from VALUE to BASE_INFO
Quoted 7 lines · Zhao Liu
Bit property info will added next. To distinguish different info fields, rename
VALUEtoBASE_INFO, then it can better reflect that it represents the basic property info.Signed-off-by Zhao Liu <[email protected]>---
You can squash this patch to the bit info one
Quoted 67 lines
rust/hw/core/src/qdev.rs | 12 ++++++------ rust/qemu-macros/src/lib.rs | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-)rust/hw/core/src/qdev.rs +6
-6@@ -109,13 +109,13 @@ pub trait ResettablePhasesImpl {/// /// # Safety /// -/// This trait is marked as `unsafe` because `VALUE` must be a valid raw +/// This trait is marked as `unsafe` because `BASE_INFO` must be a valid raw /// reference to a [`bindings::PropertyInfo`]. /// /// Note we could not use a regular reference: /// /// ```text -/// const VALUE: &bindings::PropertyInfo = ... +/// const BASE_INFO: &bindings::PropertyInfo = ... /// ``` /// /// because this results in the following compiler error: @@ -131,22 +131,22 @@ pub trait ResettablePhasesImpl {/// It is the implementer's responsibility to provide a valid /// [`bindings::PropertyInfo`] pointer for the trait implementation to be safe. pub unsafe trait QDevProp { -const VALUE : *const bindings::PropertyInfo ; +const BASE_INFO : *const bindings::PropertyInfo ; }/// Use [`bindings::qdev_prop_bool`] for `bool`. unsafe impl QDevProp for bool { -const VALUE : *const bindings::PropertyInfo =addr_of! (bindings::qdev_prop_bool); +const BASE_INFO : *const bindings::PropertyInfo =addr_of! (bindings::qdev_prop_bool); }/// Use [`bindings::qdev_prop_uint64`] for `u64`. unsafe impl QDevProp for u64 { -const VALUE : *const bindings::PropertyInfo =addr_of! (bindings::qdev_prop_uint64); +const BASE_INFO : *const bindings::PropertyInfo =addr_of! (bindings::qdev_prop_uint64); }/// Use [`bindings::qdev_prop_chr`] for [`chardev::CharBackend`]. unsafe impl QDevProp for chardev::CharBackend { -const VALUE : *const bindings::PropertyInfo =addr_of! (bindings::qdev_prop_chr); +const BASE_INFO : *const bindings::PropertyInfo =addr_of! (bindings::qdev_prop_chr); }/// Trait to define device properties. rust/qemu-macros/src/lib.rs +1
-2@@ -272,7 +272,7 @@ macro_rules! str_to_c_str { }, )?;let field_ty = field.ty.clone (); -let qdev_prop =quote! { <#field_ty as ::hwcore::QDevProp >::VALUE }; +let qdev_prop =quote! { <#field_ty as ::hwcore::QDevProp >::BASE_INFO };let set_default = defval.is_some ();let defval = defval.unwrap_or (syn::Expr ::Verbatim (quote! {0 })); properties_expanded.push (quote! { --2.34.1
Re: [PATCH 07/12] rust/qdev: Rename PropertyInfo field from VALUE to BASE_INFO
Quoted 7 lines · Manos Pitsidianakis
Date: Tue, 16 Sep 2025 13:10:39 +0300
From: Manos Pitsidianakis <[email protected]>
Subject: Re: [PATCH 07/12]rust/qdev: Rename PropertyInfo field from VALUE
toBASE_INFOQuoted 1 line · Zhao Liu
Quoted 8 lines
Quoted 6 lines
Bit property info will added next. To distinguish different info fields, rename
VALUEtoBASE_INFO, then it can better reflect that it represents the basic property info.Signed-off-by Zhao Liu <[email protected]>---
Reviewed-by Manos Pitsidianakis <[email protected]>
Thanks!
Quoted 1 line
You can squash this patch to the bit info one
Yes, after patch 8, renaming doesn't need to change too many places.
Regards,
Zhao
PATCH 8/12 rust/qdev: Support property info for more common types
In reply to Zhao LiuAdd a helper macro to implement QDevProp trait for u8/u16/u32/usize/i32 /i64.
--- rust/hw/core/src/qdev.rs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)
rust/hw/core/src/qdev.rs +16 -12
@@ -134,20 +134,24 @@ pub unsafe trait QDevProp {const BASE_INFO : *const bindings::PropertyInfo ; } -/// Use [`bindings::qdev_prop_bool`] for `bool`. -unsafe impl QDevProp for bool { -const BASE_INFO : *const bindings::PropertyInfo =addr_of! (bindings::qdev_prop_bool); -} - -/// Use [`bindings::qdev_prop_uint64`] for `u64`. -unsafe impl QDevProp for u64 { -const BASE_INFO : *const bindings::PropertyInfo =addr_of! (bindings::qdev_prop_uint64); +macro_rules! impl_qdev_prop { + ($type:ty,$info:ident) => { +unsafe impl $crate::qdev::QDevProp for $type { +const BASE_INFO : *const $crate::bindings::PropertyInfo = +addr_of! ($crate ::bindings::$info); + } + }; } -/// Use [`bindings::qdev_prop_chr`] for [`chardev::CharBackend`]. -unsafe impl QDevProp for chardev::CharBackend { -const BASE_INFO : *const bindings::PropertyInfo =addr_of! (bindings::qdev_prop_chr); -} +impl_qdev_prop! (bool , qdev_prop_bool); +impl_qdev_prop! (u8 , qdev_prop_uint8); +impl_qdev_prop! (u16 , qdev_prop_uint16); +impl_qdev_prop! (u32 , qdev_prop_uint32); +impl_qdev_prop! (u64 , qdev_prop_uint64); +impl_qdev_prop! (usize , qdev_prop_usize); +impl_qdev_prop! (i32 , qdev_prop_int32); +impl_qdev_prop! (i64 , qdev_prop_int64); +impl_qdev_prop! (chardev::CharBackend , qdev_prop_chr);/// Trait to define device properties. ///
Signature · 1 line
2.34.1
Re: [PATCH 08/12] rust/qdev: Support property info for more common types
Quoted 6 lines · Zhao Liu
Add a helper macro to implement QDevProp trait for u8/u16/u32/usize/i32 /i64.
Signed-off-by Zhao Liu <[email protected]>---
You can do something like this btw:
macro_rules! impl_qdev_prop {
($($type:ty => $info:ident),*$(,)?) => {
$(unsafe impl $crate::qdev::QDevProp for $type {
const BASE_INFO: *const $crate::bindings::PropertyInfo =
addr_of!($crate::bindings::$info);
})*
};}
impl_qdev_prop!(
bool => qdev_prop_bool,
u8 => qdev_prop_uint8,
...);
Quoted 47 lines
rust/hw/core/src/qdev.rs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)rust/hw/core/src/qdev.rs +16
-13@@ -134,20 +134,24 @@ pub unsafe trait QDevProp {const BASE_INFO : *const bindings::PropertyInfo ; } -/// Use [`bindings::qdev_prop_bool`] for `bool`. -unsafe impl QDevProp for bool { -const BASE_INFO : *const bindings::PropertyInfo =addr_of! (bindings::qdev_prop_bool); -} - -/// Use [`bindings::qdev_prop_uint64`] for `u64`. -unsafe impl QDevProp for u64 { -const BASE_INFO : *const bindings::PropertyInfo =addr_of! (bindings::qdev_prop_uint64); +macro_rules! impl_qdev_prop { + ($type:ty,$info:ident) => { +unsafe impl $crate::qdev::QDevProp for $type { +const BASE_INFO : *const $crate::bindings::PropertyInfo = +addr_of! ($crate ::bindings::$info); + } + }; } -/// Use [`bindings::qdev_prop_chr`] for [`chardev::CharBackend`]. -unsafe impl QDevProp for chardev::CharBackend { -const BASE_INFO : *const bindings::PropertyInfo =addr_of! (bindings::qdev_prop_chr); -} +impl_qdev_prop! (bool , qdev_prop_bool); +impl_qdev_prop! (u8 , qdev_prop_uint8); +impl_qdev_prop! (u16 , qdev_prop_uint16); +impl_qdev_prop! (u32 , qdev_prop_uint32); +impl_qdev_prop! (u64 , qdev_prop_uint64); +impl_qdev_prop! (usize , qdev_prop_usize); +impl_qdev_prop! (i32 , qdev_prop_int32); +impl_qdev_prop! (i64 , qdev_prop_int64); +impl_qdev_prop! (chardev::CharBackend , qdev_prop_chr);/// Trait to define device properties. /// --2.34.1
Re: [PATCH 08/12] rust/qdev: Support property info for more common types
Quoted 7 lines · Manos Pitsidianakis
Date: Tue, 16 Sep 2025 13:13:28 +0300
From: Manos Pitsidianakis <[email protected]>
Subject: Re: [PATCH 08/12]rust/qdev: Support property info for more common
typesQuoted 1 line · Zhao Liu
Quoted 7 lines
Quoted 5 lines
Add a helper macro to implement QDevProp trait for u8/u16/u32/usize/i32 /i64.
Signed-off-by Zhao Liu <[email protected]>---
Reviewed-by Manos Pitsidianakis <[email protected]>
Thanks!
Quoted 9 lines
You can do something like this btw:
macro_rules! impl_qdev_prop { ($($type:ty => $info:ident),*$(,)?) => { $(unsafe impl $crate::qdev::QDevProp for $type { const BASE_INFO: *const $crate::bindings::PropertyInfo = addr_of!($crate::bindings::$info); })* };
Quoted 8 lines
}
impl_qdev_prop!(
bool => qdev_prop_bool, u8 => qdev_prop_uint8, ...);
Yes, this can work! But a benefit of non-repetitive macro is that it can also be exposed for use by other crates if necessary.
Regards,
Zhao
PATCH 9/12 rust/qdev: Support bit property in #property macro
In reply to Zhao LiuAdd BIT_INFO to QDevProp trait, so that bit related property info could be bound to u32 & u64.
Then add "bit=*" field in #property attributes macro to allow device to configure bit property.
In addtion, convert the #property field parsing from if-else pattern to match pattern, to help readability. And note, the bitnr member of Property struct is generated by manual TokenStream construction, instead of conditional repetition (like #(bitnr: #bitnr,)?) since quote doesn't support this.
--- rust/hw/core/src/qdev.rs | 15 +++++--- rust/qemu-macros/src/lib.rs | 77 +++++++++++++++++++++++++------------ 2 files changed, 62 insertions(+), 30 deletions(-)
rust/hw/core/src/qdev.rs +10 -5
@@ -109,8 +109,8 @@ pub trait ResettablePhasesImpl {/// /// # Safety /// -/// This trait is marked as `unsafe` because `BASE_INFO` must be a valid raw -/// reference to a [`bindings::PropertyInfo`]. +/// This trait is marked as `unsafe` because `BASE_INFO` and `BIT_INFO` must be +/// the valid raw references to [`bindings::PropertyInfo`]. /// /// Note we could not use a regular reference: ///
@@ -132,13 +132,18 @@ pub trait ResettablePhasesImpl {/// [`bindings::PropertyInfo`] pointer for the trait implementation to be safe. pub unsafe trait QDevProp {const BASE_INFO : *const bindings::PropertyInfo ; +const BIT_INFO : *const bindings::PropertyInfo = { +panic! ("invalid type for bit property" ); + }; }macro_rules! impl_qdev_prop { - ($type:ty,$info:ident) => { + ($type:ty,$info:ident$(, $bit_info:ident)?) => {unsafe impl $crate::qdev::QDevProp for $type {const BASE_INFO : *const $crate::bindings::PropertyInfo =addr_of! ($crate ::bindings::$info); + $(const BIT_INFO : *const $crate::bindings::PropertyInfo = +addr_of! ($crate ::bindings::$bit_info);)? } }; }
@@ -146,8 +151,8 @@ unsafe impl $crate::qdev::QDevProp for $type {impl_qdev_prop! (bool , qdev_prop_bool);impl_qdev_prop! (u8 , qdev_prop_uint8);impl_qdev_prop! (u16 , qdev_prop_uint16); -impl_qdev_prop! (u32 , qdev_prop_uint32); -impl_qdev_prop! (u64 , qdev_prop_uint64); +impl_qdev_prop! (u32 , qdev_prop_uint32, qdev_prop_bit); +impl_qdev_prop! (u64 , qdev_prop_uint64, qdev_prop_bit64);impl_qdev_prop! (usize , qdev_prop_usize);impl_qdev_prop! (i32 , qdev_prop_int32);impl_qdev_prop! (i64 , qdev_prop_int64);
rust/qemu-macros/src/lib.rs +52 -25
119 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH 09/12] rust/qdev: Support bit property in #property macro
Quoted 24 lines · Zhao Liu
Add
BIT_INFOto QDevProp trait, so that bit related property info could be bound to u32 & u64.Then add "bit=*" field in #property attributes macro to allow device to configure bit property.
In addtion, convert the #property field parsing from
if-elsepattern tomatchpattern, to help readability. And note, thebitnrmember ofPropertystruct is generated by manual TokenStream construction, instead of conditional repetition (like #(bitnr: #bitnr,)?) sincequotedoesn't support this.Signed-off-by Zhao Liu <[email protected]>--- rust/hw/core/src/qdev.rs | 15 +++++--- rust/qemu-macros/src/lib.rs | 77 +++++++++++++++++++++++++------------ 2 files changed, 62 insertions(+), 30 deletions(-)rust/hw/core/src/qdev.rs +0
-0
rust/hw/core/src/qdev.rs pub trait ResettablePhasesImpl { · line 113
Quoted 7 lines
rust/hw/core/src/qdev.rs +2
-2@@ -109,8 +109,8 @@ pub trait ResettablePhasesImpl {/// /// # Safety /// -/// This trait is marked as `unsafe` because `BASE_INFO` must be a valid raw -/// reference to a [`bindings::PropertyInfo`]. +/// This trait is marked as `unsafe` because `BASE_INFO` and `BIT_INFO` must be +/// the valid raw references to [`bindings::PropertyInfo`].
s/the //
rust/hw/core/src/qdev.rs pub trait ResettablePhasesImpl { · line 137
Quoted 10 lines
rust/hw/core/src/qdev.rs +3
-0/// /// Note we could not use a regular reference: /// @@ -132,13 +132,18 @@ pub trait ResettablePhasesImpl {/// [`bindings::PropertyInfo`] pointer for the trait implementation to be safe. pub unsafe trait QDevProp {const BASE_INFO : *const bindings::PropertyInfo ; +const BIT_INFO : *const bindings::PropertyInfo = { +panic! ("invalid type for bit property" ); + };
Why is this needed?
Quoted 154 lines
rust/hw/core/src/qdev.rs +5
-3}macro_rules! impl_qdev_prop { - ($type:ty,$info:ident) => { + ($type:ty,$info:ident$(, $bit_info:ident)?) => {unsafe impl $crate::qdev::QDevProp for $type {const BASE_INFO : *const $crate::bindings::PropertyInfo =addr_of! ($crate ::bindings::$info); + $(const BIT_INFO : *const $crate::bindings::PropertyInfo = +addr_of! ($crate ::bindings::$bit_info);)? } }; }@@ -146,8 +151,8 @@ unsafe impl $crate::qdev::QDevProp for $type {impl_qdev_prop! (bool , qdev_prop_bool);impl_qdev_prop! (u8 , qdev_prop_uint8);impl_qdev_prop! (u16 , qdev_prop_uint16); -impl_qdev_prop! (u32 , qdev_prop_uint32); -impl_qdev_prop! (u64 , qdev_prop_uint64); +impl_qdev_prop! (u32 , qdev_prop_uint32, qdev_prop_bit); +impl_qdev_prop! (u64 , qdev_prop_uint64, qdev_prop_bit64);impl_qdev_prop! (usize , qdev_prop_usize);impl_qdev_prop! (i32 , qdev_prop_int32);impl_qdev_prop! (i64 , qdev_prop_int64);rust/qemu-macros/src/lib.rs +52
-26@@ -162,6 +162,7 @@ enum DevicePropertyName {#[derive( Debug )] struct DeviceProperty { rename:Option <DevicePropertyName >, + bitnr:Option <syn::Expr >, defval:Option <syn::Expr >, }@@ -174,40 +175,56 @@ fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {debug_assert_eq! (&attribute.to_string (),"property" );let mut retval =Self { rename:None , + bitnr:None , defval:None , };let content; _ = syn::parenthesized!(content in bracketed);while !content.is_empty () {let value: syn::Ident = content.parse ()?; -if value =="rename" { -let _: syn::Token ![=] = content.parse ()?; -if retval.rename.is_some () { -return Err (syn::Error ::new ( - value.span (), -"`rename` can only be used at most once" , - )); +match value { +ref vif v =="rename" => { +let _: syn::Token ![=] = content.parse ()?; +if retval.rename.is_some () { +return Err (syn::Error ::new ( + value.span (), +"`rename` can only be used at most once" , + )); + } +if content.peek (syn::LitStr ) { + retval.rename = +Some (DevicePropertyName ::Str (content.parse ::<syn::LitStr >()?)); + }else { + retval.rename = +Some (DevicePropertyName ::CStr (content.parse ::<syn::LitCStr >()?)); + } } -if content.peek (syn::LitStr ) { - retval.rename =Some (DevicePropertyName ::Str (content.parse ::<syn::LitStr >()?)); - }else { - retval.rename = -Some (DevicePropertyName ::CStr (content.parse ::<syn::LitCStr >()?)); +ref vif v =="bit" => { +let _: syn::Token ![=] = content.parse ()?; +if retval.bitnr.is_some () { +return Err (syn::Error ::new ( + value.span (), +"`bit` can only be used at most once" , + )); + } + retval.bitnr =Some (content.parse ()?); + } +ref vif v =="default" => { +let _: syn::Token ![=] = content.parse ()?; +if retval.defval.is_some () { +return Err (syn::Error ::new ( + value.span (), +"`default` can only be used at most once" , + )); + } + retval.defval =Some (content.parse ()?); } - }else if value =="default" { -let _: syn::Token ![=] = content.parse ()?; -if retval.defval.is_some () { + _ => {return Err (syn::Error ::new ( value.span (), -"`default` can only be used at most once" , +format! ("unrecognized field `{value}`" ), )); } - retval.defval =Some (content.parse ()?); - }else { -return Err (syn::Error ::new ( - value.span (), -format! ("unrecognized field `{value}`" ), - )); }if !content.is_empty () {@@ -242,7 +259,11 @@ fn derive_device_or_error(input: DeriveInput) -> Result<proc_macro2::TokenStreamlet mut properties_expanded =vec! [];for (field, prop)in properties { -let DeviceProperty { rename, defval } = prop; +let DeviceProperty { + rename, + bitnr, + defval, + } = prop;let field_name = field.ident.unwrap ();macro_rules! str_to_c_str { ($value:expr, $span:expr) => {{@@ -272,14 +293,20 @@ macro_rules! str_to_c_str { }, )?;let field_ty = field.ty.clone (); -let qdev_prop =quote! { <#field_ty as ::hwcore::QDevProp >::BASE_INFO }; +let qdev_prop =if bitnr.is_none () { +quote! { <#field_ty as ::hwcore::QDevProp >::BASE_INFO } + }else { +quote! { <#field_ty as ::hwcore::QDevProp >::BIT_INFO } + }; +let bitnr = bitnr.unwrap_or (syn::Expr ::Verbatim (quote! {0 }));let set_default = defval.is_some ();let defval = defval.unwrap_or (syn::Expr ::Verbatim (quote! {0 })); properties_expanded.push (quote! { ::hwcore::bindings::Property { name: ::std::ffi::CStr ::as_ptr (#prop_name), - info: #qdev_prop , + info: #qdev_prop, offset: ::core::mem::offset_of!(#name, #field_name)as isize , + bitnr: #bitnr, set_default: #set_default, defval: ::hwcore::bindings::Property__bindgen_ty_1 { u: #defvalas u64 }, ..::common::Zeroable ::ZERO --2.34.1
Re: [PATCH 09/12] rust/qdev: Support bit property in #property macro
Quoted 25 lines · Manos Pitsidianakis
Date: Tue, 16 Sep 2025 13:16:25 +0300
From: Manos Pitsidianakis <[email protected]>
Subject: Re: [PATCH 09/12]rust/qdev: Support bit property in #property
macroQuoted 19 lines · Zhao Liu
Add
BIT_INFOto QDevProp trait, so that bit related property info could be bound to u32 & u64.Then add "bit=*" field in #property attributes macro to allow device to configure bit property.
In addtion, convert the #property field parsing from
if-elsepattern tomatchpattern, to help readability. And note, thebitnrmember ofPropertystruct is generated by manual TokenStream construction, instead of conditional repetition (like #(bitnr: #bitnr,)?) sincequotedoesn't support this.Signed-off-by Zhao Liu <[email protected]>--- rust/hw/core/src/qdev.rs | 15 +++++--- rust/qemu-macros/src/lib.rs | 77 +++++++++++++++++++++++++------------ 2 files changed, 62 insertions(+), 30 deletions(-)
Quoted 14 lines
rust/hw/core/src/qdev.rs pub trait ResettablePhasesImpl { · line 113
Quoted 12 lines
rust/hw/core/src/qdev.rs +2
-2@@ -109,8 +109,8 @@ pub trait ResettablePhasesImpl {/// /// # Safety /// -/// This trait is marked as `unsafe` because `BASE_INFO` must be a valid raw -/// reference to a [`bindings::PropertyInfo`]. +/// This trait is marked as `unsafe` because `BASE_INFO` and `BIT_INFO` must be +/// the valid raw references to [`bindings::PropertyInfo`]. s/the //
Okay.
Quoted 4 lines
Quoted 4 lines
rust/hw/core/src/qdev.rs +0
-0/// /// Note we could not use a regular reference: /// @@ -132,13 +132,18 @@ pub trait ResettablePhasesImpl {
Quoted 8 lines
rust/hw/core/src/qdev.rs pub trait ResettablePhasesImpl { · line 137
Quoted 6 lines
rust/hw/core/src/qdev.rs +3
-0/// [`bindings::PropertyInfo`] pointer for the trait implementation to be safe. pub unsafe trait QDevProp {const BASE_INFO : *const bindings::PropertyInfo ; +const BIT_INFO : *const bindings::PropertyInfo = { +panic! ("invalid type for bit property" ); + };Why is this needed?
Only 3 types supports bit:
u32: qdev_prop_bit
u64: qdev_prop_bit64
OnOffAuto: qdev_prop_on_off_auto_bit64 (not support yet)
So for other types don't support bit, they need default BIT_INFO item, otherwise, we will meet the error:
not all trait items implemented, missing: BIT_INFO
And this panic can provide richer info about why a type can't support bit property. (I just refer the implementation of trait VMState).
Thanks,
Zhao
Re: [PATCH 09/12] rust/qdev: Support bit property in #property macro
Quoted 5 lines · Zhao Liu
Only 3 types supports bit:
u32:
qdev_prop_bit
u64:qdev_prop_bit64
OnOffAuto:qdev_prop_on_off_auto_bit64(not support yet)
Yes, this one needs to wait for QAPI (unless we move OnOffAuto to core code).
Quoted 7 lines
So for other types don't support bit, they need default
BIT_INFOitem, otherwise, we will meet the error:not all trait items implemented, missing:
BIT_INFOAnd this panic can provide richer info about why a type can't support bit property. (I just refer the implementation of
trait VMState).
Yep, looks good. I added to rust-next a couple patches that you can rebase on, to use the attrs crate.
Also please add a testcase.
Paolo
Re: [PATCH 09/12] rust/qdev: Support bit property in #property macro
In reply to Zhao LiuQuoted 11 lines · Zhao Liu
Add
BIT_INFOto QDevProp trait, so that bit related property info could be bound to u32 & u64.Then add "bit=*" field in #property attributes macro to allow device to configure bit property.
In addtion, convert the #property field parsing from
if-elsepattern tomatchpattern, to help readability. And note, thebitnrmember ofPropertystruct is generated by manual TokenStream construction, instead of conditional repetition (like #(bitnr: #bitnr,)?) sincequotedoesn't support this.
We're almost certainly going to have more attribute parsing for ToMigrationState, therefore IMO it's time to drop the handwritten parser in favor of https://lore.kernel.org/qemu-devel/[email protected]/.
Then the extra parsing would be just one line:
+ parser.once("bitnr", with::eq(set::parse(&mut self.bitnr)));
No other complaint!
Paolo
PATCH 10/12 rust/hpet: Clean up type mismatch for num_timers property
In reply to Zhao LiuNow num_timers is usize other than u8. Although the type field in declare_properties macro hasn't been used, it's better to explicitly point this out and clean up this before doing other property work.
--- rust/hw/timer/hpet/src/device.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
rust/hw/timer/hpet/src/device.rs +1 -1
@@ -909,7 +909,7 @@ impl ObjectImpl for HPETState { HPETState, num_timers, unsafe { &qdev_prop_usize }, - u8, + usize, default = HPET_MIN_TIMERS ),define_property! (
Signature · 1 line
2.34.1
PATCH 11/12 rust/hpet: Convert qdev properties to #property macro
In reply to Zhao LiuConvert HPET's properties to #property macro:
* num_timers: usize property.
* flags: u32 bit property.
* int_route_cap: u32 property.
* hpet_offset_saved: bool property.
--- rust/hw/timer/hpet/src/device.rs | 55 ++++---------------------------- 1 file changed, 7 insertions(+), 48 deletions(-)
rust/hw/timer/hpet/src/device.rs +7 -48
@@ -13,9 +13,8 @@use bql::{BqlCell ,BqlRefCell };use common::{bitops::IntegerExt , uninit_field_mut};use hwcore::{ - bindings::{qdev_prop_bit, qdev_prop_bool, qdev_prop_uint32, qdev_prop_usize}, - declare_properties, define_property,DeviceImpl ,DeviceMethods ,DeviceState ,InterruptSource , -Property ,ResetType ,ResettablePhasesImpl ,SysBusDevice ,SysBusDeviceImpl ,SysBusDeviceMethods , +DeviceImpl ,DeviceMethods ,DeviceState ,InterruptSource ,ResetType ,ResettablePhasesImpl , +SysBusDevice ,SysBusDeviceImpl ,SysBusDeviceMethods , };use migration::{ self, impl_vmstate_struct, vmstate_fields, vmstate_of, vmstate_subsections, vmstate_validate,
@@ -520,7 +519,7 @@ fn write(&mut self, reg: TimerRegister, value: u64, shift: u32, len: u32) {/// HPET Event Timer Block Abstraction #[repr( C )] -#[derive(qom:: Object )] +#[derive(qom:: Object , hwcore:: Device )] pub struct HPETState { parent_obj:ParentField <SysBusDevice >, iomem:MemoryRegion ,
@@ -540,10 +539,12 @@ pub struct HPETState {// Internal state /// Capabilities that QEMU HPET supports. /// bit 0: MSI (or FSB) support. +#[property(rename = "msi" , bit = HPET_FLAG_MSI_SUPPORT_SHIFT as u8 , default = false )] flags: u32,/// Offset of main counter relative to qemu clock. hpet_offset: BqlCell<u64>, +#[property(rename = "hpet-offset-saved" , default = true )] hpet_offset_saved: bool, irqs: [InterruptSource; HPET_NUM_IRQ_ROUTES],
@@ -555,11 +556,13 @@ pub struct HPETState {/// the timers' interrupt can be routed, and is encoded in the /// bits 32:64 of timer N's config register: #[doc(alias = "intcap" )] +#[property(rename = "hpet-intcap" , default = 0 )] int_route_cap: u32,/// HPET timer array managed by this timer block. #[doc(alias = "timer" )] timers: [BqlRefCell<HPETTimer>; HPET_MAX_TIMERS], +#[property(rename = "timers" , default = HPET_MIN_TIMERS )] num_timers: usize, num_timers_save: BqlCell<u8>,
@@ -901,44 +904,6 @@ impl ObjectImpl for HPETState {const CLASS_INIT :fn (&mut Self ::Class ) =Self ::Class ::class_init ::<Self >; } -// TODO: Make these properties user-configurable! -declare_properties! { -HPET_PROPERTIES , -define_property! ( -c"timers" , -HPETState , - num_timers, -unsafe { &qdev_prop_usize }, -usize , -default =HPET_MIN_TIMERS - ), -define_property! ( -c"msi" , -HPETState , - flags, -unsafe { &qdev_prop_bit }, -u32 , - bit =HPET_FLAG_MSI_SUPPORT_SHIFT as u8 , -default =false , - ), -define_property! ( -c"hpet-intcap" , -HPETState , - int_route_cap, -unsafe { &qdev_prop_uint32 }, -u32 , -default =0 - ), -define_property! ( -c"hpet-offset-saved" , -HPETState , - hpet_offset_saved, -unsafe { &qdev_prop_bool }, -bool , -default =true - ), -} -static VMSTATE_HPET_RTC_IRQ_LEVEL :VMStateDescription <HPETState > =VMStateDescriptionBuilder ::<HPETState >::new () .name (c"hpet/rtc_irq_level" )
@@ -1001,12 +966,6 @@ impl ObjectImpl for HPETState { )) .build(); -// SAFETY: HPET_PROPERTIES is a valid Property array constructed with the -// hwcore::declare_properties macro. -unsafe impl hwcore::DevicePropertiesImpl for HPETState { -const PROPERTIES : &'static [Property ] = &HPET_PROPERTIES ; -} -impl DeviceImpl for HPETState {const VMSTATE :Option <VMStateDescription <Self >> =Some (VMSTATE_HPET );const REALIZE :Option <fn (&Self ) -> util::Result <()>> =Some (Self ::realize);
Signature · 1 line
2.34.1
Re: [PATCH 11/12] rust/hpet: Convert qdev properties to #property macro
Quoted 9 lines · Zhao Liu
Convert HPET's properties to #property macro:
*num_timers: usize property.
* flags: u32 bit property.
*int_route_cap: u32 property.
*hpet_offset_saved: bool property.Signed-off-by Zhao Liu <[email protected]>---
Quoted 116 lines
rust/hw/timer/hpet/src/device.rs | 55 ++++---------------------------- 1 file changed, 7 insertions(+), 48 deletions(-)rust/hw/timer/hpet/src/device.rs +7
-49@@ -13,9 +13,8 @@use bql::{BqlCell ,BqlRefCell };use common::{bitops::IntegerExt , uninit_field_mut};use hwcore::{ - bindings::{qdev_prop_bit, qdev_prop_bool, qdev_prop_uint32, qdev_prop_usize}, - declare_properties, define_property,DeviceImpl ,DeviceMethods ,DeviceState ,InterruptSource , -Property ,ResetType ,ResettablePhasesImpl ,SysBusDevice ,SysBusDeviceImpl ,SysBusDeviceMethods , +DeviceImpl ,DeviceMethods ,DeviceState ,InterruptSource ,ResetType ,ResettablePhasesImpl , +SysBusDevice ,SysBusDeviceImpl ,SysBusDeviceMethods , };use migration::{ self, impl_vmstate_struct, vmstate_fields, vmstate_of, vmstate_subsections, vmstate_validate,@@ -520,7 +519,7 @@ fn write(&mut self, reg: TimerRegister, value: u64, shift: u32, len: u32) {/// HPET Event Timer Block Abstraction #[repr( C )] -#[derive(qom:: Object )] +#[derive(qom:: Object , hwcore:: Device )] pub struct HPETState { parent_obj:ParentField <SysBusDevice >, iomem:MemoryRegion ,@@ -540,10 +539,12 @@ pub struct HPETState {// Internal state /// Capabilities that QEMU HPET supports. /// bit 0: MSI (or FSB) support. +#[property(rename = "msi" , bit = HPET_FLAG_MSI_SUPPORT_SHIFT as u8 , default = false )] flags: u32,/// Offset of main counter relative to qemu clock. hpet_offset: BqlCell<u64>, +#[property(rename = "hpet-offset-saved" , default = true )] hpet_offset_saved: bool, irqs: [InterruptSource; HPET_NUM_IRQ_ROUTES],@@ -555,11 +556,13 @@ pub struct HPETState {/// the timers' interrupt can be routed, and is encoded in the /// bits 32:64 of timer N's config register: #[doc(alias = "intcap" )] +#[property(rename = "hpet-intcap" , default = 0 )] int_route_cap: u32,/// HPET timer array managed by this timer block. #[doc(alias = "timer" )] timers: [BqlRefCell<HPETTimer>; HPET_MAX_TIMERS], +#[property(rename = "timers" , default = HPET_MIN_TIMERS )] num_timers: usize, num_timers_save: BqlCell<u8>,@@ -901,44 +904,6 @@ impl ObjectImpl for HPETState {const CLASS_INIT :fn (&mut Self ::Class ) =Self ::Class ::class_init ::<Self >; } -// TODO: Make these properties user-configurable! -declare_properties! { -HPET_PROPERTIES , -define_property! ( -c"timers" , -HPETState , - num_timers, -unsafe { &qdev_prop_usize }, -usize , -default =HPET_MIN_TIMERS - ), -define_property! ( -c"msi" , -HPETState , - flags, -unsafe { &qdev_prop_bit }, -u32 , - bit =HPET_FLAG_MSI_SUPPORT_SHIFT as u8 , -default =false , - ), -define_property! ( -c"hpet-intcap" , -HPETState , - int_route_cap, -unsafe { &qdev_prop_uint32 }, -u32 , -default =0 - ), -define_property! ( -c"hpet-offset-saved" , -HPETState , - hpet_offset_saved, -unsafe { &qdev_prop_bool }, -bool , -default =true - ), -} -static VMSTATE_HPET_RTC_IRQ_LEVEL :VMStateDescription <HPETState > =VMStateDescriptionBuilder ::<HPETState >::new () .name (c"hpet/rtc_irq_level" )@@ -1001,12 +966,6 @@ impl ObjectImpl for HPETState { )) .build(); -// SAFETY: HPET_PROPERTIES is a valid Property array constructed with the -// hwcore::declare_properties macro. -unsafe impl hwcore::DevicePropertiesImpl for HPETState { -const PROPERTIES : &'static [Property ] = &HPET_PROPERTIES ; -} -impl DeviceImpl for HPETState {const VMSTATE :Option <VMStateDescription <Self >> =Some (VMSTATE_HPET );const REALIZE :Option <fn (&Self ) -> util::Result <()>> =Some (Self ::realize); --2.34.1
PATCH 12/12 rust/qdev: Drop declare_properties & define_property macros
In reply to Zhao LiuAfter HPET's #property conversion, there's no use case for declare_properties & define_property. So get rid of them for now.
In future, if there's something that #property really cannot resolve, they can be brought back.
--- rust/hw/core/src/qdev.rs | 53 ---------------------------------------- 1 file changed, 53 deletions(-)
rust/hw/core/src/qdev.rs +0 -53
@@ -248,59 +248,6 @@ pub fn class_init<T: DeviceImpl>(&mut self) { } } -#[macro_export] -macro_rules! define_property { - ($name:expr, $state:ty, $field:ident, $prop:expr, $type:ty, bit = $bitnr:expr,default = $defval:expr$(,)*) => { - $crate::bindings::Property { -// use associated function syntax for type checking - name: ::std::ffi::CStr ::as_ptr ($name), - info: $prop, - offset: ::std::mem::offset_of!($state, $field)as isize , - bitnr: $bitnr, - set_default:true , - defval: $crate::bindings::Property__bindgen_ty_1 { u: $defvalas u64 }, - ..::common::zeroable::Zeroable ::ZERO - } - }; - ($name:expr, $state:ty, $field:ident, $prop:expr, $type:ty,default = $defval:expr$(,)*) => { - $crate::bindings::Property { -// use associated function syntax for type checking - name: ::std::ffi::CStr ::as_ptr ($name), - info: $prop, - offset: ::std::mem::offset_of!($state, $field)as isize , - set_default:true , - defval: $crate::bindings::Property__bindgen_ty_1 { u: $defvalas u64 }, - ..::common::zeroable::Zeroable ::ZERO - } - }; - ($name:expr, $state:ty, $field:ident, $prop:expr, $type:ty$(,)*) => { - $crate::bindings::Property { -// use associated function syntax for type checking - name: ::std::ffi::CStr ::as_ptr ($name), - info: $prop, - offset: ::std::mem::offset_of!($state, $field)as isize , - set_default:false , - ..::common::zeroable::Zeroable ::ZERO - } - }; -} - -#[macro_export] -macro_rules! declare_properties { - ($ident:ident, $($prop:expr),*$(,)*) => { -pub static $ident: [$crate::bindings::Property ; { -let mut len =0 ; - $({ - _ =stringify! ($prop); - len +=1 ; - })* - len - }] = [ - $($prop),*, - ]; - }; -} -unsafe impl ObjectType for DeviceState {type Class =DeviceClass ; const TYPE_NAME: &'static CStr =
Signature · 1 line
2.34.1
Re: [PATCH 12/12] rust/qdev: Drop declare_properties & define_property macros
Quoted 9 lines · Zhao Liu
After HPET's #property conversion, there's no use case for
declare_properties&define_property. So get rid of them for now.In future, if there's something that #property really cannot resolve, they can be brought back.
Signed-off-by Zhao Liu <[email protected]>---
Quoted 70 lines
rust/hw/core/src/qdev.rs | 53 ---------------------------------------- 1 file changed, 53 deletions(-)rust/hw/core/src/qdev.rs +0
-54@@ -248,59 +248,6 @@ pub fn class_init<T: DeviceImpl>(&mut self) { } } -#[macro_export] -macro_rules! define_property { - ($name:expr, $state:ty, $field:ident, $prop:expr, $type:ty, bit = $bitnr:expr,default = $defval:expr$(,)*) => { - $crate::bindings::Property { -// use associated function syntax for type checking - name: ::std::ffi::CStr ::as_ptr ($name), - info: $prop, - offset: ::std::mem::offset_of!($state, $field)as isize , - bitnr: $bitnr, - set_default:true , - defval: $crate::bindings::Property__bindgen_ty_1 { u: $defvalas u64 }, - ..::common::zeroable::Zeroable ::ZERO - } - }; - ($name:expr, $state:ty, $field:ident, $prop:expr, $type:ty,default = $defval:expr$(,)*) => { - $crate::bindings::Property { -// use associated function syntax for type checking - name: ::std::ffi::CStr ::as_ptr ($name), - info: $prop, - offset: ::std::mem::offset_of!($state, $field)as isize , - set_default:true , - defval: $crate::bindings::Property__bindgen_ty_1 { u: $defvalas u64 }, - ..::common::zeroable::Zeroable ::ZERO - } - }; - ($name:expr, $state:ty, $field:ident, $prop:expr, $type:ty$(,)*) => { - $crate::bindings::Property { -// use associated function syntax for type checking - name: ::std::ffi::CStr ::as_ptr ($name), - info: $prop, - offset: ::std::mem::offset_of!($state, $field)as isize , - set_default:false , - ..::common::zeroable::Zeroable ::ZERO - } - }; -} - -#[macro_export] -macro_rules! declare_properties { - ($ident:ident, $($prop:expr),*$(,)*) => { -pub static $ident: [$crate::bindings::Property ; { -let mut len =0 ; - $({ - _ =stringify! ($prop); - len +=1 ; - })* - len - }] = [ - $($prop),*, - ]; - }; -} -unsafe impl ObjectType for DeviceState {type Class =DeviceClass ; const TYPE_NAME: &'static CStr = --2.34.1