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::acpi_device_id);
14
15unsafe impl RawDeviceId for DeviceId {
20 type RawType = bindings::acpi_device_id;
21
22 const DRIVER_DATA_OFFSET: usize = core::mem::offset_of!(bindings::acpi_device_id, driver_data);
23
24 fn index(&self) -> usize {
25 self.0.driver_data as _
26 }
27}
28
29impl DeviceId {
30 const ACPI_ID_LEN: usize = 16;
31
32 #[inline(always)]
34 pub const fn new(id: &'static CStr) -> Self {
35 build_assert!(
36 id.len_with_nul() <= Self::ACPI_ID_LEN,
37 "ID exceeds 16 bytes"
38 );
39 let src = id.as_bytes_with_nul();
40 let mut acpi: bindings::acpi_device_id = unsafe { core::mem::zeroed() };
43 let mut i = 0;
44 while i < src.len() {
45 acpi.id[i] = src[i];
46 i += 1;
47 }
48
49 Self(acpi)
50 }
51}
52
53#[macro_export]
55macro_rules! acpi_device_table {
56 ($table_name:ident, $module_table_name:ident, $id_info_type: ty, $table_data: expr) => {
57 const $table_name: $crate::device_id::IdArray<
58 $crate::acpi::DeviceId,
59 $id_info_type,
60 { $table_data.len() },
61 > = $crate::device_id::IdArray::new($table_data);
62
63 $crate::module_device_table!("acpi", $module_table_name, $table_name);
64 };
65}