1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-27 02:03:29 +04:00
rCore/kernel/src/syscall/custom.rs

54 lines
1.6 KiB
Rust
Raw Normal View History

//! Custom nonstandard syscalls
2019-03-27 14:35:08 +04:00
use super::*;
use rcore_memory::memory_set::handler::Linear;
use rcore_memory::memory_set::MemoryAttr;
/// Allocate this PCI device to user space
/// The kernel driver using the PCI device will be unloaded
2019-03-16 07:40:05 +04:00
#[cfg(target_arch = "x86_64")]
pub fn sys_map_pci_device(vendor: usize, product: usize) -> SysResult {
2019-03-16 07:40:05 +04:00
use crate::drivers::bus::pci;
info!(
"map_pci_device: vendor: {:x}, product: {:x}",
vendor, product
);
2019-03-30 19:43:20 +04:00
let tag = pci::find_device(vendor as u16, product as u16).ok_or(SysError::ENOENT)?;
if pci::detach_driver(&tag) {
info!("Kernel driver detached");
}
2019-03-16 07:40:05 +04:00
// Get BAR0 memory
2019-03-30 19:43:20 +04:00
let (base, len) = pci::get_bar0_mem(tag).ok_or(SysError::ENOENT)?;
2019-03-16 07:40:05 +04:00
let mut proc = process();
2019-03-22 19:45:57 +04:00
let virt_addr = proc.vm.find_free_area(0, len);
2019-03-16 07:40:05 +04:00
let attr = MemoryAttr::default().user();
2019-03-22 19:45:57 +04:00
proc.vm.push(
2019-03-16 07:40:05 +04:00
virt_addr,
virt_addr + len,
attr,
Linear::new(base as isize - virt_addr as isize),
"pci",
);
Ok(virt_addr)
}
#[cfg(not(target_arch = "x86_64"))]
pub fn sys_map_pci_device(vendor: usize, product: usize) -> SysResult {
Err(SysError::ENOSYS)
}
2019-03-16 17:24:41 +04:00
/// Get start physical addresses of frames
/// mapped to a list of virtual addresses.
pub fn sys_get_paddr(vaddrs: *const u64, paddrs: *mut u64, count: usize) -> SysResult {
let mut proc = process();
2019-04-28 11:55:45 +04:00
let vaddrs = unsafe { proc.vm.check_read_array(vaddrs, count)? };
let paddrs = unsafe { proc.vm.check_write_array(paddrs, count)? };
2019-03-16 17:24:41 +04:00
for i in 0..count {
2019-03-22 19:45:57 +04:00
let paddr = proc.vm.translate(vaddrs[i] as usize).unwrap_or(0);
2019-03-16 17:24:41 +04:00
paddrs[i] = paddr as u64;
}
Ok(0)
}