use core::{ ops::{Deref, Index, IndexMut}, slice::SliceIndex, }; use alloc::{boxed::Box, vec}; use bitfield_struct::bitfield; use mammoth::physical_box::PhysicalBox; #[bitfield(u128)] pub struct TransferRequestBlock { parameter: u64, status: u32, cycle: bool, evaluate_next: bool, flag_2: bool, flag_3: bool, flag_4: bool, flag_5: bool, flag_6: bool, flag_7: bool, flag_8: bool, flag_9: bool, #[bits(6)] trb_type: u8, control: u16, } #[repr(transparent)] pub struct TrbRing(PhysicalBox<[TransferRequestBlock]>); impl TrbRing { pub fn new(size: usize) -> Self { Self(PhysicalBox::default_with_count( TransferRequestBlock::default(), size, )) } pub fn len(&self) -> usize { self.0.len() } pub fn physical_address(&self) -> usize { self.0.physical_address() } } impl Index for TrbRing { type Output = TransferRequestBlock; fn index(&self, index: I) -> &Self::Output { self.0[index] } } impl IndexMut for TrbRing where I: SliceIndex<[TransferRequestBlock]>, { fn index_mut(&mut self, index: I) -> &mut Self::Output { &mut self.0[index] } }