From d5d8afa602d2420154604c929b9d8d39ee09c729 Mon Sep 17 00:00:00 2001 From: Joerg Roedel Date: Thu, 7 Feb 2019 12:59:14 +0100 Subject: [PATCH 2677/2944] swiotlb: Add is_swiotlb_active() function to #39258954 commit 492366f7b4237257ef50ca9c431a6a0d50225aca upstream This function will be used from dma_direct code to determine the maximum segment size of a dma mapping. 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 | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index 1d8b141..db6ad04 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -116,6 +116,7 @@ extern void swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr, extern void __init swiotlb_exit(void); unsigned int swiotlb_max_segment(void); size_t swiotlb_max_mapping_size(struct device *dev); +bool is_swiotlb_active(void); #else static inline void swiotlb_exit(void) { } static inline unsigned int swiotlb_max_segment(void) { return 0; } @@ -123,6 +124,10 @@ static inline void swiotlb_exit(void) { } { return SIZE_MAX; } +static inline bool is_swiotlb_active(void) +{ + return false; +} #endif extern void swiotlb_print_info(void); diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 5240e39..5d091b1 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -1014,6 +1014,15 @@ size_t swiotlb_max_mapping_size(struct device *dev) return ((size_t)1 << IO_TLB_SHIFT) * IO_TLB_SEGSIZE; } +bool is_swiotlb_active(void) +{ + /* + * When SWIOTLB is initialized, even if io_tlb_start points to physical + * address zero, io_tlb_end surely doesn't. + */ + return io_tlb_end != 0; +} + void *swiotlb_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs) { -- 1.8.3.1