mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-10 14:47:42 +00:00
acpi_tables: aml: Add support for named definitions
Named definitions use op code 0x08 and are used to name some more complex object. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
5a7076442c
commit
bf0d0d9f9b
@ -62,9 +62,9 @@ impl From<&str> for Path {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type AmlByte = u8;
|
pub type Byte = u8;
|
||||||
|
|
||||||
impl Aml for AmlByte {
|
impl Aml for Byte {
|
||||||
fn to_bytes(&self) -> Vec<u8> {
|
fn to_bytes(&self) -> Vec<u8> {
|
||||||
let mut bytes = Vec::new();
|
let mut bytes = Vec::new();
|
||||||
bytes.push(0x0a); /* BytePrefix */
|
bytes.push(0x0a); /* BytePrefix */
|
||||||
@ -73,9 +73,9 @@ impl Aml for AmlByte {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type AmlWord = u16;
|
pub type Word = u16;
|
||||||
|
|
||||||
impl Aml for AmlWord {
|
impl Aml for Word {
|
||||||
fn to_bytes(&self) -> Vec<u8> {
|
fn to_bytes(&self) -> Vec<u8> {
|
||||||
let mut bytes = Vec::new();
|
let mut bytes = Vec::new();
|
||||||
bytes.push(0x0bu8); /* WordPrefix */
|
bytes.push(0x0bu8); /* WordPrefix */
|
||||||
@ -84,9 +84,9 @@ impl Aml for AmlWord {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type AmlDWord = u32;
|
pub type DWord = u32;
|
||||||
|
|
||||||
impl Aml for AmlDWord {
|
impl Aml for DWord {
|
||||||
fn to_bytes(&self) -> Vec<u8> {
|
fn to_bytes(&self) -> Vec<u8> {
|
||||||
let mut bytes = Vec::new();
|
let mut bytes = Vec::new();
|
||||||
bytes.push(0x0c); /* DWordPrefix */
|
bytes.push(0x0c); /* DWordPrefix */
|
||||||
@ -95,9 +95,9 @@ impl Aml for AmlDWord {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type AmlQWord = u64;
|
pub type QWord = u64;
|
||||||
|
|
||||||
impl Aml for AmlQWord {
|
impl Aml for QWord {
|
||||||
fn to_bytes(&self) -> Vec<u8> {
|
fn to_bytes(&self) -> Vec<u8> {
|
||||||
let mut bytes = Vec::new();
|
let mut bytes = Vec::new();
|
||||||
bytes.push(0x0e); /* QWordPrefix */
|
bytes.push(0x0e); /* QWordPrefix */
|
||||||
@ -106,6 +106,26 @@ impl Aml for AmlQWord {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct Name {
|
||||||
|
bytes: Vec<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Aml for Name {
|
||||||
|
fn to_bytes(&self) -> Vec<u8> {
|
||||||
|
self.bytes.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Name {
|
||||||
|
pub fn new(path: Path, inner: &dyn Aml) -> Self {
|
||||||
|
let mut bytes = Vec::new();
|
||||||
|
bytes.push(0x08); /* NameOp */
|
||||||
|
bytes.append(&mut path.to_bytes());
|
||||||
|
bytes.append(&mut inner.to_bytes());
|
||||||
|
Name { bytes }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@ -140,4 +160,21 @@ mod tests {
|
|||||||
[0x0e, 0xad, 0xfb, 0xca, 0xde, 0xad, 0xfb, 0xca, 0xde]
|
[0x0e, 0xad, 0xfb, 0xca, 0xde, 0xad, 0xfb, 0xca, 0xde]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_name() {
|
||||||
|
assert_eq!(
|
||||||
|
Name::new("_SB_.PCI0._UID".into(), &0x1234u16).to_bytes(),
|
||||||
|
[
|
||||||
|
0x08, /* NameOp */
|
||||||
|
0x2F, /* MultiNamePrefix */
|
||||||
|
0x03, /* 3 name parts */
|
||||||
|
0x5F, 0x53, 0x42, 0x5F, /* _SB_ */
|
||||||
|
0x50, 0x43, 0x49, 0x30, /* PCI0 */
|
||||||
|
0x5F, 0x55, 0x49, 0x44, /* _UID */
|
||||||
|
0x0b, /* WordPrefix */
|
||||||
|
0x34, 0x12
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user