mirror of
https://github.com/Motorhead1991/qemu.git
synced 2026-01-05 22:17:40 -07:00
rust: qdev: support returning errors from realize
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
9a33f49f44
commit
4b66abead9
3 changed files with 14 additions and 8 deletions
|
|
@ -175,7 +175,7 @@ impl DeviceImpl for PL011State {
|
||||||
fn vmsd() -> Option<&'static VMStateDescription> {
|
fn vmsd() -> Option<&'static VMStateDescription> {
|
||||||
Some(&device_class::VMSTATE_PL011)
|
Some(&device_class::VMSTATE_PL011)
|
||||||
}
|
}
|
||||||
const REALIZE: Option<fn(&Self)> = Some(Self::realize);
|
const REALIZE: Option<fn(&Self) -> qemu_api::Result<()>> = Some(Self::realize);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ResettablePhasesImpl for PL011State {
|
impl ResettablePhasesImpl for PL011State {
|
||||||
|
|
@ -619,9 +619,10 @@ impl PL011State {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn realize(&self) {
|
fn realize(&self) -> qemu_api::Result<()> {
|
||||||
self.char_backend
|
self.char_backend
|
||||||
.enable_handlers(self, Self::can_receive, Self::receive, Self::event);
|
.enable_handlers(self, Self::can_receive, Self::receive, Self::event);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reset_hold(&self, _type: ResetType) {
|
fn reset_hold(&self, _type: ResetType) {
|
||||||
|
|
|
||||||
|
|
@ -724,7 +724,7 @@ impl HPETState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn realize(&self) {
|
fn realize(&self) -> qemu_api::Result<()> {
|
||||||
if self.int_route_cap == 0 {
|
if self.int_route_cap == 0 {
|
||||||
// TODO: Add error binding: warn_report()
|
// TODO: Add error binding: warn_report()
|
||||||
println!("Hpet's hpet-intcap property not initialized");
|
println!("Hpet's hpet-intcap property not initialized");
|
||||||
|
|
@ -751,6 +751,7 @@ impl HPETState {
|
||||||
|
|
||||||
self.init_gpio_in(2, HPETState::handle_legacy_irq);
|
self.init_gpio_in(2, HPETState::handle_legacy_irq);
|
||||||
self.init_gpio_out(from_ref(&self.pit_enabled));
|
self.init_gpio_out(from_ref(&self.pit_enabled));
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reset_hold(&self, _type: ResetType) {
|
fn reset_hold(&self, _type: ResetType) {
|
||||||
|
|
@ -1042,7 +1043,7 @@ impl DeviceImpl for HPETState {
|
||||||
Some(&VMSTATE_HPET)
|
Some(&VMSTATE_HPET)
|
||||||
}
|
}
|
||||||
|
|
||||||
const REALIZE: Option<fn(&Self)> = Some(Self::realize);
|
const REALIZE: Option<fn(&Self) -> qemu_api::Result<()>> = Some(Self::realize);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ResettablePhasesImpl for HPETState {
|
impl ResettablePhasesImpl for HPETState {
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,11 @@ use std::{
|
||||||
pub use bindings::{ClockEvent, DeviceClass, Property, ResetType};
|
pub use bindings::{ClockEvent, DeviceClass, Property, ResetType};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
bindings::{self, qdev_init_gpio_in, qdev_init_gpio_out, Error, ResettableClass},
|
bindings::{self, qdev_init_gpio_in, qdev_init_gpio_out, ResettableClass},
|
||||||
callbacks::FnCall,
|
callbacks::FnCall,
|
||||||
cell::{bql_locked, Opaque},
|
cell::{bql_locked, Opaque},
|
||||||
chardev::Chardev,
|
chardev::Chardev,
|
||||||
|
error::{Error, Result},
|
||||||
irq::InterruptSource,
|
irq::InterruptSource,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
qom::{ObjectClass, ObjectImpl, Owned},
|
qom::{ObjectClass, ObjectImpl, Owned},
|
||||||
|
|
@ -108,7 +109,7 @@ pub trait DeviceImpl: ObjectImpl + ResettablePhasesImpl + IsA<DeviceState> {
|
||||||
///
|
///
|
||||||
/// If not `None`, the parent class's `realize` method is overridden
|
/// If not `None`, the parent class's `realize` method is overridden
|
||||||
/// with the function pointed to by `REALIZE`.
|
/// with the function pointed to by `REALIZE`.
|
||||||
const REALIZE: Option<fn(&Self)> = None;
|
const REALIZE: Option<fn(&Self) -> Result<()>> = None;
|
||||||
|
|
||||||
/// An array providing the properties that the user can set on the
|
/// An array providing the properties that the user can set on the
|
||||||
/// device. Not a `const` because referencing statics in constants
|
/// device. Not a `const` because referencing statics in constants
|
||||||
|
|
@ -134,10 +135,13 @@ pub trait DeviceImpl: ObjectImpl + ResettablePhasesImpl + IsA<DeviceState> {
|
||||||
/// readable/writeable from one thread at any time.
|
/// readable/writeable from one thread at any time.
|
||||||
unsafe extern "C" fn rust_realize_fn<T: DeviceImpl>(
|
unsafe extern "C" fn rust_realize_fn<T: DeviceImpl>(
|
||||||
dev: *mut bindings::DeviceState,
|
dev: *mut bindings::DeviceState,
|
||||||
_errp: *mut *mut Error,
|
errp: *mut *mut bindings::Error,
|
||||||
) {
|
) {
|
||||||
let state = NonNull::new(dev).unwrap().cast::<T>();
|
let state = NonNull::new(dev).unwrap().cast::<T>();
|
||||||
T::REALIZE.unwrap()(unsafe { state.as_ref() });
|
let result = T::REALIZE.unwrap()(unsafe { state.as_ref() });
|
||||||
|
unsafe {
|
||||||
|
Error::ok_or_propagate(result, errp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl InterfaceType for ResettableClass {
|
unsafe impl InterfaceType for ResettableClass {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue