mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: John Stultz <john.stultz@linaro.org>
To: LKML <linux-kernel@vger.kernel.org>
Cc: John Stultz <john.stultz@linaro.org>,
	Colin Cross <ccross@android.com>,
	Greg KH <gregkh@linuxfoundation.org>,
	Jesse Barker <jesse.barker@arm.com>,
	Android Kernel Team <kernel-team@android.com>
Subject: [PATCH 2/2] ion: Add carveout and chunk heaps to dummy driver
Date: Thu,  9 Jan 2014 21:08:38 -0800	[thread overview]
Message-ID: <1389330518-31919-3-git-send-email-john.stultz@linaro.org> (raw)
In-Reply-To: <1389330518-31919-1-git-send-email-john.stultz@linaro.org>

Add support to the dummy driver for basic carveout and chunk heaps.

Since we're generating these heaps at module_init, and we want
this driver to be generic enough to be tested on any arch, we
don't have the ability to alloc bootmem, so both of these heaps
are conventionally allocated using alloc_pages(), which limits us
to 4M in size.

Should look into using CMA for heap allocation eventually, but
this provides enough to test the basic functionality of the
heaps.

Cc: Colin Cross <ccross@android.com>
Cc: Greg KH <gregkh@linuxfoundation.org>
Cc: Jesse Barker <jesse.barker@arm.com>
Cc: Android Kernel Team <kernel-team@android.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 drivers/staging/android/ion/ion_dummy_driver.c | 67 +++++++++++++++++++++++++-
 1 file changed, 66 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/android/ion/ion_dummy_driver.c b/drivers/staging/android/ion/ion_dummy_driver.c
index 6749d29..55b2002 100644
--- a/drivers/staging/android/ion/ion_dummy_driver.c
+++ b/drivers/staging/android/ion/ion_dummy_driver.c
@@ -26,6 +26,9 @@
 struct ion_device *idev;
 struct ion_heap **heaps;
 
+void *carveout_ptr;
+void *chunk_ptr;
+
 struct ion_platform_heap dummy_heaps[] = {
 		{
 			.id	= ION_HEAP_TYPE_SYSTEM,
@@ -37,10 +40,24 @@ struct ion_platform_heap dummy_heaps[] = {
 			.type	= ION_HEAP_TYPE_SYSTEM_CONTIG,
 			.name	= "system contig",
 		},
+		{
+			.id	= ION_HEAP_TYPE_CARVEOUT,
+			.type	= ION_HEAP_TYPE_CARVEOUT,
+			.name	= "carveout",
+			.size	= SZ_4M,
+		},
+		{
+			.id	= ION_HEAP_TYPE_CHUNK,
+			.type	= ION_HEAP_TYPE_CHUNK,
+			.name	= "chunk",
+			.size	= SZ_4M,
+			.align	= SZ_16K,
+			.priv	= (void *)(SZ_16K),
+		},
 };
 
 struct ion_platform_data dummy_ion_pdata = {
-	.nr = 2,
+	.nr = 4,
 	.heaps = dummy_heaps,
 };
 
@@ -54,9 +71,36 @@ static int __init ion_dummy_init(void)
 	if (!heaps)
 		return PTR_ERR(heaps);
 
+
+	/* Allocate a dummy carveout heap */
+	carveout_ptr = alloc_pages_exact(
+				dummy_heaps[ION_HEAP_TYPE_CARVEOUT].size,
+				GFP_KERNEL);
+	if (carveout_ptr)
+		dummy_heaps[ION_HEAP_TYPE_CARVEOUT].base =
+						virt_to_phys(carveout_ptr);
+	else
+		pr_err("ion_dummy: Could not allocate carveout\n");
+
+	/* Allocate a dummy chunk heap */
+	chunk_ptr = alloc_pages_exact(
+				dummy_heaps[ION_HEAP_TYPE_CHUNK].size,
+				GFP_KERNEL);
+	if (chunk_ptr)
+		dummy_heaps[ION_HEAP_TYPE_CHUNK].base = virt_to_phys(chunk_ptr);
+	else
+		pr_err("ion_dummy: Could not allocate chunk\n");
+
 	for (i = 0; i < dummy_ion_pdata.nr; i++) {
 		struct ion_platform_heap *heap_data = &dummy_ion_pdata.heaps[i];
 
+		if (heap_data->type == ION_HEAP_TYPE_CARVEOUT &&
+							!heap_data->base)
+			continue;
+
+		if (heap_data->type == ION_HEAP_TYPE_CHUNK && !heap_data->base)
+			continue;
+
 		heaps[i] = ion_heap_create(heap_data);
 		if (IS_ERR_OR_NULL(heaps[i])) {
 			err = PTR_ERR(heaps[i]);
@@ -72,6 +116,16 @@ err:
 	}
 	kfree(heaps);
 
+	if (carveout_ptr) {
+		free_pages_exact(carveout_ptr,
+				dummy_heaps[ION_HEAP_TYPE_CARVEOUT].size);
+		carveout_ptr = NULL;
+	}
+	if (chunk_ptr) {
+		free_pages_exact(chunk_ptr,
+				dummy_heaps[ION_HEAP_TYPE_CHUNK].size);
+		chunk_ptr = NULL;
+	}
 	return err;
 }
 
@@ -85,6 +139,17 @@ static void __exit ion_dummy_exit(void)
 		ion_heap_destroy(heaps[i]);
 	kfree(heaps);
 
+	if (carveout_ptr) {
+		free_pages_exact(carveout_ptr,
+				dummy_heaps[ION_HEAP_TYPE_CARVEOUT].size);
+		carveout_ptr = NULL;
+	}
+	if (chunk_ptr) {
+		free_pages_exact(chunk_ptr,
+				dummy_heaps[ION_HEAP_TYPE_CHUNK].size);
+		chunk_ptr = NULL;
+	}
+
 	return;
 }
 
-- 
1.8.3.2


  parent reply	other threads:[~2014-01-10  5:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-10  5:08 [PATCH 0/2] ION dummy driver v2 John Stultz
2014-01-10  5:08 ` [PATCH 1/2] ion: Add dummy driver for testing John Stultz
2014-01-10  5:08 ` John Stultz [this message]
  -- strict thread matches above, loose matches on Subject: below --
2014-01-10  3:40 [PATCH 0/2] ION dummy driver John Stultz
2014-01-10  3:40 ` [PATCH 2/2] ion: Add carveout and chunk heaps to " John Stultz

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=1389330518-31919-3-git-send-email-john.stultz@linaro.org \
    --to=john.stultz@linaro.org \
    --cc=ccross@android.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jesse.barker@arm.com \
    --cc=kernel-team@android.com \
    --cc=linux-kernel@vger.kernel.org \
    /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

Powered by JetHome