[U-Boot] [RFC PATCH 06/13] dm: core: Support allocating driver-private data for DMA

Simon Glass sjg at chromium.org
Sun Mar 1 17:33:32 CET 2015


Some driver want to put DMA buffers in their private data. Add a flag
to tell driver model to align driver-private data to a cache boundary so
that DMA will work correctly in this case.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 drivers/core/device.c | 11 ++++++++++-
 include/dm/device.h   |  3 +++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/core/device.c b/drivers/core/device.c
index 37dc882..b7a5654 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -190,7 +190,16 @@ int device_probe_child(struct udevice *dev, void *parent_priv)
 
 	/* Allocate private data if requested */
 	if (drv->priv_auto_alloc_size) {
-		dev->priv = calloc(1, drv->priv_auto_alloc_size);
+		if (drv->flags & DM_FLAG_ALLOC_PRIV_DMA) {
+			dev->priv = memalign(ARCH_DMA_MINALIGN,
+					     drv->priv_auto_alloc_size);
+			if (dev->priv) {
+				memset(dev->priv, '\0',
+				       drv->priv_auto_alloc_size);
+			}
+		} else {
+			dev->priv = calloc(1, drv->priv_auto_alloc_size);
+		}
 		if (!dev->priv) {
 			ret = -ENOMEM;
 			goto fail;
diff --git a/include/dm/device.h b/include/dm/device.h
index 7a48eb8..7f810ed 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -30,6 +30,9 @@ struct driver_info;
 /* DM is responsible for allocating and freeing parent_platdata */
 #define DM_FLAG_ALLOC_PARENT_PDATA	(1 << 3)
 
+/* Allocate driver private data on a DMA boundary */
+#define DM_FLAG_ALLOC_PRIV_DMA	(1 << 4)
+
 /**
  * struct udevice - An instance of a driver
  *
-- 
2.2.0.rc0.207.ga3a616c



More information about the U-Boot mailing list