部分函数从返回值为Result<<>,i32>修改为Result<<>,SystemError> (#210)

* 将Result<<>,i32>替换为Result<<>,SystemError>
* bugfix: 显示双缓冲区初始化的时候,连续注册了两次Video Softirq的问题。

Co-authored-by: longjin <longjin@RinGoTek.cn>
This commit is contained in:
Mork
2023-03-29 21:24:11 +08:00
committed by GitHub
parent 64aea4b349
commit 676b8ef62e
37 changed files with 801 additions and 786 deletions

View File

@ -1,9 +1,10 @@
use crate::libs::spinlock::{SpinLock, SpinLockGuard};
use crate::syscall::SystemError;
use crate::{
arch::asm::current::current_pcb,
include::bindings::bindings::{
initial_mm, mm_create_vma, mm_unmap, vm_area_del, vm_area_free, vm_area_struct, vm_flags_t,
vma_find, EINVAL, ENOMEM, EPERM, MMIO_BASE, MMIO_TOP, PAGE_1G_SHIFT, PAGE_1G_SIZE,
vma_find, MMIO_BASE, MMIO_TOP, PAGE_1G_SHIFT, PAGE_1G_SIZE,
PAGE_2M_SIZE, PAGE_4K_SHIFT, PAGE_4K_SIZE, VM_DONTCOPY, VM_IO,
},
kdebug, kerror,
@ -73,11 +74,11 @@ impl MmioBuddyMemPool {
///
/// @return Ok(i32) 返回0
///
/// @return Err(i32) 返回错误码
fn give_back_block(&self, vaddr: u64, exp: u32) -> Result<i32, i32> {
/// @return Err(SystemError) 返回错误码
fn give_back_block(&self, vaddr: u64, exp: u32) -> Result<i32, SystemError> {
// 确保内存对齐低位都要为0
if (vaddr & ((1 << exp) - 1)) != 0 {
return Err(-(EINVAL as i32));
return Err(SystemError::EINVAL);
}
let region: Box<MmioBuddyAddrRegion> = self.create_region(vaddr);
// 加入buddy
@ -440,16 +441,16 @@ impl MmioBuddyMemPool {
///
/// @return Ok(i32) 成功返回0
///
/// @return Err(i32) 失败返回错误码
/// @return Err(SystemError) 失败返回错误码
pub fn create_mmio(
&self,
size: u32,
vm_flags: vm_flags_t,
res_vaddr: *mut u64,
res_length: *mut u64,
) -> Result<i32, i32> {
) -> Result<i32, SystemError> {
if size > PAGE_1G_SIZE || size == 0 {
return Err(-(EPERM as i32));
return Err(SystemError::EPERM);
}
let mut retval: i32 = 0;
// 计算前导0
@ -502,7 +503,7 @@ impl MmioBuddyMemPool {
vm_area_del(*vma);
vm_area_free(*vma);
}
return Err(retval);
return Err(SystemError::from_posix_errno(retval).unwrap());
}
loop_i += PAGE_2M_SIZE as u64;
}
@ -532,14 +533,14 @@ impl MmioBuddyMemPool {
vm_area_del(*vma);
vm_area_free(*vma);
}
return Err(retval);
return Err(SystemError::from_posix_errno(retval).unwrap());
}
loop_i += PAGE_4K_SIZE as u64;
}
}
Err(_) => {
kdebug!("failed to create mmio vma.pid = {:?}", current_pcb().pid);
return Err(-(ENOMEM as i32));
return Err(SystemError::ENOMEM);
}
}
return Ok(retval);
@ -553,8 +554,8 @@ impl MmioBuddyMemPool {
///
/// @return Ok(i32) 成功返回0
///
/// @return Err(i32) 失败返回错误码
pub fn release_mmio(&self, vaddr: u64, length: u64) -> Result<i32, i32> {
/// @return Err(SystemError) 失败返回错误码
pub fn release_mmio(&self, vaddr: u64, length: u64) -> Result<i32, SystemError> {
//先将要释放的空间取消映射
unsafe {
mm_unmap(&mut initial_mm, vaddr, length, false);
@ -572,7 +573,7 @@ impl MmioBuddyMemPool {
vaddr + loop_i,
current_pcb().pid
);
return Err(-(EINVAL as i32));
return Err(SystemError::EINVAL);
}
// 检查vma起始地址是否正确
if unsafe { (*vma).vm_start != (vaddr + loop_i) } {
@ -581,7 +582,7 @@ impl MmioBuddyMemPool {
vaddr + loop_i,
current_pcb().pid
);
return Err(-(EINVAL as i32));
return Err(SystemError::EINVAL);
}
// 将vma对应空间归还
match MMIO_POOL.give_back_block(unsafe { (*vma).vm_start }, unsafe {
@ -699,7 +700,7 @@ pub extern "C" fn mmio_create(
res_length: *mut u64,
) -> i32 {
if let Err(err) = MMIO_POOL.create_mmio(size, vm_flags, res_vaddr, res_length) {
return err;
return err.to_posix_errno();
} else {
return 0;
}
@ -717,7 +718,7 @@ pub extern "C" fn mmio_create(
#[no_mangle]
pub extern "C" fn mmio_release(vaddr: u64, length: u64) -> i32 {
if let Err(err) = MMIO_POOL.release_mmio(vaddr, length) {
return err;
return err.to_posix_errno();
} else {
return 0;
}