acpica_bindings/interface/
types.rs1mod generic_address;
4pub mod object;
5pub mod tables;
6
7use core::{
8 ffi::{c_void, CStr},
9 fmt::{Debug, Display},
10};
11
12use crate::bindings::types::{
13 functions::{FfiAcpiOsdExecCallback, FfiAcpiOsdHandler},
14 FfiAcpiCpuFlags, FfiAcpiPciId, FfiAcpiPredefinedNames,
15};
16
17pub use generic_address::*;
18
19use self::object::AcpiObject;
20
21#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
23pub struct AcpiPhysicalAddress(pub usize);
24
25impl AcpiPhysicalAddress {
26 pub const NULL: Self = Self(0);
28}
29
30impl Debug for AcpiPhysicalAddress {
31 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
32 f.debug_tuple("AcpiPhysicalAddress")
33 .field(&format_args!("{:#x}", self.0))
34 .finish()
35 }
36}
37
38#[cfg(feature = "x86_64")]
39impl From<AcpiPhysicalAddress> for x86_64::PhysAddr {
40 fn from(val: AcpiPhysicalAddress) -> Self {
41 x86_64::PhysAddr::new(val.0.try_into().unwrap())
42 }
43}
44
45#[derive(Debug)]
51pub struct AcpiPredefinedNames<'a>(&'a FfiAcpiPredefinedNames);
52
53impl<'a> AcpiPredefinedNames<'a> {
54 pub(crate) fn from_ffi(ffi_predefined_names: &'a FfiAcpiPredefinedNames) -> Self {
55 Self(ffi_predefined_names)
56 }
57
58 pub(crate) fn as_ffi(&self) -> &'a FfiAcpiPredefinedNames {
59 self.0
60 }
61
62 #[must_use]
64 #[allow(clippy::missing_panics_doc)] pub fn name(&self) -> &str {
66 unsafe {
68 CStr::from_ptr(self.0.name)
69 .to_str()
70 .expect("Object name should have been valid utf-8")
71 }
72 }
73
74 #[must_use]
76 pub fn object(&self) -> AcpiObject {
77 unsafe { AcpiObject::from_type_and_val(self.0.object_type, self.0.val) }
79 }
80}
81
82#[derive(Debug, Clone, Copy)]
84pub struct AcpiIoAddress(pub usize);
85
86#[derive(Debug)]
92pub struct AcpiInterruptCallbackTag(pub(crate) FfiAcpiOsdHandler);
93
94#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
100pub struct AcpiInterruptCallback {
101 pub(crate) function: FfiAcpiOsdHandler,
102 pub(crate) context: *mut c_void,
103}
104
105unsafe impl Send for AcpiInterruptCallback {}
109
110#[derive(Debug, Clone, Copy, PartialEq, Eq)]
114pub enum AcpiInterruptHandledStatus {
115 Handled,
117 NotHandled,
119}
120
121impl AcpiInterruptCallback {
122 pub unsafe fn call(&mut self) -> AcpiInterruptHandledStatus {
129 let call_result = unsafe { (self.function)(self.context) };
131 match call_result {
132 0 => AcpiInterruptHandledStatus::Handled,
133 1 => AcpiInterruptHandledStatus::NotHandled,
134 _ => unreachable!("Acpi callback returned an invalid value"),
135 }
136 }
137
138 #[must_use]
140 pub fn is_tag(&self, tag: &AcpiInterruptCallbackTag) -> bool {
141 self.function == tag.0
142 }
143}
144
145#[derive(Debug)]
151pub struct AcpiThreadCallback {
152 pub(crate) function: FfiAcpiOsdExecCallback,
153 pub(crate) context: *mut c_void,
154}
155
156impl AcpiThreadCallback {
157 pub unsafe fn call(&mut self) {
162 unsafe { (self.function)(self.context) };
164 }
165}
166
167#[derive(Debug, Copy, Clone, PartialEq, Eq)]
169pub struct AcpiPciId {
170 pub segment: u16,
172 pub bus: u16,
174 pub device: u16,
176 pub function: u16,
178}
179
180impl AcpiPciId {
181 pub(crate) fn from_ffi(v: FfiAcpiPciId) -> Self {
182 Self {
183 segment: v.segment,
184 bus: v.bus,
185 device: v.device,
186 function: v.function,
187 }
188 }
189}
190
191#[derive(Debug, Clone, Copy, PartialEq, Eq)]
193pub enum AcpiAllocationError {
194 OutOfMemory,
196}
197
198impl Display for AcpiAllocationError {
199 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
200 match self {
201 Self::OutOfMemory => f.write_str("Out of memory"),
202 }
203 }
204}
205
206#[derive(Debug, Clone, Copy, PartialEq, Eq)]
208pub enum AcpiMappingError {
209 OutOfMemory,
211}
212
213impl Display for AcpiMappingError {
214 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
215 match self {
216 Self::OutOfMemory => f.write_str("Out of memory"),
217 }
218 }
219}
220
221#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
225pub struct AcpiCpuFlags(pub FfiAcpiCpuFlags);