From: Joerg Roedel Date: Thu, 7 Feb 2019 12:59:14 +0100 Subject: swiotlb: Add is_swiotlb_active() function Git-commit: 492366f7b4237257ef50ca9c431a6a0d50225aca Patch-mainline: v5.1-rc1 References: bsc#1120008 This function will be used from dma_direct code to determine the maximum segment size of a dma mapping. Reviewed-by: Konrad Rzeszutek Wilk Reviewed-by: Christoph Hellwig Signed-off-by: Joerg Roedel Signed-off-by: Michael S. Tsirkin --- include/linux/swiotlb.h | 6 ++++++ kernel/dma/swiotlb.c | 9 +++++++++ 2 files changed, 15 insertions(+) --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -117,6 +117,7 @@ swiotlb_dma_supported(struct device *hwd extern void __init swiotlb_free(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_free(void) { } static inline unsigned int swiotlb_max_segment(void) { return 0; } @@ -124,6 +125,10 @@ static inline size_t swiotlb_max_mapping { return SIZE_MAX; } +static inline bool is_swiotlb_active(void) +{ + return false; +} #endif extern void swiotlb_print_info(void); --- a/lib/swiotlb.c +++ b/lib/swiotlb.c @@ -1093,3 +1093,13 @@ size_t swiotlb_max_mapping_size(struct d return ((size_t)1 << IO_TLB_SHIFT) * IO_TLB_SEGSIZE; } EXPORT_SYMBOL(swiotlb_max_mapping_size); + +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; +} +EXPORT_SYMBOL(is_swiotlb_active);