Skip to content

Commit 5778ce9

Browse files
committed
rust: cell: add full example of declaring a SysBusDevice
Reviewed-by: Zhao Liu <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 519088b commit 5778ce9

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

rust/qemu-api/src/cell.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,34 @@
7373
//! QEMU device implementations is usually incorrect and can lead to
7474
//! thread-safety issues.
7575
//!
76+
//! ### Example
77+
//!
78+
//! ```
79+
//! # use qemu_api::prelude::*;
80+
//! # use qemu_api::{c_str, cell::BqlRefCell, irq::InterruptSource, irq::IRQState};
81+
//! # use qemu_api::{sysbus::SysBusDevice, qom::Owned, qom::ParentField};
82+
//! # const N_GPIOS: usize = 8;
83+
//! # struct PL061Registers { /* ... */ }
84+
//! # unsafe impl ObjectType for PL061State {
85+
//! # type Class = <SysBusDevice as ObjectType>::Class;
86+
//! # const TYPE_NAME: &'static std::ffi::CStr = c_str!("pl061");
87+
//! # }
88+
//! struct PL061State {
89+
//! parent_obj: ParentField<SysBusDevice>,
90+
//!
91+
//! // Configuration is read-only after initialization
92+
//! pullups: u32,
93+
//! pulldowns: u32,
94+
//!
95+
//! // Single values shared with C code use BqlCell, in this case via InterruptSource
96+
//! out: [InterruptSource; N_GPIOS],
97+
//! interrupt: InterruptSource,
98+
//!
99+
//! // Larger state accessed by device methods uses BqlRefCell or Mutex
100+
//! registers: BqlRefCell<PL061Registers>,
101+
//! }
102+
//! ```
103+
//!
76104
//! ### `BqlCell<T>`
77105
//!
78106
//! [`BqlCell<T>`] implements interior mutability by moving values in and out of

0 commit comments

Comments
 (0)