Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 103 additions & 53 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 1 addition & 7 deletions api/ruxfeat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,7 @@ driver-ramdisk = ["ruxdriver?/ramdisk", "ruxfs?/use-ramdisk"]
driver-ixgbe = ["ruxdriver?/ixgbe"]
driver-bcm2835-sdhci = ["ruxdriver?/bcm2835-sdhci"]

# Logging
log-level-off = ["axlog/log-level-off"]
log-level-error = ["axlog/log-level-error"]
log-level-warn = ["axlog/log-level-warn"]
log-level-info = ["axlog/log-level-info"]
log-level-debug = ["axlog/log-level-debug"]
log-level-trace = ["axlog/log-level-trace"]


# this feature has already been deprecated
tty = []
Expand Down
2 changes: 1 addition & 1 deletion crates/axlog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ default = []

[dependencies]
cfg-if = "1.0"
log = "< 0.4.22"
log = "0.4"
spinlock = { path = "../spinlock" }
crate_interface = { version = "0.1.1" }
chrono = { version = "0.4", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/driver_pci/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ repository = "https://github.com/rcore-os/arceos/tree/main/crates/driver_pci"
documentation = "https://rcore-os.github.io/arceos/driver_pci/index.html"

[dependencies]
virtio-drivers = { git = "https://github.com/syswonder/virtio-drivers.git", rev = "62dbe5a"}
virtio-drivers = { git = "https://github.com/syswonder/virtio-drivers.git", rev = "31f6555"}
6 changes: 4 additions & 2 deletions crates/driver_pci/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@

#![no_std]

pub use virtio_drivers::transport::pci::bus::{BarInfo, Cam, HeaderType, MemoryBarType, PciError};
pub use virtio_drivers::transport::pci::bus::ConfigurationAccess;
pub use virtio_drivers::transport::pci::bus::{
BarInfo, Cam, HeaderType, MemoryBarType, MmioCam, PciError,
};
pub use virtio_drivers::transport::pci::bus::{
CapabilityInfo, Command, DeviceFunction, DeviceFunctionInfo, PciRoot, Status,
};

/// Used to allocate MMIO regions for PCI BARs.
pub struct PciRangeAllocator {
_start: u64,
Expand Down
2 changes: 1 addition & 1 deletion crates/driver_virtio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ driver_net = { path = "../driver_net", optional = true }
driver_display = { path = "../driver_display", optional = true }
driver_9p = { path = "../driver_9p", optional = true }
driver_console = { path = "../driver_console", optional = true }
virtio-drivers = { git = "https://github.com/syswonder/virtio-drivers.git", rev = "62dbe5a" }
virtio-drivers = { git = "https://github.com/syswonder/virtio-drivers.git", rev = "31f6555" }
4 changes: 2 additions & 2 deletions crates/driver_virtio/src/blk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ impl<H: Hal, T: Transport> BlockDriverOps for VirtIoBlkDev<H, T> {

fn read_block(&mut self, block_id: u64, buf: &mut [u8]) -> DevResult {
self.inner
.read_block(block_id as _, buf)
.read_blocks(block_id as _, buf)
.map_err(as_dev_err)
}

fn write_block(&mut self, block_id: u64, buf: &[u8]) -> DevResult {
self.inner
.write_block(block_id as _, buf)
.write_blocks(block_id as _, buf)
.map_err(as_dev_err)
}

Expand Down
2 changes: 1 addition & 1 deletion crates/driver_virtio/src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use virtio_drivers::{device::console::VirtIOConsole as InnerDev, transport::Tran

/// VirtIO console device
pub struct VirtIoConsoleDev<H: Hal, T: Transport> {
inner: InnerDev<'static, H, T>,
inner: InnerDev<H, T>,
}

unsafe impl<H: Hal, T: Transport> Send for VirtIoConsoleDev<H, T> {}
Expand Down
2 changes: 1 addition & 1 deletion crates/driver_virtio/src/gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use virtio_drivers::{device::gpu::VirtIOGpu as InnerDev, transport::Transport, H

/// The VirtIO GPU device driver.
pub struct VirtIoGpuDev<H: Hal, T: Transport> {
inner: InnerDev<'static, H, T>,
inner: InnerDev<H, T>,
info: DisplayInfo,
}

Expand Down
19 changes: 12 additions & 7 deletions crates/driver_virtio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub use self::net::VirtIoNetDev;
pub use self::v9p::VirtIo9pDev;

pub use virtio_drivers::transport::pci::bus as pci;
use virtio_drivers::transport::pci::bus::ConfigurationAccess;
pub use virtio_drivers::transport::{mmio::MmioTransport, pci::PciTransport, Transport};
pub use virtio_drivers::{BufferDirection, Hal as VirtIoHal, PhysAddr};

Expand All @@ -59,13 +60,13 @@ use virtio_drivers::transport::DeviceType as VirtIoDevType;
/// for later operations. Otherwise, returns [`None`].
pub fn probe_mmio_device(
reg_base: *mut u8,
_reg_size: usize,
) -> Option<(DeviceType, MmioTransport)> {
reg_size: usize,
) -> Option<(DeviceType, MmioTransport<'static>)> {
use core::ptr::NonNull;
use virtio_drivers::transport::mmio::VirtIOHeader;

let header = NonNull::new(reg_base as *mut VirtIOHeader).unwrap();
let transport = unsafe { MmioTransport::new(header) }.ok()?;
let transport = unsafe { MmioTransport::new(header, reg_size) }.ok()?;
let dev_type = as_dev_type(transport.device_type())?;
Some((dev_type, transport))
}
Expand All @@ -74,15 +75,19 @@ pub fn probe_mmio_device(
///
/// If the device is recognized, returns the device type and a transport object
/// for later operations. Otherwise, returns [`None`].
pub fn probe_pci_device<H: VirtIoHal>(
root: &mut PciRoot,
pub fn probe_pci_device<H, C>(
root: &mut PciRoot<C>,
bdf: DeviceFunction,
dev_info: &DeviceFunctionInfo,
) -> Option<(DeviceType, PciTransport)> {
) -> Option<(DeviceType, PciTransport)>
where
H: VirtIoHal,
C: ConfigurationAccess,
{
use virtio_drivers::transport::pci::virtio_device_type;

let dev_type = virtio_device_type(dev_info).and_then(as_dev_type)?;
let transport = PciTransport::new::<H>(root, bdf).ok()?;
let transport = PciTransport::new::<H, C>(root, bdf).ok()?;
Some((dev_type, transport))
}

Expand Down
4 changes: 2 additions & 2 deletions crates/driver_virtio/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ impl<H: Hal, T: Transport, const QS: usize> NetDriverOps for VirtIoNetDev<H, T,

#[inline]
fn can_transmit(&self) -> bool {
!self.free_tx_bufs.is_empty() && self.inner.can_transmit()
!self.free_tx_bufs.is_empty() && self.inner.can_send()
}

#[inline]
fn can_receive(&self) -> bool {
self.inner.can_receive()
self.inner.poll_receive().is_some()
}

#[inline]
Expand Down
23 changes: 13 additions & 10 deletions modules/ruxdriver/src/bus/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,27 @@

use crate::{prelude::*, AllDevices};
use driver_pci::{
BarInfo, Cam, Command, DeviceFunction, HeaderType, MemoryBarType, PciRangeAllocator, PciRoot,
BarInfo, Cam, Command, ConfigurationAccess, DeviceFunction, HeaderType, MemoryBarType, MmioCam,
PciRangeAllocator, PciRoot,
};
use ruxhal::mem::phys_to_virt;

const PCI_BAR_NUM: u8 = 6;

fn config_pci_device(
root: &mut PciRoot,
root: &mut PciRoot<impl ConfigurationAccess>,
bdf: DeviceFunction,
allocator: &mut Option<PciRangeAllocator>,
) -> DevResult {
let mut bar = 0;
while bar < PCI_BAR_NUM {
let info = root.bar_info(bdf, bar).unwrap();
if let BarInfo::Memory {
if let core::prelude::v1::Some(BarInfo::Memory {
address_type,
address,
size,
..
} = info
}) = info
{
// if the BAR address is not assigned, call the allocator and assign it.
if size > 0 && address == 0 {
Expand All @@ -46,19 +47,20 @@ fn config_pci_device(
}

// read the BAR info again after assignment.
let info = root.bar_info(bdf, bar).unwrap();
let info_ = root.bar_info(bdf, bar);
let info = info_.expect("Failed to read BAR info");
match info {
BarInfo::IO { address, size } => {
core::prelude::v1::Some(BarInfo::IO { address, size }) => {
if address > 0 && size > 0 {
debug!(" BAR {}: IO [{:#x}, {:#x})", bar, address, address + size);
}
}
BarInfo::Memory {
core::prelude::v1::Some(BarInfo::Memory {
address_type,
prefetchable,
address,
size,
} => {
}) => {
if address > 0 && size > 0 {
debug!(
" BAR {}: MEM [{:#x}, {:#x}){}{}",
Expand All @@ -74,10 +76,11 @@ fn config_pci_device(
);
}
}
None => todo!(),
}

bar += 1;
if info.takes_two_entries() {
if info.expect("REASON").takes_two_entries() {
bar += 1;
}
}
Expand All @@ -94,7 +97,7 @@ fn config_pci_device(
impl AllDevices {
pub(crate) fn probe_bus_devices(&mut self) {
let base_vaddr = phys_to_virt(ruxconfig::PCI_ECAM_BASE.into());
let mut root = unsafe { PciRoot::new(base_vaddr.as_mut_ptr(), Cam::Ecam) };
let mut root = PciRoot::new(unsafe { MmioCam::new(base_vaddr.as_mut_ptr(), Cam::Ecam) });

// PCI 32-bit MMIO space
let mut allocator = ruxconfig::PCI_RANGES
Expand Down
14 changes: 7 additions & 7 deletions modules/ruxdriver/src/drivers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use driver_common::DeviceType;
use crate::virtio::{self, VirtIoDevMeta};

#[cfg(feature = "bus-pci")]
use driver_pci::{DeviceFunction, DeviceFunctionInfo, PciRoot};
use driver_pci::{ConfigurationAccess, DeviceFunction, DeviceFunctionInfo, MmioCam, PciRoot};

pub use super::dummy::*;

Expand All @@ -34,7 +34,7 @@ pub trait DriverProbe {

#[cfg(bus = "pci")]
fn probe_pci(
_root: &mut PciRoot,
_root: &mut PciRoot<MmioCam>,
_bdf: DeviceFunction,
_dev_info: &DeviceFunctionInfo,
) -> Option<AxDeviceEnum> {
Expand Down Expand Up @@ -68,19 +68,19 @@ register_net_driver!(
#[cfg(block_dev = "virtio-blk")]
register_block_driver!(
<virtio::VirtIoBlk as VirtIoDevMeta>::Driver,
<virtio::VirtIoBlk as VirtIoDevMeta>::Device
<virtio::VirtIoBlk as VirtIoDevMeta>::Device<'static>
);

#[cfg(display_dev = "virtio-gpu")]
register_display_driver!(
<virtio::VirtIoGpu as VirtIoDevMeta>::Driver,
<virtio::VirtIoGpu as VirtIoDevMeta>::Device
<virtio::VirtIoGpu as VirtIoDevMeta>::Device<'static>
);

#[cfg(_9p_dev = "virtio-9p")]
register_9p_driver!(
<virtio::VirtIo9p as VirtIoDevMeta>::Driver,
<virtio::VirtIo9p as VirtIoDevMeta>::Device
<virtio::VirtIo9p as VirtIoDevMeta>::Device<'static>
);

cfg_if::cfg_if! {
Expand Down Expand Up @@ -121,7 +121,7 @@ cfg_if::cfg_if! {
register_net_driver!(IxgbeDriver, driver_net::ixgbe::IxgbeNic<IxgbeHalImpl, 1024, 1>);
impl DriverProbe for IxgbeDriver {
fn probe_pci(
root: &mut driver_pci::PciRoot,
root: &mut driver_pci::PciRoot<MmioCam>,
bdf: driver_pci::DeviceFunction,
dev_info: &driver_pci::DeviceFunctionInfo,
) -> Option<crate::AxDeviceEnum> {
Expand All @@ -136,7 +136,7 @@ cfg_if::cfg_if! {
const QN: u16 = 1;
const QS: usize = 1024;
let bar_info = root.bar_info(bdf, 0).unwrap();
match bar_info {
match bar_info.unwrap() {
driver_pci::BarInfo::Memory {
address,
size,
Expand Down
33 changes: 16 additions & 17 deletions modules/ruxdriver/src/virtio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,24 @@ use ruxhal::virtio::virtio_hal::VirtIoHalImpl;

cfg_if! {
if #[cfg(bus = "pci")] {
use driver_pci::{PciRoot, DeviceFunction, DeviceFunctionInfo};
type VirtIoTransport = driver_virtio::PciTransport;
use driver_pci::{PciRoot, DeviceFunction, DeviceFunctionInfo, ConfigurationAccess, MmioCam};
type VirtIoTransport<'a> = driver_virtio::PciTransport;
} else if #[cfg(bus = "mmio")] {
type VirtIoTransport = driver_virtio::MmioTransport;
type VirtIoTransport<'a> = driver_virtio::MmioTransport<'a>;
}
}

/// A trait for VirtIO device meta information.
pub trait VirtIoDevMeta {
/// The device type of the VirtIO device.
const DEVICE_TYPE: DeviceType;

/// The device type of the VirtIO device.
type Device: BaseDriverOps;
type Device<'a>: BaseDriverOps + 'static;
/// The driver for the VirtIO device.
type Driver = VirtIoDriver<Self>;

/// Try to create a new instance of the VirtIO device.
fn try_new(transport: VirtIoTransport) -> DevResult<AxDeviceEnum>;
/// Try to create a new instance of the VirtIO device.Z
fn try_new(transport: VirtIoTransport<'static>) -> DevResult<AxDeviceEnum>;
}

cfg_if! {
Expand All @@ -54,9 +53,9 @@ cfg_if! {

impl VirtIoDevMeta for VirtIoNet {
const DEVICE_TYPE: DeviceType = DeviceType::Net;
type Device = driver_virtio::VirtIoNetDev<VirtIoHalImpl, VirtIoTransport, 64>;
type Device<'a> = driver_virtio::VirtIoNetDev<VirtIoHalImpl, VirtIoTransport<'static>, 64>;

fn try_new(transport: VirtIoTransport) -> DevResult<AxDeviceEnum> {
fn try_new(transport: VirtIoTransport<'static>) -> DevResult<AxDeviceEnum> {
Ok(AxDeviceEnum::from_net(Self::Device::try_new(transport)?))
}
}
Expand All @@ -70,9 +69,9 @@ cfg_if! {

impl VirtIoDevMeta for VirtIoBlk {
const DEVICE_TYPE: DeviceType = DeviceType::Block;
type Device = driver_virtio::VirtIoBlkDev<VirtIoHalImpl, VirtIoTransport>;
type Device<'a> = driver_virtio::VirtIoBlkDev<VirtIoHalImpl, VirtIoTransport<'static>>;

fn try_new(transport: VirtIoTransport) -> DevResult<AxDeviceEnum> {
fn try_new(transport: VirtIoTransport<'static>) -> DevResult<AxDeviceEnum> {
Ok(AxDeviceEnum::from_block(Self::Device::try_new(transport)?))
}
}
Expand All @@ -86,9 +85,9 @@ cfg_if! {

impl VirtIoDevMeta for VirtIoGpu {
const DEVICE_TYPE: DeviceType = DeviceType::Display;
type Device = driver_virtio::VirtIoGpuDev<VirtIoHalImpl, VirtIoTransport>;
type Device<'a> = driver_virtio::VirtIoGpuDev<VirtIoHalImpl, VirtIoTransport<'static>>;

fn try_new(transport: VirtIoTransport) -> DevResult<AxDeviceEnum> {
fn try_new(transport: VirtIoTransport<'static>) -> DevResult<AxDeviceEnum> {
Ok(AxDeviceEnum::from_display(Self::Device::try_new(transport)?))
}
}
Expand All @@ -102,9 +101,9 @@ cfg_if! {

impl VirtIoDevMeta for VirtIo9p {
const DEVICE_TYPE: DeviceType = DeviceType::_9P;
type Device = driver_virtio::VirtIo9pDev<VirtIoHalImpl, VirtIoTransport>;
type Device<'a> = driver_virtio::VirtIo9pDev<VirtIoHalImpl, VirtIoTransport<'static>>;

fn try_new(transport: VirtIoTransport) -> DevResult<AxDeviceEnum> {
fn try_new(transport: VirtIoTransport<'static>) -> DevResult<AxDeviceEnum> {
Ok(AxDeviceEnum::from_9p(Self::Device::try_new(transport)?))
}
}
Expand Down Expand Up @@ -141,7 +140,7 @@ impl<D: VirtIoDevMeta> DriverProbe for VirtIoDriver<D> {

#[cfg(bus = "pci")]
fn probe_pci(
root: &mut PciRoot,
root: &mut PciRoot<MmioCam>,
bdf: DeviceFunction,
dev_info: &DeviceFunctionInfo,
) -> Option<AxDeviceEnum> {
Expand All @@ -157,7 +156,7 @@ impl<D: VirtIoDevMeta> DriverProbe for VirtIoDriver<D> {
}

if let Some((ty, transport)) =
driver_virtio::probe_pci_device::<VirtIoHalImpl>(root, bdf, dev_info)
driver_virtio::probe_pci_device::<VirtIoHalImpl, MmioCam>(root, bdf, dev_info)
{
if ty == D::DEVICE_TYPE {
match D::try_new(transport) {
Expand Down
2 changes: 1 addition & 1 deletion modules/ruxhal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ percpu = "0.2"
driver_console = { path = "../../crates/driver_console", optional = true }
driver_virtio = { path = "../../crates/driver_virtio", optional = true }
driver_common = { path = "../../crates/driver_common", optional = true }
virtio-drivers = { git = "https://github.com/syswonder/virtio-drivers.git", rev = "62dbe5a", optional = true }
virtio-drivers = { git = "https://github.com/syswonder/virtio-drivers.git", rev = "31f6555", optional = true }
lazy_static = { version = "1.4", features = ["spin_no_std"] }
memory_addr = "0.1.0"
handler_table = "0.1.0"
Expand Down
Loading
Loading