Namespaces

Enumerations

enum class Error : uint8_t
Name Value Comments
INVALID_ARGS 0

The power configuration appears to be invalid. A non-exhaustive list of
possible reasons is it contained no elements, the element definition
appears malformed, or other reasons.

IO 1

A general I/O error happened which we're not sure about. This should be
a rare occurrence and typically more specific errors should be returned.

DEPENDENCY_NOT_FOUND 2

The configuration has a dependency, but we couldn't get access to the
tokens for it. Maybe a parent didn't offer something expected or SAG
didn't make something available.

TOKEN_SERVICE_CAPABILITY_NOT_FOUND 3

No token services capability available, maybe it wasn't routed?

READ_INSTANCES 4

An unexpected error occurred listing service instances.

NO_TOKEN_SERVICE_INSTANCES 5

We were able to access the token service capability, but no instances
were available. Did the parents offer any?

TOKEN_REQUEST 6

Requesting a token from the provider protocol failed. Maybe the token
provider is not implemented correctly?

ACTIVITY_GOVERNOR_UNAVAILABLE 7

Couldn't access the capability for System Activity Governor tokens.

ACTIVITY_GOVERNOR_REQUEST 8

Request to System Activity Governor returned an error.

TOPOLOGY_UNAVAILABLE 9

fuchsia.power.broker/Topology could not be connected to.

CONFIGURATION_UNAVAILABLE 10

The power configuration could not be retrieved.

CPU_ELEMENT_MANAGER_UNAVAILABLE 11

Could not access the CpuElementManager capability.

CPU_ELEMENT_MANAGER_REQUEST 12

There was an error making a request to the CpuElementManager protocol.

INTERNAL 13

There was an error making a request to the CpuElementManager protocol.

NOT_AUTHORIZED 14

There was an error making a request to the CpuElementManager protocol.

Defined at line 32 of file ../../sdk/lib/driver/power/cpp/power-support.h

enum class SagElement : uint32_t
Name Value
kExecutionState 1
kApplicationActivity 4

NOTE: This is _not_ a complete list of SAG elements. This enum only lists the elements supported

by the power support library.

Defined at line 68 of file ../../sdk/lib/driver/power/cpp/types.h

enum class CpuElement : uint32_t
Name Value
kCpu 1

Defined at line 73 of file ../../sdk/lib/driver/power/cpp/types.h

Records

Functions

  • fit::result<zx_status_t, uint8_t> default_level_changer (uint8_t level)

    Defined at line 80 of file ../../sdk/lib/driver/power/cpp/power-support.h

  • zx::error<zx_status_t> ErrorToZxError (Error e)

    Convenience methods that provide an approximate mapping to Zircon error values.

    Defined at line 245 of file ../../sdk/lib/driver/power/cpp/power-support.cc

  • zx::error<zx_status_t> LeaseErrorToZxError (fuchsia_power_broker::LeaseError e)

    Defined at line 309 of file ../../sdk/lib/driver/power/cpp/power-support.cc

  • zx::error<zx_status_t> AddElementErrorToZxError (fuchsia_power_broker::AddElementError e)

    Defined at line 322 of file ../../sdk/lib/driver/power/cpp/power-support.cc

  • const char * ErrorToString (Error e)

    Convenience methods for printing errors.

    Defined at line 273 of file ../../sdk/lib/driver/power/cpp/power-support.cc

  • const char * LeaseErrorToString (fuchsia_power_broker::LeaseError e)

    Defined at line 333 of file ../../sdk/lib/driver/power/cpp/power-support.cc

  • const char * AddElementErrorToString (fuchsia_power_broker::AddElementError e)

    Defined at line 346 of file ../../sdk/lib/driver/power/cpp/power-support.cc

  • fit::result<Error, std::vector<ElementDesc>> ApplyPowerConfiguration (const fdf::Namespace & ns, cpp20::span<PowerElementConfiguration> power_configs, bool use_element_runner)

    Uses the provided namespace to add the power elements described in

    |power_configs| to the power topology and returns corresponding

    `ElementDesc` instances.

    This function:

    * Retrieves the tokens of any dependencies via

    `fuchsia.hardware.power/PowerTokenProvider` instances

    * Adds the power element via `fuchsia.power.broker/Topology`

    In effect, this function converts the provided |power_configs| into their

    corresponding `ElementDesc` objects and returns them.

    Defined at line 602 of file ../../sdk/lib/driver/power/cpp/power-support.cc

  • fit::result<Error, ElementDependencyMap> LevelDependencyFromConfig (const PowerElementConfiguration & element_config)

    Given a `PowerElementConfiguration` from driver framework, convert this

    into a set of Power Broker's `LevelDependency` objects. The map is keyed

    by the name of the parent/dependency.

    If the `PowerElementConfiguration` expresses no dependencies, we return an

    empty map.

    NOTE: The `requires_token` of each of the `LevelDependency` objects is

    **not** populated and must be filled in before providing this map to

    `AddElement`.

    Error returns:

    - Error::INVALID_ARGS if `element_config` is missing fields, for example

    if a level dependency doesn't have a parent level.

    Defined at line 357 of file ../../sdk/lib/driver/power/cpp/power-support.cc

  • std::vector<fuchsia_power_broker::PowerLevel> PowerLevelsFromConfig (PowerElementConfiguration element_config)

    Given a `PowerElementConfiguration` from driver framework, convert this

    into a set of Power Broker's `PowerLevel` objects.

    If the `PowerElementConfiguration` expresses no levels, we return an

    empty vector.

    Defined at line 385 of file ../../sdk/lib/driver/power/cpp/power-support.cc

  • fit::result<Error, TokenMap> GetDependencyTokens (const fdf::Namespace & ns, const PowerElementConfiguration & element_config)

    For the Power Element represented by `element_config`, get the tokens for

    the element's dependencies (ie. "parents") from

    `fuchsia.hardware.power/PowerTokenProvider` instances in `ns`.

    If the power element represented by `element_config` has no dependencies,

    this function returns an empty set. If any dependency's token can not be

    be retrieved we return an error.

    Error returns:

    - `Error::INVALID_ARGS` if the element_config appears invalid

    - `Error::IO` if there is a communication failure when talking to a

    service or a protocol required to get a token.

    - `Error::DEPENDENCY_NOT_FOUND` if a token for a required dependency is

    not available.

    Defined at line 396 of file ../../sdk/lib/driver/power/cpp/power-support.cc

  • fit::result<Error, TokenMap> GetDependencyTokens (const PowerElementConfiguration & element_config, fidl::ClientEnd<fuchsia_io::Directory> svcs_dir)

    For the Power Element represented by `element_config`, get the tokens for

    the

    element's dependencies (ie. "parents") from

    `fuchsia.hardware.power/PowerTokenProvider` instances in `svcs_dir`.

    `svcs_dir` should contain an entry for

    `fuchsia.hardware.power/PowerTokenService`.

    Returns a set of tokens from services instances found in `svcs_dir`. If

    the power element represented by `element_config` has no dependencies, this

    function returns an empty set. If any dependency's token can not be

    be retrieved we return an error.

    Error returns:

    - `Error::INVALID_ARGS` if the element_config appears invalid

    - `Error::IO` if there is a communication failure when talking to a

    service or a protocol required to get a token.

    - `Error::DEPENDENCY_NOT_FOUND` if a token for a required dependency is

    not available.

    Defined at line 409 of file ../../sdk/lib/driver/power/cpp/power-support.cc

  • fit::result<Error> AddElement (const fidl::ClientEnd<fuchsia_power_broker::Topology> & power_broker, const PowerElementConfiguration & config, TokenMap tokens, const zx::unowned_event & assertive_token, std::optional<fidl::ServerEnd<fuchsia_power_broker::Lessor>> lessor, std::optional<fidl::ServerEnd<fuchsia_power_broker::ElementControl>> element_control, std::optional<fidl::UnownedClientEnd<fuchsia_power_broker::ElementControl>> element_control_client, std::optional<fidl::ClientEnd<fuchsia_power_broker::ElementRunner>> element_runner)

    Call `AddElement` on the `power_broker` channel passed in.

    This function uses the `config` and `tokens` arguments to properly construct

    the call to `fuchsia.power.broker/Topology.AddElement`. Optionally callers

    can pass in tokens to be registered for granting assertive

    dependency access on the created element.

    Error

    - Error::DEPENDENCY_NOT_FOUND if there is a dependency specified by

    `config` which is to found in `tokens`.

    - Error::INVALID_ARGS if `config` appears to be invalid, we fail to

    duplicate a token and therefore assume it must have been invalid, or

    the call to power broker fails for any reason *other* than a closed

    channel.

    Defined at line 487 of file ../../sdk/lib/driver/power/cpp/power-support.cc

  • fit::result<Error> AddElement (fidl::ClientEnd<fuchsia_power_broker::Topology> & power_broker, ElementDesc & description)

    Call `AddElement` on the `power_broker` channel passed in.

    This function uses `ElementDescription` passed in to make the proper call

    to `fuchsia.power.broker/Topology.AddElement`. See `ElementDescription` for

    more information about what fields are inputs to `AddElement`.

    Error

    - Error::DEPENDENCY_NOT_FOUND if there is a dependency specified by

    `config` which is to found in `tokens`.

    - Error::INVALID_ARGS if `config` appears to be invalid, we fail to

    duplicate a token and therefore assume it must have been invalid, or

    the call to power broker fails for any reason *other* than a closed

    channel.

    Defined at line 587 of file ../../sdk/lib/driver/power/cpp/power-support.cc

  • fit::result<Error> AcquireLease (const fidl::UnownedClientEnd<fuchsia_power_broker::Topology> & topology, zx::event dependency_token, fuchsia_power_broker::PowerLevel level, std::string_view lease_name, bool should_return_pending_lease, fuchsia_power_broker::LeaseToken broker_lease_token)

    Helper to acquire a lease on an element using `fuchsia.power.broker/Topology.Lease`.

    Clients should create an eventpair and pass one end as `broker_lease_token` to be held by the

    broker. The other end should be retained by the client. The lease will remain open until the

    client's end is dropped.

    Defined at line 644 of file ../../sdk/lib/driver/power/cpp/power-support.cc