diff --git a/Cargo.lock b/Cargo.lock index aa9a3a5ccf..583fab0341 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -165,6 +165,8 @@ dependencies = [ "fdt 0.1.5", "libredox 0.1.3", "redox-daemon", + "redox-scheme", + "redox_event", "redox_syscall 0.5.3", ] @@ -172,6 +174,7 @@ dependencies = [ name = "bgad" version = "0.1.0" dependencies = [ + "common", "libredox 0.1.3", "orbclient", "pcid", @@ -955,6 +958,7 @@ dependencies = [ name = "pcspkrd" version = "0.1.0" dependencies = [ + "common", "libredox 0.1.3", "redox-daemon", "redox_syscall 0.5.3", diff --git a/Cargo.toml b/Cargo.toml index 65715466f7..83a012f471 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ members = [ "storage/bcm2835-sdhcid", "storage/driver-block", "storage/ided", - "storage/lived", # TODO: not really a driver... + "storage/lived", # TODO: not really a driver... "storage/nvmed", "storage/usbscsid", "storage/virtio-blkd", diff --git a/acpid/src/acpi.rs b/acpid/src/acpi.rs index 34edc263b9..2564825b15 100644 --- a/acpid/src/acpi.rs +++ b/acpid/src/acpi.rs @@ -6,7 +6,7 @@ use std::sync::{Arc, Mutex}; use std::{fmt, mem}; #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -use syscall::io::{Io, Pio}; +use common::io::{Io, Pio}; use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard}; use thiserror::Error; diff --git a/acpid/src/acpi/dmar/drhd.rs b/acpid/src/acpi/dmar/drhd.rs index 70c8f8b42b..da51d4349c 100644 --- a/acpid/src/acpi/dmar/drhd.rs +++ b/acpid/src/acpi/dmar/drhd.rs @@ -1,6 +1,6 @@ use std::ops::{Deref, DerefMut}; -use syscall::io::Mmio; +use common::io::Mmio; // TODO: Only wrap with Mmio where there are hardware-registers. (Some of these structs seem to be // ring buffer entries, which are not to be treated the same way). diff --git a/acpid/src/acpi/dmar/mod.rs b/acpid/src/acpi/dmar/mod.rs index 6d59c25e99..f89eae95f2 100644 --- a/acpid/src/acpi/dmar/mod.rs +++ b/acpid/src/acpi/dmar/mod.rs @@ -10,7 +10,7 @@ use std::convert::TryFrom; use std::ops::Deref; use std::{fmt, mem}; -use syscall::io::Io as _; +use common::io::Io as _; use num_derive::FromPrimitive; use num_traits::FromPrimitive; diff --git a/acpid/src/aml_physmem.rs b/acpid/src/aml_physmem.rs index 03d0eb5fef..e8f82d5f4c 100644 --- a/acpid/src/aml_physmem.rs +++ b/acpid/src/aml_physmem.rs @@ -3,7 +3,8 @@ use rustc_hash::FxHashMap; use std::fmt::LowerHex; use std::mem::size_of; use std::sync::{Arc, Mutex}; -use syscall::{Io, Pio, PAGE_SIZE}; +use syscall::PAGE_SIZE; +use common::io::{Io, Pio}; const PAGE_MASK: usize = !(PAGE_SIZE - 1); const OFFSET_MASK: usize = PAGE_SIZE - 1; diff --git a/audio/ac97d/src/device.rs b/audio/ac97d/src/device.rs index e5b747e8f9..1892d34fda 100644 --- a/audio/ac97d/src/device.rs +++ b/audio/ac97d/src/device.rs @@ -5,10 +5,10 @@ use std::collections::BTreeMap; use std::sync::atomic::{AtomicUsize, Ordering}; use syscall::error::{Error, EACCES, EBADF, Result, EINVAL, ENOENT}; -use syscall::io::{Mmio, Pio, Io}; +use common::io::Pio; use syscall::scheme::SchemeBlockMut; -use common::dma::Dma; +use common::{dma::Dma, io::{Io, Mmio}}; use spin::Mutex; const NUM_SUB_BUFFS: usize = 32; diff --git a/audio/ihdad/src/hda/cmdbuff.rs b/audio/ihdad/src/hda/cmdbuff.rs index c06c448d65..93e771d01c 100644 --- a/audio/ihdad/src/hda/cmdbuff.rs +++ b/audio/ihdad/src/hda/cmdbuff.rs @@ -1,5 +1,5 @@ use common::dma::Dma; -use syscall::io::{Io, Mmio}; +use common::io::{Io, Mmio}; use super::common::*; diff --git a/audio/ihdad/src/hda/device.rs b/audio/ihdad/src/hda/device.rs index 09d2c56bfb..86847d3a00 100755 --- a/audio/ihdad/src/hda/device.rs +++ b/audio/ihdad/src/hda/device.rs @@ -8,9 +8,9 @@ use std::collections::BTreeMap; use std::sync::atomic::{AtomicUsize, Ordering}; use common::dma::Dma; +use common::io::{Mmio, Io}; use syscall::error::{Error, EACCES, EBADF, Result, EINVAL}; use syscall::flag::{SEEK_SET, SEEK_CUR, SEEK_END}; -use syscall::io::{Mmio, Io}; use syscall::scheme::SchemeBlockMut; use spin::Mutex; diff --git a/audio/ihdad/src/hda/stream.rs b/audio/ihdad/src/hda/stream.rs index afad58a609..49fb4dd2f7 100644 --- a/audio/ihdad/src/hda/stream.rs +++ b/audio/ihdad/src/hda/stream.rs @@ -1,7 +1,7 @@ use common::dma::Dma; +use common::io::{Mmio, Io}; use syscall::PAGE_SIZE; use syscall::error::{Error, EIO, Result}; -use syscall::io::{Mmio, Io}; use std::result; use std::cmp::min; use std::ptr::copy_nonoverlapping; diff --git a/audio/pcspkrd/Cargo.toml b/audio/pcspkrd/Cargo.toml index 2ff4476a9a..555c25f566 100644 --- a/audio/pcspkrd/Cargo.toml +++ b/audio/pcspkrd/Cargo.toml @@ -5,6 +5,7 @@ authors = ["Tibor Nagy "] edition = "2018" [dependencies] +common = { path = "../../common" } redox_syscall = "0.5" redox-daemon = "0.1" libredox = "0.1.3" diff --git a/audio/pcspkrd/src/pcspkr.rs b/audio/pcspkrd/src/pcspkr.rs index f8c6760683..945421c2eb 100644 --- a/audio/pcspkrd/src/pcspkr.rs +++ b/audio/pcspkrd/src/pcspkr.rs @@ -1,4 +1,4 @@ -use syscall::io::{Io, Pio}; +use common::io::{Io, Pio}; pub struct Pcspkr { command: Pio, diff --git a/audio/sb16d/src/device.rs b/audio/sb16d/src/device.rs index ea0530d78f..47cf231f5a 100644 --- a/audio/sb16d/src/device.rs +++ b/audio/sb16d/src/device.rs @@ -4,8 +4,9 @@ use std::{thread, time}; use std::collections::BTreeMap; use std::sync::atomic::{AtomicUsize, Ordering}; +use common::io::{Pio, Io, ReadOnly, WriteOnly}; + use syscall::error::{Error, EACCES, EBADF, Result, ENODEV}; -use syscall::io::{Pio, Io, ReadOnly, WriteOnly}; use syscall::scheme::SchemeBlockMut; use spin::Mutex; diff --git a/common/src/io.rs b/common/src/io.rs new file mode 100644 index 0000000000..955cf0a06f --- /dev/null +++ b/common/src/io.rs @@ -0,0 +1,95 @@ +use core::{ + cmp::PartialEq, + ops::{BitAnd, BitOr, Not}, +}; + +mod mmio; +mod pio; + +pub use mmio::*; +pub use pio::*; + +/// IO abstraction +pub trait Io { + /// Value type for IO, usually some unsigned number + type Value: Copy + + PartialEq + + BitAnd + + BitOr + + Not; + + /// Read the underlying valu2e + fn read(&self) -> Self::Value; + /// Write the underlying value + fn write(&mut self, value: Self::Value); + + /// Check whether the underlying value contains bit flags + #[inline(always)] + fn readf(&self, flags: Self::Value) -> bool { + (self.read() & flags) as Self::Value == flags + } + + /// Enable or disable specific bit flags + #[inline(always)] + fn writef(&mut self, flags: Self::Value, value: bool) { + let tmp: Self::Value = match value { + true => self.read() | flags, + false => self.read() & !flags, + }; + self.write(tmp); + } +} + +/// Read-only IO +#[repr(transparent)] +pub struct ReadOnly { + inner: I, +} + +impl ReadOnly { + /// Wraps IO + pub const fn new(inner: I) -> ReadOnly { + ReadOnly { inner } + } +} + +impl ReadOnly { + /// Calls [Io::read] + #[inline(always)] + pub fn read(&self) -> I::Value { + self.inner.read() + } + + /// Calls [Io::readf] + #[inline(always)] + pub fn readf(&self, flags: I::Value) -> bool { + self.inner.readf(flags) + } +} + +#[repr(transparent)] +/// Write-only IO +pub struct WriteOnly { + inner: I, +} + +impl WriteOnly { + /// Wraps IO + pub const fn new(inner: I) -> WriteOnly { + WriteOnly { inner } + } +} + +impl WriteOnly { + /// Calls [Io::write] + #[inline(always)] + pub fn write(&mut self, value: I::Value) { + self.inner.write(value) + } + + #[inline(always)] + /// Calls [Io::writef] + pub fn writef(&mut self, flags: I::Value, value: bool) { + self.inner.writef(flags, value) + } +} \ No newline at end of file diff --git a/common/src/io/mmio.rs b/common/src/io/mmio.rs new file mode 100644 index 0000000000..ca9d564ce2 --- /dev/null +++ b/common/src/io/mmio.rs @@ -0,0 +1,169 @@ +use core::{mem::MaybeUninit, ptr}; + +use super::Io; + +/// MMIO abstraction +#[repr(packed)] +pub struct Mmio { + value: MaybeUninit, +} + +impl Mmio { + /// Creates a zeroed instance + pub unsafe fn zeroed() -> Self { + Self { + value: MaybeUninit::zeroed(), + } + } + + /// Creates an unitialized instance + pub unsafe fn uninit() -> Self { + Self { + value: MaybeUninit::uninit(), + } + } + + /// Creates a new instance + pub const fn new(value: T) -> Self { + Self { + value: MaybeUninit::new(value), + } + } +} + +// Generic implementation (WARNING: requires aligned pointers!) +#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))] +impl Io for Mmio +where + T: Copy + PartialEq + BitAnd + BitOr + Not, +{ + type Value = T; + + fn read(&self) -> T { + unsafe { ptr::read_volatile(ptr::addr_of!(self.value).cast::()) } + } + + fn write(&mut self, value: T) { + unsafe { ptr::write_volatile(ptr::addr_of_mut!(self.value).cast::(), value) }; + } +} + +// x86 u8 implementation +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +impl Io for Mmio { + type Value = u8; + + fn read(&self) -> Self::Value { + unsafe { + let value: Self::Value; + let ptr: *const Self::Value = ptr::addr_of!(self.value).cast::(); + core::arch::asm!( + "mov {}, [{}]", + out(reg_byte) value, + in(reg) ptr + ); + value + } + } + + fn write(&mut self, value: Self::Value) { + unsafe { + let ptr: *mut Self::Value = ptr::addr_of_mut!(self.value).cast::(); + core::arch::asm!( + "mov [{}], {}", + in(reg) ptr, + in(reg_byte) value, + ); + } + } +} + +// x86 u16 implementation +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +impl Io for Mmio { + type Value = u16; + + fn read(&self) -> Self::Value { + unsafe { + let value: Self::Value; + let ptr: *const Self::Value = ptr::addr_of!(self.value).cast::(); + core::arch::asm!( + "mov {:x}, [{}]", + out(reg) value, + in(reg) ptr + ); + value + } + } + + fn write(&mut self, value: Self::Value) { + unsafe { + let ptr: *mut Self::Value = ptr::addr_of_mut!(self.value).cast::(); + core::arch::asm!( + "mov [{}], {:x}", + in(reg) ptr, + in(reg) value, + ); + } + } +} + +// x86 u32 implementation +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +impl Io for Mmio { + type Value = u32; + + fn read(&self) -> Self::Value { + unsafe { + let value: Self::Value; + let ptr: *const Self::Value = ptr::addr_of!(self.value).cast::(); + core::arch::asm!( + "mov {:e}, [{}]", + out(reg) value, + in(reg) ptr + ); + value + } + } + + fn write(&mut self, value: Self::Value) { + unsafe { + let ptr: *mut Self::Value = ptr::addr_of_mut!(self.value).cast::(); + core::arch::asm!( + "mov [{}], {:e}", + in(reg) ptr, + in(reg) value, + ); + } + } +} + +// x86 u64 implementation (x86_64 only) +#[cfg(target_arch = "x86_64")] +impl Io for Mmio { + type Value = u64; + + fn read(&self) -> Self::Value { + unsafe { + let value: Self::Value; + let ptr: *const Self::Value = ptr::addr_of!(self.value).cast::(); + core::arch::asm!( + "mov {:r}, [{}]", + out(reg) value, + in(reg) ptr + ); + value + } + } + + fn write(&mut self, value: Self::Value) { + unsafe { + let ptr: *mut Self::Value = ptr::addr_of_mut!(self.value).cast::(); + core::arch::asm!( + "mov [{}], {:r}", + in(reg) ptr, + in(reg) value, + ); + } + } +} diff --git a/common/src/io/pio.rs b/common/src/io/pio.rs new file mode 100644 index 0000000000..187e4734c3 --- /dev/null +++ b/common/src/io/pio.rs @@ -0,0 +1,89 @@ +use core::{arch::asm, marker::PhantomData}; + +use super::Io; + +/// Generic PIO +#[derive(Copy, Clone)] +pub struct Pio { + port: u16, + value: PhantomData, +} + +impl Pio { + /// Create a PIO from a given port + pub const fn new(port: u16) -> Self { + Pio:: { + port, + value: PhantomData, + } + } +} + +/// Read/Write for byte PIO +impl Io for Pio { + type Value = u8; + + /// Read + #[inline(always)] + fn read(&self) -> u8 { + let value: u8; + unsafe { + asm!("in al, dx", in("dx") self.port, out("al") value, options(nostack, nomem, preserves_flags)); + } + value + } + + /// Write + #[inline(always)] + fn write(&mut self, value: u8) { + unsafe { + asm!("out dx, al", in("dx") self.port, in("al") value, options(nostack, nomem, preserves_flags)); + } + } +} + +/// Read/Write for word PIO +impl Io for Pio { + type Value = u16; + + /// Read + #[inline(always)] + fn read(&self) -> u16 { + let value: u16; + unsafe { + asm!("in ax, dx", in("dx") self.port, out("ax") value, options(nostack, nomem, preserves_flags)); + } + value + } + + /// Write + #[inline(always)] + fn write(&mut self, value: u16) { + unsafe { + asm!("out dx, ax", in("dx") self.port, in("ax") value, options(nostack, nomem, preserves_flags)); + } + } +} + +/// Read/Write for doubleword PIO +impl Io for Pio { + type Value = u32; + + /// Read + #[inline(always)] + fn read(&self) -> u32 { + let value: u32; + unsafe { + asm!("in eax, dx", in("dx") self.port, out("eax") value, options(nostack, nomem, preserves_flags)); + } + value + } + + /// Write + #[inline(always)] + fn write(&mut self, value: u32) { + unsafe { + asm!("out dx, eax", in("dx") self.port, in("eax") value, options(nostack, nomem, preserves_flags)); + } + } +} diff --git a/common/src/lib.rs b/common/src/lib.rs index f90ed57454..61fa6ced99 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -12,6 +12,8 @@ use syscall::PAGE_SIZE; /// The Direct Memory Access (DMA) API for drivers pub mod dma; +/// MMIO utilities +pub mod io; mod logger; /// The Scatter Gather List (SGL) API for drivers. pub mod sgl; @@ -128,7 +130,7 @@ pub unsafe fn physmap( // TODO: arraystring? //Return an error rather than potentially crash the kernel. - if(base_phys == 0) { + if base_phys == 0 { return Err(Error::new(EINVAL)); } diff --git a/graphics/bgad/Cargo.toml b/graphics/bgad/Cargo.toml index 76dc78b582..4e9fe1ae5f 100644 --- a/graphics/bgad/Cargo.toml +++ b/graphics/bgad/Cargo.toml @@ -8,5 +8,6 @@ orbclient = "0.3.47" redox-daemon = "0.1" redox_syscall = "0.5" +common = { path = "../../common" } pcid = { path = "../../pcid" } libredox = "0.1.3" diff --git a/graphics/bgad/src/bga.rs b/graphics/bgad/src/bga.rs index ee196f7f95..a498125c9a 100644 --- a/graphics/bgad/src/bga.rs +++ b/graphics/bgad/src/bga.rs @@ -1,4 +1,4 @@ -use syscall::io::{Io, Pio}; +use common::io::{Io, Pio}; const BGA_INDEX_XRES: u16 = 1; const BGA_INDEX_YRES: u16 = 2; diff --git a/net/alxd/src/device/mod.rs b/net/alxd/src/device/mod.rs index 0222cd1c27..baac6fc89d 100644 --- a/net/alxd/src/device/mod.rs +++ b/net/alxd/src/device/mod.rs @@ -3,7 +3,7 @@ use std::convert::TryInto; use syscall::error::{Error, EACCES, EINVAL, EIO, EWOULDBLOCK, Result}; use syscall::flag::{EventFlags, O_NONBLOCK}; -use syscall::io::{Io, Mmio}; +use common::io::{Io, Mmio}; use syscall::scheme; use common::dma::Dma; diff --git a/net/rtl8139d/src/device.rs b/net/rtl8139d/src/device.rs index e6ef45053b..d67a1b3078 100644 --- a/net/rtl8139d/src/device.rs +++ b/net/rtl8139d/src/device.rs @@ -3,8 +3,8 @@ use std::convert::TryInto; use driver_network::NetworkAdapter; use syscall::error::{Error, EIO, EMSGSIZE, Result}; -use syscall::io::{Mmio, Io, ReadOnly}; +use common::io::{Mmio, Io, ReadOnly}; use common::dma::Dma; const RX_BUFFER_SIZE: usize = 64 * 1024; diff --git a/net/rtl8168d/src/device.rs b/net/rtl8168d/src/device.rs index 717ac194e2..b2aef1889e 100644 --- a/net/rtl8168d/src/device.rs +++ b/net/rtl8168d/src/device.rs @@ -3,7 +3,7 @@ use std::convert::TryInto; use driver_network::NetworkAdapter; use syscall::error::{Error, Result, EMSGSIZE}; -use syscall::io::{Mmio, Io, ReadOnly}; +use common::io::{Mmio, Io, ReadOnly}; use common::dma::Dma; diff --git a/pcid/src/cfg_access/fallback.rs b/pcid/src/cfg_access/fallback.rs index 1f1e49a8ae..671d17f735 100644 --- a/pcid/src/cfg_access/fallback.rs +++ b/pcid/src/cfg_access/fallback.rs @@ -3,7 +3,7 @@ use std::convert::TryFrom; use std::sync::Mutex; #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -use syscall::io::{Io as _, Pio}; +use common::io::{Io as _, Pio}; use log::info; use pci_types::{ConfigRegionAccess, PciAddress}; diff --git a/pcid/src/driver_interface/msi.rs b/pcid/src/driver_interface/msi.rs index cba4d21399..d95837eb77 100644 --- a/pcid/src/driver_interface/msi.rs +++ b/pcid/src/driver_interface/msi.rs @@ -3,7 +3,7 @@ use std::fmt; use crate::driver_interface::PciBar; use serde::{Deserialize, Serialize}; -use syscall::{Io, Mmio}; +use common::io::{Io, Mmio}; /// The address and data to use for MSI and MSI-X. /// diff --git a/ps2d/src/controller.rs b/ps2d/src/controller.rs index ecb9036794..24968b84a5 100644 --- a/ps2d/src/controller.rs +++ b/ps2d/src/controller.rs @@ -1,5 +1,5 @@ use log::{debug, error, info, trace}; -use syscall::io::{Io, Pio, ReadOnly, WriteOnly}; +use common::io::{Io, Pio, ReadOnly, WriteOnly}; use std::fmt; diff --git a/storage/ahcid/src/ahci/fis.rs b/storage/ahcid/src/ahci/fis.rs index 1d4013ae88..0e4b380271 100644 --- a/storage/ahcid/src/ahci/fis.rs +++ b/storage/ahcid/src/ahci/fis.rs @@ -1,4 +1,4 @@ -use syscall::io::Mmio; +use common::io::Mmio; #[repr(u8)] pub enum FisType { diff --git a/storage/ahcid/src/ahci/hba.rs b/storage/ahcid/src/ahci/hba.rs index 5ca6af72f7..b893fddc81 100644 --- a/storage/ahcid/src/ahci/hba.rs +++ b/storage/ahcid/src/ahci/hba.rs @@ -3,7 +3,7 @@ use std::mem::size_of; use std::ops::DerefMut; use std::{ptr, u32}; -use syscall::io::{Io, Mmio}; +use common::io::{Io, Mmio}; use syscall::error::{Error, Result, EIO}; use super::fis::{FisType, FisRegH2D}; diff --git a/storage/ahcid/src/ahci/mod.rs b/storage/ahcid/src/ahci/mod.rs index 3f63ca235e..aaf3b78523 100644 --- a/storage/ahcid/src/ahci/mod.rs +++ b/storage/ahcid/src/ahci/mod.rs @@ -1,6 +1,6 @@ use driver_block::Disk; use log::{error, info}; -use syscall::io::Io; +use common::io::Io; use self::disk_ata::DiskATA; use self::disk_atapi::DiskATAPI; diff --git a/storage/ahcid/src/scheme.rs b/storage/ahcid/src/scheme.rs index 8a6cc89480..c5f03d97b6 100644 --- a/storage/ahcid/src/scheme.rs +++ b/storage/ahcid/src/scheme.rs @@ -5,9 +5,10 @@ use std::fmt::Write; use driver_block::{Disk, DiskWrapper}; use syscall::schemev2::NewFdFlags; use syscall::{ - Error, EACCES, EBADF, EINVAL, EISDIR, ENOENT, ENOLCK, EOVERFLOW, Result, Io, Stat, MODE_DIR, + Error, EACCES, EBADF, EINVAL, EISDIR, ENOENT, ENOLCK, EOVERFLOW, Result, Stat, MODE_DIR, MODE_FILE, O_DIRECTORY, O_STAT, }; +use common::io::Io as _; use redox_scheme::{CallerCtx, OpenResult, SchemeBlockMut}; use crate::ahci::hba::HbaMem; diff --git a/storage/bcm2835-sdhcid/src/sd/mod.rs b/storage/bcm2835-sdhcid/src/sd/mod.rs index ece800a329..2e31b3ae19 100644 --- a/storage/bcm2835-sdhcid/src/sd/mod.rs +++ b/storage/bcm2835-sdhcid/src/sd/mod.rs @@ -1,6 +1,7 @@ -use std::{sync::{Mutex, RwLock}, time::{self, Duration}, thread}; -use syscall::{io::Mmio, Io, Error, Result, EINVAL}; +use common::io::{Io, Mmio}; use driver_block::Disk; +use std::{sync::RwLock, thread, time::Duration}; +use syscall::{Error, Result, EINVAL}; #[cfg(target_arch = "aarch64")] #[inline(always)] diff --git a/storage/ided/src/ide.rs b/storage/ided/src/ide.rs index 8428d92b60..f61003c1a2 100644 --- a/storage/ided/src/ide.rs +++ b/storage/ided/src/ide.rs @@ -6,12 +6,10 @@ use std::{ }; use driver_block::Disk; -use syscall::{ - error::{Error, Result, EIO}, - io::{Io, Pio, ReadOnly, WriteOnly}, -}; +use syscall::error::{Error, Result, EIO}; use common::dma::Dma; +use common::io::{Io, Pio, ReadOnly, WriteOnly}; static TIMEOUT: Duration = Duration::new(1, 0); diff --git a/storage/ided/src/main.rs b/storage/ided/src/main.rs index 28719cfddd..73db90c14f 100644 --- a/storage/ided/src/main.rs +++ b/storage/ided/src/main.rs @@ -12,8 +12,9 @@ use std::{ thread::{self, sleep}, time::Duration, }; +use common::io::Io as _; use syscall::{ - data::{Event, Packet}, error::{Error, ENODEV}, flag::EVENT_READ, io::Io, scheme::SchemeBlockMut, EAGAIN, EINTR, EWOULDBLOCK + data::{Event, Packet}, error::{Error, ENODEV}, flag::EVENT_READ, scheme::SchemeBlockMut, EAGAIN, EINTR, EWOULDBLOCK }; use crate::{ diff --git a/storage/nvmed/src/main.rs b/storage/nvmed/src/main.rs index 28ff062e47..0676d6a3be 100644 --- a/storage/nvmed/src/main.rs +++ b/storage/nvmed/src/main.rs @@ -13,7 +13,7 @@ use libredox::flag; use pcid_interface::{PciFeature, PciFeatureInfo, PciFunction, PciFunctionHandle}; use redox_scheme::{CallRequest, RequestKind, SignalBehavior, Socket, V2}; use syscall::{ - Event, Mmio, Packet, Result, SchemeBlockMut, + Event, Packet, Result, SchemeBlockMut, PAGE_SIZE, }; diff --git a/storage/nvmed/src/nvme/mod.rs b/storage/nvmed/src/nvme/mod.rs index 14e502777a..a4127a3b51 100644 --- a/storage/nvmed/src/nvme/mod.rs +++ b/storage/nvmed/src/nvme/mod.rs @@ -10,7 +10,7 @@ use crossbeam_channel::Sender; use smallvec::{smallvec, SmallVec}; use syscall::error::{Error, Result, EINVAL, EIO}; -use syscall::io::{Io, Mmio}; +use common::io::{Io, Mmio}; use common::dma::Dma; diff --git a/storage/nvmed/src/scheme.rs b/storage/nvmed/src/scheme.rs index a301a7fa98..a38fb1cada 100644 --- a/storage/nvmed/src/scheme.rs +++ b/storage/nvmed/src/scheme.rs @@ -8,7 +8,7 @@ use std::{cmp, str}; use syscall::schemev2::NewFdFlags; use syscall::{ - Error, Io, Result, Stat, EACCES, EBADF, EINVAL, EISDIR, ENOENT, ENOLCK, EOVERFLOW, MODE_DIR, + Error, Result, Stat, EACCES, EBADF, EINVAL, EISDIR, ENOENT, ENOLCK, EOVERFLOW, MODE_DIR, MODE_FILE, O_DIRECTORY, O_STAT, SEEK_CUR, SEEK_END, SEEK_SET, }; use redox_scheme::{CallerCtx, OpenResult, SchemeBlockMut}; diff --git a/vboxd/src/bga.rs b/vboxd/src/bga.rs index 21599f7fd0..d9fe280100 100644 --- a/vboxd/src/bga.rs +++ b/vboxd/src/bga.rs @@ -1,4 +1,4 @@ -use syscall::io::{Io, Pio}; +use common::io::{Io, Pio}; const BGA_INDEX_XRES: u16 = 1; const BGA_INDEX_YRES: u16 = 2; diff --git a/vboxd/src/main.rs b/vboxd/src/main.rs index fac9717351..8a50ccce82 100644 --- a/vboxd/src/main.rs +++ b/vboxd/src/main.rs @@ -8,7 +8,7 @@ use std::io::{Result, Read, Write}; use pcid_interface::{PciBar, PciFunctionHandle}; use syscall::flag::EventFlags; -use syscall::io::{Io, Mmio, Pio}; +use common::io::{Io, Mmio, Pio}; use common::dma::Dma; diff --git a/xhcid/src/main.rs b/xhcid/src/main.rs index e3798cd580..e117f2a867 100644 --- a/xhcid/src/main.rs +++ b/xhcid/src/main.rs @@ -49,7 +49,7 @@ use event::{Event, RawEventQueue}; use syscall::data::Packet; use syscall::error::EWOULDBLOCK; use syscall::flag::EventFlags; -use syscall::io::Io; +use common::io::Io; use syscall::scheme::Scheme; use crate::xhci::{InterruptMethod, Xhci}; diff --git a/xhcid/src/xhci/capability.rs b/xhcid/src/xhci/capability.rs index ab3ffb8502..7dfd670448 100644 --- a/xhcid/src/xhci/capability.rs +++ b/xhcid/src/xhci/capability.rs @@ -1,4 +1,4 @@ -use syscall::io::{Io, Mmio}; +use common::io::{Io, Mmio}; /// Represents the memory-mapped Capability Registers of the XHCI /// diff --git a/xhcid/src/xhci/context.rs b/xhcid/src/xhci/context.rs index aabbeaf754..932fe6f202 100644 --- a/xhcid/src/xhci/context.rs +++ b/xhcid/src/xhci/context.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; use log::debug; use syscall::error::Result; -use syscall::io::{Io, Mmio}; +use common::io::{Io, Mmio}; use syscall::PAGE_SIZE; use common::dma::Dma; diff --git a/xhcid/src/xhci/doorbell.rs b/xhcid/src/xhci/doorbell.rs index b464186b98..58c6cba36f 100644 --- a/xhcid/src/xhci/doorbell.rs +++ b/xhcid/src/xhci/doorbell.rs @@ -1,4 +1,4 @@ -use syscall::io::{Io, Mmio}; +use common::io::{Io, Mmio}; #[repr(packed)] pub struct Doorbell(Mmio); diff --git a/xhcid/src/xhci/event.rs b/xhcid/src/xhci/event.rs index c955d6488d..f2da331a95 100644 --- a/xhcid/src/xhci/event.rs +++ b/xhcid/src/xhci/event.rs @@ -1,5 +1,5 @@ use syscall::error::Result; -use syscall::io::{Io, Mmio}; +use common::io::{Io, Mmio}; use common::dma::Dma; diff --git a/xhcid/src/xhci/extended.rs b/xhcid/src/xhci/extended.rs index 6e303c30b7..1f8115b7e5 100644 --- a/xhcid/src/xhci/extended.rs +++ b/xhcid/src/xhci/extended.rs @@ -1,7 +1,7 @@ use std::ops::Range; use std::ptr::NonNull; use std::{fmt, mem, ptr, slice}; -use syscall::{Io, Mmio}; +use common::io::{Io, Mmio}; pub struct ExtendedCapabilitiesIter { base: *const u8, @@ -111,7 +111,7 @@ pub enum Lp { impl ProtocolSpeed { pub const fn from_raw(raw: u32) -> Self { - Self { a: Mmio::from(raw) } + Self { a: Mmio::new(raw) } } pub fn is_lowspeed(&self) -> bool { self.psim() == 1500 && self.psie() == Psie::Kbps && !self.pfd() diff --git a/xhcid/src/xhci/irq_reactor.rs b/xhcid/src/xhci/irq_reactor.rs index 2de350cbba..a42728d4cc 100644 --- a/xhcid/src/xhci/irq_reactor.rs +++ b/xhcid/src/xhci/irq_reactor.rs @@ -1,20 +1,16 @@ -use std::collections::BTreeMap; use std::fs::File; use std::future::Future; use std::io::prelude::*; use std::pin::Pin; -use std::sync::atomic::{self, AtomicUsize}; use std::sync::{Arc, Mutex}; -use std::{io, mem, task, thread}; +use std::task; use std::os::unix::io::AsRawFd; use crossbeam_channel::{Receiver, Sender}; -use futures::Stream; use log::{debug, error, info, trace, warn}; -use syscall::Io; -use event::{Event, EventQueue, RawEventQueue}; +use event::RawEventQueue; use super::doorbell::Doorbell; use super::event::EventRing; @@ -22,6 +18,8 @@ use super::ring::Ring; use super::trb::{Trb, TrbCompletionCode, TrbType}; use super::Xhci; +use common::io::Io as _; + /// Short-term states (as in, they are removed when the waker is consumed, but probably pushed back /// by the future unless it completed). #[derive(Debug)] diff --git a/xhcid/src/xhci/mod.rs b/xhcid/src/xhci/mod.rs index 07a6826bb1..a0a72f296a 100644 --- a/xhcid/src/xhci/mod.rs +++ b/xhcid/src/xhci/mod.rs @@ -21,7 +21,7 @@ use std::sync::{Arc, Mutex, MutexGuard, Weak}; use std::{mem, process, slice, sync::atomic, task, thread}; use syscall::error::{Error, Result, EBADF, EBADMSG, EIO, ENOENT}; -use syscall::io::Io; +use common::io::Io; use syscall::PAGE_SIZE; use chashmap::CHashMap; diff --git a/xhcid/src/xhci/operational.rs b/xhcid/src/xhci/operational.rs index 4dcc760e9f..42918c922c 100644 --- a/xhcid/src/xhci/operational.rs +++ b/xhcid/src/xhci/operational.rs @@ -1,6 +1,6 @@ use std::num::NonZeroU8; use std::slice; -use syscall::io::{Io, Mmio}; +use common::io::{Io, Mmio}; use super::CapabilityRegs; diff --git a/xhcid/src/xhci/port.rs b/xhcid/src/xhci/port.rs index 674a79332a..d1b4e37187 100644 --- a/xhcid/src/xhci/port.rs +++ b/xhcid/src/xhci/port.rs @@ -1,4 +1,4 @@ -use syscall::io::{Io, Mmio}; +use common::io::{Io, Mmio}; bitflags! { pub struct PortFlags: u32 { diff --git a/xhcid/src/xhci/runtime.rs b/xhcid/src/xhci/runtime.rs index b18fb482e9..deeb96f401 100644 --- a/xhcid/src/xhci/runtime.rs +++ b/xhcid/src/xhci/runtime.rs @@ -1,4 +1,4 @@ -use syscall::io::Mmio; +use common::io::Mmio; #[repr(packed)] pub struct Interrupter { diff --git a/xhcid/src/xhci/scheme.rs b/xhcid/src/xhci/scheme.rs index b5824d5f61..47914b8769 100644 --- a/xhcid/src/xhci/scheme.rs +++ b/xhcid/src/xhci/scheme.rs @@ -28,7 +28,7 @@ use log::{debug, error, info, trace, warn}; use serde::{Deserialize, Serialize}; use smallvec::{smallvec, SmallVec}; -use syscall::io::Io; +use common::io::Io; use syscall::scheme::Scheme; use syscall::{ Error, Result, Stat, EACCES, EBADF, EBADFD, EBADMSG, EEXIST, EINVAL, EIO, EISDIR, ENOENT, diff --git a/xhcid/src/xhci/trb.rs b/xhcid/src/xhci/trb.rs index 37fee43a95..f30443a5f4 100644 --- a/xhcid/src/xhci/trb.rs +++ b/xhcid/src/xhci/trb.rs @@ -1,6 +1,6 @@ use crate::usb; use std::{fmt, mem}; -use syscall::io::{Io, Mmio}; +use common::io::{Io, Mmio}; use super::context::StreamContextType; @@ -118,10 +118,10 @@ pub struct Trb { impl Clone for Trb { fn clone(&self) -> Self { Self { - data_low: Mmio::from(self.data_low.read()), - data_high: Mmio::from(self.data_high.read()), - status: Mmio::from(self.status.read()), - control: Mmio::from(self.control.read()), + data_low: Mmio::new(self.data_low.read()), + data_high: Mmio::new(self.data_high.read()), + status: Mmio::new(self.status.read()), + control: Mmio::new(self.control.read()), } } }