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

Map e1000 to kernel space addr as well and rename its iface

This commit is contained in:
Jiajie Chen 2019-04-02 10:24:18 +08:00
parent 66af7473eb
commit ee66451873
3 changed files with 25 additions and 41 deletions

View File

@ -457,7 +457,6 @@ pub fn ahci_init(irq: Option<u32>, header: usize, size: usize) -> Arc<AHCIDriver
fis.command = CMD_IDENTIFY_DEVICE; fis.command = CMD_IDENTIFY_DEVICE;
fis.sector_count = 1; fis.sector_count = 1;
debug!("issued identify command");
port.issue_command(0); port.issue_command(0);
port.spin_on_slot(0); port.spin_on_slot(0);

View File

@ -101,6 +101,7 @@ unsafe fn enable(loc: Location) -> Option<u32> {
} }
pub fn init_driver(dev: &PCIDevice) { pub fn init_driver(dev: &PCIDevice) {
let name = format!("enp{}s{}f{}", dev.loc.bus, dev.loc.device, dev.loc.function);
match (dev.id.vendor_id, dev.id.device_id) { match (dev.id.vendor_id, dev.id.device_id) {
(0x8086, 0x100e) | (0x8086, 0x100f) | (0x8086, 0x10d3) => { (0x8086, 0x100e) | (0x8086, 0x100f) | (0x8086, 0x10d3) => {
// 0x100e // 0x100e
@ -110,14 +111,19 @@ pub fn init_driver(dev: &PCIDevice) {
// 0x10d3 // 0x10d3
// 82574L Gigabit Network Connection // 82574L Gigabit Network Connection
if let Some(BAR::Memory(addr, len, _, _)) = dev.bars[0] { if let Some(BAR::Memory(addr, len, _, _)) = dev.bars[0] {
let _ = unsafe { enable(dev.loc) }; let irq = unsafe { enable(dev.loc) };
e1000::e1000_init(addr as usize, len as usize); let vaddr = KERNEL_OFFSET + addr as usize;
let mut current_addr = addr as usize;
while current_addr < addr as usize + len as usize {
active_table().map_if_not_exists(KERNEL_OFFSET + current_addr, current_addr);
current_addr = current_addr + PAGE_SIZE;
}
e1000::e1000_init(name, irq, vaddr, len as usize);
} }
} }
(0x8086, 0x10fb) => { (0x8086, 0x10fb) => {
// 82599ES 10-Gigabit SFI/SFP+ Network Connection // 82599ES 10-Gigabit SFI/SFP+ Network Connection
if let Some(BAR::Memory(addr, len, _, _)) = dev.bars[0] { if let Some(BAR::Memory(addr, len, _, _)) = dev.bars[0] {
let name = format!("enp{}s{}f{}", dev.loc.bus, dev.loc.device, dev.loc.function);
let irq = unsafe { enable(dev.loc) }; let irq = unsafe { enable(dev.loc) };
PCI_DRIVERS.lock().insert( PCI_DRIVERS.lock().insert(
dev.loc, dev.loc,

View File

@ -73,20 +73,19 @@ const E1000_RAH: usize = 0x5404 / 4;
pub struct E1000Interface { pub struct E1000Interface {
iface: Mutex<EthernetInterface<'static, 'static, 'static, E1000Driver>>, iface: Mutex<EthernetInterface<'static, 'static, 'static, E1000Driver>>,
driver: E1000Driver, driver: E1000Driver,
name: String,
irq: Option<u32>,
} }
impl Driver for E1000Interface { impl Driver for E1000Interface {
fn try_handle_interrupt(&self, _irq: Option<u32>) -> bool { fn try_handle_interrupt(&self, irq: Option<u32>) -> bool {
let irq = { if irq.is_some() && self.irq.is_some() && irq != self.irq {
let driver = self.driver.0.lock(); // not ours, skip it
return false;
}
if let None = active_table().get_entry(driver.header) { let data = {
let mut current_addr = driver.header; let driver = self.driver.0.lock();
while current_addr < driver.header + driver.size {
active_table().map_if_not_exists(current_addr, current_addr);
current_addr = current_addr + PAGE_SIZE;
}
}
let e1000 = unsafe { let e1000 = unsafe {
slice::from_raw_parts_mut(driver.header as *mut Volatile<u32>, driver.size / 4) slice::from_raw_parts_mut(driver.header as *mut Volatile<u32>, driver.size / 4)
@ -102,7 +101,7 @@ impl Driver for E1000Interface {
} }
}; };
if irq { if data {
let timestamp = Instant::from_millis(crate::trap::uptime_msec() as i64); let timestamp = Instant::from_millis(crate::trap::uptime_msec() as i64);
let mut sockets = SOCKETS.lock(); let mut sockets = SOCKETS.lock();
match self.iface.lock().poll(&mut sockets, timestamp) { match self.iface.lock().poll(&mut sockets, timestamp) {
@ -115,7 +114,7 @@ impl Driver for E1000Interface {
} }
} }
return irq; return data;
} }
fn device_type(&self) -> DeviceType { fn device_type(&self) -> DeviceType {
@ -131,7 +130,7 @@ impl Driver for E1000Interface {
} }
fn get_ifname(&self) -> String { fn get_ifname(&self) -> String {
format!("e1000") self.name.clone()
} }
fn ipv4_address(&self) -> Option<Ipv4Address> { fn ipv4_address(&self) -> Option<Ipv4Address> {
@ -185,14 +184,6 @@ impl<'a> phy::Device<'a> for E1000Driver {
fn receive(&'a mut self) -> Option<(Self::RxToken, Self::TxToken)> { fn receive(&'a mut self) -> Option<(Self::RxToken, Self::TxToken)> {
let driver = self.0.lock(); let driver = self.0.lock();
if let None = active_table().get_entry(driver.header) {
let mut current_addr = driver.header;
while current_addr < driver.header + driver.size {
active_table().map_if_not_exists(current_addr, current_addr);
current_addr = current_addr + PAGE_SIZE;
}
}
let e1000 = unsafe { let e1000 = unsafe {
slice::from_raw_parts_mut(driver.header as *mut Volatile<u32>, driver.size / 4) slice::from_raw_parts_mut(driver.header as *mut Volatile<u32>, driver.size / 4)
}; };
@ -238,14 +229,6 @@ impl<'a> phy::Device<'a> for E1000Driver {
fn transmit(&'a mut self) -> Option<Self::TxToken> { fn transmit(&'a mut self) -> Option<Self::TxToken> {
let driver = self.0.lock(); let driver = self.0.lock();
if let None = active_table().get_entry(driver.header) {
let mut current_addr = driver.header;
while current_addr < driver.header + driver.size {
active_table().map_if_not_exists(current_addr, current_addr);
current_addr = current_addr + PAGE_SIZE;
}
}
let e1000 = unsafe { let e1000 = unsafe {
slice::from_raw_parts_mut(driver.header as *mut Volatile<u32>, driver.size / 4) slice::from_raw_parts_mut(driver.header as *mut Volatile<u32>, driver.size / 4)
}; };
@ -354,8 +337,8 @@ bitflags! {
} }
// JudgeDuck-OS/kern/e1000.c // JudgeDuck-OS/kern/e1000.c
pub fn e1000_init(header: usize, size: usize) { pub fn e1000_init(name: String, irq: Option<u32>, header: usize, size: usize) {
info!("Probing e1000"); info!("Probing e1000 {}", name);
assert_eq!(size_of::<E1000SendDesc>(), 16); assert_eq!(size_of::<E1000SendDesc>(), 16);
assert_eq!(size_of::<E1000RecvDesc>(), 16); assert_eq!(size_of::<E1000RecvDesc>(), 16);
@ -387,12 +370,6 @@ pub fn e1000_init(header: usize, size: usize) {
first_trans: true, first_trans: true,
}; };
let mut current_addr = header;
while current_addr < header + size {
active_table().map_if_not_exists(current_addr, current_addr);
current_addr = current_addr + PAGE_SIZE;
}
let e1000 = unsafe { slice::from_raw_parts_mut(header as *mut Volatile<u32>, size / 4) }; let e1000 = unsafe { slice::from_raw_parts_mut(header as *mut Volatile<u32>, size / 4) };
debug!( debug!(
"status before setup: {:#?}", "status before setup: {:#?}",
@ -502,6 +479,8 @@ pub fn e1000_init(header: usize, size: usize) {
let e1000_iface = E1000Interface { let e1000_iface = E1000Interface {
iface: Mutex::new(iface), iface: Mutex::new(iface),
driver: net_driver.clone(), driver: net_driver.clone(),
name,
irq,
}; };
let driver = Arc::new(e1000_iface); let driver = Arc::new(e1000_iface);