Skip to content

Commit

Permalink
add interface to determine the name of a device driver
Browse files Browse the repository at this point in the history
  • Loading branch information
stlankes committed Sep 3, 2024
1 parent 3a761a2 commit 5afa00a
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 36 deletions.
5 changes: 1 addition & 4 deletions src/arch/riscv64/kernel/interrupts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ pub fn enable() {
}
}

#[cfg(all(feature = "pci", feature = "tcp"))]
pub fn add_irq_name(irq_number: u8, name: &'static str) {
warn!("add_irq_name({irq_number}, {name}) called but not implemented");
}
pub(crate) fn add_irq_name(_irq_number: u8, _name: &'static str) {}

/// Waits for the next interrupt (Only Supervisor-level software/timer interrupt for now)
/// and calls the specific handler
Expand Down
4 changes: 4 additions & 0 deletions src/drivers/fs/virtio_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ impl Driver for VirtioFsDriver {
fn get_interrupt_number(&self) -> InterruptLine {
self.irq
}

fn get_name(&self) -> &str {
"virtio"
}
}

/// Error module of virtios filesystem driver.
Expand Down
3 changes: 3 additions & 0 deletions src/drivers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ pub mod error {
pub(crate) trait Driver {
/// Returns the interrupt number of the device
fn get_interrupt_number(&self) -> InterruptLine;

/// Returns the device driver name
fn get_name(&self) -> &str;
}

pub(crate) fn init() {
Expand Down
4 changes: 4 additions & 0 deletions src/drivers/net/gem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,10 @@ impl Driver for GEMDriver {
fn get_interrupt_number(&self) -> InterruptLine {
self.irq
}

fn get_name(&self) -> &str {
"gem"
}
}

impl GEMDriver {
Expand Down
9 changes: 6 additions & 3 deletions src/drivers/net/rtl8139.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ impl Driver for RTL8139Driver {
fn get_interrupt_number(&self) -> InterruptLine {
self.irq
}

fn get_name(&self) -> &str {
"rtl8139"
}
}

impl RTL8139Driver {
Expand Down Expand Up @@ -571,9 +575,8 @@ pub(crate) fn init_device(
);
}

// Install interrupt handler for RTL8139
debug!("Install interrupt handler for RTL8139 at {}", irq);
add_irq_name(irq, "rtl8139_net");
info!("RTL8139 use interrupt line {}", irq);
add_irq_name(irq, "rtl8139");

Ok(RTL8139Driver {
iobase,
Expand Down
4 changes: 4 additions & 0 deletions src/drivers/net/virtio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,10 @@ impl Driver for VirtioNetDriver {
fn get_interrupt_number(&self) -> InterruptLine {
self.irq
}

fn get_name(&self) -> &str {
"virtio"
}
}

// Backend-independent interface for Virtio network driver
Expand Down
6 changes: 4 additions & 2 deletions src/drivers/virtio/transport/mmio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,9 @@ pub(crate) fn init_device(
virtio::Id::Net => match VirtioNetDriver::init(dev_id, registers, irq_no) {
Ok(virt_net_drv) => {
info!("Virtio network driver initialized.");
#[cfg(not(target_arch = "riscv64"))]

crate::arch::interrupts::add_irq_name(irq_no, "virtio");
info!("Virtio interrupt handler at line {}", irq_no);

Ok(VirtioDriver::Network(virt_net_drv))
}
Expand All @@ -383,8 +384,9 @@ pub(crate) fn init_device(
virtio::Id::Vsock => match VirtioVsockDriver::init(dev_id, registers, irq_no) {
Ok(virt_net_drv) => {
info!("Virtio sock driver initialized.");
#[cfg(not(target_arch = "riscv64"))]

crate::arch::interrupts::add_irq_name(irq_no, "virtio");
info!("Virtio interrupt handler at line {}", irq_no);

Ok(VirtioDriver::Vsock(virt_vsock_drv))
}
Expand Down
38 changes: 11 additions & 27 deletions src/drivers/virtio/transport/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -888,11 +888,16 @@ pub(crate) fn init_device(

let id = virtio::Id::from(u8::try_from(device_id - 0x1040).unwrap());

let virt_drv = match id {
match id {
#[cfg(all(not(feature = "rtl8139"), any(feature = "tcp", feature = "udp")))]
virtio::Id::Net => match VirtioNetDriver::init(device) {
Ok(virt_net_drv) => {
info!("Virtio network driver initialized.");

let irq = device.get_irq().unwrap();
crate::arch::interrupts::add_irq_name(irq, "virtio");
info!("Virtio interrupt handler at line {}", irq);

Ok(VirtioDriver::Network(virt_net_drv))
}
Err(virtio_error) => {
Expand All @@ -907,6 +912,11 @@ pub(crate) fn init_device(
virtio::Id::Vsock => match VirtioVsockDriver::init(device) {
Ok(virt_sock_drv) => {
info!("Virtio sock driver initialized.");

let irq = device.get_irq().unwrap();
crate::arch::interrupts::add_irq_name(irq, "virtio");
info!("Virtio interrupt handler at line {}", irq);

Ok(VirtioDriver::Vsock(virt_sock_drv))
}
Err(virtio_error) => {
Expand Down Expand Up @@ -943,32 +953,6 @@ pub(crate) fn init_device(
VirtioError::DevNotSupported(device_id),
))
}
};

match virt_drv {
Ok(drv) => match &drv {
#[cfg(all(not(feature = "rtl8139"), any(feature = "tcp", feature = "udp")))]
VirtioDriver::Network(_) => {
let irq = device.get_irq().unwrap();

info!("Install virtio interrupt handler at line {}", irq);
crate::arch::interrupts::add_irq_name(irq, "virtio");

Ok(drv)
}
#[cfg(feature = "vsock")]
VirtioDriver::Vsock(_) => {
let irq = device.get_irq().unwrap();

info!("Install virtio interrupt handler at line {}", irq);
crate::arch::interrupts::add_irq_name(irq, "virtio");

Ok(drv)
}
#[cfg(feature = "fuse")]
VirtioDriver::FileSystem(_) => Ok(drv),
},
Err(virt_err) => Err(virt_err),
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/drivers/vsock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ impl Driver for VirtioVsockDriver {
fn get_interrupt_number(&self) -> InterruptLine {
self.irq
}

fn get_name(&self) -> &str {
"virtio"
}
}

impl VirtioVsockDriver {
Expand Down

0 comments on commit 5afa00a

Please sign in to comment.