Major update to supergfx and others

This commit is contained in:
Luke D. Jones
2021-08-26 11:43:47 +12:00
parent 60b7f3be69
commit 498e604531
33 changed files with 535 additions and 278 deletions

View File

@@ -3,7 +3,6 @@ use serde_derive::{Deserialize, Serialize};
use std::fs::{File, OpenOptions};
use std::io::{Read, Write};
use crate::config_old::*;
use crate::VERSION;
pub static CONFIG_PATH: &str = "/etc/asusd/asusd.conf";
@@ -36,9 +35,6 @@ impl Config {
config = Self::new();
} else if let Ok(data) = serde_json::from_str(&buf) {
config = data;
} else if let Ok(data) = serde_json::from_str::<ConfigV352>(&buf) {
config = data.into_current();
info!("Updated config version to: {}", VERSION);
} else {
warn!("Could not deserialise {}", CONFIG_PATH);
panic!("Please remove {} then restart asusd", CONFIG_PATH);

View File

@@ -1,53 +0,0 @@
use serde_derive::{Deserialize, Serialize};
use supergfxctl::gfx_vendors::GfxVendors;
use std::collections::BTreeMap;
use crate::config::Config;
#[derive(Deserialize, Serialize)]
pub struct ConfigV352 {
pub gfx_mode: GfxVendors,
pub gfx_last_mode: GfxVendors,
pub gfx_managed: bool,
pub gfx_vfio_enable: bool,
pub gfx_save_compute_vfio: bool,
pub active_profile: String,
pub toggle_profiles: Vec<String>,
#[serde(skip)]
pub curr_fan_mode: u8,
pub bat_charge_limit: u8,
pub power_profiles: BTreeMap<String, ProfileV317>,
}
impl ConfigV352 {
pub(crate) fn into_current(self) -> Config {
Config {
bat_charge_limit: self.bat_charge_limit,
}
}
}
#[derive(Deserialize, Serialize)]
pub struct ConfigV372 {
pub gfx_mode: GfxVendors,
/// Only for informational purposes.
#[serde(skip)]
pub gfx_tmp_mode: Option<GfxVendors>,
pub gfx_managed: bool,
pub gfx_vfio_enable: bool,
pub active_profile: String,
pub toggle_profiles: Vec<String>,
#[serde(skip)]
pub curr_fan_mode: u8,
pub bat_charge_limit: u8,
pub power_profiles: BTreeMap<String, ProfileV317>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ProfileV317 {
pub min_percentage: u8,
pub max_percentage: u8,
pub turbo: bool,
pub fan_preset: u8,
pub fan_curve: Option<()>,
}

View File

@@ -40,19 +40,23 @@ impl GetSupported for CtrlPlatformProfile {
fn get_supported() -> Self::A {
if !Profile::is_platform_profile_supported() {
warn!(r#"
warn!(
r#"
platform_profile kernel interface not found, your laptop does not support this, or the iterface is missing.
To enable profile support you require a kernel with the following patch applied:
https://lkml.org/lkml/2021/8/18/1022
"#);
"#
);
}
if !FanCurves::is_fan_curves_supported() {
info!(r#"
info!(
r#"
fan curves kernel interface not found, your laptop does not support this, or the iterface is missing.
To enable fan-curve support you require a kernel with the following patch applied:
https://lkml.org/lkml/2021/8/20/232
Please note that as of 24/08/2021 this is not final.
"#);
"#
);
}
PlatformProfileFunctions {
platform_profile: Profile::is_platform_profile_supported(),

View File

@@ -1,5 +1,6 @@
use daemon::ctrl_anime::config::AnimeConfig;
use daemon::ctrl_anime::zbus::CtrlAnimeZbus;
use daemon::ctrl_anime::*;
use daemon::ctrl_aura::config::AuraConfig;
use daemon::ctrl_aura::controller::{
CtrlKbdLed, CtrlKbdLedReloader, CtrlKbdLedTask, CtrlKbdLedZbus,
@@ -10,15 +11,11 @@ use daemon::ctrl_profiles::controller::CtrlPlatformTask;
use daemon::{
config::Config, ctrl_supported::SupportedFunctions, laptops::print_board_info, GetSupported,
};
use daemon::{ctrl_anime::*};
use daemon::{
ctrl_profiles::{controller::CtrlPlatformProfile, zbus::ProfileZbus},
laptops::LaptopLedData,
};
use supergfxctl::config::GfxConfig;
use supergfxctl::controller::CtrlGraphics;
use supergfxctl::gfx_vendors::GfxVendors;
use ::zbus::{fdo, Connection, ObjectServer};
use daemon::{CtrlTask, Reloadable, ZbusAdd};
use log::LevelFilter;
@@ -34,7 +31,6 @@ use daemon::ctrl_rog_bios::CtrlRogBios;
use zvariant::ObjectPath;
static PROFILE_CONFIG_PATH: &str = "/etc/asusd/profile.conf";
static GFX_CONFIG_PATH: &str = "/etc/asusd/supergfx.conf";
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut logger = env_logger::Builder::new();
@@ -86,10 +82,6 @@ fn start_daemon() -> Result<(), Box<dyn Error>> {
let config = Config::load();
let config = Arc::new(Mutex::new(config));
let gfx_config = GfxConfig::load(GFX_CONFIG_PATH.into());
let enable_gfx_switching = gfx_config.gfx_managed;
let gfx_config = Arc::new(Mutex::new(gfx_config));
supported.add_to_server(&mut object_server);
match CtrlRogBios::new(config.clone()) {
@@ -105,7 +97,7 @@ fn start_daemon() -> Result<(), Box<dyn Error>> {
}
}
match CtrlCharge::new(config.clone()) {
match CtrlCharge::new(config) {
Ok(mut ctrl) => {
// Do a reload of any settings
ctrl.reload()
@@ -173,48 +165,6 @@ fn start_daemon() -> Result<(), Box<dyn Error>> {
}
}
// Graphics switching requires some checks on boot specifically for g-sync capable laptops
if enable_gfx_switching {
match CtrlGraphics::new(gfx_config.clone()) {
Ok(mut ctrl) => {
// Need to check if a laptop has the dedicated gfx switch
if CtrlRogBios::has_dedicated_gfx_toggle() {
if let Ok(ded) = CtrlRogBios::get_gfx_mode() {
if let Ok(config) = gfx_config.lock() {
if ded == 1 {
warn!("Dedicated GFX toggle is on but driver mode is not nvidia \nSetting to nvidia driver mode");
let devices = ctrl.devices();
let bus = ctrl.bus();
CtrlGraphics::do_mode_setup_tasks(
GfxVendors::Nvidia,
false,
&devices,
&bus,
)?;
} else if ded == 0 {
info!("Dedicated GFX toggle is off");
let devices = ctrl.devices();
let bus = ctrl.bus();
CtrlGraphics::do_mode_setup_tasks(
config.gfx_mode,
false,
&devices,
&bus,
)?;
}
}
}
}
ctrl.reload()
.unwrap_or_else(|err| error!("Gfx controller: {}", err));
ctrl.add_to_server(&mut object_server);
}
Err(err) => {
error!("Gfx control: {}", err);
}
}
}
// TODO: implement messaging between threads to check fails
// Run tasks

View File

@@ -1,6 +1,4 @@
use rog_profiles::error::ProfileError;
use rog_types::error::GraphicsError;
use supergfxctl::error::GfxError;
use std::convert::From;
use std::fmt;
@@ -19,7 +17,6 @@ pub enum RogError {
MissingFunction(String),
MissingLedBrightNode(String, std::io::Error),
ReloadFail(String),
GfxSwitching(GfxError),
Profiles(ProfileError),
Initramfs(String),
Modprobe(String),
@@ -44,7 +41,6 @@ impl fmt::Display for RogError {
RogError::MissingFunction(deets) => write!(f, "Missing functionality: {}", deets),
RogError::MissingLedBrightNode(path, error) => write!(f, "Led node at {} is missing, please check you have the required patch or dkms module installed: {}", path, error),
RogError::ReloadFail(deets) => write!(f, "Task error: {}", deets),
RogError::GfxSwitching(deets) => write!(f, "Graphics switching error: {}", deets),
RogError::Profiles(deets) => write!(f, "Profile error: {}", deets),
RogError::Initramfs(detail) => write!(f, "Initiramfs error: {}", detail),
RogError::Modprobe(detail) => write!(f, "Modprobe error: {}", detail),
@@ -56,15 +52,6 @@ impl fmt::Display for RogError {
impl std::error::Error for RogError {}
impl From<GraphicsError> for RogError {
fn from(err: GraphicsError) -> Self {
match err {
GraphicsError::ParseVendor => RogError::GfxSwitching(GfxError::ParseVendor),
GraphicsError::ParsePower => RogError::GfxSwitching(GfxError::ParsePower),
}
}
}
impl From<ProfileError> for RogError {
fn from(err: ProfileError) -> Self {
RogError::Profiles(err)

View File

@@ -1,7 +1,6 @@
#![deny(unused_must_use)]
/// Configuration loading, saving
pub mod config;
pub(crate) mod config_old;
/// Control of AniMe matrix display
pub mod ctrl_anime;
/// Keyboard LED brightness control, RGB, and LED display modes