rust: add SysBusDeviceImpl

The only function, right now, is to ensure that anything with a
SysBusDeviceClass class is a SysBusDevice.

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2025-02-12 12:23:59 +01:00
parent ac5699c5da
commit 3212da0033
3 changed files with 12 additions and 5 deletions

View File

@ -20,7 +20,7 @@
prelude::*, prelude::*,
qdev::{Clock, ClockEvent, DeviceImpl, DeviceState, Property, ResetType, ResettablePhasesImpl}, qdev::{Clock, ClockEvent, DeviceImpl, DeviceState, Property, ResetType, ResettablePhasesImpl},
qom::{ClassInitImpl, ObjectImpl, Owned, ParentField}, qom::{ClassInitImpl, ObjectImpl, Owned, ParentField},
sysbus::{SysBusDevice, SysBusDeviceClass}, sysbus::{SysBusDevice, SysBusDeviceClass, SysBusDeviceImpl},
vmstate::VMStateDescription, vmstate::VMStateDescription,
}; };
@ -176,6 +176,8 @@ impl ResettablePhasesImpl for PL011State {
const HOLD: Option<fn(&Self, ResetType)> = Some(Self::reset_hold); const HOLD: Option<fn(&Self, ResetType)> = Some(Self::reset_hold);
} }
impl SysBusDeviceImpl for PL011State {}
impl PL011Registers { impl PL011Registers {
pub(self) fn read(&mut self, offset: RegisterOffset) -> (bool, u32) { pub(self) fn read(&mut self, offset: RegisterOffset) -> (bool, u32) {
use RegisterOffset::*; use RegisterOffset::*;
@ -746,3 +748,4 @@ impl ObjectImpl for PL011Luminary {
impl DeviceImpl for PL011Luminary {} impl DeviceImpl for PL011Luminary {}
impl ResettablePhasesImpl for PL011Luminary {} impl ResettablePhasesImpl for PL011Luminary {}
impl SysBusDeviceImpl for PL011Luminary {}

View File

@ -23,7 +23,7 @@
qdev::{DeviceImpl, DeviceMethods, DeviceState, Property, ResetType, ResettablePhasesImpl}, qdev::{DeviceImpl, DeviceMethods, DeviceState, Property, ResetType, ResettablePhasesImpl},
qom::{ObjectImpl, ObjectType, ParentField}, qom::{ObjectImpl, ObjectType, ParentField},
qom_isa, qom_isa,
sysbus::SysBusDevice, sysbus::{SysBusDevice, SysBusDeviceImpl},
timer::{Timer, CLOCK_VIRTUAL}, timer::{Timer, CLOCK_VIRTUAL},
}; };
@ -887,3 +887,5 @@ fn properties() -> &'static [Property] {
impl ResettablePhasesImpl for HPETState { impl ResettablePhasesImpl for HPETState {
const HOLD: Option<fn(&Self, ResetType)> = Some(Self::reset_hold); const HOLD: Option<fn(&Self, ResetType)> = Some(Self::reset_hold);
} }
impl SysBusDeviceImpl for HPETState {}

View File

@ -14,7 +14,7 @@
irq::{IRQState, InterruptSource}, irq::{IRQState, InterruptSource},
memory::MemoryRegion, memory::MemoryRegion,
prelude::*, prelude::*,
qdev::{DeviceClass, DeviceState}, qdev::{DeviceClass, DeviceImpl, DeviceState},
qom::{ClassInitImpl, Owned}, qom::{ClassInitImpl, Owned},
}; };
@ -25,10 +25,12 @@ unsafe impl ObjectType for SysBusDevice {
} }
qom_isa!(SysBusDevice: DeviceState, Object); qom_isa!(SysBusDevice: DeviceState, Object);
// TODO: add SysBusDeviceImpl // TODO: add virtual methods
pub trait SysBusDeviceImpl: DeviceImpl + IsA<SysBusDevice> {}
impl<T> ClassInitImpl<SysBusDeviceClass> for T impl<T> ClassInitImpl<SysBusDeviceClass> for T
where where
T: ClassInitImpl<DeviceClass>, T: SysBusDeviceImpl + ClassInitImpl<DeviceClass>,
{ {
fn class_init(sdc: &mut SysBusDeviceClass) { fn class_init(sdc: &mut SysBusDeviceClass) {
<T as ClassInitImpl<DeviceClass>>::class_init(&mut sdc.parent_class); <T as ClassInitImpl<DeviceClass>>::class_init(&mut sdc.parent_class);