[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 05/12] rust: irq: wrap IRQState with Opaque<>
From: |
Paolo Bonzini |
Subject: |
[PATCH 05/12] rust: irq: wrap IRQState with Opaque<> |
Date: |
Thu, 27 Feb 2025 15:22:12 +0100 |
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
rust/qemu-api/src/irq.rs | 15 ++++++++++-----
rust/qemu-api/src/sysbus.rs | 1 +
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/rust/qemu-api/src/irq.rs b/rust/qemu-api/src/irq.rs
index 34c19263c23..1222d4fde30 100644
--- a/rust/qemu-api/src/irq.rs
+++ b/rust/qemu-api/src/irq.rs
@@ -8,10 +8,16 @@
use crate::{
bindings::{self, qemu_set_irq},
+ cell::Opaque,
prelude::*,
qom::ObjectClass,
};
+/// An opaque wrapper around [`bindings::IRQState`].
+#[repr(transparent)]
+#[derive(Debug, qemu_api_macros::Wrapper)]
+pub struct IRQState(Opaque<bindings::IRQState>);
+
/// Interrupt sources are used by devices to pass changes to a value (typically
/// a boolean). The interrupt sink is usually an interrupt controller or
/// GPIO controller.
@@ -21,8 +27,7 @@
/// method sends a `true` value to the sink. If the guest has to see a
/// different polarity, that change is performed by the board between the
/// device and the interrupt controller.
-pub type IRQState = bindings::IRQState;
-
+///
/// Interrupts are implemented as a pointer to the interrupt "sink", which has
/// type [`IRQState`]. A device exposes its source as a QOM link property
using
/// a function such as [`SysBusDeviceMethods::init_irq`], and
@@ -40,7 +45,7 @@ pub struct InterruptSource<T = bool>
where
c_int: From<T>,
{
- cell: BqlCell<*mut IRQState>,
+ cell: BqlCell<*mut bindings::IRQState>,
_marker: PhantomData<T>,
}
@@ -79,11 +84,11 @@ pub fn set(&self, level: T) {
}
}
- pub(crate) const fn as_ptr(&self) -> *mut *mut IRQState {
+ pub(crate) const fn as_ptr(&self) -> *mut *mut bindings::IRQState {
self.cell.as_ptr()
}
- pub(crate) const fn slice_as_ptr(slice: &[Self]) -> *mut *mut IRQState {
+ pub(crate) const fn slice_as_ptr(slice: &[Self]) -> *mut *mut
bindings::IRQState {
assert!(!slice.is_empty());
slice[0].as_ptr()
}
diff --git a/rust/qemu-api/src/sysbus.rs b/rust/qemu-api/src/sysbus.rs
index 04821a2b9b3..48803a655f9 100644
--- a/rust/qemu-api/src/sysbus.rs
+++ b/rust/qemu-api/src/sysbus.rs
@@ -79,6 +79,7 @@ fn mmio_map(&self, id: u32, addr: u64) {
fn connect_irq(&self, id: u32, irq: &Owned<IRQState>) {
assert!(bql_locked());
let id: i32 = id.try_into().unwrap();
+ let irq: &IRQState = irq;
unsafe {
bindings::sysbus_connect_irq(self.as_mut_ptr(), id,
irq.as_mut_ptr());
}
--
2.48.1
- [PATCH v2 00/12] rust: wrap all C types exposed through qemu_api, Paolo Bonzini, 2025/02/27
- [PATCH 03/12] rust: vmstate: add std::pin::Pin as transparent wrapper, Paolo Bonzini, 2025/02/27
- [PATCH 01/12] rust: cell: add wrapper for FFI types, Paolo Bonzini, 2025/02/27
- [PATCH 04/12] rust: timer: wrap QEMUTimer with Opaque<> and express pinning requirements, Paolo Bonzini, 2025/02/27
- [PATCH 06/12] rust: qom: wrap Object with Opaque<>, Paolo Bonzini, 2025/02/27
- [PATCH 05/12] rust: irq: wrap IRQState with Opaque<>,
Paolo Bonzini <=
- [PATCH 09/12] rust: sysbus: wrap SysBusDevice with Opaque<>, Paolo Bonzini, 2025/02/27
- [PATCH 11/12] rust: chardev: wrap Chardev with Opaque<>, Paolo Bonzini, 2025/02/27
- [PATCH 07/12] rust: qdev: wrap Clock and DeviceState with Opaque<>, Paolo Bonzini, 2025/02/27
- [PATCH 08/12] rust: hpet: do not access fields of SysBusDevice, Paolo Bonzini, 2025/02/27
- [PATCH 10/12] rust: memory: wrap MemoryRegion with Opaque<>, Paolo Bonzini, 2025/02/27
- [PATCH 02/12] rust: qemu_api_macros: add Wrapper derive macro, Paolo Bonzini, 2025/02/27
- [PATCH 12/12] rust: bindings: remove more unnecessary Send/Sync impls, Paolo Bonzini, 2025/02/27