driver core: add a min_align_mask field to struct device_dma_parameters
authorJianxiong Gao <jxgao@google.com>
Mon, 1 Feb 2021 18:30:15 +0000 (10:30 -0800)
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Sat, 20 Feb 2021 15:13:26 +0000 (10:13 -0500)
Some devices rely on the address offset in a page to function
correctly (NVMe driver as an example). These devices may use
a different page size than the Linux kernel. The address offset
has to be preserved upon mapping, and in order to do so, we
need to record the page_offset_mask first.

Signed-off-by: Jianxiong Gao <jxgao@google.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
include/linux/device.h
include/linux/dma-mapping.h

index 1779f90eeb4cb4b3daf2a99b2246148de0c407a7..7960bf516dd7fead084a0cdf52a5f6fb58f04d2a 100644 (file)
@@ -291,6 +291,7 @@ struct device_dma_parameters {
         * sg limitations.
         */
        unsigned int max_segment_size;
+       unsigned int min_align_mask;
        unsigned long segment_boundary_mask;
 };
 
index 2e49996a8f391aef941563909c9cb1a05d9b9252..9c26225754e71983b62a44dc20fb0da852c3ab9f 100644 (file)
@@ -500,6 +500,22 @@ static inline int dma_set_seg_boundary(struct device *dev, unsigned long mask)
        return -EIO;
 }
 
+static inline unsigned int dma_get_min_align_mask(struct device *dev)
+{
+       if (dev->dma_parms)
+               return dev->dma_parms->min_align_mask;
+       return 0;
+}
+
+static inline int dma_set_min_align_mask(struct device *dev,
+               unsigned int min_align_mask)
+{
+       if (WARN_ON_ONCE(!dev->dma_parms))
+               return -EIO;
+       dev->dma_parms->min_align_mask = min_align_mask;
+       return 0;
+}
+
 static inline int dma_get_cache_alignment(void)
 {
 #ifdef ARCH_DMA_MINALIGN