From 0be1b1e56bc8d6ef5f76973c5723ccf237f4defa Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Fri, 24 May 2019 16:45:28 +0800 Subject: [PATCH] Support 32bit MSI Addr --- kernel/Cargo.lock | 1 + kernel/Cargo.toml | 2 +- kernel/src/drivers/bus/pci.rs | 17 +++++++++++++---- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/kernel/Cargo.lock b/kernel/Cargo.lock index c3a5aeb..03a2328 100644 --- a/kernel/Cargo.lock +++ b/kernel/Cargo.lock @@ -208,6 +208,7 @@ source = "git+https://github.com/rcore-os/isomorphic_drivers#fe4af36d5f7bf3ac32b dependencies = [ "bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "volatile 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 0b67d6b..26bccb0 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -59,7 +59,7 @@ console-traits = "0.3" buddy_system_allocator = "0.3" pci = { git = "https://github.com/rcore-os/pci-rs" } device_tree = { git = "https://github.com/rcore-os/device_tree-rs" } -isomorphic_drivers = { git = "https://github.com/rcore-os/isomorphic_drivers" } +isomorphic_drivers = { git = "https://github.com/rcore-os/isomorphic_drivers", features = ["log"] } lazy_static = { version = "1.3", features = ["spin_no_std"] } smoltcp = { git = "https://github.com/rcore-os/smoltcp", default-features = false, features = ["alloc", "log", "proto-ipv4", "proto-igmp", "socket-icmp", "socket-udp", "socket-tcp", "socket-raw"] } bitmap-allocator = { git = "https://github.com/rcore-os/bitmap-allocator" } diff --git a/kernel/src/drivers/bus/pci.rs b/kernel/src/drivers/bus/pci.rs index 1c6f103..7640dfe 100644 --- a/kernel/src/drivers/bus/pci.rs +++ b/kernel/src/drivers/bus/pci.rs @@ -16,7 +16,8 @@ const PCI_INTERRUPT_PIN: u16 = 0x3d; const PCI_MSI_CTRL_CAP: u16 = 0x00; const PCI_MSI_ADDR: u16 = 0x04; const PCI_MSI_UPPER_ADDR: u16 = 0x08; -const PCI_MSI_DATA: u16 = 0x0C; +const PCI_MSI_DATA_32: u16 = 0x08; +const PCI_MSI_DATA_64: u16 = 0x0C; const PCI_CAP_ID_MSI: u8 = 0x05; @@ -94,6 +95,7 @@ unsafe fn enable(loc: Location) -> Option { while cap_ptr > 0 { let cap_id = am.read8(ops, loc, cap_ptr); if cap_id == PCI_CAP_ID_MSI { + let orig_ctrl = am.read32(ops, loc, cap_ptr + PCI_MSI_CTRL_CAP); // The manual Volume 3 Chapter 10.11 Message Signalled Interrupts // 0 is (usually) the apic id of the bsp. am.write32(ops, loc, cap_ptr + PCI_MSI_ADDR, 0xfee00000 | (0 << 12)); @@ -101,10 +103,15 @@ unsafe fn enable(loc: Location) -> Option { let irq = MSI_IRQ; assigned_irq = Some(irq); // we offset all our irq numbers by 32 - am.write32(ops, loc, cap_ptr + PCI_MSI_DATA, irq + 32); + if (orig_ctrl >> 16) & (1 << 7) != 0 { + // 64bit + am.write32(ops, loc, cap_ptr + PCI_MSI_DATA_64, irq + 32); + } else { + // 32bit + am.write32(ops, loc, cap_ptr + PCI_MSI_DATA_32, irq + 32); + } // enable MSI interrupt, assuming 64bit for now - let orig_ctrl = am.read32(ops, loc, cap_ptr + PCI_MSI_CTRL_CAP); am.write32(ops, loc, cap_ptr + PCI_MSI_CTRL_CAP, orig_ctrl | 0x10000); debug!( "MSI control {:#b}, enabling MSI interrupt {}", @@ -112,7 +119,6 @@ unsafe fn enable(loc: Location) -> Option { irq ); msi_found = true; - break; } debug!("PCI device has cap id {} at {:#X}", cap_id, cap_ptr); cap_ptr = am.read8(ops, loc, cap_ptr + 1) as u16; @@ -125,6 +131,8 @@ unsafe fn enable(loc: Location) -> Option { debug!("MSI not found, using PCI interrupt"); } + info!("pci device enable done"); + assigned_irq } @@ -162,6 +170,7 @@ pub fn init_driver(dev: &PCIDevice) { // 200 Series PCH SATA controller [AHCI mode] // C610/X99 series chipset 6-Port SATA Controller [AHCI mode] if let Some(BAR::Memory(addr, len, _, _)) = dev.bars[5] { + info!("Found AHCI dev {:?} BAR5 {:x?}", dev, addr); let irq = unsafe { enable(dev.loc) }; assert!(len as usize <= PAGE_SIZE); let vaddr = phys_to_virt(addr as usize);