fix(virtio):修复了特定virtio设备环境下中断号重复错误,以及开机内核panic的bug (#881)

This commit is contained in:
曾俊
2024-09-06 19:56:49 +08:00
committed by GitHub
parent 2b7818e80e
commit 886ce28516
2 changed files with 15 additions and 4 deletions

View File

@ -115,6 +115,7 @@ impl PciTransport {
/// - `device` - The PCI device structure for the VirtIO device.
/// - `irq_handler` - An optional handler for the device's interrupt. If `None`, a default
/// handler `DefaultVirtioIrqHandler` will be used.
/// - `irq_number_offset` - Currently, this parameter is just simple make a offset to the irq number, cause it's not be allowed to have the same irq number within different device
#[allow(clippy::extra_unused_type_parameters)]
pub fn new<H: Hal>(
device: &mut PciDeviceStructureGeneralDevice,
@ -140,8 +141,8 @@ impl PciTransport {
let irq_vector = standard_device.irq_vector_mut().unwrap();
irq_vector.push(irq);
standard_device
.irq_init(IRQ::PCI_IRQ_MSIX)
.expect("IRQ init failed");
.irq_init(IRQ::PCI_IRQ_MSIX | IRQ::PCI_IRQ_MSI)
.ok_or(VirtioPciError::UnableToInitIrq)?;
// 中断相关信息
let msg = PciIrqMsg {
irq_common_message: IrqCommonMsg::init_from(
@ -445,6 +446,8 @@ pub enum VirtioPciError {
/// `VIRTIO_PCI_CAP_NOTIFY_CFG` capability has a `notify_off_multiplier` that is not a multiple
/// of 2.
InvalidNotifyOffMultiplier(u32),
/// Unable to find capability such as MSIX or MSI.
UnableToInitIrq,
/// No valid `VIRTIO_PCI_CAP_ISR_CFG` capability was found.
MissingIsrConfig,
/// An IO BAR was provided rather than a memory BAR.
@ -474,6 +477,7 @@ impl Display for VirtioPciError {
"PCI device vender ID {:#06x} was not the VirtIO vendor ID {:#06x}.",
vendor_id, VIRTIO_VENDOR_ID
),
Self::UnableToInitIrq => write!(f, "Unable to find capability such as MSIX or MSI."),
Self::MissingCommonConfig => write!(
f,
"No valid `VIRTIO_PCI_CAP_COMMON_CFG` capability was found."