diff --git a/kernel/src/drivers/bus/pci.rs b/kernel/src/drivers/bus/pci.rs index 766f27b..8761d34 100644 --- a/kernel/src/drivers/bus/pci.rs +++ b/kernel/src/drivers/bus/pci.rs @@ -251,3 +251,27 @@ pub fn init() { } } } + +pub fn find_device(vendor: u32, product: u32) -> Option { + 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 +} \ No newline at end of file diff --git a/kernel/src/syscall/custom.rs b/kernel/src/syscall/custom.rs new file mode 100644 index 0000000..bf10b22 --- /dev/null +++ b/kernel/src/syscall/custom.rs @@ -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) + } +} \ No newline at end of file diff --git a/kernel/src/syscall/mod.rs b/kernel/src/syscall/mod.rs index 43e4ba5..bad01f1 100644 --- a/kernel/src/syscall/mod.rs +++ b/kernel/src/syscall/mod.rs @@ -21,6 +21,7 @@ use self::proc::*; use self::time::*; use self::net::*; use self::misc::*; +use self::custom::*; mod fs; mod mem; @@ -28,6 +29,7 @@ mod proc; mod time; mod net; mod misc; +mod custom; /// System call dispatcher 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), 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 + // custom temporary syscall + 999 => sys_map_pci_device(args[0], args[1]), // 293 => sys_pipe(), // 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"); Ok(0) } + 038 => { + warn!("sys_setitimer is unimplemented"); + Ok(0) + } 072 => { warn!("sys_fcntl is unimplemented"); Ok(0)