@@ -21,16 +21,14 @@ impl<T> Dma<T> {
21
21
}
22
22
23
23
pub unsafe fn zeroed ( ) -> Result < Dma < T > > {
24
- // let (sip_addr, physical_addr) = physical_alloc::<T>()?;
24
+ let ( sip_addr, physical_addr) = physical_alloc :: < T > ( ) ?;
25
25
26
- // (sip_addr as *mut u8).write_bytes(0, mem::size_of::<T>());
27
-
28
- // Ok(Dma {
29
- // physical_addr,
30
- // sip_addr,
31
- // })
32
- Dma :: new ( mem:: zeroed ( ) )
26
+ ( sip_addr as * mut u8 ) . write_bytes ( 0 , mem:: size_of :: < T > ( ) ) ;
33
27
28
+ Ok ( Dma {
29
+ physical_addr,
30
+ sip_addr,
31
+ } )
34
32
}
35
33
36
34
pub fn physical ( & self ) -> u64 {
@@ -54,17 +52,15 @@ impl<T> DerefMut for Dma<T> {
54
52
impl < T > Drop for Dma < T > {
55
53
fn drop ( & mut self ) {
56
54
unsafe {
57
- self . sip_addr . drop_in_place ( ) ;
55
+ // self.sip_addr.drop_in_place();
58
56
59
57
// let _ = physical_unmap(self.sip_addr);
60
58
}
61
59
}
62
60
}
63
61
64
62
pub unsafe fn physical_map < T : Sized > ( phys_addr : u64 ) -> Result < * mut T > {
65
- let page_count = page_count :: < T > ( ) ;
66
-
67
- let res: Result < u32 > = abi:: physical_map ( phys_addr, page_count) . into ( ) ;
63
+ let res: Result < u32 > = abi:: physical_map ( phys_addr, mem:: size_of :: < T > ( ) ) . into ( ) ;
68
64
69
65
res. map ( |offset| offset as _ )
70
66
}
@@ -79,16 +75,9 @@ pub unsafe fn physical_map<T: Sized>(phys_addr: u64) -> Result<*mut T> {
79
75
80
76
/// Allocate some physical memory and return the physical address.
81
77
pub unsafe fn physical_alloc < T : Sized > ( ) -> Result < ( * mut T , u64 ) > {
82
- let page_count = page_count :: < T > ( ) ;
83
-
84
78
let mut physical_addr = 0 ;
85
79
86
- let res: Result < u32 > = abi:: physical_alloc ( page_count , & mut physical_addr as * mut _ ) . into ( ) ;
80
+ let res: Result < u32 > = abi:: physical_alloc ( mem :: size_of :: < T > ( ) , & mut physical_addr as * mut _ ) . into ( ) ;
87
81
88
82
res. map ( |sip_addr| ( sip_addr as * mut T , physical_addr) )
89
- }
90
-
91
- fn page_count < T : Sized > ( ) -> usize {
92
- let wasm_page_size = 1 << 16 ;
93
- ( mem:: size_of :: < T > ( ) + wasm_page_size - 1 ) / wasm_page_size
94
83
}
0 commit comments