Rust XHCI Implementation.
This commit is contained in:
parent
0b95098748
commit
2c271360ce
25 changed files with 1288 additions and 202 deletions
|
|
@ -78,6 +78,10 @@ impl MemoryRegion {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn vaddr(&self) -> usize {
|
||||
self.virt_addr as usize
|
||||
}
|
||||
|
||||
pub fn slice<T>(&self) -> &[T] {
|
||||
unsafe {
|
||||
slice::from_raw_parts(
|
||||
|
|
@ -246,11 +250,11 @@ pub fn map_cap_and_leak(mem_cap: Capability) -> u64 {
|
|||
vaddr
|
||||
}
|
||||
|
||||
pub fn map_direct_physical_and_leak(paddr: u64, size: u64) -> u64 {
|
||||
pub fn map_direct_physical_and_leak<T>(paddr: u64, size: u64) -> *mut T {
|
||||
let mem_cap = syscall::memory_object_direct_physical(paddr, size).unwrap();
|
||||
let vaddr = syscall::address_space_map(&mem_cap).unwrap();
|
||||
mem_cap.release();
|
||||
vaddr
|
||||
vaddr as *mut T
|
||||
}
|
||||
|
||||
pub fn map_physical_and_leak(size: u64) -> (u64, u64) {
|
||||
|
|
|
|||
|
|
@ -4,12 +4,13 @@ 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>,
|
||||
|
|
@ -54,6 +55,12 @@ impl<T> PhysicalBox<[T]> {
|
|||
let (memory_region, paddr) =
|
||||
MemoryRegion::contiguous_physical(layout.size() as u64).expect("Failed to allocate");
|
||||
|
||||
crate::debug!(
|
||||
"Physical box allocated: v {:0x} p {:0x}",
|
||||
memory_region.vaddr(),
|
||||
paddr
|
||||
);
|
||||
|
||||
let ptr: *mut T = memory_region.mut_ptr_at_offset(0);
|
||||
for i in 0..len {
|
||||
unsafe {
|
||||
|
|
@ -122,6 +129,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