ION dummy driver v2
cover ION dummy driver v2
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, and I've already made a fool of myself with v1 (but maaaaybe you don't remember!) so no pressure if you want to defer this for 3.15.
thanks
-john
Changes in v2:
* Fix module build issue (should have been bool instead of tristate)
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
Signature · 1 line
1.8.3.2
PATCH 1/2 ion: Add dummy driver for testing
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.
--- 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
drivers/staging/android/ion/Kconfig +10 -0
@@ -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 + bool "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
drivers/staging/android/ion/Makefile +3 -0
@@ -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/ +
drivers/staging/android/ion/ion_dummy_driver.c new file +93 -0
93 lines not on this page · raw message
Signature · 1 line
1.8.3.2
PATCH 2/2 ion: Add carveout and chunk heaps to dummy driver
In reply to John StultzAdd 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.
--- drivers/staging/android/ion/ion_dummy_driver.c | 67 +++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-)
drivers/staging/android/ion/ion_dummy_driver.c +66 -1
@@ -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 ; }
Signature · 1 line
1.8.3.2