[PATCH v3 4/4] dma-mapping: remove unused mapping resource callbacks

Leon Romanovsky posted 4 patches 2 weeks, 2 days ago
There is a newer version of this series
[PATCH v3 4/4] dma-mapping: remove unused mapping resource callbacks
Posted by Leon Romanovsky 2 weeks, 2 days ago
From: Leon Romanovsky <leonro@nvidia.com>

After ARM conversion to use physical addresses for the mapping,
there is no in-kernel users for map_resource/unmap_resource callbacks,
so remove it.

Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 include/linux/dma-map-ops.h |  6 ------
 kernel/dma/mapping.c        | 16 ++++------------
 2 files changed, 4 insertions(+), 18 deletions(-)

diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h
index 25603cb273769..a2ec1566aa270 100644
--- a/include/linux/dma-map-ops.h
+++ b/include/linux/dma-map-ops.h
@@ -53,12 +53,6 @@ struct dma_map_ops {
 			enum dma_data_direction dir, unsigned long attrs);
 	void (*unmap_sg)(struct device *dev, struct scatterlist *sg, int nents,
 			enum dma_data_direction dir, unsigned long attrs);
-	dma_addr_t (*map_resource)(struct device *dev, phys_addr_t phys_addr,
-			size_t size, enum dma_data_direction dir,
-			unsigned long attrs);
-	void (*unmap_resource)(struct device *dev, dma_addr_t dma_handle,
-			size_t size, enum dma_data_direction dir,
-			unsigned long attrs);
 	void (*sync_single_for_cpu)(struct device *dev, dma_addr_t dma_handle,
 			size_t size, enum dma_data_direction dir);
 	void (*sync_single_for_device)(struct device *dev,
diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c
index 4080aebe5debb..32a85bfdf873a 100644
--- a/kernel/dma/mapping.c
+++ b/kernel/dma/mapping.c
@@ -157,7 +157,7 @@ dma_addr_t dma_map_phys(struct device *dev, phys_addr_t phys, size_t size,
 {
 	const struct dma_map_ops *ops = get_dma_ops(dev);
 	bool is_mmio = attrs & DMA_ATTR_MMIO;
-	dma_addr_t addr;
+	dma_addr_t addr = DMA_MAPPING_ERROR;
 
 	BUG_ON(!valid_dma_direction(dir));
 
@@ -171,18 +171,13 @@ dma_addr_t dma_map_phys(struct device *dev, phys_addr_t phys, size_t size,
 		addr = iommu_dma_map_phys(dev, phys, size, dir, attrs);
 	else if (ops->map_phys)
 		addr = ops->map_phys(dev, phys, size, dir, attrs);
-	else if (is_mmio) {
-		if (!ops->map_resource)
-			return DMA_MAPPING_ERROR;
-
-		addr = ops->map_resource(dev, phys, size, dir, attrs);
-	} else {
+	else if (!is_mmio && ops->map_page) {
 		struct page *page = phys_to_page(phys);
 		size_t offset = offset_in_page(phys);
 
 		/*
 		 * The dma_ops API contract for ops->map_page() requires
-		 * kmappable memory, while ops->map_resource() does not.
+		 * kmappable memory.
 		 */
 		addr = ops->map_page(dev, page, offset, size, dir, attrs);
 	}
@@ -227,10 +222,7 @@ void dma_unmap_phys(struct device *dev, dma_addr_t addr, size_t size,
 		iommu_dma_unmap_phys(dev, addr, size, dir, attrs);
 	else if (ops->unmap_phys)
 		ops->unmap_phys(dev, addr, size, dir, attrs);
-	else if (is_mmio) {
-		if (ops->unmap_resource)
-			ops->unmap_resource(dev, addr, size, dir, attrs);
-	} else
+	else
 		ops->unmap_page(dev, addr, size, dir, attrs);
 	trace_dma_unmap_phys(dev, addr, size, dir, attrs);
 	debug_dma_unmap_phys(dev, addr, size, dir);
-- 
2.51.0
Re: [PATCH v3 4/4] dma-mapping: remove unused mapping resource callbacks
Posted by Jason Gunthorpe 2 weeks, 1 day ago
On Tue, Sep 16, 2025 at 10:32:07AM +0300, Leon Romanovsky wrote:
> From: Leon Romanovsky <leonro@nvidia.com>
> 
> After ARM conversion to use physical addresses for the mapping,
> there is no in-kernel users for map_resource/unmap_resource callbacks,
> so remove it.
> 
> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
> ---
>  include/linux/dma-map-ops.h |  6 ------
>  kernel/dma/mapping.c        | 16 ++++------------
>  2 files changed, 4 insertions(+), 18 deletions(-)

Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>

Looks like xen_swiotlb_dma_ops will be easy enough to fix..

Jason
Re: [PATCH v3 4/4] dma-mapping: remove unused mapping resource callbacks
Posted by Leon Romanovsky 2 weeks, 2 days ago
On Tue, Sep 16, 2025 at 10:32:07AM +0300, Leon Romanovsky wrote:
> From: Leon Romanovsky <leonro@nvidia.com>
> 
> After ARM conversion to use physical addresses for the mapping,
> there is no in-kernel users for map_resource/unmap_resource callbacks,
> so remove it.
> 
> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
> ---
>  include/linux/dma-map-ops.h |  6 ------
>  kernel/dma/mapping.c        | 16 ++++------------
>  2 files changed, 4 insertions(+), 18 deletions(-)

This patch is premature, I missed another map_resource user in
drivers/xen/swiotlb-xen.c.

Thanks

> 
> diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h
> index 25603cb273769..a2ec1566aa270 100644
> --- a/include/linux/dma-map-ops.h
> +++ b/include/linux/dma-map-ops.h
> @@ -53,12 +53,6 @@ struct dma_map_ops {
>  			enum dma_data_direction dir, unsigned long attrs);
>  	void (*unmap_sg)(struct device *dev, struct scatterlist *sg, int nents,
>  			enum dma_data_direction dir, unsigned long attrs);
> -	dma_addr_t (*map_resource)(struct device *dev, phys_addr_t phys_addr,
> -			size_t size, enum dma_data_direction dir,
> -			unsigned long attrs);
> -	void (*unmap_resource)(struct device *dev, dma_addr_t dma_handle,
> -			size_t size, enum dma_data_direction dir,
> -			unsigned long attrs);
>  	void (*sync_single_for_cpu)(struct device *dev, dma_addr_t dma_handle,
>  			size_t size, enum dma_data_direction dir);
>  	void (*sync_single_for_device)(struct device *dev,
> diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c
> index 4080aebe5debb..32a85bfdf873a 100644
> --- a/kernel/dma/mapping.c
> +++ b/kernel/dma/mapping.c
> @@ -157,7 +157,7 @@ dma_addr_t dma_map_phys(struct device *dev, phys_addr_t phys, size_t size,
>  {
>  	const struct dma_map_ops *ops = get_dma_ops(dev);
>  	bool is_mmio = attrs & DMA_ATTR_MMIO;
> -	dma_addr_t addr;
> +	dma_addr_t addr = DMA_MAPPING_ERROR;
>  
>  	BUG_ON(!valid_dma_direction(dir));
>  
> @@ -171,18 +171,13 @@ dma_addr_t dma_map_phys(struct device *dev, phys_addr_t phys, size_t size,
>  		addr = iommu_dma_map_phys(dev, phys, size, dir, attrs);
>  	else if (ops->map_phys)
>  		addr = ops->map_phys(dev, phys, size, dir, attrs);
> -	else if (is_mmio) {
> -		if (!ops->map_resource)
> -			return DMA_MAPPING_ERROR;
> -
> -		addr = ops->map_resource(dev, phys, size, dir, attrs);
> -	} else {
> +	else if (!is_mmio && ops->map_page) {
>  		struct page *page = phys_to_page(phys);
>  		size_t offset = offset_in_page(phys);
>  
>  		/*
>  		 * The dma_ops API contract for ops->map_page() requires
> -		 * kmappable memory, while ops->map_resource() does not.
> +		 * kmappable memory.
>  		 */
>  		addr = ops->map_page(dev, page, offset, size, dir, attrs);
>  	}
> @@ -227,10 +222,7 @@ void dma_unmap_phys(struct device *dev, dma_addr_t addr, size_t size,
>  		iommu_dma_unmap_phys(dev, addr, size, dir, attrs);
>  	else if (ops->unmap_phys)
>  		ops->unmap_phys(dev, addr, size, dir, attrs);
> -	else if (is_mmio) {
> -		if (ops->unmap_resource)
> -			ops->unmap_resource(dev, addr, size, dir, attrs);
> -	} else
> +	else
>  		ops->unmap_page(dev, addr, size, dir, attrs);
>  	trace_dma_unmap_phys(dev, addr, size, dir, attrs);
>  	debug_dma_unmap_phys(dev, addr, size, dir);
> -- 
> 2.51.0
> 
>