Skip to content

Commit

Permalink
tool: Restrict port IO interfaces to x86
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Crawford <[email protected]>
  • Loading branch information
crawfxrd committed Dec 14, 2024
1 parent 264f34b commit a865083
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 15 deletions.
4 changes: 3 additions & 1 deletion tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ clap = { version = "4.5", features = ["derive"], optional = true }
libc = { version = "0.2", optional = true }
# NOTE: Upgrading to 2.x blocked on Ubuntu shipping newer hidapi
hidapi = { version = "1.5", default-features = false, features = ["linux-shared-hidraw"], optional = true }
redox_hwio = { version = "0.1.6", default-features = false, optional = true }
downcast-rs = { version = "1.2.0", default-features = false }

[target.'cfg(any(target_arch = "x86", target_arch = "x86_64"))'.dependencies]
redox_hwio = { version = "0.1.6", default-features = false, optional = true }

[features]
default = ["std", "hidapi", "clap"]
std = ["libc", "downcast-rs/std"]
Expand Down
10 changes: 8 additions & 2 deletions tool/src/access/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ pub use self::hid::AccessHid;
#[cfg(feature = "hidapi")]
mod hid;

#[cfg(any(feature = "redox_hwio", all(feature = "std", target_os = "linux")))]
#[cfg(all(
any(target_arch = "x86", target_arch = "x86_64"),
any(feature = "redox_hwio", all(feature = "std", target_os = "linux"))
))]
pub use self::lpc::*;
#[cfg(any(feature = "redox_hwio", all(feature = "std", target_os = "linux")))]
#[cfg(all(
any(target_arch = "x86", target_arch = "x86_64"),
any(feature = "redox_hwio", all(feature = "std", target_os = "linux"))
))]
mod lpc;

/// Access method for running an EC command
Expand Down
41 changes: 29 additions & 12 deletions tool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
//!
//! There are some differences between targets and features that are listed below:
//! - `AccessHid` requires the `hidapi` feature. Only functional on USB ECs.
//! - `AccessLpcDirect` requires the `redox_hwio` feature and a nightly compiler. This method is
//! - `AccessLpcDirect` requires the `redox_hwio` feature and an x86 target. This method is
//! only recommended for use in firmware with LPC ECs, as mutual exclusion is not guaranteed.
//! - `AccessLpcLinux` requires the `std` feature and `linux` target_os. Recommended for LPC ECs,
//! as this method can utilize mutual exclusion.
//! - `EcLegacy`, `Pmc`, and `SuperIo` all require the `redox_hwio` feature and a nightly
//! compiler. It is only recommended to use these in firmware, as mutual exclusion is not
//! guaranteed.
//! - `AccessLpcLinux` requires the `std` feature, `linux` target_os, and x86 target. Recommended
//! for LPC ECs, as this method can utilize mutual exclusion.
//! - `EcLegacy`, `Pmc`, and `SuperIo` all require the `redox_hwio` feature and an x86 target.
//! It is only recommended to use these in firmware, as mutual exclusion is not guaranteed.
#![allow(clippy::missing_safety_doc)]
#![allow(clippy::needless_range_loop)]
Expand All @@ -33,22 +32,40 @@ mod error;
pub use self::firmware::Firmware;
mod firmware;

#[cfg(feature = "redox_hwio")]
#[cfg(all(
feature = "redox_hwio",
any(target_arch = "x86", target_arch = "x86_64")
))]
pub use self::legacy::EcLegacy;
#[cfg(feature = "redox_hwio")]
#[cfg(all(
feature = "redox_hwio",
any(target_arch = "x86", target_arch = "x86_64")
))]
mod legacy;

#[cfg(feature = "redox_hwio")]
#[cfg(all(
feature = "redox_hwio",
any(target_arch = "x86", target_arch = "x86_64")
))]
pub use self::pmc::Pmc;
#[cfg(feature = "redox_hwio")]
#[cfg(all(
feature = "redox_hwio",
any(target_arch = "x86", target_arch = "x86_64")
))]
mod pmc;

pub use self::spi::{Spi, SpiRom, SpiTarget};
mod spi;

#[cfg(feature = "redox_hwio")]
#[cfg(all(
feature = "redox_hwio",
any(target_arch = "x86", target_arch = "x86_64")
))]
pub use self::super_io::SuperIo;
#[cfg(feature = "redox_hwio")]
#[cfg(all(
feature = "redox_hwio",
any(target_arch = "x86", target_arch = "x86_64")
))]
mod super_io;

#[cfg(feature = "std")]
Expand Down

0 comments on commit a865083

Please sign in to comment.