Skip to content

Commit 7f6bb2e

Browse files
committed
Parse DefPowerResources
Just parse them and stick them in the namespace. This was actually way less work than I thought was required for these objects.
1 parent 9dcd661 commit 7f6bb2e

File tree

5 files changed

+69
-2
lines changed

5 files changed

+69
-2
lines changed

aml/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,9 @@ impl AmlContext {
296296

297297
LevelType::Scope => Ok(true),
298298

299-
// TODO: can either of these contain devices?
299+
// TODO: can any of these contain devices?
300300
LevelType::Processor => Ok(false),
301+
LevelType::PowerResource => Ok(false),
301302
LevelType::MethodLocals => Ok(false),
302303
})?;
303304

aml/src/namespace.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ pub enum LevelType {
3030
/// A legacy `Processor` object's sub-objects are stored in a level of this type. Modern tables define
3131
/// processors as `Device`s.
3232
Processor,
33+
/// A `PowerResource` object's sub-objects are stored in a level of this type.
34+
PowerResource,
3335
/// A level of this type is created at the same path as the name of a method when it is invoked. It can be
3436
/// used by the method to store local variables.
3537
MethodLocals,

aml/src/opcode.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub const EXT_DEF_OP_REGION_OP: u8 = 0x80;
3131
pub const EXT_DEF_FIELD_OP: u8 = 0x81;
3232
pub const EXT_DEF_DEVICE_OP: u8 = 0x82;
3333
pub const EXT_DEF_PROCESSOR_OP: u8 = 0x83;
34+
pub const EXT_DEF_POWER_RES_OP: u8 = 0x84;
3435

3536
/*
3637
* Type 1 opcodes

aml/src/term_object.rs

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,15 @@ where
9797
comment_scope(
9898
DebugVerbosity::AllScopes,
9999
"NamedObj",
100-
choice!(def_op_region(), def_field(), def_method(), def_device(), def_processor(), def_mutex()),
100+
choice!(
101+
def_op_region(),
102+
def_field(),
103+
def_method(),
104+
def_device(),
105+
def_processor(),
106+
def_power_res(),
107+
def_mutex()
108+
),
101109
)
102110
}
103111

@@ -235,6 +243,56 @@ where
235243
.discard_result()
236244
}
237245

246+
pub fn def_power_res<'a, 'c>() -> impl Parser<'a, 'c, ()>
247+
where
248+
'c: 'a,
249+
{
250+
/*
251+
* DefPowerRes := ExtOpPrefix 0x84 PkgLength NameString SystemLevel ResourceOrder TermList
252+
* SystemLevel := ByteData
253+
* ResourceOrder := WordData
254+
*/
255+
ext_opcode(opcode::EXT_DEF_POWER_RES_OP)
256+
.then(comment_scope(
257+
DebugVerbosity::Scopes,
258+
"DefPowerRes",
259+
pkg_length()
260+
.then(name_string())
261+
.then(take())
262+
.then(take_u16())
263+
.map_with_context(|(((pkg_length, name), system_level), resource_order), context| {
264+
/*
265+
* `PowerResource` objects contain data within themselves, and can also have sub-objects,
266+
* so we add both a level for the sub-objects, and a value for the data.
267+
*/
268+
let resolved_name = try_with_context!(context, name.resolve(&context.current_scope));
269+
try_with_context!(
270+
context,
271+
context.namespace.add_level(resolved_name.clone(), LevelType::PowerResource)
272+
);
273+
try_with_context!(
274+
context,
275+
context.namespace.add_value(
276+
resolved_name.clone(),
277+
AmlValue::PowerResource { system_level, resource_order }
278+
)
279+
);
280+
let previous_scope = context.current_scope.clone();
281+
context.current_scope = resolved_name;
282+
283+
(Ok((previous_scope, pkg_length)), context)
284+
})
285+
.feed(move |(previous_scope, pkg_length)| {
286+
term_list(pkg_length).map(move |_| Ok(previous_scope.clone()))
287+
})
288+
.map_with_context(|previous_scope, context| {
289+
context.current_scope = previous_scope;
290+
(Ok(()), context)
291+
}),
292+
))
293+
.discard_result()
294+
}
295+
238296
pub fn def_field<'a, 'c>() -> impl Parser<'a, 'c, ()>
239297
where
240298
'c: 'a,

aml/src/value.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ pub enum AmlValue {
201201
sync_level: u8,
202202
},
203203
Package(Vec<AmlValue>),
204+
PowerResource {
205+
system_level: u8,
206+
resource_order: u16,
207+
},
204208
}
205209

206210
impl AmlValue {
@@ -236,6 +240,7 @@ impl AmlValue {
236240
AmlValue::Processor { .. } => AmlType::Processor,
237241
AmlValue::Mutex { .. } => AmlType::Mutex,
238242
AmlValue::Package(_) => AmlType::Package,
243+
AmlValue::PowerResource { .. } => AmlType::PowerResource,
239244
}
240245
}
241246

0 commit comments

Comments
 (0)