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 use core::ptr::NonNull; 6 7 use qemu_api::{bindings::*, definitions::ObjectImpl}; 8 9 use crate::device::PL011State; 10 11 #[used] 12 pub static VMSTATE_PL011: VMStateDescription = VMStateDescription { 13 name: PL011State::TYPE_INFO.name, 14 unmigratable: true, 15 ..unsafe { ::core::mem::MaybeUninit::<VMStateDescription>::zeroed().assume_init() } 16 }; 17 18 qemu_api::declare_properties! { 19 PL011_PROPERTIES, 20 qemu_api::define_property!( 21 c"chardev", 22 PL011State, 23 char_backend, 24 unsafe { &qdev_prop_chr }, 25 CharBackend 26 ), 27 qemu_api::define_property!( 28 c"migrate-clk", 29 PL011State, 30 migrate_clock, 31 unsafe { &qdev_prop_bool }, 32 bool 33 ), 34 } 35 36 qemu_api::device_class_init! { 37 pl011_class_init, 38 props => PL011_PROPERTIES, 39 realize_fn => Some(pl011_realize), 40 legacy_reset_fn => Some(pl011_reset), 41 vmsd => VMSTATE_PL011, 42 } 43 44 /// # Safety 45 /// 46 /// We expect the FFI user of this function to pass a valid pointer, that has 47 /// the same size as [`PL011State`]. We also expect the device is 48 /// readable/writeable from one thread at any time. 49 pub unsafe extern "C" fn pl011_realize(dev: *mut DeviceState, _errp: *mut *mut Error) { 50 unsafe { 51 assert!(!dev.is_null()); 52 let mut state = NonNull::new_unchecked(dev.cast::<PL011State>()); 53 state.as_mut().realize(); 54 } 55 } 56 57 /// # Safety 58 /// 59 /// We expect the FFI user of this function to pass a valid pointer, that has 60 /// the same size as [`PL011State`]. We also expect the device is 61 /// readable/writeable from one thread at any time. 62 pub unsafe extern "C" fn pl011_reset(dev: *mut DeviceState) { 63 unsafe { 64 assert!(!dev.is_null()); 65 let mut state = NonNull::new_unchecked(dev.cast::<PL011State>()); 66 state.as_mut().reset(); 67 } 68 } 69