mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Begin cleanup
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,3 +4,4 @@ cargo-config
|
|||||||
.idea
|
.idea
|
||||||
vendor-*
|
vendor-*
|
||||||
vendor_*
|
vendor_*
|
||||||
|
.vscode-ctags
|
||||||
|
|||||||
@@ -60,8 +60,8 @@ impl Config {
|
|||||||
if l == 0 {
|
if l == 0 {
|
||||||
warn!("File is empty {}", CONFIG_PATH);
|
warn!("File is empty {}", CONFIG_PATH);
|
||||||
} else {
|
} else {
|
||||||
serde_json::from_str(&buf)
|
*self = serde_json::from_str(&buf)
|
||||||
.unwrap_or_else(|_| panic!("Could not deserialise {}", CONFIG_PATH))
|
.unwrap_or_else(|_| panic!("Could not deserialise {}", CONFIG_PATH));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,6 @@ use std::io::{Read, Write};
|
|||||||
|
|
||||||
use crate::gfx_vendors::GfxVendors;
|
use crate::gfx_vendors::GfxVendors;
|
||||||
|
|
||||||
pub static CONFIG_PATH: &str = "/etc/asusd/asusd.conf";
|
|
||||||
pub static AURA_CONFIG_PATH: &str = "/etc/asusd/asusd.conf";
|
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
pub struct GfxConfig {
|
pub struct GfxConfig {
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
|
use ::zbus::Connection;
|
||||||
use log::{error, info, warn};
|
use log::{error, info, warn};
|
||||||
use logind_zbus::{
|
use logind_zbus::{
|
||||||
types::{SessionClass, SessionInfo, SessionState, SessionType},
|
types::{SessionClass, SessionInfo, SessionState, SessionType},
|
||||||
ManagerProxy, SessionProxy,
|
ManagerProxy, SessionProxy,
|
||||||
};
|
};
|
||||||
use ::zbus::Connection;
|
|
||||||
use std::{io::Write, ops::Add, path::Path, time::Instant};
|
use std::{io::Write, ops::Add, path::Path, time::Instant};
|
||||||
use std::{process::Command, thread::sleep, time::Duration};
|
use std::{process::Command, thread::sleep, time::Duration};
|
||||||
use std::{str::FromStr, sync::mpsc};
|
use std::{str::FromStr, sync::mpsc};
|
||||||
@@ -11,7 +11,12 @@ use std::{sync::Arc, sync::Mutex};
|
|||||||
use sysfs_class::RuntimePM;
|
use sysfs_class::RuntimePM;
|
||||||
use sysfs_class::{PciDevice, SysClass};
|
use sysfs_class::{PciDevice, SysClass};
|
||||||
|
|
||||||
use crate::{*, error::GfxError, system::{GraphicsDevice, PciBus}};
|
use crate::{
|
||||||
|
error::GfxError,
|
||||||
|
special::{get_asus_gsync_gfx_mode, has_asus_gsync_gfx_mode},
|
||||||
|
system::{GraphicsDevice, PciBus},
|
||||||
|
*,
|
||||||
|
};
|
||||||
|
|
||||||
use super::config::GfxConfig;
|
use super::config::GfxConfig;
|
||||||
use super::gfx_vendors::{GfxPower, GfxRequiredUserAction, GfxVendors};
|
use super::gfx_vendors::{GfxPower, GfxRequiredUserAction, GfxVendors};
|
||||||
@@ -137,12 +142,8 @@ impl CtrlGraphics {
|
|||||||
pub(super) fn get_runtime_status() -> Result<GfxPower, GfxError> {
|
pub(super) fn get_runtime_status() -> Result<GfxPower, GfxError> {
|
||||||
let path = Path::new(NVIDIA_RUNTIME_STATUS_PATH);
|
let path = Path::new(NVIDIA_RUNTIME_STATUS_PATH);
|
||||||
if path.exists() {
|
if path.exists() {
|
||||||
let buf = std::fs::read_to_string(path).map_err(|err| {
|
let buf = std::fs::read_to_string(path)
|
||||||
GfxError::Read(
|
.map_err(|err| GfxError::Read(path.to_string_lossy().to_string(), err))?;
|
||||||
path.to_string_lossy().to_string(),
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
Ok(GfxPower::from_str(&buf)?)
|
Ok(GfxPower::from_str(&buf)?)
|
||||||
} else {
|
} else {
|
||||||
Ok(GfxPower::Off)
|
Ok(GfxPower::Off)
|
||||||
@@ -630,11 +631,13 @@ impl CtrlGraphics {
|
|||||||
///
|
///
|
||||||
/// For manually calling (not on boot/startup) via dbus
|
/// For manually calling (not on boot/startup) via dbus
|
||||||
pub fn set_gfx_mode(&mut self, vendor: GfxVendors) -> Result<GfxRequiredUserAction, GfxError> {
|
pub fn set_gfx_mode(&mut self, vendor: GfxVendors) -> Result<GfxRequiredUserAction, GfxError> {
|
||||||
// if let Ok(gsync) = CtrlRogBios::get_gfx_mode() {
|
if has_asus_gsync_gfx_mode() {
|
||||||
// if gsync == 1 {
|
if let Ok(gsync) = get_asus_gsync_gfx_mode() {
|
||||||
// return Err(GfxError::GsyncModeActive.into());
|
if gsync == 1 {
|
||||||
// }
|
return Err(GfxError::AsusGsyncModeActive);
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let vfio_enable = if let Ok(config) = self.config.try_lock() {
|
let vfio_enable = if let Ok(config) = self.config.try_lock() {
|
||||||
config.gfx_vfio_enable
|
config.gfx_vfio_enable
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ pub enum GfxError {
|
|||||||
Bus(String, std::io::Error),
|
Bus(String, std::io::Error),
|
||||||
DisplayManagerAction(String, ExitStatus),
|
DisplayManagerAction(String, ExitStatus),
|
||||||
DisplayManagerTimeout(String),
|
DisplayManagerTimeout(String),
|
||||||
GsyncModeActive,
|
AsusGsyncModeActive,
|
||||||
VfioBuiltin,
|
VfioBuiltin,
|
||||||
VfioDisabled,
|
VfioDisabled,
|
||||||
MissingModule(String),
|
MissingModule(String),
|
||||||
@@ -34,7 +34,7 @@ impl fmt::Display for GfxError {
|
|||||||
GfxError::DisplayManagerTimeout(state) => {
|
GfxError::DisplayManagerTimeout(state) => {
|
||||||
write!(f, "Timed out waiting for display-manager {} state", state)
|
write!(f, "Timed out waiting for display-manager {} state", state)
|
||||||
}
|
}
|
||||||
GfxError::GsyncModeActive => write!(
|
GfxError::AsusGsyncModeActive => write!(
|
||||||
f,
|
f,
|
||||||
"Can not switch gfx modes when dedicated/G-Sync mode is active"
|
"Can not switch gfx modes when dedicated/G-Sync mode is active"
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ pub mod config;
|
|||||||
pub mod gfx_vendors;
|
pub mod gfx_vendors;
|
||||||
pub mod controller;
|
pub mod controller;
|
||||||
pub mod system;
|
pub mod system;
|
||||||
|
/// Special-case functions for check/read/write of key functions on unique laptops
|
||||||
|
/// such as the G-Sync mode available on some ASUS ROG laptops
|
||||||
|
pub(crate) mod special;
|
||||||
pub mod zbus;
|
pub mod zbus;
|
||||||
|
|
||||||
const NVIDIA_DRIVERS: [&str; 4] = ["nvidia_drm", "nvidia_modeset", "nvidia_uvm", "nvidia"];
|
const NVIDIA_DRIVERS: [&str; 4] = ["nvidia_drm", "nvidia_modeset", "nvidia_uvm", "nvidia"];
|
||||||
@@ -17,13 +20,9 @@ const VFIO_DRIVERS: [&str; 5] = [
|
|||||||
|
|
||||||
const DISPLAY_MANAGER: &str = "display-manager.service";
|
const DISPLAY_MANAGER: &str = "display-manager.service";
|
||||||
|
|
||||||
const MODPROBE_PATH: &str = "/etc/modprobe.d/asusd.conf";
|
const MODPROBE_PATH: &str = "/etc/modprobe.d/supergfxd.conf";
|
||||||
|
|
||||||
static MODPROBE_BASE: &[u8] = br#"# Automatically generated by asusd
|
static MODPROBE_BASE: &[u8] = br#"# Automatically generated by supergfxd
|
||||||
# If you have issues with i2c_nvidia_gpu, copy the 2 lines below to a
|
|
||||||
# new blacklist file and uncomment
|
|
||||||
#blacklist i2c_nvidia_gpu
|
|
||||||
#alias i2c_nvidia_gpu off
|
|
||||||
blacklist nouveau
|
blacklist nouveau
|
||||||
alias nouveau off
|
alias nouveau off
|
||||||
options nvidia NVreg_DynamicPowerManagement=0x02
|
options nvidia NVreg_DynamicPowerManagement=0x02
|
||||||
@@ -33,7 +32,7 @@ static MODPROBE_DRM_MODESET: &[u8] = br#"
|
|||||||
options nvidia-drm modeset=1
|
options nvidia-drm modeset=1
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
static MODPROBE_INTEGRATED: &[u8] = br#"# Automatically generated by asusd
|
static MODPROBE_INTEGRATED: &[u8] = br#"# Automatically generated by supergfxd
|
||||||
blacklist i2c_nvidia_gpu
|
blacklist i2c_nvidia_gpu
|
||||||
blacklist nvidia
|
blacklist nvidia
|
||||||
blacklist nvidia-drm
|
blacklist nvidia-drm
|
||||||
@@ -47,7 +46,7 @@ static MODPROBE_VFIO: &[u8] = br#"options vfio-pci ids="#;
|
|||||||
const XORG_FILE: &str = "90-nvidia-primary.conf";
|
const XORG_FILE: &str = "90-nvidia-primary.conf";
|
||||||
const XORG_PATH: &str = "/etc/X11/xorg.conf.d/";
|
const XORG_PATH: &str = "/etc/X11/xorg.conf.d/";
|
||||||
|
|
||||||
static PRIMARY_GPU_BEGIN: &[u8] = br#"# Automatically generated by asusd
|
static PRIMARY_GPU_BEGIN: &[u8] = br#"# Automatically generated by supergfxd
|
||||||
Section "OutputClass"
|
Section "OutputClass"
|
||||||
Identifier "nvidia"
|
Identifier "nvidia"
|
||||||
MatchDriver "nvidia-drm"
|
MatchDriver "nvidia-drm"
|
||||||
|
|||||||
25
supergfx/src/special.rs
Normal file
25
supergfx/src/special.rs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
use std::{fs::OpenOptions, io::Read, path::Path};
|
||||||
|
|
||||||
|
use crate::error::GfxError;
|
||||||
|
|
||||||
|
static ASUS_SWITCH_GRAPHIC_MODE: &str =
|
||||||
|
"/sys/firmware/efi/efivars/AsusSwitchGraphicMode-607005d5-3f75-4b2e-98f0-85ba66797a3e";
|
||||||
|
|
||||||
|
pub(crate) fn has_asus_gsync_gfx_mode() -> bool {
|
||||||
|
Path::new(ASUS_SWITCH_GRAPHIC_MODE).exists()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn get_asus_gsync_gfx_mode() -> Result<i8, GfxError> {
|
||||||
|
let path = ASUS_SWITCH_GRAPHIC_MODE;
|
||||||
|
let mut file = OpenOptions::new()
|
||||||
|
.read(true)
|
||||||
|
.open(path)
|
||||||
|
.map_err(|err| GfxError::Path(path.into(), err))?;
|
||||||
|
|
||||||
|
let mut data = Vec::new();
|
||||||
|
file.read_to_end(&mut data)
|
||||||
|
.map_err(|err| GfxError::Read(path.into(), err))?;
|
||||||
|
|
||||||
|
let idx = data.len() - 1;
|
||||||
|
Ok(data[idx] as i8)
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ use log::{error, info, warn};
|
|||||||
use zvariant::ObjectPath;
|
use zvariant::ObjectPath;
|
||||||
use ::zbus::dbus_interface;
|
use ::zbus::dbus_interface;
|
||||||
|
|
||||||
use crate::{gfx_vendors::{GfxPower, GfxRequiredUserAction, GfxVendors}};
|
use crate::gfx_vendors::{GfxPower, GfxRequiredUserAction, GfxVendors};
|
||||||
|
|
||||||
use super::controller::CtrlGraphics;
|
use super::controller::CtrlGraphics;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user