Change the method to identify the legacy virtio device
This commit is contained in:
parent
cc280272cc
commit
fc72398fbc
|
|
@ -8,6 +8,8 @@ use log::info;
|
|||
use ostd::arch::kernel::MappedIrqLine;
|
||||
#[cfg(target_arch = "riscv64")] // TODO: Add `MappedIrqLine` support for RISC-V.
|
||||
use ostd::trap::irq::IrqLine as MappedIrqLine;
|
||||
#[cfg(target_arch = "loongarch64")] // TODO: Add `MappedIrqLine` support for Loongarch.
|
||||
use ostd::trap::irq::IrqLine as MappedIrqLine;
|
||||
use ostd::{io::IoMem, mm::VmIoOnce, trap::irq::IrqLine, Error, Result};
|
||||
|
||||
/// A MMIO common device.
|
||||
|
|
|
|||
|
|
@ -272,12 +272,13 @@ impl VirtioPciModernTransport {
|
|||
common_device: PciCommonDevice,
|
||||
) -> Result<Self, (BusProbeError, PciCommonDevice)> {
|
||||
let device_id = common_device.device_id().device_id;
|
||||
if device_id <= 0x1040 {
|
||||
warn!("Unrecognized virtio-pci device id:{:x?}", device_id);
|
||||
return Err((BusProbeError::DeviceNotMatch, common_device));
|
||||
}
|
||||
let device_type_value = if device_id <= 0x1040 {
|
||||
device_id - 0x1000
|
||||
} else {
|
||||
device_id - 0x1040
|
||||
};
|
||||
|
||||
let device_type = match VirtioDeviceType::try_from((device_id - 0x1040) as u8) {
|
||||
let device_type = match VirtioDeviceType::try_from(device_type_value as u8) {
|
||||
Ok(device) => device,
|
||||
Err(_) => {
|
||||
warn!("Unrecognized virtio-pci device id:{:x?}", device_id);
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use ostd::{
|
|||
bus::{
|
||||
pci::{
|
||||
bus::{PciDevice, PciDriver},
|
||||
capability::CapabilityData,
|
||||
common_device::PciCommonDevice,
|
||||
},
|
||||
BusProbeError,
|
||||
|
|
@ -46,14 +47,25 @@ impl PciDriver for VirtioPciDriver {
|
|||
return Err((BusProbeError::DeviceNotMatch, device));
|
||||
}
|
||||
|
||||
let has_vendor_cap = device
|
||||
.capabilities()
|
||||
.iter()
|
||||
.any(|cap| matches!(cap.capability_data(), CapabilityData::Vndr(_)));
|
||||
let device_id = *device.device_id();
|
||||
let transport: Box<dyn VirtioTransport> = match device_id.device_id {
|
||||
0x1000..0x1040 if (device.device_id().revision_id == 0) => {
|
||||
// Transitional PCI Device ID in the range 0x1000 to 0x103f.
|
||||
let legacy = VirtioPciLegacyTransport::new(device)?;
|
||||
Box::new(legacy)
|
||||
if has_vendor_cap {
|
||||
let modern = VirtioPciModernTransport::new(device)?;
|
||||
Box::new(modern)
|
||||
} else {
|
||||
let legacy = VirtioPciLegacyTransport::new(device)?;
|
||||
Box::new(legacy)
|
||||
}
|
||||
}
|
||||
0x1040..0x107f => {
|
||||
if !has_vendor_cap {
|
||||
return Err((BusProbeError::DeviceNotMatch, device));
|
||||
}
|
||||
let modern = VirtioPciModernTransport::new(device)?;
|
||||
Box::new(modern)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue