driver_interface/
register.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use crate::{interrupt_controller, timer};

#[repr(C)]
#[derive(Clone)]
pub struct DriverRegister {
    pub name: &'static str,
    pub compatibles: &'static [&'static str],
    pub probe: ProbeFnKind,
}

unsafe impl Send for DriverRegister {}
unsafe impl Sync for DriverRegister {}

#[derive(Clone)]
pub enum ProbeFnKind {
    InterruptController(interrupt_controller::ProbeFn),
    Timer(timer::ProbeFn),
}

#[repr(C)]
pub struct DriverRegisterListRef {
    data: *const u8,
    len: usize,
}

impl DriverRegisterListRef {
    pub fn from_raw(data: &'static [u8]) -> Self {
        Self {
            data: data.as_ptr(),
            len: data.len(),
        }
    }

    pub fn as_slice(&self) -> &[DriverRegister] {
        unsafe {
            core::slice::from_raw_parts(self.data as _, self.len / size_of::<DriverRegister>())
        }
    }
}