Commit 3d6daeb7 authored by Stefan Lankes's avatar Stefan Lankes Committed by Stefan Lankes
Browse files

use irqsave to disable interrupts

parent 57bb1473
......@@ -5,8 +5,8 @@
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.
use crate::arch::irq;
use crate::arch::kernel::percore::*;
use crate::collections::irqsave;
use crate::scheduler::task::TaskHandle;
use crate::synch::semaphore::*;
use crate::synch::spinlock::SpinlockIrqSave;
......@@ -25,13 +25,11 @@ const POLL_PERIOD: u64 = 20_000;
fn set_polling_mode(value: bool) {
// is the driver already in polling mode?
if POLLING.swap(value, Ordering::SeqCst) != value {
let irq = irq::nested_disable();
if let Some(driver) = crate::arch::kernel::pci::get_network_driver() {
driver.borrow_mut().set_polling_mode(value);
}
irq::nested_enable(irq);
irqsave(|| {
if let Some(driver) = crate::arch::kernel::pci::get_network_driver() {
driver.borrow_mut().set_polling_mode(value);
}
});
// wakeup network thread to sleep for longer time
NET_SEM.release();
......@@ -70,13 +68,11 @@ pub fn netwait_and_wakeup(handles: &[usize], millis: Option<u64>) {
}
if reset_nic {
let irq = irq::nested_disable();
if let Some(driver) = crate::arch::kernel::pci::get_network_driver() {
driver.borrow_mut().set_polling_mode(false);
}
irq::nested_enable(irq);
irqsave(|| {
if let Some(driver) = crate::arch::kernel::pci::get_network_driver() {
driver.borrow_mut().set_polling_mode(false);
}
});
} else {
NET_SEM.acquire(millis);
}
......
......@@ -14,10 +14,10 @@ use core::fmt::Write;
use core::{isize, ptr, slice, str};
use crate::arch;
use crate::collections::irqsave;
use crate::console;
use crate::environment;
use crate::errno::*;
use crate::synch::spinlock::SpinlockIrqSave;
use crate::syscalls::fs::{self, FilePerms, PosixFile, SeekWhence};
use crate::util;
......@@ -27,8 +27,6 @@ pub use self::uhyve::*;
mod generic;
mod uhyve;
static DRIVER_LOCK: SpinlockIrqSave<()> = SpinlockIrqSave::new(());
const SEEK_SET: i32 = 0;
const SEEK_CUR: i32 = 1;
const SEEK_END: i32 = 2;
......@@ -119,69 +117,55 @@ pub trait SyscallInterface: Send + Sync {
}
fn get_mac_address(&self) -> Result<[u8; 6], ()> {
let _lock = DRIVER_LOCK.lock();
match arch::kernel::pci::get_network_driver() {
irqsave(|| match arch::kernel::pci::get_network_driver() {
Some(driver) => Ok(driver.borrow().get_mac_address()),
_ => Err(()),
}
})
}
fn get_mtu(&self) -> Result<u16, ()> {
let _lock = DRIVER_LOCK.lock();
match arch::kernel::pci::get_network_driver() {
irqsave(|| match arch::kernel::pci::get_network_driver() {
Some(driver) => Ok(driver.borrow().get_mtu()),
_ => Err(()),
}
})
}
fn has_packet(&self) -> bool {
let _lock = DRIVER_LOCK.lock();
match arch::kernel::pci::get_network_driver() {
irqsave(|| match arch::kernel::pci::get_network_driver() {
Some(driver) => driver.borrow().has_packet(),
_ => false,
}
})
}
fn get_tx_buffer(&self, len: usize) -> Result<(*mut u8, usize), ()> {
let _lock = DRIVER_LOCK.lock();
match arch::kernel::pci::get_network_driver() {
irqsave(|| match arch::kernel::pci::get_network_driver() {
Some(driver) => driver.borrow_mut().get_tx_buffer(len),
_ => Err(()),
}
})
}
fn send_tx_buffer(&self, handle: usize, len: usize) -> Result<(), ()> {
let _lock = DRIVER_LOCK.lock();
match arch::kernel::pci::get_network_driver() {
irqsave(|| match arch::kernel::pci::get_network_driver() {
Some(driver) => driver.borrow_mut().send_tx_buffer(handle, len),
_ => Err(()),
}
})
}
fn receive_rx_buffer(&self) -> Result<&'static [u8], ()> {
let _lock = DRIVER_LOCK.lock();
match arch::kernel::pci::get_network_driver() {
irqsave(|| match arch::kernel::pci::get_network_driver() {
Some(driver) => driver.borrow().receive_rx_buffer(),
_ => Err(()),
}
})
}
fn rx_buffer_consumed(&self) -> Result<(), ()> {
let _lock = DRIVER_LOCK.lock();
match arch::kernel::pci::get_network_driver() {
irqsave(|| match arch::kernel::pci::get_network_driver() {
Some(driver) => {
driver.borrow_mut().rx_buffer_consumed();
Ok(())
}
_ => Err(()),
}
})
}
#[cfg(not(target_arch = "x86_64"))]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment