forked from Azure-stars/arceos
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathdrivers.rs
130 lines (113 loc) · 4.3 KB
/
drivers.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//! Defines types and probe methods of all supported devices.
#![allow(unused_imports)]
use crate::AxDeviceEnum;
use driver_common::DeviceType;
#[cfg(feature = "virtio")]
use crate::virtio::{self, VirtIoDevMeta};
#[cfg(feature = "bus-pci")]
use driver_pci::{DeviceFunction, DeviceFunctionInfo, PciRoot};
pub use super::dummy::*;
pub trait DriverProbe {
fn probe_global() -> Option<AxDeviceEnum> {
None
}
#[cfg(bus = "mmio")]
fn probe_mmio(_mmio_base: usize, _mmio_size: usize) -> Option<AxDeviceEnum> {
None
}
#[cfg(bus = "pci")]
fn probe_pci(
_root: &mut PciRoot,
_bdf: DeviceFunction,
_dev_info: &DeviceFunctionInfo,
) -> Option<AxDeviceEnum> {
None
}
}
#[cfg(net_dev = "virtio-net")]
register_net_driver!(
<virtio::VirtIoNet as VirtIoDevMeta>::Driver,
<virtio::VirtIoNet as VirtIoDevMeta>::Device
);
#[cfg(block_dev = "virtio-blk")]
register_block_driver!(
<virtio::VirtIoBlk as VirtIoDevMeta>::Driver,
<virtio::VirtIoBlk as VirtIoDevMeta>::Device
);
#[cfg(display_dev = "virtio-gpu")]
register_display_driver!(
<virtio::VirtIoGpu as VirtIoDevMeta>::Driver,
<virtio::VirtIoGpu as VirtIoDevMeta>::Device
);
cfg_if::cfg_if! {
if #[cfg(block_dev = "ramdisk")] {
pub struct RamDiskDriver;
register_block_driver!(RamDiskDriver, driver_block::ramdisk::RamDisk);
impl DriverProbe for RamDiskDriver {
fn probe_global() -> Option<AxDeviceEnum> {
// TODO: format RAM disk
Some(AxDeviceEnum::from_block(
driver_block::ramdisk::RamDisk::new(0x100_0000), // 16 MiB
))
}
}
}
}
cfg_if::cfg_if! {
if #[cfg(block_dev = "bcm2835-sdhci")]{
pub struct BcmSdhciDriver;
register_block_driver!(MmckDriver, driver_block::bcm2835sdhci::SDHCIDriver);
impl DriverProbe for BcmSdhciDriver {
fn probe_global() -> Option<AxDeviceEnum> {
debug!("mmc probe");
driver_block::bcm2835sdhci::SDHCIDriver::try_new().ok().map(AxDeviceEnum::from_block)
}
}
}
}
cfg_if::cfg_if! {
if #[cfg(net_dev = "ixgbe")] {
use crate::ixgbe::IxgbeHalImpl;
use axhal::mem::phys_to_virt;
pub struct IxgbeDriver;
register_net_driver!(IxgbeDriver, driver_net::ixgbe::IxgbeNic<IxgbeHalImpl, 1024, 1>);
impl DriverProbe for IxgbeDriver {
fn probe_pci(
root: &mut driver_pci::PciRoot,
bdf: driver_pci::DeviceFunction,
dev_info: &driver_pci::DeviceFunctionInfo,
) -> Option<crate::AxDeviceEnum> {
use crate::ixgbe::IxgbeHalImpl;
use driver_net::ixgbe::{INTEL_82599, INTEL_VEND, IxgbeNic};
if dev_info.vendor_id == INTEL_VEND && dev_info.device_id == INTEL_82599 {
// Intel 10Gb Network
info!("ixgbe PCI device found at {:?}", bdf);
// Initialize the device
// These can be changed according to the requirments specified in the ixgbe init function.
const QN: u16 = 1;
const QS: usize = 1024;
let bar_info = root.bar_info(bdf, 0).unwrap();
match bar_info {
driver_pci::BarInfo::Memory {
address,
size,
..
} => {
let ixgbe_nic = IxgbeNic::<IxgbeHalImpl, QS, QN>::init(
phys_to_virt((address as usize).into()).into(),
size as usize
)
.expect("failed to initialize ixgbe device");
return Some(AxDeviceEnum::from_net(ixgbe_nic));
}
driver_pci::BarInfo::IO { .. } => {
error!("ixgbe: BAR0 is of I/O type");
return None;
}
}
}
None
}
}
}
}