Skip to content

Commit e1d69da

Browse files
rleonmszyprow
authored andcommitted
mm/hmm: migrate to physical address-based DMA mapping API
Convert HMM DMA operations from the legacy page-based API to the new physical address-based dma_map_phys() and dma_unmap_phys() functions. This demonstrates the preferred approach for new code that should use physical addresses directly rather than page+offset parameters. The change replaces dma_map_page() and dma_unmap_page() calls with dma_map_phys() and dma_unmap_phys() respectively, using the physical address that was already available in the code. This eliminates the redundant page-to-physical address conversion and aligns with the DMA subsystem's move toward physical address-centric interfaces. This serves as an example of how new code should be written to leverage the more efficient physical address API, which provides cleaner interfaces for drivers that already have access to physical addresses. 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/d45207f195b8f77d23cc2d571c83197328a86b04.1757423202.git.leonro@nvidia.com
1 parent f732619 commit e1d69da

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

mm/hmm.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -775,8 +775,8 @@ dma_addr_t hmm_dma_map_pfn(struct device *dev, struct hmm_dma_map *map,
775775
if (WARN_ON_ONCE(dma_need_unmap(dev) && !dma_addrs))
776776
goto error;
777777

778-
dma_addr = dma_map_page(dev, page, 0, map->dma_entry_size,
779-
DMA_BIDIRECTIONAL);
778+
dma_addr = dma_map_phys(dev, paddr, map->dma_entry_size,
779+
DMA_BIDIRECTIONAL, 0);
780780
if (dma_mapping_error(dev, dma_addr))
781781
goto error;
782782

@@ -819,8 +819,8 @@ bool hmm_dma_unmap_pfn(struct device *dev, struct hmm_dma_map *map, size_t idx)
819819
dma_iova_unlink(dev, state, idx * map->dma_entry_size,
820820
map->dma_entry_size, DMA_BIDIRECTIONAL, attrs);
821821
} else if (dma_need_unmap(dev))
822-
dma_unmap_page(dev, dma_addrs[idx], map->dma_entry_size,
823-
DMA_BIDIRECTIONAL);
822+
dma_unmap_phys(dev, dma_addrs[idx], map->dma_entry_size,
823+
DMA_BIDIRECTIONAL, 0);
824824

825825
pfns[idx] &=
826826
~(HMM_PFN_DMA_MAPPED | HMM_PFN_P2PDMA | HMM_PFN_P2PDMA_BUS);

0 commit comments

Comments
 (0)