Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: dma: remove dma::CoherentAllocation<T>

Now that everything has been converted to the new dma::Coherent<T> API,
remove dma::CoherentAllocation<T>.

Suggested-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Gary Guo <gary@garyguo.net>
Link: https://patch.msgid.link/DH8O47F2GM1Z.3H3E13RSKIV22@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

-150
-150
rust/kernel/dma.rs
··· 853 853 } 854 854 } 855 855 856 - // Type alias for compatibility. 857 - #[doc(hidden)] 858 - pub type CoherentAllocation<T> = Coherent<[T]>; 859 - 860 - impl<T: AsBytes + FromBytes> CoherentAllocation<T> { 861 - /// Allocates a region of `size_of::<T> * count` of coherent memory. 862 - /// 863 - /// # Examples 864 - /// 865 - /// ``` 866 - /// # use kernel::device::{Bound, Device}; 867 - /// use kernel::dma::{attrs::*, CoherentAllocation}; 868 - /// 869 - /// # fn test(dev: &Device<Bound>) -> Result { 870 - /// let c: CoherentAllocation<u64> = 871 - /// CoherentAllocation::alloc_attrs(dev, 4, GFP_KERNEL, DMA_ATTR_NO_WARN)?; 872 - /// # Ok::<(), Error>(()) } 873 - /// ``` 874 - pub fn alloc_attrs( 875 - dev: &device::Device<Bound>, 876 - count: usize, 877 - gfp_flags: kernel::alloc::Flags, 878 - dma_attrs: Attrs, 879 - ) -> Result<CoherentAllocation<T>> { 880 - Coherent::alloc_slice_with_attrs(dev, count, gfp_flags, dma_attrs) 881 - } 882 - 883 - /// Performs the same functionality as [`CoherentAllocation::alloc_attrs`], except the 884 - /// `dma_attrs` is 0 by default. 885 - pub fn alloc_coherent( 886 - dev: &device::Device<Bound>, 887 - count: usize, 888 - gfp_flags: kernel::alloc::Flags, 889 - ) -> Result<CoherentAllocation<T>> { 890 - CoherentAllocation::alloc_attrs(dev, count, gfp_flags, Attrs(0)) 891 - } 892 - 893 - /// Returns the base address to the allocated region in the CPU's virtual address space. 894 - pub fn start_ptr(&self) -> *const T { 895 - self.as_ptr().cast() 896 - } 897 - 898 - /// Returns the base address to the allocated region in the CPU's virtual address space as 899 - /// a mutable pointer. 900 - pub fn start_ptr_mut(&mut self) -> *mut T { 901 - self.as_mut_ptr().cast() 902 - } 903 - 904 - /// Returns a DMA handle starting at `offset` (in units of `T`) which may be given to the 905 - /// device as the DMA address base of the region. 906 - /// 907 - /// Returns `EINVAL` if `offset` is not within the bounds of the allocation. 908 - pub fn dma_handle_with_offset(&self, offset: usize) -> Result<DmaAddress> { 909 - if offset >= self.len() { 910 - Err(EINVAL) 911 - } else { 912 - Ok(self.dma_handle + (offset * core::mem::size_of::<T>()) as DmaAddress) 913 - } 914 - } 915 - 916 - /// Common helper to validate a range applied from the allocated region in the CPU's virtual 917 - /// address space. 918 - fn validate_range(&self, offset: usize, count: usize) -> Result { 919 - if offset.checked_add(count).ok_or(EOVERFLOW)? > self.len() { 920 - return Err(EINVAL); 921 - } 922 - Ok(()) 923 - } 924 - 925 - /// Returns the data from the region starting from `offset` as a slice. 926 - /// `offset` and `count` are in units of `T`, not the number of bytes. 927 - /// 928 - /// For ringbuffer type of r/w access or use-cases where the pointer to the live data is needed, 929 - /// [`CoherentAllocation::start_ptr`] or [`CoherentAllocation::start_ptr_mut`] could be used 930 - /// instead. 931 - /// 932 - /// # Safety 933 - /// 934 - /// * Callers must ensure that the device does not read/write to/from memory while the returned 935 - /// slice is live. 936 - /// * Callers must ensure that this call does not race with a write to the same region while 937 - /// the returned slice is live. 938 - pub unsafe fn as_slice(&self, offset: usize, count: usize) -> Result<&[T]> { 939 - self.validate_range(offset, count)?; 940 - // SAFETY: 941 - // - The pointer is valid due to type invariant on `CoherentAllocation`, 942 - // we've just checked that the range and index is within bounds. The immutability of the 943 - // data is also guaranteed by the safety requirements of the function. 944 - // - `offset + count` can't overflow since it is smaller than `self.count` and we've checked 945 - // that `self.count` won't overflow early in the constructor. 946 - Ok(unsafe { core::slice::from_raw_parts(self.start_ptr().add(offset), count) }) 947 - } 948 - 949 - /// Performs the same functionality as [`CoherentAllocation::as_slice`], except that a mutable 950 - /// slice is returned. 951 - /// 952 - /// # Safety 953 - /// 954 - /// * Callers must ensure that the device does not read/write to/from memory while the returned 955 - /// slice is live. 956 - /// * Callers must ensure that this call does not race with a read or write to the same region 957 - /// while the returned slice is live. 958 - pub unsafe fn as_slice_mut(&mut self, offset: usize, count: usize) -> Result<&mut [T]> { 959 - self.validate_range(offset, count)?; 960 - // SAFETY: 961 - // - The pointer is valid due to type invariant on `CoherentAllocation`, 962 - // we've just checked that the range and index is within bounds. The immutability of the 963 - // data is also guaranteed by the safety requirements of the function. 964 - // - `offset + count` can't overflow since it is smaller than `self.count` and we've checked 965 - // that `self.count` won't overflow early in the constructor. 966 - Ok(unsafe { core::slice::from_raw_parts_mut(self.start_ptr_mut().add(offset), count) }) 967 - } 968 - 969 - /// Writes data to the region starting from `offset`. `offset` is in units of `T`, not the 970 - /// number of bytes. 971 - /// 972 - /// # Safety 973 - /// 974 - /// * Callers must ensure that this call does not race with a read or write to the same region 975 - /// that overlaps with this write. 976 - /// 977 - /// # Examples 978 - /// 979 - /// ``` 980 - /// # fn test(alloc: &mut kernel::dma::CoherentAllocation<u8>) -> Result { 981 - /// let somedata: [u8; 4] = [0xf; 4]; 982 - /// let buf: &[u8] = &somedata; 983 - /// // SAFETY: There is no concurrent HW operation on the device and no other R/W access to the 984 - /// // region. 985 - /// unsafe { alloc.write(buf, 0)?; } 986 - /// # Ok::<(), Error>(()) } 987 - /// ``` 988 - pub unsafe fn write(&mut self, src: &[T], offset: usize) -> Result { 989 - self.validate_range(offset, src.len())?; 990 - // SAFETY: 991 - // - The pointer is valid due to type invariant on `CoherentAllocation` 992 - // and we've just checked that the range and index is within bounds. 993 - // - `offset + count` can't overflow since it is smaller than `self.count` and we've checked 994 - // that `self.count` won't overflow early in the constructor. 995 - unsafe { 996 - core::ptr::copy_nonoverlapping( 997 - src.as_ptr(), 998 - self.start_ptr_mut().add(offset), 999 - src.len(), 1000 - ) 1001 - }; 1002 - Ok(()) 1003 - } 1004 - } 1005 - 1006 856 /// Note that the device configured to do DMA must be halted before this object is dropped. 1007 857 impl<T: KnownSize + ?Sized> Drop for Coherent<T> { 1008 858 fn drop(&mut self) {