devices: implement Aml trait for GED device

Fixes: #657

Signed-off-by: Qiu Wenbo <qiuwenbo@phytium.com.cn>
This commit is contained in:
Qiu Wenbo 2020-02-25 15:20:59 +08:00 committed by Rob Bradford
parent b77fdeba2d
commit 9de3ace8c7
5 changed files with 62 additions and 52 deletions

1
Cargo.lock generated
View File

@ -223,6 +223,7 @@ dependencies = [
name = "devices"
version = "0.1.0"
dependencies = [
"acpi_tables 0.1.0",
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"epoll 4.1.0 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -10,6 +10,7 @@ epoll = ">=4.0.1"
libc = "0.2.67"
log = "0.4.8"
vm-device = { path = "../vm-device" }
acpi_tables = { path = "../acpi_tables", optional = true }
vm-memory = { git = "https://github.com/rust-vmm/vm-memory" }
vmm-sys-util = ">=0.3.1"
@ -18,5 +19,5 @@ tempfile = "3.1.0"
[features]
default = []
acpi = []
acpi = ["acpi_tables"]
cmos = []

View File

@ -3,6 +3,7 @@
// SPDX-License-Identifier: Apache-2.0
//
use acpi_tables::{aml, aml::Aml};
use std::sync::Arc;
use vm_device::interrupt::InterruptSourceGroup;
use vmm_sys_util::eventfd::EventFd;
@ -94,3 +95,52 @@ impl BusDevice for AcpiGEDDevice {
fn write(&mut self, _base: u64, _offset: u64, _data: &[u8]) {}
}
#[cfg(feature = "acpi")]
impl Aml for AcpiGEDDevice {
fn to_aml_bytes(&self) -> Vec<u8> {
aml::Device::new(
"_SB_.GED_".into(),
vec![
&aml::Name::new("_HID".into(), &"ACPI0013"),
&aml::Name::new("_UID".into(), &aml::ZERO),
&aml::Name::new(
"_CRS".into(),
&aml::ResourceTemplate::new(vec![&aml::Interrupt::new(
true,
true,
false,
false,
self.ged_irq,
)]),
),
&aml::OpRegion::new("GDST".into(), aml::OpRegionSpace::SystemIO, 0xb000, 0x1),
&aml::Field::new(
"GDST".into(),
aml::FieldAccessType::Byte,
aml::FieldUpdateRule::WriteAsZeroes,
vec![aml::FieldEntry::Named(*b"GDAT", 8)],
),
&aml::Method::new(
"_EVT".into(),
1,
true,
vec![
&aml::Store::new(&aml::Local(0), &aml::Path::new("GDAT")),
&aml::And::new(&aml::Local(1), &aml::Local(0), &aml::ONE),
&aml::If::new(
&aml::Equal::new(&aml::Local(1), &aml::ONE),
vec![&aml::MethodCall::new("\\_SB_.CPUS.CSCN".into(), vec![])],
),
&aml::And::new(&aml::Local(1), &aml::Local(0), &2usize),
&aml::If::new(
&aml::Equal::new(&aml::Local(1), &2usize),
vec![&aml::MethodCall::new("\\_SB_.MHPC.MSCN".into(), vec![])],
),
],
),
],
)
.to_aml_bytes()
}
}

View File

@ -13,6 +13,8 @@ extern crate epoll;
extern crate libc;
#[macro_use]
extern crate log;
#[cfg(feature = "acpi")]
extern crate acpi_tables;
extern crate vm_device;
extern crate vm_memory;
extern crate vmm_sys_util;

View File

@ -1567,49 +1567,6 @@ impl DeviceManager {
}
}
#[cfg(feature = "acpi")]
fn create_ged_device(ged_irq: u32) -> Vec<u8> {
aml::Device::new(
"_SB_.GED_".into(),
vec![
&aml::Name::new("_HID".into(), &"ACPI0013"),
&aml::Name::new("_UID".into(), &aml::ZERO),
&aml::Name::new(
"_CRS".into(),
&aml::ResourceTemplate::new(vec![&aml::Interrupt::new(
true, true, false, false, ged_irq,
)]),
),
&aml::OpRegion::new("GDST".into(), aml::OpRegionSpace::SystemIO, 0xb000, 0x1),
&aml::Field::new(
"GDST".into(),
aml::FieldAccessType::Byte,
aml::FieldUpdateRule::WriteAsZeroes,
vec![aml::FieldEntry::Named(*b"GDAT", 8)],
),
&aml::Method::new(
"_EVT".into(),
1,
true,
vec![
&aml::Store::new(&aml::Local(0), &aml::Path::new("GDAT")),
&aml::And::new(&aml::Local(1), &aml::Local(0), &aml::ONE),
&aml::If::new(
&aml::Equal::new(&aml::Local(1), &aml::ONE),
vec![&aml::MethodCall::new("\\_SB_.CPUS.CSCN".into(), vec![])],
),
&aml::And::new(&aml::Local(1), &aml::Local(0), &2usize),
&aml::If::new(
&aml::Equal::new(&aml::Local(1), &2usize),
vec![&aml::MethodCall::new("\\_SB_.MHPC.MSCN".into(), vec![])],
),
],
),
],
)
.to_aml_bytes()
}
#[cfg(feature = "acpi")]
impl Aml for DeviceManager {
fn to_aml_bytes(&self) -> Vec<u8> {
@ -1687,14 +1644,13 @@ impl Aml for DeviceManager {
let s5_sleep_data =
aml::Name::new("_S5_".into(), &aml::Package::new(vec![&5u8])).to_aml_bytes();
let ged_data = create_ged_device(
self.ged_notification_device
.as_ref()
.unwrap()
.lock()
.unwrap()
.irq(),
);
let ged_data = self
.ged_notification_device
.as_ref()
.unwrap()
.lock()
.unwrap()
.to_aml_bytes();
bytes.extend_from_slice(pci_dsdt_data.as_slice());
bytes.extend_from_slice(mbrd_dsdt_data.as_slice());