From c734e171dc08bf4dc0e7b48591f74e61763df5a0 Mon Sep 17 00:00:00 2001 From: Joerg Roedel Date: Thu, 7 Feb 2019 12:59:13 +0100 Subject: [PATCH 2676/2944] swiotlb: Introduce swiotlb_max_mapping_size() to #39258954 commit abe420bfae528c92bd8cc5ecb62dc95672b1fd6f upstream The function returns the maximum size that can be remapped by the SWIOTLB implementation. This function will be later exposed to users through the DMA-API. Cc: stable@vger.kernel.org Reviewed-by: Konrad Rzeszutek Wilk Reviewed-by: Christoph Hellwig Signed-off-by: Joerg Roedel Signed-off-by: Michael S. Tsirkin Signed-off-by: Zelin Deng Reviewed-by: Artie Ding Reviewed-by: Baolin Wang --- include/linux/swiotlb.h | 5 +++++ kernel/dma/swiotlb.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index 965be92..1d8b141 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -115,9 +115,14 @@ extern void swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr, #ifdef CONFIG_SWIOTLB extern void __init swiotlb_exit(void); unsigned int swiotlb_max_segment(void); +size_t swiotlb_max_mapping_size(struct device *dev); #else static inline void swiotlb_exit(void) { } static inline unsigned int swiotlb_max_segment(void) { return 0; } +static inline size_t swiotlb_max_mapping_size(struct device *dev); +{ + return SIZE_MAX; +} #endif extern void swiotlb_print_info(void); diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 2a8c41f..5240e39 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -1009,6 +1009,11 @@ void swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr, return __phys_to_dma(hwdev, io_tlb_end - 1) <= mask; } +size_t swiotlb_max_mapping_size(struct device *dev) +{ + return ((size_t)1 << IO_TLB_SHIFT) * IO_TLB_SEGSIZE; +} + void *swiotlb_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs) { -- 1.8.3.1