Skip to content

Commit

Permalink
refac(d1): don't repeat PLIC MIE indexing (#312)
Browse files Browse the repository at this point in the history
I just thought this was a little nicer...
  • Loading branch information
hawkw committed Apr 15, 2024
1 parent a12e31f commit df41dec
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions platforms/allwinner-d1/d1-core/src/plic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,14 @@ impl Plic {
///
/// May effect normal interrupt processing
pub unsafe fn unmask(&self, interrupt: Interrupt) {
let nr = interrupt.into_bits() as usize;
let (reg_offset, irq_en) = (nr / 32, 1 << (nr % 32));
self.plic.mie[reg_offset].modify(|r, w| w.bits(r.bits() | irq_en));
let (mie, irq_en) = self.index_mie(interrupt);
mie.modify(|r, w| w.bits(r.bits() | irq_en));
}

/// Disable an interrupt
pub fn mask(&self, interrupt: Interrupt) {
let nr = interrupt.into_bits() as usize;
let (reg_offset, irq_en) = (nr / 32, 1 << (nr % 32));
self.plic.mie[reg_offset].modify(|r, w| unsafe { w.bits(r.bits() & !irq_en) });
let (mie, irq_en) = self.index_mie(interrupt);
mie.modify(|r, w| unsafe { w.bits(r.bits() | irq_en) });
}

/// Globally set priority for one interrupt
Expand Down Expand Up @@ -151,6 +149,12 @@ impl Plic {
Ok(())
}
}

#[inline(always)]
fn index_mie(&self, interrupt: Interrupt) -> (&plic::MIE, u32) {
let nr = interrupt.into_bits() as usize;
(&self.plic.mie[nr / 32], 1 << (nr % 32))
}
}

/// Bit conversions
Expand Down

0 comments on commit df41dec

Please sign in to comment.