Skip to content
Open
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
35 changes: 24 additions & 11 deletions Cargo.lock

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

21 changes: 12 additions & 9 deletions modules/axdriver/src/bus/pci.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use axdriver_pci::{
BarInfo, Cam, Command, DeviceFunction, HeaderType, MemoryBarType, PciRangeAllocator, PciRoot,
BarInfo, Cam, Command, ConfigurationAccess, DeviceFunction, HeaderType, MemoryBarType,
MmioCam, PciRangeAllocator, PciRoot,
};
use axhal::mem::phys_to_virt;

Expand All @@ -8,19 +9,19 @@ use crate::{AllDevices, prelude::*};
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 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 @@ -40,17 +41,17 @@ fn config_pci_device(
// read the BAR info again after assignment.
let info = root.bar_info(bdf, bar).unwrap();
match info {
BarInfo::IO { address, size } => {
Some(BarInfo::IO { address, size }) => {
if address > 0 && size > 0 {
debug!(" BAR {}: IO [{:#x}, {:#x})", bar, address, address + size);
}
}
BarInfo::Memory {
Some(BarInfo::Memory {
address_type,
prefetchable,
address,
size,
} => {
}) => {
if address > 0 && size > 0 {
debug!(
" BAR {}: MEM [{:#x}, {:#x}){}{}",
Expand All @@ -66,10 +67,11 @@ fn config_pci_device(
);
}
}
None => {}
}

bar += 1;
if info.takes_two_entries() {
if info.as_ref().is_some_and(BarInfo::takes_two_entries) {
bar += 1;
}
}
Expand All @@ -86,7 +88,8 @@ fn config_pci_device(
impl AllDevices {
pub(crate) fn probe_bus_devices(&mut self) {
let base_vaddr = phys_to_virt(axconfig::devices::PCI_ECAM_BASE.into());
let mut root = unsafe { PciRoot::new(base_vaddr.as_mut_ptr(), Cam::Ecam) };
let cam = unsafe { MmioCam::new(base_vaddr.as_mut_ptr(), Cam::Ecam) };
let mut root = PciRoot::new(cam);

// PCI 32-bit MMIO space
let mut allocator = axconfig::devices::PCI_RANGES
Expand Down
6 changes: 3 additions & 3 deletions modules/axdriver/src/drivers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

pub use super::dummy::*;
use crate::AxDeviceEnum;
Expand All @@ -22,8 +22,8 @@ pub trait DriverProbe {
}

#[cfg(bus = "pci")]
fn probe_pci(
_root: &mut PciRoot,
fn probe_pci<C: ConfigurationAccess>(
_root: &mut PciRoot<C>,
_bdf: DeviceFunction,
_dev_info: &DeviceFunctionInfo,
) -> Option<AxDeviceEnum> {
Expand Down
16 changes: 8 additions & 8 deletions modules/axdriver/src/virtio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use crate::{AxDeviceEnum, drivers::DriverProbe};

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

Expand Down Expand Up @@ -130,8 +130,8 @@ impl<D: VirtIoDevMeta> DriverProbe for VirtIoDriver<D> {
}

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

if let Some((ty, transport, irq)) =
axdriver_virtio::probe_pci_device::<VirtIoHalImpl>(root, bdf, dev_info)
axdriver_virtio::probe_pci_device::<VirtIoHalImpl, C>(root, bdf, dev_info)
&& ty == D::DEVICE_TYPE
{
match D::try_new(transport, Some(irq)) {
Expand All @@ -175,7 +175,7 @@ unsafe impl VirtIoHal for VirtIoHalImpl {
};
let paddr = virt_to_phys(vaddr.into());
let ptr = NonNull::new(vaddr as _).unwrap();
(paddr.as_usize(), ptr)
(paddr.as_usize() as PhysAddr, ptr)
}

unsafe fn dma_dealloc(_paddr: PhysAddr, vaddr: NonNull<u8>, pages: usize) -> i32 {
Expand All @@ -185,13 +185,13 @@ unsafe impl VirtIoHal for VirtIoHalImpl {

#[inline]
unsafe fn mmio_phys_to_virt(paddr: PhysAddr, _size: usize) -> NonNull<u8> {
NonNull::new(phys_to_virt(paddr.into()).as_mut_ptr()).unwrap()
NonNull::new(phys_to_virt((paddr as usize).into()).as_mut_ptr()).unwrap()
}

#[inline]
unsafe fn share(buffer: NonNull<[u8]>, _direction: BufferDirection) -> PhysAddr {
let vaddr = buffer.as_ptr() as *mut u8 as usize;
virt_to_phys(vaddr.into()).into()
virt_to_phys(vaddr.into()).as_usize() as PhysAddr
}

#[inline]
Expand Down
Loading