OSDN Git Service

dma-direct: provide a arch_dma_clear_uncached hook
authorChristoph Hellwig <hch@lst.de>
Fri, 21 Feb 2020 20:35:05 +0000 (12:35 -0800)
committerChristoph Hellwig <hch@lst.de>
Mon, 16 Mar 2020 09:48:12 +0000 (10:48 +0100)
This allows the arch code to reset the page tables to cached access when
freeing a dma coherent allocation that was set to uncached using
arch_dma_set_uncached.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
arch/Kconfig
include/linux/dma-noncoherent.h
kernel/dma/direct.c

index 090cfe0..c26302f 100644 (file)
@@ -255,6 +255,13 @@ config ARCH_HAS_SET_DIRECT_MAP
 config ARCH_HAS_DMA_SET_UNCACHED
        bool
 
+#
+# Select if the architectures provides the arch_dma_clear_uncached symbol
+# to undo an in-place page table remap for uncached access.
+#
+config ARCH_HAS_DMA_CLEAR_UNCACHED
+       bool
+
 # Select if arch init_task must go in the __init_task_data section
 config ARCH_TASK_STRUCT_ON_STACK
        bool
index 1a40395..b59f1b6 100644 (file)
@@ -109,5 +109,6 @@ static inline void arch_dma_prep_coherent(struct page *page, size_t size)
 #endif /* CONFIG_ARCH_HAS_DMA_PREP_COHERENT */
 
 void *arch_dma_set_uncached(void *addr, size_t size);
+void arch_dma_clear_uncached(void *addr, size_t size);
 
 #endif /* _LINUX_DMA_NONCOHERENT_H */
index baf4e93..412f560 100644 (file)
@@ -231,6 +231,8 @@ void dma_direct_free_pages(struct device *dev, size_t size, void *cpu_addr,
 
        if (IS_ENABLED(CONFIG_DMA_REMAP) && is_vmalloc_addr(cpu_addr))
                vunmap(cpu_addr);
+       else if (IS_ENABLED(CONFIG_ARCH_HAS_DMA_CLEAR_UNCACHED))
+               arch_dma_clear_uncached(cpu_addr, size);
 
        dma_free_contiguous(dev, dma_direct_to_page(dev, dma_addr), size);
 }