-
-
Notifications
You must be signed in to change notification settings - Fork 158
完成e1000e驱动 #393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
完成e1000e驱动 #393
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0c49c74
测试RESET
Hdksg10 9a81666
测试RESET
Hdksg10 81153a0
基于轮询的实现
Hdksg10 c7694d8
规范化部分unsafe的使用
Hdksg10 2e5e978
完成中断处理函数,同时去除了不必要的内存拷贝行为,准备编写napi机制
Hdksg10 f31d2cb
实现现有协议栈下的部分napi机制;修复了内存泄漏的问题;添加了一部分代码注释
Hdksg10 4f80791
去除部分无用代码
Hdksg10 a8fdcb2
去除一些无用代码
Hdksg10 e93c3cc
Merge branch 'master' of https://github.com/Hdksg10/DragonOS into dev…
Hdksg10 52bb161
适配新的驱动模型
Hdksg10 760dacd
Merge branch 'master' into dev-e1000e
Hdksg10 671421c
完成msi中断测试
Hdksg10 513d0ab
去除一些无用代码
Hdksg10 a15fe58
Merge branch 'master' into dev-e1000e
Hdksg10 56b6a05
格式化代码
Hdksg10 e18c709
增加了一些注释,提高代码可读性
Hdksg10 096759f
去除无关文件
Hdksg10 866bf27
优化了读取mac地址的方式,提高可读性
Hdksg10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use crate::arch::mm::kernel_page_flags; | ||
|
||
use crate::arch::MMArch; | ||
|
||
use crate::mm::kernel_mapper::KernelMapper; | ||
use crate::mm::page::PageFlags; | ||
use crate::mm::{ | ||
allocator::page_frame::{ | ||
allocate_page_frames, deallocate_page_frames, PageFrameCount, PhysPageFrame, | ||
}, | ||
MemoryManagementArch, PhysAddr, VirtAddr, | ||
}; | ||
use core::ptr::NonNull; | ||
const PAGE_SIZE: usize = 4096; | ||
/// @brief 申请用于DMA的内存页 | ||
/// @param pages 页数(4k一页) | ||
/// @return PhysAddr 获得的内存页的初始物理地址 | ||
pub fn dma_alloc(pages: usize) -> (usize, NonNull<u8>) { | ||
let page_num = PageFrameCount::new( | ||
((pages * PAGE_SIZE + MMArch::PAGE_SIZE - 1) / MMArch::PAGE_SIZE).next_power_of_two(), | ||
); | ||
unsafe { | ||
let (paddr, count) = allocate_page_frames(page_num).expect("e1000e: alloc page failed"); | ||
let virt = MMArch::phys_2_virt(paddr).unwrap(); | ||
// 清空这块区域,防止出现脏数据 | ||
core::ptr::write_bytes(virt.data() as *mut u8, 0, count.data() * MMArch::PAGE_SIZE); | ||
|
||
let dma_flags: PageFlags<MMArch> = PageFlags::mmio_flags(); | ||
|
||
let mut kernel_mapper = KernelMapper::lock(); | ||
let kernel_mapper = kernel_mapper.as_mut().unwrap(); | ||
let flusher = kernel_mapper | ||
.remap(virt, dma_flags) | ||
.expect("e1000e: remap failed"); | ||
flusher.flush(); | ||
return ( | ||
paddr.data(), | ||
NonNull::new(MMArch::phys_2_virt(paddr).unwrap().data() as _).unwrap(), | ||
); | ||
} | ||
} | ||
/// @brief 释放用于DMA的内存页 | ||
/// @param paddr 起始物理地址 pages 页数(4k一页) | ||
/// @return i32 0表示成功 | ||
pub unsafe fn dma_dealloc(paddr: usize, vaddr: NonNull<u8>, pages: usize) -> i32 { | ||
let page_count = PageFrameCount::new( | ||
((pages * PAGE_SIZE + MMArch::PAGE_SIZE - 1) / MMArch::PAGE_SIZE).next_power_of_two(), | ||
); | ||
|
||
// 恢复页面属性 | ||
let vaddr = VirtAddr::new(vaddr.as_ptr() as *mut u8 as usize); | ||
let mut kernel_mapper = KernelMapper::lock(); | ||
let kernel_mapper = kernel_mapper.as_mut().unwrap(); | ||
let flusher = kernel_mapper | ||
.remap(vaddr, kernel_page_flags(vaddr)) | ||
.expect("e1000e: remap failed"); | ||
flusher.flush(); | ||
|
||
unsafe { | ||
deallocate_page_frames(PhysPageFrame::new(PhysAddr::new(paddr)), page_count); | ||
} | ||
return 0; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的代码下一个pr可以把它整合到mm模块里面去。并且加上守卫来保护。目前这样的写法容易造成内存泄露、越界。