From 02343d0b5b47c07e7f4ec3818940795b1009fae1 Mon Sep 17 00:00:00 2001 From: LoGin Date: Tue, 2 Jan 2024 14:16:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0/dev/fb0=EF=BC=8C=E8=83=BD?= =?UTF-8?q?=E5=A4=9F=E5=9C=A8=E7=94=A8=E6=88=B7=E7=A8=8B=E5=BA=8F=E8=AF=BB?= =?UTF-8?q?=E5=86=99=E5=B8=A7=E7=BC=93=E5=86=B2=E5=8C=BA=20(#485)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/driver/base/device/device_number.rs | 5 + kernel/src/driver/base/device/mod.rs | 7 +- kernel/src/driver/disk/ahci/ahci_inode.rs | 6 +- kernel/src/driver/keyboard/ps2_keyboard.rs | 7 +- kernel/src/driver/video/fbdev/base/fbmem.rs | 124 ++++++++++++++++-- kernel/src/driver/video/fbdev/vesafb.rs | 42 ++++++ kernel/src/driver/video/mod.rs | 6 +- kernel/src/filesystem/devfs/mod.rs | 10 +- kernel/src/filesystem/devfs/null_dev.rs | 4 +- kernel/src/filesystem/devfs/zero_dev.rs | 4 +- kernel/src/filesystem/fat/fs.rs | 4 +- kernel/src/filesystem/kernfs/mod.rs | 5 +- kernel/src/filesystem/procfs/mod.rs | 5 +- kernel/src/filesystem/ramfs/mod.rs | 6 +- kernel/src/filesystem/vfs/mod.rs | 14 +- kernel/src/filesystem/vfs/syscall.rs | 3 +- kernel/src/ipc/pipe.rs | 2 +- kernel/src/sched/syscall.rs | 4 + kernel/src/syscall/mod.rs | 8 ++ kernel/src/virt/kvm/kvm_dev.rs | 5 +- kernel/src/virt/kvm/vcpu_dev.rs | 7 +- kernel/src/virt/kvm/vm_dev.rs | 5 +- 22 files changed, 230 insertions(+), 53 deletions(-) diff --git a/kernel/src/driver/base/device/device_number.rs b/kernel/src/driver/base/device/device_number.rs index a9d9482b8..fd28c7021 100644 --- a/kernel/src/driver/base/device/device_number.rs +++ b/kernel/src/driver/base/device/device_number.rs @@ -8,6 +8,11 @@ impl Major { /// 未命名的主设备 pub const UNNAMED_MAJOR: Self = Self::new(0); + + pub const IDE0_MAJOR: Self = Self::new(3); + pub const HD_MAJOR: Self = Self::IDE0_MAJOR; + + pub const INPUT_MAJOR: Self = Self::new(13); /// /dev/fb* framebuffers pub const FB_MAJOR: Self = Self::new(29); diff --git a/kernel/src/driver/base/device/mod.rs b/kernel/src/driver/base/device/mod.rs index c9bf6b2de..4f78a4e79 100644 --- a/kernel/src/driver/base/device/mod.rs +++ b/kernel/src/driver/base/device/mod.rs @@ -423,7 +423,7 @@ impl DeviceManager { /// https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/base/core.c#3398 /// /// todo: 完善错误处理逻辑:如果添加失败,需要将之前添加的内容全部回滚 - #[inline] + #[inline(never)] #[allow(dead_code)] pub fn add_device(&self, device: Arc) -> Result<(), SystemError> { // 在这里处理与parent相关的逻辑 @@ -547,6 +547,9 @@ impl DeviceManager { /// @brief: 卸载设备 /// @parameter id_table: 总线标识符,用于唯一标识该设备 /// @return: None + /// + /// ## 注意 + /// 该函数已废弃,不再使用 #[inline] #[allow(dead_code)] pub fn remove_device(&self, _id_table: &IdTable) { @@ -554,7 +557,7 @@ impl DeviceManager { } /// 参考 https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/base/dd.c?fi=driver_attach#542 - fn remove(&self, _dev: &Arc) { + pub fn remove(&self, _dev: &Arc) { todo!("DeviceManager::remove") } diff --git a/kernel/src/driver/disk/ahci/ahci_inode.rs b/kernel/src/driver/disk/ahci/ahci_inode.rs index 048bca7fa..5ec44763e 100644 --- a/kernel/src/driver/disk/ahci/ahci_inode.rs +++ b/kernel/src/driver/disk/ahci/ahci_inode.rs @@ -1,10 +1,10 @@ use crate::driver::base::block::block_device::BlockDevice; +use crate::driver::base::device::device_number::{DeviceNumber, Major}; use crate::filesystem::devfs::{DevFS, DeviceINode}; use crate::filesystem::vfs::file::FileMode; use crate::filesystem::vfs::syscall::ModeType; use crate::filesystem::vfs::{ - core::generate_inode_id, make_rawdev, FilePrivateData, FileSystem, FileType, IndexNode, - Metadata, + core::generate_inode_id, FilePrivateData, FileSystem, FileType, IndexNode, Metadata, }; use crate::{libs::spinlock::SpinLock, time::TimeSpec}; use alloc::{ @@ -54,7 +54,7 @@ impl LockedAhciInode { nlinks: 1, uid: 0, gid: 0, - raw_dev: make_rawdev(1, 3), // 这里用来作为device number + raw_dev: DeviceNumber::new(Major::HD_MAJOR, 0), }, }; diff --git a/kernel/src/driver/keyboard/ps2_keyboard.rs b/kernel/src/driver/keyboard/ps2_keyboard.rs index e472b21bf..e8b41806f 100644 --- a/kernel/src/driver/keyboard/ps2_keyboard.rs +++ b/kernel/src/driver/keyboard/ps2_keyboard.rs @@ -3,7 +3,10 @@ use core::{ffi::c_void, sync::atomic::AtomicI32}; use alloc::sync::{Arc, Weak}; use crate::{ - driver::tty::tty_device::TTY_DEVICES, + driver::{ + base::device::device_number::{DeviceNumber, Major}, + tty::tty_device::TTY_DEVICES, + }, filesystem::{ devfs::{devfs_register, DevFS, DeviceINode}, vfs::{ @@ -65,7 +68,7 @@ impl LockedPS2KeyBoardInode { nlinks: 1, uid: 0, gid: 0, - raw_dev: 0, // 这里用来作为device number + raw_dev: DeviceNumber::new(Major::INPUT_MAJOR, 0), // 这里用来作为device number }, }; diff --git a/kernel/src/driver/video/fbdev/base/fbmem.rs b/kernel/src/driver/video/fbdev/base/fbmem.rs index 16bbdeb04..cce48c873 100644 --- a/kernel/src/driver/video/fbdev/base/fbmem.rs +++ b/kernel/src/driver/video/fbdev/base/fbmem.rs @@ -3,6 +3,7 @@ use core::intrinsics::unlikely; use alloc::{ string::{String, ToString}, sync::{Arc, Weak}, + vec::Vec, }; use system_error::SystemError; @@ -22,11 +23,19 @@ use crate::{ kset::KSet, subsys::SubSysPrivate, }, - filesystem::{kernfs::KernFSInode, sysfs::AttributeGroup}, + filesystem::{ + devfs::{devfs_register, DevFS, DeviceINode}, + kernfs::KernFSInode, + sysfs::AttributeGroup, + vfs::{ + file::FileMode, syscall::ModeType, FilePrivateData, FileSystem, FileType, IndexNode, + Metadata, + }, + }, init::initcall::INITCALL_SUBSYS, libs::{ rwlock::{RwLock, RwLockReadGuard, RwLockWriteGuard}, - spinlock::SpinLock, + spinlock::{SpinLock, SpinLockGuard}, }, }; @@ -141,6 +150,16 @@ impl FrameBufferManager { fb.set_fb_device(Some(fb_device.clone())); device_manager().add_device(fb_device.clone() as Arc)?; + // 添加到devfs + devfs_register(&fb_device.name(), fb_device.clone()).map_err(|e| { + kerror!( + "register fb device '{}' to devfs failed: {:?}", + fb_device.name(), + e + ); + device_manager().remove(&(fb_device.clone() as Arc)); + e + })?; // todo: 从Modedb中获取信息 // 参考: https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/video/fbdev/core/fbmem.c#1584 @@ -195,7 +214,7 @@ pub struct FbDevice { impl FbDevice { pub const BASENAME: &'static str = "fb"; fn new(fb: Weak, id: FbId) -> Arc { - Arc::new(Self { + let r = Arc::new(Self { inner: SpinLock::new(InnerFbDevice { fb, kern_inode: None, @@ -203,14 +222,36 @@ impl FbDevice { kset: None, ktype: None, fb_id: id, + device_inode_fs: None, + devfs_metadata: Metadata::new( + FileType::FramebufferDevice, + ModeType::from_bits_truncate(0o666), + ), }), kobj_state: LockedKObjectState::new(None), - }) + }); + + let mut inner_guard = r.inner.lock(); + + inner_guard.devfs_metadata.raw_dev = r.do_device_number(&inner_guard); + drop(inner_guard); + + return r; } pub fn framebuffer(&self) -> Option> { self.inner.lock().fb.upgrade() } + + /// 获取设备号 + pub fn device_number(&self) -> DeviceNumber { + let inner_guard = self.inner.lock(); + self.do_device_number(&inner_guard) + } + + fn do_device_number(&self, inner_guard: &SpinLockGuard<'_, InnerFbDevice>) -> DeviceNumber { + DeviceNumber::new(Major::FB_MAJOR, inner_guard.fb_id.data()) + } } #[derive(Debug)] @@ -222,6 +263,10 @@ struct InnerFbDevice { ktype: Option<&'static dyn KObjType>, /// 帧缓冲区id fb_id: FbId, + + /// device inode要求的字段 + device_inode_fs: Option>, + devfs_metadata: Metadata, } impl KObject for FbDevice { @@ -288,13 +333,7 @@ impl Device for FbDevice { } fn id_table(&self) -> IdTable { - IdTable::new( - Self::BASENAME.to_string(), - Some(DeviceNumber::new( - Major::FB_MAJOR, - self.inner.lock().fb_id.data(), - )), - ) + IdTable::new(Self::BASENAME.to_string(), Some(self.device_number())) } fn set_bus(&self, _bus: Option>) { @@ -336,3 +375,66 @@ impl Device for FbDevice { Some(&[&FbDeviceAttrGroup]) } } + +impl DeviceINode for FbDevice { + fn set_fs(&self, fs: Weak) { + self.inner.lock().device_inode_fs = Some(fs); + } +} + +impl IndexNode for FbDevice { + fn open(&self, _data: &mut FilePrivateData, _mode: &FileMode) -> Result<(), SystemError> { + Ok(()) + } + + fn close(&self, _data: &mut FilePrivateData) -> Result<(), SystemError> { + Ok(()) + } + fn read_at( + &self, + offset: usize, + len: usize, + buf: &mut [u8], + _data: &mut FilePrivateData, + ) -> Result { + let fb = self.inner.lock().fb.upgrade().unwrap(); + return fb.fb_read(&mut buf[0..len], offset); + } + + fn write_at( + &self, + offset: usize, + len: usize, + buf: &[u8], + _data: &mut FilePrivateData, + ) -> Result { + let fb = self.inner.lock().fb.upgrade().unwrap(); + return fb.fb_write(&buf[0..len], offset); + } + + fn fs(&self) -> Arc { + self.inner + .lock() + .device_inode_fs + .as_ref() + .unwrap() + .upgrade() + .unwrap() + } + + fn as_any_ref(&self) -> &dyn core::any::Any { + self + } + + fn list(&self) -> Result, SystemError> { + todo!() + } + + fn metadata(&self) -> Result { + Ok(self.inner.lock().devfs_metadata.clone()) + } + + fn resize(&self, _len: usize) -> Result<(), SystemError> { + return Ok(()); + } +} diff --git a/kernel/src/driver/video/fbdev/vesafb.rs b/kernel/src/driver/video/fbdev/vesafb.rs index 3b91e0fc6..232f34abd 100644 --- a/kernel/src/driver/video/fbdev/vesafb.rs +++ b/kernel/src/driver/video/fbdev/vesafb.rs @@ -295,6 +295,48 @@ impl FrameBufferOps for VesaFb { fn fb_destroy(&self) { todo!() } + + fn fb_read(&self, buf: &mut [u8], pos: usize) -> Result { + let bp = boot_params().read(); + + let vaddr = bp.screen_info.lfb_virt_base.ok_or(SystemError::ENODEV)?; + let size = self.current_fb_fix().smem_len; + drop(bp); + if pos >= size { + return Ok(0); + } + + let pos = pos as i64; + let size = size as i64; + + let len = core::cmp::min(size - pos, buf.len() as i64) as usize; + + let slice = unsafe { core::slice::from_raw_parts(vaddr.as_ptr::(), size as usize) }; + buf[..len].copy_from_slice(&slice[pos as usize..(pos as usize + len)]); + + return Ok(len); + } + + fn fb_write(&self, buf: &[u8], pos: usize) -> Result { + let bp = boot_params().read(); + + let vaddr = bp.screen_info.lfb_virt_base.ok_or(SystemError::ENODEV)?; + let size = self.current_fb_fix().smem_len; + + if pos >= size { + return Ok(0); + } + + let pos = pos as i64; + let size = size as i64; + + let len = core::cmp::min(size - pos, buf.len() as i64) as usize; + + let slice = unsafe { core::slice::from_raw_parts_mut(vaddr.as_ptr::(), size as usize) }; + slice[pos as usize..(pos as usize + len)].copy_from_slice(&buf[..len]); + + return Ok(len); + } } impl FrameBufferInfo for VesaFb { diff --git a/kernel/src/driver/video/mod.rs b/kernel/src/driver/video/mod.rs index 7559114e5..63f2a1a29 100644 --- a/kernel/src/driver/video/mod.rs +++ b/kernel/src/driver/video/mod.rs @@ -91,15 +91,15 @@ impl VideoRefreshManager { ); boot_params().write_irqsave().screen_info.lfb_virt_base = Some(buf_vaddr); - let mut frame_buffer_info_graud = self.device_buffer.write(); - if let ScmBuffer::DeviceBuffer(vaddr) = &mut (frame_buffer_info_graud).buf { + let mut frame_buffer_info_guard = self.device_buffer.write(); + if let ScmBuffer::DeviceBuffer(vaddr) = &mut (frame_buffer_info_guard).buf { *vaddr = buf_vaddr; } // 地址映射 let mut paddr = boot_params().read().screen_info.lfb_base; let count = PageFrameCount::new( - page_align_up(frame_buffer_info_graud.buf_size()) / MMArch::PAGE_SIZE, + page_align_up(frame_buffer_info_guard.buf_size()) / MMArch::PAGE_SIZE, ); let page_flags: PageFlags = PageFlags::new().set_execute(true).set_write(true); diff --git a/kernel/src/filesystem/devfs/mod.rs b/kernel/src/filesystem/devfs/mod.rs index da569edd9..1e2cdaf9c 100644 --- a/kernel/src/filesystem/devfs/mod.rs +++ b/kernel/src/filesystem/devfs/mod.rs @@ -9,6 +9,7 @@ use super::vfs::{ FileSystem, FileType, FsInfo, IndexNode, Metadata, }; use crate::{ + driver::base::device::device_number::DeviceNumber, kerror, kinfo, libs::{ once::Once, @@ -154,6 +155,11 @@ impl DevFS { .add_dev(name, device.clone()) .expect("DevFS: Failed to register /dev/kvm"); } + FileType::FramebufferDevice => { + dev_root_inode + .add_dev(name, device.clone()) + .expect("DevFS: Failed to register /dev/fb"); + } _ => { return Err(SystemError::EOPNOTSUPP_OR_ENOTSUP); } @@ -254,7 +260,7 @@ impl DevFSInode { nlinks: 1, uid: 0, gid: 0, - raw_dev: data_, + raw_dev: DeviceNumber::from(data_ as u32), }, fs: Weak::default(), }; @@ -344,7 +350,7 @@ impl LockedDevFSInode { nlinks: 1, uid: 0, gid: 0, - raw_dev: data, + raw_dev: DeviceNumber::from(data as u32), }, fs: guard.fs.clone(), }))); diff --git a/kernel/src/filesystem/devfs/null_dev.rs b/kernel/src/filesystem/devfs/null_dev.rs index 586625ffa..4b661b9c6 100644 --- a/kernel/src/filesystem/devfs/null_dev.rs +++ b/kernel/src/filesystem/devfs/null_dev.rs @@ -1,5 +1,5 @@ +use crate::driver::base::device::device_number::DeviceNumber; use crate::filesystem::vfs::file::FileMode; -use crate::filesystem::vfs::make_rawdev; use crate::filesystem::vfs::syscall::ModeType; use crate::filesystem::vfs::{ core::generate_inode_id, FilePrivateData, FileSystem, FileType, IndexNode, Metadata, @@ -49,7 +49,7 @@ impl LockedNullInode { nlinks: 1, uid: 0, gid: 0, - raw_dev: make_rawdev(1, 3), // 这里用来作为device number + raw_dev: DeviceNumber::default(), // 这里用来作为device number }, }; diff --git a/kernel/src/filesystem/devfs/zero_dev.rs b/kernel/src/filesystem/devfs/zero_dev.rs index 914d77ea0..913406632 100644 --- a/kernel/src/filesystem/devfs/zero_dev.rs +++ b/kernel/src/filesystem/devfs/zero_dev.rs @@ -1,5 +1,5 @@ +use crate::driver::base::device::device_number::DeviceNumber; use crate::filesystem::vfs::file::FileMode; -use crate::filesystem::vfs::make_rawdev; use crate::filesystem::vfs::syscall::ModeType; use crate::filesystem::vfs::{ core::generate_inode_id, FilePrivateData, FileSystem, FileType, IndexNode, Metadata, @@ -49,7 +49,7 @@ impl LockedZeroInode { nlinks: 1, uid: 0, gid: 0, - raw_dev: make_rawdev(1, 3), // 这里用来作为device number + raw_dev: DeviceNumber::default(), // 这里用来作为device number }, }; diff --git a/kernel/src/filesystem/fat/fs.rs b/kernel/src/filesystem/fat/fs.rs index f642210d5..f7c1065c3 100644 --- a/kernel/src/filesystem/fat/fs.rs +++ b/kernel/src/filesystem/fat/fs.rs @@ -201,7 +201,7 @@ impl LockedFATInode { nlinks: 1, uid: 0, gid: 0, - raw_dev: 0, + raw_dev: DeviceNumber::default(), }, special_node: None, }))); @@ -321,7 +321,7 @@ impl FATFileSystem { nlinks: 1, uid: 0, gid: 0, - raw_dev: 0, + raw_dev: DeviceNumber::default(), }, special_node: None, }))); diff --git a/kernel/src/filesystem/kernfs/mod.rs b/kernel/src/filesystem/kernfs/mod.rs index 1ad7a532a..268d6da72 100644 --- a/kernel/src/filesystem/kernfs/mod.rs +++ b/kernel/src/filesystem/kernfs/mod.rs @@ -9,6 +9,7 @@ use hashbrown::HashMap; use system_error::SystemError; use crate::{ + driver::base::device::device_number::DeviceNumber, libs::{ casting::DowncastArc, rwlock::RwLock, @@ -84,7 +85,7 @@ impl KernFS { inode_id: generate_inode_id(), file_type: FileType::Dir, nlinks: 1, - raw_dev: 0, + raw_dev: DeviceNumber::default(), }; let root_inode = Arc::new(KernFSInode { name: String::from(""), @@ -507,7 +508,7 @@ impl KernFSInode { inode_id: generate_inode_id(), file_type: file_type.into(), nlinks: 1, - raw_dev: 0, + raw_dev: DeviceNumber::default(), }; let new_inode: Arc = Self::new( diff --git a/kernel/src/filesystem/procfs/mod.rs b/kernel/src/filesystem/procfs/mod.rs index 29fcadba5..bea3a571f 100644 --- a/kernel/src/filesystem/procfs/mod.rs +++ b/kernel/src/filesystem/procfs/mod.rs @@ -12,6 +12,7 @@ use system_error::SystemError; use crate::{ arch::mm::LockedFrameAllocator, + driver::base::device::device_number::DeviceNumber, filesystem::vfs::{ core::{generate_inode_id, ROOT_INODE}, FileType, @@ -298,7 +299,7 @@ impl ProcFS { nlinks: 1, uid: 0, gid: 0, - raw_dev: 0, + raw_dev: DeviceNumber::default(), }, fs: Weak::default(), fdata: InodeInfo { @@ -559,7 +560,7 @@ impl IndexNode for LockedProcFSInode { nlinks: 1, uid: 0, gid: 0, - raw_dev: data, + raw_dev: DeviceNumber::from(data as u32), }, fs: inode.fs.clone(), fdata: InodeInfo { diff --git a/kernel/src/filesystem/ramfs/mod.rs b/kernel/src/filesystem/ramfs/mod.rs index 5b2146600..e793038b4 100644 --- a/kernel/src/filesystem/ramfs/mod.rs +++ b/kernel/src/filesystem/ramfs/mod.rs @@ -100,7 +100,7 @@ impl RamFS { nlinks: 1, uid: 0, gid: 0, - raw_dev: 0, + raw_dev: DeviceNumber::default(), }, fs: Weak::default(), special_node: None, @@ -287,7 +287,7 @@ impl IndexNode for LockedRamFSInode { nlinks: 1, uid: 0, gid: 0, - raw_dev: data, + raw_dev: DeviceNumber::from(data as u32), }, fs: inode.fs.clone(), special_node: None, @@ -508,7 +508,7 @@ impl IndexNode for LockedRamFSInode { nlinks: 1, uid: 0, gid: 0, - raw_dev: 0, + raw_dev: DeviceNumber::default(), }, fs: inode.fs.clone(), special_node: None, diff --git a/kernel/src/filesystem/vfs/mod.rs b/kernel/src/filesystem/vfs/mod.rs index 4dbc81d06..22c2dcd79 100644 --- a/kernel/src/filesystem/vfs/mod.rs +++ b/kernel/src/filesystem/vfs/mod.rs @@ -40,6 +40,8 @@ pub enum FileType { BlockDevice, /// 字符设备 CharDevice, + /// 帧缓冲设备 + FramebufferDevice, /// kvm设备 KvmDevice, /// 管道文件 @@ -99,6 +101,7 @@ impl FileType { FileType::Pipe => DT_FIFO, FileType::SymLink => DT_LNK, FileType::Socket => DT_SOCK, + FileType::FramebufferDevice => DT_CHR, }; } } @@ -536,7 +539,7 @@ pub struct Metadata { pub gid: usize, /// 文件指向的设备的id(对于设备文件系统来说) - pub raw_dev: usize, + pub raw_dev: DeviceNumber, } impl Default for Metadata { @@ -555,7 +558,7 @@ impl Default for Metadata { nlinks: 1, uid: 0, gid: 0, - raw_dev: 0, + raw_dev: DeviceNumber::default(), }; } } @@ -587,11 +590,6 @@ pub struct FsInfo { pub max_name_len: usize, } -/// @brief 整合主设备号+次设备号 -pub fn make_rawdev(major: usize, minor: usize) -> usize { - ((major & 0xffffff) << 8) | (minor & 0xff) -} - /// @brief #[repr(C)] #[derive(Debug)] @@ -619,7 +617,7 @@ impl Metadata { nlinks: 1, uid: 0, gid: 0, - raw_dev: 0, + raw_dev: DeviceNumber::default(), } } } diff --git a/kernel/src/filesystem/vfs/syscall.rs b/kernel/src/filesystem/vfs/syscall.rs index 77c1f3a30..a5126bfc8 100644 --- a/kernel/src/filesystem/vfs/syscall.rs +++ b/kernel/src/filesystem/vfs/syscall.rs @@ -775,7 +775,7 @@ impl Syscall { kstat.nlink = metadata.nlinks as u64; kstat.uid = metadata.uid as i32; kstat.gid = metadata.gid as i32; - kstat.rdev = metadata.raw_dev as i64; + kstat.rdev = metadata.raw_dev.data() as i64; kstat.mode = metadata.mode; match file.lock().file_type() { FileType::File => kstat.mode.insert(ModeType::S_IFREG), @@ -786,6 +786,7 @@ impl Syscall { FileType::Socket => kstat.mode.insert(ModeType::S_IFSOCK), FileType::Pipe => kstat.mode.insert(ModeType::S_IFIFO), FileType::KvmDevice => kstat.mode.insert(ModeType::S_IFCHR), + FileType::FramebufferDevice => kstat.mode.insert(ModeType::S_IFCHR), } return Ok(kstat); diff --git a/kernel/src/ipc/pipe.rs b/kernel/src/ipc/pipe.rs index ef57d87c7..2b6f7cee4 100644 --- a/kernel/src/ipc/pipe.rs +++ b/kernel/src/ipc/pipe.rs @@ -125,7 +125,7 @@ impl LockedPipeInode { nlinks: 1, uid: 0, gid: 0, - raw_dev: 0, + raw_dev: Default::default(), }, reader: 0, writer: 0, diff --git a/kernel/src/sched/syscall.rs b/kernel/src/sched/syscall.rs index 0934c8b13..06da798d0 100644 --- a/kernel/src/sched/syscall.rs +++ b/kernel/src/sched/syscall.rs @@ -33,4 +33,8 @@ impl Syscall { drop(irq_guard); return Ok(0); } + + pub fn sched_yield() -> Result { + return Syscall::sched(false); + } } diff --git a/kernel/src/syscall/mod.rs b/kernel/src/syscall/mod.rs index 2c79b6c5c..abd01953f 100644 --- a/kernel/src/syscall/mod.rs +++ b/kernel/src/syscall/mod.rs @@ -956,6 +956,14 @@ impl Syscall { Self::fchmodat(dirfd, pathname, mode) } + SYS_SCHED_GETAFFINITY => { + // todo: 这个系统调用还没有实现 + + Err(SystemError::ENOSYS) + } + + SYS_SCHED_YIELD => Self::sched_yield(), + _ => panic!("Unsupported syscall ID: {}", syscall_num), }; diff --git a/kernel/src/virt/kvm/kvm_dev.rs b/kernel/src/virt/kvm/kvm_dev.rs index 2e1dd1078..f0ca43207 100644 --- a/kernel/src/virt/kvm/kvm_dev.rs +++ b/kernel/src/virt/kvm/kvm_dev.rs @@ -1,8 +1,9 @@ +use crate::driver::base::device::device_number::DeviceNumber; use crate::filesystem::devfs::{DevFS, DeviceINode}; use crate::filesystem::vfs::{ core::generate_inode_id, file::{File, FileMode}, - make_rawdev, FilePrivateData, FileSystem, FileType, IndexNode, Metadata, + FilePrivateData, FileSystem, FileType, IndexNode, Metadata, }; use crate::process::ProcessManager; use crate::{arch::KVMArch, libs::spinlock::SpinLock, time::TimeSpec}; @@ -65,7 +66,7 @@ impl LockedKvmInode { nlinks: 1, uid: 0, gid: 0, - raw_dev: make_rawdev(1, 4), // 这里用来作为device number + raw_dev: DeviceNumber::default(), // 这里用来作为device number }, }; diff --git a/kernel/src/virt/kvm/vcpu_dev.rs b/kernel/src/virt/kvm/vcpu_dev.rs index b5ca6c11e..916587fa3 100644 --- a/kernel/src/virt/kvm/vcpu_dev.rs +++ b/kernel/src/virt/kvm/vcpu_dev.rs @@ -1,9 +1,10 @@ use crate::arch::kvm::vmx::vcpu::VcpuContextFrame; use crate::arch::KVMArch; +use crate::driver::base::device::device_number::DeviceNumber; use crate::filesystem::devfs::DevFS; use crate::filesystem::vfs::{ - core::generate_inode_id, file::FileMode, make_rawdev, FilePrivateData, FileSystem, FileType, - IndexNode, Metadata, + core::generate_inode_id, file::FileMode, FilePrivateData, FileSystem, FileType, IndexNode, + Metadata, }; use crate::mm::VirtAddr; use crate::syscall::user_access::copy_from_user; @@ -76,7 +77,7 @@ impl LockedVcpuInode { nlinks: 1, uid: 0, gid: 0, - raw_dev: make_rawdev(1, 4), // 这里用来作为device number + raw_dev: DeviceNumber::default(), // 这里用来作为device number }, // fdata: InodeInfo { // kvm: kvm, diff --git a/kernel/src/virt/kvm/vm_dev.rs b/kernel/src/virt/kvm/vm_dev.rs index 2f12a677e..4f311395d 100644 --- a/kernel/src/virt/kvm/vm_dev.rs +++ b/kernel/src/virt/kvm/vm_dev.rs @@ -1,8 +1,9 @@ +use crate::driver::base::device::device_number::DeviceNumber; use crate::filesystem::devfs::DevFS; use crate::filesystem::vfs::{ core::generate_inode_id, file::{File, FileMode}, - make_rawdev, FilePrivateData, FileSystem, FileType, IndexNode, Metadata, + FilePrivateData, FileSystem, FileType, IndexNode, Metadata, }; use crate::mm::VirtAddr; use crate::process::ProcessManager; @@ -74,7 +75,7 @@ impl LockedVmInode { nlinks: 1, uid: 0, gid: 0, - raw_dev: make_rawdev(1, 4), // 这里用来作为device number + raw_dev: DeviceNumber::default(), // 这里用来作为device number }, // fdata: InodeInfo { // kvm: kvm,