Struct OPP

Source
pub struct OPP(/* private fields */);
Expand description

A reference-counted Operating performance point (OPP).

Rust abstraction for the C struct dev_pm_opp.

§Invariants

The pointer stored in Self is non-null and valid for the lifetime of the OPP.

Instances of this type are reference-counted. The reference count is incremented by the dev_pm_opp_get function and decremented by dev_pm_opp_put. The Rust type ARef<OPP> represents a pointer that owns a reference count on the OPP.

A reference to the OPP, &OPP, isn’t refcounted by the Rust code.

§Examples

The following example demonstrates how to get OPP corresponding to a frequency value and configure the device with it.

use kernel::clk::Hertz;
use kernel::error::Result;
use kernel::opp::{SearchType, Table};

fn configure_opp(table: &Table, freq: Hertz) -> Result {
    let opp = table.opp_from_freq(freq, Some(true), None, SearchType::Exact)?;

    if opp.freq(None) != freq {
        return Err(EINVAL);
    }

    table.set_opp(&opp)
}

Implementations§

Source§

impl OPP

Source

pub unsafe fn from_raw_opp_owned(ptr: *mut dev_pm_opp) -> Result<ARef<Self>>

Creates an owned reference to a OPP from a valid pointer.

The refcount is incremented by the C code and will be decremented by dec_ref when the ARef object is dropped.

§Safety

The caller must ensure that ptr is valid and the refcount of the OPP is incremented. The caller must also ensure that it doesn’t explicitly drop the refcount of the OPP, as the returned ARef object takes over the refcount increment on the underlying object and the same will be dropped along with it.

Source

pub unsafe fn from_raw_opp<'a>(ptr: *mut dev_pm_opp) -> Result<&'a Self>

Creates a reference to a OPP from a valid pointer.

The refcount is not updated by the Rust API unless the returned reference is converted to an ARef object.

§Safety

The caller must ensure that ptr is valid and remains valid for the duration of 'a.

Source

pub fn freq(&self, index: Option<u32>) -> Hertz

Returns the frequency of an OPP.

Source

pub fn voltage(&self) -> MicroVolt

Returns the voltage of an OPP.

Source

pub fn level(&self) -> u32

Returns the level of an OPP.

Source

pub fn power(&self) -> MicroWatt

Returns the power of an OPP.

Source

pub fn required_pstate(&self, index: u32) -> u32

Returns the required pstate of an OPP.

Source

pub fn is_turbo(&self) -> bool

Returns true if the OPP is turbo.

Trait Implementations§

Source§

impl AlwaysRefCounted for OPP

SAFETY: The type invariants guarantee that OPP is always refcounted.

Source§

fn inc_ref(&self)

Increments the reference count on the object.
Source§

unsafe fn dec_ref(obj: NonNull<Self>)

Decrements the reference count on the object. Read more
Source§

impl Send for OPP

SAFETY: It is okay to send the ownership of OPP across thread boundaries.

Source§

impl Sync for OPP

SAFETY: It is okay to access OPP through shared references from other threads because we’re either accessing properties that don’t change or that are properly synchronised by C code.

Auto Trait Implementations§

§

impl !Freeze for OPP

§

impl !RefUnwindSafe for OPP

§

impl !Unpin for OPP

§

impl UnwindSafe for OPP

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, E> Init<T, E> for T

Source§

unsafe fn __init(self, slot: *mut T) -> Result<(), E>

Initializes slot. Read more
Source§

fn chain<F>(self, f: F) -> ChainInit<Self, F, T, E>
where F: FnOnce(&mut T) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, E> PinInit<T, E> for T

Source§

unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E>

Initializes slot. Read more
Source§

fn pin_chain<F>(self, f: F) -> ChainPinInit<Self, F, T, E>
where F: FnOnce(Pin<&mut T>) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.