Skip to content

Commit 133001e

Browse files
committed
aml: add support for the DefStall opcode
1 parent bb664d0 commit 133001e

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

aml/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,11 @@ pub trait Handler: Send + Sync {
689689
fn write_pci_u16(&self, segment: u16, bus: u8, device: u8, function: u8, offset: u16, value: u16);
690690
fn write_pci_u32(&self, segment: u16, bus: u8, device: u8, function: u8, offset: u16, value: u32);
691691

692+
/// Stall for at least the given number of **microseconds**. An implementation should not relinquish control of
693+
/// the processor during the stall, and for this reason, firmwares should not stall for periods of more than
694+
/// 100 microseconds.
695+
fn stall(&self, microseconds: u64);
696+
692697
fn handle_fatal_error(&self, fatal_type: u8, fatal_code: u32, fatal_arg: u64) {
693698
panic!("Fatal error while executing AML (encountered DefFatal op). fatal_type = {:?}, fatal_code = {:?}, fatal_arg = {:?}", fatal_type, fatal_code, fatal_arg);
694699
}

aml/src/opcode.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub const EXT_DEF_POWER_RES_OP: u8 = 0x84;
4545
pub const EXT_DEF_THERMAL_ZONE_OP: u8 = 0x85;
4646

4747
/*
48-
* Type 1 opcodes
48+
* Statement opcodes
4949
*/
5050
pub const DEF_CONTINUE_OP: u8 = 0x9f;
5151
pub const DEF_IF_ELSE_OP: u8 = 0xa0;
@@ -55,9 +55,10 @@ pub const DEF_NOOP_OP: u8 = 0xa3;
5555
pub const DEF_RETURN_OP: u8 = 0xa4;
5656
pub const DEF_BREAK_OP: u8 = 0xa5;
5757
pub const DEF_BREAKPOINT_OP: u8 = 0xcc;
58+
pub const EXT_DEF_STALL_OP: u8 = 0x21;
5859

5960
/*
60-
* Type 2 opcodes
61+
* Expression opcodes
6162
*/
6263
pub const DEF_STORE_OP: u8 = 0x70;
6364
pub const DEF_ADD_OP: u8 = 0x72;

aml/src/statement.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ where
3939
def_if_else(),
4040
def_noop(),
4141
def_return(),
42+
def_stall(),
4243
def_while()
4344
),
4445
)
@@ -209,6 +210,27 @@ where
209210
.discard_result()
210211
}
211212

213+
fn def_stall<'a, 'c>() -> impl Parser<'a, 'c, ()>
214+
where
215+
'c: 'a,
216+
{
217+
/*
218+
* DefStall := ExtOpPrefix 0x21 USecTime
219+
* USecTime := TermArg => Integer
220+
*/
221+
ext_opcode(opcode::EXT_DEF_STALL_OP)
222+
.then(comment_scope(
223+
DebugVerbosity::Scopes,
224+
"DefStall",
225+
term_arg().map_with_context(|microseconds, context| {
226+
let microseconds = try_with_context!(context, microseconds.as_integer(&context));
227+
context.handler.stall(microseconds);
228+
(Ok(()), context)
229+
}),
230+
))
231+
.discard_result()
232+
}
233+
212234
fn def_while<'a, 'c>() -> impl Parser<'a, 'c, ()>
213235
where
214236
'c: 'a,

0 commit comments

Comments
 (0)