Skip to content

Commit 33d2c5e

Browse files
rleonmszyprow
authored andcommitted
x86: Use physical address for DMA mapping
Perform mechanical conversion from DMA .map_page to .map_phys. 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/20251015-remove-map-page-v5-12-3bbfe3a25cdf@kernel.org
1 parent 38c0d0e commit 33d2c5e

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

arch/x86/kernel/amd_gart_64.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,14 @@ static dma_addr_t dma_map_area(struct device *dev, dma_addr_t phys_mem,
222222
}
223223

224224
/* Map a single area into the IOMMU */
225-
static dma_addr_t gart_map_page(struct device *dev, struct page *page,
226-
unsigned long offset, size_t size,
227-
enum dma_data_direction dir,
225+
static dma_addr_t gart_map_phys(struct device *dev, phys_addr_t paddr,
226+
size_t size, enum dma_data_direction dir,
228227
unsigned long attrs)
229228
{
230229
unsigned long bus;
231-
phys_addr_t paddr = page_to_phys(page) + offset;
230+
231+
if (unlikely(attrs & DMA_ATTR_MMIO))
232+
return DMA_MAPPING_ERROR;
232233

233234
if (!need_iommu(dev, paddr, size))
234235
return paddr;
@@ -242,7 +243,7 @@ static dma_addr_t gart_map_page(struct device *dev, struct page *page,
242243
/*
243244
* Free a DMA mapping.
244245
*/
245-
static void gart_unmap_page(struct device *dev, dma_addr_t dma_addr,
246+
static void gart_unmap_phys(struct device *dev, dma_addr_t dma_addr,
246247
size_t size, enum dma_data_direction dir,
247248
unsigned long attrs)
248249
{
@@ -282,7 +283,7 @@ static void gart_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
282283
for_each_sg(sg, s, nents, i) {
283284
if (!s->dma_length || !s->length)
284285
break;
285-
gart_unmap_page(dev, s->dma_address, s->dma_length, dir, 0);
286+
gart_unmap_phys(dev, s->dma_address, s->dma_length, dir, 0);
286287
}
287288
}
288289

@@ -487,7 +488,7 @@ static void
487488
gart_free_coherent(struct device *dev, size_t size, void *vaddr,
488489
dma_addr_t dma_addr, unsigned long attrs)
489490
{
490-
gart_unmap_page(dev, dma_addr, size, DMA_BIDIRECTIONAL, 0);
491+
gart_unmap_phys(dev, dma_addr, size, DMA_BIDIRECTIONAL, 0);
491492
dma_direct_free(dev, size, vaddr, dma_addr, attrs);
492493
}
493494

@@ -668,8 +669,8 @@ static __init int init_amd_gatt(struct agp_kern_info *info)
668669
static const struct dma_map_ops gart_dma_ops = {
669670
.map_sg = gart_map_sg,
670671
.unmap_sg = gart_unmap_sg,
671-
.map_page = gart_map_page,
672-
.unmap_page = gart_unmap_page,
672+
.map_phys = gart_map_phys,
673+
.unmap_phys = gart_unmap_phys,
673674
.alloc = gart_alloc_coherent,
674675
.free = gart_free_coherent,
675676
.mmap = dma_common_mmap,

0 commit comments

Comments
 (0)