You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It'd be nice to add a support to Event Ring Segment Table Entry structure.
The implementation would be something like this:
(I'll make an actual PR once we determine whether the ring buffer type should be &[[u32;4]] or wrapped-type like &[Block]. This is mentioned in #161 )
usesuper::block::Block;use bit_field::BitField;use core::ops::{Index,IndexMut};/// The Event Ring Segment Table entry./// This plays the same role as an array pointer, and require special care to guarantee memory safety.////// For example, the entry do not implement `Drop` trait, so the user should manually free its memory.#[repr(transparent)]#[derive(Clone,Copy,Debug)]pubstructEventRingSegmentTableEntry([u32;4]);implEventRingSegmentTableEntry{/// Create new segment table entry from a block buffer./// /// # Panics////// This method will panic if `len >= 4096`.pubunsafefnfrom_buf(buf:&[Block]) -> Self{assert!(buf.len() <= u16::MAXasusize);letmut entry = Self([0;4]);
entry
.set_ring_segment_base_address(buf.as_ptr()asusizeasu64).set_ring_segment_size(buf.len()asu16);
entry
}/// Returns the entry count of the segment.pubfnlen(&self) -> usize{returnself.ring_segment_size()asusize;}/// Returns the slice that this entry is representing.pubfnas_slice(&self) -> &[Block]{unsafe{let base = self.ring_segment_base_address()as*const_;let len = self.len();
core::slice::from_raw_parts(base, len)}}/// Returns the mutable slice that this entry is representing.pubfnas_mut_slice(&mutself) -> &mut[Block]{unsafe{let base = self.ring_segment_base_address()as*mut_;let len = self.len();
core::slice::from_raw_parts_mut(base, len)}}}implEventRingSegmentTableEntry{/// Returns the value of the Ring Segment Base Address field.pubunsafefnring_segment_base_address(&self) -> u64{let l:u64 = self.0[0].into();let u:u64 = self.0[1].into();(u << 32) | l
}/// Sets the value of the Ring Segment Base Address field.////// # Panics////// This method panics if `p` is not 64-byte aligned.pubunsafefnset_ring_segment_base_address(&mutself,p:u64) -> &mutSelf{assert_eq!(
p % 64,0,"The Ring Segment Base Address must be 64-byte aligned.");let l = p.get_bits(0..32);let u = p.get_bits(32..64);self.0[0] = l.try_into().unwrap();self.0[1] = u.try_into().unwrap();self}/// Returns the value of the Ring Segment Size field.////// This field represents entry count.pubfnring_segment_size(&self) -> u16{self.0[2].get_bits(0..16)as_}/// Sets the value of the Ring Segment Size field.////// The value should be entry count.pubunsafefnset_ring_segment_size(&mutself,v:u16) -> &mutSelf{self.0[2].set_bits(0..16, v.into());self}// rw_field!([2](0..16), ring_segment_size, "Ring Segment Size", u16);/// Returns the value of the ring segment end address.pubunsafefnring_segment_bound_address(&self) -> u64{self.ring_segment_base_address() + (core::mem::size_of::<Block>()*self.ring_segment_size()asusize)asu64}}
The text was updated successfully, but these errors were encountered:
It'd be nice to add a support to Event Ring Segment Table Entry structure.
The implementation would be something like this:
(I'll make an actual PR once we determine whether the ring buffer type should be
&[[u32;4]]
or wrapped-type like&[Block]
. This is mentioned in #161 )The text was updated successfully, but these errors were encountered: