Rust XHCI Implementation.
This commit is contained in:
parent
da2eb4fda3
commit
c1ab41bbad
19 changed files with 933 additions and 110 deletions
|
|
@ -4,17 +4,34 @@ use core::{
|
|||
ptr::NonNull,
|
||||
};
|
||||
|
||||
use alloc::{slice, vec::Vec};
|
||||
use alloc::{boxed::Box, slice, vec::Vec};
|
||||
|
||||
use crate::mem::MemoryRegion;
|
||||
|
||||
pub struct PhysicalBox<T: ?Sized> {
|
||||
data: NonNull<T>,
|
||||
#[allow(dead_code)]
|
||||
region: MemoryRegion,
|
||||
physical_address: usize,
|
||||
_marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T> PhysicalBox<T> {
|
||||
pub fn new(data: T) -> Self {
|
||||
let (memory_region, paddr) =
|
||||
MemoryRegion::contiguous_physical(size_of::<T>() as u64).expect("Failed to allocate");
|
||||
// UNWRAP: We know this isn't null.
|
||||
let ptr = NonNull::new(memory_region.mut_ptr_at_offset(0)).unwrap();
|
||||
unsafe { ptr.write(data) };
|
||||
Self {
|
||||
data: ptr,
|
||||
region: memory_region,
|
||||
physical_address: paddr as usize,
|
||||
_marker: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ?Sized> PhysicalBox<T> {
|
||||
pub fn physical_address(&self) -> usize {
|
||||
self.physical_address
|
||||
|
|
@ -50,7 +67,7 @@ impl<T> PhysicalBox<[T]> {
|
|||
{
|
||||
let layout = core::alloc::Layout::array::<T>(len).expect("Layout overflow");
|
||||
|
||||
// TODO: Implement a function like alloc that takes a layout. let (memory_region, paddr) =
|
||||
// TODO: Implement a function like alloc that takes a layout.
|
||||
let (memory_region, paddr) =
|
||||
MemoryRegion::contiguous_physical(layout.size() as u64).expect("Failed to allocate");
|
||||
|
||||
|
|
@ -122,6 +139,13 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// SAFETY: We are the only owner of this pointer.
|
||||
unsafe impl<T: ?Sized> Send for PhysicalBox<T> where Box<T>: Send {}
|
||||
|
||||
/// SAFETY: You must have a mutable reference to this
|
||||
/// type to modify the data at the pointer.
|
||||
unsafe impl<T: ?Sized> Sync for PhysicalBox<T> where Box<T>: Sync {}
|
||||
|
||||
impl<T: ?Sized> Drop for PhysicalBox<T> {
|
||||
fn drop(&mut self) {
|
||||
// SAFETY:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue