* [PATCH] rust: cell: add full example of declaring a SysBusDevice
@ 2025-02-28 8:55 Paolo Bonzini
2025-03-04 17:04 ` Zhao Liu
0 siblings, 1 reply; 3+ messages in thread
From: Paolo Bonzini @ 2025-02-28 8:55 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-rust
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
rust/qemu-api/src/cell.rs | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/rust/qemu-api/src/cell.rs b/rust/qemu-api/src/cell.rs
index 6db678161ff..13e267ad355 100644
--- a/rust/qemu-api/src/cell.rs
+++ b/rust/qemu-api/src/cell.rs
@@ -73,6 +73,36 @@
//! QEMU device implementations is usually incorrect and can lead to
//! thread-safety issues.
//!
+//! ### Example
+//!
+//! ```
+//! # use qemu_api::prelude::*;
+//! # use qemu_api::{c_str, cell::BqlRefCell, irq::InterruptSource, irq::IRQState};
+//! # use qemu_api::{sysbus::SysBusDevice, qom::Owned, qom::ParentField};
+//! # const N_GPIOS: usize = 8;
+//! # struct PL061Registers { /* ... */ }
+//! # unsafe impl ObjectType for PL061Device {
+//! # type Class = <SysBusDevice as ObjectType>::Class;
+//! # const TYPE_NAME: &'static std::ffi::CStr = c_str!("pl061");
+//! # }
+//! struct PL061Device {
+//! parent_obj: ParentField<SysBusDevice>,
+//!
+//! // Configuration is read-only after initialization
+//! pullups: u32,
+//! pulldowns: u32,
+//!
+//! // Same for sub-objects of the device
+//! out: [Owned<IRQState>; N_GPIOS],
+//!
+//! // Single values shared with C code use BqlCell, in this case via InterruptSource
+//! interrupt: InterruptSource,
+//!
+//! // Larger state accessed by device methods uses BqlRefCell or Mutex
+//! registers: BqlRefCell<PL061Registers>,
+//! }
+//! ```
+//!
//! ### `BqlCell<T>`
//!
//! [`BqlCell<T>`] implements interior mutability by moving values in and out of
--
2.48.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] rust: cell: add full example of declaring a SysBusDevice
2025-02-28 8:55 [PATCH] rust: cell: add full example of declaring a SysBusDevice Paolo Bonzini
@ 2025-03-04 17:04 ` Zhao Liu
2025-03-04 19:44 ` Paolo Bonzini
0 siblings, 1 reply; 3+ messages in thread
From: Zhao Liu @ 2025-03-04 17:04 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: qemu-devel, qemu-rust
> +//! ### Example
> +//!
> +//! ```
> +//! # use qemu_api::prelude::*;
> +//! # use qemu_api::{c_str, cell::BqlRefCell, irq::InterruptSource, irq::IRQState};
> +//! # use qemu_api::{sysbus::SysBusDevice, qom::Owned, qom::ParentField};
> +//! # const N_GPIOS: usize = 8;
> +//! # struct PL061Registers { /* ... */ }
> +//! # unsafe impl ObjectType for PL061Device {
> +//! # type Class = <SysBusDevice as ObjectType>::Class;
> +//! # const TYPE_NAME: &'static std::ffi::CStr = c_str!("pl061");
> +//! # }
> +//! struct PL061Device {
Maybe PL061State?
> +//! parent_obj: ParentField<SysBusDevice>,
> +//!
> +//! // Configuration is read-only after initialization
> +//! pullups: u32,
> +//! pulldowns: u32,
> +//!
> +//! // Same for sub-objects of the device
> +//! out: [Owned<IRQState>; N_GPIOS],
Should this be InterruptSource type?
Just have a quick look at pl061.c:
qdev_init_gpio_out(dev, s->out, N_GPIOS);
So in Rust side, `out` would be initialized by
DeviceMethods::init_gpio_out().
Others are fine for me ~ with above nits fixed,
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] rust: cell: add full example of declaring a SysBusDevice
2025-03-04 17:04 ` Zhao Liu
@ 2025-03-04 19:44 ` Paolo Bonzini
0 siblings, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2025-03-04 19:44 UTC (permalink / raw)
To: Zhao Liu; +Cc: qemu-devel, qemu-rust
On 3/4/25 18:04, Zhao Liu wrote:
>> +//! struct PL061Device {
>
> Maybe PL061State?
>
>> +//! parent_obj: ParentField<SysBusDevice>,
>> +//!
>> +//! // Configuration is read-only after initialization
>> +//! pullups: u32,
>> +//! pulldowns: u32,
>> +//!
>> +//! // Same for sub-objects of the device
>> +//! out: [Owned<IRQState>; N_GPIOS],
>
> Should this be InterruptSource type?
>
> Just have a quick look at pl061.c:
>
> qdev_init_gpio_out(dev, s->out, N_GPIOS);
>
> So in Rust side, `out` would be initialized by
> DeviceMethods::init_gpio_out().
>
>
> Others are fine for me ~ with above nits fixed,
>
> Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Yes, all good points. Looks like we're set for 10.0 soft freeze. :)
Paolo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-03-04 19:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-28 8:55 [PATCH] rust: cell: add full example of declaring a SysBusDevice Paolo Bonzini
2025-03-04 17:04 ` Zhao Liu
2025-03-04 19:44 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).