Implement sys_map_pci_device call for mapping BAR into user space

master
Jiajie Chen 6 years ago
parent 8860f1e4a3
commit e7657356a2

@ -251,3 +251,27 @@ pub fn init() {
} }
} }
} }
pub fn find_device(vendor: u32, product: u32) -> Option<PciTag> {
for bus in 0..256 {
for dev in 0..32 {
let tag = PciTag::new(bus, dev, 0);
if let Some((vid, did, next)) = tag.probe() {
if vid == vendor && did == product {
return Some(tag);
}
if next {
for func in 1..8 {
let tag = PciTag::new(bus, dev, func);
if let Some((vid, did, _)) = tag.probe() {
if vid == vendor && did == product {
return Some(tag);
}
}
}
}
}
}
}
None
}

@ -0,0 +1,32 @@
//! Custom nonstandard syscalls
use rcore_memory::memory_set::handler::Linear;
use rcore_memory::memory_set::MemoryAttr;
use super::*;
use crate::drivers::bus::pci;
pub fn sys_map_pci_device(vendor: usize, product: usize) -> SysResult {
info!(
"map_pci_device: vendor: {}, product: {}",
vendor, product
);
if let Some(tag) = pci::find_device(vendor as u32, product as u32) {
// Get BAR0 memory
if let Some((base, len)) = unsafe { tag.get_bar_mem(0) } {
let mut proc = process();
let virt_addr = proc.memory_set.find_free_area(0, len);
let attr = MemoryAttr::default().user();
proc.memory_set.push(
virt_addr,
virt_addr + len,
attr,
Linear::new(base as isize - virt_addr as isize),
"pci",
);
Ok(virt_addr)
} else {
Err(SysError::ENOENT)
}
} else {
Err(SysError::ENOENT)
}
}

@ -21,6 +21,7 @@ use self::proc::*;
use self::time::*; use self::time::*;
use self::net::*; use self::net::*;
use self::misc::*; use self::misc::*;
use self::custom::*;
mod fs; mod fs;
mod mem; mod mem;
@ -28,6 +29,7 @@ mod proc;
mod time; mod time;
mod net; mod net;
mod misc; mod misc;
mod custom;
/// System call dispatcher /// System call dispatcher
pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize { pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize {
@ -124,6 +126,8 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize {
228 => sys_clock_gettime(args[0], args[1] as *mut TimeSpec), 228 => sys_clock_gettime(args[0], args[1] as *mut TimeSpec),
231 => sys_exit_group(args[0]), 231 => sys_exit_group(args[0]),
288 => sys_accept(args[0], args[1] as *mut SockAddr, args[2] as *mut u32), // use accept for accept4 288 => sys_accept(args[0], args[1] as *mut SockAddr, args[2] as *mut u32), // use accept for accept4
// custom temporary syscall
999 => sys_map_pci_device(args[0], args[1]),
// 293 => sys_pipe(), // 293 => sys_pipe(),
// for musl: empty impl // for musl: empty impl
@ -151,6 +155,10 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize {
warn!("sys_alarm is unimplemented"); warn!("sys_alarm is unimplemented");
Ok(0) Ok(0)
} }
038 => {
warn!("sys_setitimer is unimplemented");
Ok(0)
}
072 => { 072 => {
warn!("sys_fcntl is unimplemented"); warn!("sys_fcntl is unimplemented");
Ok(0) Ok(0)

Loading…
Cancel
Save