mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-08 02:03:56 -06:00
rust: pl011: use the bits macro
This avoids the repeated ".0" when using the Interrupt struct. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
648fe157d3
commit
9c8ff2a1ed
5 changed files with 49 additions and 44 deletions
1
rust/Cargo.lock
generated
1
rust/Cargo.lock
generated
|
@ -73,6 +73,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bilge",
|
"bilge",
|
||||||
"bilge-impl",
|
"bilge-impl",
|
||||||
|
"bits",
|
||||||
"qemu_api",
|
"qemu_api",
|
||||||
"qemu_api_macros",
|
"qemu_api_macros",
|
||||||
]
|
]
|
||||||
|
|
|
@ -18,6 +18,7 @@ crate-type = ["staticlib"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bilge = { version = "0.2.0" }
|
bilge = { version = "0.2.0" }
|
||||||
bilge-impl = { version = "0.2.0" }
|
bilge-impl = { version = "0.2.0" }
|
||||||
|
bits = { path = "../../../bits" }
|
||||||
qemu_api = { path = "../../../qemu-api" }
|
qemu_api = { path = "../../../qemu-api" }
|
||||||
qemu_api_macros = { path = "../../../qemu-api-macros" }
|
qemu_api_macros = { path = "../../../qemu-api-macros" }
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ _libpl011_rs = static_library(
|
||||||
dependencies: [
|
dependencies: [
|
||||||
bilge_rs,
|
bilge_rs,
|
||||||
bilge_impl_rs,
|
bilge_impl_rs,
|
||||||
|
bits_rs,
|
||||||
qemu_api,
|
qemu_api,
|
||||||
qemu_api_macros,
|
qemu_api_macros,
|
||||||
],
|
],
|
||||||
|
|
|
@ -85,8 +85,8 @@ pub struct PL011Registers {
|
||||||
#[doc(alias = "cr")]
|
#[doc(alias = "cr")]
|
||||||
pub control: registers::Control,
|
pub control: registers::Control,
|
||||||
pub dmacr: u32,
|
pub dmacr: u32,
|
||||||
pub int_enabled: u32,
|
pub int_enabled: Interrupt,
|
||||||
pub int_level: u32,
|
pub int_level: Interrupt,
|
||||||
pub read_fifo: Fifo,
|
pub read_fifo: Fifo,
|
||||||
pub ilpr: u32,
|
pub ilpr: u32,
|
||||||
pub ibrd: u32,
|
pub ibrd: u32,
|
||||||
|
@ -199,9 +199,9 @@ impl PL011Registers {
|
||||||
LCR_H => u32::from(self.line_control),
|
LCR_H => u32::from(self.line_control),
|
||||||
CR => u32::from(self.control),
|
CR => u32::from(self.control),
|
||||||
FLS => self.ifl,
|
FLS => self.ifl,
|
||||||
IMSC => self.int_enabled,
|
IMSC => u32::from(self.int_enabled),
|
||||||
RIS => self.int_level,
|
RIS => u32::from(self.int_level),
|
||||||
MIS => self.int_level & self.int_enabled,
|
MIS => u32::from(self.int_level & self.int_enabled),
|
||||||
ICR => {
|
ICR => {
|
||||||
// "The UARTICR Register is the interrupt clear register and is write-only"
|
// "The UARTICR Register is the interrupt clear register and is write-only"
|
||||||
// Source: ARM DDI 0183G 3.3.13 Interrupt Clear Register, UARTICR
|
// Source: ARM DDI 0183G 3.3.13 Interrupt Clear Register, UARTICR
|
||||||
|
@ -263,13 +263,13 @@ impl PL011Registers {
|
||||||
self.set_read_trigger();
|
self.set_read_trigger();
|
||||||
}
|
}
|
||||||
IMSC => {
|
IMSC => {
|
||||||
self.int_enabled = value;
|
self.int_enabled = Interrupt::from(value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
RIS => {}
|
RIS => {}
|
||||||
MIS => {}
|
MIS => {}
|
||||||
ICR => {
|
ICR => {
|
||||||
self.int_level &= !value;
|
self.int_level &= !Interrupt::from(value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
DMACR => {
|
DMACR => {
|
||||||
|
@ -295,7 +295,7 @@ impl PL011Registers {
|
||||||
self.flags.set_receive_fifo_empty(true);
|
self.flags.set_receive_fifo_empty(true);
|
||||||
}
|
}
|
||||||
if self.read_count + 1 == self.read_trigger {
|
if self.read_count + 1 == self.read_trigger {
|
||||||
self.int_level &= !Interrupt::RX.0;
|
self.int_level &= !Interrupt::RX;
|
||||||
}
|
}
|
||||||
self.receive_status_error_clear.set_from_data(c);
|
self.receive_status_error_clear.set_from_data(c);
|
||||||
*update = true;
|
*update = true;
|
||||||
|
@ -305,7 +305,7 @@ impl PL011Registers {
|
||||||
fn write_data_register(&mut self, value: u32) -> bool {
|
fn write_data_register(&mut self, value: u32) -> bool {
|
||||||
// interrupts always checked
|
// interrupts always checked
|
||||||
let _ = self.loopback_tx(value.into());
|
let _ = self.loopback_tx(value.into());
|
||||||
self.int_level |= Interrupt::TX.0;
|
self.int_level |= Interrupt::TX;
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,19 +361,19 @@ impl PL011Registers {
|
||||||
// Change interrupts based on updated FR
|
// Change interrupts based on updated FR
|
||||||
let mut il = self.int_level;
|
let mut il = self.int_level;
|
||||||
|
|
||||||
il &= !Interrupt::MS.0;
|
il &= !Interrupt::MS;
|
||||||
|
|
||||||
if self.flags.data_set_ready() {
|
if self.flags.data_set_ready() {
|
||||||
il |= Interrupt::DSR.0;
|
il |= Interrupt::DSR;
|
||||||
}
|
}
|
||||||
if self.flags.data_carrier_detect() {
|
if self.flags.data_carrier_detect() {
|
||||||
il |= Interrupt::DCD.0;
|
il |= Interrupt::DCD;
|
||||||
}
|
}
|
||||||
if self.flags.clear_to_send() {
|
if self.flags.clear_to_send() {
|
||||||
il |= Interrupt::CTS.0;
|
il |= Interrupt::CTS;
|
||||||
}
|
}
|
||||||
if self.flags.ring_indicator() {
|
if self.flags.ring_indicator() {
|
||||||
il |= Interrupt::RI.0;
|
il |= Interrupt::RI;
|
||||||
}
|
}
|
||||||
self.int_level = il;
|
self.int_level = il;
|
||||||
true
|
true
|
||||||
|
@ -391,8 +391,8 @@ impl PL011Registers {
|
||||||
self.line_control.reset();
|
self.line_control.reset();
|
||||||
self.receive_status_error_clear.reset();
|
self.receive_status_error_clear.reset();
|
||||||
self.dmacr = 0;
|
self.dmacr = 0;
|
||||||
self.int_enabled = 0;
|
self.int_enabled = 0.into();
|
||||||
self.int_level = 0;
|
self.int_level = 0.into();
|
||||||
self.ilpr = 0;
|
self.ilpr = 0;
|
||||||
self.ibrd = 0;
|
self.ibrd = 0;
|
||||||
self.fbrd = 0;
|
self.fbrd = 0;
|
||||||
|
@ -451,7 +451,7 @@ impl PL011Registers {
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.read_count == self.read_trigger {
|
if self.read_count == self.read_trigger {
|
||||||
self.int_level |= Interrupt::RX.0;
|
self.int_level |= Interrupt::RX;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
|
@ -632,7 +632,7 @@ impl PL011State {
|
||||||
let regs = self.regs.borrow();
|
let regs = self.regs.borrow();
|
||||||
let flags = regs.int_level & regs.int_enabled;
|
let flags = regs.int_level & regs.int_enabled;
|
||||||
for (irq, i) in self.interrupts.iter().zip(IRQMASK) {
|
for (irq, i) in self.interrupts.iter().zip(IRQMASK) {
|
||||||
irq.set(flags & i != 0);
|
irq.set(flags.any_set(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -642,14 +642,13 @@ impl PL011State {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Which bits in the interrupt status matter for each outbound IRQ line ?
|
/// Which bits in the interrupt status matter for each outbound IRQ line ?
|
||||||
const IRQMASK: [u32; 6] = [
|
const IRQMASK: [Interrupt; 6] = [
|
||||||
/* combined IRQ */
|
Interrupt::all(),
|
||||||
Interrupt::E.0 | Interrupt::MS.0 | Interrupt::RT.0 | Interrupt::TX.0 | Interrupt::RX.0,
|
Interrupt::RX,
|
||||||
Interrupt::RX.0,
|
Interrupt::TX,
|
||||||
Interrupt::TX.0,
|
Interrupt::RT,
|
||||||
Interrupt::RT.0,
|
Interrupt::MS,
|
||||||
Interrupt::MS.0,
|
Interrupt::E,
|
||||||
Interrupt::E.0,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/// # Safety
|
/// # Safety
|
||||||
|
|
|
@ -9,7 +9,8 @@
|
||||||
// https://developer.arm.com/documentation/ddi0183/latest/
|
// https://developer.arm.com/documentation/ddi0183/latest/
|
||||||
|
|
||||||
use bilge::prelude::*;
|
use bilge::prelude::*;
|
||||||
use qemu_api::impl_vmstate_bitsized;
|
use bits::bits;
|
||||||
|
use qemu_api::{impl_vmstate_bitsized, impl_vmstate_forward};
|
||||||
|
|
||||||
/// Offset of each register from the base memory address of the device.
|
/// Offset of each register from the base memory address of the device.
|
||||||
#[doc(alias = "offset")]
|
#[doc(alias = "offset")]
|
||||||
|
@ -326,22 +327,24 @@ impl Default for Control {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bits! {
|
||||||
/// Interrupt status bits in UARTRIS, UARTMIS, UARTIMSC
|
/// Interrupt status bits in UARTRIS, UARTMIS, UARTIMSC
|
||||||
pub struct Interrupt(pub u32);
|
#[derive(Default)]
|
||||||
|
pub struct Interrupt(u32) {
|
||||||
|
OE = 1 << 10,
|
||||||
|
BE = 1 << 9,
|
||||||
|
PE = 1 << 8,
|
||||||
|
FE = 1 << 7,
|
||||||
|
RT = 1 << 6,
|
||||||
|
TX = 1 << 5,
|
||||||
|
RX = 1 << 4,
|
||||||
|
DSR = 1 << 3,
|
||||||
|
DCD = 1 << 2,
|
||||||
|
CTS = 1 << 1,
|
||||||
|
RI = 1 << 0,
|
||||||
|
|
||||||
impl Interrupt {
|
E = bits!(Self as u32: OE | BE | PE | FE),
|
||||||
pub const OE: Self = Self(1 << 10);
|
MS = bits!(Self as u32: RI | DSR | DCD | CTS),
|
||||||
pub const BE: Self = Self(1 << 9);
|
|
||||||
pub const PE: Self = Self(1 << 8);
|
|
||||||
pub const FE: Self = Self(1 << 7);
|
|
||||||
pub const RT: Self = Self(1 << 6);
|
|
||||||
pub const TX: Self = Self(1 << 5);
|
|
||||||
pub const RX: Self = Self(1 << 4);
|
|
||||||
pub const DSR: Self = Self(1 << 3);
|
|
||||||
pub const DCD: Self = Self(1 << 2);
|
|
||||||
pub const CTS: Self = Self(1 << 1);
|
|
||||||
pub const RI: Self = Self(1 << 0);
|
|
||||||
|
|
||||||
pub const E: Self = Self(Self::OE.0 | Self::BE.0 | Self::PE.0 | Self::FE.0);
|
|
||||||
pub const MS: Self = Self(Self::RI.0 | Self::DSR.0 | Self::DCD.0 | Self::CTS.0);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
impl_vmstate_forward!(Interrupt);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue