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.

dma-mapping: convert dma_direct_*map_page to be phys_addr_t based

Convert the DMA direct mapping functions to accept physical addresses
directly instead of page+offset parameters. The functions were already
operating on physical addresses internally, so this change eliminates
the redundant page-to-physical conversion at the API boundary.

The functions dma_direct_map_page() and dma_direct_unmap_page() are
renamed to dma_direct_map_phys() and dma_direct_unmap_phys() respectively,
with their calling convention changed from (struct page *page,
unsigned long offset) to (phys_addr_t phys).

Architecture-specific functions arch_dma_map_page_direct() and
arch_dma_unmap_page_direct() are similarly renamed to
arch_dma_map_phys_direct() and arch_dma_unmap_phys_direct().

The is_pci_p2pdma_page() checks are replaced with DMA_ATTR_MMIO checks
to allow integration with dma_direct_map_resource and dma_direct_map_phys()
is extended to support MMIO path either.

Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Link: https://lore.kernel.org/r/bb15a22f76dc2e26683333ff54e789606cfbfcf0.1757423202.git.leonro@nvidia.com

authored by

Leon Romanovsky and committed by
Marek Szyprowski
e53d29f9 f9374de1

+48 -33
+2 -2
arch/powerpc/kernel/dma-iommu.c
··· 14 14 #define can_map_direct(dev, addr) \ 15 15 ((dev)->bus_dma_limit >= phys_to_dma((dev), (addr))) 16 16 17 - bool arch_dma_map_page_direct(struct device *dev, phys_addr_t addr) 17 + bool arch_dma_map_phys_direct(struct device *dev, phys_addr_t addr) 18 18 { 19 19 if (likely(!dev->bus_dma_limit)) 20 20 return false; ··· 24 24 25 25 #define is_direct_handle(dev, h) ((h) >= (dev)->archdata.dma_offset) 26 26 27 - bool arch_dma_unmap_page_direct(struct device *dev, dma_addr_t dma_handle) 27 + bool arch_dma_unmap_phys_direct(struct device *dev, dma_addr_t dma_handle) 28 28 { 29 29 if (likely(!dev->bus_dma_limit)) 30 30 return false;
+4 -4
include/linux/dma-map-ops.h
··· 395 395 void arch_dma_clear_uncached(void *addr, size_t size); 396 396 397 397 #ifdef CONFIG_ARCH_HAS_DMA_MAP_DIRECT 398 - bool arch_dma_map_page_direct(struct device *dev, phys_addr_t addr); 399 - bool arch_dma_unmap_page_direct(struct device *dev, dma_addr_t dma_handle); 398 + bool arch_dma_map_phys_direct(struct device *dev, phys_addr_t addr); 399 + bool arch_dma_unmap_phys_direct(struct device *dev, dma_addr_t dma_handle); 400 400 bool arch_dma_map_sg_direct(struct device *dev, struct scatterlist *sg, 401 401 int nents); 402 402 bool arch_dma_unmap_sg_direct(struct device *dev, struct scatterlist *sg, 403 403 int nents); 404 404 #else 405 - #define arch_dma_map_page_direct(d, a) (false) 406 - #define arch_dma_unmap_page_direct(d, a) (false) 405 + #define arch_dma_map_phys_direct(d, a) (false) 406 + #define arch_dma_unmap_phys_direct(d, a) (false) 407 407 #define arch_dma_map_sg_direct(d, s, n) (false) 408 408 #define arch_dma_unmap_sg_direct(d, s, n) (false) 409 409 #endif
+3 -3
kernel/dma/direct.c
··· 448 448 if (sg_dma_is_bus_address(sg)) 449 449 sg_dma_unmark_bus_address(sg); 450 450 else 451 - dma_direct_unmap_page(dev, sg->dma_address, 451 + dma_direct_unmap_phys(dev, sg->dma_address, 452 452 sg_dma_len(sg), dir, attrs); 453 453 } 454 454 } ··· 471 471 */ 472 472 break; 473 473 case PCI_P2PDMA_MAP_NONE: 474 - sg->dma_address = dma_direct_map_page(dev, sg_page(sg), 475 - sg->offset, sg->length, dir, attrs); 474 + sg->dma_address = dma_direct_map_phys(dev, sg_phys(sg), 475 + sg->length, dir, attrs); 476 476 if (sg->dma_address == DMA_MAPPING_ERROR) { 477 477 ret = -EIO; 478 478 goto out_unmap;
+35 -20
kernel/dma/direct.h
··· 80 80 arch_dma_mark_clean(paddr, size); 81 81 } 82 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) 83 + static inline dma_addr_t dma_direct_map_phys(struct device *dev, 84 + phys_addr_t phys, size_t size, enum dma_data_direction dir, 85 + unsigned long attrs) 86 86 { 87 - phys_addr_t phys = page_to_phys(page) + offset; 88 - dma_addr_t dma_addr = phys_to_dma(dev, phys); 87 + dma_addr_t dma_addr; 89 88 90 89 if (is_swiotlb_force_bounce(dev)) { 91 - if (is_pci_p2pdma_page(page)) 92 - return DMA_MAPPING_ERROR; 90 + if (attrs & DMA_ATTR_MMIO) 91 + goto err_overflow; 92 + 93 93 return swiotlb_map(dev, phys, size, dir, attrs); 94 94 } 95 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); 96 + if (attrs & DMA_ATTR_MMIO) { 97 + dma_addr = phys; 98 + if (unlikely(!dma_capable(dev, dma_addr, size, false))) 99 + goto err_overflow; 100 + } else { 101 + dma_addr = phys_to_dma(dev, phys); 102 + if (unlikely(!dma_capable(dev, dma_addr, size, true)) || 103 + dma_kmalloc_needs_bounce(dev, size, dir)) { 104 + if (is_swiotlb_active(dev)) 105 + return swiotlb_map(dev, phys, size, dir, attrs); 102 106 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 + goto err_overflow; 108 + } 107 109 } 108 110 109 - if (!dev_is_dma_coherent(dev) && !(attrs & DMA_ATTR_SKIP_CPU_SYNC)) 111 + if (!dev_is_dma_coherent(dev) && 112 + !(attrs & (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_MMIO))) 110 113 arch_sync_dma_for_device(phys, size, dir); 111 114 return dma_addr; 115 + 116 + err_overflow: 117 + dev_WARN_ONCE( 118 + dev, 1, 119 + "DMA addr %pad+%zu overflow (mask %llx, bus limit %llx).\n", 120 + &dma_addr, size, *dev->dma_mask, dev->bus_dma_limit); 121 + return DMA_MAPPING_ERROR; 112 122 } 113 123 114 - static inline void dma_direct_unmap_page(struct device *dev, dma_addr_t addr, 124 + static inline void dma_direct_unmap_phys(struct device *dev, dma_addr_t addr, 115 125 size_t size, enum dma_data_direction dir, unsigned long attrs) 116 126 { 117 - phys_addr_t phys = dma_to_phys(dev, addr); 127 + phys_addr_t phys; 118 128 129 + if (attrs & DMA_ATTR_MMIO) 130 + /* nothing to do: uncached and no swiotlb */ 131 + return; 132 + 133 + phys = dma_to_phys(dev, addr); 119 134 if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC)) 120 135 dma_direct_sync_single_for_cpu(dev, addr, size, dir); 121 136
+4 -4
kernel/dma/mapping.c
··· 166 166 return DMA_MAPPING_ERROR; 167 167 168 168 if (dma_map_direct(dev, ops) || 169 - arch_dma_map_page_direct(dev, phys + size)) 170 - addr = dma_direct_map_page(dev, page, offset, size, dir, attrs); 169 + arch_dma_map_phys_direct(dev, phys + size)) 170 + addr = dma_direct_map_phys(dev, phys, size, dir, attrs); 171 171 else if (use_dma_iommu(dev)) 172 172 addr = iommu_dma_map_phys(dev, phys, size, dir, attrs); 173 173 else ··· 187 187 188 188 BUG_ON(!valid_dma_direction(dir)); 189 189 if (dma_map_direct(dev, ops) || 190 - arch_dma_unmap_page_direct(dev, addr + size)) 191 - dma_direct_unmap_page(dev, addr, size, dir, attrs); 190 + arch_dma_unmap_phys_direct(dev, addr + size)) 191 + dma_direct_unmap_phys(dev, addr, size, dir, attrs); 192 192 else if (use_dma_iommu(dev)) 193 193 iommu_dma_unmap_phys(dev, addr, size, dir, attrs); 194 194 else