~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/kernel/dma/direct.h

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 /*
  3  * Copyright (C) 2018 Christoph Hellwig.
  4  *
  5  * DMA operations that map physical memory directly without using an IOMMU.
  6  */
  7 #ifndef _KERNEL_DMA_DIRECT_H
  8 #define _KERNEL_DMA_DIRECT_H
  9 
 10 #include <linux/dma-direct.h>
 11 #include <linux/memremap.h>
 12 
 13 int dma_direct_get_sgtable(struct device *dev, struct sg_table *sgt,
 14                 void *cpu_addr, dma_addr_t dma_addr, size_t size,
 15                 unsigned long attrs);
 16 bool dma_direct_can_mmap(struct device *dev);
 17 int dma_direct_mmap(struct device *dev, struct vm_area_struct *vma,
 18                 void *cpu_addr, dma_addr_t dma_addr, size_t size,
 19                 unsigned long attrs);
 20 bool dma_direct_need_sync(struct device *dev, dma_addr_t dma_addr);
 21 int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl, int nents,
 22                 enum dma_data_direction dir, unsigned long attrs);
 23 bool dma_direct_all_ram_mapped(struct device *dev);
 24 size_t dma_direct_max_mapping_size(struct device *dev);
 25 
 26 #if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \
 27     defined(CONFIG_SWIOTLB)
 28 void dma_direct_sync_sg_for_device(struct device *dev, struct scatterlist *sgl,
 29                 int nents, enum dma_data_direction dir);
 30 #else
 31 static inline void dma_direct_sync_sg_for_device(struct device *dev,
 32                 struct scatterlist *sgl, int nents, enum dma_data_direction dir)
 33 {
 34 }
 35 #endif
 36 
 37 #if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \
 38     defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL) || \
 39     defined(CONFIG_SWIOTLB)
 40 void dma_direct_unmap_sg(struct device *dev, struct scatterlist *sgl,
 41                 int nents, enum dma_data_direction dir, unsigned long attrs);
 42 void dma_direct_sync_sg_for_cpu(struct device *dev,
 43                 struct scatterlist *sgl, int nents, enum dma_data_direction dir);
 44 #else
 45 static inline void dma_direct_unmap_sg(struct device *dev,
 46                 struct scatterlist *sgl, int nents, enum dma_data_direction dir,
 47                 unsigned long attrs)
 48 {
 49 }
 50 static inline void dma_direct_sync_sg_for_cpu(struct device *dev,
 51                 struct scatterlist *sgl, int nents, enum dma_data_direction dir)
 52 {
 53 }
 54 #endif
 55 
 56 static inline void dma_direct_sync_single_for_device(struct device *dev,
 57                 dma_addr_t addr, size_t size, enum dma_data_direction dir)
 58 {
 59         phys_addr_t paddr = dma_to_phys(dev, addr);
 60 
 61         swiotlb_sync_single_for_device(dev, paddr, size, dir);
 62 
 63         if (!dev_is_dma_coherent(dev))
 64                 arch_sync_dma_for_device(paddr, size, dir);
 65 }
 66 
 67 static inline void dma_direct_sync_single_for_cpu(struct device *dev,
 68                 dma_addr_t addr, size_t size, enum dma_data_direction dir)
 69 {
 70         phys_addr_t paddr = dma_to_phys(dev, addr);
 71 
 72         if (!dev_is_dma_coherent(dev)) {
 73                 arch_sync_dma_for_cpu(paddr, size, dir);
 74                 arch_sync_dma_for_cpu_all();
 75         }
 76 
 77         swiotlb_sync_single_for_cpu(dev, paddr, size, dir);
 78 
 79         if (dir == DMA_FROM_DEVICE)
 80                 arch_dma_mark_clean(paddr, size);
 81 }
 82 
 83 static inline dma_addr_t dma_direct_map_page(struct device *dev,
 84                 struct page *page, unsigned long offset, size_t size,
 85                 enum dma_data_direction dir, unsigned long attrs)
 86 {
 87         phys_addr_t phys = page_to_phys(page) + offset;
 88         dma_addr_t dma_addr = phys_to_dma(dev, phys);
 89 
 90         if (is_swiotlb_force_bounce(dev)) {
 91                 if (is_pci_p2pdma_page(page))
 92                         return DMA_MAPPING_ERROR;
 93                 return swiotlb_map(dev, phys, size, dir, attrs);
 94         }
 95 
 96         if (unlikely(!dma_capable(dev, dma_addr, size, true)) ||
 97             dma_kmalloc_needs_bounce(dev, size, dir)) {
 98                 if (is_pci_p2pdma_page(page))
 99                         return DMA_MAPPING_ERROR;
100                 if (is_swiotlb_active(dev))
101                         return swiotlb_map(dev, phys, size, dir, attrs);
102 
103                 dev_WARN_ONCE(dev, 1,
104                              "DMA addr %pad+%zu overflow (mask %llx, bus limit %llx).\n",
105                              &dma_addr, size, *dev->dma_mask, dev->bus_dma_limit);
106                 return DMA_MAPPING_ERROR;
107         }
108 
109         if (!dev_is_dma_coherent(dev) && !(attrs & DMA_ATTR_SKIP_CPU_SYNC))
110                 arch_sync_dma_for_device(phys, size, dir);
111         return dma_addr;
112 }
113 
114 static inline void dma_direct_unmap_page(struct device *dev, dma_addr_t addr,
115                 size_t size, enum dma_data_direction dir, unsigned long attrs)
116 {
117         phys_addr_t phys = dma_to_phys(dev, addr);
118 
119         if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC))
120                 dma_direct_sync_single_for_cpu(dev, addr, size, dir);
121 
122         swiotlb_tbl_unmap_single(dev, phys, size, dir,
123                                          attrs | DMA_ATTR_SKIP_CPU_SYNC);
124 }
125 #endif /* _KERNEL_DMA_DIRECT_H */
126 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php