rog-platform: add CPU and GPU tunings

rog-platform: add tunables to supported dat

Anime: fixes to how some power options work
This commit is contained in:
Luke D. Jones
2023-11-16 21:31:15 +13:00
parent b9c2d929b3
commit fa043adc99
10 changed files with 201 additions and 72 deletions

View File

@@ -1,8 +1,8 @@
#[macro_export]
macro_rules! has_attr {
($(#[$doc_comment:meta])? $attr_name:literal $item:ident) => {
($(#[$attr:meta])* $attr_name:literal $item:ident) => {
concat_idents::concat_idents!(fn_name = has_, $attr_name {
$(#[$doc_comment])*
$(#[$attr])*
pub fn fn_name(&self) -> bool {
match to_device(&self.$item) {
Ok(p) => $crate::has_attr(&p, $attr_name),
@@ -15,9 +15,9 @@ macro_rules! has_attr {
#[macro_export]
macro_rules! watch_attr {
($(#[$doc_comment:meta])? $attr_name:literal $item:ident) => {
($(#[$attr:meta])* $attr_name:literal $item:ident) => {
concat_idents::concat_idents!(fn_name = monitor_, $attr_name {
$(#[$doc_comment])*
$(#[$attr])*
pub fn fn_name(&self) -> Result<inotify::Inotify> {
let mut path = self.$item.clone();
path.push($attr_name);
@@ -41,9 +41,9 @@ macro_rules! watch_attr {
#[macro_export]
macro_rules! get_attr_bool {
($(#[$doc_comment:meta])? $attr_name:literal $item:ident) => {
($(#[$attr:meta])* $attr_name:literal $item:ident) => {
concat_idents::concat_idents!(fn_name = get_, $attr_name {
$(#[$doc_comment])*
$(#[$attr])*
pub fn fn_name(&self) -> Result<bool> {
$crate::read_attr_bool(&to_device(&self.$item)?, $attr_name)
}
@@ -53,9 +53,9 @@ macro_rules! get_attr_bool {
#[macro_export]
macro_rules! set_attr_bool {
($(#[$doc_comment:meta])? $attr_name:literal $item:ident) => {
($(#[$attr:meta])* $attr_name:literal $item:ident) => {
concat_idents::concat_idents!(fn_name = set_, $attr_name {
$(#[$doc_comment])*
$(#[$attr])*
pub fn fn_name(&self, value: bool) -> Result<()> {
$crate::write_attr_bool(&mut to_device(&self.$item)?, $attr_name, value)
}
@@ -65,7 +65,7 @@ macro_rules! set_attr_bool {
#[macro_export]
macro_rules! attr_bool {
($attr_name:literal, $item:ident) => {
($(#[$attr:meta])* $attr_name:literal, $item:ident) => {
$crate::has_attr!($attr_name $item);
$crate::get_attr_bool!( $attr_name $item);
$crate::set_attr_bool!($attr_name $item);
@@ -75,9 +75,9 @@ macro_rules! attr_bool {
#[macro_export]
macro_rules! get_attr_u8 {
($(#[$doc_comment:meta])? $attr_name:literal $item:ident) => {
($(#[$attr:meta])* $attr_name:literal $item:ident) => {
concat_idents::concat_idents!(fn_name = get_, $attr_name {
$(#[$doc_comment])*
$(#[$attr])*
pub fn fn_name(&self) -> Result<u8> {
$crate::read_attr_u8(&to_device(&self.$item)?, $attr_name)
}
@@ -88,9 +88,9 @@ macro_rules! get_attr_u8 {
/// Most attributes expect `u8` as a char, so `1` should be written as `b'1'`.
#[macro_export]
macro_rules! set_attr_u8 {
($(#[$doc_comment:meta])? $attr_name:literal $item:ident) => {
($(#[$attr:meta])* $attr_name:literal $item:ident) => {
concat_idents::concat_idents!(fn_name = set_, $attr_name {
$(#[$doc_comment])*
$(#[$attr])*
pub fn fn_name(&self, value: u8) -> Result<()> {
$crate::write_attr_u8(&mut to_device(&self.$item)?, $attr_name, value)
}
@@ -100,19 +100,19 @@ macro_rules! set_attr_u8 {
#[macro_export]
macro_rules! attr_u8 {
($attr_name:literal, $item:ident) => {
$crate::has_attr!($attr_name $item);
$crate::get_attr_u8!($attr_name $item);
$crate::set_attr_u8!($attr_name $item);
$crate::watch_attr!($attr_name $item);
($(#[$attr:meta])* $attr_name:literal, $item:ident) => {
$crate::has_attr!($(#[$attr])* $attr_name $item);
$crate::get_attr_u8!($(#[$attr])* $attr_name $item);
$crate::set_attr_u8!($(#[$attr])* $attr_name $item);
$crate::watch_attr!($(#[$attr])* $attr_name $item);
};
}
#[macro_export]
macro_rules! get_attr_u8_array {
($(#[$doc_comment:meta])? $attr_name:literal $item:ident) => {
($(#[$attr:meta])* $attr_name:literal $item:ident) => {
concat_idents::concat_idents!(fn_name = get_, $attr_name {
$(#[$doc_comment])*
$(#[$attr])*
pub fn fn_name(&self) -> Result<Vec<u8>> {
$crate::read_attr_u8_array(&to_device(&self.$item)?, $attr_name)
}
@@ -122,9 +122,9 @@ macro_rules! get_attr_u8_array {
#[macro_export]
macro_rules! set_attr_u8_array {
($(#[$doc_comment:meta])? $attr_name:literal $item:ident) => {
($(#[$attr:meta])* $attr_name:literal $item:ident) => {
concat_idents::concat_idents!(fn_name = set_, $attr_name {
$(#[$doc_comment])*
$(#[$attr])*
pub fn fn_name(&self, values: &[u8]) -> Result<()> {
$crate::write_attr_u8_array(&mut to_device(&self.$item)?, $attr_name, values)
}
@@ -134,7 +134,7 @@ macro_rules! set_attr_u8_array {
#[macro_export]
macro_rules! attr_u8_array {
($attr_name:literal, $item:ident) => {
($(#[$attr:meta])* $attr_name:literal, $item:ident) => {
$crate::has_attr!($attr_name $item);
$crate::get_attr_u8_array!($attr_name $item);
$crate::set_attr_u8_array!($attr_name $item);
@@ -144,9 +144,9 @@ macro_rules! attr_u8_array {
#[macro_export]
macro_rules! get_attr_string {
($(#[$doc_comment:meta])? $attr_name:literal $item:ident) => {
($(#[$attr:meta])* $attr_name:literal $item:ident) => {
concat_idents::concat_idents!(fn_name = get_, $attr_name {
$(#[$doc_comment])*
$(#[$attr])*
pub fn fn_name(&self) -> Result<String> {
$crate::read_attr_string(&to_device(&self.$item)?, $attr_name)
}
@@ -156,9 +156,9 @@ macro_rules! get_attr_string {
#[macro_export]
macro_rules! set_attr_string {
($(#[$doc_comment:meta])? $attr_name:literal $item:ident) => {
($(#[$attr:meta])* $attr_name:literal $item:ident) => {
concat_idents::concat_idents!(fn_name = set_, $attr_name {
$(#[$doc_comment])*
$(#[$attr])*
pub fn fn_name(&self, values: &str) -> Result<()> {
$crate::write_attr_string(&mut to_device(&self.$item)?, $attr_name, values)
}
@@ -168,7 +168,7 @@ macro_rules! set_attr_string {
#[macro_export]
macro_rules! attr_string {
($attr_name:literal, $item:ident) => {
($(#[$attr:meta])* $attr_name:literal, $item:ident) => {
$crate::has_attr!($attr_name $item);
$crate::get_attr_string!($attr_name $item);
$crate::set_attr_string!($attr_name $item);

View File

@@ -8,6 +8,7 @@ use typeshare::typeshare;
use zbus::zvariant::Type;
use crate::error::{PlatformError, Result};
use crate::supported::PlatformSupportedFunctions;
use crate::{attr_bool, attr_string, attr_u8, to_device};
/// The "platform" device provides access to things like:
@@ -15,6 +16,7 @@ use crate::{attr_bool, attr_string, attr_u8, to_device};
/// - `egpu_enable`
/// - `panel_od`
/// - `gpu_mux`
/// - various CPU an GPU tunings
/// - `keyboard_mode`, set keyboard RGB mode and speed
/// - `keyboard_state`, set keyboard power states
#[derive(Debug, PartialEq, Eq, PartialOrd, Clone)]
@@ -34,12 +36,69 @@ impl AsusPlatform {
attr_bool!("gpu_mux_mode", path);
// This is technically the same as `platform_profile` since both are tied
// in-kernel
attr_u8!("throttle_thermal_policy", path);
attr_u8!(
/// This is technically the same as `platform_profile` since both are
/// tied in-kernel
"throttle_thermal_policy",
path
);
// The acpi platform_profile support
attr_string!("platform_profile", pp_path);
attr_string!(
/// The acpi platform_profile support
"platform_profile",
pp_path
);
attr_u8!(
/// Package Power Target total of CPU: PL1 on Intel, SPL on AMD.
/// Shown on Intel+Nvidia or AMD+Nvidia based systems:
/// * min=5, max=250
"ppt_pl1_spl",
path
);
attr_u8!(
/// Slow Package Power Tracking Limit of CPU: PL2 on Intel, SPPT,
/// on AMD. Shown on Intel+Nvidia or AMD+Nvidia based systems:
/// * min=5, max=250
"ppt_pl2_sppt",
path
);
attr_u8!(
/// Fast Package Power Tracking Limit of CPU. AMD+Nvidia only:
/// * min=5, max=250
"ppt_fppt",
path
);
attr_u8!(
/// APU SPPT limit. Shown on full AMD systems only:
/// * min=5, max=130
"ppt_apu_sppt",
path
);
attr_u8!(
/// Platform SPPT limit. Shown on full AMD systems only:
/// * min=5, max=130
"ppt_platform_sppt",
path
);
attr_u8!(
/// Dynamic boost limit of the Nvidia dGPU:
/// * min=5, max=25
"nv_dynamic_boost",
path
);
attr_u8!(
/// Target temperature limit of the Nvidia dGPU:
/// * min=75, max=87
"nv_temp_target",
path
);
pub fn new() -> Result<Self> {
let mut enumerator = udev::Enumerator::new().map_err(|err| {
@@ -73,6 +132,37 @@ impl AsusPlatform {
}
}
impl Default for AsusPlatform {
fn default() -> Self {
unsafe {
Self {
path: PathBuf::from_str("/this_shouldNeVErr_exisid").unwrap_unchecked(),
pp_path: PathBuf::from_str("/this_shouldNeVErr_exisid").unwrap_unchecked(),
}
}
}
}
impl From<AsusPlatform> for PlatformSupportedFunctions {
fn from(a: AsusPlatform) -> Self {
PlatformSupportedFunctions {
post_sound: false,
gpu_mux: a.has_gpu_mux_mode(),
panel_overdrive: a.has_panel_od(),
dgpu_disable: a.has_dgpu_disable(),
egpu_enable: a.has_egpu_enable(),
mini_led_mode: a.has_mini_led_mode(),
ppt_pl1_spl: a.has_ppt_pl1_spl(),
ppt_pl2_sppt: a.has_ppt_pl2_sppt(),
ppt_fppt: a.has_ppt_fppt(),
ppt_apu_sppt: a.has_ppt_apu_sppt(),
ppt_platform_sppt: a.has_ppt_platform_sppt(),
nv_dynamic_boost: a.has_nv_dynamic_boost(),
nv_temp_target: a.has_nv_temp_target(),
}
}
}
#[typeshare]
#[derive(Serialize, Deserialize, Default, Type, Debug, PartialEq, Eq, Clone, Copy)]
pub enum GpuMode {

View File

@@ -15,7 +15,7 @@ pub struct SupportedFunctions {
pub charge_ctrl: ChargeSupportedFunctions,
pub platform_profile: PlatformProfileFunctions,
pub keyboard_led: LedSupportedFunctions,
pub rog_bios_ctrl: RogBiosSupportedFunctions,
pub rog_bios_ctrl: PlatformSupportedFunctions,
}
#[typeshare]
@@ -68,13 +68,21 @@ pub struct LedSupportedFunctions {
#[typeshare]
#[derive(Serialize, Deserialize, Type, Debug, Default, Clone)]
pub struct RogBiosSupportedFunctions {
pub struct PlatformSupportedFunctions {
pub post_sound: bool,
pub gpu_mux: bool,
pub panel_overdrive: bool,
pub dgpu_disable: bool,
pub egpu_enable: bool,
pub mini_led_mode: bool,
pub ppt_pl1_spl: bool,
pub ppt_pl2_sppt: bool,
pub ppt_fppt: bool,
pub ppt_apu_sppt: bool,
pub ppt_platform_sppt: bool,
pub nv_dynamic_boost: bool,
pub nv_temp_target: bool,
}
impl fmt::Display for SupportedFunctions {
@@ -120,7 +128,8 @@ impl fmt::Display for LedSupportedFunctions {
writeln!(f, "\tAdvanced modes: {:?}", self.advanced_type)
}
}
impl fmt::Display for RogBiosSupportedFunctions {
impl fmt::Display for PlatformSupportedFunctions {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "ROG BIOS:")?;
writeln!(f, "\tPOST sound switch: {}", self.post_sound)?;
@@ -129,6 +138,13 @@ impl fmt::Display for RogBiosSupportedFunctions {
writeln!(f, "\tdGPU disable switch: {}", self.dgpu_disable)?;
writeln!(f, "\teGPU enable switch: {}", self.egpu_enable)?;
writeln!(f, "\tGPU MUX control: {}", self.gpu_mux)?;
writeln!(f, "\tppt_pl1_spl: {}", self.ppt_pl1_spl)?;
writeln!(f, "\tppt_pl2_sppt: {}", self.ppt_pl2_sppt)?;
writeln!(f, "\tppt_fppt {}", self.ppt_fppt)?;
writeln!(f, "\tppt_apu_sppt: {}", self.ppt_apu_sppt)?;
writeln!(f, "\tppt_platform_sppt: {}", self.ppt_platform_sppt)?;
writeln!(f, "\tnv_dynamic_boost: {}", self.nv_dynamic_boost)?;
writeln!(f, "\tnv_temp_target: {}", self.nv_temp_target)?;
Ok(())
}
}