[U-Boot] [PATCH 2/5] drivers: dma: Add function to zeroes a range of destination such as memory

tien.fong.chee at intel.com tien.fong.chee at intel.com
Thu May 31 08:08:51 UTC 2018


From: Tien Fong Chee <tien.fong.chee at intel.com>

This new DMA class function enables DMA being used for initializing
a range of destination such as memory to zeros. This is quite useful to
help accelerating the performance in scrubbing memory when ECC is enabled.

Signed-off-by: Tien Fong Chee <tien.fong.chee at intel.com>
---
 drivers/dma/dma-uclass.c | 15 +++++++++++++++
 include/dma.h            | 12 ++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/drivers/dma/dma-uclass.c b/drivers/dma/dma-uclass.c
index a33f7d5..cb83c24 100644
--- a/drivers/dma/dma-uclass.c
+++ b/drivers/dma/dma-uclass.c
@@ -61,6 +61,21 @@ int dma_memcpy(void *dst, void *src, size_t len)
 	return ops->transfer(dev, DMA_MEM_TO_MEM, dst, src, len);
 }
 
+int dma_memcpy_zeroes(struct udevice *dev, void *dst, size_t len)
+{
+	const struct dma_ops *ops;
+
+	ops = device_get_ops(dev);
+	if (!ops->transfer_zeroes)
+		return -ENOSYS;
+
+	/* Invalidate the area, so no writeback into the RAM races with DMA */
+	invalidate_dcache_range((unsigned long)dst, (unsigned long)dst +
+				roundup(len, ARCH_DMA_MINALIGN));
+
+	return ops->transfer_zeroes(dev, dst, len);
+}
+
 UCLASS_DRIVER(dma) = {
 	.id		= UCLASS_DMA,
 	.name		= "dma",
diff --git a/include/dma.h b/include/dma.h
index 50e9652..6bad2264 100644
--- a/include/dma.h
+++ b/include/dma.h
@@ -46,6 +46,7 @@ struct dma_ops {
 	 */
 	int (*transfer)(struct udevice *dev, int direction, void *dst,
 			void *src, size_t len);
+	int (*transfer_zeroes)(struct udevice *dev, void *dst, size_t len);
 };
 
 /*
@@ -82,4 +83,15 @@ int dma_get_device(u32 transfer_type, struct udevice **devp);
  */
 int dma_memcpy(void *dst, void *src, size_t len);
 
+/*
+ * dma_memcpy_zeroes - Fill up destination with zeros through DMA.
+ *
+ * @dev: The DMA device
+ * @dst: destination pointer
+ * @len: length to be copied with zero
+ * @return: on successful transfer returns zero.
+ *	    on failure returns error code.
+ */
+int dma_memcpy_zeroes(struct udevice *dev, void *dst, size_t len);
+
 #endif	/* _DMA_H_ */
-- 
2.2.0



More information about the U-Boot mailing list