From dcdee1e718f9400a2bf523f2b009fb936370ae4b Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 8 Sep 2025 12:49:40 +0200 Subject: rust: vmstate: use const_refs_to_static The VMStateDescriptionBuilder already needs const_refs_static, so use it to remove the need for vmstate_clock! and vmstate_struct!, as well as to simplify the implementation for scalars. If the consts in the VMState trait can reference to static VMStateDescription, scalars do not need the info_enum_to_ref! indirection and structs can implement the VMState trait themselves. Reviewed-by: Zhao Liu Link: https://lore.kernel.org/r/20250908105005.2119297-9-pbonzini@redhat.com Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'rust/hw/char/pl011/src') diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index 21611d9c09..87a17716fe 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -2,14 +2,11 @@ // Author(s): Manos Pitsidianakis // SPDX-License-Identifier: GPL-2.0-or-later -use std::{ - ffi::CStr, - mem::size_of -}; +use std::{ffi::CStr, mem::size_of}; use qemu_api::{ chardev::{CharBackend, Chardev, Event}, - impl_vmstate_forward, + impl_vmstate_forward, impl_vmstate_struct, irq::{IRQState, InterruptSource}, log::Log, log_mask_ln, @@ -21,7 +18,7 @@ use qemu_api::{ sysbus::{SysBusDevice, SysBusDeviceImpl}, uninit_field_mut, vmstate::{self, VMStateDescription, VMStateDescriptionBuilder}, - vmstate_clock, vmstate_fields, vmstate_of, vmstate_struct, vmstate_subsections, vmstate_unused, + vmstate_fields, vmstate_of, vmstate_subsections, vmstate_unused, }; use crate::registers::{self, Interrupt, RegisterOffset}; @@ -725,11 +722,12 @@ static VMSTATE_PL011_CLOCK: VMStateDescription = .minimum_version_id(1) .needed(&PL011State::clock_needed) .fields(vmstate_fields! { - vmstate_clock!(PL011State, clock), + vmstate_of!(PL011State, clock), }) .build(); -static VMSTATE_PL011_REGS: VMStateDescription = +impl_vmstate_struct!( + PL011Registers, VMStateDescriptionBuilder::::new() .name(c"pl011/regs") .version_id(2) @@ -751,7 +749,8 @@ static VMSTATE_PL011_REGS: VMStateDescription = vmstate_of!(PL011Registers, read_count), vmstate_of!(PL011Registers, read_trigger), }) - .build(); + .build() +); pub const VMSTATE_PL011: VMStateDescription = VMStateDescriptionBuilder::::new() @@ -761,7 +760,7 @@ pub const VMSTATE_PL011: VMStateDescription = .post_load(&PL011State::post_load) .fields(vmstate_fields! { vmstate_unused!(core::mem::size_of::()), - vmstate_struct!(PL011State, regs, &VMSTATE_PL011_REGS, BqlRefCell), + vmstate_of!(PL011State, regs), }) .subsections(vmstate_subsections! { VMSTATE_PL011_CLOCK -- cgit 1.4.1