@@ -7,7 +7,9 @@ use crate::{
77 process:: Identity ,
88 uapi:: {
99 self ,
10- drm:: { self , DRM_FORMAT_XRGB8888 , drm_mode_modeinfo} ,
10+ drm:: {
11+ self , DRM_FORMAT_XRGB8888 , DRM_MODE_CURSOR_BO , DRM_MODE_CURSOR_MOVE , drm_mode_modeinfo,
12+ } ,
1113 } ,
1214 util:: { event:: Event , mutex:: spin:: SpinMutex } ,
1315 vfs:: {
@@ -71,7 +73,7 @@ pub trait Device: Send + Sync {
7173 fn driver_version ( & self ) -> ( i32 , i32 , i32 ) ;
7274
7375 /// Returns a tuple of (name, description, date).
74- fn driver_info ( & self ) -> ( & [ u8 ] , & [ u8 ] , & [ u8 ] ) ;
76+ fn driver_info ( & self ) -> ( & str , & str , & str ) ;
7577
7678 /// Creates a dumb framebuffer. Also returns the pitch in bytes.
7779 fn create_dumb (
@@ -82,7 +84,11 @@ pub trait Device: Send + Sync {
8284 bpp : u32 ,
8385 ) -> EResult < ( Arc < dyn BufferObject > , u32 ) > {
8486 let _ = ( file, width, height, bpp) ;
85- Err ( Errno :: ENOSYS )
87+ warn ! (
88+ "drm::Device::create_dumb is not implemented for {}!" ,
89+ self . driver_info( ) . 0
90+ ) ;
91+ Err ( Errno :: ENOTTY )
8692 }
8793
8894 fn create_fb (
@@ -95,7 +101,11 @@ pub trait Device: Send + Sync {
95101 pitch : u32 ,
96102 ) -> EResult < Arc < Framebuffer > > {
97103 let _ = ( file, buffer, width, height, format, pitch) ;
98- Err ( Errno :: ENOSYS )
104+ warn ! (
105+ "drm::Device::create_fb is not implemented for {}!" ,
106+ self . driver_info( ) . 0
107+ ) ;
108+ Err ( Errno :: ENOTTY )
99109 }
100110
101111 fn commit ( & self , state : & AtomicState ) ;
@@ -105,19 +115,29 @@ pub trait Device: Send + Sync {
105115 /// `hot_x` and `hot_y` are the hotspot offsets (pixels from top-left of cursor image).
106116 fn set_cursor (
107117 & self ,
108- _crtc_id : u32 ,
109- _buffer : Option < Arc < dyn BufferObject > > ,
110- _width : u32 ,
111- _height : u32 ,
112- _hot_x : i32 ,
113- _hot_y : i32 ,
118+ crtc_id : u32 ,
119+ buffer : Option < Arc < dyn BufferObject > > ,
120+ width : u32 ,
121+ height : u32 ,
122+ hot_x : i32 ,
123+ hot_y : i32 ,
114124 ) -> EResult < ( ) > {
115- Err ( Errno :: ENOSYS )
125+ let _ = ( buffer, crtc_id, width, height, hot_x, hot_y) ;
126+ warn ! (
127+ "drm::Device::set_cursor is not implemented for {}!" ,
128+ self . driver_info( ) . 0
129+ ) ;
130+ Err ( Errno :: ENOTTY )
116131 }
117132
118133 /// Move the cursor to a new position on the given CRTC.
119- fn move_cursor ( & self , _crtc_id : u32 , _x : i32 , _y : i32 ) -> EResult < ( ) > {
120- Err ( Errno :: ENOSYS )
134+ fn move_cursor ( & self , crtc_id : u32 , x : i32 , y : i32 ) -> EResult < ( ) > {
135+ let _ = ( crtc_id, x, y) ;
136+ warn ! (
137+ "drm::Device::move_cursor is not implemented for {}!" ,
138+ self . driver_info( ) . 0
139+ ) ;
140+ Err ( Errno :: ENOTTY )
121141 }
122142}
123143
@@ -289,19 +309,25 @@ impl FileOps for DrmFile {
289309
290310 if !val. name . is_null ( ) && val. name_len > 0 {
291311 let len = name. len ( ) . min ( val. name_len ) ;
292- val. name . write_slice ( & name[ ..len] ) . ok_or ( Errno :: EFAULT ) ?;
312+ val. name
313+ . write_slice ( & name. as_bytes ( ) [ ..len] )
314+ . ok_or ( Errno :: EFAULT ) ?;
293315 }
294316 val. name_len = name. len ( ) ;
295317
296318 if !val. date . is_null ( ) && val. date_len > 0 {
297319 let len = date. len ( ) . min ( val. date_len ) ;
298- val. date . write_slice ( & date[ ..len] ) . ok_or ( Errno :: EFAULT ) ?;
320+ val. date
321+ . write_slice ( & date. as_bytes ( ) [ ..len] )
322+ . ok_or ( Errno :: EFAULT ) ?;
299323 }
300324 val. date_len = date. len ( ) ;
301325
302326 if !val. desc . is_null ( ) && val. desc_len > 0 {
303327 let len = desc. len ( ) . min ( val. desc_len ) ;
304- val. desc . write_slice ( & desc[ ..len] ) . ok_or ( Errno :: EFAULT ) ?;
328+ val. desc
329+ . write_slice ( & desc. as_bytes ( ) [ ..len] )
330+ . ok_or ( Errno :: EFAULT ) ?;
305331 }
306332 val. desc_len = desc. len ( ) ;
307333
@@ -997,22 +1023,20 @@ impl FileOps for DrmFile {
9971023 let ptr = UserPtr :: < drm:: drm_mode_cursor > :: new ( arg) ;
9981024 let val = ptr. read ( ) . ok_or ( Errno :: EFAULT ) ?;
9991025
1000- const DRM_MODE_CURSOR_BO : u32 = 0x01 ;
1001- const DRM_MODE_CURSOR_MOVE : u32 = 0x02 ;
1002-
10031026 if val. flags & DRM_MODE_CURSOR_BO != 0 {
10041027 if val. handle == 0 {
10051028 // Hide cursor
10061029 self . device . set_cursor ( val. crtc_id , None , 0 , 0 , 0 , 0 ) ?;
10071030 } else {
10081031 // Set cursor image
1009- let buffers = self . buffers . lock ( ) ;
1010- let buffer = buffers
1011- . iter ( )
1012- . find ( |b| b. id ( ) == val. handle )
1013- . ok_or ( Errno :: EINVAL ) ?
1014- . clone ( ) ;
1015- drop ( buffers) ;
1032+ let buffer = {
1033+ let buffers = self . buffers . lock ( ) ;
1034+ buffers
1035+ . iter ( )
1036+ . find ( |b| b. id ( ) == val. handle )
1037+ . ok_or ( Errno :: EINVAL ) ?
1038+ . clone ( )
1039+ } ;
10161040 self . device . set_cursor (
10171041 val. crtc_id ,
10181042 Some ( buffer) ,
@@ -1031,22 +1055,20 @@ impl FileOps for DrmFile {
10311055 let ptr = UserPtr :: < drm:: drm_mode_cursor2 > :: new ( arg) ;
10321056 let val = ptr. read ( ) . ok_or ( Errno :: EFAULT ) ?;
10331057
1034- const DRM_MODE_CURSOR_BO : u32 = 0x01 ;
1035- const DRM_MODE_CURSOR_MOVE : u32 = 0x02 ;
1036-
10371058 if val. flags & DRM_MODE_CURSOR_BO != 0 {
10381059 if val. handle == 0 {
10391060 // Hide cursor
10401061 self . device . set_cursor ( val. crtc_id , None , 0 , 0 , 0 , 0 ) ?;
10411062 } else {
10421063 // Set cursor image with hotspot
1043- let buffers = self . buffers . lock ( ) ;
1044- let buffer = buffers
1045- . iter ( )
1046- . find ( |b| b. id ( ) == val. handle )
1047- . ok_or ( Errno :: EINVAL ) ?
1048- . clone ( ) ;
1049- drop ( buffers) ;
1064+ let buffer = {
1065+ let buffers = self . buffers . lock ( ) ;
1066+ buffers
1067+ . iter ( )
1068+ . find ( |b| b. id ( ) == val. handle )
1069+ . ok_or ( Errno :: EINVAL ) ?
1070+ . clone ( )
1071+ } ;
10501072 self . device . set_cursor (
10511073 val. crtc_id ,
10521074 Some ( buffer) ,
@@ -1082,7 +1104,7 @@ impl FileOps for DrmFile {
10821104 }
10831105 x => {
10841106 error ! ( "Unknown ioctl {x:x}" ) ;
1085- return Err ( Errno :: ENOSYS ) ;
1107+ return Err ( Errno :: ENOTTY ) ;
10861108 }
10871109 }
10881110 Ok ( 0 )
0 commit comments