@@ -8,7 +8,7 @@ use crate::{pages, Error, Result, PAGE_SIZE};
88use alloc:: boxed:: Box ;
99use bitflags:: bitflags;
1010use log:: info;
11- use zerocopy:: { AsBytes , FromBytes , FromZeroes } ;
11+ use zerocopy:: { FromBytes , FromZeros , Immutable , IntoBytes , KnownLayout } ;
1212
1313const QUEUE_SIZE : u16 = 2 ;
1414const SUPPORTED_FEATURES : Features = Features :: RING_EVENT_IDX . union ( Features :: RING_INDIRECT_DESC ) ;
@@ -66,8 +66,8 @@ impl<H: Hal, T: Transport> VirtIOGpu<H, T> {
6666 negotiated_features. contains ( Features :: RING_EVENT_IDX ) ,
6767 ) ?;
6868
69- let queue_buf_send = FromZeroes :: new_box_slice_zeroed ( PAGE_SIZE ) ;
70- let queue_buf_recv = FromZeroes :: new_box_slice_zeroed ( PAGE_SIZE ) ;
69+ let queue_buf_send = FromZeros :: new_box_zeroed_with_elems ( PAGE_SIZE ) . unwrap ( ) ;
70+ let queue_buf_recv = FromZeros :: new_box_zeroed_with_elems ( PAGE_SIZE ) . unwrap ( ) ;
7171
7272 transport. finish_init ( ) ;
7373
@@ -173,18 +173,18 @@ impl<H: Hal, T: Transport> VirtIOGpu<H, T> {
173173 }
174174
175175 /// Send a request to the device and block for a response.
176- fn request < Req : AsBytes , Rsp : FromBytes > ( & mut self , req : Req ) -> Result < Rsp > {
176+ fn request < Req : IntoBytes + Immutable , Rsp : FromBytes > ( & mut self , req : Req ) -> Result < Rsp > {
177177 req. write_to_prefix ( & mut self . queue_buf_send ) . unwrap ( ) ;
178178 self . control_queue . add_notify_wait_pop (
179179 & [ & self . queue_buf_send ] ,
180180 & mut [ & mut self . queue_buf_recv ] ,
181181 & mut self . transport ,
182182 ) ?;
183- Ok ( Rsp :: read_from_prefix ( & self . queue_buf_recv ) . unwrap ( ) )
183+ Ok ( Rsp :: read_from_prefix ( & self . queue_buf_recv ) . unwrap ( ) . 0 )
184184 }
185185
186186 /// Send a mouse cursor operation request to the device and block for a response.
187- fn cursor_request < Req : AsBytes > ( & mut self , req : Req ) -> Result {
187+ fn cursor_request < Req : IntoBytes + Immutable > ( & mut self , req : Req ) -> Result {
188188 req. write_to_prefix ( & mut self . queue_buf_send ) . unwrap ( ) ;
189189 self . cursor_queue . add_notify_wait_pop (
190190 & [ & self . queue_buf_send ] ,
@@ -338,7 +338,7 @@ bitflags! {
338338}
339339
340340#[ repr( transparent) ]
341- #[ derive( AsBytes , Clone , Copy , Debug , Eq , PartialEq , FromBytes , FromZeroes ) ]
341+ #[ derive( Clone , Copy , Debug , Eq , FromBytes , Immutable , IntoBytes , KnownLayout , PartialEq ) ]
342342struct Command ( u32 ) ;
343343
344344impl Command {
@@ -371,7 +371,7 @@ impl Command {
371371const GPU_FLAG_FENCE : u32 = 1 << 0 ;
372372
373373#[ repr( C ) ]
374- #[ derive( AsBytes , Debug , Clone , Copy , FromBytes , FromZeroes ) ]
374+ #[ derive( Debug , Clone , Copy , FromBytes , Immutable , IntoBytes , KnownLayout ) ]
375375struct CtrlHeader {
376376 hdr_type : Command ,
377377 flags : u32 ,
@@ -402,7 +402,7 @@ impl CtrlHeader {
402402}
403403
404404#[ repr( C ) ]
405- #[ derive( AsBytes , Debug , Copy , Clone , Default , FromBytes , FromZeroes ) ]
405+ #[ derive( Debug , Copy , Clone , Default , FromBytes , Immutable , IntoBytes , KnownLayout ) ]
406406struct Rect {
407407 x : u32 ,
408408 y : u32 ,
@@ -411,7 +411,7 @@ struct Rect {
411411}
412412
413413#[ repr( C ) ]
414- #[ derive( Debug , FromBytes , FromZeroes ) ]
414+ #[ derive( Debug , FromBytes , Immutable , KnownLayout ) ]
415415struct RespDisplayInfo {
416416 header : CtrlHeader ,
417417 rect : Rect ,
@@ -420,7 +420,7 @@ struct RespDisplayInfo {
420420}
421421
422422#[ repr( C ) ]
423- #[ derive( AsBytes , Debug ) ]
423+ #[ derive( Debug , Immutable , IntoBytes , KnownLayout ) ]
424424struct ResourceCreate2D {
425425 header : CtrlHeader ,
426426 resource_id : u32 ,
@@ -430,13 +430,13 @@ struct ResourceCreate2D {
430430}
431431
432432#[ repr( u32 ) ]
433- #[ derive( AsBytes , Debug ) ]
433+ #[ derive( Debug , Immutable , IntoBytes , KnownLayout ) ]
434434enum Format {
435435 B8G8R8A8UNORM = 1 ,
436436}
437437
438438#[ repr( C ) ]
439- #[ derive( AsBytes , Debug ) ]
439+ #[ derive( Debug , Immutable , IntoBytes , KnownLayout ) ]
440440struct ResourceAttachBacking {
441441 header : CtrlHeader ,
442442 resource_id : u32 ,
@@ -447,7 +447,7 @@ struct ResourceAttachBacking {
447447}
448448
449449#[ repr( C ) ]
450- #[ derive( AsBytes , Debug ) ]
450+ #[ derive( Debug , Immutable , IntoBytes , KnownLayout ) ]
451451struct SetScanout {
452452 header : CtrlHeader ,
453453 rect : Rect ,
@@ -456,7 +456,7 @@ struct SetScanout {
456456}
457457
458458#[ repr( C ) ]
459- #[ derive( AsBytes , Debug ) ]
459+ #[ derive( Debug , Immutable , IntoBytes , KnownLayout ) ]
460460struct TransferToHost2D {
461461 header : CtrlHeader ,
462462 rect : Rect ,
@@ -466,7 +466,7 @@ struct TransferToHost2D {
466466}
467467
468468#[ repr( C ) ]
469- #[ derive( AsBytes , Debug ) ]
469+ #[ derive( Debug , Immutable , IntoBytes , KnownLayout ) ]
470470struct ResourceFlush {
471471 header : CtrlHeader ,
472472 rect : Rect ,
@@ -475,7 +475,7 @@ struct ResourceFlush {
475475}
476476
477477#[ repr( C ) ]
478- #[ derive( AsBytes , Debug , Clone , Copy ) ]
478+ #[ derive( Copy , Clone , Debug , Immutable , IntoBytes , KnownLayout ) ]
479479struct CursorPos {
480480 scanout_id : u32 ,
481481 x : u32 ,
@@ -484,7 +484,7 @@ struct CursorPos {
484484}
485485
486486#[ repr( C ) ]
487- #[ derive( AsBytes , Debug , Clone , Copy ) ]
487+ #[ derive( Copy , Clone , Debug , Immutable , IntoBytes , KnownLayout ) ]
488488struct UpdateCursor {
489489 header : CtrlHeader ,
490490 pos : CursorPos ,
0 commit comments