@@ -475,7 +475,7 @@ impl AmlValue {
475
475
}
476
476
}
477
477
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 > {
479
479
use bitvec:: view:: BitView ;
480
480
481
481
if let AmlValue :: BufferField { buffer_data, offset, length } = self {
@@ -519,6 +519,30 @@ impl AmlValue {
519
519
bitslice[ ( offset + bits_to_copy) ..( offset + length) ] . fill ( false ) ;
520
520
Ok ( ( ) )
521
521
}
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
+ }
522
546
_ => Err ( AmlError :: TypeCannotBeWrittenToBufferField ( value. type_of ( ) ) ) ,
523
547
}
524
548
} else {
0 commit comments