On Tue, Sep 16, 2025 at 01:16:25PM +0300, Manos Pitsidianakis wrote:
> 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
> macro
>
> On Tue, Sep 16, 2025 at 11:34 AM Zhao Liu <[email protected]> wrote:
> >
> > Add 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.
> >
> > 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(-)
> >
> > diff --git a/rust/hw/core/src/qdev.rs b/rust/hw/core/src/qdev.rs
> > index b57dc05ebb0e..a8cd9e3c2fd5 100644
> > --- a/rust/hw/core/src/qdev.rs
> > +++ b/rust/hw/core/src/qdev.rs
> > @@ -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.
> > ///
> > /// 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?
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