Merge branch 'better_fmap' into 'master'

Better fmap

See merge request redox-os/drivers!108
This commit is contained in:
Jeremy Soller
2023-08-07 15:37:20 +00:00
5 changed files with 31 additions and 35 deletions
Generated
+1 -2
View File
@@ -1123,8 +1123,7 @@ dependencies = [
[[package]]
name = "redox_syscall"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29"
source = "git+https://gitlab.redox-os.org/redox-os/syscall.git#a525620c818a801bb7038e111b71033eff56a3ee"
dependencies = [
"bitflags 1.3.2",
]
+1
View File
@@ -39,3 +39,4 @@ lto = "fat"
mio = { git = "https://gitlab.redox-os.org/redox-os/mio.git", branch = "redox-unix" }
net2 = { git = "https://gitlab.redox-os.org/redox-os/net2-rs.git", branch = "master" }
orbclient = { git = "https://gitlab.redox-os.org/redox-os/orbclient.git", version = "0.3.44" }
redox_syscall = { git = "https://gitlab.redox-os.org/redox-os/syscall.git" }
+17 -9
View File
@@ -1,7 +1,8 @@
use std::collections::BTreeMap;
use std::{mem, ptr, slice, str};
use syscall::{Error, EventFlags, EBADF, EINVAL, ENOENT, Map, O_NONBLOCK, Result, SchemeMut, PAGE_SIZE};
use orbclient::{Event, EventOption};
use syscall::{Error, EventFlags, EACCES, EBADF, EINVAL, ENOENT, Map, O_NONBLOCK, Result, SchemeMut, PAGE_SIZE, Packet, KSMSG_MMAP_PREP, KSMSG_MMAP, MapFlags, ESKMSG, SKMSG_PROVIDE_MMAP};
use crate::{
display::Display,
@@ -213,6 +214,7 @@ impl SchemeMut for DisplayScheme {
}
}
/*
fn fmap(&mut self, id: usize, map: &Map) -> Result<usize> {
let handle = self.handles.get(&id).ok_or(Error::new(EBADF))?;
@@ -226,14 +228,7 @@ impl SchemeMut for DisplayScheme {
Err(Error::new(EBADF))
}
fn fmap_old(&mut self, id: usize, map: &syscall::OldMap) -> syscall::Result<usize> {
self.fmap(id, &Map {
offset: map.offset,
size: map.size,
flags: map.flags,
address: 0,
})
}
*/
fn fpath(&mut self, id: usize, buf: &mut [u8]) -> Result<usize> {
let handle = self.handles.get(&id).ok_or(Error::new(EBADF))?;
@@ -382,4 +377,17 @@ impl SchemeMut for DisplayScheme {
self.handles.remove(&id).ok_or(Error::new(EBADF))?;
Ok(0)
}
fn mmap_prep(&mut self, id: usize, off: u64, size: usize, _flags: MapFlags) -> Result<usize> {
let handle = self.handles.get(&id).ok_or(Error::new(EBADF))?;
if let HandleKind::Screen(vt_i, screen_i) = handle.kind {
if let Some(screens) = self.vts.get(&vt_i) {
if let Some(screen) = screens.get(&screen_i) {
return screen.map(off as usize, size);
}
}
}
Err(Error::new(EBADF))
}
}
+1 -1
View File
@@ -453,7 +453,7 @@ fn deamon(deamon: redox_daemon::Daemon) -> anyhow::Result<()> {
socket_file
.read(&mut packet)
.expect("virtio-gpud: failed to read disk scheme");
scheme.handle(&mut packet);
unsafe { scheme.handle(&mut packet); }
socket_file
.write(&packet)
.expect("virtio-gpud: failed to read disk scheme");
+11 -23
View File
@@ -4,9 +4,9 @@ use std::sync::atomic::{AtomicBool, AtomicU32, AtomicUsize, Ordering};
use std::sync::Arc;
use inputd::Damage;
use common::dma::Dma;
use syscall::{Error as SysError, SchemeMut, EAGAIN, EINVAL};
use syscall::{Error as SysError, SchemeMut, EAGAIN, EINVAL, MapFlags, PAGE_SIZE, KSMSG_MMAP, KSMSG_MMAP_PREP, KSMSG_MSYNC, KSMSG_MUNMAP};
use virtio_core::spec::{Buffer, ChainBuilder, DescriptorFlags};
use virtio_core::transport::{Error, Queue, StandardTransport};
@@ -368,27 +368,6 @@ impl<'a> SchemeMut for Scheme<'a> {
}
}
fn fmap_old(&mut self, id: usize, map: &syscall::OldMap) -> syscall::Result<usize> {
self.fmap(
id,
&syscall::Map {
offset: map.offset,
size: map.size,
flags: map.flags,
address: 0,
},
)
}
fn fmap(&mut self, id: usize, map: &syscall::Map) -> syscall::Result<usize> {
match self.handles.get(&id).ok_or(SysError::new(EINVAL))? {
Handle::Vt { display, .. } => {
Ok(futures::executor::block_on(display.map_screen(map.offset)).unwrap())
}
_ => unreachable!(),
}
}
fn fsync(&mut self, id: usize) -> syscall::Result<usize> {
match self.handles.get(&id).ok_or(SysError::new(EINVAL))? {
Handle::Vt { display, .. } => {
@@ -484,4 +463,13 @@ impl<'a> SchemeMut for Scheme<'a> {
fn close(&mut self, _id: usize) -> syscall::Result<usize> {
Ok(0)
}
fn mmap_prep(&mut self, id: usize, offset: u64, size: usize, flags: MapFlags) -> syscall::Result<usize> {
log::info!("KSMSG MMAP {} {:?} {} {}", id, flags, offset, size);
match self.handles.get(&id).ok_or(SysError::new(EINVAL))? {
Handle::Vt { display, .. } => {
Ok(futures::executor::block_on(display.map_screen(offset as usize)).unwrap())
}
_ => unreachable!(),
}
}
}