rust: chardev, qdev: add bindings to qdev_prop_set_chr

Because the argument to the function is an Owned<Chardev>, this also
adds an ObjectType implementation to Chardev.

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2025-02-03 11:04:07 +01:00
parent 61faf6ac7b
commit a22bd55ffd
5 changed files with 32 additions and 1 deletions

View file

@ -12,9 +12,10 @@ use qemu_api::{
bindings::{ bindings::{
error_fatal, qdev_prop_set_chr, qemu_chr_fe_accept_input, qemu_chr_fe_ioctl, error_fatal, qdev_prop_set_chr, qemu_chr_fe_accept_input, qemu_chr_fe_ioctl,
qemu_chr_fe_set_handlers, qemu_chr_fe_write_all, qemu_irq, sysbus_connect_irq, qemu_chr_fe_set_handlers, qemu_chr_fe_write_all, qemu_irq, sysbus_connect_irq,
sysbus_mmio_map, sysbus_realize, CharBackend, Chardev, QEMUChrEvent, sysbus_mmio_map, sysbus_realize, CharBackend, QEMUChrEvent,
CHR_IOCTL_SERIAL_SET_BREAK, CHR_IOCTL_SERIAL_SET_BREAK,
}, },
chardev::Chardev,
c_str, impl_vmstate_forward, c_str, impl_vmstate_forward,
irq::InterruptSource, irq::InterruptSource,
memory::{hwaddr, MemoryRegion, MemoryRegionOps, MemoryRegionOpsBuilder}, memory::{hwaddr, MemoryRegion, MemoryRegionOps, MemoryRegionOpsBuilder},

View file

@ -20,6 +20,7 @@ _qemu_api_rs = static_library(
'src/bitops.rs', 'src/bitops.rs',
'src/callbacks.rs', 'src/callbacks.rs',
'src/cell.rs', 'src/cell.rs',
'src/chardev.rs',
'src/c_str.rs', 'src/c_str.rs',
'src/irq.rs', 'src/irq.rs',
'src/memory.rs', 'src/memory.rs',

View file

@ -0,0 +1,19 @@
// Copyright 2024 Red Hat, Inc.
// Author(s): Paolo Bonzini <pbonzini@redhat.com>
// SPDX-License-Identifier: GPL-2.0-or-later
//! Bindings for character devices
use std::ffi::CStr;
use crate::{bindings, prelude::*};
pub type Chardev = bindings::Chardev;
pub type ChardevClass = bindings::ChardevClass;
unsafe impl ObjectType for Chardev {
type Class = ChardevClass;
const TYPE_NAME: &'static CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(bindings::TYPE_CHARDEV) };
}
qom_isa!(Chardev: Object);

View file

@ -18,6 +18,7 @@ pub mod bitops;
pub mod c_str; pub mod c_str;
pub mod callbacks; pub mod callbacks;
pub mod cell; pub mod cell;
pub mod chardev;
pub mod irq; pub mod irq;
pub mod memory; pub mod memory;
pub mod module; pub mod module;

View file

@ -16,6 +16,7 @@ use crate::{
bindings::{self, Error, ResettableClass}, bindings::{self, Error, ResettableClass},
callbacks::FnCall, callbacks::FnCall,
cell::bql_locked, cell::bql_locked,
chardev::Chardev,
prelude::*, prelude::*,
qom::{ClassInitImpl, ObjectClass, ObjectImpl, Owned}, qom::{ClassInitImpl, ObjectClass, ObjectImpl, Owned},
vmstate::VMStateDescription, vmstate::VMStateDescription,
@ -297,6 +298,14 @@ where
Owned::from(&*clk) Owned::from(&*clk)
} }
} }
fn prop_set_chr(&self, propname: &str, chr: &Owned<Chardev>) {
assert!(bql_locked());
let c_propname = CString::new(propname).unwrap();
unsafe {
bindings::qdev_prop_set_chr(self.as_mut_ptr(), c_propname.as_ptr(), chr.as_mut_ptr());
}
}
} }
impl<R: ObjectDeref> DeviceMethods for R where R::Target: IsA<DeviceState> {} impl<R: ObjectDeref> DeviceMethods for R where R::Target: IsA<DeviceState> {}