From mboxrd@z Thu Jan 1 00:00:00 1970 From: tien.fong.chee at intel.com Date: Thu, 31 May 2018 16:08:51 +0800 Subject: [U-Boot] [PATCH 2/5] drivers: dma: Add function to zeroes a range of destination such as memory In-Reply-To: <1527754134-164985-1-git-send-email-tien.fong.chee@intel.com> References: <1527754134-164985-1-git-send-email-tien.fong.chee@intel.com> Message-ID: <1527754134-164985-3-git-send-email-tien.fong.chee@intel.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de From: Tien Fong Chee 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 --- 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