Skip to content

Commit 54f4043

Browse files
committed
Added ability to write an AmlValue::Field into a buffer
1 parent 0a850f7 commit 54f4043

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

aml/src/value.rs

+25-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ impl AmlValue {
475475
}
476476
}
477477

478-
pub fn write_buffer_field(&mut self, value: AmlValue, _context: &mut AmlContext) -> Result<(), AmlError> {
478+
pub fn write_buffer_field(&mut self, value: AmlValue, context: &mut AmlContext) -> Result<(), AmlError> {
479479
use bitvec::view::BitView;
480480

481481
if let AmlValue::BufferField { buffer_data, offset, length } = self {
@@ -519,6 +519,30 @@ impl AmlValue {
519519
bitslice[(offset + bits_to_copy)..(offset + length)].fill(false);
520520
Ok(())
521521
}
522+
AmlValue::Field {
523+
region: _region,
524+
flags: _flags,
525+
offset: _field_offset,
526+
length: _field_length,
527+
} => {
528+
/*
529+
* When a `Field` (FieldUnit) is written into a `BufferField`, the field is read and
530+
* interpreted as an `Integer`, then written using the same rules as Integer writes.
531+
* This is permitted by ACPI 19.3.5 (Implicit Data Type Conversion), which allows a
532+
* FieldUnit to be converted to Integer when used as a source operand.
533+
*/
534+
let int_value = value.read_field(context)?.as_integer(context)?;
535+
536+
// Write val into the buffer field as an Integer
537+
let bits_to_copy = cmp::min(length, 64);
538+
539+
bitslice[offset..(offset + bits_to_copy)]
540+
.copy_from_bitslice(&int_value.to_le_bytes().view_bits()[..bits_to_copy]);
541+
542+
bitslice[(offset + bits_to_copy)..(offset + length)].fill(false);
543+
544+
Ok(())
545+
}
522546
_ => Err(AmlError::TypeCannotBeWrittenToBufferField(value.type_of())),
523547
}
524548
} else {

0 commit comments

Comments
 (0)