From 504284bf72d4c645caf05ab5e5445840287855d2 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Thu, 18 Feb 2021 14:14:44 -0800 Subject: [PATCH] tool: Move `read_debug` to trait so generic code can use it Returns error for backends that don't support it. --- tool/src/access/lpc/linux.rs | 10 ++++------ tool/src/access/lpc/sim.rs | 10 ++++------ tool/src/access/mod.rs | 6 ++++++ tool/src/error.rs | 2 ++ 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/tool/src/access/lpc/linux.rs b/tool/src/access/lpc/linux.rs index 6334c79..18ea379 100644 --- a/tool/src/access/lpc/linux.rs +++ b/tool/src/access/lpc/linux.rs @@ -130,12 +130,6 @@ impl AccessLpcLinux { Ok(self.cmd.write(addr as u16, data)?) } - /// Read from the debug space - //TODO: better public interface - pub unsafe fn read_debug(&mut self, addr: u8) -> Result { - Ok(self.dbg.read(addr as u16)?) - } - /// Returns Ok if a command can be sent unsafe fn command_check(&mut self) -> Result<(), Error> { if self.read_cmd(SMFI_CMD_CMD)? == 0 { @@ -180,4 +174,8 @@ impl Access for AccessLpcLinux { fn data_size(&self) -> usize { SMFI_CMD_SIZE - SMFI_CMD_DATA as usize } + + unsafe fn read_debug(&mut self, addr: u8) -> Result { + Ok(self.dbg.read(addr as u16)?) + } } diff --git a/tool/src/access/lpc/sim.rs b/tool/src/access/lpc/sim.rs index d43a0f6..307b93f 100644 --- a/tool/src/access/lpc/sim.rs +++ b/tool/src/access/lpc/sim.rs @@ -71,12 +71,6 @@ impl AccessLpcSim { self.outb(SMFI_CMD_BASE + u16::from(addr), data) } - /// Read from the debug space - //TODO: better public interface - pub unsafe fn read_debug(&mut self, addr: u8) -> Result { - self.inb(SMFI_DBG_BASE + u16::from(addr)) - } - /// Returns Ok if a command can be sent unsafe fn command_check(&mut self) -> Result<(), Error> { if self.read_cmd(SMFI_CMD_CMD)? == 0 { @@ -121,4 +115,8 @@ impl Access for AccessLpcSim { fn data_size(&self) -> usize { SMFI_CMD_SIZE - SMFI_CMD_DATA as usize } + + unsafe fn read_debug(&mut self, addr: u8) -> Result { + self.inb(SMFI_DBG_BASE + u16::from(addr)) + } } diff --git a/tool/src/access/mod.rs b/tool/src/access/mod.rs index 1aff1e7..297ea3c 100644 --- a/tool/src/access/mod.rs +++ b/tool/src/access/mod.rs @@ -23,6 +23,12 @@ pub trait Access { /// The maximum size that can be provided for the data argument fn data_size(&self) -> usize; + + /// Read from the debug space + //TODO: better public interface + unsafe fn read_debug(&mut self, _addr: u8) -> Result { + Err(Error::NotSupported) + } } impl Access for &mut dyn Access { diff --git a/tool/src/error.rs b/tool/src/error.rs index bfc7636..2b03e25 100644 --- a/tool/src/error.rs +++ b/tool/src/error.rs @@ -3,6 +3,8 @@ pub enum Error { /// Data length is too large DataLength(usize), + /// Operation not supported + NotSupported, /// A parameter was invalid Parameter, /// EC protocol returned an error result