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 4747 const_ptr_is_null, // https://github.com/rust-lang/rust/issues/74939
4848 trait_upcasting, // https://github.com/rust-lang/rust/issues/65991
4949 naked_functions, // https://github.com/rust-lang/rust/issues/32408
50+ strict_provenance
5051) ]
5152#![ deny( trivial_numeric_casts, unused_allocation) ]
5253#![ test_runner( crate :: tests:: test_runner) ]
Original file line number Diff line number Diff line change @@ -77,6 +77,13 @@ impl LockedFrameAllocator {
7777 . call_once ( || Mutex :: new ( GlobalFrameAllocator :: new ( memory_map) ) ) ;
7878 }
7979
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+
8087 pub fn alloc ( & self , size_bytes : usize ) -> Option < PhysAddr > {
8188 let order = order_from_size ( size_bytes as u64 ) ;
8289
Original file line number Diff line number Diff line change @@ -30,7 +30,6 @@ pub struct DmaAllocator;
3030// the data using the ISA or PCI system bus (which carry physical addresses).
3131unsafe impl Allocator for DmaAllocator {
3232 fn allocate ( & self , layout : Layout ) -> Result < NonNull < [ u8 ] > , AllocError > {
33- // XXX: The DMA buffer must be aligned to a page boundary.
3433 let size_bytes = layout. size ( ) ;
3534
3635 let phys = FRAME_ALLOCATOR . alloc_zeroed ( size_bytes) . ok_or ( AllocError ) ?;
@@ -41,7 +40,14 @@ unsafe impl Allocator for DmaAllocator {
4140 Ok ( NonNull :: slice_from_raw_parts ( ptr, size_bytes) )
4241 }
4342
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+ }
4551}
4652
4753pub type DmaBuffer < T > = Box < T , DmaAllocator > ;
You can’t perform that action at this time.
0 commit comments