mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-05 08:43:55 -06:00
rust: pl011: extract CharBackend receive logic into a separate function
Prepare for moving all references to the registers and the FIFO into a separate struct. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
6d314cc045
commit
137612772e
1 changed files with 9 additions and 6 deletions
|
@ -6,7 +6,7 @@ use core::ptr::{addr_of, addr_of_mut, NonNull};
|
||||||
use std::{
|
use std::{
|
||||||
ffi::CStr,
|
ffi::CStr,
|
||||||
ops::ControlFlow,
|
ops::ControlFlow,
|
||||||
os::raw::{c_int, c_uint, c_void},
|
os::raw::{c_int, c_void},
|
||||||
};
|
};
|
||||||
|
|
||||||
use qemu_api::{
|
use qemu_api::{
|
||||||
|
@ -478,6 +478,12 @@ impl PL011State {
|
||||||
self.read_count < self.fifo_depth()
|
self.read_count < self.fifo_depth()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn receive(&mut self, ch: u32) {
|
||||||
|
if !self.loopback_enabled() {
|
||||||
|
self.put_fifo(ch)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn event(&mut self, event: QEMUChrEvent) {
|
pub fn event(&mut self, event: QEMUChrEvent) {
|
||||||
if event == QEMUChrEvent::CHR_EVENT_BREAK && !self.loopback_enabled() {
|
if event == QEMUChrEvent::CHR_EVENT_BREAK && !self.loopback_enabled() {
|
||||||
self.put_fifo(registers::Data::BREAK.into());
|
self.put_fifo(registers::Data::BREAK.into());
|
||||||
|
@ -503,7 +509,7 @@ impl PL011State {
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn put_fifo(&mut self, value: c_uint) {
|
pub fn put_fifo(&mut self, value: u32) {
|
||||||
let depth = self.fifo_depth();
|
let depth = self.fifo_depth();
|
||||||
assert!(depth > 0);
|
assert!(depth > 0);
|
||||||
let slot = (self.read_pos + self.read_count) & (depth - 1);
|
let slot = (self.read_pos + self.read_count) & (depth - 1);
|
||||||
|
@ -626,12 +632,9 @@ pub unsafe extern "C" fn pl011_can_receive(opaque: *mut c_void) -> c_int {
|
||||||
pub unsafe extern "C" fn pl011_receive(opaque: *mut c_void, buf: *const u8, size: c_int) {
|
pub unsafe extern "C" fn pl011_receive(opaque: *mut c_void, buf: *const u8, size: c_int) {
|
||||||
let mut state = NonNull::new(opaque).unwrap().cast::<PL011State>();
|
let mut state = NonNull::new(opaque).unwrap().cast::<PL011State>();
|
||||||
unsafe {
|
unsafe {
|
||||||
if state.as_ref().loopback_enabled() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if size > 0 {
|
if size > 0 {
|
||||||
debug_assert!(!buf.is_null());
|
debug_assert!(!buf.is_null());
|
||||||
state.as_mut().put_fifo(c_uint::from(buf.read_volatile()))
|
state.as_mut().receive(u32::from(buf.read_volatile()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue