1use crate::{bindings, device_id::RawDeviceId, prelude::*};
6
7pub type IdTable<T> = &'static dyn kernel::device_id::IdTable<DeviceId, T>;
9
10#[repr(transparent)]
12#[derive(Clone, Copy)]
13pub struct DeviceId(bindings::of_device_id);
14
15unsafe impl RawDeviceId for DeviceId {
20 type RawType = bindings::of_device_id;
21
22 const DRIVER_DATA_OFFSET: usize = core::mem::offset_of!(bindings::of_device_id, data);
23
24 fn index(&self) -> usize {
25 self.0.data as _
26 }
27}
28
29impl DeviceId {
30 pub const fn new(compatible: &'static CStr) -> Self {
32 let src = compatible.as_bytes_with_nul();
33 let mut of: bindings::of_device_id = unsafe { core::mem::zeroed() };
36
37 let mut i = 0;
39 while i < src.len() {
40 of.compatible[i] = src[i] as _;
41 i += 1;
42 }
43
44 Self(of)
45 }
46}
47
48#[macro_export]
50macro_rules! of_device_table {
51 ($table_name:ident, $module_table_name:ident, $id_info_type: ty, $table_data: expr) => {
52 const $table_name: $crate::device_id::IdArray<
53 $crate::of::DeviceId,
54 $id_info_type,
55 { $table_data.len() },
56 > = $crate::device_id::IdArray::new($table_data);
57
58 $crate::module_device_table!("of", $module_table_name, $table_name);
59 };
60}