Lines Matching defs:T

343 /// - The size in bytes of the allocation is equal to `size_of::<T> * count`.
344 /// - `size_of::<T> * count` fits into a `usize`.
357 pub struct CoherentAllocation<T: AsBytes + FromBytes> {
361 cpu_addr: *mut T,
365 impl<T: AsBytes + FromBytes> CoherentAllocation<T> {
366 /// Allocates a region of `size_of::<T> * count` of coherent memory.
384 ) -> Result<CoherentAllocation<T>> {
386 core::mem::size_of::<T>() > 0,
391 .checked_mul(core::mem::size_of::<T>())
411 // - The allocated `size` is equal to `size_of::<T> * count`.
417 cpu_addr: ret.cast::<T>(),
428 ) -> Result<CoherentAllocation<T>> {
432 /// Returns the number of elements `T` in this allocation.
442 // INVARIANT: The type invariant of `Self` guarantees that `size_of::<T> * count` fits into
444 self.count * core::mem::size_of::<T>()
448 pub fn start_ptr(&self) -> *const T {
454 pub fn start_ptr_mut(&mut self) -> *mut T {
464 /// Returns a DMA handle starting at `offset` (in units of `T`) which may be given to the
472 // INVARIANT: The type invariant of `Self` guarantees that `size_of::<T> * count` fits
474 Ok(self.dma_handle + (offset * core::mem::size_of::<T>()) as DmaAddress)
488 /// `offset` and `count` are in units of `T`, not the number of bytes.
500 pub unsafe fn as_slice(&self, offset: usize, count: usize) -> Result<&[T]> {
520 pub unsafe fn as_slice_mut(&mut self, offset: usize, count: usize) -> Result<&mut [T]> {
531 /// Writes data to the region starting from `offset`. `offset` is in units of `T`, not the
552 pub unsafe fn write(&mut self, src: &[T], offset: usize) -> Result {
566 /// units of `T`, not the number of bytes.
570 pub fn item_from_index(&self, offset: usize) -> Result<*mut T> {
630 impl<T: AsBytes + FromBytes> Drop for CoherentAllocation<T> {
632 let size = self.count * core::mem::size_of::<T>();
648 // SAFETY: It is safe to send a `CoherentAllocation` to another thread if `T`
650 unsafe impl<T: AsBytes + FromBytes + Send> Send for CoherentAllocation<T> {}