Skip to content

Commit

Permalink
Merge pull request #384 from roblabla/futures
Browse files Browse the repository at this point in the history
IPC Server based on future executor
  • Loading branch information
roblabla authored Aug 16, 2019
2 parents 6cb25e0 + 269527c commit f6c2111
Show file tree
Hide file tree
Showing 31 changed files with 1,669 additions and 425 deletions.
98 changes: 98 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ahci/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ sunrise-libutils = { path = "../libutils" }
spin = "0.5"
log = "0.4.6"
bitfield = "0.13.1"
futures-preview = { version = "0.3.0-alpha.16", default-features = false, features = ["nightly", "alloc"] }

[dependencies.lazy_static]
features = ["spin_no_std"]
Expand Down
8 changes: 4 additions & 4 deletions ahci/src/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use sunrise_libuser::error::{Error, AhciError};
use sunrise_libuser::types::SharedMemory;
use sunrise_libuser::syscalls::MemoryPermissions;
use sunrise_libuser::ahci::IDisk as IDiskInterface;
use sunrise_libuser::ipc::server::WaitableManager;
use sunrise_libuser::futures::WorkQueue;
use sunrise_libuser::zero_box::ZeroBox;

use crate::hba::*;
Expand Down Expand Up @@ -167,7 +167,7 @@ impl IDisk {

impl IDiskInterface for IDisk {
/// Returns the number of addressable 512-octet sectors for this disk.
fn sector_count(&mut self, _manager: &WaitableManager) -> Result<u64, Error> {
fn sector_count(&mut self, _work_queue: WorkQueue<'static>) -> Result<u64, Error> {
Ok(self.0.lock().sectors)
}

Expand All @@ -186,7 +186,7 @@ impl IDiskInterface for IDisk {
/// - The passed handle points to memory that is so physically scattered it overflows
/// the PRDT. This can only happen for read/writes of 1985 sectors or more.
/// You should consider retrying with a smaller `sector_count`.
fn read_dma(&mut self, _manager: &WaitableManager, sharedmem: SharedMemory, mapping_size: u64, lba: u64, sector_count: u64) -> Result<(), Error> {
fn read_dma(&mut self, _manager: WorkQueue<'static>, sharedmem: SharedMemory, mapping_size: u64, lba: u64, sector_count: u64) -> Result<(), Error> {
let addr = sunrise_libuser::mem::find_free_address(mapping_size as _, 0x1000)?;
let mapped = sharedmem.map(addr, mapping_size as _, MemoryPermissions::empty())
// no need for permission, only the disk will dma to it.
Expand All @@ -209,7 +209,7 @@ impl IDiskInterface for IDisk {
/// - The passed handle points to memory that is so physically scattered it overflows
/// the PRDT. This can only happen for read/writes of 1985 sectors or more.
/// You should consider retrying with a smaller `sector_count`.
fn write_dma(&mut self, _manager: &WaitableManager, sharedmem: SharedMemory, mapping_size: u64, lba: u64, sector_count: u64) -> Result<(), Error> {
fn write_dma(&mut self, _manager: WorkQueue<'static>, sharedmem: SharedMemory, mapping_size: u64, lba: u64, sector_count: u64) -> Result<(), Error> {
let addr = sunrise_libuser::mem::find_free_address(mapping_size as _, 0x1000)?;
let mapped = sharedmem.map(addr, mapping_size as _, MemoryPermissions::empty())
// no need for permission, only the disk will dma to it.
Expand Down
19 changes: 10 additions & 9 deletions ahci/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ use alloc::boxed::Box;
use alloc::vec::Vec;
use alloc::sync::Arc;
use sunrise_libuser::error::{Error, AhciError};
use sunrise_libuser::ipc::server::{WaitableManager, PortHandler, IWaitable};
use sunrise_libuser::futures::{WaitableManager, WorkQueue};
use sunrise_libuser::ipc::server::{port_handler, new_session_wrapper};
use spin::Mutex;
use sunrise_libuser::syscalls;
use sunrise_libuser::ipc::server::SessionWrapper;
use sunrise_libuser::ahci::{AhciInterface as IAhciInterface, IDiskProxy, IDisk as _};
use futures::future::FutureObj;

/// Array of discovered disk.
///
Expand Down Expand Up @@ -112,9 +113,9 @@ fn main() {
debug!("AHCI initialised disks : {:#x?}", DISKS);

// event loop
let man = WaitableManager::new();
let handler = Box::new(PortHandler::new("ahci:\0", AhciInterface::dispatch).unwrap());
man.add_waitable(handler as Box<dyn IWaitable>);
let mut man = WaitableManager::new();
let handler = port_handler(man.work_queue(), "ahci:\0", AhciInterface::dispatch).unwrap();
man.work_queue().spawn(FutureObj::new(Box::new(handler)));
man.run();
}

Expand All @@ -134,7 +135,7 @@ impl IAhciInterface for AhciInterface {
/// Returns the number of discovered disks.
///
/// Any number in the range `0..disk_count()` is considered a valid disk id.
fn discovered_disks_count(&mut self, _manager: &WaitableManager) -> Result<u32, Error> {
fn discovered_disks_count(&mut self, _manager: WorkQueue<'static>) -> Result<u32, Error> {
Ok(DISKS.lock().len() as u32)
}

Expand All @@ -145,14 +146,14 @@ impl IAhciInterface for AhciInterface {
/// # Error
///
/// - InvalidArg: `disk_id` is not a valid disk id.
fn get_disk(&mut self, manager: &WaitableManager, disk_id: u32,) -> Result<IDiskProxy, Error> {
fn get_disk(&mut self, work_queue: WorkQueue<'static>, disk_id: u32,) -> Result<IDiskProxy, Error> {
let idisk = IDisk::new(Arc::clone(
DISKS.lock().get(disk_id as usize)
.ok_or(AhciError::InvalidArg)?
));
let (server, client) = syscalls::create_session(false, 0)?;
let wrapper = SessionWrapper::new(server, idisk, IDisk::dispatch);
manager.add_waitable(Box::new(wrapper) as Box<dyn IWaitable>);
let wrapper = new_session_wrapper(work_queue.clone(), server, idisk, IDisk::dispatch);
work_queue.spawn(FutureObj::new(Box::new(wrapper)));
Ok(IDiskProxy::from(client))
}
}
Expand Down
Loading

0 comments on commit f6c2111

Please sign in to comment.