Check if we need to allocate uncached memory for a device given the allocation flags. Switch over the uncached segment check to this helper to deal with architectures that do not support the dma_cache_sync operation and thus should not returned cacheable memory for DMA_ATTR_NON_CONSISTENT allocations.
Showing the changes to include/linux (1 of 2 files). Show all
Unified · Split
| @@ -20,6 +20,20 @@ static inline bool dev_is_dma_coherent(struct device *dev) · 19 unmodified lines | |||
| 20 | } | 20 | } |
| 21 | #endif /* CONFIG_ARCH_HAS_DMA_COHERENCE_H */ | 21 | #endif /* CONFIG_ARCH_HAS_DMA_COHERENCE_H */ |
| 22 | 22 | ||
| 23 | /* | ||
| 24 | * Check if an allocation needs to be marked uncached to be coherent. | ||
| 25 | */ | ||
| 26 | static inline bool dma_alloc_need_uncached(struct device *dev, | ||
| 27 | unsigned long attrs) | ||
| 28 | { | ||
| 29 | if (dev_is_dma_coherent(dev)) | ||
| 30 | return false; | ||
| 31 | if (IS_ENABLED(CONFIG_DMA_NONCOHERENT_CACHE_SYNC) && | ||
| 32 | (attrs & DMA_ATTR_NON_CONSISTENT)) | ||
| 33 | return false; | ||
| 34 | return true; | ||
| 35 | } | ||
| 36 | |||
| 23 | void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, | 37 | void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, |
| 24 | gfp_t gfp, unsigned long attrs); | 38 | gfp_t gfp, unsigned long attrs); |
| 25 | void arch_dma_free(struct device *dev, size_t size, void *cpu_addr, | 39 | void arch_dma_free(struct device *dev, size_t size, void *cpu_addr, |