@@ -12,6 +12,14 @@
#define DIRECT_MAPPING_ERROR 0
+/*
+ * Most architectures use ZONE_DMA for the first 16 Megabytes, but
+ * some use it for entirely different regions:
+ */
+#ifndef ARCH_ZONE_DMA_BITS
+#define ARCH_ZONE_DMA_BITS 24
+#endif
+
static bool
check_addr(struct device *dev, dma_addr_t dma_addr, size_t size,
const char *caller)
@@ -40,6 +48,12 @@ void *dma_direct_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
int page_order = get_order(size);
struct page *page = NULL;
+ /* GFP_DMA32 and GFP_DMA are no ops without the corresponding zones: */
+ if (dev->coherent_dma_mask < DMA_BIT_MASK(32))
+ gfp |= GFP_DMA32;
+ else if (dev->coherent_dma_mask < DMA_BIT_MASK(ARCH_ZONE_DMA_BITS))
+ gfp |= GFP_DMA;
+
again:
/* CMA can be used only in the context which permits sleeping */
if (gfpflags_allow_blocking(gfp)) {
Signed-off-by: Christoph Hellwig <hch@lst.de> --- lib/dma-direct.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)