kernel: use wfi() on Renode

While it would be nice if we stopped the PLLs as we do on hardware,
Renode does not yet have the ability to issue the `wfi` instruction from
a peripheral write.

As such, directly call `wfi()` on Renode similar to how Cramium
operates.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2023-12-24 15:20:11 +08:00
parent 7087b8f018
commit a19b1b4f51

View file

@ -6,20 +6,20 @@ use riscv::register::{satp, sie, sstatus};
pub mod exception; pub mod exception;
pub mod irq; pub mod irq;
pub mod mem; pub mod mem;
pub mod panic;
pub mod process; pub mod process;
pub mod syscall; pub mod syscall;
pub mod panic;
pub use process::Thread; pub use process::Thread;
#[cfg(any(feature="precursor", feature="renode"))]
use utralib::generated::*;
#[cfg(any(feature="precursor", feature="renode"))]
use xous_kernel::{MemoryFlags, MemoryType, PID};
#[cfg(any(feature = "precursor", feature = "renode"))] #[cfg(any(feature = "precursor", feature = "renode"))]
use crate::mem::MemoryManager; use crate::mem::MemoryManager;
#[cfg(any(feature = "precursor", feature = "renode"))]
use utralib::generated::*;
#[cfg(any(feature = "cramium-soc", feature = "cramium-fpga"))] #[cfg(any(feature = "cramium-soc", feature = "cramium-fpga"))]
use xous_kernel::PID; use xous_kernel::PID;
#[cfg(any(feature = "precursor", feature = "renode"))]
use xous_kernel::{MemoryFlags, MemoryType, PID};
#[cfg(any(feature = "precursor", feature = "renode"))] #[cfg(any(feature = "precursor", feature = "renode"))]
pub const WFI_KERNEL: Wfi = Wfi { pub const WFI_KERNEL: Wfi = Wfi {
@ -64,17 +64,17 @@ pub fn init() {
/// Put the core to sleep until an interrupt hits. Returns `true` /// Put the core to sleep until an interrupt hits. Returns `true`
/// to indicate the kernel should not exit. /// to indicate the kernel should not exit.
pub fn idle() -> bool { pub fn idle() -> bool {
#[cfg(any(feature="precursor", feature="renode"))]
let mut wfi_kernel_csr = CSR::new(WFI_KERNEL.base as *mut u32);
// Issue `wfi`. This will return as soon as an external interrupt // Issue `wfi`. This will return as soon as an external interrupt
// is available. // is available.
#[cfg(any(feature="cramium-fpga", feature="cramium-soc"))] #[cfg(any(feature = "cramium-fpga", feature = "cramium-soc", feature = "renode"))]
// "traditional" path for stopping a clock // "traditional" path for stopping a clock
unsafe { riscv::asm::wfi() }; unsafe {
riscv::asm::wfi()
};
#[cfg(any(feature="precursor", feature="renode"))] #[cfg(any(feature = "precursor"))]
{ {
let mut wfi_kernel_csr = CSR::new(WFI_KERNEL.base as *mut u32);
// this invokes Precusor-SoC specific path to gate clocks: // this invokes Precusor-SoC specific path to gate clocks:
// 1. ignore_locked prevents the chip from going into reset if the PLL goes unlocked // 1. ignore_locked prevents the chip from going into reset if the PLL goes unlocked
wfi_kernel_csr.wfo(utra::wfi::IGNORE_LOCKED_IGNORE_LOCKED, 1); wfi_kernel_csr.wfo(utra::wfi::IGNORE_LOCKED_IGNORE_LOCKED, 1);