mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Feng Tang <feng.tang@intel.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	John Stultz <john.stultz@linaro.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Michal Nazarewicz <mina86@mina86.com>,
	Kyungmin Park <kyungmin.park@samsung.com>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	LKML <linux-kernel@vger.kernel.org>
Cc: Feng Tang <feng.tang@intel.com>
Subject: [PATCH v2] staging: ion: Add a default struct device for cma heap
Date: Fri,  7 Aug 2015 11:50:13 +0800	[thread overview]
Message-ID: <1438919413-14440-1-git-send-email-feng.tang@intel.com> (raw)

When trying to use several cma heaps on our platforms,
we met a memory issue due to that the several cma_heaps
are sharing the same "struct device *".

As in current code base, the normal cma heap creating
process is, one platform device is created during boot,
and it will sequentially create cma heaps (usually passing
its own struct device * as a parameter)

For the multiple cma heaps case, there will be one "struct
cma" created for each cma heap, and this "struct cma *" is
saved in dev->cma_area. So the single platform device can't
meet the requirement here.

This patch adds one default device for each cma heap to avoid
sharing the same "struct device", thus fix the issue. And it
doesn't break existing code by only using that default device
when no "struct device *" is passed in.

Also, since the cma framework has been cleaned up recently,
this patch also adds a platform data member to pass the
"struct cma*" to ion_cma_heap_create().

Signed-off-by: Feng Tang <feng.tang@intel.com>
[From CMA’s point of view: ]
Acked-by: Michal Nazarewicz <mina86@mina86.com>
---
 drivers/staging/android/ion/ion.h          |    4 ++++
 drivers/staging/android/ion/ion_cma_heap.c |   20 +++++++++++++++++---
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/android/ion/ion.h b/drivers/staging/android/ion/ion.h
index 443db84..11336df 100644
--- a/drivers/staging/android/ion/ion.h
+++ b/drivers/staging/android/ion/ion.h
@@ -44,6 +44,9 @@ struct ion_buffer;
  * @base:	base address of heap in physical memory if applicable
  * @size:	size of the heap in bytes if applicable
  * @align:	required alignment in physical memory if applicable
+ * @cma:	when creating CMA heap, platform device should better also
+ *		pass the "struct cma *" info, so that the cma buffer request
+ *		know where to go for the buffer
  * @priv:	private info passed from the board file
  *
  * Provided by the board file.
@@ -55,6 +58,7 @@ struct ion_platform_heap {
 	ion_phys_addr_t base;
 	size_t size;
 	ion_phys_addr_t align;
+	struct cma *cma;
 	void *priv;
 };
 
diff --git a/drivers/staging/android/ion/ion_cma_heap.c b/drivers/staging/android/ion/ion_cma_heap.c
index f4211f1..27f218a 100644
--- a/drivers/staging/android/ion/ion_cma_heap.c
+++ b/drivers/staging/android/ion/ion_cma_heap.c
@@ -29,6 +29,7 @@
 struct ion_cma_heap {
 	struct ion_heap heap;
 	struct device *dev;
+	struct device default_dma_dev;
 };
 
 #define to_cma_heap(x) container_of(x, struct ion_cma_heap, heap)
@@ -180,9 +181,22 @@ struct ion_heap *ion_cma_heap_create(struct ion_platform_heap *data)
 		return ERR_PTR(-ENOMEM);
 
 	cma_heap->heap.ops = &ion_cma_ops;
-	/* get device from private heaps data, later it will be
-	 * used to make the link with reserved CMA memory */
-	cma_heap->dev = data->priv;
+
+	/*
+	 * data->priv for cma heap is currently supposed to point
+	 * to a "struct device *"
+	 */
+	if (data->priv) {
+		cma_heap->dev = data->priv;
+	} else {
+		cma_heap->dev = &cma_heap->default_dma_dev;
+		cma_heap->dev->coherent_dma_mask = DMA_BIT_MASK(32);
+		cma_heap->dev->dma_mask = &cma_heap->dev->coherent_dma_mask;
+	}
+
+	if (data->cma)
+		dev_set_cma_area(cma_heap->dev, data->cma);
+
 	cma_heap->heap.type = ION_HEAP_TYPE_DMA;
 	return &cma_heap->heap;
 }
-- 
1.7.9.5


             reply	other threads:[~2015-08-07  3:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-07  3:50 Feng Tang [this message]
2015-08-07  4:54 ` Greg Kroah-Hartman
2015-08-07  6:46   ` Feng Tang
2015-08-07 14:48     ` Michal Nazarewicz
2015-08-07 15:50       ` Feng Tang
2015-08-07 18:05         ` Greg Kroah-Hartman
2015-08-07 23:09           ` Laura Abbott
2015-08-08 22:18             ` Greg Kroah-Hartman
2015-08-09  8:47               ` Feng Tang
2015-08-08 10:39         ` Michal Nazarewicz
2015-08-09  9:12           ` Feng Tang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1438919413-14440-1-git-send-email-feng.tang@intel.com \
    --to=feng.tang@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=john.stultz@linaro.org \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=mina86@mina86.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®