1#![allow(unused_imports)]
9
10use bitflags::bitflags;
11use zerocopy::{FromBytes, IntoBytes};
12
13use crate::zx_common::*;
14
15pub const MAX_POWER_LEVELS: usize = 256;
16
17pub const MAX_POWER_LEVEL_TRANSITIONS: usize = 65536;
18
19#[repr(C)]
20#[derive(Clone, Copy, Debug, Eq, FromBytes, IntoBytes, PartialEq)]
21pub struct ProcessorPowerDomain {
22 pub mask: [u64; 8],
23 pub domain_id: u32,
24 pub padding1: [u8; 4],
25}
26
27#[repr(C)]
28#[derive(IntoBytes, FromBytes, Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
29pub struct ProcessorPowerLevelOptions(u64);
30
31bitflags::bitflags! {
32 impl ProcessorPowerLevelOptions : u64 {
33 const PROCESSOR_POWER_LEVEL_OPTIONS_DOMAIN_INDEPENDENT = 1 << 0;
34 }
35}
36
37#[repr(u64)]
38#[derive(Clone, Copy, Debug, Eq, IntoBytes, PartialEq)]
39pub enum ProcessorPowerControl {
40 ProcessorPowerControlCpuDriver = 0,
41 ProcessorPowerControlArmPsci = 1,
42 ProcessorPowerControlArmWfi = 2,
43 ProcessorPowerControlRiscvSbi = 3,
44 ProcessorPowerControlRiscvWfi = 4,
45}
46
47impl ProcessorPowerControl {
48 pub fn from_raw(raw: u64) -> Option<Self> {
49 match raw {
50 0 => Some(Self::ProcessorPowerControlCpuDriver),
51
52 1 => Some(Self::ProcessorPowerControlArmPsci),
53
54 2 => Some(Self::ProcessorPowerControlArmWfi),
55
56 3 => Some(Self::ProcessorPowerControlRiscvSbi),
57
58 4 => Some(Self::ProcessorPowerControlRiscvWfi),
59
60 _ => None,
61 }
62 }
63}
64
65#[repr(C)]
66#[derive(Clone, Copy, Debug, Eq, IntoBytes, PartialEq)]
67pub struct ProcessorPowerLevel {
68 pub options: ProcessorPowerLevelOptions,
69 pub processing_rate: u64,
70 pub power_coefficient_nw: u64,
71 pub control_interface: ProcessorPowerControl,
72 pub control_argument: u64,
73 pub diagnostic_name: [u8; 32],
74 pub reserved: [u8; 32],
75}
76
77#[repr(C)]
78#[derive(Clone, Copy, Debug, Eq, FromBytes, IntoBytes, PartialEq)]
79pub struct ProcessorPowerLevelTransition {
80 pub latency: Duration,
81 pub energy_nj: u64,
82 pub from: u8,
83 pub to: u8,
84 pub reserved: [u8; 6],
85}
86
87#[repr(C)]
88#[derive(Clone, Copy, Debug, Eq, IntoBytes, PartialEq)]
89pub struct ProcessorPowerState {
90 pub domain_id: u32,
91 pub option: u32,
92 pub control_interface: ProcessorPowerControl,
93 pub control_argument: u64,
94}
95
96#[repr(C)]
97#[derive(Clone, Copy, Debug, Eq, FromBytes, IntoBytes, PartialEq)]
98pub struct SystemPowerctlArg {}
99
100#[repr(C)]
103#[derive(IntoBytes, FromBytes, Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
104pub struct SystemSuspendOption(u64);
105
106bitflags::bitflags! {
107 impl SystemSuspendOption : u64 {
108
109 const DISCARD = 1 << 0;
116
117 const REPORT_ONLY = 1 << 1;
121 }
122}
123
124#[repr(C)]
127#[derive(IntoBytes, FromBytes, Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
128pub struct SystemWakeReportEntryFlag(u32);
129
130bitflags::bitflags! {
131 impl SystemWakeReportEntryFlag : u32 {
132
133 const SIGNALED = 1 << 0;
137
138 const PREVIOUSLY_REPORTED = 1 << 1;
143 }
144}
145
146#[repr(C)]
150#[derive(Clone, Copy, Debug, Eq, FromBytes, IntoBytes, PartialEq)]
151pub struct WakeSourceReportEntry {
152 pub koid: Koid,
155
156 pub name: [u8; 32],
160
161 pub initial_signal_time: InstantBoot,
164
165 pub last_signal_time: InstantBoot,
169
170 pub last_ack_time: InstantBoot,
173
174 pub signal_count: u32,
177
178 pub flags: SystemWakeReportEntryFlag,
180}
181
182#[repr(C)]
183#[derive(Clone, Copy, Debug, Eq, FromBytes, IntoBytes, PartialEq)]
184pub struct WakeSourceReportHeader {
185 pub report_time: InstantBoot,
187
188 pub suspend_start_time: InstantBoot,
191
192 pub total_wake_sources: u32,
195
196 pub unreported_wake_report_entries: u32,
200}
201
202#[repr(C)]
203#[derive(Clone, Copy, Debug, Eq, PartialEq)]
204pub struct StringView {
205 pub c_str: *const u8,
206 pub length: usize,
207}
208
209#[repr(u32)]
210#[derive(Clone, Copy, Debug, Eq, IntoBytes, PartialEq)]
211pub enum CpuPerfLimitType {
212 Rate = 0,
217
218 Power = 1,
221}
222
223impl CpuPerfLimitType {
224 pub fn from_raw(raw: u32) -> Option<Self> {
225 match raw {
226 0 => Some(Self::Rate),
227
228 1 => Some(Self::Power),
229
230 _ => None,
231 }
232 }
233}
234
235#[repr(C)]
236#[derive(Clone, Copy, Debug, Eq, IntoBytes, PartialEq)]
237pub struct CpuPerfLimit {
238 pub logical_cpu_number: u32,
239 pub limit_type: CpuPerfLimitType,
240 pub min: u64,
241 pub max: u64,
242}