1use crate::{
6 bindings,
7 device_id::{RawDeviceId, RawDeviceIdIndex},
8 prelude::*,
9};
10
11pub type IdTable<T> = &'static dyn kernel::device_id::IdTable<DeviceId, T>;
13
14#[repr(transparent)]
16#[derive(Clone, Copy)]
17pub struct DeviceId(bindings::acpi_device_id);
18
19unsafe impl RawDeviceId for DeviceId {
22 type RawType = bindings::acpi_device_id;
23}
24
25unsafe impl RawDeviceIdIndex for DeviceId {
27 const DRIVER_DATA_OFFSET: usize = core::mem::offset_of!(bindings::acpi_device_id, driver_data);
28
29 fn index(&self) -> usize {
30 self.0.driver_data
31 }
32}
33
34impl DeviceId {
35 const ACPI_ID_LEN: usize = 16;
36
37 #[inline(always)]
39 pub const fn new(id: &'static CStr) -> Self {
40 let src = id.to_bytes_with_nul();
41 build_assert!(src.len() <= Self::ACPI_ID_LEN, "ID exceeds 16 bytes");
42 let mut acpi: bindings::acpi_device_id = unsafe { core::mem::zeroed() };
45 let mut i = 0;
46 while i < src.len() {
47 acpi.id[i] = src[i];
48 i += 1;
49 }
50
51 Self(acpi)
52 }
53}
54
55#[macro_export]
57macro_rules! acpi_device_table {
58 ($table_name:ident, $module_table_name:ident, $id_info_type: ty, $table_data: expr) => {
59 const $table_name: $crate::device_id::IdArray<
60 $crate::acpi::DeviceId,
61 $id_info_type,
62 { $table_data.len() },
63 > = $crate::device_id::IdArray::new($table_data);
64
65 $crate::module_device_table!("acpi", $module_table_name, $table_name);
66 };
67}