1 // Copyright 2024, Linaro Limited 2 // Author(s): Manos Pitsidianakis <manos.pitsidianakis@linaro.org> 3 // SPDX-License-Identifier: GPL-2.0-or-later 4 5 #[macro_export] 6 macro_rules! device_class_init { 7 ($func:ident, props => $props:ident, realize_fn => $realize_fn:expr, legacy_reset_fn => $legacy_reset_fn:expr, vmsd => $vmsd:ident$(,)*) => { 8 pub unsafe extern "C" fn $func( 9 klass: *mut $crate::bindings::ObjectClass, 10 _: *mut ::std::os::raw::c_void, 11 ) { 12 let mut dc = 13 ::core::ptr::NonNull::new(klass.cast::<$crate::bindings::DeviceClass>()).unwrap(); 14 unsafe { 15 dc.as_mut().realize = $realize_fn; 16 dc.as_mut().vmsd = &$vmsd; 17 $crate::bindings::device_class_set_legacy_reset(dc.as_mut(), $legacy_reset_fn); 18 $crate::bindings::device_class_set_props(dc.as_mut(), $props.as_ptr()); 19 } 20 } 21 }; 22 } 23 24 #[macro_export] 25 macro_rules! define_property { 26 ($name:expr, $state:ty, $field:ident, $prop:expr, $type:expr, default = $defval:expr$(,)*) => { 27 $crate::bindings::Property { 28 // use associated function syntax for type checking 29 name: ::std::ffi::CStr::as_ptr($name), 30 info: $prop, 31 offset: $crate::offset_of!($state, $field) as isize, 32 set_default: true, 33 defval: $crate::bindings::Property__bindgen_ty_1 { u: $defval as u64 }, 34 ..$crate::zeroable::Zeroable::ZERO 35 } 36 }; 37 ($name:expr, $state:ty, $field:ident, $prop:expr, $type:expr$(,)*) => { 38 $crate::bindings::Property { 39 // use associated function syntax for type checking 40 name: ::std::ffi::CStr::as_ptr($name), 41 info: $prop, 42 offset: $crate::offset_of!($state, $field) as isize, 43 set_default: false, 44 ..$crate::zeroable::Zeroable::ZERO 45 } 46 }; 47 } 48 49 #[macro_export] 50 macro_rules! declare_properties { 51 ($ident:ident, $($prop:expr),*$(,)*) => { 52 pub static $ident: [$crate::bindings::Property; { 53 let mut len = 1; 54 $({ 55 _ = stringify!($prop); 56 len += 1; 57 })* 58 len 59 }] = [ 60 $($prop),*, 61 $crate::zeroable::Zeroable::ZERO, 62 ]; 63 }; 64 } 65