diff mbox

[U-Boot,v2,05/80] dm: core: Support allocating driver-private data for DMA

Message ID 1427307788-7496-6-git-send-email-sjg@chromium.org
State Accepted
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass March 25, 2015, 6:21 p.m. UTC
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@chromium.org>
---

Changes in v2: None

 drivers/core/device.c | 19 +++++++++++++++++--
 include/dm/device.h   |  3 +++
 2 files changed, 20 insertions(+), 2 deletions(-)

Comments

Simon Glass April 7, 2015, 6:39 p.m. UTC | #1
On 25 March 2015 at 12:21, Simon Glass <sjg@chromium.org> wrote:
> 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@chromium.org>
> ---
>
> Changes in v2: None
>
>  drivers/core/device.c | 19 +++++++++++++++++--
>  include/dm/device.h   |  3 +++
>  2 files changed, 20 insertions(+), 2 deletions(-)

Applied to u-boot-dm/next.
diff mbox

Patch

diff --git a/drivers/core/device.c b/drivers/core/device.c
index 7483405..1ca5d1c 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -164,6 +164,21 @@  int device_bind_by_name(struct udevice *parent, bool pre_reloc_only,
 			   -1, devp);
 }
 
+static void *alloc_priv(int size, uint flags)
+{
+	void *priv;
+
+	if (flags & DM_FLAG_ALLOC_PRIV_DMA) {
+		priv = memalign(ARCH_DMA_MINALIGN, size);
+		if (priv)
+			memset(priv, '\0', size);
+	} else {
+		priv = calloc(1, size);
+	}
+
+	return priv;
+}
+
 int device_probe_child(struct udevice *dev, void *parent_priv)
 {
 	struct driver *drv;
@@ -182,7 +197,7 @@  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);
+		dev->priv = alloc_priv(drv->priv_auto_alloc_size, drv->flags);
 		if (!dev->priv) {
 			ret = -ENOMEM;
 			goto fail;
@@ -206,7 +221,7 @@  int device_probe_child(struct udevice *dev, void *parent_priv)
 					per_child_auto_alloc_size;
 		}
 		if (size) {
-			dev->parent_priv = calloc(1, size);
+			dev->parent_priv = alloc_priv(size, drv->flags);
 			if (!dev->parent_priv) {
 				ret = -ENOMEM;
 				goto fail;
diff --git a/include/dm/device.h b/include/dm/device.h
index 6980954..f27b34b 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
  *