From 4544f9039a513e02d233209ba025d16ebbdf5273 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 8 Oct 2016 20:36:21 -0600 Subject: [PATCH] Enable bus mastering --- drivers/pcid/src/main.rs | 6 ++++++ drivers/pcid/src/pci/mod.rs | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/drivers/pcid/src/main.rs b/drivers/pcid/src/main.rs index a34ff17..108e830 100644 --- a/drivers/pcid/src/main.rs +++ b/drivers/pcid/src/main.rs @@ -108,6 +108,12 @@ fn main() { } if let Some(ref args) = driver.command { + // Enable bus mastering + unsafe { + let cmd = pci.read(bus.num, dev.num, func.num, 0x04); + pci.write(bus.num, dev.num, func.num, 0x04, cmd | 4); + } + let mut args = args.iter(); if let Some(program) = args.next() { let mut command = Command::new(program); diff --git a/drivers/pcid/src/pci/mod.rs b/drivers/pcid/src/pci/mod.rs index 0d760ef..d2a8e89 100644 --- a/drivers/pcid/src/pci/mod.rs +++ b/drivers/pcid/src/pci/mod.rs @@ -34,6 +34,17 @@ impl Pci { : "={eax}"(value) : "{eax}"(address) : "dx" : "intel", "volatile"); value } + + #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] + pub unsafe fn write(&self, bus: u8, dev: u8, func: u8, offset: u8, value: u32) { + let address = 0x80000000 | ((bus as u32) << 16) | ((dev as u32) << 11) | ((func as u32) << 8) | ((offset as u32) & 0xFC); + asm!("mov dx, 0xCF8 + out dx, eax" + : : "{eax}"(address) : "dx" : "intel", "volatile"); + asm!("mov dx, 0xCFC + out dx, eax" + : : "{eax}"(value) : "dx" : "intel", "volatile"); + } } pub struct PciIter<'pci> {