@@ -12,6 +12,7 @@ use alloc::vec::Vec;
1212use core:: cell:: UnsafeCell ;
1313use core:: mem:: { self , MaybeUninit } ;
1414
15+ use mem_barrier:: BarrierType ;
1516#[ cfg( not( feature = "pci" ) ) ]
1617use virtio:: mmio:: NotificationData ;
1718#[ cfg( feature = "pci" ) ]
@@ -25,7 +26,6 @@ use super::super::transport::pci::{ComCfg, NotifCfg, NotifCtrl};
2526use super :: error:: VirtqError ;
2627use super :: index_alloc:: IndexAlloc ;
2728use super :: { AvailBufferToken , BufferType , TransferToken , UsedBufferToken , Virtq , VirtqPrivate } ;
28- use crate :: arch:: memory_barrier;
2929use crate :: mm:: device_alloc:: DeviceAlloc ;
3030
3131struct DescrRing {
@@ -36,6 +36,7 @@ struct DescrRing {
3636 descr_table_cell : Box < UnsafeCell < [ MaybeUninit < virtq:: Desc > ] > , DeviceAlloc > ,
3737 avail_ring_cell : Box < UnsafeCell < virtq:: Avail > , DeviceAlloc > ,
3838 used_ring_cell : Box < UnsafeCell < virtq:: Used > , DeviceAlloc > ,
39+ order_platform : bool ,
3940}
4041
4142impl DescrRing {
@@ -88,14 +89,15 @@ impl DescrRing {
8889 self . avail_ring_mut ( ) . ring_mut ( true ) [ idx as usize % len] =
8990 le16:: from_ne ( index. try_into ( ) . unwrap ( ) ) ;
9091
91- memory_barrier ( ) ;
92+ super :: virtio_mem_barrier ( BarrierType :: Write , self . order_platform ) ;
9293 let next_idx = idx. wrapping_add ( 1 ) ;
9394 self . avail_ring_mut ( ) . idx = next_idx. into ( ) ;
9495
9596 Ok ( next_idx)
9697 }
9798
9899 fn try_recv ( & mut self ) -> Result < UsedBufferToken , VirtqError > {
100+ super :: virtio_mem_barrier ( BarrierType :: Read , self . order_platform ) ;
99101 if self . read_idx == self . used_ring ( ) . idx . to_ne ( ) {
100102 return Err ( VirtqError :: NoNewUsed ) ;
101103 }
@@ -123,7 +125,6 @@ impl DescrRing {
123125 }
124126 }
125127
126- memory_barrier ( ) ;
127128 self . read_idx = self . read_idx . wrapping_add ( 1 ) ;
128129 Ok ( UsedBufferToken :: from_avail_buffer_token (
129130 tkn. buff_tkn ,
@@ -291,6 +292,8 @@ impl SplitVq {
291292 vq_handler. set_drv_ctrl_addr ( DeviceAlloc . phys_addr_from ( avail_ring_cell. as_mut ( ) ) ) ;
292293 vq_handler. set_dev_ctrl_addr ( DeviceAlloc . phys_addr_from ( used_ring_cell. as_mut ( ) ) ) ;
293294
295+ let order_platform = features. contains ( virtio:: F :: ORDER_PLATFORM ) ;
296+
294297 let descr_ring = DescrRing {
295298 read_idx : 0 ,
296299 token_ring : core:: iter:: repeat_with ( || None )
@@ -302,6 +305,7 @@ impl SplitVq {
302305 descr_table_cell,
303306 avail_ring_cell,
304307 used_ring_cell,
308+ order_platform,
305309 } ;
306310
307311 let mut notif_ctrl = NotifCtrl :: new ( notif_cfg. notification_location ( & mut vq_handler) ) ;
0 commit comments