Only remap device memory region lazily

master
Jiajie Chen 6 years ago
parent af63d937d6
commit 02a40b359b

@ -72,11 +72,14 @@ impl Driver for E1000Interface {
fn try_handle_interrupt(&self) -> bool { fn try_handle_interrupt(&self) -> bool {
let irq = { let irq = {
let driver = self.driver.0.lock(); let driver = self.driver.0.lock();
if let None = active_table().get_entry(driver.header) {
let mut current_addr = driver.header; let mut current_addr = driver.header;
while current_addr < driver.header + driver.size { while current_addr < driver.header + driver.size {
active_table().map_if_not_exists(current_addr, current_addr); active_table().map_if_not_exists(current_addr, current_addr);
current_addr = current_addr + PAGE_SIZE; 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)
@ -115,12 +118,13 @@ impl Driver for E1000Interface {
impl E1000 { impl E1000 {
fn transmit_available(&self) -> bool { fn transmit_available(&self) -> bool {
// TODO map it in all cpu if let None = active_table().get_entry(self.header) {
let mut current_addr = self.header; let mut current_addr = self.header;
while current_addr < self.header + self.size { while current_addr < self.header + self.size {
active_table().map_if_not_exists(current_addr, current_addr); active_table().map_if_not_exists(current_addr, current_addr);
current_addr = current_addr + PAGE_SIZE; current_addr = current_addr + PAGE_SIZE;
} }
}
let e1000 = let e1000 =
unsafe { slice::from_raw_parts_mut(self.header as *mut Volatile<u32>, self.size / 4) }; unsafe { slice::from_raw_parts_mut(self.header as *mut Volatile<u32>, self.size / 4) };
@ -136,12 +140,13 @@ impl E1000 {
} }
fn receive_available(&self) -> bool { fn receive_available(&self) -> bool {
// TODO map it in all cpu if let None = active_table().get_entry(self.header) {
let mut current_addr = self.header; let mut current_addr = self.header;
while current_addr < self.header + self.size { while current_addr < self.header + self.size {
active_table().map_if_not_exists(current_addr, current_addr); active_table().map_if_not_exists(current_addr, current_addr);
current_addr = current_addr + PAGE_SIZE; current_addr = current_addr + PAGE_SIZE;
} }
}
let e1000 = let e1000 =
unsafe { slice::from_raw_parts_mut(self.header as *mut Volatile<u32>, self.size / 4) }; unsafe { slice::from_raw_parts_mut(self.header as *mut Volatile<u32>, self.size / 4) };

@ -878,7 +878,6 @@ impl IoVecs {
fn write_all_from_slice(&mut self, buf: &[u8]) { fn write_all_from_slice(&mut self, buf: &[u8]) {
let mut copied_len = 0; let mut copied_len = 0;
debug!("copy {:?}", buf);
for slice in self.0.iter_mut() { for slice in self.0.iter_mut() {
let copy_len = min(slice.len(), buf.len() - copied_len); let copy_len = min(slice.len(), buf.len() - copied_len);
if copy_len == 0 { if copy_len == 0 {
@ -886,7 +885,6 @@ impl IoVecs {
} }
slice[..copy_len].copy_from_slice(&buf[copied_len..copied_len + copy_len]); slice[..copy_len].copy_from_slice(&buf[copied_len..copied_len + copy_len]);
debug!("copy to {:?}", slice);
copied_len += copy_len; copied_len += copy_len;
} }
} }

Loading…
Cancel
Save