15a5110d2SManos Pitsidianakis // Copyright 2024, Linaro Limited 25a5110d2SManos Pitsidianakis // Author(s): Manos Pitsidianakis <manos.pitsidianakis@linaro.org> 35a5110d2SManos Pitsidianakis // SPDX-License-Identifier: GPL-2.0-or-later 45a5110d2SManos Pitsidianakis 55a5110d2SManos Pitsidianakis #[macro_export] 65a5110d2SManos Pitsidianakis macro_rules! device_class_init { 75a5110d2SManos Pitsidianakis ($func:ident, props => $props:ident, realize_fn => $realize_fn:expr, legacy_reset_fn => $legacy_reset_fn:expr, vmsd => $vmsd:ident$(,)*) => { 85a5110d2SManos Pitsidianakis pub unsafe extern "C" fn $func( 95a5110d2SManos Pitsidianakis klass: *mut $crate::bindings::ObjectClass, 105a5110d2SManos Pitsidianakis _: *mut ::core::ffi::c_void, 115a5110d2SManos Pitsidianakis ) { 125a5110d2SManos Pitsidianakis let mut dc = 135a5110d2SManos Pitsidianakis ::core::ptr::NonNull::new(klass.cast::<$crate::bindings::DeviceClass>()).unwrap(); 147b72c7ddSPaolo Bonzini unsafe { 155a5110d2SManos Pitsidianakis dc.as_mut().realize = $realize_fn; 165a5110d2SManos Pitsidianakis dc.as_mut().vmsd = &$vmsd; 175a5110d2SManos Pitsidianakis $crate::bindings::device_class_set_legacy_reset(dc.as_mut(), $legacy_reset_fn); 18c92c447fSPaolo Bonzini $crate::bindings::device_class_set_props(dc.as_mut(), $props.as_ptr()); 195a5110d2SManos Pitsidianakis } 207b72c7ddSPaolo Bonzini } 215a5110d2SManos Pitsidianakis }; 225a5110d2SManos Pitsidianakis } 235a5110d2SManos Pitsidianakis 245a5110d2SManos Pitsidianakis #[macro_export] 255a5110d2SManos Pitsidianakis macro_rules! define_property { 265a5110d2SManos Pitsidianakis ($name:expr, $state:ty, $field:expr, $prop:expr, $type:expr, default = $defval:expr$(,)*) => { 275a5110d2SManos Pitsidianakis $crate::bindings::Property { 2803a573b9SPaolo Bonzini // use associated function syntax for type checking 2903a573b9SPaolo Bonzini name: ::core::ffi::CStr::as_ptr($name), 305a5110d2SManos Pitsidianakis info: $prop, 31c92c447fSPaolo Bonzini offset: ::core::mem::offset_of!($state, $field) as isize, 325a5110d2SManos Pitsidianakis set_default: true, 3303a573b9SPaolo Bonzini defval: $crate::bindings::Property__bindgen_ty_1 { u: $defval as u64 }, 34*6e50bde1SPaolo Bonzini ..$crate::zeroable::Zeroable::ZERO 355a5110d2SManos Pitsidianakis } 365a5110d2SManos Pitsidianakis }; 375a5110d2SManos Pitsidianakis ($name:expr, $state:ty, $field:expr, $prop:expr, $type:expr$(,)*) => { 385a5110d2SManos Pitsidianakis $crate::bindings::Property { 3903a573b9SPaolo Bonzini // use associated function syntax for type checking 4003a573b9SPaolo Bonzini name: ::core::ffi::CStr::as_ptr($name), 415a5110d2SManos Pitsidianakis info: $prop, 42c92c447fSPaolo Bonzini offset: ::core::mem::offset_of!($state, $field) as isize, 435a5110d2SManos Pitsidianakis set_default: false, 44*6e50bde1SPaolo Bonzini ..$crate::zeroable::Zeroable::ZERO 455a5110d2SManos Pitsidianakis } 465a5110d2SManos Pitsidianakis }; 475a5110d2SManos Pitsidianakis } 485a5110d2SManos Pitsidianakis 495a5110d2SManos Pitsidianakis #[macro_export] 505a5110d2SManos Pitsidianakis macro_rules! declare_properties { 515a5110d2SManos Pitsidianakis ($ident:ident, $($prop:expr),*$(,)*) => { 52c92c447fSPaolo Bonzini pub static $ident: [$crate::bindings::Property; { 535a5110d2SManos Pitsidianakis let mut len = 1; 545a5110d2SManos Pitsidianakis $({ 555a5110d2SManos Pitsidianakis _ = stringify!($prop); 565a5110d2SManos Pitsidianakis len += 1; 575a5110d2SManos Pitsidianakis })* 585a5110d2SManos Pitsidianakis len 59c92c447fSPaolo Bonzini }] = [ 605a5110d2SManos Pitsidianakis $($prop),*, 61*6e50bde1SPaolo Bonzini $crate::zeroable::Zeroable::ZERO, 62c92c447fSPaolo Bonzini ]; 635a5110d2SManos Pitsidianakis }; 645a5110d2SManos Pitsidianakis } 655a5110d2SManos Pitsidianakis 665a5110d2SManos Pitsidianakis #[macro_export] 675a5110d2SManos Pitsidianakis macro_rules! vm_state_description { 685a5110d2SManos Pitsidianakis ($(#[$outer:meta])* 695a5110d2SManos Pitsidianakis $name:ident, 705a5110d2SManos Pitsidianakis $(name: $vname:expr,)* 715a5110d2SManos Pitsidianakis $(unmigratable: $um_val:expr,)* 725a5110d2SManos Pitsidianakis ) => { 735a5110d2SManos Pitsidianakis #[used] 745a5110d2SManos Pitsidianakis $(#[$outer])* 755a5110d2SManos Pitsidianakis pub static $name: $crate::bindings::VMStateDescription = $crate::bindings::VMStateDescription { 765a5110d2SManos Pitsidianakis $(name: { 775a5110d2SManos Pitsidianakis #[used] 785a5110d2SManos Pitsidianakis static VMSTATE_NAME: &::core::ffi::CStr = $vname; 795a5110d2SManos Pitsidianakis $vname.as_ptr() 805a5110d2SManos Pitsidianakis },)* 815a5110d2SManos Pitsidianakis unmigratable: true, 82*6e50bde1SPaolo Bonzini ..$crate::zeroable::Zeroable::ZERO 835a5110d2SManos Pitsidianakis }; 845a5110d2SManos Pitsidianakis } 855a5110d2SManos Pitsidianakis } 86