From 89ca75c4bf3e9b65b784ec1be8407ce429692751 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 3 Oct 2022 02:24:44 +0800 Subject: [PATCH] move over to remote susres api --- apps/vault/Cargo.toml | 2 +- services/codec/Cargo.toml | 2 +- services/com/Cargo.toml | 2 +- services/engine-25519/Cargo.toml | 2 +- services/engine-sha512/Cargo.toml | 2 +- services/ffi-test/Cargo.toml | 2 +- services/gam/Cargo.toml | 2 +- services/graphics-server/Cargo.toml | 2 +- services/jtag/Cargo.toml | 2 +- services/keyboard/Cargo.toml | 2 +- services/llio/Cargo.toml | 2 +- services/net/Cargo.toml | 2 +- services/pddb/Cargo.toml | 2 +- services/root-keys/Cargo.toml | 2 +- services/shellchat/Cargo.toml | 2 +- services/skeleton/Cargo.toml | 2 +- services/spinor/Cargo.toml | 2 +- services/status/Cargo.toml | 2 +- services/susres/src/api.rs | 239 --------------------------- services/susres/src/lib.rs | 191 --------------------- services/ticktimer-server/Cargo.toml | 8 +- services/trng/Cargo.toml | 2 +- services/usb-device-xous/Cargo.toml | 2 +- services/usb-test/Cargo.toml | 2 +- 24 files changed, 25 insertions(+), 455 deletions(-) delete mode 100644 services/susres/src/api.rs delete mode 100644 services/susres/src/lib.rs diff --git a/apps/vault/Cargo.toml b/apps/vault/Cargo.toml index 8b28e9020..c2562712b 100644 --- a/apps/vault/Cargo.toml +++ b/apps/vault/Cargo.toml @@ -21,7 +21,7 @@ usbd-human-interface-device = "0.2.1" pddb = {path = "../../services/pddb" } modals = {path = "../../services/modals" } trng = {path="../../services/trng"} -susres = {path = "../../services/susres", package = "xous-susres"} +susres = {version = "0.9.0", package = "xous-api-susres"} ime-plugin-api = {path = "../../services/ime-plugin-api"} content-plugin-api = {path = "../../services/content-plugin-api"} # all content canvas providers must provide this API ctap-crypto = {path = "libraries/crypto"} diff --git a/services/codec/Cargo.toml b/services/codec/Cargo.toml index 2431bd33a..2647c3ad8 100644 --- a/services/codec/Cargo.toml +++ b/services/codec/Cargo.toml @@ -12,7 +12,7 @@ log-server = { version = "0.1.3", package = "xous-api-log" } ticktimer-server = { path = "../ticktimer-server", package = "xous-ticktimer" } xous-names = { version = "0.9.3", package = "xous-api-names" } log = "0.4.14" -susres = {path = "../susres", package = "xous-susres"} +susres = {version = "0.9.0", package = "xous-api-susres"} llio = {path = "../llio"} trng = {path = "../trng"} diff --git a/services/com/Cargo.toml b/services/com/Cargo.toml index d81198b1e..9baabac37 100644 --- a/services/com/Cargo.toml +++ b/services/com/Cargo.toml @@ -11,7 +11,7 @@ com_rs-ref = {path = "../../imports/com_rs-ref"} log = "0.4.14" log-server = {version = "0.1.3", package = "xous-api-log"} ticktimer-server = {path = "../ticktimer-server", package = "xous-ticktimer"} -susres = {path = "../susres", package = "xous-susres"} +susres = {version = "0.9.0", package = "xous-api-susres"} typenum = "1.12" xous = "0.9.9" xous-ipc = "0.9.9" diff --git a/services/engine-25519/Cargo.toml b/services/engine-25519/Cargo.toml index ac354a664..d3b763fd9 100644 --- a/services/engine-25519/Cargo.toml +++ b/services/engine-25519/Cargo.toml @@ -12,7 +12,7 @@ log-server = { version = "0.1.3", package = "xous-api-log" } ticktimer-server = { path = "../ticktimer-server", package = "xous-ticktimer" } xous-names = { version = "0.9.3", package = "xous-api-names" } log = "0.4.14" -susres = {path = "../susres", package = "xous-susres"} +susres = {version = "0.9.0", package = "xous-api-susres"} llio = {path = "../llio"} # temporary for testing some power stuff utralib = { version = "0.1.3", optional = true, default-features = false } diff --git a/services/engine-sha512/Cargo.toml b/services/engine-sha512/Cargo.toml index 0a66b6b5d..4f8d6e687 100644 --- a/services/engine-sha512/Cargo.toml +++ b/services/engine-sha512/Cargo.toml @@ -12,7 +12,7 @@ log-server = { version = "0.1.3", package = "xous-api-log" } ticktimer-server = { path = "../ticktimer-server", package = "xous-ticktimer" } xous-names = { version = "0.9.3", package = "xous-api-names" } log = "0.4.14" -susres = {path = "../susres", package = "xous-susres"} +susres = {version = "0.9.0", package = "xous-api-susres"} trng = { path = "../trng" } xous-ipc = "0.9.9" diff --git a/services/ffi-test/Cargo.toml b/services/ffi-test/Cargo.toml index 18d85ab48..7d84758bd 100644 --- a/services/ffi-test/Cargo.toml +++ b/services/ffi-test/Cargo.toml @@ -14,7 +14,7 @@ xous-names = { version = "0.9.3", package = "xous-api-names" } log = "0.4.14" num-derive = {version = "0.3.3", default-features = false} num-traits = {version = "0.2.14", default-features = false} -susres = {path = "../susres", package = "xous-susres"} +susres = {version = "0.9.0", package = "xous-api-susres"} ffi-sys = {path = "sys"} keyboard = {path = "../keyboard"} diff --git a/services/gam/Cargo.toml b/services/gam/Cargo.toml index bc7db10d7..779fd434a 100644 --- a/services/gam/Cargo.toml +++ b/services/gam/Cargo.toml @@ -25,7 +25,7 @@ num-derive = {version = "0.3.3", default-features = false} num-traits = {version = "0.2.14", default-features = false} rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]} -susres = {path = "../susres", package = "xous-susres"} # used for the sleep now menu item +susres = {version = "0.9.0", package = "xous-api-susres"} # used for the sleep now menu item enum_dispatch = "0.3.7" # used for trait-based dispatch off of multiple layout objects. locales = {path = "../../locales"} diff --git a/services/graphics-server/Cargo.toml b/services/graphics-server/Cargo.toml index 3820c78b8..0ce2c435a 100644 --- a/services/graphics-server/Cargo.toml +++ b/services/graphics-server/Cargo.toml @@ -11,7 +11,7 @@ keyboard = {path = "../keyboard"} log = "0.4.14" log-server = {version = "0.1.3", package = "xous-api-log"} xous = "0.9.9" -susres = {path = "../susres", package = "xous-susres"} +susres = {version = "0.9.0", package = "xous-api-susres"} ticktimer-server = {path = "../ticktimer-server", package = "xous-ticktimer"} xous-ipc = "0.9.9" diff --git a/services/jtag/Cargo.toml b/services/jtag/Cargo.toml index fd48f8999..16d773487 100644 --- a/services/jtag/Cargo.toml +++ b/services/jtag/Cargo.toml @@ -14,7 +14,7 @@ xous-names = { version = "0.9.3", package = "xous-api-names" } log = "0.4.14" num-derive = {version = "0.3.3", default-features = false} num-traits = {version = "0.2.14", default-features = false} -susres = {path = "../susres", package = "xous-susres"} +susres = {version = "0.9.0", package = "xous-api-susres"} xous-ipc = "0.9.9" rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]} diff --git a/services/keyboard/Cargo.toml b/services/keyboard/Cargo.toml index 0391c683a..626f5c8c7 100644 --- a/services/keyboard/Cargo.toml +++ b/services/keyboard/Cargo.toml @@ -14,7 +14,7 @@ xous = "0.9.9" xous-ipc = "0.9.9" xous-names = {version = "0.9.3", package = "xous-api-names"} llio = {path = "../llio"} -susres = {path = "../susres", package = "xous-susres"} +susres = {version = "0.9.0", package = "xous-api-susres"} spinor = {path = "../spinor"} num-derive = {version = "0.3.3", default-features = false} diff --git a/services/llio/Cargo.toml b/services/llio/Cargo.toml index 1abe9b652..931ccadf4 100644 --- a/services/llio/Cargo.toml +++ b/services/llio/Cargo.toml @@ -13,7 +13,7 @@ ticktimer-server = {path = "../ticktimer-server", package = "xous-ticktimer"} xous = "0.9.9" xous-ipc = "0.9.9" xous-names = {version = "0.9.3", package = "xous-api-names"} -susres = {path = "../susres", package = "xous-susres"} +susres = {version = "0.9.0", package = "xous-api-susres"} # RTC dependencies bitflags = "1.2.1" diff --git a/services/net/Cargo.toml b/services/net/Cargo.toml index d04b06845..b5ea8a7c1 100644 --- a/services/net/Cargo.toml +++ b/services/net/Cargo.toml @@ -15,7 +15,7 @@ xous-names = { version = "0.9.3", package = "xous-api-names" } log = "0.4.14" num-derive = {version = "0.3.3", default-features = false} num-traits = {version = "0.2.14", default-features = false} -susres = {path = "../susres", package = "xous-susres"} +susres = {version = "0.9.0", package = "xous-api-susres"} #rkyv = "0.7.18" rkyv = {version = "0.4.3", features = ["const_generics"], default-features = false} llio = {path = "../llio"} diff --git a/services/pddb/Cargo.toml b/services/pddb/Cargo.toml index 3cb957052..48745f54b 100644 --- a/services/pddb/Cargo.toml +++ b/services/pddb/Cargo.toml @@ -16,7 +16,7 @@ xous-names = { version = "0.9.3", package = "xous-api-names" } log = "0.4.14" num-derive = {version = "0.3.3", default-features = false} num-traits = {version = "0.2.14", default-features = false} -susres = {path = "../susres", package = "xous-susres"} +susres = {version = "0.9.0", package = "xous-api-susres"} rkyv = {version = "0.4.3", features = ["const_generics"], default-features = false} trng = {path = "../trng"} spinor = {path = "../spinor"} diff --git a/services/root-keys/Cargo.toml b/services/root-keys/Cargo.toml index 4450790b7..51228da1b 100644 --- a/services/root-keys/Cargo.toml +++ b/services/root-keys/Cargo.toml @@ -12,7 +12,7 @@ log-server = { version = "0.1.3", package = "xous-api-log" } ticktimer-server = { path = "../ticktimer-server", package = "xous-ticktimer" } xous-names = { version = "0.9.3", package = "xous-api-names" } log = "0.4.14" -susres = {path = "../susres", package = "xous-susres"} +susres = {version = "0.9.0", package = "xous-api-susres"} trng = {path= "../trng"} spinor = {path="../spinor"} llio = {path="../llio"} diff --git a/services/shellchat/Cargo.toml b/services/shellchat/Cargo.toml index 0f29ed9d2..e30daa94d 100644 --- a/services/shellchat/Cargo.toml +++ b/services/shellchat/Cargo.toml @@ -22,7 +22,7 @@ xous = "0.9.9" xous-ipc = "0.9.9" xous-names = {version = "0.9.3", package = "xous-api-names"} keyboard = {path = "../keyboard"} -susres = {path = "../susres", package = "xous-susres"} +susres = {version = "0.9.0", package = "xous-api-susres"} codec = {path = "../codec"} #engine-sha512 = {path="../engine-sha512"} sha2 = {path="../engine-sha512"} diff --git a/services/skeleton/Cargo.toml b/services/skeleton/Cargo.toml index 883f6b231..2e6d70b04 100644 --- a/services/skeleton/Cargo.toml +++ b/services/skeleton/Cargo.toml @@ -14,7 +14,7 @@ xous-names = { version = "0.9.3", package = "xous-api-names" } log = "0.4.14" num-derive = {version = "0.3.3", default-features = false} num-traits = {version = "0.2.14", default-features = false} -susres = {path = "../susres", package = "xous-susres"} +susres = {version = "0.9.0", package = "xous-api-susres"} utralib = { version = "0.1.3", optional = true, default-features = false } diff --git a/services/spinor/Cargo.toml b/services/spinor/Cargo.toml index f6e3b242a..dd74c5209 100644 --- a/services/spinor/Cargo.toml +++ b/services/spinor/Cargo.toml @@ -12,7 +12,7 @@ log-server = { version = "0.1.3", package = "xous-api-log" } ticktimer-server = { path = "../ticktimer-server", package = "xous-ticktimer" } xous-names = { version = "0.9.3", package = "xous-api-names" } log = "0.4.14" -susres = {path = "../susres", package = "xous-susres"} +susres = {version = "0.9.0", package = "xous-api-susres"} trng = { path = "../trng" } com = { path = "../com" } llio = { path = "../llio" } diff --git a/services/status/Cargo.toml b/services/status/Cargo.toml index d9228b78d..372440163 100644 --- a/services/status/Cargo.toml +++ b/services/status/Cargo.toml @@ -20,7 +20,7 @@ xous-names = {version = "0.9.3", package = "xous-api-names"} graphics-server = {path = "../graphics-server"} gam = {path = "../gam"} locales = {path = "../../locales"} -susres = {path = "../susres", package = "xous-susres"} +susres = {version = "0.9.0", package = "xous-api-susres"} root-keys = {path = "../root-keys"} modals = {path = "../modals"} pddb = {path = "../pddb"} diff --git a/services/susres/src/api.rs b/services/susres/src/api.rs deleted file mode 100644 index a35f23b8d..000000000 --- a/services/susres/src/api.rs +++ /dev/null @@ -1,239 +0,0 @@ -#![cfg_attr(not(target_os = "none"), allow(dead_code))] - -#[cfg(any(feature="precursor", feature="renode"))] -use utralib::generated::*; - -pub(crate) const SERVER_NAME_SUSRES: &str = "_Suspend/resume manager_"; - -/// Note: there must be at least one subscriber to the `Last` suspend order event, otherwise -/// the logic will never terminate. There may be multiple `Last` subscribers, but the order at -/// which they finish would be indeterminate. Currently, the `Last` subscriber is the `spinor` -/// block, which is last because you want to make sure all the PDDB commits and other saved -/// data are flushed before turning off access to the SPINOR. -#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone, PartialEq, Eq)] -pub enum SuspendOrder { - Early, - Normal, - Late, - Later, - Last, -} -impl SuspendOrder { - pub fn next(&self) -> SuspendOrder { - match self { - SuspendOrder::Early => SuspendOrder::Normal, - SuspendOrder::Normal => SuspendOrder::Late, - SuspendOrder::Late => SuspendOrder::Later, - SuspendOrder::Later => SuspendOrder::Last, - SuspendOrder::Last => SuspendOrder::Last, - } - } -} - -#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)] -pub(crate) enum Opcode { - /// requests a suspend - SuspendRequest, - /// locks out suspend capability -- meant to be used only to prevent suspend during firmware updates - SuspendDeny, - /// unlocks suspend capability - SuspendAllow, - - /// register a subscriber to the suspend event - /// (if you don't register, you just get suspend without any warning!) - SuspendEventSubscribe, - - /// indicate we're ready to suspend - SuspendReady, - - /// from the timeout thread - SuspendTimeout, - - /// queries if my suspend was clean or not - WasSuspendClean, - - /// reboot opcodes - RebootRequest, - RebootSocConfirm, // all peripherals + CPU - RebootCpuConfirm, // just the CPU, peripherals (in particular the USB debug bridge) keep state - - /// not tested - reboot address - RebootVector, //(u32), - - /// used by processes to indicate they are suspending now; this blocks until resume using the "execution gate" - SuspendingNow, - - /// exit the server - Quit, -} - -#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)] -pub(crate) struct ScalarHook { - pub sid: (u32, u32, u32, u32), - pub id: u32, // ID of the scalar message to send through (e.g. the discriminant of the Enum on the caller's side API) - pub cid: xous::CID, // caller-side connection ID for the scalar message to route to. Created by the caller before hooking. - pub order: SuspendOrder, -} - -#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)] -pub(crate) enum SuspendEventCallback { - Event, // this contains a token as well which must be returned to indicate you're ready for the suspend - Drop, -} - - -///////////////////////////////////////////////////////////////////////// -/////////////////////////// suspend-resume hardware management primitives -///////////////////////////////////////////////////////////////////////// -#[cfg(any(feature="precursor", feature="renode"))] -#[allow(dead_code)] -#[derive(Debug, Copy, Clone)] -pub enum RegOrField { - Field(Field), - Reg(Register), -} -#[cfg(any(feature="precursor", feature="renode"))] -#[allow(dead_code)] -#[derive(Debug, Copy, Clone)] -pub struct ManagedReg { - /// register, or a field of a register - pub item: RegOrField, - /// override the default mask value if Some() - mask is aligned to the register or field (do not shift the mask to the left to correspond to the actual bit position) - pub mask: Option, - /// the saved value of the field or register - pub value: Option, - /// if true, value is static and should not be updated during suspend, but restored to this value ta resume - pub fixed_value: bool, -} - -#[derive(Debug)] -#[allow(dead_code)] -#[cfg(any(feature="precursor", feature="renode"))] -pub struct RegManager { - pub csr: CSR, - pub registers: [Option; N], -} -#[allow(dead_code)] -#[cfg(any(feature="precursor", feature="renode"))] -impl RegManager:: where ManagedReg: core::marker::Copy { - pub fn new(reg_base: *mut u32) -> RegManager:: { - RegManager:: { - csr: CSR::new(reg_base), - registers: [None; N], - } - } - pub fn push_fixed_value(&mut self, mr: RegOrField, value: usize) { - let mrt = ManagedReg { - item: mr, - mask: None, - value: Some(value), - fixed_value: true, - }; - for entry in self.registers.iter_mut() { - if entry.is_none() { - *entry = Some(mrt); - return; - } - } - panic!("Ran out of space pushing to suspend/resume manager structure. Please increase the allocated size!"); - } - // push registers into the manager in the order that you would normally initialized them - pub fn push(&mut self, mr: RegOrField, mask_override: Option) { - let mrt = ManagedReg { - item: mr, - mask: mask_override, - value: None, - fixed_value: false, - }; - for entry in self.registers.iter_mut() { - if entry.is_none() { - *entry = Some(mrt); - return; - } - } - // A panic! is most appropriate here, because there is really no graceful - // remedy to this. It is a straight-up programmer error that needs to be fixed. - panic!("Ran out of space pushing to suspend/resume manager structure. Please increase the allocated size!"); - } -} -#[cfg(any(feature="precursor", feature="renode"))] -pub trait SuspendResume { - fn suspend(&mut self); - fn resume(&mut self); -} -#[cfg(any(feature="precursor", feature="renode"))] -impl SuspendResume for RegManager { - fn suspend(&mut self) { - for entry in self.registers.iter_mut().rev() { - if let Some(reg) = entry { - if !reg.fixed_value { - // masking is done on the write side - match reg.item { - RegOrField::Field(field) => reg.value = Some(self.csr.rf(field) as usize), - RegOrField::Reg(r) => reg.value = Some(self.csr.r(r) as usize), - } - *entry = Some(*reg); - } - } - } - /* - log::trace!("suspend csr: {:?}", self.csr); - for entry in self.registers.iter().rev() { - log::trace!("suspend: {:?}", entry); - }*/ - } - fn resume(&mut self) { - for entry in self.registers.iter() { // this is in reverse order to the suspend - if let Some(reg) = entry { - if let Some(mut value) = reg.value { - if let Some(mask) = reg.mask { - value &= mask; - } - match reg.item { - RegOrField::Field(field) => self.csr.rmwf(field, value as u32), - RegOrField::Reg(r) => self.csr.wo(r, value as u32), - } - } - } - } - /* - log::trace!("resume csr: {:?}", self.csr); - for entry in self.registers.iter() { - log::trace!("resume: {:?}", entry); - }*/ - } -} - -// because the volatile memory regions can be potentially large (128kiB), but fewer (maybe 5-6 total in the system), -// we allocate these as stand-alone structures and manage them explicitly. -#[derive(Debug)] -#[cfg(any(feature="precursor", feature="renode"))] -pub struct ManagedMem { - pub mem: xous::MemoryRange, - pub backing: [u32; N], -} -#[allow(dead_code)] -#[cfg(any(feature="precursor", feature="renode"))] -impl ManagedMem { - pub fn new(src: xous::MemoryRange) -> Self { - ManagedMem { - mem: src, - backing: [0; N], - } - } -} -#[cfg(any(feature="precursor", feature="renode"))] -impl SuspendResume for ManagedMem { - fn suspend(&mut self) { - let src = self.mem.as_ptr() as *const u32; - for words in 0..(N / core::mem::size_of::()) { - self.backing[words] = unsafe{src.add(words).read_volatile()}; - } - } - fn resume(&mut self) { - let dst = self.mem.as_ptr() as *mut u32; - for words in 0..(N / core::mem::size_of::()) { - unsafe{dst.add(words).write_volatile(self.backing[words])}; - } - } -} diff --git a/services/susres/src/lib.rs b/services/susres/src/lib.rs deleted file mode 100644 index 4f06809ea..000000000 --- a/services/susres/src/lib.rs +++ /dev/null @@ -1,191 +0,0 @@ -#![cfg_attr(target_os = "none", no_std)] -#![cfg_attr(not(target_os = "none"), allow(dead_code))] -#![cfg_attr(not(target_os = "none"), allow(unused_imports))] -#![cfg_attr(not(target_os = "none"), allow(unused_variables))] - -pub mod api; -pub use api::*; - -use xous::{send_message, CID, Message, msg_scalar_unpack}; -use xous_ipc::Buffer; -use num_traits::{ToPrimitive, FromPrimitive}; - -#[derive(Debug)] -pub struct Susres { - conn: CID, - suspend_cb_sid: Option, -} -impl Susres { - #[cfg(any(feature="precursor", feature="renode"))] - pub fn new(order: Option, xns: &xous_names::XousNames, cb_discriminant: u32, cid: CID) -> Result { - REFCOUNT.fetch_add(1, Ordering::Relaxed); - let conn = xns.request_connection_blocking(api::SERVER_NAME_SUSRES).expect("Can't connect to SUSRES"); - - let sid = xous::create_server().unwrap(); - let sid_tuple = sid.to_u32(); - xous::create_thread_4(suspend_cb_server, sid_tuple.0 as usize, sid_tuple.1 as usize, sid_tuple.2 as usize, sid_tuple.3 as usize).unwrap(); - let hookdata = ScalarHook { - sid: sid_tuple, - id: cb_discriminant, - cid, - order: order.unwrap_or(SuspendOrder::Normal), - }; - log::debug!("hooking {:?}", hookdata); - let buf = Buffer::into_buf(hookdata).or(Err(xous::Error::InternalError))?; - buf.lend(conn, Opcode::SuspendEventSubscribe.to_u32().unwrap())?; - - Ok(Susres { - conn, - suspend_cb_sid: Some(sid), - }) - } - // suspend/resume is not implemented in hosted mode, and will break if you try to do it. - // the main reason this was doen is actually it seems hosted mode can't handle the level - // of concurrency introduced by suspend/resume, as its underlying IPC mechanisms are quite - // different and have a lot of overhead; it seems like the system goes into a form of deadlock - // during boot when all the hosted mode servers try to connect. This isn't an issue on real hardware. - #[cfg(any(feature="hosted"))] - pub fn new(_ordering: Option, xns: &xous_names::XousNames, cb_discriminant: u32, cid: CID) -> Result { - REFCOUNT.fetch_add(1, Ordering::Relaxed); - Ok(Susres { - conn: 0, - suspend_cb_sid: None, - }) - } - pub fn conn(&self) -> CID { self.conn } - - pub fn new_without_hook(xns: &xous_names::XousNames) -> Result { - REFCOUNT.fetch_add(1, Ordering::Relaxed); - let conn = xns.request_connection_blocking(api::SERVER_NAME_SUSRES)?; - Ok(Susres { - conn, - suspend_cb_sid: None, - }) - } - - pub fn initiate_suspend(&self) -> Result<(), xous::Error> { - log::trace!("suspend initiated"); - match send_message(self.conn, - Message::new_blocking_scalar(Opcode::SuspendRequest.to_usize().unwrap(), 0, 0, 0, 0) - ) { - Ok(xous::Result::Scalar1(result)) => { - if result == 1 { - Ok(()) - } else { - // indicate that we couldn't initiate the suspend - Err(xous::Error::Timeout) - } - }, - _ => Err(xous::Error::InternalError) - } - } - - pub fn suspend_until_resume(&mut self, token: usize) -> Result { - if self.suspend_cb_sid.is_none() { // this happens if you created without a hook - return Err(xous::Error::UseBeforeInit) - } - log::debug!("token {} pid {} suspending", token, xous::process::id()); // <-- use this to debug s/r - xous::yield_slice(); - // first tell the susres server that we're ready to suspend - send_message(self.conn, - Message::new_scalar(Opcode::SuspendReady.to_usize().unwrap(), token, 0, 0, 0) - ).map(|_|())?; - log::trace!("blocking until suspend"); - - // sometime between here and when this next message unblocks, the power went out... - - // now block until we've resumed - send_message(self.conn, - Message::new_blocking_scalar(Opcode::SuspendingNow.to_usize().unwrap(), 0, 0, 0, 0) - ).map(|_|())?; - - let response = send_message(self.conn, - Message::new_blocking_scalar(Opcode::WasSuspendClean.to_usize().unwrap(), token, 0, 0, 0) - ).expect("couldn't query if my suspend was successful"); - if let xous::Result::Scalar1(result) = response { - if result != 0 { - log::debug!("resume pid {} clean", xous::process::id()); // <-- use this to debug s/r - Ok(true) - } else { - log::debug!("resume pid {} dirty", xous::process::id()); // <-- use this to debug s/r - Ok(false) - } - } else { - Err(xous::Error::InternalError) - } - } - - pub fn set_suspendable(&mut self, allow_suspend: bool) -> Result<(), xous::Error> { - if allow_suspend { - send_message(self.conn, - Message::new_scalar(Opcode::SuspendAllow.to_usize().unwrap(), 0, 0, 0, 0) - ).map(|_|()) - } else { - send_message(self.conn, - Message::new_scalar(Opcode::SuspendDeny.to_usize().unwrap(), 0, 0, 0, 0) - ).map(|_|()) - } - } - - /// Passing `true` causes the whole SOC including peripherals to receive a reset signal - /// `false` causes only the CPU to reboot, while the peripherals retain state. Generally you want `true`. - pub fn reboot(&self, whole_soc: bool) -> Result<(), xous::Error> { - send_message(self.conn, - Message::new_scalar(Opcode::RebootRequest.to_usize().unwrap(), 0, 0, 0, 0) - ).map(|_|())?; - - if whole_soc { - send_message(self.conn, - Message::new_scalar(Opcode::RebootSocConfirm.to_usize().unwrap(), 0, 0, 0, 0) - ).map(|_|()) - } else { - send_message(self.conn, - Message::new_scalar(Opcode::RebootCpuConfirm.to_usize().unwrap(), 0, 0, 0, 0) - ).map(|_|()) - } - } -} -fn drop_conn(sid: xous::SID) { - let cid = xous::connect(sid).unwrap(); - xous::send_message(cid, - Message::new_scalar(SuspendEventCallback::Drop.to_usize().unwrap(), 0, 0, 0, 0)).unwrap(); - unsafe{xous::disconnect(cid).unwrap();} -} -use core::sync::atomic::{AtomicU32, Ordering}; -static REFCOUNT: AtomicU32 = AtomicU32::new(0); -impl Drop for Susres { - fn drop(&mut self) { - if let Some(sid) = self.suspend_cb_sid.take() { - drop_conn(sid); - } - if REFCOUNT.fetch_sub(1, Ordering::Relaxed) == 1 { - unsafe{xous::disconnect(self.conn).unwrap();} - } - } -} - -fn suspend_cb_server(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); - let mut print_once = false; - loop { - let msg = xous::receive_message(sid).unwrap(); - match FromPrimitive::from_usize(msg.body.id()) { - Some(SuspendEventCallback::Event) => msg_scalar_unpack!(msg, cid, id, token, _, { - // directly pass the scalar message onto the CID with the ID memorized in the original hook - if !print_once { - // dump this only once so we have a PID->token map in the debug logs, but don't dump it every time as it slows down the suspend - log::info!("PID {} has s/r token {}", xous::current_pid().unwrap().get(), token); // <-- use this to debug s/r - print_once = true; - } - send_message(cid as u32, - Message::new_scalar(id, token, 0, 0, 0) - ).unwrap(); - }), - Some(SuspendEventCallback::Drop) => { - break; // this exits the loop and kills the thread - } - None => (), - } - } - xous::destroy_server(sid).unwrap(); -} \ No newline at end of file diff --git a/services/ticktimer-server/Cargo.toml b/services/ticktimer-server/Cargo.toml index d50548120..c87398d3c 100644 --- a/services/ticktimer-server/Cargo.toml +++ b/services/ticktimer-server/Cargo.toml @@ -14,7 +14,7 @@ xous-ipc = "0.9.9" rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]} num-derive = {version = "0.3.3", default-features = false} num-traits = {version = "0.2.14", default-features = false} -susres = {path = "../susres", package = "xous-susres"} +susres = {version = "0.9.0", package = "xous-api-susres"} xous-names = {version = "0.9.3", package = "xous-api-names"} xous-semver = "0.1.2" @@ -23,9 +23,9 @@ utralib = {version = "0.1.3", optional = true, default-features = false } [target.'cfg(any(windows,unix))'.dependencies] [features] -precursor = ["utralib/precursor"] -hosted = ["utralib/hosted"] -renode = ["utralib/renode"] +precursor = ["utralib/precursor", "susres/precursor"] +hosted = ["utralib/hosted", "susres/hosted"] +renode = ["utralib/renode", "susres/renode"] debug-print = [] watchdog = [] no-timestamp = [] # turns off embedded timestamp for reproducible builds diff --git a/services/trng/Cargo.toml b/services/trng/Cargo.toml index 6914c772f..711f812ee 100644 --- a/services/trng/Cargo.toml +++ b/services/trng/Cargo.toml @@ -14,7 +14,7 @@ xous-names = { version = "0.9.3", package = "xous-api-names" } log = "0.4.14" num-derive = {version = "0.3.3", default-features = false} num-traits = {version = "0.2.14", default-features = false} -susres = {path = "../susres", package = "xous-susres"} +susres = {version = "0.9.0", package = "xous-api-susres"} rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]} xous-ipc = "0.9.9" diff --git a/services/usb-device-xous/Cargo.toml b/services/usb-device-xous/Cargo.toml index b309eca3e..8c3821e8b 100644 --- a/services/usb-device-xous/Cargo.toml +++ b/services/usb-device-xous/Cargo.toml @@ -17,7 +17,7 @@ llio = {path="../llio"} num-derive = {version = "0.3.3", default-features = false} num-traits = {version = "0.2.14", default-features = false} rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]} -susres = {path = "../susres", package = "xous-susres"} +susres = {version = "0.9.0", package = "xous-api-susres"} modals = {path = "../modals"} keyboard = {path = "../keyboard"} bitfield = "0.13.2" diff --git a/services/usb-test/Cargo.toml b/services/usb-test/Cargo.toml index 6352f8676..d310f981f 100644 --- a/services/usb-test/Cargo.toml +++ b/services/usb-test/Cargo.toml @@ -14,7 +14,7 @@ xous-names = { version = "0.9.3", package = "xous-api-names" } log = "0.4.14" num-derive = {version = "0.3.3", default-features = false} num-traits = {version = "0.2.14", default-features = false} -susres = {path = "../susres", package = "xous-susres"} +susres = {version = "0.9.0", package = "xous-api-susres"} keyboard = {path = "../keyboard"} bitfield = "0.13.2" vcell = "0.1.3"