Add setter validation for pp_dpm_*
This commit is contained in:
parent
c9f2f2849e
commit
c1ebbd1ce8
1 changed files with 29 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
||||||
use powerbox::primitives::{GetSet, ClockFrequency, Value, ValueMap, Selectable, SpacedList};
|
use powerbox::primitives::{GetSet, ClockFrequency, Value, ValueMap, Selectable, SpacedList};
|
||||||
use powerbox::{Power, PowerOp};
|
use powerbox::{Power, PowerOp, RatifiedPower};
|
||||||
use sysfuss::SysEntityAttributesExt;
|
use sysfuss::SysEntityAttributesExt;
|
||||||
|
|
||||||
use crate::gpu::{GpuPower, GpuPowerOp};
|
use crate::gpu::{GpuPower, GpuPowerOp};
|
||||||
|
@ -172,6 +172,34 @@ macro_rules! get_set_gen_impl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl RatifiedPower<$setter> for AmdGpu {
|
||||||
|
fn is_possible(&self, op: &$setter) -> bool {
|
||||||
|
if let Ok(val_map) = self.act($getter) {
|
||||||
|
let allowed: std::collections::HashSet<_> = val_map.0.keys().collect();
|
||||||
|
op.0.iter().all(|key| allowed.contains(key))
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn clamp(&self, op: &mut $setter) -> bool {
|
||||||
|
if let Ok(val_map) = self.act($getter) {
|
||||||
|
let allowed: std::collections::HashSet<_> = val_map.0.keys().collect();
|
||||||
|
let mut i = 0;
|
||||||
|
while i < op.0.len() {
|
||||||
|
if allowed.contains(&op.0[i]) {
|
||||||
|
i += 1;
|
||||||
|
} else {
|
||||||
|
op.0.remove(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl GpuPower<$setter, ()> for AmdGpu {}
|
impl GpuPower<$setter, ()> for AmdGpu {}
|
||||||
|
|
||||||
impl core::convert::Into<$alias> for $setter {
|
impl core::convert::Into<$alias> for $setter {
|
||||||
|
|
Loading…
Reference in a new issue