Skip to content
Snippets Groups Projects
Commit 3855c517 authored by Andreas Hindborg's avatar Andreas Hindborg Committed by Lyude Paul
Browse files

WIP: rust: device: add dma map functions

Based on
https://github.com/wedsonaf/linux/commit/02541e65a7e778c0049fed86ae49302bc07abed3

TODO:
* All of these are currently missing documentation. We'll add that later
  once we have a better idea of what we'll all need.
parent 7be6db63
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
use crate::{ use crate::{
bindings, bindings,
error::Error,
prelude::*,
types::{ARef, Opaque}, types::{ARef, Opaque},
}; };
use core::{fmt, ptr}; use core::{fmt, ptr};
...@@ -189,6 +191,51 @@ impl Device { ...@@ -189,6 +191,51 @@ impl Device {
) )
}; };
} }
pub fn dma_set_mask(&self, mask: u64) -> Result {
let dev = self.as_raw();
let ret = unsafe { bindings::dma_set_mask(dev as _, mask) };
if ret != 0 {
Err(Error::from_errno(ret))
} else {
Ok(())
}
}
pub fn dma_set_coherent_mask(&self, mask: u64) -> Result {
let dev = self.as_raw();
let ret = unsafe { bindings::dma_set_coherent_mask(dev as _, mask) };
if ret != 0 {
Err(Error::from_errno(ret))
} else {
Ok(())
}
}
pub fn dma_map_sg(&self, sglist: &mut [bindings::scatterlist], dir: i32) -> Result {
let dev = self.as_raw();
let count = sglist.len().try_into()?;
let ret = unsafe {
bindings::dma_map_sg_attrs(
dev,
&mut sglist[0],
count,
dir,
bindings::DMA_ATTR_NO_WARN.into(),
)
};
// TODO: It may map fewer than what was requested. What happens then?
if ret == 0 {
return Err(EIO);
}
Ok(())
}
pub fn dma_unmap_sg(&self, sglist: &mut [bindings::scatterlist], dir: i32) {
let dev = self.as_raw();
let count = sglist.len() as _;
unsafe { bindings::dma_unmap_sg_attrs(dev, &mut sglist[0], count, dir, 0) };
}
} }
// SAFETY: Instances of `Device` are always reference-counted. // SAFETY: Instances of `Device` are always reference-counted.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment