From 4f496e39a18374d4089fe04cc13c8b6a3069e851 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Wed, 3 Nov 2021 14:29:05 +0000 Subject: [PATCH] acpi_tables: aml: Implement Aml::append_aml_bytes() for ResourceTemplate For now it still relies on Aml::to_aml_bytes() for the children as not all structures have been ported. Signed-off-by: Rob Bradford --- acpi_tables/src/aml.rs | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/acpi_tables/src/aml.rs b/acpi_tables/src/aml.rs index 5399cf9e3..fcf903df5 100644 --- a/acpi_tables/src/aml.rs +++ b/acpi_tables/src/aml.rs @@ -303,36 +303,31 @@ pub struct ResourceTemplate<'a> { } impl<'a> Aml for ResourceTemplate<'a> { - fn to_aml_bytes(&self) -> Vec { - let mut bytes = Vec::new(); - + fn append_aml_bytes(&self, bytes: &mut Vec) { + let mut tmp = Vec::new(); // Add buffer data for child in &self.children { - bytes.append(&mut child.to_aml_bytes()); + tmp.append(&mut child.to_aml_bytes()); } // Mark with end and mark checksum as as always valid - bytes.push(0x79); /* EndTag */ - bytes.push(0); /* zero checksum byte */ + tmp.push(0x79); /* EndTag */ + tmp.push(0); /* zero checksum byte */ // Buffer length is an encoded integer including buffer data // and EndTag and checksum byte - let mut buffer_length = bytes.len().to_aml_bytes(); + let mut buffer_length = tmp.len().to_aml_bytes(); buffer_length.reverse(); for byte in buffer_length { - bytes.insert(0, byte); + tmp.insert(0, byte); } // PkgLength is everything else - let mut pkg_length = create_pkg_length(&bytes, true); - pkg_length.reverse(); - for byte in pkg_length { - bytes.insert(0, byte); - } + let mut pkg_length = create_pkg_length(&tmp, true); - bytes.insert(0, 0x11); /* BufferOp */ - - bytes + bytes.push(0x11); /* BufferOp */ + bytes.append(&mut pkg_length); + bytes.append(&mut tmp); } }