1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-23 00:16:17 +04:00

Use IRQ_MANAGER in drivers

This commit is contained in:
Jiajie Chen 2019-06-30 01:11:40 +08:00
parent dec07da035
commit e77e09a949
12 changed files with 42 additions and 35 deletions

View File

@ -1,6 +1,6 @@
pub use self::context::*; pub use self::context::*;
use crate::arch::paging::get_root_page_table_ptr; use crate::arch::paging::get_root_page_table_ptr;
use crate::drivers::DRIVERS; use crate::drivers::{DRIVERS, IRQ_MANAGER};
use log::*; use log::*;
use mips::addr::*; use mips::addr::*;
use mips::interrupts; use mips::interrupts;
@ -131,13 +131,7 @@ fn try_process_serial() -> bool {
} }
fn try_process_drivers() -> bool { fn try_process_drivers() -> bool {
// TODO IRQ_MANAGER.read().try_handle_interrupt(None)
for driver in DRIVERS.read().iter() {
if driver.try_handle_interrupt(None) == true {
return true;
}
}
return false;
} }
fn ipi() { fn ipi() {

View File

@ -1,5 +1,5 @@
pub use self::context::*; pub use self::context::*;
use crate::drivers::DRIVERS; use crate::drivers::{DRIVERS, IRQ_MANAGER};
use log::*; use log::*;
use riscv::register::*; use riscv::register::*;
@ -99,12 +99,7 @@ fn try_process_serial() -> bool {
} }
fn try_process_drivers() -> bool { fn try_process_drivers() -> bool {
for driver in DRIVERS.read().iter() { IRQ_MANAGER.read().try_handle_interrupt(None)
if driver.try_handle_interrupt(None) == true {
return true;
}
}
return false;
} }
fn ipi() { fn ipi() {

View File

@ -66,7 +66,7 @@
use super::consts::*; use super::consts::*;
use super::TrapFrame; use super::TrapFrame;
use crate::drivers::DRIVERS; use crate::drivers::{DRIVERS, IRQ_MANAGER};
use bitflags::*; use bitflags::*;
use log::*; use log::*;
@ -96,11 +96,9 @@ pub extern "C" fn rust_trap(tf: &mut TrapFrame) {
COM2 => com2(), COM2 => com2(),
IDE => ide(), IDE => ide(),
_ => { _ => {
for driver in DRIVERS.read().iter() { if IRQ_MANAGER.read().try_handle_interrupt(Some(irq.into())) {
if driver.try_handle_interrupt(Some(irq.into())) == true { debug!("driver processed interrupt");
debug!("driver processed interrupt"); return;
return;
}
} }
warn!("unhandled external IRQ number: {}", irq); warn!("unhandled external IRQ number: {}", irq);
} }

View File

@ -14,7 +14,7 @@ use volatile::Volatile;
use crate::sync::SpinNoIrqLock as Mutex; use crate::sync::SpinNoIrqLock as Mutex;
use super::super::bus::virtio_mmio::*; use super::super::bus::virtio_mmio::*;
use super::super::{DeviceType, Driver, BLK_DRIVERS, DRIVERS}; use super::super::{DeviceType, Driver, BLK_DRIVERS, DRIVERS, IRQ_MANAGER};
use crate::memory::phys_to_virt; use crate::memory::phys_to_virt;
pub struct VirtIOBlk { pub struct VirtIOBlk {
@ -213,5 +213,6 @@ pub fn virtio_blk_init(node: &Node) {
let driver = Arc::new(driver); let driver = Arc::new(driver);
DRIVERS.write().push(driver.clone()); DRIVERS.write().push(driver.clone());
IRQ_MANAGER.write().register_all(driver.clone());
BLK_DRIVERS.write().push(driver); BLK_DRIVERS.write().push(driver);
} }

View File

@ -16,7 +16,7 @@ use crate::sync::SpinNoIrqLock as Mutex;
use crate::HEAP_ALLOCATOR; use crate::HEAP_ALLOCATOR;
use super::super::bus::virtio_mmio::*; use super::super::bus::virtio_mmio::*;
use super::super::{DeviceType, Driver, DRIVERS}; use super::super::{DeviceType, Driver, DRIVERS, IRQ_MANAGER};
use super::test::mandelbrot; use super::test::mandelbrot;
use crate::memory::phys_to_virt; use crate::memory::phys_to_virt;
@ -399,5 +399,6 @@ pub fn virtio_gpu_init(node: &Node) {
setup_framebuffer(&mut driver); setup_framebuffer(&mut driver);
let driver = Arc::new(VirtIOGpuDriver(Mutex::new(driver))); let driver = Arc::new(VirtIOGpuDriver(Mutex::new(driver)));
IRQ_MANAGER.write().register_all(driver.clone());
DRIVERS.write().push(driver); DRIVERS.write().push(driver);
} }

View File

@ -18,7 +18,7 @@ use crate::arch::cpu;
use crate::sync::SpinNoIrqLock as Mutex; use crate::sync::SpinNoIrqLock as Mutex;
use super::super::bus::virtio_mmio::*; use super::super::bus::virtio_mmio::*;
use super::super::{DeviceType, Driver, DRIVERS}; use super::super::{DeviceType, Driver, DRIVERS, IRQ_MANAGER};
use crate::memory::phys_to_virt; use crate::memory::phys_to_virt;
struct VirtIOInput { struct VirtIOInput {
@ -222,5 +222,6 @@ pub fn virtio_input_init(node: &Node) {
.write(VirtIODeviceStatus::DRIVER_OK.bits()); .write(VirtIODeviceStatus::DRIVER_OK.bits());
let driver = Arc::new(VirtIOInputDriver(Mutex::new(driver))); let driver = Arc::new(VirtIOInputDriver(Mutex::new(driver)));
IRQ_MANAGER.write().register_all(driver.clone());
DRIVERS.write().push(driver); DRIVERS.write().push(driver);
} }

View File

@ -4,7 +4,7 @@ use alloc::collections::BTreeMap;
use alloc::sync::Arc; use alloc::sync::Arc;
use alloc::vec::Vec; use alloc::vec::Vec;
struct IrqManager { pub struct IrqManager {
// drivers that only respond to specific irq // drivers that only respond to specific irq
mapping: BTreeMap<u32, Vec<Arc<Driver>>>, mapping: BTreeMap<u32, Vec<Arc<Driver>>>,
// drivers that respond to all irqs // drivers that respond to all irqs
@ -36,6 +36,14 @@ impl IrqManager {
self.all.push(driver); self.all.push(driver);
} }
pub fn register_opt(&mut self, irq_opt: Option<u32>, driver: Arc<Driver>) {
if let Some(irq) = irq_opt {
self.register_irq(irq, driver);
} else {
self.register_all(driver);
}
}
pub fn deregister_irq(&mut self, irq: u32, driver: Arc<Driver>) { pub fn deregister_irq(&mut self, irq: u32, driver: Arc<Driver>) {
if let Some(e) = self.mapping.get_mut(&irq) { if let Some(e) = self.mapping.get_mut(&irq) {
e.retain(|d| !Arc::ptr_eq(&d, &driver)); e.retain(|d| !Arc::ptr_eq(&d, &driver));
@ -46,17 +54,19 @@ impl IrqManager {
self.all.retain(|d| !Arc::ptr_eq(&d, &driver)); self.all.retain(|d| !Arc::ptr_eq(&d, &driver));
} }
pub fn handle_interrupt(&self, irq: u32) -> bool { pub fn try_handle_interrupt(&self, irq_opt: Option<u32>) -> bool {
if let Some(e) = self.mapping.get(&irq) { if let Some(irq) = irq_opt {
for dri in e.iter() { if let Some(e) = self.mapping.get(&irq) {
if dri.try_handle_interrupt(Some(irq)) { for dri in e.iter() {
return true; if dri.try_handle_interrupt(Some(irq)) {
return true;
}
} }
} }
} }
for dri in self.all.iter() { for dri in self.all.iter() {
if dri.try_handle_interrupt(Some(irq)) { if dri.try_handle_interrupt(irq_opt) {
return true; return true;
} }
} }

View File

@ -97,6 +97,7 @@ lazy_static! {
pub static ref DRIVERS: RwLock<Vec<Arc<Driver>>> = RwLock::new(Vec::new()); pub static ref DRIVERS: RwLock<Vec<Arc<Driver>>> = RwLock::new(Vec::new());
pub static ref NET_DRIVERS: RwLock<Vec<Arc<Driver>>> = RwLock::new(Vec::new()); pub static ref NET_DRIVERS: RwLock<Vec<Arc<Driver>>> = RwLock::new(Vec::new());
pub static ref BLK_DRIVERS: RwLock<Vec<Arc<Driver>>> = RwLock::new(Vec::new()); pub static ref BLK_DRIVERS: RwLock<Vec<Arc<Driver>>> = RwLock::new(Vec::new());
pub static ref IRQ_MANAGER: RwLock<irq::IrqManager> = RwLock::new(irq::IrqManager::new());
} }
pub struct BlockDriver(pub Arc<Driver>); pub struct BlockDriver(pub Arc<Driver>);

View File

@ -20,7 +20,7 @@ use crate::drivers::provider::Provider;
use crate::net::SOCKETS; use crate::net::SOCKETS;
use crate::sync::SpinNoIrqLock as Mutex; use crate::sync::SpinNoIrqLock as Mutex;
use super::super::{DeviceType, Driver, DRIVERS, NET_DRIVERS, SOCKET_ACTIVITY}; use super::super::{DeviceType, Driver, DRIVERS, IRQ_MANAGER, NET_DRIVERS, SOCKET_ACTIVITY};
#[derive(Clone)] #[derive(Clone)]
pub struct E1000Driver(Arc<Mutex<E1000<Provider>>>); pub struct E1000Driver(Arc<Mutex<E1000<Provider>>>);
@ -202,5 +202,6 @@ pub fn init(name: String, irq: Option<u32>, header: usize, size: usize, index: u
let driver = Arc::new(e1000_iface); let driver = Arc::new(e1000_iface);
DRIVERS.write().push(driver.clone()); DRIVERS.write().push(driver.clone());
IRQ_MANAGER.write().register_opt(irq, driver.clone());
NET_DRIVERS.write().push(driver); NET_DRIVERS.write().push(driver);
} }

View File

@ -19,7 +19,9 @@ use crate::net::SOCKETS;
use crate::sync::FlagsGuard; use crate::sync::FlagsGuard;
use crate::sync::SpinNoIrqLock as Mutex; use crate::sync::SpinNoIrqLock as Mutex;
use super::super::{provider::Provider, DeviceType, Driver, DRIVERS, NET_DRIVERS, SOCKET_ACTIVITY}; use super::super::{
provider::Provider, DeviceType, Driver, DRIVERS, IRQ_MANAGER, NET_DRIVERS, SOCKET_ACTIVITY,
};
#[derive(Clone)] #[derive(Clone)]
struct IXGBEDriver { struct IXGBEDriver {
@ -220,6 +222,7 @@ pub fn ixgbe_init(
}; };
let driver = Arc::new(ixgbe_iface); let driver = Arc::new(ixgbe_iface);
IRQ_MANAGER.write().register_opt(irq, driver.clone());
DRIVERS.write().push(driver.clone()); DRIVERS.write().push(driver.clone());
NET_DRIVERS.write().push(driver.clone()); NET_DRIVERS.write().push(driver.clone());
driver driver

View File

@ -15,7 +15,7 @@ use smoltcp::Result;
use crate::net::SOCKETS; use crate::net::SOCKETS;
use crate::sync::SpinNoIrqLock as Mutex; use crate::sync::SpinNoIrqLock as Mutex;
use super::super::{DeviceType, Driver, DRIVERS, NET_DRIVERS, SOCKET_ACTIVITY}; use super::super::{DeviceType, Driver, DRIVERS, IRQ_MANAGER, NET_DRIVERS, SOCKET_ACTIVITY};
use crate::memory::phys_to_virt; use crate::memory::phys_to_virt;
const AXI_STREAM_FIFO_ISR: *mut u32 = phys_to_virt(0x64A0_0000) as *mut u32; const AXI_STREAM_FIFO_ISR: *mut u32 = phys_to_virt(0x64A0_0000) as *mut u32;
@ -253,6 +253,7 @@ pub fn router_init() {
let driver = Arc::new(router_iface); let driver = Arc::new(router_iface);
DRIVERS.write().push(driver.clone()); DRIVERS.write().push(driver.clone());
IRQ_MANAGER.write().register_all(driver.clone());
NET_DRIVERS.write().push(driver.clone()); NET_DRIVERS.write().push(driver.clone());
} }

View File

@ -20,7 +20,7 @@ use crate::sync::SpinNoIrqLock as Mutex;
use crate::HEAP_ALLOCATOR; use crate::HEAP_ALLOCATOR;
use super::super::bus::virtio_mmio::*; use super::super::bus::virtio_mmio::*;
use super::super::{DeviceType, Driver, DRIVERS, NET_DRIVERS}; use super::super::{DeviceType, Driver, DRIVERS, IRQ_MANAGER, NET_DRIVERS};
use crate::memory::phys_to_virt; use crate::memory::phys_to_virt;
pub struct VirtIONet { pub struct VirtIONet {
@ -290,5 +290,6 @@ pub fn virtio_net_init(node: &Node) {
let net_driver = Arc::new(VirtIONetDriver(Arc::new(Mutex::new(driver)))); let net_driver = Arc::new(VirtIONetDriver(Arc::new(Mutex::new(driver))));
DRIVERS.write().push(net_driver.clone()); DRIVERS.write().push(net_driver.clone());
IRQ_MANAGER.write().register_all(net_driver.clone());
NET_DRIVERS.write().push(net_driver); NET_DRIVERS.write().push(net_driver);
} }