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