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