tool: Move read_debug to trait so generic code can use it

Returns error for backends that don't support it.
This commit is contained in:
Ian Douglas Scott 2021-02-18 14:14:44 -08:00 committed by Jeremy Soller
parent 0c1584385c
commit 504284bf72
4 changed files with 16 additions and 12 deletions

View File

@ -130,12 +130,6 @@ impl AccessLpcLinux {
Ok(self.cmd.write(addr as u16, data)?) 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<u8, Error> {
Ok(self.dbg.read(addr as u16)?)
}
/// Returns Ok if a command can be sent /// Returns Ok if a command can be sent
unsafe fn command_check(&mut self) -> Result<(), Error> { unsafe fn command_check(&mut self) -> Result<(), Error> {
if self.read_cmd(SMFI_CMD_CMD)? == 0 { if self.read_cmd(SMFI_CMD_CMD)? == 0 {
@ -180,4 +174,8 @@ impl Access for AccessLpcLinux {
fn data_size(&self) -> usize { fn data_size(&self) -> usize {
SMFI_CMD_SIZE - SMFI_CMD_DATA as usize SMFI_CMD_SIZE - SMFI_CMD_DATA as usize
} }
unsafe fn read_debug(&mut self, addr: u8) -> Result<u8, Error> {
Ok(self.dbg.read(addr as u16)?)
}
} }

View File

@ -71,12 +71,6 @@ impl AccessLpcSim {
self.outb(SMFI_CMD_BASE + u16::from(addr), data) 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<u8, Error> {
self.inb(SMFI_DBG_BASE + u16::from(addr))
}
/// Returns Ok if a command can be sent /// Returns Ok if a command can be sent
unsafe fn command_check(&mut self) -> Result<(), Error> { unsafe fn command_check(&mut self) -> Result<(), Error> {
if self.read_cmd(SMFI_CMD_CMD)? == 0 { if self.read_cmd(SMFI_CMD_CMD)? == 0 {
@ -121,4 +115,8 @@ impl Access for AccessLpcSim {
fn data_size(&self) -> usize { fn data_size(&self) -> usize {
SMFI_CMD_SIZE - SMFI_CMD_DATA as usize SMFI_CMD_SIZE - SMFI_CMD_DATA as usize
} }
unsafe fn read_debug(&mut self, addr: u8) -> Result<u8, Error> {
self.inb(SMFI_DBG_BASE + u16::from(addr))
}
} }

View File

@ -23,6 +23,12 @@ pub trait Access {
/// The maximum size that can be provided for the data argument /// The maximum size that can be provided for the data argument
fn data_size(&self) -> usize; fn data_size(&self) -> usize;
/// Read from the debug space
//TODO: better public interface
unsafe fn read_debug(&mut self, _addr: u8) -> Result<u8, Error> {
Err(Error::NotSupported)
}
} }
impl Access for &mut dyn Access { impl Access for &mut dyn Access {

View File

@ -3,6 +3,8 @@
pub enum Error { pub enum Error {
/// Data length is too large /// Data length is too large
DataLength(usize), DataLength(usize),
/// Operation not supported
NotSupported,
/// A parameter was invalid /// A parameter was invalid
Parameter, Parameter,
/// EC protocol returned an error result /// EC protocol returned an error result