public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] ION dummy driver
@ 2014-01-10  3:40 John Stultz
  2014-01-10  3:40 ` [PATCH 1/2] ion: Add dummy driver for testing John Stultz
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: John Stultz @ 2014-01-10  3:40 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Colin Cross, Greg KH, Jesse Barker,
	Android Kernel Team

The ION subsystem requires something register it along with the
various heaps that may be available on a system in order to work
(Otherwise no /dev/ion is created).

This can make it difficult to play with. Thus I've created this
simple dummy driver which allocates and registers some basic heaps.

I've been using this dummy driver, along with Colin's unit tests
and test driver, to be able to validate basic functionality on
a number of architectures and it was handy to chase down a few
issues before ION was submitted to staging.

If you want to play with all of this, Colin's unit tests can be
found in AOSP under the system/core/libion directory, but if you
want to try to use them in a non-Android environment, I've
mirrored that directory and added some changes to get it building
under Ubuntu here:
   https://github.com/johnstultz-work/ion-test


Greg: I realize this is after the usual -rc6 cutoff for staging,
so no pressure if you want to defer this for 3.15, but I saw you've
picked up a few things recently, so I figured I'd send it out so
I'm not just sitting on it while we wait for LCA to finish.

thanks
-john

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>

John Stultz (2):
  ion: Add dummy driver for testing
  ion: Add carveout and chunk heaps to dummy driver

 drivers/staging/android/ion/Kconfig            |  10 ++
 drivers/staging/android/ion/Makefile           |   3 +
 drivers/staging/android/ion/ion_dummy_driver.c | 158 +++++++++++++++++++++++++
 3 files changed, 171 insertions(+)
 create mode 100644 drivers/staging/android/ion/ion_dummy_driver.c

-- 
1.8.3.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] ion: Add dummy driver for testing
  2014-01-10  3:40 [PATCH 0/2] ION dummy driver John Stultz
@ 2014-01-10  3:40 ` John Stultz
  2014-01-10  3:40 ` [PATCH 2/2] ion: Add carveout and chunk heaps to dummy driver John Stultz
  2014-01-10  4:23 ` [PATCH 0/2] ION " Greg KH
  2 siblings, 0 replies; 5+ messages in thread
From: John Stultz @ 2014-01-10  3:40 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Colin Cross, Greg KH, Jesse Barker,
	Android Kernel Team

Provide a basic dummy driver to register the ion device
and to install basic SYSTEM and SYSTEM_CONTIG heaps.

This allows for basic testing with ION without having
access to drivers or systems that have been enabled to use
ION.

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/Kconfig            | 10 +++
 drivers/staging/android/ion/Makefile           |  3 +
 drivers/staging/android/ion/ion_dummy_driver.c | 93 ++++++++++++++++++++++++++
 3 files changed, 106 insertions(+)
 create mode 100644 drivers/staging/android/ion/ion_dummy_driver.c

diff --git a/drivers/staging/android/ion/Kconfig b/drivers/staging/android/ion/Kconfig
index a9a64ea..a087b19 100644
--- a/drivers/staging/android/ion/Kconfig
+++ b/drivers/staging/android/ion/Kconfig
@@ -17,6 +17,16 @@ config ION_TEST
 	  Choose this option to create a device that can be used to test the
 	  kernel and device side ION functions.
 
+config ION_DUMMY
+	tristate "Dummy Ion driver"
+	depends on ION
+	help
+	  Provides a dummy ION driver that registers the
+	  /dev/ion device and some basic heaps. This can
+	  be used for testing the ION infrastructure if
+	  one doesn't have access to hardware drivers that
+	  use ION.
+
 config ION_TEGRA
 	tristate "Ion for Tegra"
 	depends on ARCH_TEGRA && ION
diff --git a/drivers/staging/android/ion/Makefile b/drivers/staging/android/ion/Makefile
index 75039b9..b56fd2b 100644
--- a/drivers/staging/android/ion/Makefile
+++ b/drivers/staging/android/ion/Makefile
@@ -4,4 +4,7 @@ obj-$(CONFIG_ION_TEST) += ion_test.o
 ifdef CONFIG_COMPAT
 obj-$(CONFIG_ION) += compat_ion.o
 endif
+
+obj-$(CONFIG_ION_DUMMY) += ion_dummy_driver.o
 obj-$(CONFIG_ION_TEGRA) += tegra/
+
diff --git a/drivers/staging/android/ion/ion_dummy_driver.c b/drivers/staging/android/ion/ion_dummy_driver.c
new file mode 100644
index 0000000..6749d29
--- /dev/null
+++ b/drivers/staging/android/ion/ion_dummy_driver.c
@@ -0,0 +1,93 @@
+/*
+ * drivers/gpu/ion/ion_dummy_driver.c
+ *
+ * Copyright (C) 2013 Linaro, Inc
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <linux/err.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/bootmem.h>
+#include <linux/memblock.h>
+#include <linux/sizes.h>
+#include "ion.h"
+#include "ion_priv.h"
+
+struct ion_device *idev;
+struct ion_heap **heaps;
+
+struct ion_platform_heap dummy_heaps[] = {
+		{
+			.id	= ION_HEAP_TYPE_SYSTEM,
+			.type	= ION_HEAP_TYPE_SYSTEM,
+			.name	= "system",
+		},
+		{
+			.id	= ION_HEAP_TYPE_SYSTEM_CONTIG,
+			.type	= ION_HEAP_TYPE_SYSTEM_CONTIG,
+			.name	= "system contig",
+		},
+};
+
+struct ion_platform_data dummy_ion_pdata = {
+	.nr = 2,
+	.heaps = dummy_heaps,
+};
+
+static int __init ion_dummy_init(void)
+{
+	int i, err;
+
+	idev = ion_device_create(NULL);
+	heaps = kzalloc(sizeof(struct ion_heap *) * dummy_ion_pdata.nr,
+			GFP_KERNEL);
+	if (!heaps)
+		return PTR_ERR(heaps);
+
+	for (i = 0; i < dummy_ion_pdata.nr; i++) {
+		struct ion_platform_heap *heap_data = &dummy_ion_pdata.heaps[i];
+
+		heaps[i] = ion_heap_create(heap_data);
+		if (IS_ERR_OR_NULL(heaps[i])) {
+			err = PTR_ERR(heaps[i]);
+			goto err;
+		}
+		ion_device_add_heap(idev, heaps[i]);
+	}
+	return 0;
+err:
+	for (i = 0; i < dummy_ion_pdata.nr; i++) {
+		if (heaps[i])
+			ion_heap_destroy(heaps[i]);
+	}
+	kfree(heaps);
+
+	return err;
+}
+
+static void __exit ion_dummy_exit(void)
+{
+	int i;
+
+	ion_device_destroy(idev);
+
+	for (i = 0; i < dummy_ion_pdata.nr; i++)
+		ion_heap_destroy(heaps[i]);
+	kfree(heaps);
+
+	return;
+}
+
+module_init(ion_dummy_init);
+module_exit(ion_dummy_exit);
+
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] ion: Add carveout and chunk heaps to dummy driver
  2014-01-10  3:40 [PATCH 0/2] ION dummy driver John Stultz
  2014-01-10  3:40 ` [PATCH 1/2] ion: Add dummy driver for testing John Stultz
@ 2014-01-10  3:40 ` John Stultz
  2014-01-10  4:23 ` [PATCH 0/2] ION " Greg KH
  2 siblings, 0 replies; 5+ messages in thread
From: John Stultz @ 2014-01-10  3:40 UTC (permalink / raw)
  To: LKML; +Cc: John Stultz, Colin Cross, Greg KH, Jesse Barker,
	Android Kernel Team

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] ION dummy driver
  2014-01-10  3:40 [PATCH 0/2] ION dummy driver John Stultz
  2014-01-10  3:40 ` [PATCH 1/2] ion: Add dummy driver for testing John Stultz
  2014-01-10  3:40 ` [PATCH 2/2] ion: Add carveout and chunk heaps to dummy driver John Stultz
@ 2014-01-10  4:23 ` Greg KH
  2014-01-10  4:54   ` John Stultz
  2 siblings, 1 reply; 5+ messages in thread
From: Greg KH @ 2014-01-10  4:23 UTC (permalink / raw)
  To: John Stultz; +Cc: LKML, Colin Cross, Jesse Barker, Android Kernel Team

On Thu, Jan 09, 2014 at 07:40:53PM -0800, John Stultz wrote:
> Greg: I realize this is after the usual -rc6 cutoff for staging,
> so no pressure if you want to defer this for 3.15, but I saw you've
> picked up a few things recently, so I figured I'd send it out so
> I'm not just sitting on it while we wait for LCA to finish.

I would have merged it, but I just tried and got a ton of errors when
building:

ERROR: "ion_device_destroy" [drivers/staging/android/ion/ion_dummy_driver.ko] undefined!
ERROR: "ion_heap_destroy" [drivers/staging/android/ion/ion_dummy_driver.ko] undefined!
ERROR: "ion_device_add_heap" [drivers/staging/android/ion/ion_dummy_driver.ko] undefined!
ERROR: "ion_heap_create" [drivers/staging/android/ion/ion_dummy_driver.ko] undefined!
ERROR: "ion_device_create" [drivers/staging/android/ion/ion_dummy_driver.ko] undefined!

So, I'll just drop these patches and forget you ever sent them to me :)

greg k-h

p.s.  Feel free to resend them when they work.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] ION dummy driver
  2014-01-10  4:23 ` [PATCH 0/2] ION " Greg KH
@ 2014-01-10  4:54   ` John Stultz
  0 siblings, 0 replies; 5+ messages in thread
From: John Stultz @ 2014-01-10  4:54 UTC (permalink / raw)
  To: Greg KH; +Cc: LKML, Colin Cross, Jesse Barker, Android Kernel Team

On 01/09/2014 08:23 PM, Greg KH wrote:
> On Thu, Jan 09, 2014 at 07:40:53PM -0800, John Stultz wrote:
>> Greg: I realize this is after the usual -rc6 cutoff for staging,
>> so no pressure if you want to defer this for 3.15, but I saw you've
>> picked up a few things recently, so I figured I'd send it out so
>> I'm not just sitting on it while we wait for LCA to finish.
> I would have merged it, but I just tried and got a ton of errors when
> building:
>
> ERROR: "ion_device_destroy" [drivers/staging/android/ion/ion_dummy_driver.ko] undefined!
> ERROR: "ion_heap_destroy" [drivers/staging/android/ion/ion_dummy_driver.ko] undefined!
> ERROR: "ion_device_add_heap" [drivers/staging/android/ion/ion_dummy_driver.ko] undefined!
> ERROR: "ion_heap_create" [drivers/staging/android/ion/ion_dummy_driver.ko] undefined!
> ERROR: "ion_device_create" [drivers/staging/android/ion/ion_dummy_driver.ko] undefined!
>
> So, I'll just drop these patches and forget you ever sent them to me :)

Gah. Modules bite me every time! Should have been a bool and not
tristate in the Kconfig.

Sorry! I appreciate the heads up and the build related amnesia.  :)

thanks
-john


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-01-10  4:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-10  3:40 [PATCH 0/2] ION dummy driver John Stultz
2014-01-10  3:40 ` [PATCH 1/2] ion: Add dummy driver for testing John Stultz
2014-01-10  3:40 ` [PATCH 2/2] ion: Add carveout and chunk heaps to dummy driver John Stultz
2014-01-10  4:23 ` [PATCH 0/2] ION " Greg KH
2014-01-10  4:54   ` John Stultz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox