Rust XHCI Implementation.
This commit is contained in:
parent
e621d144e9
commit
3d0db07a5d
10 changed files with 438 additions and 30 deletions
64
'
Normal file
64
'
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
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<I> Index<I> for TrbRing {
|
||||
type Output = TransferRequestBlock;
|
||||
|
||||
fn index(&self, index: I) -> &Self::Output {
|
||||
self.0[index]
|
||||
}
|
||||
}
|
||||
|
||||
impl<I> IndexMut<I> for TrbRing
|
||||
where
|
||||
I: SliceIndex<[TransferRequestBlock]>,
|
||||
{
|
||||
fn index_mut(&mut self, index: I) -> &mut Self::Output {
|
||||
&mut self.0[index]
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue