Rename RogBios bits to Platform. Better GPU MUX support.

This commit is contained in:
Luke D. Jones
2022-08-12 21:51:04 +12:00
parent d35707f2e4
commit a0f7cf3acd
16 changed files with 122 additions and 164 deletions

View File

@@ -12,6 +12,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
+ hidraw
+ usbraw
- Refactor how ROGCC handles IPC for background open, run-in-bg
### Breaking
- DBUS: rename path `/org/asuslinux/RogBios` to `/org/asuslinux/Platform`
- DBUS: renamed `dedicated_graphic_mode` to `gpu_mux_mode` (`GpuMuxMode`)
- DBUS: renamed `set_dedicated_graphic_mode` to `set_gpu_mux_mode` (`SetGpuMuxMode`)
+ The methods above take an enum: 0 = Discrete, 1 = Optimus
## [4.3.4] - 2022-08-03
### Bugfix

View File

@@ -2,7 +2,7 @@ use notify_rust::{Hint, Notification, NotificationHandle};
use rog_aura::AuraEffect;
use rog_dbus::{
zbus_charge::ChargeProxy, zbus_led::LedProxy, zbus_profile::ProfileProxy,
zbus_rogbios::RogBiosProxy,
zbus_platform::RogBiosProxy,
};
use rog_profiles::Profile;
use smol::{future, Executor};

View File

@@ -80,11 +80,11 @@ pub struct BiosCommand {
meta = "",
short = "D",
no_long,
help = "activate dGPU dedicated/G-Sync: asusctl -d <true/false>, reboot required"
help = "Switch GPU MUX mode: 0 = Discrete, 1 = Optimus, reboot required"
)]
pub dedicated_gfx_set: Option<bool>,
pub gpu_mux_mode_set: Option<u8>,
#[options(no_long, short = "d", help = "get GPU mode")]
pub dedicated_gfx_get: bool,
pub gpu_mux_mode_get: bool,
#[options(
meta = "",
short = "O",

View File

@@ -753,8 +753,8 @@ fn handle_bios_option(
cmd: &BiosCommand,
) -> Result<(), Box<dyn std::error::Error>> {
{
if (cmd.dedicated_gfx_set.is_none()
&& !cmd.dedicated_gfx_get
if (cmd.gpu_mux_mode_set.is_none()
&& !cmd.gpu_mux_mode_get
&& cmd.post_sound_set.is_none()
&& !cmd.post_sound_get
&& cmd.panel_overdrive_set.is_none()
@@ -785,21 +785,14 @@ fn handle_bios_option(
println!("Bios POST sound on: {}", res);
}
if let Some(opt) = cmd.dedicated_gfx_set {
if let Some(opt) = cmd.gpu_mux_mode_set {
println!("Rebuilding initrd to include drivers");
dbus.proxies().rog_bios().set_dedicated_graphic_mode(opt)?;
dbus.proxies().rog_bios().set_gpu_mux_mode(opt.into())?;
println!("The mode change is not active until you reboot, on boot the bios will make the required change");
if opt {
println!(
"NOTE: on reboot your display manager will be forced to use Nvidia drivers"
);
} else {
println!("NOTE: after reboot you can then select regular graphics modes");
}
}
if cmd.dedicated_gfx_get {
let res = dbus.proxies().rog_bios().dedicated_graphic_mode()?;
println!("Bios dedicated GPU on: {}", res);
if cmd.gpu_mux_mode_get {
let res = dbus.proxies().rog_bios().gpu_mux_mode()?;
println!("Bios GPU MUX: {:?}", res);
}
if let Some(opt) = cmd.panel_overdrive_set {

View File

@@ -1,10 +1,9 @@
use crate::{config::Config, error::RogError, GetSupported};
use async_trait::async_trait;
use log::{error, info, warn};
use rog_platform::platform::AsusPlatform;
use log::{info, warn};
use rog_platform::platform::{AsusPlatform, GpuMuxMode};
use rog_platform::supported::RogBiosSupportedFunctions;
use std::fs::OpenOptions;
use std::io::BufRead;
use std::io::{Read, Write};
use std::path::Path;
use std::process::Command;
@@ -13,11 +12,6 @@ use std::sync::Mutex;
use zbus::Connection;
use zbus::{dbus_interface, SignalContext};
const INITRAMFS_PATH: &str = "/usr/sbin/update-initramfs";
const DRACUT_PATH: &str = "/usr/bin/dracut";
// static ASUS_SWITCH_GRAPHIC_MODE: &str =
// "/sys/firmware/efi/efivars/AsusSwitchGraphicMode-607005d5-3f75-4b2e-98f0-85ba66797a3e";
static ASUS_POST_LOGO_SOUND: &str =
"/sys/firmware/efi/efivars/AsusPostLogoSound-607005d5-3f75-4b2e-98f0-85ba66797a3e";
@@ -54,36 +48,34 @@ impl GetSupported for CtrlRogBios {
#[dbus_interface(name = "org.asuslinux.Daemon")]
impl CtrlRogBios {
async fn set_dedicated_graphic_mode(
async fn set_gpu_mux_mode(
&mut self,
#[zbus(signal_context)] ctxt: SignalContext<'_>,
dedicated: bool,
mode: GpuMuxMode,
) {
self.set_gfx_mode(dedicated)
self.set_gfx_mode(mode)
.map_err(|err| {
warn!("CtrlRogBios: set_asus_switch_graphic_mode {}", err);
err
})
.ok();
Self::notify_dedicated_graphic_mode(&ctxt, dedicated)
.await
.ok();
Self::notify_gpu_mux_mode(&ctxt, mode).await.ok();
}
fn dedicated_graphic_mode(&self) -> bool {
self.platform
.get_gpu_mux_mode()
.map_err(|err| {
warn!("CtrlRogBios: get_gfx_mode {}", err);
err
})
.unwrap_or(false)
fn gpu_mux_mode(&self) -> GpuMuxMode {
match self.platform.get_gpu_mux_mode() {
Ok(m) => m.into(),
Err(e) => {
warn!("CtrlRogBios: get_gfx_mode {}", e);
GpuMuxMode::Error
}
}
}
#[dbus_interface(signal)]
async fn notify_dedicated_graphic_mode(
async fn notify_gpu_mux_mode(
signal_ctxt: &SignalContext<'_>,
dedicated: bool,
mode: GpuMuxMode,
) -> zbus::Result<()> {
}
@@ -151,7 +143,7 @@ impl CtrlRogBios {
#[async_trait]
impl crate::ZbusAdd for CtrlRogBios {
async fn add_to_server(self, server: &mut Connection) {
Self::add_to_server_helper(self, "/org/asuslinux/RogBios", server).await;
Self::add_to_server_helper(self, "/org/asuslinux/Platform", server).await;
}
}
@@ -191,10 +183,10 @@ impl CtrlRogBios {
Ok(())
}
pub(super) fn set_gfx_mode(&self, enable: bool) -> Result<(), RogError> {
self.platform.set_gpu_mux_mode(enable)?;
self.update_initramfs(enable)?;
if enable {
fn set_gfx_mode(&self, mode: GpuMuxMode) -> Result<(), RogError> {
self.platform.set_gpu_mux_mode(mode.into())?;
// self.update_initramfs(enable)?;
if mode == GpuMuxMode::Discrete {
info!("Set system-level graphics mode: Dedicated Nvidia");
} else {
info!("Set system-level graphics mode: Optimus");
@@ -243,89 +235,6 @@ impl CtrlRogBios {
Ok(())
}
// required for g-sync mode
fn update_initramfs(&self, dedicated: bool) -> Result<(), RogError> {
let mut initfs_cmd = None;
if Path::new(INITRAMFS_PATH).exists() {
let mut cmd = Command::new("update-initramfs");
cmd.arg("-u");
initfs_cmd = Some(cmd);
info!("Using initramfs update command 'update-initramfs'");
} else if Path::new(DRACUT_PATH).exists() {
let mut cmd = Command::new("dracut");
cmd.arg("-f");
cmd.arg("-q");
initfs_cmd = Some(cmd);
info!("Using initramfs update command 'dracut'");
}
if let Some(mut cmd) = initfs_cmd {
info!("Updating initramfs");
// If switching to Nvidia dedicated we need these modules included
if Path::new(DRACUT_PATH).exists() && dedicated {
cmd.arg("--add-drivers");
cmd.arg("nvidia nvidia-drm nvidia-modeset nvidia-uvm");
info!("System uses dracut, forcing nvidia modules to be included in init");
} else if Path::new(INITRAMFS_PATH).exists() {
let modules = vec![
"nvidia\n",
"nvidia-drm\n",
"nvidia-modeset\n",
"nvidia-uvm\n",
];
let module_include = Path::new("/etc/initramfs-tools/modules");
if dedicated {
let mut file = std::fs::OpenOptions::new()
.append(true)
.open(module_include)
.map_err(|err| {
RogError::Write(module_include.to_string_lossy().to_string(), err)
})?;
// add nvidia modules to module_include
file.write_all(modules.concat().as_bytes())?;
} else {
let file = std::fs::OpenOptions::new()
.read(true)
.open(module_include)
.map_err(|err| {
RogError::Write(module_include.to_string_lossy().to_string(), err)
})?;
let mut buf = Vec::new();
// remove modules
for line in std::io::BufReader::new(file).lines().flatten() {
if !modules.contains(&line.as_str()) {
buf.append(&mut line.as_bytes().to_vec());
}
}
let file = std::fs::OpenOptions::new()
.write(true)
.open(module_include)
.map_err(|err| {
RogError::Write(module_include.to_string_lossy().to_string(), err)
})?;
std::io::BufWriter::new(file).write_all(&buf)?;
}
}
let status = cmd
.status()
.map_err(|err| RogError::Write(format!("{:?}", cmd), err))?;
if !status.success() {
error!("Ram disk update failed");
return Err(RogError::Initramfs("Ram disk update failed".into()));
} else {
info!("Successfully updated initramfs");
}
}
Ok(())
}
fn set_panel_od(&mut self, enable: bool) -> Result<(), RogError> {
self.platform.set_panel_od(enable).map_err(|err| {
warn!("CtrlRogBios: set_panel_overdrive {}", err);

View File

@@ -6,7 +6,7 @@ use zvariant::Type;
use crate::{
ctrl_anime::CtrlAnime, ctrl_aura::controller::CtrlKbdLed, ctrl_charge::CtrlCharge,
ctrl_profiles::controller::CtrlPlatformProfile, ctrl_rog_bios::CtrlRogBios, GetSupported,
ctrl_profiles::controller::CtrlPlatformProfile, ctrl_platform::CtrlRogBios, GetSupported,
};
use rog_platform::supported::*;

View File

@@ -18,7 +18,7 @@ use daemon::ctrl_aura::controller::{
};
use daemon::ctrl_charge::CtrlCharge;
use daemon::ctrl_profiles::config::ProfileConfig;
use daemon::ctrl_rog_bios::CtrlRogBios;
use daemon::ctrl_platform::CtrlRogBios;
use daemon::{
config::Config, ctrl_supported::SupportedFunctions, laptops::print_board_info, GetSupported,
};

View File

@@ -20,7 +20,7 @@ pub mod ctrl_charge;
/// - Fan min/max RPM curve
pub mod ctrl_profiles;
/// Control ASUS bios function such as boot sound, Optimus/Dedicated gfx mode
pub mod ctrl_rog_bios;
pub mod ctrl_platform;
/// Laptop matching to determine capabilities
pub mod laptops;

View File

@@ -62,7 +62,7 @@ impl Bios {
pub fn post_boot_sound(&self) -> Result<i16> {
Ok(1)
}
pub fn dedicated_graphic_mode(&self) -> Result<i16> {
pub fn gpu_mux_mode(&self) -> Result<i16> {
Ok(1)
}
pub fn panel_overdrive(&self) -> Result<i16> {
@@ -71,7 +71,7 @@ impl Bios {
pub fn set_post_boot_sound(&self, _b: bool) -> Result<()> {
Ok(())
}
pub fn set_dedicated_graphic_mode(&self, _b: bool) -> Result<()> {
pub fn set_gpu_mux_mode(&self, _b: bool) -> Result<()> {
Ok(())
}
pub fn set_panel_overdrive(&self, _b: bool) -> Result<()> {

View File

@@ -5,7 +5,7 @@ use notify_rust::{Hint, Notification, NotificationHandle};
use rog_aura::AuraEffect;
use rog_dbus::{
zbus_anime::AnimeProxy, zbus_charge::ChargeProxy, zbus_led::LedProxy,
zbus_profile::ProfileProxy, zbus_rogbios::RogBiosProxy,
zbus_profile::ProfileProxy, zbus_platform::RogBiosProxy,
};
use rog_profiles::Profile;
use smol::{future, Executor};

View File

@@ -8,7 +8,7 @@ use std::{
use egui::Vec2;
use rog_aura::{layouts::KeyLayout, usb::AuraPowerDev, AuraEffect, AuraModeNum};
use rog_platform::supported::SupportedFunctions;
use rog_platform::{platform::GpuMuxMode, supported::SupportedFunctions};
use rog_profiles::{fan_curve_set::FanCurveSet, FanCurvePU, Profile};
use crate::{error::Result, RogDbusClientBlocking};
@@ -20,7 +20,7 @@ pub struct BiosState {
/// updated, so the full state needs refresh
pub was_notified: Arc<AtomicBool>,
pub post_sound: bool,
pub dedicated_gfx: bool,
pub dedicated_gfx: GpuMuxMode,
pub panel_overdrive: bool,
pub dgpu_disable: bool,
pub egpu_enable: bool,
@@ -40,9 +40,9 @@ impl BiosState {
false
},
dedicated_gfx: if supported.rog_bios_ctrl.dgpu_only {
dbus.proxies().rog_bios().dedicated_graphic_mode()?
dbus.proxies().rog_bios().gpu_mux_mode()?
} else {
false
GpuMuxMode::NotSupported
},
panel_overdrive: if supported.rog_bios_ctrl.panel_overdrive {
dbus.proxies().rog_bios().panel_overdrive()?
@@ -337,7 +337,7 @@ impl Default for PageDataStates {
bios: BiosState {
was_notified: Default::default(),
post_sound: Default::default(),
dedicated_gfx: Default::default(),
dedicated_gfx: GpuMuxMode::NotSupported,
panel_overdrive: Default::default(),
dgpu_disable: Default::default(),
egpu_enable: Default::default(),

View File

@@ -1,6 +1,6 @@
use crate::{page_states::PageDataStates, RogDbusClientBlocking};
use egui::Ui;
use rog_platform::supported::SupportedFunctions;
use rog_platform::{platform::GpuMuxMode, supported::SupportedFunctions};
use rog_profiles::Profile;
pub fn platform_profile(states: &mut PageDataStates, dbus: &RogDbusClientBlocking, ui: &mut Ui) {
@@ -91,16 +91,33 @@ pub fn rog_bios_group(
}
if supported.rog_bios_ctrl.dgpu_only {
if ui
.add(egui::Checkbox::new(
&mut states.bios.dedicated_gfx,
"G-Sync Dedicated GPU mode",
))
.changed()
{
let mut changed = false;
ui.group(|ui| {
ui.vertical(|ui| {
ui.horizontal_wrapped(|ui| ui.label("GPU MUX mode (reboot required)"));
ui.horizontal_wrapped(|ui| {
changed = ui
.selectable_value(
&mut states.bios.dedicated_gfx,
GpuMuxMode::Discrete,
"Dedicated (Ultimate)",
)
.clicked()
|| ui
.selectable_value(
&mut states.bios.dedicated_gfx,
GpuMuxMode::Optimus,
"Optimus (Hybrid)",
)
.clicked();
});
});
});
if changed {
dbus.proxies()
.rog_bios()
.set_dedicated_graphic_mode(states.bios.dedicated_gfx)
.set_gpu_mux_mode(states.bios.dedicated_gfx)
.map_err(|err| {
states.error = Some(err.to_string());
})

View File

@@ -6,7 +6,7 @@ pub mod zbus_anime;
pub mod zbus_charge;
pub mod zbus_led;
pub mod zbus_profile;
pub mod zbus_rogbios;
pub mod zbus_platform;
pub mod zbus_supported;
// use rog_anime::AnimePowerStates;
@@ -21,7 +21,7 @@ pub struct DbusProxiesBlocking<'a> {
charge: zbus_charge::ChargeProxyBlocking<'a>,
led: zbus_led::LedProxyBlocking<'a>,
profile: zbus_profile::ProfileProxyBlocking<'a>,
rog_bios: zbus_rogbios::RogBiosProxyBlocking<'a>,
rog_bios: zbus_platform::RogBiosProxyBlocking<'a>,
supported: zbus_supported::SupportedProxyBlocking<'a>,
}
@@ -36,7 +36,7 @@ impl<'a> DbusProxiesBlocking<'a> {
led: zbus_led::LedProxyBlocking::new(&conn)?,
charge: zbus_charge::ChargeProxyBlocking::new(&conn)?,
profile: zbus_profile::ProfileProxyBlocking::new(&conn)?,
rog_bios: zbus_rogbios::RogBiosProxyBlocking::new(&conn)?,
rog_bios: zbus_platform::RogBiosProxyBlocking::new(&conn)?,
supported: zbus_supported::SupportedProxyBlocking::new(&conn)?,
},
conn,
@@ -59,7 +59,7 @@ impl<'a> DbusProxiesBlocking<'a> {
&self.profile
}
pub fn rog_bios(&self) -> &zbus_rogbios::RogBiosProxyBlocking<'a> {
pub fn rog_bios(&self) -> &zbus_platform::RogBiosProxyBlocking<'a> {
&self.rog_bios
}
@@ -90,7 +90,7 @@ pub struct DbusProxies<'a> {
charge: zbus_charge::ChargeProxy<'a>,
led: zbus_led::LedProxy<'a>,
profile: zbus_profile::ProfileProxy<'a>,
rog_bios: zbus_rogbios::RogBiosProxy<'a>,
rog_bios: zbus_platform::RogBiosProxy<'a>,
supported: zbus_supported::SupportedProxy<'a>,
}
@@ -105,7 +105,7 @@ impl<'a> DbusProxies<'a> {
led: zbus_led::LedProxy::new(&conn).await?,
charge: zbus_charge::ChargeProxy::new(&conn).await?,
profile: zbus_profile::ProfileProxy::new(&conn).await?,
rog_bios: zbus_rogbios::RogBiosProxy::new(&conn).await?,
rog_bios: zbus_platform::RogBiosProxy::new(&conn).await?,
supported: zbus_supported::SupportedProxy::new(&conn).await?,
},
conn,
@@ -128,7 +128,7 @@ impl<'a> DbusProxies<'a> {
&self.profile
}
pub fn rog_bios(&self) -> &zbus_rogbios::RogBiosProxy<'a> {
pub fn rog_bios(&self) -> &zbus_platform::RogBiosProxy<'a> {
&self.rog_bios
}

View File

@@ -1,7 +1,7 @@
//! # DBus interface proxy for: `org.asuslinux.Daemon`
//!
//! This code was generated by `zbus-xmlgen` `1.0.0` from DBus introspection data.
//! Source: `Interface '/org/asuslinux/RogBios' from service 'org.asuslinux.Daemon' on system bus`.
//! Source: `Interface '/org/asuslinux/Platform' from service 'org.asuslinux.Daemon' on system bus`.
//!
//! You may prefer to adapt it, instead of using it verbatim.
//!
@@ -19,21 +19,22 @@
//!
//! …consequently `zbus-xmlgen` did not generate code for the above interfaces.
use rog_platform::platform::GpuMuxMode;
use zbus_macros::dbus_proxy;
#[dbus_proxy(
interface = "org.asuslinux.Daemon",
default_path = "/org/asuslinux/RogBios"
default_path = "/org/asuslinux/Platform"
)]
trait RogBios {
/// DedicatedGraphicMode method
fn dedicated_graphic_mode(&self) -> zbus::Result<bool>;
fn gpu_mux_mode(&self) -> zbus::Result<GpuMuxMode>;
/// PostBootSound method
fn post_boot_sound(&self) -> zbus::Result<i16>;
/// SetDedicatedGraphicMode method
fn set_dedicated_graphic_mode(&self, dedicated: bool) -> zbus::Result<()>;
fn set_gpu_mux_mode(&self, mode: GpuMuxMode) -> zbus::Result<()>;
/// SetPostBootSound method
fn set_post_boot_sound(&self, on: bool) -> zbus::Result<()>;
@@ -46,7 +47,7 @@ trait RogBios {
/// NotifyDedicatedGraphicMode signal
#[dbus_proxy(signal)]
fn notify_dedicated_graphic_mode(&self, dedicated: bool) -> zbus::Result<()>;
fn notify_gpu_mux_mode(&self, mode: GpuMuxMode) -> zbus::Result<()>;
/// NotifyPostBootSound signal
#[dbus_proxy(signal)]

View File

@@ -1,3 +1,6 @@
//! This crate functions as a wrapper of all the relevant ASUS functionality
//! on ROG, Strix, and TUF laptops.
pub mod error;
pub mod hid_raw;
pub mod keyboard_led;

View File

@@ -1,9 +1,11 @@
use std::path::PathBuf;
use log::warn;
use serde::{Deserialize, Serialize};
use zvariant::Type;
use crate::{
attr_bool,
attr_bool, attr_u8,
error::{PlatformError, Result},
to_device,
};
@@ -60,10 +62,38 @@ impl AsusPlatform {
attr_bool!(has_panel_od, get_panel_od, set_panel_od, "panel_od");
attr_bool!(
attr_u8!(
has_gpu_mux_mode,
get_gpu_mux_mode,
set_gpu_mux_mode,
"gpu_mux_mode"
);
}
#[derive(Serialize, Deserialize, Type, Debug, PartialEq, Clone, Copy)]
pub enum GpuMuxMode {
Discrete,
Optimus,
Error,
NotSupported,
}
impl From<u8> for GpuMuxMode {
fn from(m: u8) -> Self {
if m > 0 {
return Self::Optimus;
}
Self::Discrete
}
}
impl From<GpuMuxMode> for u8 {
fn from(m: GpuMuxMode) -> Self {
match m {
GpuMuxMode::Discrete => 0,
GpuMuxMode::Optimus => 1,
GpuMuxMode::Error => 254,
GpuMuxMode::NotSupported => 255,
}
}
}