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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ log = "0.4.20"
spinning_top = "0.3.0"
pci_types = { version = "0.10.0", public = true }
byteorder = { version = "1.5.0", default-features = false }
smallvec = { version = "1.15.2", default-features = false }

[dev-dependencies]
aml_test_tools = { path = "tools/aml_test_tools" }
Expand Down
4 changes: 2 additions & 2 deletions src/aml/pci_routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::aml::{
Operation,
namespace::AmlName,
object::Object,
resource::{self, InterruptPolarity, InterruptTrigger, Resource},
resource::{self, InterruptPolarity, InterruptTrigger, Irqs, Resource},
};
use alloc::{vec, vec::Vec};
use bit_field::BitField;
Expand Down Expand Up @@ -191,7 +191,7 @@ impl PciRoutingTable {
polarity: InterruptPolarity::ActiveLow,
is_shared: true,
is_wake_capable: false,
irq: gsi,
irqs: Irqs::from_buf([gsi]),
}),
PciRouteType::LinkObject(ref name) => {
let path = AmlName::from_str("_CRS").unwrap().resolve(name)?;
Expand Down
49 changes: 37 additions & 12 deletions src/aml/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use alloc::vec::Vec;
use bit_field::BitField;
use byteorder::{ByteOrder, LittleEndian};
use core::mem;
pub use smallvec;

#[derive(Debug, PartialEq, Eq)]
pub enum Resource {
Expand Down Expand Up @@ -339,18 +340,16 @@ fn address_space_descriptor<T>(bytes: &[u8]) -> Result<Resource, AmlError> {
}))
}

pub type Irqs = smallvec::SmallVec<[u32; 1]>;

#[derive(Debug, PartialEq, Eq, Clone)]
pub struct IrqDescriptor {
pub is_consumer: bool,
pub trigger: InterruptTrigger,
pub polarity: InterruptPolarity,
pub is_shared: bool,
pub is_wake_capable: bool,
/*
* NOTE: We currently only support the cases where a descriptor only contains a single interrupt
* number.
*/
pub irq: u32,
pub irqs: Irqs,
}

fn irq_format_descriptor(bytes: &[u8]) -> Result<Resource, AmlError> {
Expand Down Expand Up @@ -386,6 +385,15 @@ fn irq_format_descriptor(bytes: &[u8]) -> Result<Resource, AmlError> {
* 0 Level-Triggered – Interrupt is triggered in response to signal in a low state.
* 1 Edge-Triggered – Interrupt is triggered in response to a change in signal state from low to high.
*/
fn irqs_from_bit_mask(bit_mask: u16) -> Irqs {
let mut irqs = Irqs::default();
for bit in 0..16 {
if bit_mask.get_bit(bit) {
irqs.push(bit as u32);
}
}
irqs
}

match bytes.len() {
0..=2 => Err(AmlError::InvalidResourceDescriptor),
Expand All @@ -394,7 +402,7 @@ fn irq_format_descriptor(bytes: &[u8]) -> Result<Resource, AmlError> {
let irq = LittleEndian::read_u16(&bytes[1..=2]);

Ok(Resource::Irq(IrqDescriptor {
irq: irq as u32,
irqs: irqs_from_bit_mask(irq),
is_wake_capable: false,
is_shared: false,
polarity: InterruptPolarity::ActiveHigh,
Expand All @@ -420,7 +428,7 @@ fn irq_format_descriptor(bytes: &[u8]) -> Result<Resource, AmlError> {
};

Ok(Resource::Irq(IrqDescriptor {
irq: irq as u32,
irqs: irqs_from_bit_mask(irq),
is_wake_capable,
is_shared,
polarity,
Expand Down Expand Up @@ -568,16 +576,33 @@ fn extended_interrupt_descriptor(bytes: &[u8]) -> Result<Resource, AmlError> {
}

let number_of_interrupts = bytes[4] as usize;
assert_eq!(number_of_interrupts, 1);
let irq = LittleEndian::read_u32(&[bytes[5], bytes[6], bytes[7], bytes[8]]);

let irqs = if number_of_interrupts == 1 {
let irq = LittleEndian::read_u32(&bytes[5..9]);

Irqs::from_buf([irq])
} else {
let mut irqs = Irqs::with_capacity(number_of_interrupts);

for i in 0..number_of_interrupts {
let start = 5 + i * size_of::<u32>();
let end = start + 4;

let irq = LittleEndian::read_u32(&bytes[start..end]);

irqs.push(irq);
}

irqs
};

Ok(Resource::Irq(IrqDescriptor {
is_consumer: bytes[3].get_bit(0),
trigger: if bytes[3].get_bit(1) { InterruptTrigger::Edge } else { InterruptTrigger::Level },
polarity: if bytes[3].get_bit(2) { InterruptPolarity::ActiveLow } else { InterruptPolarity::ActiveHigh },
is_shared: bytes[3].get_bit(3),
is_wake_capable: bytes[3].get_bit(4),
irq,
irqs,
}))
}

Expand Down Expand Up @@ -641,7 +666,7 @@ mod tests {
polarity: InterruptPolarity::ActiveHigh,
is_shared: false,
is_wake_capable: false,
irq: (1 << 1)
irqs: Irqs::from_buf([1 << 1])
})
])
);
Expand Down Expand Up @@ -898,7 +923,7 @@ mod tests {
polarity: InterruptPolarity::ActiveHigh,
is_shared: false,
is_wake_capable: false,
irq: (1 << 6)
irqs: Irqs::from_buf([1 << 6])
}),
Resource::Dma(DMADescriptor {
channel_mask: 1 << 2,
Expand Down
7 changes: 4 additions & 3 deletions tests/package_name_references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use acpi::aml::{
namespace::AmlName,
object::Object,
pci_routing::{PciRoutingTable, Pin},
resource::Irqs,
};
use aml_test_tools::handlers::null_handler::NullHandler;
use std::str::FromStr;
Expand Down Expand Up @@ -154,9 +155,9 @@ DefinitionBlock("", "DSDT", 2, "RSACPI", "PRTTST", 1) {

// An absolute name, a relative name found by the namespace search rules, and a GSI.
// The IRQ of a link object is decoded from its `_CRS` as a mask.
assert_eq!(table.route(1, 0, Pin::IntA, &interpreter).unwrap().irq, 1 << 11);
assert_eq!(table.route(2, 0, Pin::IntB, &interpreter).unwrap().irq, 1 << 10);
assert_eq!(table.route(3, 0, Pin::IntC, &interpreter).unwrap().irq, 19);
assert_eq!(table.route(1, 0, Pin::IntA, &interpreter).unwrap().irqs, Irqs::from_buf([1 << 11]));
assert_eq!(table.route(2, 0, Pin::IntB, &interpreter).unwrap().irqs, Irqs::from_buf([1 << 10]));
assert_eq!(table.route(3, 0, Pin::IntC, &interpreter).unwrap().irqs, Irqs::from_buf([19]));
}

/// `DerefOf` of a string is a namespace lookup, and must not recurse into the object it finds -
Expand Down