Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,14 @@ jobs:
profile: minimal
components: clippy

- name: Run clippy
- name: Run clippy (ACPI)
run: cargo clippy -p acpi

- name: Run clippy (ACPI tests)
run: cargo clippy -p acpi --tests

- name: Run clippy (AML)
run: cargo clippy -p aml

- name: Run clippy (AML tests)
run: cargo clippy -p aml --tests
12 changes: 6 additions & 6 deletions aml/src/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ where
}

let mut buffer = vec![0; buffer_size];
(&mut buffer[0..bytes.len()]).copy_from_slice(bytes);
buffer[0..bytes.len()].copy_from_slice(bytes);
(Ok(buffer), context)
})
}),
Expand Down Expand Up @@ -564,16 +564,16 @@ where
context,
match source {
AmlValue::Buffer(bytes) => {
let foo = bytes.lock();
if index >= foo.len() {
let guard = bytes.lock();
if index >= guard.len() {
Ok(AmlValue::Buffer(Arc::new(spinning_top::Spinlock::new(vec![]))))
} else if (index + length) >= foo.len() {
} else if (index + length) >= guard.len() {
Ok(AmlValue::Buffer(Arc::new(spinning_top::Spinlock::new(
foo[index..].to_vec(),
guard[index..].to_vec(),
))))
} else {
Ok(AmlValue::Buffer(Arc::new(spinning_top::Spinlock::new(
foo[index..(index + length)].to_vec(),
guard[index..(index + length)].to_vec(),
))))
}
}
Expand Down
102 changes: 53 additions & 49 deletions aml/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ use alloc::{
format,
string::{String, ToString},
};
use core::mem;
use core::{mem, str::FromStr};
use log::{error, warn};
use misc::{ArgNum, LocalNum};
use name_object::Target;
Expand Down Expand Up @@ -171,7 +171,7 @@ impl AmlContext {
format!("buf {:X?}", abbreviated)
}

if stream.len() == 0 {
if stream.is_empty() {
return Err(AmlError::UnexpectedEndOfStream);
}

Expand Down Expand Up @@ -287,7 +287,7 @@ impl AmlContext {
self.namespace.clone().traverse(|path, level: &NamespaceLevel| match level.typ {
LevelType::Device => {
let status = if level.values.contains_key(&NameSeg::from_str("_STA").unwrap()) {
self.invoke_method(&AmlName::from_str("_STA").unwrap().resolve(&path)?, Args::default())?
self.invoke_method(&AmlName::from_str("_STA").unwrap().resolve(path)?, Args::default())?
.as_status()?
} else {
StatusObject::default()
Expand All @@ -298,7 +298,7 @@ impl AmlContext {
*/
if status.present && level.values.contains_key(&NameSeg::from_str("_INI").unwrap()) {
log::info!("Invoking _INI at level: {}", path);
self.invoke_method(&AmlName::from_str("_INI").unwrap().resolve(&path)?, Args::default())?;
self.invoke_method(&AmlName::from_str("_INI").unwrap().resolve(path)?, Args::default())?;
}

/*
Expand Down Expand Up @@ -339,7 +339,7 @@ impl AmlContext {

/// Get the current value of a local by its local number. Can only be executed from inside a control method.
pub(crate) fn local(&self, local: LocalNum) -> Result<&AmlValue, AmlError> {
if let None = self.method_context {
if self.method_context.is_none() {
return Err(AmlError::NotExecutingControlMethod);
}
if local > 7 {
Expand Down Expand Up @@ -384,7 +384,7 @@ impl AmlContext {
}

Target::Arg(arg_num) => {
if let None = self.method_context {
if self.method_context.is_none() {
return Err(AmlError::NotExecutingControlMethod);
}

Expand All @@ -399,7 +399,7 @@ impl AmlContext {
}

Target::Local(local_num) => {
if let None = self.method_context {
if self.method_context.is_none() {
return Err(AmlError::NotExecutingControlMethod);
}

Expand Down Expand Up @@ -454,49 +454,53 @@ impl AmlContext {
AmlName::from_str("\\_OSI").unwrap(),
AmlValue::native_method(1, false, 0, |context| {
let value = context.current_arg(0)?.clone();
Ok(match value.as_string(context)?.as_str() {
"Windows 2000" => true, // 2000
"Windows 2001" => true, // XP
"Windows 2001 SP1" => true, // XP SP1
"Windows 2001 SP2" => true, // XP SP2
"Windows 2001.1" => true, // Server 2003
"Windows 2001.1 SP1" => true, // Server 2003 SP1
"Windows 2006" => true, // Vista
"Windows 2006 SP1" => true, // Vista SP1
"Windows 2006 SP2" => true, // Vista SP2
"Windows 2006.1" => true, // Server 2008
"Windows 2009" => true, // 7 and Server 2008 R2
"Windows 2012" => true, // 8 and Server 2012
"Windows 2013" => true, // 8.1 and Server 2012 R2
"Windows 2015" => true, // 10
"Windows 2016" => true, // 10 version 1607
"Windows 2017" => true, // 10 version 1703
"Windows 2017.2" => true, // 10 version 1709
"Windows 2018" => true, // 10 version 1803
"Windows 2018.2" => true, // 10 version 1809
"Windows 2019" => true, // 10 version 1903

"Darwin" => true,

"Linux" => {
// TODO: should we allow users to specify that this should be true? Linux has a
// command line option for this.
warn!("ACPI evaluated `_OSI(\"Linux\")`. This is a bug. Reporting no support.");
false
}

"Extended Address Space Descriptor" => true,
// TODO: support module devices
"Module Device" => false,
"3.0 Thermal Model" => true,
"3.0 _SCP Extensions" => true,
// TODO: support processor aggregator devices
"Processor Aggregator Device" => false,
Ok(
if match value.as_string(context)?.as_str() {
"Windows 2000" => true, // 2000
"Windows 2001" => true, // XP
"Windows 2001 SP1" => true, // XP SP1
"Windows 2001 SP2" => true, // XP SP2
"Windows 2001.1" => true, // Server 2003
"Windows 2001.1 SP1" => true, // Server 2003 SP1
"Windows 2006" => true, // Vista
"Windows 2006 SP1" => true, // Vista SP1
"Windows 2006 SP2" => true, // Vista SP2
"Windows 2006.1" => true, // Server 2008
"Windows 2009" => true, // 7 and Server 2008 R2
"Windows 2012" => true, // 8 and Server 2012
"Windows 2013" => true, // 8.1 and Server 2012 R2
"Windows 2015" => true, // 10
"Windows 2016" => true, // 10 version 1607
"Windows 2017" => true, // 10 version 1703
"Windows 2017.2" => true, // 10 version 1709
"Windows 2018" => true, // 10 version 1803
"Windows 2018.2" => true, // 10 version 1809
"Windows 2019" => true, // 10 version 1903

"Darwin" => true,

"Linux" => {
// TODO: should we allow users to specify that this should be true? Linux has a
// command line option for this.
warn!("ACPI evaluated `_OSI(\"Linux\")`. This is a bug. Reporting no support.");
false
}

_ => false,
}
.then_some(AmlValue::ones())
.unwrap_or(AmlValue::zero()))
"Extended Address Space Descriptor" => true,
// TODO: support module devices
"Module Device" => false,
"3.0 Thermal Model" => true,
"3.0 _SCP Extensions" => true,
// TODO: support processor aggregator devices
"Processor Aggregator Device" => false,

_ => false,
} {
AmlValue::ones()
} else {
AmlValue::zero()
},
)
}),
)
.unwrap();
Expand Down
19 changes: 8 additions & 11 deletions aml/src/name_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ where
PREFIX_CHAR => prefix_path.parse(input, context),
_ => name_path()
.map(|path| {
if path.len() == 0 {
if path.is_empty() {
return Err(Propagate::Err(AmlError::EmptyNamesAreInvalid));
}

Expand Down Expand Up @@ -175,7 +175,7 @@ pub struct NameSeg(pub(crate) [u8; 4]);
impl NameSeg {
pub(crate) fn from_str(string: &str) -> Result<NameSeg, AmlError> {
// Each NameSeg can only have four chars, and must have at least one
if string.len() < 1 || string.len() > 4 {
if string.is_empty() || string.len() > 4 {
return Err(AmlError::InvalidNameSeg);
}

Expand Down Expand Up @@ -234,28 +234,25 @@ where
}

fn is_lead_name_char(byte: u8) -> bool {
(byte >= b'A' && byte <= b'Z') || byte == b'_'
}

fn is_digit_char(byte: u8) -> bool {
byte >= b'0' && byte <= b'9'
byte.is_ascii_uppercase() || byte == b'_'
}

fn is_name_char(byte: u8) -> bool {
is_lead_name_char(byte) || is_digit_char(byte)
is_lead_name_char(byte) || byte.is_ascii_digit()
}

#[cfg(test)]
mod tests {
use super::*;
use crate::{parser::Parser, test_utils::*, AmlError};
use core::str::FromStr;

#[test]
fn test_name_seg() {
let mut context = crate::test_utils::make_test_context();

check_ok!(
name_seg().parse(&[b'A', b'F', b'3', b'Z'], &mut context),
name_seg().parse(b"AF3Z", &mut context),
NameSeg([b'A', b'F', b'3', b'Z']),
&[]
);
Expand Down Expand Up @@ -295,12 +292,12 @@ mod tests {
let mut context = crate::test_utils::make_test_context();

check_ok!(
name_string().parse(&[b'^', b'A', b'B', b'C', b'D'], &mut context),
name_string().parse(b"^ABCD", &mut context),
AmlName::from_str("^ABCD").unwrap(),
&[]
);
check_ok!(
name_string().parse(&[b'^', b'^', b'^', b'A', b'B', b'C', b'D'], &mut context),
name_string().parse(b"^^^ABCD", &mut context),
AmlName::from_str("^^^ABCD").unwrap(),
&[]
);
Expand Down
Loading
Loading