From 03d8cdc4f25e48db069fd0643ca599118ec39cb6 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Fri, 18 Oct 2019 17:26:56 +0100 Subject: [PATCH] acpi_tables: aml: Generate EISA name IDs EISA names (of the the form UUUNNNN) are encoded into a 32-bit integer. Signed-off-by: Rob Bradford --- acpi_tables/src/aml.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/acpi_tables/src/aml.rs b/acpi_tables/src/aml.rs index 81c200095..d3d136890 100644 --- a/acpi_tables/src/aml.rs +++ b/acpi_tables/src/aml.rs @@ -209,6 +209,35 @@ fn create_pkg_length(data: &[u8]) -> Vec { result } +pub struct EISAName { + value: DWord, +} + +impl EISAName { + pub fn new(name: &str) -> Self { + assert_eq!(name.len(), 7); + + let data = name.as_bytes(); + + let value: u32 = (u32::from(data[0] - 0x40) << 26 + | u32::from(data[1] - 0x40) << 21 + | u32::from(data[2] - 0x40) << 16 + | name.chars().nth(3).unwrap().to_digit(16).unwrap() << 12 + | name.chars().nth(4).unwrap().to_digit(16).unwrap() << 8 + | name.chars().nth(5).unwrap().to_digit(16).unwrap() << 4 + | name.chars().nth(6).unwrap().to_digit(16).unwrap()) + .swap_bytes(); + + EISAName { value } + } +} + +impl Aml for EISAName { + fn to_bytes(&self) -> Vec { + self.value.to_bytes() + } +} + #[cfg(test)] mod tests { use super::*; @@ -245,6 +274,13 @@ mod tests { assert_eq!(s5_sleep_data.to_vec(), s5.to_bytes()); } + #[test] + fn test_eisa_name() { + assert_eq!( + Name::new("_HID".into(), &EISAName::new("PNP0501")).to_bytes(), + [0x08, 0x5F, 0x48, 0x49, 0x44, 0x0C, 0x41, 0xD0, 0x05, 0x01], + ) + } #[test] fn test_name_path() { assert_eq!(