1#![allow(unused_imports)]
9
10use bitflags::bitflags;
11use zerocopy::{FromBytes, IntoBytes};
12
13#[repr(u32)]
15#[derive(Clone, Copy, Debug, Eq, IntoBytes, PartialEq)]
16pub enum KernelDriver {
17 ArmPsci = 0x49435350,
19
20 ArmPsciCpuSuspend = 0x53435350,
22
23 ArmGicV2 = 0x32434947,
25
26 ArmGicV3 = 0x33434947,
28
29 ArmGenericTimer = 0x4d495441,
31
32 ArmGenericTimerMmio = 0x4d4d5441,
34
35 Pl011Uart = 0x55304c50,
37
38 AmlogicUart = 0x554c4d41,
40
41 AmlogicHdcp = 0x484c4d41,
43
44 Dw8250Uart = 0x44573855,
46
47 AmlogicRngV1 = 0x484c4d52,
49
50 AmlogicRngV2 = 0x524c4d41,
52
53 Generic32Watchdog = 0x32334457,
55
56 GeniUart = 0x494E4547,
58
59 I8250PioUart = 0x30353238,
61
62 I8250Mmio32Uart = 0x4d353238,
64
65 I8250Mmio8Uart = 0x42353238,
67
68 MotmotPower = 0x4d4d5450,
70
71 As370Power = 0x50303733,
73
74 MoonflowerPower = 0x4d4e4650,
76
77 ImxUart = 0x55584d49,
79
80 RiscvPlic = 0x43494C50,
82
83 RiscvGenericTimer = 0x4D495452,
85
86 PxaUart = 0x50584155,
88
89 ExynosUsiUart = 0x45585955,
91
92 QcomRng = 0x474E5251,
94}
95
96impl KernelDriver {
97 pub fn from_raw(raw: u32) -> Option<Self> {
98 match raw {
99 0x49435350 => Some(Self::ArmPsci),
100
101 0x53435350 => Some(Self::ArmPsciCpuSuspend),
102
103 0x32434947 => Some(Self::ArmGicV2),
104
105 0x33434947 => Some(Self::ArmGicV3),
106
107 0x4d495441 => Some(Self::ArmGenericTimer),
108
109 0x4d4d5441 => Some(Self::ArmGenericTimerMmio),
110
111 0x55304c50 => Some(Self::Pl011Uart),
112
113 0x554c4d41 => Some(Self::AmlogicUart),
114
115 0x484c4d41 => Some(Self::AmlogicHdcp),
116
117 0x44573855 => Some(Self::Dw8250Uart),
118
119 0x484c4d52 => Some(Self::AmlogicRngV1),
120
121 0x524c4d41 => Some(Self::AmlogicRngV2),
122
123 0x32334457 => Some(Self::Generic32Watchdog),
124
125 0x494E4547 => Some(Self::GeniUart),
126
127 0x30353238 => Some(Self::I8250PioUart),
128
129 0x4d353238 => Some(Self::I8250Mmio32Uart),
130
131 0x42353238 => Some(Self::I8250Mmio8Uart),
132
133 0x4d4d5450 => Some(Self::MotmotPower),
134
135 0x50303733 => Some(Self::As370Power),
136
137 0x4d4e4650 => Some(Self::MoonflowerPower),
138
139 0x55584d49 => Some(Self::ImxUart),
140
141 0x43494C50 => Some(Self::RiscvPlic),
142
143 0x4D495452 => Some(Self::RiscvGenericTimer),
144
145 0x50584155 => Some(Self::PxaUart),
146
147 0x45585955 => Some(Self::ExynosUsiUart),
148
149 0x474E5251 => Some(Self::QcomRng),
150
151 _ => None,
152 }
153 }
154}
155
156#[repr(C)]
160#[derive(Clone, Copy, Debug, Eq, FromBytes, IntoBytes, PartialEq)]
161pub struct DcfgSimple {
162 pub mmio_phys: u64,
163 pub irq: u32,
164 pub flags: u32,
165}
166
167#[repr(C)]
168#[derive(IntoBytes, FromBytes, Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
169pub struct KernelDriverIrqFlags(u32);
170
171bitflags::bitflags! {
172 impl KernelDriverIrqFlags : u32 {
173
174 const EDGE_TRIGGERED = 1 << 0;
177 const LEVEL_TRIGGERED = 1 << 1;
178
179 const POLARITY_LOW = 1 << 2;
183
184 const POLARITY_HIGH = 1 << 3;
188 }
189}
190
191#[repr(C)]
193#[derive(Clone, Copy, Debug, Eq, FromBytes, IntoBytes, PartialEq)]
194pub struct DcfgSimplePio {
195 pub base: u16,
196 pub reserved: u16,
197 pub irq: u32,
198}
199
200#[repr(C)]
202#[derive(Clone, Copy, Debug, Eq, FromBytes, IntoBytes, PartialEq)]
203pub struct DcfgArmPsciDriver {
204 pub use_hvc: u8,
205 pub reserved: [u8; 7],
206 pub shutdown_args: [u64; 3],
207 pub reboot_args: [u64; 3],
208 pub reboot_bootloader_args: [u64; 3],
209 pub reboot_recovery_args: [u64; 3],
210}
211
212#[repr(C)]
214#[derive(Clone, Copy, Debug, Eq, FromBytes, IntoBytes, PartialEq)]
215pub struct DcfgArmGicV2Driver {
216 pub mmio_phys: u64,
217 pub msi_frame_phys: u64,
218 pub gicd_offset: u64,
219 pub gicc_offset: u64,
220 pub gich_offset: u64,
221 pub gicv_offset: u64,
222 pub ipi_base: u32,
223 pub optional: u8,
224 pub use_msi: u8,
225 pub reserved: u16,
226}
227
228#[repr(C)]
230#[derive(Clone, Copy, Debug, Eq, FromBytes, IntoBytes, PartialEq)]
231pub struct DcfgArmGicV3Driver {
232 pub mmio_phys: u64,
233 pub gicd_offset: u64,
234 pub gicr_offset: u64,
235 pub gicr_stride: u64,
236 pub reserved0: u64,
237 pub ipi_base: u32,
238 pub optional: u8,
239 pub reserved1: [u8; 3],
240}
241
242#[repr(C)]
244#[derive(Clone, Copy, Debug, Eq, FromBytes, IntoBytes, PartialEq)]
245pub struct DcfgArmGenericTimerDriver {
246 pub irq_phys: u32,
247 pub irq_virt: u32,
248 pub irq_sphys: u32,
249 pub freq_override: u32,
250}
251
252#[repr(C)]
253#[derive(Clone, Copy, Debug, Eq, FromBytes, IntoBytes, PartialEq)]
254pub struct DcfgArmGenericTimerMmioFrame {
255 pub mmio_phys_el1: u64,
257
258 pub mmio_phys_el0: u64,
261
262 pub irq_phys: u32,
264
265 pub irq_phys_flags: u32,
267
268 pub irq_virt: u32,
272
273 pub irq_virt_flags: u32,
275}
276
277#[repr(C)]
279#[derive(Clone, Copy, Debug, Eq, FromBytes, IntoBytes, PartialEq)]
280pub struct DcfgArmGenericTimerMmioDriver {
281 pub mmio_phys: u64,
283
284 pub frequency: u32,
286
287 pub active_frames_mask: u8,
292 pub reserved0: [u8; 3],
293
294 pub frames: [DcfgArmGenericTimerMmioFrame; 8],
297}
298
299#[repr(C)]
301#[derive(Clone, Copy, Debug, Eq, FromBytes, IntoBytes, PartialEq)]
302pub struct DcfgAmlogicHdcpDriver {
303 pub preset_phys: u64,
304 pub hiu_phys: u64,
305 pub hdmitx_phys: u64,
306}
307
308#[repr(C)]
311#[derive(Clone, Copy, Debug, Eq, FromBytes, IntoBytes, PartialEq)]
312pub struct DcfgAmlogicRngDriver {
313 pub rng_data_phys: u64,
314 pub rng_status_phys: u64,
315 pub rng_refresh_interval_usec: u64,
316}
317
318#[repr(C)]
326#[derive(Clone, Copy, Debug, Eq, FromBytes, IntoBytes, PartialEq)]
327pub struct DcfgGeneric32WatchdogAction {
328 pub addr: u64,
329 pub clr_mask: u32,
330 pub set_mask: u32,
331}
332
333#[repr(C)]
334#[derive(IntoBytes, FromBytes, Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
335pub struct KernelDriverGeneric32WatchdogFlags(u32);
336
337bitflags::bitflags! {
338 impl KernelDriverGeneric32WatchdogFlags : u32 {
339 const ENABLED = 1 << 0;
340 }
341}
342
343pub const KERNEL_DRIVER_GENERIC32_WATCHDOG_MIN_PERIOD: i64 = 1000000;
345
346#[repr(C)]
350#[derive(Clone, Copy, Debug, Eq, FromBytes, IntoBytes, PartialEq)]
351pub struct DcfgGeneric32Watchdog {
352 pub pet_action: DcfgGeneric32WatchdogAction,
354
355 pub enable_action: DcfgGeneric32WatchdogAction,
358
359 pub disable_action: DcfgGeneric32WatchdogAction,
363
364 pub watchdog_period_nsec: i64,
369
370 pub flags: KernelDriverGeneric32WatchdogFlags,
374 pub reserved: u32,
375}
376
377#[repr(C)]
379#[derive(Clone, Copy, Debug, Eq, FromBytes, IntoBytes, PartialEq)]
380pub struct DcfgRiscvPlicDriver {
381 pub mmio_phys: u64,
383
384 pub size_bytes: u32,
386
387 pub num_irqs: u32,
389}
390
391#[repr(C)]
393#[derive(Clone, Copy, Debug, Eq, FromBytes, IntoBytes, PartialEq)]
394pub struct DcfgRiscvGenericTimerDriver {
395 pub freq_hz: u32,
396 pub reserved: u32,
397}
398
399#[repr(C)]
400#[derive(IntoBytes, FromBytes, Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
401pub struct ArmPsciCpuSuspendStateFlags(u32);
402
403bitflags::bitflags! {
404 impl ArmPsciCpuSuspendStateFlags : u32 {
405
406 const LOCAL_TIMER_STOPS = 1 << 0;
410
411 const TARGETS_POWER_DOMAIN = 1 << 1;
415 }
416}
417
418#[repr(C)]
427#[derive(Clone, Copy, Debug, Eq, FromBytes, IntoBytes, PartialEq)]
428pub struct DcfgArmPsciCpuSuspendState {
429 pub id: u32,
431
432 pub power_state: u32,
435 pub flags: ArmPsciCpuSuspendStateFlags,
436
437 pub entry_latency_us: u32,
439
440 pub exit_latency_us: u32,
442
443 pub min_residency_us: u32,
446}
447
448#[repr(C)]
449#[derive(IntoBytes, FromBytes, Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
450pub struct QcomRngFlags(u32);
451
452bitflags::bitflags! {
453 impl QcomRngFlags : u32 {
454
455 const ENABLED = 1 << 0;
457 }
458}
459
460#[repr(C)]
461#[derive(Clone, Copy, Debug, Eq, FromBytes, IntoBytes, PartialEq)]
462pub struct DcfgQcomRng {
463 pub mmio_phys: u64,
465 pub flags: QcomRngFlags,
466 pub reserved: [u8; 4],
467}