44
55//! Collection of AML helpers and wrappers.
66
7- use acpi_tables:: aml;
7+ use super :: AcpiVariant ;
8+ use acpi_tables:: { aml, Aml , AmlSink } ;
9+ use std:: collections:: HashSet ;
10+
11+ // Flags used to defined ACPI methods concurrency control.
12+ //
13+ // See ACPI section 19.6.84 "Method (Declare Control Method)" for authoritative
14+ // information about these flags.
15+
16+ /// Declare the ASL method marked as "Serialized", meaning it is not safe for
17+ /// use by multiple concurrent threads.
18+ pub const SERIALIZED : bool = true ;
19+
20+ /// Declare the ASL method marked as "NotSerialized", meaning it is safe for
21+ /// concurrent access (does not declare objects internally, etc)
22+ pub const NOT_SERIALIZED : bool = false ;
823
924/// Creates an IO port with a fixed port number.
1025///
@@ -22,18 +37,30 @@ pub fn io_port(port: u16, alignment: u8, length: u8) -> aml::IO {
2237 aml:: IO :: new ( port, port, alignment, length)
2338}
2439
25- // Flags used to defined ACPI methods concurrency control.
26- //
27- // See ACPI section 19.6.84 "Method (Declare Control Method)" for authoritative
28- // information about these flags.
29-
30- /// Declare the ASL method marked as "Serialized", meaning it is not safe for
31- /// use by multiple concurrent threads.
32- pub const SERIALIZED : bool = true ;
33-
34- /// Declare the ASL method marked as "NotSerialized", meaning it is safe for
35- /// concurrent access (does not declare objects internally, etc)
36- pub const NOT_SERIALIZED : bool = false ;
40+ /// Wrapper for an `Aml` that only writes the AML bytecode to the sink if the
41+ /// target [`AcpiVariant`] is present in the filter.
42+ pub struct AcpiVariantFilter < ' a > {
43+ target : AcpiVariant ,
44+ filter : HashSet < AcpiVariant > ,
45+ inner : & ' a dyn Aml ,
46+ }
47+ impl < ' a > AcpiVariantFilter < ' a > {
48+ pub fn new (
49+ target : AcpiVariant ,
50+ filter : Vec < AcpiVariant > ,
51+ inner : & ' a dyn Aml ,
52+ ) -> Self {
53+ Self { target, filter : HashSet :: from_iter ( filter) , inner }
54+ }
55+ }
56+ impl < ' a > Aml for AcpiVariantFilter < ' a > {
57+ fn to_aml_bytes ( & self , sink : & mut dyn AmlSink ) {
58+ if !self . filter . contains ( & self . target ) {
59+ return ;
60+ }
61+ self . inner . to_aml_bytes ( sink) ;
62+ }
63+ }
3764
3865/// Constructors for ACPI paths defined in the ACPI specification.
3966///
0 commit comments