summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2018-01-10 01:39:03 +0300
committerChristoph Hellwig <hch@lst.de>2018-01-15 11:35:12 +0300
commitc61e9637340e1d0672c6f0c0b11aa81d7262c49d (patch)
tree2e38215dba2ec8b18ac7f89e4a24c0a0b7da7b52 /lib
parent21f237e4d08511eb662b59d8ff1b64be68e0c2bc (diff)
downloadlinux-c61e9637340e1d0672c6f0c0b11aa81d7262c49d.tar.xz
dma-direct: add support for allocation from ZONE_DMA and ZONE_DMA32
This allows to dip into zones for lower memory if they are available. If one of the zones is not available the corresponding GFP_* flag will evaluate to 0 so they won't change anything. We provide an arch tunable for those architectures that do not use GFP_DMA for the lowest 24-bits, given that there are a few. Roughly based on the x86 code. Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/dma-direct.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/dma-direct.c b/lib/dma-direct.c
index f04a424f91fa..8f76032ebc3c 100644
--- a/lib/dma-direct.c
+++ b/lib/dma-direct.c
@@ -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)
@@ -34,6 +42,12 @@ static void *dma_direct_alloc(struct device *dev, size_t size,
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(ARCH_ZONE_DMA_BITS))
+ gfp |= GFP_DMA;
+ if (dev->coherent_dma_mask <= DMA_BIT_MASK(32) && !(gfp & GFP_DMA))
+ gfp |= GFP_DMA32;
+
/* CMA can be used only in the context which permits sleeping */
if (gfpflags_allow_blocking(gfp))
page = dma_alloc_from_contiguous(dev, count, page_order, gfp);