mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-01-22 17:33:19 +01:00
Begin cleanup
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,3 +4,4 @@ cargo-config
|
||||
.idea
|
||||
vendor-*
|
||||
vendor_*
|
||||
.vscode-ctags
|
||||
|
||||
@@ -60,8 +60,8 @@ impl Config {
|
||||
if l == 0 {
|
||||
warn!("File is empty {}", CONFIG_PATH);
|
||||
} else {
|
||||
serde_json::from_str(&buf)
|
||||
.unwrap_or_else(|_| panic!("Could not deserialise {}", CONFIG_PATH))
|
||||
*self = serde_json::from_str(&buf)
|
||||
.unwrap_or_else(|_| panic!("Could not deserialise {}", CONFIG_PATH));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,6 @@ use std::io::{Read, Write};
|
||||
|
||||
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)]
|
||||
pub struct GfxConfig {
|
||||
#[serde(skip)]
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use ::zbus::Connection;
|
||||
use log::{error, info, warn};
|
||||
use logind_zbus::{
|
||||
types::{SessionClass, SessionInfo, SessionState, SessionType},
|
||||
ManagerProxy, SessionProxy,
|
||||
};
|
||||
use ::zbus::Connection;
|
||||
use std::{io::Write, ops::Add, path::Path, time::Instant};
|
||||
use std::{process::Command, thread::sleep, time::Duration};
|
||||
use std::{str::FromStr, sync::mpsc};
|
||||
@@ -11,7 +11,12 @@ use std::{sync::Arc, sync::Mutex};
|
||||
use sysfs_class::RuntimePM;
|
||||
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::gfx_vendors::{GfxPower, GfxRequiredUserAction, GfxVendors};
|
||||
@@ -137,12 +142,8 @@ impl CtrlGraphics {
|
||||
pub(super) fn get_runtime_status() -> Result<GfxPower, GfxError> {
|
||||
let path = Path::new(NVIDIA_RUNTIME_STATUS_PATH);
|
||||
if path.exists() {
|
||||
let buf = std::fs::read_to_string(path).map_err(|err| {
|
||||
GfxError::Read(
|
||||
path.to_string_lossy().to_string(),
|
||||
err,
|
||||
)
|
||||
})?;
|
||||
let buf = std::fs::read_to_string(path)
|
||||
.map_err(|err| GfxError::Read(path.to_string_lossy().to_string(), err))?;
|
||||
Ok(GfxPower::from_str(&buf)?)
|
||||
} else {
|
||||
Ok(GfxPower::Off)
|
||||
@@ -630,11 +631,13 @@ impl CtrlGraphics {
|
||||
///
|
||||
/// For manually calling (not on boot/startup) via dbus
|
||||
pub fn set_gfx_mode(&mut self, vendor: GfxVendors) -> Result<GfxRequiredUserAction, GfxError> {
|
||||
// if let Ok(gsync) = CtrlRogBios::get_gfx_mode() {
|
||||
// if gsync == 1 {
|
||||
// return Err(GfxError::GsyncModeActive.into());
|
||||
// }
|
||||
// }
|
||||
if has_asus_gsync_gfx_mode() {
|
||||
if let Ok(gsync) = get_asus_gsync_gfx_mode() {
|
||||
if gsync == 1 {
|
||||
return Err(GfxError::AsusGsyncModeActive);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let vfio_enable = if let Ok(config) = self.config.try_lock() {
|
||||
config.gfx_vfio_enable
|
||||
|
||||
@@ -8,7 +8,7 @@ pub enum GfxError {
|
||||
Bus(String, std::io::Error),
|
||||
DisplayManagerAction(String, ExitStatus),
|
||||
DisplayManagerTimeout(String),
|
||||
GsyncModeActive,
|
||||
AsusGsyncModeActive,
|
||||
VfioBuiltin,
|
||||
VfioDisabled,
|
||||
MissingModule(String),
|
||||
@@ -34,7 +34,7 @@ impl fmt::Display for GfxError {
|
||||
GfxError::DisplayManagerTimeout(state) => {
|
||||
write!(f, "Timed out waiting for display-manager {} state", state)
|
||||
}
|
||||
GfxError::GsyncModeActive => write!(
|
||||
GfxError::AsusGsyncModeActive => write!(
|
||||
f,
|
||||
"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 controller;
|
||||
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;
|
||||
|
||||
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 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
|
||||
# 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
|
||||
static MODPROBE_BASE: &[u8] = br#"# Automatically generated by supergfxd
|
||||
blacklist nouveau
|
||||
alias nouveau off
|
||||
options nvidia NVreg_DynamicPowerManagement=0x02
|
||||
@@ -33,7 +32,7 @@ static MODPROBE_DRM_MODESET: &[u8] = br#"
|
||||
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 nvidia
|
||||
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_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"
|
||||
Identifier "nvidia"
|
||||
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 ::zbus::dbus_interface;
|
||||
|
||||
use crate::{gfx_vendors::{GfxPower, GfxRequiredUserAction, GfxVendors}};
|
||||
use crate::gfx_vendors::{GfxPower, GfxRequiredUserAction, GfxVendors};
|
||||
|
||||
use super::controller::CtrlGraphics;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user