Skip to content
Open
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
74 changes: 74 additions & 0 deletions src/aml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const BUFFEROP: u8 = 0x11;
const PACKAGEOP: u8 = 0x12;
const VARPACKAGEOP: u8 = 0x13;
const METHODOP: u8 = 0x14;
const DMADESC: u8 = 0x2A;
const DUALNAMEPREFIX: u8 = 0x2e;
const MULTINAMEPREFIX: u8 = 0x2f;
const NAMECHARBASE: u8 = 0x40;
Expand Down Expand Up @@ -759,6 +760,66 @@ impl Aml for Interrupt {
}
}

#[derive(Copy, Clone, Debug)]
pub enum DmaChannelSpeed {
Compatibility = 0b00,
TypeA = 0b01,
TypeB = 0b10,
TypeF = 0b11,
}

#[derive(Copy, Clone, Debug)]
pub enum DmaMasterStatus {
NotMaster = 0,
Master = 1,
}

#[derive(Copy, Clone, Debug)]
pub enum DmaTransferType {
Transfer8 = 0b00,
Transfer8_16 = 0b01,
Transfer16 = 0b10,
}

/// DMA resource object.
pub struct Dma {
channels: Vec<u8>,
speed: DmaChannelSpeed,
status: DmaMasterStatus,
transfer: DmaTransferType,
}

impl Dma {
pub fn new(
speed: DmaChannelSpeed,
status: DmaMasterStatus,
transfer: DmaTransferType,
channels: Vec<u8>,
) -> Self {
Self {
speed,
status,
transfer,
channels,
}
}
}

impl Aml for Dma {
fn to_aml_bytes(&self, sink: &mut dyn AmlSink) {
let channel_mask = self
.channels
.iter()
.fold(0, |mask, channel| mask | 1 << channel);

let config = (self.speed as u8) << 5 | (self.status as u8) << 2 | self.transfer as u8;

sink.byte(DMADESC); /* DMA Descriptor */
sink.byte(channel_mask);
sink.byte(config);
}
}

/// Register resource object
pub struct Register {
reg: gas::GAS,
Expand Down Expand Up @@ -2136,6 +2197,19 @@ mod tests {
assert_eq!(aml, [0x0d, b'A', b'C', b'P', b'I', 0]);
}

#[test]
fn test_dma() {
let mut aml = Vec::new();
Dma::new(
DmaChannelSpeed::TypeB,
DmaMasterStatus::Master,
DmaTransferType::Transfer16,
vec![0, 3, 7],
)
.to_aml_bytes(&mut aml);
assert_eq!(aml, [0x2a, 0b10001001, 0b0_10_00_1_10]);
}

#[test]
fn test_method() {
let mut aml = Vec::new();
Expand Down