File tree Expand file tree Collapse file tree 3 files changed +16
-2
lines changed Expand file tree Collapse file tree 3 files changed +16
-2
lines changed Original file line number Diff line number Diff line change 47
47
const_ptr_is_null, // https://github.com/rust-lang/rust/issues/74939
48
48
trait_upcasting, // https://github.com/rust-lang/rust/issues/65991
49
49
naked_functions, // https://github.com/rust-lang/rust/issues/32408
50
+ strict_provenance
50
51
) ]
51
52
#![ deny( trivial_numeric_casts, unused_allocation) ]
52
53
#![ test_runner( crate :: tests:: test_runner) ]
Original file line number Diff line number Diff line change @@ -77,6 +77,13 @@ impl LockedFrameAllocator {
77
77
. call_once ( || Mutex :: new ( GlobalFrameAllocator :: new ( memory_map) ) ) ;
78
78
}
79
79
80
+ pub fn dealloc ( & self , addr : PhysAddr , size_bytes : usize ) {
81
+ let order = order_from_size ( size_bytes as u64 ) ;
82
+
83
+ let mut allocator = self . 0 . get ( ) . unwrap ( ) . lock_irq ( ) ;
84
+ allocator. deallocate_frame_inner ( addr, order) ;
85
+ }
86
+
80
87
pub fn alloc ( & self , size_bytes : usize ) -> Option < PhysAddr > {
81
88
let order = order_from_size ( size_bytes as u64 ) ;
82
89
Original file line number Diff line number Diff line change @@ -30,7 +30,6 @@ pub struct DmaAllocator;
30
30
// the data using the ISA or PCI system bus (which carry physical addresses).
31
31
unsafe impl Allocator for DmaAllocator {
32
32
fn allocate ( & self , layout : Layout ) -> Result < NonNull < [ u8 ] > , AllocError > {
33
- // XXX: The DMA buffer must be aligned to a page boundary.
34
33
let size_bytes = layout. size ( ) ;
35
34
36
35
let phys = FRAME_ALLOCATOR . alloc_zeroed ( size_bytes) . ok_or ( AllocError ) ?;
@@ -41,7 +40,14 @@ unsafe impl Allocator for DmaAllocator {
41
40
Ok ( NonNull :: slice_from_raw_parts ( ptr, size_bytes) )
42
41
}
43
42
44
- unsafe fn deallocate ( & self , _ptr : NonNull < u8 > , _layout : Layout ) { }
43
+ unsafe fn deallocate ( & self , ptr : NonNull < u8 > , layout : Layout ) {
44
+ let size_bytes = layout. size ( ) ;
45
+
46
+ let addr: usize = ptr. addr ( ) . into ( ) ;
47
+ let addr = VirtAddr :: new ( addr as u64 ) ;
48
+
49
+ FRAME_ALLOCATOR . dealloc ( addr. as_hhdm_phys ( ) , size_bytes) ;
50
+ }
45
51
}
46
52
47
53
pub type DmaBuffer < T > = Box < T , DmaAllocator > ;
You can’t perform that action at this time.
0 commit comments