mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-12 09:22:26 -04:00
Turn galileo detection into generalized model detection
This commit is contained in:
parent
ebd89f4f72
commit
3565886d3f
3 changed files with 112 additions and 31 deletions
78
src/hardware.rs
Normal file
78
src/hardware.rs
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
/*
|
||||||
|
* Copyright © 2023 Collabora Ltd.
|
||||||
|
* Copyright © 2024 Valve Software
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
use tokio::fs;
|
||||||
|
|
||||||
|
use crate::path;
|
||||||
|
|
||||||
|
const BOARD_VENDOR_PATH: &str = "/sys/class/dmi/id/board_vendor";
|
||||||
|
const BOARD_NAME_PATH: &str = "/sys/class/dmi/id/board_name";
|
||||||
|
const VALVE_VENDOR: &str = "Valve";
|
||||||
|
const JUPITER_NAME: &str = "Jupiter";
|
||||||
|
const GALILEO_NAME: &str = "Galileo";
|
||||||
|
|
||||||
|
#[derive(PartialEq, Debug, Copy, Clone)]
|
||||||
|
pub enum HardwareVariant {
|
||||||
|
Unknown,
|
||||||
|
Jupiter,
|
||||||
|
Galileo,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn variant() -> Result<HardwareVariant> {
|
||||||
|
let board_vendor = fs::read_to_string(path(BOARD_VENDOR_PATH)).await?;
|
||||||
|
if board_vendor.trim_end() != VALVE_VENDOR {
|
||||||
|
return Ok(HardwareVariant::Unknown);
|
||||||
|
}
|
||||||
|
|
||||||
|
let board_name = fs::read_to_string(path(BOARD_NAME_PATH)).await?;
|
||||||
|
Ok(match board_name.trim_end() {
|
||||||
|
JUPITER_NAME => HardwareVariant::Jupiter,
|
||||||
|
GALILEO_NAME => HardwareVariant::Galileo,
|
||||||
|
_ => HardwareVariant::Unknown,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
use crate::testing;
|
||||||
|
use tokio::fs::{create_dir_all, write};
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn board_lookup() {
|
||||||
|
let h = testing::start();
|
||||||
|
|
||||||
|
create_dir_all(crate::path("/sys/class/dmi/id"))
|
||||||
|
.await
|
||||||
|
.expect("create_dir_all");
|
||||||
|
assert!(variant().await.is_err());
|
||||||
|
|
||||||
|
write(crate::path("/sys/class/dmi/id/board_vendor"), "LENOVO\n")
|
||||||
|
.await
|
||||||
|
.expect("write");
|
||||||
|
assert_eq!(variant().await.unwrap(), HardwareVariant::Unknown);
|
||||||
|
|
||||||
|
write(crate::path("/sys/class/dmi/id/board_vendor"), "Valve\n")
|
||||||
|
.await
|
||||||
|
.expect("write");
|
||||||
|
write(crate::path("/sys/class/dmi/id/board_name"), "Jupiter\n")
|
||||||
|
.await
|
||||||
|
.expect("write");
|
||||||
|
assert_eq!(variant().await.unwrap(), HardwareVariant::Jupiter);
|
||||||
|
|
||||||
|
write(crate::path("/sys/class/dmi/id/board_name"), "Galileo\n")
|
||||||
|
.await
|
||||||
|
.expect("write");
|
||||||
|
assert_eq!(variant().await.unwrap(), HardwareVariant::Galileo);
|
||||||
|
|
||||||
|
write(crate::path("/sys/class/dmi/id/board_name"), "Neptune\n")
|
||||||
|
.await
|
||||||
|
.expect("write");
|
||||||
|
assert_eq!(variant().await.unwrap(), HardwareVariant::Unknown);
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,6 +21,7 @@ use crate::sls::ftrace::Ftrace;
|
||||||
use crate::sls::{LogLayer, LogReceiver};
|
use crate::sls::{LogLayer, LogReceiver};
|
||||||
|
|
||||||
mod ds_inhibit;
|
mod ds_inhibit;
|
||||||
|
mod hardware;
|
||||||
mod manager;
|
mod manager;
|
||||||
mod sls;
|
mod sls;
|
||||||
|
|
||||||
|
@ -117,7 +118,7 @@ async fn reload() -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create_connection() -> Result<Connection> {
|
async fn create_connection() -> Result<Connection> {
|
||||||
let manager = manager::SMManager::new()?;
|
let manager = manager::SMManager::new().await?;
|
||||||
|
|
||||||
ConnectionBuilder::system()?
|
ConnectionBuilder::system()?
|
||||||
.name("com.steampowered.SteamOSManager1")?
|
.name("com.steampowered.SteamOSManager1")?
|
||||||
|
|
|
@ -6,11 +6,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use anyhow::{ensure, Result};
|
use anyhow::{ensure, Result};
|
||||||
use std::{ffi::OsStr, fmt, fs};
|
use std::{ffi::OsStr, fmt};
|
||||||
use tokio::{fs::File, io::AsyncWriteExt, process::Command};
|
use tokio::{fs, fs::File, io::AsyncWriteExt, process::Command};
|
||||||
use tracing::{error, warn};
|
use tracing::{error, warn};
|
||||||
use zbus::{interface, zvariant::Fd};
|
use zbus::{interface, zvariant::Fd};
|
||||||
|
|
||||||
|
use crate::hardware::{variant, HardwareVariant};
|
||||||
|
|
||||||
#[derive(PartialEq, Debug, Copy, Clone)]
|
#[derive(PartialEq, Debug, Copy, Clone)]
|
||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
enum WifiDebugMode {
|
enum WifiDebugMode {
|
||||||
|
@ -46,10 +48,10 @@ pub struct SMManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SMManager {
|
impl SMManager {
|
||||||
pub fn new() -> Result<Self> {
|
pub async fn new() -> Result<Self> {
|
||||||
Ok(SMManager {
|
Ok(SMManager {
|
||||||
wifi_debug_mode: WifiDebugMode::Off,
|
wifi_debug_mode: WifiDebugMode::Off,
|
||||||
should_trace: is_galileo()?,
|
should_trace: variant().await? == HardwareVariant::Galileo,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,9 +67,6 @@ const OVERRIDE_PATH: &str = "/etc/systemd/system/iwd.service.d/override.conf";
|
||||||
const OUTPUT_FILE: &str = "/var/log/wifitrace.dat";
|
const OUTPUT_FILE: &str = "/var/log/wifitrace.dat";
|
||||||
const MIN_BUFFER_SIZE: u32 = 100;
|
const MIN_BUFFER_SIZE: u32 = 100;
|
||||||
|
|
||||||
const BOARD_NAME_PATH: &str = "/sys/class/dmi/id/board_name";
|
|
||||||
const GALILEO_NAME: &str = "Galileo";
|
|
||||||
|
|
||||||
const ALS_INTEGRATION_PATH: &str = "/sys/devices/platform/AMDI0010:00/i2c-0/i2c-PRP0001:01/iio:device0/in_illuminance_integration_time";
|
const ALS_INTEGRATION_PATH: &str = "/sys/devices/platform/AMDI0010:00/i2c-0/i2c-PRP0001:01/iio:device0/in_illuminance_integration_time";
|
||||||
const POWER1_CAP_PATH: &str = "/sys/class/hwmon/hwmon5/power1_cap";
|
const POWER1_CAP_PATH: &str = "/sys/class/hwmon/hwmon5/power1_cap";
|
||||||
const POWER2_CAP_PATH: &str = "/sys/class/hwmon/hwmon5/power2_cap";
|
const POWER2_CAP_PATH: &str = "/sys/class/hwmon/hwmon5/power2_cap";
|
||||||
|
@ -76,13 +75,8 @@ const GPU_PERFORMANCE_LEVEL_PATH: &str =
|
||||||
"/sys/class/drm/card0/device/power_dpm_force_performance_level";
|
"/sys/class/drm/card0/device/power_dpm_force_performance_level";
|
||||||
const GPU_CLOCKS_PATH: &str = "/sys/class/drm/card0/device/pp_od_clk_voltage";
|
const GPU_CLOCKS_PATH: &str = "/sys/class/drm/card0/device/pp_od_clk_voltage";
|
||||||
|
|
||||||
fn is_galileo() -> Result<bool> {
|
const SYSTEMCTL_PATH: &str = "/usr/bin/systemctl";
|
||||||
let mut board_name = fs::read_to_string(BOARD_NAME_PATH)?;
|
const TRACE_CMD_PATH: &str = "/usr/bin/trace-cmd";
|
||||||
board_name = board_name.trim().to_string();
|
|
||||||
|
|
||||||
let matches = board_name == GALILEO_NAME;
|
|
||||||
Ok(matches)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn script_exit_code(executable: &str, args: &[impl AsRef<OsStr>]) -> Result<bool> {
|
async fn script_exit_code(executable: &str, args: &[impl AsRef<OsStr>]) -> Result<bool> {
|
||||||
// Run given script and return true on success
|
// Run given script and return true on success
|
||||||
|
@ -116,23 +110,23 @@ async fn setup_iwd_config(want_override: bool) -> std::io::Result<()> {
|
||||||
if want_override {
|
if want_override {
|
||||||
// Copy it in
|
// Copy it in
|
||||||
// Make sure the folder exists
|
// Make sure the folder exists
|
||||||
tokio::fs::create_dir_all(OVERRIDE_FOLDER).await?;
|
fs::create_dir_all(OVERRIDE_FOLDER).await?;
|
||||||
// Then write the contents into the file
|
// Then write the contents into the file
|
||||||
tokio::fs::write(OVERRIDE_PATH, OVERRIDE_CONTENTS).await
|
fs::write(OVERRIDE_PATH, OVERRIDE_CONTENTS).await
|
||||||
} else {
|
} else {
|
||||||
// Delete it
|
// Delete it
|
||||||
tokio::fs::remove_file(OVERRIDE_PATH).await
|
fs::remove_file(OVERRIDE_PATH).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn restart_iwd() -> Result<bool> {
|
async fn restart_iwd() -> Result<bool> {
|
||||||
// First reload systemd since we modified the config most likely
|
// First reload systemd since we modified the config most likely
|
||||||
// otherwise we wouldn't be restarting iwd.
|
// otherwise we wouldn't be restarting iwd.
|
||||||
match run_script("reload systemd", "systemctl", &["daemon-reload"]).await {
|
match run_script("reload systemd", SYSTEMCTL_PATH, &["daemon-reload"]).await {
|
||||||
Ok(value) => {
|
Ok(value) => {
|
||||||
if value {
|
if value {
|
||||||
// worked, now restart iwd
|
// worked, now restart iwd
|
||||||
run_script("restart iwd", "systemctl", &["restart", "iwd"]).await
|
run_script("restart iwd", SYSTEMCTL_PATH, &["restart", "iwd"]).await
|
||||||
} else {
|
} else {
|
||||||
// reload failed
|
// reload failed
|
||||||
error!("restart_iwd: reload systemd failed with non-zero exit code");
|
error!("restart_iwd: reload systemd failed with non-zero exit code");
|
||||||
|
@ -148,11 +142,11 @@ async fn restart_iwd() -> Result<bool> {
|
||||||
|
|
||||||
async fn stop_tracing() -> Result<bool> {
|
async fn stop_tracing() -> Result<bool> {
|
||||||
// Stop tracing and extract ring buffer to disk for capture
|
// Stop tracing and extract ring buffer to disk for capture
|
||||||
run_script("stop tracing", "trace-cmd", &["stop"]).await?;
|
run_script("stop tracing", TRACE_CMD_PATH, &["stop"]).await?;
|
||||||
// stop tracing worked
|
// stop tracing worked
|
||||||
run_script(
|
run_script(
|
||||||
"extract traces",
|
"extract traces",
|
||||||
"trace-cmd",
|
TRACE_CMD_PATH,
|
||||||
&["extract", "-o", OUTPUT_FILE],
|
&["extract", "-o", OUTPUT_FILE],
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
@ -163,7 +157,7 @@ async fn start_tracing(buffer_size: u32) -> Result<bool> {
|
||||||
let size_str = format!("{}", buffer_size);
|
let size_str = format!("{}", buffer_size);
|
||||||
run_script(
|
run_script(
|
||||||
"start tracing",
|
"start tracing",
|
||||||
"trace-cmd",
|
TRACE_CMD_PATH,
|
||||||
&["start", "-e", "ath11k_wmi_diag", "-b", &size_str],
|
&["start", "-e", "ath11k_wmi_diag", "-b", &size_str],
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
@ -254,7 +248,11 @@ impl SMManager {
|
||||||
|
|
||||||
async fn factory_reset(&self) -> bool {
|
async fn factory_reset(&self) -> bool {
|
||||||
// Run steamos factory reset script and return true on success
|
// Run steamos factory reset script and return true on success
|
||||||
run_script("factory reset", "steamos-factory-reset-config", &[""])
|
run_script(
|
||||||
|
"factory reset",
|
||||||
|
"/usr/bin/steamos-factory-reset-config",
|
||||||
|
&[""],
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
@ -275,7 +273,7 @@ impl SMManager {
|
||||||
if enable {
|
if enable {
|
||||||
run_script(
|
run_script(
|
||||||
"enable fan control",
|
"enable fan control",
|
||||||
"systemcltl",
|
SYSTEMCTL_PATH,
|
||||||
&["start", "jupiter-fan-control-service"],
|
&["start", "jupiter-fan-control-service"],
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
@ -283,7 +281,7 @@ impl SMManager {
|
||||||
} else {
|
} else {
|
||||||
run_script(
|
run_script(
|
||||||
"disable fan control",
|
"disable fan control",
|
||||||
"systemctl",
|
SYSTEMCTL_PATH,
|
||||||
&["stop", "jupiter-fan-control.service"],
|
&["stop", "jupiter-fan-control.service"],
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
@ -294,7 +292,11 @@ impl SMManager {
|
||||||
async fn hardware_check_support(&self) -> bool {
|
async fn hardware_check_support(&self) -> bool {
|
||||||
// Run jupiter-check-support note this script does exit 1 for "Support: No" case
|
// Run jupiter-check-support note this script does exit 1 for "Support: No" case
|
||||||
// so no need to parse output, etc.
|
// so no need to parse output, etc.
|
||||||
run_script("check hardware support", "jupiter-check-support", &[""])
|
run_script(
|
||||||
|
"check hardware support",
|
||||||
|
"/usr/bin/jupiter-check-support",
|
||||||
|
&[""],
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue