1pub mod manager;
9pub mod fdt;
10pub mod platform;
11pub mod block;
12pub mod char;
13pub mod events;
14
15extern crate alloc;
16use core::any::Any;
17
18use alloc::vec::Vec;
19
20pub trait DeviceInfo {
21 fn name(&self) -> &'static str;
22 fn id(&self) -> usize;
23 fn compatible(&self) -> Vec<&'static str>;
24 fn as_any(&self) -> &dyn Any;
25}
26
27pub trait DeviceDriver {
33 fn name(&self) -> &'static str;
34 fn match_table(&self) -> Vec<&'static str>;
35 fn probe(&self, device: &dyn DeviceInfo) -> Result<(), &'static str>;
36 fn remove(&self, device: &dyn DeviceInfo) -> Result<(), &'static str>;
37}
38
39#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
46pub enum DeviceType {
47 Block,
48 Char,
49 Network,
50 Generic,
51 #[cfg(test)]
52 NonExistent,
53}
54
55pub trait Device: Send + Sync {
61 fn device_type(&self) -> DeviceType;
62 fn name(&self) -> &'static str;
63 fn as_any(&self) -> &dyn Any;
64 fn as_any_mut(&mut self) -> &mut dyn Any;
65
66 fn as_char_device(&self) -> Option<&dyn char::CharDevice> {
68 None
69 }
70
71 fn as_block_device(&self) -> Option<&dyn block::BlockDevice> {
73 None
74 }
75}
76
77pub struct GenericDevice {
78 device_type: DeviceType,
79 name: &'static str,
80}
81
82impl GenericDevice {
83 pub fn new(name: &'static str) -> Self {
84 Self { device_type: DeviceType::Generic, name }
85 }
86}
87
88impl Device for GenericDevice {
89 fn device_type(&self) -> DeviceType {
90 self.device_type
91 }
92
93 fn name(&self) -> &'static str {
94 self.name
95 }
96
97 fn as_any(&self) -> &dyn Any {
98 self
99 }
100
101 fn as_any_mut(&mut self) -> &mut dyn Any {
102 self
103 }
104}