char: rename CharBackend->CharFrontend
The actual backend is "Chardev", CharBackend is the frontend side of it (whatever talks to the backend), let's rename it for readability. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Link: https://lore.kernel.org/r/20251022074612.1258413-1-marcandre.lureau@redhat.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
dc72ba5dc4
commit
1b21518f73
89 changed files with 428 additions and 429 deletions
|
|
@ -28,8 +28,8 @@ include!(concat!(env!("OUT_DIR"), "/bindings.inc.rs"));
|
|||
// BQL is taken, either directly or via `BqlCell` and `BqlRefCell`.
|
||||
// When bindings for character devices are introduced, this can be
|
||||
// moved to the Opaque<> wrapper in src/chardev.rs.
|
||||
unsafe impl Send for CharBackend {}
|
||||
unsafe impl Sync for CharBackend {}
|
||||
unsafe impl Send for CharFrontend {}
|
||||
unsafe impl Sync for CharFrontend {}
|
||||
|
||||
// SAFETY: this is a pure data struct
|
||||
unsafe impl Send for CoalescedMemoryRange {}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ include!(concat!(env!("OUT_DIR"), "/bindings.inc.rs"));
|
|||
// BQL is taken, either directly or via `BqlCell` and `BqlRefCell`.
|
||||
// When bindings for character devices are introduced, this can be
|
||||
// moved to the Opaque<> wrapper in src/chardev.rs.
|
||||
unsafe impl Send for CharBackend {}
|
||||
unsafe impl Sync for CharBackend {}
|
||||
unsafe impl Send for CharFrontend {}
|
||||
unsafe impl Sync for CharFrontend {}
|
||||
|
||||
unsafe impl Zeroable for CharBackend {}
|
||||
unsafe impl Zeroable for CharFrontend {}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
//!
|
||||
//! Character devices in QEMU can run under the big QEMU lock or in a separate
|
||||
//! `GMainContext`. Here we only support the former, because the bindings
|
||||
//! enforce that the BQL is taken whenever the functions in [`CharBackend`] are
|
||||
//! enforce that the BQL is taken whenever the functions in [`CharFrontend`] are
|
||||
//! called.
|
||||
|
||||
use std::{
|
||||
|
|
@ -32,25 +32,25 @@ pub struct Chardev(Opaque<bindings::Chardev>);
|
|||
pub type ChardevClass = bindings::ChardevClass;
|
||||
pub type Event = bindings::QEMUChrEvent;
|
||||
|
||||
/// A safe wrapper around [`bindings::CharBackend`], denoting the character
|
||||
/// A safe wrapper around [`bindings::CharFrontend`], denoting the character
|
||||
/// back-end that is used for example by a device. Compared to the
|
||||
/// underlying C struct it adds BQL protection, and is marked as pinned
|
||||
/// because the QOM object ([`bindings::Chardev`]) contains a pointer to
|
||||
/// the `CharBackend`.
|
||||
pub struct CharBackend {
|
||||
inner: BqlRefCell<bindings::CharBackend>,
|
||||
/// the `CharFrontend`.
|
||||
pub struct CharFrontend {
|
||||
inner: BqlRefCell<bindings::CharFrontend>,
|
||||
_pin: PhantomPinned,
|
||||
}
|
||||
|
||||
pub struct CharBackendMut<'a>(BqlRefMut<'a, bindings::CharBackend>);
|
||||
pub struct CharFrontendMut<'a>(BqlRefMut<'a, bindings::CharFrontend>);
|
||||
|
||||
impl Write for CharBackendMut<'_> {
|
||||
impl Write for CharFrontendMut<'_> {
|
||||
fn flush(&mut self) -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||||
let chr: &mut bindings::CharBackend = &mut self.0;
|
||||
let chr: &mut bindings::CharFrontend = &mut self.0;
|
||||
|
||||
let len = buf.len().try_into().unwrap();
|
||||
let r = unsafe { bindings::qemu_chr_fe_write(addr_of_mut!(*chr), buf.as_ptr(), len) };
|
||||
|
|
@ -58,7 +58,7 @@ impl Write for CharBackendMut<'_> {
|
|||
}
|
||||
|
||||
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
|
||||
let chr: &mut bindings::CharBackend = &mut self.0;
|
||||
let chr: &mut bindings::CharFrontend = &mut self.0;
|
||||
|
||||
let len = buf.len().try_into().unwrap();
|
||||
let r = unsafe { bindings::qemu_chr_fe_write_all(addr_of_mut!(*chr), buf.as_ptr(), len) };
|
||||
|
|
@ -72,7 +72,7 @@ impl Write for CharBackendMut<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
impl Debug for CharBackend {
|
||||
impl Debug for CharFrontend {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
// SAFETY: accessed just to print the values
|
||||
let chr = self.inner.as_ptr();
|
||||
|
|
@ -81,13 +81,13 @@ impl Debug for CharBackend {
|
|||
}
|
||||
|
||||
// FIXME: use something like PinnedDrop from the pinned_init crate
|
||||
impl Drop for CharBackend {
|
||||
impl Drop for CharFrontend {
|
||||
fn drop(&mut self) {
|
||||
self.disable_handlers();
|
||||
}
|
||||
}
|
||||
|
||||
impl CharBackend {
|
||||
impl CharFrontend {
|
||||
/// Enable the front-end's character device handlers, if there is an
|
||||
/// associated `Chardev`.
|
||||
pub fn enable_handlers<
|
||||
|
|
@ -198,7 +198,7 @@ impl CharBackend {
|
|||
/// the big QEMU lock while the character device is borrowed, as
|
||||
/// that might cause C code to write to the character device.
|
||||
pub fn borrow_mut(&self) -> impl Write + '_ {
|
||||
CharBackendMut(self.inner.borrow_mut())
|
||||
CharFrontendMut(self.inner.borrow_mut())
|
||||
}
|
||||
|
||||
/// Send a continuous stream of zero bits on the line if `enabled` is
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
use std::{ffi::CStr, mem::size_of};
|
||||
|
||||
use bql::BqlRefCell;
|
||||
use chardev::{CharBackend, Chardev, Event};
|
||||
use chardev::{CharFrontend, Chardev, Event};
|
||||
use common::{static_assert, uninit_field_mut};
|
||||
use hwcore::{
|
||||
Clock, ClockEvent, DeviceImpl, DeviceMethods, DeviceState, IRQState, InterruptSource,
|
||||
|
|
@ -106,7 +106,7 @@ pub struct PL011State {
|
|||
pub iomem: MemoryRegion,
|
||||
#[doc(alias = "chr")]
|
||||
#[property(rename = "chardev")]
|
||||
pub char_backend: CharBackend,
|
||||
pub char_frontend: CharFrontend,
|
||||
pub regs: BqlRefCell<PL011Registers>,
|
||||
/// QEMU interrupts
|
||||
///
|
||||
|
|
@ -240,7 +240,7 @@ impl PL011Registers {
|
|||
}
|
||||
let update = (self.line_control.send_break() != new_val.send_break()) && {
|
||||
let break_enable = new_val.send_break();
|
||||
let _ = device.char_backend.send_break(break_enable);
|
||||
let _ = device.char_frontend.send_break(break_enable);
|
||||
self.loopback_break(break_enable)
|
||||
};
|
||||
self.line_control = new_val;
|
||||
|
|
@ -561,7 +561,7 @@ impl PL011State {
|
|||
trace::trace_pl011_read(offset, result, c"");
|
||||
if update_irq {
|
||||
self.update();
|
||||
self.char_backend.accept_input();
|
||||
self.char_frontend.accept_input();
|
||||
}
|
||||
result.into()
|
||||
}
|
||||
|
|
@ -579,7 +579,7 @@ impl PL011State {
|
|||
let ch: [u8; 1] = [value as u8];
|
||||
// XXX this blocks entire thread. Rewrite to use
|
||||
// qemu_chr_fe_write and background I/O callbacks
|
||||
let _ = self.char_backend.write_all(&ch);
|
||||
let _ = self.char_frontend.write_all(&ch);
|
||||
}
|
||||
|
||||
update_irq = self.regs.borrow_mut().write(field, value as u32, self);
|
||||
|
|
@ -645,7 +645,7 @@ impl PL011State {
|
|||
}
|
||||
|
||||
fn realize(&self) -> util::Result<()> {
|
||||
self.char_backend
|
||||
self.char_frontend
|
||||
.enable_handlers(self, Self::can_receive, Self::receive, Self::event);
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ impl_qdev_prop!(u64, qdev_prop_uint64, qdev_prop_bit64);
|
|||
impl_qdev_prop!(usize, qdev_prop_usize);
|
||||
impl_qdev_prop!(i32, qdev_prop_int32);
|
||||
impl_qdev_prop!(i64, qdev_prop_int64);
|
||||
impl_qdev_prop!(chardev::CharBackend, qdev_prop_chr);
|
||||
impl_qdev_prop!(chardev::CharFrontend, qdev_prop_chr);
|
||||
|
||||
/// Trait to define device properties.
|
||||
///
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue