diff --git a/loader/src/main.rs b/loader/src/main.rs index 7f7b791c9..d853566a3 100644 --- a/loader/src/main.rs +++ b/loader/src/main.rs @@ -1068,10 +1068,103 @@ pub unsafe extern "C" fn rust_entry(arg_buffer: *const usize, signature: u32) -> boot_sequence(kab, signature); } +fn memtest() { + let ram_ptr: *mut u32 = 0x4000_0000 as *mut u32; + let sram_ptr: *mut u32 = 0x1000_0000 as *mut u32; + use utralib::generated::*; + + let mut sram_csr = CSR::new(utra::sram_ext::HW_SRAM_EXT_BASE as *mut u32); + sram_csr.wfo(utra::sram_ext::READ_CONFIG_TRIGGER, 1); + + // give some time for the status to read + for i in 0..8 { + unsafe { sram_ptr.add(i).write_volatile(i as u32) }; + } + + println!("status: 0x{:08x}", sram_csr.rf(utra::sram_ext::CONFIG_STATUS_MODE)); + + for i in 0..(256*1024/4) { + unsafe { + ram_ptr.add(i).write_volatile( (0xACE0_0000 + i) as u32 ); + } + } + + let mut errcnt = 0; + for i in 0..(256*1024/4) { + unsafe { + let rd = ram_ptr.add(i).read_volatile(); + if rd != (0xACE0_0000 + i) as u32 { + if errcnt < 16 || ((errcnt % 256) == 0) { + println!("* 0x{:08x}: e:0x{:08x} o:0x{:08x}", i*4, 0xACE0_0000 + i, rd); + } + errcnt += 1; + } else if (i & 0x1FFF) == 8 { + println!(" 0x{:08x}: e:0x{:08x} o:0x{:08x}", i*4, 0xACE0_0000 + i, rd); + }; + } + } + // TRNG virtual memory mapping already set up, but we pump values out just to make sure + // the pipeline is fresh. Simulations show this isn't necessary, but I feel paranoid; + // I worry a subtle bug in the reset logic could leave deterministic values in the pipeline. + for _k in 0..8 { + let trng_csr = CSR::new(utra::trng_kernel::HW_TRNG_KERNEL_BASE as *mut u32); + for i in 0x3E_0000..0x3F_0000 { + while trng_csr.rf(utra::trng_kernel::URANDOM_VALID_URANDOM_VALID) == 0 {} + unsafe { + ram_ptr.add(i).write_volatile(trng_csr.rf(utra::trng_kernel::URANDOM_URANDOM)); + } + } + for i in 0x3D_0000..0x3E_0000 { + unsafe { + ram_ptr.add(i).write_volatile(ram_ptr.add(i + 0x10000).read_volatile()); + } + } + let basecnt = errcnt; + println!("** take one **"); + for i in 0x3D_0000..0x3E_0000 { + let rd1 = unsafe{ram_ptr.add(i).read_volatile()}; + let rd2 = unsafe{ram_ptr.add(i+0x10000).read_volatile()}; + if rd1 != rd2 { + if errcnt < 16 + basecnt || ((errcnt % 256) == 0) { + println!("* 0x{:08x}: rd1:0x{:08x} rd2:0x{:08x}", i*4, rd1, rd2); + } + errcnt += 1; + } else if (i & 0x1FFF) == 12 { + println!(" 0x{:08x}: rd1:0x{:08x} rd2:0x{:08x}", i*4, rd1, rd2); + } + } + println!("** take two (check for read errors)**"); + let basecnt = errcnt; + for i in 0x3D_0000..0x3E_0000 { + let rd1 = unsafe{ram_ptr.add(i).read_volatile()}; + let rd2 = unsafe{ram_ptr.add(i+0x10000).read_volatile()}; + if rd1 != rd2 { + if errcnt < 16 + basecnt || ((errcnt % 256) == 0) { + println!("* 0x{:08x}: rd1:0x{:08x} rd2:0x{:08x}", i*4, rd1, rd2); + } + errcnt += 1; + } else if (i & 0x1FFF) == 12 { + println!(" 0x{:08x}: rd1:0x{:08x} rd2:0x{:08x}", i*4, rd1, rd2); + } + } + } + + if errcnt != 0 { + println!("error count: {}", errcnt); + println!("0x01000: {:08x}", unsafe{ ram_ptr.add(0x1000/4).read_volatile() }); + println!("0x00000: {:08x}", unsafe{ ram_ptr.add(0x0).read_volatile() }); + println!("0x0FFFC: {:08x}", unsafe{ ram_ptr.add(0xFFFC/4).read_volatile() }); + println!("0xfdff04: {:08x}", unsafe{ ram_ptr.add(0xfdff04/4).read_volatile() }); + } +} + fn boot_sequence(args: KernelArguments, _signature: u32) -> ! { // Store the initial boot config on the stack. We don't know // where in heap this memory will go. #[allow(clippy::cast_ptr_alignment)] // This test only works on 32-bit systems + if false { + memtest(); + } let mut cfg = BootConfig { base_addr: args.base as *const usize, args, diff --git a/precursors/soc.svd b/precursors/soc.svd index a1b1021df..0e00afddd 100755 --- a/precursors/soc.svd +++ b/precursors/soc.svd @@ -3,7 +3,7 @@ litex SOC - + 8 32 @@ -1222,10 +1222,10 @@ register to disable individual events.]]> GIT_GITREV 0x0014 - 0x977355ba + 0xafcc1323 32 @@ -1242,7 +1242,7 @@ the exact git version used to build this firmware.]]> is ``1``, then the repository this was built from has one additional commit beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]> 0x0018 - 0x26 + 0x2a 32 @@ -3467,7 +3467,7 @@ inject too fast.]]> SEED1 0x0000 - 0x698bb704 + 0x6d48a16e 32 @@ -3482,7 +3482,7 @@ inject too fast.]]> SEED0 0x0004 - 0x5d2ea7df + 0x71a7a0e3 32 @@ -3535,10 +3535,40 @@ inject too fast.]]> + + LOCKADDR + + 0x0008 + 0x00 + 32 + + + lockaddr + 7 + [7:0] + 0 + + + + + LOCKSTAT + + 0x000c + 0x00 + 32 + + + lockstat + 0 + [0:0] + 0 + + + 0 - 0x8 + 0x10 registers @@ -6973,7 +7003,7 @@ of the PLL]]> SRAM 0x10000000 - 0x00020000 + 0x00004000 VEXRISCV_DEBUG diff --git a/precursors/soc_csr.bin b/precursors/soc_csr.bin index 1636496a5..84679bdec 100755 Binary files a/precursors/soc_csr.bin and b/precursors/soc_csr.bin differ diff --git a/services/engine-sha512/src/lib.rs b/services/engine-sha512/src/lib.rs index b036b98a6..fb2edc2e1 100644 --- a/services/engine-sha512/src/lib.rs +++ b/services/engine-sha512/src/lib.rs @@ -160,6 +160,9 @@ macro_rules! sha512_comms { panic!("Internal error in AcquireExclusive"); } } + } else if self.strategy == FallbackStrategy::SoftwareOnly { + self.use_soft = true; + self.in_progress = true; } } pub(crate) fn reset_hw(&mut self) { diff --git a/services/shellchat/src/cmds/aes.rs b/services/shellchat/src/cmds/aes.rs index c7d4c0d76..46e5c0921 100644 --- a/services/shellchat/src/cmds/aes.rs +++ b/services/shellchat/src/cmds/aes.rs @@ -134,6 +134,10 @@ software: -151mA @ 100% CPU usage, 158.36us/block enc+dec AES128 (500 iters, 819 hardware: -148mA @ 100% CPU usage, 103.73us/block enc+dec AES256 (500 iters, 8192 len) software: -149mA @ 100% CPU usage, 217.95us/block enc+dec AES256 (500 iters, 8192 len) + +with L2 cache on: +hardware 92.24us/block enc+dec aes256 (500 iters, 8192 len) +software 158.48us/block enc+dec aes256 (500 iters, 8192 len) */ pub fn benchmark_thread(sid0: usize, sid1: usize, sid2: usize, sid3: usize) { let sid = xous::SID::from_u32(sid0 as u32, sid1 as u32, sid2 as u32, sid3 as u32); diff --git a/services/shellchat/src/cmds/engine.rs b/services/shellchat/src/cmds/engine.rs index dbae78d45..226044bb3 100644 --- a/services/shellchat/src/cmds/engine.rs +++ b/services/shellchat/src/cmds/engine.rs @@ -159,6 +159,7 @@ pub fn benchmark_thread(sid0: usize, sid1: usize, sid2: usize, sid3: usize) { 26ms/2xop (200 iters -hw) -- affine done in hardware 13.54ms/2xop (200 iters -hw) -- microcode pre-loaded, minimal registers transferred using MontgomeryJob call + 12.2ms/2xop (200 iters -hw) -- with L2 cache on */ Some(BenchOp::StartDh) => { let mut passes = 0; diff --git a/services/shellchat/src/cmds/sha.rs b/services/shellchat/src/cmds/sha.rs index 72fb089e9..ef0f86138 100644 --- a/services/shellchat/src/cmds/sha.rs +++ b/services/shellchat/src/cmds/sha.rs @@ -35,6 +35,9 @@ TEST_MAX_LEN = 1024 (fixed length) / TEST_ITERS = 1000: hw 7.257ms/hash, sw 11.6 TEST_MAX_LEN = 8192 (random length) / TEST_ITERS = 1000: hw 10.528ms/hash, sw 40.631ms/hash TEST_MAX_LEN = 8192 (fixed length) / TEST_ITERS = 1000: hw 17.035ms/hash, sw 78.633ms/hash +with L2 cache on: +TEST_MAX_LEN = 8192 (fixed length) / TEST_ITERS = 1000: hw 13.798ms/hash, sw 29.034ms/hash + power consumption - 4.1V system voltage 159mA nominal diff --git a/services/susres/src/main.rs b/services/susres/src/main.rs index a53c1cca6..3334a3767 100644 --- a/services/susres/src/main.rs +++ b/services/susres/src/main.rs @@ -79,6 +79,14 @@ mod implementation { reboot_csr.wfo(utra::reboot::SOC_RESET_SOC_RESET, 0xAC); } + // flush the L2 cache by writing 0's to a region of memory that matches the L2 cache size + if let Some(cf) = sr.cacheflush { + let cf_ptr = cf.as_ptr() as *mut u32; + for i in 0..(cf.len() / 4) { + unsafe {cf_ptr.add(i).write_volatile(0); } + } + } + // power the system down - this should result in an almost immediate loss of power sr.csr.wfo(utra::susres::POWERDOWN_POWERDOWN, 1); @@ -103,6 +111,8 @@ mod implementation { seed_csr: utralib::CSR, /// we also own the reboot facility reboot_csr: utralib::CSR, + /// cache flushing memory raea + cacheflush: Option, } impl SusResHw { pub fn new() -> Self { @@ -159,6 +169,7 @@ mod implementation { marker, seed_csr: CSR::new(seed_csr.as_mut_ptr() as *mut u32), reboot_csr: CSR::new(reboot_csr.as_mut_ptr() as *mut u32), + cacheflush: None, }; // start the OS timer running @@ -200,6 +211,26 @@ mod implementation { } pub fn do_suspend(&mut self, forced: bool) { + // allocate memory for the cache flush + if self.cacheflush.is_none() { + self.cacheflush = Some ( + xous::syscall::map_memory( + None, + None, + 128 * 1024, // this matches a 128k L2 cache + xous::MemoryFlags::R | xous::MemoryFlags::W | xous::MemoryFlags::RESERVE, + ).expect("couldn't allocate RAM for cache flushing") + ); + // the RESERVE flag should pre-allocate the pages, but for good measure + // we write all the pages to make sure they are at a defined value + if let Some(cf) = self.cacheflush { + let cf_ptr = cf.as_ptr() as *mut u32; + for i in 0..(cf.len() / 4) { + unsafe {cf_ptr.add(i).write_volatile(0); } + } + } + } + println!("Stopping preemption"); // stop pre-emption self.os_timer.wfo(utra::timer0::EN_EN, 0); @@ -351,6 +382,11 @@ mod implementation { panic!("Can't resume because the ticktimer value was not saved properly before suspend!") }; + // de-allocate the cache flush memory + if let Some(cf) = self.cacheflush.take() { + xous::syscall::unmap_memory(cf).expect("couldn't de-allocate cache flush region"); + } + if self.csr.rf(utra::susres::STATE_WAS_FORCED) == 0 { false } else {