rust: pl011, qemu_api tests: do not use ClassInitImpl
Outside the qemu_api crate, orphan rules make the usage of ClassInitImpl unwieldy. Now that it is optional, do not use it. For PL011Class, this makes it easier to provide a PL011Impl trait similar to the ones in the qemu_api crate. The device id consts are moved there. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
4551f342fe
commit
567c0c41a6
@ -50,11 +50,6 @@ impl std::ops::Index<hwaddr> for DeviceId {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DeviceId {
|
|
||||||
const ARM: Self = Self(&[0x11, 0x10, 0x14, 0x00, 0x0d, 0xf0, 0x05, 0xb1]);
|
|
||||||
const LUMINARY: Self = Self(&[0x11, 0x00, 0x18, 0x01, 0x0d, 0xf0, 0x05, 0xb1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIFOs use 32-bit indices instead of usize, for compatibility with
|
// FIFOs use 32-bit indices instead of usize, for compatibility with
|
||||||
// the migration stream produced by the C version of this device.
|
// the migration stream produced by the C version of this device.
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
@ -143,16 +138,24 @@ pub struct PL011Class {
|
|||||||
device_id: DeviceId,
|
device_id: DeviceId,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trait PL011Impl: SysBusDeviceImpl + IsA<PL011State> {
|
||||||
|
const DEVICE_ID: DeviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PL011Class {
|
||||||
|
fn class_init<T: PL011Impl>(&mut self) {
|
||||||
|
self.device_id = T::DEVICE_ID;
|
||||||
|
<T as ClassInitImpl<SysBusDeviceClass>>::class_init(&mut self.parent_class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unsafe impl ObjectType for PL011State {
|
unsafe impl ObjectType for PL011State {
|
||||||
type Class = PL011Class;
|
type Class = PL011Class;
|
||||||
const TYPE_NAME: &'static CStr = crate::TYPE_PL011;
|
const TYPE_NAME: &'static CStr = crate::TYPE_PL011;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ClassInitImpl<PL011Class> for PL011State {
|
impl PL011Impl for PL011State {
|
||||||
fn class_init(klass: &mut PL011Class) {
|
const DEVICE_ID: DeviceId = DeviceId(&[0x11, 0x10, 0x14, 0x00, 0x0d, 0xf0, 0x05, 0xb1]);
|
||||||
klass.device_id = DeviceId::ARM;
|
|
||||||
<Self as ClassInitImpl<SysBusDeviceClass>>::class_init(&mut klass.parent_class);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ObjectImpl for PL011State {
|
impl ObjectImpl for PL011State {
|
||||||
@ -160,7 +163,7 @@ impl ObjectImpl for PL011State {
|
|||||||
|
|
||||||
const INSTANCE_INIT: Option<unsafe fn(&mut Self)> = Some(Self::init);
|
const INSTANCE_INIT: Option<unsafe fn(&mut Self)> = Some(Self::init);
|
||||||
const INSTANCE_POST_INIT: Option<fn(&Self)> = Some(Self::post_init);
|
const INSTANCE_POST_INIT: Option<fn(&Self)> = Some(Self::post_init);
|
||||||
const CLASS_INIT: fn(&mut Self::Class) = <Self as ClassInitImpl<Self::Class>>::class_init;
|
const CLASS_INIT: fn(&mut Self::Class) = Self::Class::class_init::<Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DeviceImpl for PL011State {
|
impl DeviceImpl for PL011State {
|
||||||
@ -729,13 +732,6 @@ pub struct PL011Luminary {
|
|||||||
parent_obj: ParentField<PL011State>,
|
parent_obj: ParentField<PL011State>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ClassInitImpl<PL011Class> for PL011Luminary {
|
|
||||||
fn class_init(klass: &mut PL011Class) {
|
|
||||||
klass.device_id = DeviceId::LUMINARY;
|
|
||||||
<Self as ClassInitImpl<SysBusDeviceClass>>::class_init(&mut klass.parent_class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
qom_isa!(PL011Luminary : PL011State, SysBusDevice, DeviceState, Object);
|
qom_isa!(PL011Luminary : PL011State, SysBusDevice, DeviceState, Object);
|
||||||
|
|
||||||
unsafe impl ObjectType for PL011Luminary {
|
unsafe impl ObjectType for PL011Luminary {
|
||||||
@ -746,7 +742,11 @@ unsafe impl ObjectType for PL011Luminary {
|
|||||||
impl ObjectImpl for PL011Luminary {
|
impl ObjectImpl for PL011Luminary {
|
||||||
type ParentType = PL011State;
|
type ParentType = PL011State;
|
||||||
|
|
||||||
const CLASS_INIT: fn(&mut Self::Class) = <Self as ClassInitImpl<Self::Class>>::class_init;
|
const CLASS_INIT: fn(&mut Self::Class) = Self::Class::class_init::<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PL011Impl for PL011Luminary {
|
||||||
|
const DEVICE_ID: DeviceId = DeviceId(&[0x11, 0x00, 0x18, 0x01, 0x0d, 0xf0, 0x05, 0xb1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DeviceImpl for PL011Luminary {}
|
impl DeviceImpl for PL011Luminary {}
|
||||||
|
@ -13,7 +13,7 @@ use qemu_api::{
|
|||||||
cell::{self, BqlCell},
|
cell::{self, BqlCell},
|
||||||
declare_properties, define_property,
|
declare_properties, define_property,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
qdev::{DeviceClass, DeviceImpl, DeviceState, Property, ResettablePhasesImpl},
|
qdev::{DeviceImpl, DeviceState, Property, ResettablePhasesImpl},
|
||||||
qom::{ClassInitImpl, ObjectImpl, ParentField},
|
qom::{ClassInitImpl, ObjectImpl, ParentField},
|
||||||
sysbus::SysBusDevice,
|
sysbus::SysBusDevice,
|
||||||
vmstate::VMStateDescription,
|
vmstate::VMStateDescription,
|
||||||
@ -41,6 +41,12 @@ pub struct DummyClass {
|
|||||||
parent_class: <DeviceState as ObjectType>::Class,
|
parent_class: <DeviceState as ObjectType>::Class,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl DummyClass {
|
||||||
|
pub fn class_init<T: DeviceImpl>(self: &mut DummyClass) {
|
||||||
|
<T as ClassInitImpl<DeviceClass>>::class_init(&mut self.parent_class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
declare_properties! {
|
declare_properties! {
|
||||||
DUMMY_PROPERTIES,
|
DUMMY_PROPERTIES,
|
||||||
define_property!(
|
define_property!(
|
||||||
@ -60,7 +66,7 @@ unsafe impl ObjectType for DummyState {
|
|||||||
impl ObjectImpl for DummyState {
|
impl ObjectImpl for DummyState {
|
||||||
type ParentType = DeviceState;
|
type ParentType = DeviceState;
|
||||||
const ABSTRACT: bool = false;
|
const ABSTRACT: bool = false;
|
||||||
const CLASS_INIT: fn(&mut DummyClass) = <Self as ClassInitImpl<DummyClass>>::class_init;
|
const CLASS_INIT: fn(&mut DummyClass) = DummyClass::class_init::<Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ResettablePhasesImpl for DummyState {}
|
impl ResettablePhasesImpl for DummyState {}
|
||||||
@ -74,14 +80,6 @@ impl DeviceImpl for DummyState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// `impl<T> ClassInitImpl<DummyClass> for T` doesn't work since it violates
|
|
||||||
// orphan rule.
|
|
||||||
impl ClassInitImpl<DummyClass> for DummyState {
|
|
||||||
fn class_init(klass: &mut DummyClass) {
|
|
||||||
<Self as ClassInitImpl<DeviceClass>>::class_init(&mut klass.parent_class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(qemu_api_macros::offsets)]
|
#[derive(qemu_api_macros::offsets)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(qemu_api_macros::Object)]
|
#[derive(qemu_api_macros::Object)]
|
||||||
@ -103,22 +101,15 @@ unsafe impl ObjectType for DummyChildState {
|
|||||||
impl ObjectImpl for DummyChildState {
|
impl ObjectImpl for DummyChildState {
|
||||||
type ParentType = DummyState;
|
type ParentType = DummyState;
|
||||||
const ABSTRACT: bool = false;
|
const ABSTRACT: bool = false;
|
||||||
const CLASS_INIT: fn(&mut DummyChildClass) =
|
const CLASS_INIT: fn(&mut DummyChildClass) = DummyChildClass::class_init::<Self>;
|
||||||
<Self as ClassInitImpl<DummyChildClass>>::class_init;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ResettablePhasesImpl for DummyChildState {}
|
impl ResettablePhasesImpl for DummyChildState {}
|
||||||
impl DeviceImpl for DummyChildState {}
|
impl DeviceImpl for DummyChildState {}
|
||||||
|
|
||||||
impl ClassInitImpl<DummyClass> for DummyChildState {
|
impl DummyChildClass {
|
||||||
fn class_init(klass: &mut DummyClass) {
|
pub fn class_init<T: DeviceImpl>(self: &mut DummyChildClass) {
|
||||||
<Self as ClassInitImpl<DeviceClass>>::class_init(&mut klass.parent_class);
|
self.parent_class.class_init::<T>();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ClassInitImpl<DummyChildClass> for DummyChildState {
|
|
||||||
fn class_init(klass: &mut DummyChildClass) {
|
|
||||||
<Self as ClassInitImpl<DummyClass>>::class_init(&mut klass.parent_class);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user