vmm: Port MemoryManager to Aml::append_aml_bytes()

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2021-11-04 17:12:59 +00:00
parent e04cbb2ad4
commit 185f0c1bf3

View File

@ -1783,13 +1783,13 @@ struct MemoryNotify {
#[cfg(feature = "acpi")] #[cfg(feature = "acpi")]
impl Aml for MemoryNotify { impl Aml for MemoryNotify {
fn to_aml_bytes(&self) -> Vec<u8> { fn append_aml_bytes(&self, bytes: &mut Vec<u8>) {
let object = aml::Path::new(&format!("M{:03}", self.slot_id)); let object = aml::Path::new(&format!("M{:03}", self.slot_id));
aml::If::new( aml::If::new(
&aml::Equal::new(&aml::Arg(0), &self.slot_id), &aml::Equal::new(&aml::Arg(0), &self.slot_id),
vec![&aml::Notify::new(&object, &aml::Arg(1))], vec![&aml::Notify::new(&object, &aml::Arg(1))],
) )
.to_aml_bytes() .append_aml_bytes(bytes)
} }
} }
@ -1800,7 +1800,7 @@ struct MemorySlot {
#[cfg(feature = "acpi")] #[cfg(feature = "acpi")]
impl Aml for MemorySlot { impl Aml for MemorySlot {
fn to_aml_bytes(&self) -> Vec<u8> { fn append_aml_bytes(&self, bytes: &mut Vec<u8>) {
aml::Device::new( aml::Device::new(
format!("M{:03}", self.slot_id).as_str().into(), format!("M{:03}", self.slot_id).as_str().into(),
vec![ vec![
@ -1838,7 +1838,7 @@ impl Aml for MemorySlot {
), ),
], ],
) )
.to_aml_bytes() .append_aml_bytes(bytes)
} }
} }
@ -1849,14 +1849,10 @@ struct MemorySlots {
#[cfg(feature = "acpi")] #[cfg(feature = "acpi")]
impl Aml for MemorySlots { impl Aml for MemorySlots {
fn to_aml_bytes(&self) -> Vec<u8> { fn append_aml_bytes(&self, bytes: &mut Vec<u8>) {
let mut bytes = Vec::new();
for slot_id in 0..self.slots { for slot_id in 0..self.slots {
bytes.extend_from_slice(&MemorySlot { slot_id }.to_aml_bytes()); MemorySlot { slot_id }.append_aml_bytes(bytes);
} }
bytes
} }
} }
@ -1867,8 +1863,7 @@ struct MemoryMethods {
#[cfg(feature = "acpi")] #[cfg(feature = "acpi")]
impl Aml for MemoryMethods { impl Aml for MemoryMethods {
fn to_aml_bytes(&self) -> Vec<u8> { fn append_aml_bytes(&self, bytes: &mut Vec<u8>) {
let mut bytes = Vec::new();
// Add "MTFY" notification method // Add "MTFY" notification method
let mut memory_notifies = Vec::new(); let mut memory_notifies = Vec::new();
for slot_id in 0..self.slots { for slot_id in 0..self.slots {
@ -1880,13 +1875,10 @@ impl Aml for MemoryMethods {
memory_notifies_refs.push(memory_notifier); memory_notifies_refs.push(memory_notifier);
} }
bytes.extend_from_slice( aml::Method::new("MTFY".into(), 2, true, memory_notifies_refs).append_aml_bytes(bytes);
&aml::Method::new("MTFY".into(), 2, true, memory_notifies_refs).to_aml_bytes(),
);
// MSCN method // MSCN method
bytes.extend_from_slice( aml::Method::new(
&aml::Method::new(
"MSCN".into(), "MSCN".into(),
0, 0,
true, true,
@ -1909,10 +1901,7 @@ impl Aml for MemoryMethods {
vec![&aml::Local(0), &aml::ONE], vec![&aml::Local(0), &aml::ONE],
), ),
// Reset MINS bit // Reset MINS bit
&aml::Store::new( &aml::Store::new(&aml::Path::new("\\_SB_.MHPC.MINS"), &aml::ONE),
&aml::Path::new("\\_SB_.MHPC.MINS"),
&aml::ONE,
),
], ],
), ),
// Check if MRMV bit is set // Check if MRMV bit is set
@ -1920,15 +1909,9 @@ impl Aml for MemoryMethods {
&aml::Equal::new(&aml::Path::new("\\_SB_.MHPC.MRMV"), &aml::ONE), &aml::Equal::new(&aml::Path::new("\\_SB_.MHPC.MRMV"), &aml::ONE),
// Notify device if it is (with the eject constant 0x3) // Notify device if it is (with the eject constant 0x3)
vec![ vec![
&aml::MethodCall::new( &aml::MethodCall::new("MTFY".into(), vec![&aml::Local(0), &3u8]),
"MTFY".into(),
vec![&aml::Local(0), &3u8],
),
// Reset MRMV bit // Reset MRMV bit
&aml::Store::new( &aml::Store::new(&aml::Path::new("\\_SB_.MHPC.MRMV"), &aml::ONE),
&aml::Path::new("\\_SB_.MHPC.MRMV"),
&aml::ONE,
),
], ],
), ),
&aml::Add::new(&aml::Local(0), &aml::Local(0), &aml::ONE), &aml::Add::new(&aml::Local(0), &aml::Local(0), &aml::ONE),
@ -1938,12 +1921,10 @@ impl Aml for MemoryMethods {
&aml::Release::new("MLCK".into()), &aml::Release::new("MLCK".into()),
], ],
) )
.to_aml_bytes(), .append_aml_bytes(bytes);
);
bytes.extend_from_slice(
// Memory status method // Memory status method
&aml::Method::new( aml::Method::new(
"MSTA".into(), "MSTA".into(),
1, 1,
true, true,
@ -1964,12 +1945,10 @@ impl Aml for MemoryMethods {
&aml::Return::new(&aml::Local(0)), &aml::Return::new(&aml::Local(0)),
], ],
) )
.to_aml_bytes(), .append_aml_bytes(bytes);
);
bytes.extend_from_slice(
// Memory range method // Memory range method
&aml::Method::new( aml::Method::new(
"MCRS".into(), "MCRS".into(),
1, 1,
true, true,
@ -2015,30 +1994,21 @@ impl Aml for MemoryMethods {
&aml::Path::new("MAXH"), &aml::Path::new("MAXH"),
)], )],
), ),
&aml::Subtract::new( &aml::Subtract::new(&aml::Path::new("MAXL"), &aml::Path::new("MAXL"), &aml::ONE),
&aml::Path::new("MAXL"),
&aml::Path::new("MAXL"),
&aml::ONE,
),
// Release lock // Release lock
&aml::Release::new("MLCK".into()), &aml::Release::new("MLCK".into()),
&aml::Return::new(&aml::Path::new("MR64")), &aml::Return::new(&aml::Path::new("MR64")),
], ],
) )
.to_aml_bytes(), .append_aml_bytes(bytes)
);
bytes
} }
} }
#[cfg(feature = "acpi")] #[cfg(feature = "acpi")]
impl Aml for MemoryManager { impl Aml for MemoryManager {
fn to_aml_bytes(&self) -> Vec<u8> { fn append_aml_bytes(&self, bytes: &mut Vec<u8>) {
let mut bytes = Vec::new();
// Memory Hotplug Controller // Memory Hotplug Controller
bytes.extend_from_slice( aml::Device::new(
&aml::Device::new(
"_SB_.MHPC".into(), "_SB_.MHPC".into(),
vec![ vec![
&aml::Name::new("_HID".into(), &aml::EisaName::new("PNP0A06")), &aml::Name::new("_HID".into(), &aml::EisaName::new("PNP0A06")),
@ -2111,8 +2081,7 @@ impl Aml for MemoryManager {
}, },
], ],
) )
.to_aml_bytes(), .append_aml_bytes(bytes);
);
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
{ {
@ -2120,8 +2089,7 @@ impl Aml for MemoryManager {
let min = sgx_epc_region.start().raw_value() as u64; let min = sgx_epc_region.start().raw_value() as u64;
let max = min + sgx_epc_region.size() as u64 - 1; let max = min + sgx_epc_region.size() as u64 - 1;
// SGX EPC region // SGX EPC region
bytes.extend_from_slice( aml::Device::new(
&aml::Device::new(
"_SB_.EPC_".into(), "_SB_.EPC_".into(),
vec![ vec![
&aml::Name::new("_HID".into(), &aml::EisaName::new("INT0E0C")), &aml::Name::new("_HID".into(), &aml::EisaName::new("INT0E0C")),
@ -2135,20 +2103,12 @@ impl Aml for MemoryManager {
max, max,
)]), )]),
), ),
&aml::Method::new( &aml::Method::new("_STA".into(), 0, false, vec![&aml::Return::new(&0xfu8)]),
"_STA".into(),
0,
false,
vec![&aml::Return::new(&0xfu8)],
),
], ],
) )
.to_aml_bytes(), .append_aml_bytes(bytes);
);
} }
} }
bytes
} }
} }