use dma_api::*;// ----- OS Side -----init(&Impled);structImpled;implOsalforImpled{fnmap(&self,addr: std::ptr::NonNull<u8>,size:usize,direction:Direction) -> u64{/// your virtual to physical mapping code here.println!("map @{:?}, size {size:#x}, {direction:?}", addr);
addr.as_ptr()asusizeas_}fnunmap(&self,addr: std::ptr::NonNull<u8>,size:usize){println!("unmap @{:?}, size {size:#x}", addr);}fnflush(&self,addr: std::ptr::NonNull<u8>,size:usize){/// flush cache to memoryprintln!("flush @{:?}, size {size:#x}", addr);}fninvalidate(&self,addr: std::ptr::NonNull<u8>,size:usize){/// invalidate cacheprintln!("invalidate @{:?}, size {size:#x}", addr);}}// then you can do some thing with the driver.// ----- Driver Side -----// use global allocator to alloc `to device` type memory#[cfg(feature = "alloc")]{let dma_mask = u64::MAX;letmut dma:DVec<u32> = DVec::zeros(dma_mask,10,0x1000,Direction::ToDevice).unwrap();// flush cache to memory.
dma.set(0,1);// do nothing with cachelet o = dma.get(0).unwrap();assert_eq!(o,1);}Uh oh!
There was an error while loading. Please reload this page.
Latest commit
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|