Skip to contentSkip to conversation

dma_get_required_mask()

PATCH New James Bottomley 1 participant 1 message Jun 25, 2004

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dma_get_required_mask()

Following the discussion, this is a patch implementing dma_get_required_mask(). The default implementation simply works out the largest mask covering all of memory and returns the and of that with the current dma_mask. If this looks OK, I'll send out another patch including the documentation updates as well.

I've put the implementation in linux/dma-mapping.h with a ARCH_HAS_DMA_GET_REQUIRED_MASK override for those architectures that would like to do something different.

Any opinions on whether I should also make linux/dma-mapping.h include linux/bitops.h now since it requires fls() from there?

James

===== include/linux/dma-mapping.h 1.3 vs edited =====

include/linux/dma-mapping.h +23 -0
@@ -19,6 +19,29 @@
 #define dma_sync_single		dma_sync_single_for_cpu
 #define dma_sync_sg		dma_sync_sg_for_cpu
 
+#ifndef ARCH_HAS_DMA_GET_REQUIRED_MASK
+static inline u64 dma_get_required_mask(struct device *dev)
+{
+	extern unsigned long max_pfn; /* defined in bootmem.h but may
+					 not be included */
+	u32 low_totalram = ((max_pfn - 1) << PAGE_SHIFT);
+	u32 high_totalram = ((max_pfn - 1) >> (32 - PAGE_SHIFT));
+	u64 mask;
+
+	if (!high_totalram) {
+		/* convert to mask just covering totalram */
+		low_totalram = (1 << (fls(low_totalram) - 1));
+		low_totalram += low_totalram - 1;
+		mask = low_totalram;
+	} else {
+		high_totalram = (1 << (fls(high_totalram) - 1));
+		high_totalram += high_totalram - 1;
+		mask = (((u64)high_totalram) << 32) + 0xffffffff;
+	}
+	return mask & *dev->dma_mask;
+}
+#endif
+		
 #endif