rust: irq: wrap IRQState with Opaque<>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
a32b239699
commit
9c9a6a889c
@ -8,10 +8,16 @@ use std::{ffi::CStr, marker::PhantomData, os::raw::c_int, ptr};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
bindings::{self, qemu_set_irq},
|
bindings::{self, qemu_set_irq},
|
||||||
|
cell::Opaque,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
qom::ObjectClass,
|
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
|
/// Interrupt sources are used by devices to pass changes to a value (typically
|
||||||
/// a boolean). The interrupt sink is usually an interrupt controller or
|
/// a boolean). The interrupt sink is usually an interrupt controller or
|
||||||
/// GPIO controller.
|
/// GPIO controller.
|
||||||
@ -21,8 +27,7 @@ use crate::{
|
|||||||
/// method sends a `true` value to the sink. If the guest has to see a
|
/// 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
|
/// different polarity, that change is performed by the board between the
|
||||||
/// device and the interrupt controller.
|
/// device and the interrupt controller.
|
||||||
pub type IRQState = bindings::IRQState;
|
///
|
||||||
|
|
||||||
/// Interrupts are implemented as a pointer to the interrupt "sink", which has
|
/// 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
|
/// type [`IRQState`]. A device exposes its source as a QOM link property using
|
||||||
/// a function such as [`SysBusDeviceMethods::init_irq`], and
|
/// a function such as [`SysBusDeviceMethods::init_irq`], and
|
||||||
@ -40,7 +45,7 @@ pub struct InterruptSource<T = bool>
|
|||||||
where
|
where
|
||||||
c_int: From<T>,
|
c_int: From<T>,
|
||||||
{
|
{
|
||||||
cell: BqlCell<*mut IRQState>,
|
cell: BqlCell<*mut bindings::IRQState>,
|
||||||
_marker: PhantomData<T>,
|
_marker: PhantomData<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,11 +84,11 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
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());
|
assert!(!slice.is_empty());
|
||||||
slice[0].as_ptr()
|
slice[0].as_ptr()
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,7 @@ where
|
|||||||
fn connect_irq(&self, id: u32, irq: &Owned<IRQState>) {
|
fn connect_irq(&self, id: u32, irq: &Owned<IRQState>) {
|
||||||
assert!(bql_locked());
|
assert!(bql_locked());
|
||||||
let id: i32 = id.try_into().unwrap();
|
let id: i32 = id.try_into().unwrap();
|
||||||
|
let irq: &IRQState = irq;
|
||||||
unsafe {
|
unsafe {
|
||||||
bindings::sysbus_connect_irq(self.as_mut_ptr(), id, irq.as_mut_ptr());
|
bindings::sysbus_connect_irq(self.as_mut_ptr(), id, irq.as_mut_ptr());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user