From 14584d0540efc42268745fc1d5f2e1ee4fd250b7 Mon Sep 17 00:00:00 2001 From: Jeremy Whiting Date: Mon, 9 Oct 2023 12:56:22 -0600 Subject: [PATCH 1/6] Add format sdcard, update bios/dock, trim devices scripts. For each of those use the respective polkit-helper script for forward compatibility in case those change. --- src/manager.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/manager.rs b/src/manager.rs index a92c547..fcfc331 100644 --- a/src/manager.rs +++ b/src/manager.rs @@ -108,6 +108,31 @@ impl SMManager { value } + async fn update_bios(&self) -> bool { + // Update the bios as needed + // Return true if the script was successful (though that might mean no update was needed), false otherwise + run_script("update bios", "/usr/bin/steamos-potlkit-helpers/jupiter-biosupdate", &["--auto"]).await + } + + async fn update_dock(&self) -> bool { + // Update the dock firmware as needed + // Retur true if successful, false otherwise + run_script("update dock firmware", "/usr/bin/steamos-polkit-helpers/jupiter-dock-updater", &[""]).await + } + + async fn trim_devices(&self) -> bool { + // Run steamos-trim-devices script + // return true on success, false otherwise + run_script("trim devices", "/usr/bin/steamos-polkit-helpers/steamos-trim-devices", &[""]).await + } + + async fn format_sdcard(&self) -> bool { + // Run steamos-format-sdcard script + // return true on success, false otherwise + run_script("format sdcard", "/usr/bin/steamos-polkit-helpers/steamos-format-sdcard", &[""]).await + } + + /// A version property. #[dbus_interface(property)] async fn version(&self) -> u32 { From 05a716b3b1d496a56cfb5e4319d477cc0bdd458f Mon Sep 17 00:00:00 2001 From: Jeremy Whiting Date: Mon, 9 Oct 2023 13:08:53 -0600 Subject: [PATCH 2/6] Remove SetAdaptiveBrightness, SetLEDBrightness, and SetBacklight. For now these 3 aren't needed or aren't used by steam client so removing them for now. --- com.steampowered.SteamOSManager1.xml | 36 ---------------------------- 1 file changed, 36 deletions(-) diff --git a/com.steampowered.SteamOSManager1.xml b/com.steampowered.SteamOSManager1.xml index c5ddbc9..47eeb73 100644 --- a/com.steampowered.SteamOSManager1.xml +++ b/com.steampowered.SteamOSManager1.xml @@ -175,18 +175,6 @@ - - - - - - - - - - - - - - - - - From 0a49fdaf1f4ff162b172994a2586e42141ad0c24 Mon Sep 17 00:00:00 2001 From: Jeremy Whiting Date: Wed, 11 Oct 2023 13:20:53 -0600 Subject: [PATCH 3/6] Implement set_gpu_performance_level. Use an enum of values for level: 0 - auto 1 - low 2 - high 3 - manual 4 - peak_performance If any out of range are given, return an false. If unable to write or open for writing, return false. May change to give an err type instead later if that helps client side. --- com.steampowered.SteamOSManager1.xml | 4 +--- src/manager.rs | 32 +++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/com.steampowered.SteamOSManager1.xml b/com.steampowered.SteamOSManager1.xml index 47eeb73..5828e1f 100644 --- a/com.steampowered.SteamOSManager1.xml +++ b/com.steampowered.SteamOSManager1.xml @@ -137,15 +137,13 @@ - diff --git a/src/manager.rs b/src/manager.rs index fcfc331..084ecd9 100644 --- a/src/manager.rs +++ b/src/manager.rs @@ -24,7 +24,7 @@ */ use std::{ffi::OsStr}; -use tokio::process::Command; +use tokio::{process::Command, fs::File, io::AsyncWriteExt}; use zbus_macros::dbus_interface; pub struct SMManager { } @@ -132,6 +132,36 @@ impl SMManager { run_script("format sdcard", "/usr/bin/steamos-polkit-helpers/steamos-format-sdcard", &[""]).await } + async fn set_gpu_performance_level(&self, level: i32) -> bool { + // Set given level to sysfs path /sys/class/drm/card0/device/power_dpm_force_performance_level + // Levels are defined below + // return true if able to write, false otherwise or if level is out of range, etc. + let levels = [ + "auto", + "low", + "high", + "manual", + "peak_performance" + ]; + if level < 0 || level >= levels.len() as i32 { + return false; + } + + // Open sysfs file + let result = File::create("/sys/class/drm/card0/device/power_dpm_force_performance_level").await; + let mut myfile; + match result { + Ok(f) => myfile = f, + Err(message) => { println!("Error opening sysfs file for writing {message}"); return false; } + }; + + // write value + let result = myfile.write_all(levels[level as usize].as_bytes()).await; + match result { + Ok(_worked) => true, + Err(message) => { println!("Error writing to sysfs file {message}"); false } + } + } /// A version property. #[dbus_interface(property)] From e2190d69ebed9feb246a62c694f71fba24020625 Mon Sep 17 00:00:00 2001 From: Jeremy Whiting Date: Wed, 18 Oct 2023 14:37:53 -0600 Subject: [PATCH 4/6] Add set_gpu_clocks for setting manual clock rates. Also fix typos in dbus xml to match generated api signatures. --- com.steampowered.SteamOSManager1.xml | 12 ++++----- src/manager.rs | 37 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/com.steampowered.SteamOSManager1.xml b/com.steampowered.SteamOSManager1.xml index 5828e1f..7354b17 100644 --- a/com.steampowered.SteamOSManager1.xml +++ b/com.steampowered.SteamOSManager1.xml @@ -136,28 +136,26 @@ - + - + - diff --git a/src/manager.rs b/src/manager.rs index 084ecd9..42873c0 100644 --- a/src/manager.rs +++ b/src/manager.rs @@ -162,6 +162,43 @@ impl SMManager { Err(message) => { println!("Error writing to sysfs file {message}"); false } } } + + async fn set_gpu_clocks(&self, clocks: i32) -> bool { + // Set gpu clocks to given value valid between 200 - 1600 + // Only used when Gpu Performance Level is manual, but write whenever called. + // Writes value to /sys/class/drm/card0/device/pp_od_clk_voltage + if !(200..=1600).contains(&clocks) { + return false; + } + + let result = File::create("/sys/class/drm/card0/device/pp_od_clk_voltage").await; + let mut myfile; + match result { + Ok(f) => myfile = f, + Err(message) => { println!("Error opening sysfs file for writing {message}"); return false; } + }; + + // write value + let data = format!("s 0 {clocks}\n"); + let result = myfile.write(data.as_bytes()).await; + match result { + Ok(_worked) => { + let data = format!("s 1 {clocks}\n"); + let result = myfile.write(data.as_bytes()).await; + match result { + Ok(_worked) => { + let result = myfile.write("c\n".as_bytes()).await; + match result { + Ok(_worked) => true, + Err(message) => { println!("Error writing to sysfs file {message}"); false } + } + }, + Err(message) => { println!("Error writing to sysfs file {message}"); false } + } + }, + Err(message) => { println!("Error writing to sysfs file {message}"); false } + } + } /// A version property. #[dbus_interface(property)] From bc3ad0a54f4d0a4e87f71516a3b5c2e8b50185a7 Mon Sep 17 00:00:00 2001 From: Jeremy Whiting Date: Wed, 18 Oct 2023 15:09:16 -0600 Subject: [PATCH 5/6] Implement SetTdpLimit. Write given limit to /sys/class/hwmon/hwmon5/power[12]_cap if in the range of 3..15. Return false if out of range or unable to write. --- com.steampowered.SteamOSManager1.xml | 4 +-- src/manager.rs | 37 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/com.steampowered.SteamOSManager1.xml b/com.steampowered.SteamOSManager1.xml index 7354b17..8e61396 100644 --- a/com.steampowered.SteamOSManager1.xml +++ b/com.steampowered.SteamOSManager1.xml @@ -160,8 +160,8 @@