1c566df45SLoGin use alloc::sync::Arc; 2*2eab6dd7S曾俊 use log::warn; 3c566df45SLoGin use system_error::SystemError; 4c566df45SLoGin 5c566df45SLoGin use crate::{ 6c566df45SLoGin driver::base::kobject::KObject, 7c566df45SLoGin filesystem::{ 8c566df45SLoGin sysfs::{file::sysfs_emit_str, Attribute, AttributeGroup, SysFSOpsSupport}, 9c566df45SLoGin vfs::syscall::ModeType, 10c566df45SLoGin }, 11c566df45SLoGin }; 12c566df45SLoGin 13c566df45SLoGin use super::fbmem::FbDevice; 14c566df45SLoGin 15c566df45SLoGin /// 为FbDevice实现的sysfs属性组 16c566df45SLoGin #[derive(Debug)] 17c566df45SLoGin pub struct FbDeviceAttrGroup; 18c566df45SLoGin 19c566df45SLoGin impl AttributeGroup for FbDeviceAttrGroup { name(&self) -> Option<&str>20c566df45SLoGin fn name(&self) -> Option<&str> { 21c566df45SLoGin None 22c566df45SLoGin } 23c566df45SLoGin attrs(&self) -> &[&'static dyn Attribute]24c566df45SLoGin fn attrs(&self) -> &[&'static dyn Attribute] { 25c566df45SLoGin &[ 26c566df45SLoGin &AttrBitsPerPixel, 27c566df45SLoGin &AttrBlank, 28c566df45SLoGin &AttrMode, 29c566df45SLoGin &AttrModes, 30c566df45SLoGin &AttrName, 31c566df45SLoGin &AttrPan, 32c566df45SLoGin &AttrRotate, 33c566df45SLoGin &AttrState, 34c566df45SLoGin &AttrStride, 35c566df45SLoGin &AttrVirtualSize, 36c566df45SLoGin ] 37c566df45SLoGin } 38c566df45SLoGin is_visible( &self, _kobj: alloc::sync::Arc<dyn KObject>, _attr: &'static dyn Attribute, ) -> Option<ModeType>39c566df45SLoGin fn is_visible( 40c566df45SLoGin &self, 41c566df45SLoGin _kobj: alloc::sync::Arc<dyn KObject>, 42c566df45SLoGin _attr: &'static dyn Attribute, 43c566df45SLoGin ) -> Option<ModeType> { 44c566df45SLoGin None 45c566df45SLoGin } 46c566df45SLoGin } 47c566df45SLoGin 48c566df45SLoGin #[derive(Debug)] 49c566df45SLoGin struct AttrName; 50c566df45SLoGin 51c566df45SLoGin impl Attribute for AttrName { name(&self) -> &str52c566df45SLoGin fn name(&self) -> &str { 53c566df45SLoGin "name" 54c566df45SLoGin } 55c566df45SLoGin mode(&self) -> ModeType56c566df45SLoGin fn mode(&self) -> ModeType { 57c566df45SLoGin ModeType::S_IRUGO 58c566df45SLoGin } 59c566df45SLoGin support(&self) -> SysFSOpsSupport60c566df45SLoGin fn support(&self) -> SysFSOpsSupport { 61196b75dcSLoGin SysFSOpsSupport::ATTR_SHOW 62c566df45SLoGin } 63c566df45SLoGin show(&self, kobj: Arc<dyn KObject>, buf: &mut [u8]) -> Result<usize, SystemError>64c566df45SLoGin fn show(&self, kobj: Arc<dyn KObject>, buf: &mut [u8]) -> Result<usize, SystemError> { 65c566df45SLoGin let fb_dev = kobj.arc_any().downcast::<FbDevice>().unwrap(); 66c566df45SLoGin let fb = fb_dev.framebuffer().ok_or(SystemError::ENODEV)?; 67c566df45SLoGin let name = fb.name(); 68c566df45SLoGin return sysfs_emit_str(buf, &format!("{}\n", name)); 69c566df45SLoGin } 70c566df45SLoGin } 71c566df45SLoGin 72c566df45SLoGin #[derive(Debug)] 73c566df45SLoGin struct AttrBitsPerPixel; 74c566df45SLoGin 75c566df45SLoGin impl Attribute for AttrBitsPerPixel { name(&self) -> &str76c566df45SLoGin fn name(&self) -> &str { 77c566df45SLoGin "bits_per_pixel" 78c566df45SLoGin } 79c566df45SLoGin mode(&self) -> ModeType80c566df45SLoGin fn mode(&self) -> ModeType { 81c566df45SLoGin ModeType::S_IRUGO | ModeType::S_IWUSR 82c566df45SLoGin } 83c566df45SLoGin support(&self) -> SysFSOpsSupport84c566df45SLoGin fn support(&self) -> SysFSOpsSupport { 85196b75dcSLoGin SysFSOpsSupport::ATTR_SHOW | SysFSOpsSupport::ATTR_STORE 86c566df45SLoGin } 87c566df45SLoGin store(&self, _kobj: Arc<dyn KObject>, _buf: &[u8]) -> Result<usize, SystemError>88c566df45SLoGin fn store(&self, _kobj: Arc<dyn KObject>, _buf: &[u8]) -> Result<usize, SystemError> { 89*2eab6dd7S曾俊 warn!("attr bits_per_pixel store not implemented"); 90c566df45SLoGin return Err(SystemError::ENOSYS); 91c566df45SLoGin } 92c566df45SLoGin show(&self, kobj: Arc<dyn KObject>, buf: &mut [u8]) -> Result<usize, SystemError>93c566df45SLoGin fn show(&self, kobj: Arc<dyn KObject>, buf: &mut [u8]) -> Result<usize, SystemError> { 94c566df45SLoGin let fb_dev = kobj.arc_any().downcast::<FbDevice>().unwrap(); 95c566df45SLoGin let fb = fb_dev.framebuffer().ok_or(SystemError::ENODEV)?; 96c566df45SLoGin let bits_per_pixel = fb.current_fb_var().bits_per_pixel; 97c566df45SLoGin return sysfs_emit_str(buf, &format!("{}\n", bits_per_pixel)); 98c566df45SLoGin } 99c566df45SLoGin } 100c566df45SLoGin 101c566df45SLoGin /// 用于清空屏幕的属性 102c566df45SLoGin #[derive(Debug)] 103c566df45SLoGin struct AttrBlank; 104c566df45SLoGin 105c566df45SLoGin impl Attribute for AttrBlank { name(&self) -> &str106c566df45SLoGin fn name(&self) -> &str { 107c566df45SLoGin "blank" 108c566df45SLoGin } 109c566df45SLoGin mode(&self) -> ModeType110c566df45SLoGin fn mode(&self) -> ModeType { 111c566df45SLoGin ModeType::S_IWUSR 112c566df45SLoGin } 113c566df45SLoGin support(&self) -> SysFSOpsSupport114c566df45SLoGin fn support(&self) -> SysFSOpsSupport { 115196b75dcSLoGin SysFSOpsSupport::ATTR_STORE 116c566df45SLoGin } 117c566df45SLoGin 118c566df45SLoGin // todo: https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/video/fbdev/core/fbsysfs.c#309 store(&self, _kobj: Arc<dyn KObject>, _buf: &[u8]) -> Result<usize, SystemError>119c566df45SLoGin fn store(&self, _kobj: Arc<dyn KObject>, _buf: &[u8]) -> Result<usize, SystemError> { 120*2eab6dd7S曾俊 warn!("attr blank store not implemented"); 121c566df45SLoGin return Err(SystemError::ENOSYS); 122c566df45SLoGin } 123c566df45SLoGin } 124c566df45SLoGin 125c566df45SLoGin #[derive(Debug)] 126c566df45SLoGin struct AttrMode; 127c566df45SLoGin 128c566df45SLoGin impl Attribute for AttrMode { name(&self) -> &str129c566df45SLoGin fn name(&self) -> &str { 130c566df45SLoGin "mode" 131c566df45SLoGin } 132c566df45SLoGin mode(&self) -> ModeType133c566df45SLoGin fn mode(&self) -> ModeType { 134c566df45SLoGin ModeType::S_IRUGO | ModeType::S_IWUSR 135c566df45SLoGin } 136c566df45SLoGin support(&self) -> SysFSOpsSupport137c566df45SLoGin fn support(&self) -> SysFSOpsSupport { 138196b75dcSLoGin SysFSOpsSupport::ATTR_SHOW | SysFSOpsSupport::ATTR_STORE 139c566df45SLoGin } 140c566df45SLoGin 141c566df45SLoGin /// https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/video/fbdev/core/fbsysfs.c#166 show(&self, _kobj: Arc<dyn KObject>, _buf: &mut [u8]) -> Result<usize, SystemError>142c566df45SLoGin fn show(&self, _kobj: Arc<dyn KObject>, _buf: &mut [u8]) -> Result<usize, SystemError> { 143c566df45SLoGin todo!("AttrMode::show") 144c566df45SLoGin } 145c566df45SLoGin 146c566df45SLoGin /// https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/video/fbdev/core/fbsysfs.c#135 store(&self, _kobj: Arc<dyn KObject>, _buf: &[u8]) -> Result<usize, SystemError>147c566df45SLoGin fn store(&self, _kobj: Arc<dyn KObject>, _buf: &[u8]) -> Result<usize, SystemError> { 148c566df45SLoGin todo!("AttrMode::store") 149c566df45SLoGin } 150c566df45SLoGin } 151c566df45SLoGin 152c566df45SLoGin #[derive(Debug)] 153c566df45SLoGin struct AttrModes; 154c566df45SLoGin 155c566df45SLoGin impl Attribute for AttrModes { name(&self) -> &str156c566df45SLoGin fn name(&self) -> &str { 157c566df45SLoGin "modes" 158c566df45SLoGin } 159c566df45SLoGin mode(&self) -> ModeType160c566df45SLoGin fn mode(&self) -> ModeType { 161c566df45SLoGin ModeType::S_IRUGO | ModeType::S_IWUSR 162c566df45SLoGin } 163c566df45SLoGin support(&self) -> SysFSOpsSupport164c566df45SLoGin fn support(&self) -> SysFSOpsSupport { 165196b75dcSLoGin SysFSOpsSupport::ATTR_SHOW | SysFSOpsSupport::ATTR_STORE 166c566df45SLoGin } 167c566df45SLoGin 168c566df45SLoGin /// https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/video/fbdev/core/fbsysfs.c#206 show(&self, _kobj: Arc<dyn KObject>, _buf: &mut [u8]) -> Result<usize, SystemError>169c566df45SLoGin fn show(&self, _kobj: Arc<dyn KObject>, _buf: &mut [u8]) -> Result<usize, SystemError> { 170c566df45SLoGin todo!("AttrMode::show") 171c566df45SLoGin } 172c566df45SLoGin 173c566df45SLoGin /// https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/video/fbdev/core/fbsysfs.c#177 store(&self, _kobj: Arc<dyn KObject>, _buf: &[u8]) -> Result<usize, SystemError>174c566df45SLoGin fn store(&self, _kobj: Arc<dyn KObject>, _buf: &[u8]) -> Result<usize, SystemError> { 175c566df45SLoGin todo!("AttrMode::store") 176c566df45SLoGin } 177c566df45SLoGin } 178c566df45SLoGin 179c566df45SLoGin #[derive(Debug)] 180c566df45SLoGin struct AttrPan; 181c566df45SLoGin 182c566df45SLoGin impl Attribute for AttrPan { name(&self) -> &str183c566df45SLoGin fn name(&self) -> &str { 184c566df45SLoGin "pan" 185c566df45SLoGin } 186c566df45SLoGin mode(&self) -> ModeType187c566df45SLoGin fn mode(&self) -> ModeType { 188c566df45SLoGin ModeType::S_IRUGO | ModeType::S_IWUSR 189c566df45SLoGin } 190c566df45SLoGin support(&self) -> SysFSOpsSupport191c566df45SLoGin fn support(&self) -> SysFSOpsSupport { 192196b75dcSLoGin SysFSOpsSupport::ATTR_SHOW | SysFSOpsSupport::ATTR_STORE 193c566df45SLoGin } 194c566df45SLoGin show(&self, kobj: Arc<dyn KObject>, buf: &mut [u8]) -> Result<usize, SystemError>195c566df45SLoGin fn show(&self, kobj: Arc<dyn KObject>, buf: &mut [u8]) -> Result<usize, SystemError> { 196c566df45SLoGin let fb_dev = kobj.arc_any().downcast::<FbDevice>().unwrap(); 197c566df45SLoGin let fb = fb_dev.framebuffer().ok_or(SystemError::ENODEV)?; 198c566df45SLoGin let var_info = fb.current_fb_var(); 199c566df45SLoGin return sysfs_emit_str(buf, &format!("{},{}\n", var_info.xoffset, var_info.yoffset)); 200c566df45SLoGin } 201c566df45SLoGin 202c566df45SLoGin /// https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/video/fbdev/core/fbsysfs.c#365 store(&self, _kobj: Arc<dyn KObject>, _buf: &[u8]) -> Result<usize, SystemError>203c566df45SLoGin fn store(&self, _kobj: Arc<dyn KObject>, _buf: &[u8]) -> Result<usize, SystemError> { 204c566df45SLoGin todo!("AttrPan::store") 205c566df45SLoGin } 206c566df45SLoGin } 207c566df45SLoGin 208c566df45SLoGin #[derive(Debug)] 209c566df45SLoGin struct AttrVirtualSize; 210c566df45SLoGin 211c566df45SLoGin impl Attribute for AttrVirtualSize { name(&self) -> &str212c566df45SLoGin fn name(&self) -> &str { 213c566df45SLoGin "virtual_size" 214c566df45SLoGin } 215c566df45SLoGin mode(&self) -> ModeType216c566df45SLoGin fn mode(&self) -> ModeType { 217c566df45SLoGin ModeType::S_IRUGO | ModeType::S_IWUSR 218c566df45SLoGin } 219c566df45SLoGin support(&self) -> SysFSOpsSupport220c566df45SLoGin fn support(&self) -> SysFSOpsSupport { 221196b75dcSLoGin SysFSOpsSupport::ATTR_SHOW | SysFSOpsSupport::ATTR_STORE 222c566df45SLoGin } 223c566df45SLoGin show(&self, kobj: Arc<dyn KObject>, buf: &mut [u8]) -> Result<usize, SystemError>224c566df45SLoGin fn show(&self, kobj: Arc<dyn KObject>, buf: &mut [u8]) -> Result<usize, SystemError> { 225c566df45SLoGin let fb_dev = kobj.arc_any().downcast::<FbDevice>().unwrap(); 226c566df45SLoGin let fb = fb_dev.framebuffer().ok_or(SystemError::ENODEV)?; 227c566df45SLoGin let var_info = fb.current_fb_var(); 228c566df45SLoGin return sysfs_emit_str( 229c566df45SLoGin buf, 230c566df45SLoGin &format!("{},{}\n", var_info.xres_virtual, var_info.yres_virtual), 231c566df45SLoGin ); 232c566df45SLoGin } 233c566df45SLoGin 234c566df45SLoGin /// https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/video/fbdev/core/fbsysfs.c#273 store(&self, _kobj: Arc<dyn KObject>, _buf: &[u8]) -> Result<usize, SystemError>235c566df45SLoGin fn store(&self, _kobj: Arc<dyn KObject>, _buf: &[u8]) -> Result<usize, SystemError> { 236c566df45SLoGin todo!("AttrVirtualSize::store") 237c566df45SLoGin } 238c566df45SLoGin } 239c566df45SLoGin 240c566df45SLoGin #[derive(Debug)] 241c566df45SLoGin struct AttrStride; 242c566df45SLoGin 243c566df45SLoGin impl Attribute for AttrStride { name(&self) -> &str244c566df45SLoGin fn name(&self) -> &str { 245c566df45SLoGin "stride" 246c566df45SLoGin } 247c566df45SLoGin mode(&self) -> ModeType248c566df45SLoGin fn mode(&self) -> ModeType { 249c566df45SLoGin ModeType::S_IRUGO 250c566df45SLoGin } 251c566df45SLoGin support(&self) -> SysFSOpsSupport252c566df45SLoGin fn support(&self) -> SysFSOpsSupport { 253196b75dcSLoGin SysFSOpsSupport::ATTR_SHOW 254c566df45SLoGin } 255c566df45SLoGin show(&self, kobj: Arc<dyn KObject>, buf: &mut [u8]) -> Result<usize, SystemError>256c566df45SLoGin fn show(&self, kobj: Arc<dyn KObject>, buf: &mut [u8]) -> Result<usize, SystemError> { 257c566df45SLoGin let fb_dev = kobj.arc_any().downcast::<FbDevice>().unwrap(); 258c566df45SLoGin let fb = fb_dev.framebuffer().ok_or(SystemError::ENODEV)?; 259c566df45SLoGin let fix_info = fb.current_fb_fix(); 260c566df45SLoGin return sysfs_emit_str(buf, &format!("{}\n", fix_info.line_length)); 261c566df45SLoGin } 262c566df45SLoGin } 263c566df45SLoGin 264c566df45SLoGin #[derive(Debug)] 265c566df45SLoGin struct AttrRotate; 266c566df45SLoGin 267c566df45SLoGin impl Attribute for AttrRotate { name(&self) -> &str268c566df45SLoGin fn name(&self) -> &str { 269c566df45SLoGin "rotate" 270c566df45SLoGin } 271c566df45SLoGin mode(&self) -> ModeType272c566df45SLoGin fn mode(&self) -> ModeType { 273c566df45SLoGin ModeType::S_IRUGO | ModeType::S_IWUSR 274c566df45SLoGin } 275c566df45SLoGin support(&self) -> SysFSOpsSupport276c566df45SLoGin fn support(&self) -> SysFSOpsSupport { 277196b75dcSLoGin SysFSOpsSupport::ATTR_SHOW | SysFSOpsSupport::ATTR_STORE 278c566df45SLoGin } 279c566df45SLoGin show(&self, kobj: Arc<dyn KObject>, buf: &mut [u8]) -> Result<usize, SystemError>280c566df45SLoGin fn show(&self, kobj: Arc<dyn KObject>, buf: &mut [u8]) -> Result<usize, SystemError> { 281c566df45SLoGin let fb_dev = kobj.arc_any().downcast::<FbDevice>().unwrap(); 282c566df45SLoGin let fb = fb_dev.framebuffer().ok_or(SystemError::ENODEV)?; 283c566df45SLoGin let var_info = fb.current_fb_var(); 284c566df45SLoGin 285c566df45SLoGin return sysfs_emit_str(buf, &format!("{}\n", var_info.rotate_angle)); 286c566df45SLoGin } 287c566df45SLoGin 288c566df45SLoGin /// todo https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/video/fbdev/core/fbsysfs.c#246 store(&self, _kobj: Arc<dyn KObject>, _buf: &[u8]) -> Result<usize, SystemError>289c566df45SLoGin fn store(&self, _kobj: Arc<dyn KObject>, _buf: &[u8]) -> Result<usize, SystemError> { 290c566df45SLoGin todo!("AttrRotate::store") 291c566df45SLoGin } 292c566df45SLoGin } 293c566df45SLoGin 294c566df45SLoGin #[derive(Debug)] 295c566df45SLoGin struct AttrState; 296c566df45SLoGin 297c566df45SLoGin impl Attribute for AttrState { name(&self) -> &str298c566df45SLoGin fn name(&self) -> &str { 299c566df45SLoGin "state" 300c566df45SLoGin } 301c566df45SLoGin mode(&self) -> ModeType302c566df45SLoGin fn mode(&self) -> ModeType { 303c566df45SLoGin ModeType::S_IRUGO | ModeType::S_IWUSR 304c566df45SLoGin } 305c566df45SLoGin support(&self) -> SysFSOpsSupport306c566df45SLoGin fn support(&self) -> SysFSOpsSupport { 307196b75dcSLoGin SysFSOpsSupport::ATTR_SHOW | SysFSOpsSupport::ATTR_STORE 308c566df45SLoGin } 309c566df45SLoGin show(&self, kobj: Arc<dyn KObject>, buf: &mut [u8]) -> Result<usize, SystemError>310c566df45SLoGin fn show(&self, kobj: Arc<dyn KObject>, buf: &mut [u8]) -> Result<usize, SystemError> { 311c566df45SLoGin let fb_dev = kobj.arc_any().downcast::<FbDevice>().unwrap(); 312c566df45SLoGin let fb = fb_dev.framebuffer().ok_or(SystemError::ENODEV)?; 313c566df45SLoGin 314c566df45SLoGin return sysfs_emit_str(buf, &format!("{}\n", fb.state() as u8)); 315c566df45SLoGin } 316c566df45SLoGin 317c566df45SLoGin /// todo https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/video/fbdev/core/fbsysfs.c#406 store(&self, _kobj: Arc<dyn KObject>, _buf: &[u8]) -> Result<usize, SystemError>318c566df45SLoGin fn store(&self, _kobj: Arc<dyn KObject>, _buf: &[u8]) -> Result<usize, SystemError> { 319c566df45SLoGin todo!("AttrState::store") 320c566df45SLoGin } 321c566df45SLoGin } 322