All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Cc: qemu-devel@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Thomas Huth" <thuth@redhat.com>,
	"Junjie Mao" <junjie.mao@hotmail.com>,
	"Junjie Mao" <junjie.mao@intel.com>,
	"Zhao Liu" <zhao1.liu@intel.com>, "Kevin Wolf" <kwolf@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Gustavo Romero" <gustavo.romero@linaro.org>,
	"Pierrick Bouvier" <pierrick.bouvier@linaro.org>
Subject: Re: [PATCH 03/11] rust/qemu-api-macros: introduce Device proc macro
Date: Thu, 24 Oct 2024 16:13:57 +0100	[thread overview]
Message-ID: <87plnpile2.fsf@draig.linaro.org> (raw)
In-Reply-To: <20241024-rust-round-2-v1-3-051e7a25b978@linaro.org> (Manos Pitsidianakis's message of "Thu, 24 Oct 2024 17:03:01 +0300")

Manos Pitsidianakis <manos.pitsidianakis@linaro.org> writes:

> Add a new derive procedural macro to declare device models. Add
> corresponding DeviceImpl trait after already existing ObjectImpl trait.
> At the same time, add instance_init, instance_post_init,
> instance_finalize methods to the ObjectImpl trait and call them from the
> ObjectImplUnsafe trait, which is generated by the procedural macro.
>
> This allows all the boilerplate device model registration to be handled
> by macros, and all pertinent details to be declared through proc macro
> attributes or trait associated constants and methods.
>
> The device class can now be generated automatically and the name can be
> optionally overridden:
>
>   ------------------------ >8 ------------------------
>  #[repr(C)]
>  #[derive(Debug, qemu_api_macros::Object, qemu_api_macros::Device)]
>  #[device(class_name_override = PL011Class)]
>  /// PL011 Device Model in QEMU
>  pub struct PL011State {
>   ------------------------ >8 ------------------------
>
> Properties are now marked as field attributes:
>
>   ------------------------ >8 ------------------------
>  #[property(name = c"chardev", qdev_prop = qdev_prop_chr)]
>  pub char_backend: CharBackend,
>   ------------------------ >8 ------------------------
>
> Object methods (instance_init, etc) methods are now trait methods:
>
>   ------------------------ >8 ------------------------
>  /// Trait a type must implement to be registered with QEMU.
>  pub trait ObjectImpl {
>      type Class: ClassImpl;
>      const TYPE_NAME: &'static CStr;
>      const PARENT_TYPE_NAME: Option<&'static CStr>;
>      const ABSTRACT: bool;
>
>      unsafe fn instance_init(&mut self) {}
>      fn instance_post_init(&mut self) {}
>      fn instance_finalize(&mut self) {}
>  }
>   ------------------------ >8 ------------------------
>
> Device methods (realize/reset etc) are now safe idiomatic trait methods:
>
>   ------------------------ >8 ------------------------
>  /// Implementation methods for device types.
>  pub trait DeviceImpl: ObjectImpl {
>      fn realize(&mut self) {}
>      fn reset(&mut self) {}
>  }
>   ------------------------ >8 ------------------------
>
> The derive Device macro is responsible for creating all the extern "C" FFI
> functions that QEMU needs to call these methods.
>
> Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
> ---
>  rust/hw/char/pl011/src/device.rs              | 124 +++-----
>  rust/hw/char/pl011/src/device_class.rs        |  70 -----
>  rust/hw/char/pl011/src/lib.rs                 |   1 -
>  rust/qemu-api-macros/src/device.rs            | 433 ++++++++++++++++++++++++++
>  rust/qemu-api-macros/src/lib.rs               |  45 +--
>  rust/qemu-api-macros/src/object.rs            | 107 +++++++
>  rust/qemu-api-macros/src/symbols.rs           |  55 ++++
>  rust/qemu-api-macros/src/utilities.rs         | 152 +++++++++
>  rust/qemu-api/meson.build                     |   3 +-
>  rust/qemu-api/src/definitions.rs              |  97 ------
>  rust/qemu-api/src/device_class.rs             | 128 --------
>  rust/qemu-api/src/lib.rs                      |   6 +-
>  rust/qemu-api/src/objects.rs                  |  90 ++++++
>  rust/qemu-api/src/tests.rs                    |  49 ---
>  subprojects/packagefiles/syn-2-rs/meson.build |   1 +
>  15 files changed, 902 insertions(+), 459 deletions(-)

My initial reaction is these patches are getting quite large because we
are doing several things at once. Is it possible to split them so:

  - we bring in one macro at a time (with unit tests)
  - we then convert pl011 to the new idiom

? 

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


  reply	other threads:[~2024-10-24 15:14 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-24 14:02 [PATCH 00/11] Rust device model patches and misc cleanups Manos Pitsidianakis
2024-10-24 14:02 ` [PATCH 01/11] Revert "rust: add PL011 device model" Manos Pitsidianakis
2024-10-24 14:03 ` [PATCH 02/11] rust: add PL011 device model Manos Pitsidianakis
2024-10-24 14:03 ` [PATCH 03/11] rust/qemu-api-macros: introduce Device proc macro Manos Pitsidianakis
2024-10-24 15:13   ` Alex Bennée [this message]
2024-10-24 17:06     ` Manos Pitsidianakis
2024-10-25 12:01   ` Paolo Bonzini
2024-10-25 14:04     ` Manos Pitsidianakis
2024-10-25 15:22       ` Paolo Bonzini
2024-10-25 16:22         ` Manos Pitsidianakis
2024-10-27 20:58   ` Paolo Bonzini
2024-10-27 22:39     ` Manos Pitsidianakis
2024-10-28  7:07       ` Paolo Bonzini
2024-10-24 14:03 ` [PATCH 04/11] rust: add support for migration in device models Manos Pitsidianakis
2024-10-24 14:03 ` [PATCH 05/11] rust/pl011: move CLK_NAME static to function scope Manos Pitsidianakis
2024-10-24 14:03 ` [PATCH 06/11] rust/pl011: add TYPE_PL011_LUMINARY device Manos Pitsidianakis
2024-10-24 17:27   ` Zhao Liu
2024-10-24 14:03 ` [PATCH 07/11] rust/pl011: move pub callback decl to local scope Manos Pitsidianakis
2024-10-24 14:03 ` [PATCH 08/11] rust/pl011: remove commented out C code Manos Pitsidianakis
2024-10-24 14:03 ` [PATCH 09/11] rust/pl011: Use correct masks for IBRD and FBRD Manos Pitsidianakis
2024-10-24 14:03 ` [PATCH 10/11] rust/qemu-api: add log module Manos Pitsidianakis
2024-10-24 14:03 ` [PATCH 11/11] rust/pl011: log guest/unimp errors Manos Pitsidianakis
2024-10-25  9:33 ` [PATCH 00/11] Rust device model patches and misc cleanups Paolo Bonzini
2024-10-26 10:06   ` Manos Pitsidianakis
2024-10-27  8:13     ` Paolo Bonzini

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=87plnpile2.fsf@draig.linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=berrange@redhat.com \
    --cc=gustavo.romero@linaro.org \
    --cc=junjie.mao@hotmail.com \
    --cc=junjie.mao@intel.com \
    --cc=kwolf@redhat.com \
    --cc=manos.pitsidianakis@linaro.org \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=pierrick.bouvier@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=thuth@redhat.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.