From ad773bac072f90678f0e5f2e2a4c5680f8b5722d Mon Sep 17 00:00:00 2001 From: kfx Date: Wed, 14 Dec 2011 12:58:55 +0800 Subject: [PATCH] add ion(kernel allocator) for gralloc --- arch/arm/mach-rk29/board-rk29-ddr3sdk.c | 27 +++++++ drivers/gpu/ion/Kconfig | 5 ++ drivers/gpu/ion/Makefile | 1 + drivers/gpu/ion/ion.c | 17 +++++ drivers/gpu/ion/rockchip/Makefile | 1 + drivers/gpu/ion/rockchip/rockchip_ion.c | 94 +++++++++++++++++++++++++ 6 files changed, 145 insertions(+) mode change 100644 => 100755 drivers/gpu/ion/Makefile mode change 100644 => 100755 drivers/gpu/ion/ion.c create mode 100644 drivers/gpu/ion/rockchip/Makefile create mode 100755 drivers/gpu/ion/rockchip/rockchip_ion.c diff --git a/arch/arm/mach-rk29/board-rk29-ddr3sdk.c b/arch/arm/mach-rk29/board-rk29-ddr3sdk.c index 3a17560f22ea..0d9b9c83e026 100755 --- a/arch/arm/mach-rk29/board-rk29-ddr3sdk.c +++ b/arch/arm/mach-rk29/board-rk29-ddr3sdk.c @@ -27,6 +27,7 @@ #ifdef CONFIG_USB_ANDROID #include #endif +#include #include #include @@ -824,6 +825,29 @@ static struct platform_device android_pmem_skype_device = { }; #endif +#ifdef CONFIG_ION +static struct ion_platform_data rk29_ion_pdata = { + .nr = 1, + .heaps = { + { + .type = ION_HEAP_TYPE_CARVEOUT, + .id = 0, + .name = "ui", + .base = PMEM_UI_BASE, + .size = PMEM_UI_SIZE, + } + }, +}; + +static struct platform_device rk29_ion_device = { + .name = "ion-rockchip", + .id = 0, + .dev = { + .platform_data = &rk29_ion_pdata, + }, +}; +#endif + #ifdef CONFIG_VIDEO_RK29XX_VOUT static struct platform_device rk29_v4l2_output_devce = { .name = "rk29_vout", @@ -2680,6 +2704,9 @@ static struct platform_device *devices[] __initdata = { #endif #if PMEM_SKYPE_SIZE > 0 &android_pmem_skype_device, +#endif +#ifdef CONFIG_ION + &rk29_ion_device, #endif &android_pmem_device, &rk29_vpu_mem_device, diff --git a/drivers/gpu/ion/Kconfig b/drivers/gpu/ion/Kconfig index 5b48b4e85e73..9ae4672d0890 100644 --- a/drivers/gpu/ion/Kconfig +++ b/drivers/gpu/ion/Kconfig @@ -10,3 +10,8 @@ config ION_TEGRA help Choose this option if you wish to use ion on an nVidia Tegra. +config ION_ROCKCHIP + tristate "Ion for Rockchip" + depends on ARCH_RK29 && ION + help + Choose this option if you wish to use ion on an Rockchip. diff --git a/drivers/gpu/ion/Makefile b/drivers/gpu/ion/Makefile old mode 100644 new mode 100755 index 73fe3fa10706..92eb4395b188 --- a/drivers/gpu/ion/Makefile +++ b/drivers/gpu/ion/Makefile @@ -1,2 +1,3 @@ obj-$(CONFIG_ION) += ion.o ion_heap.o ion_system_heap.o ion_carveout_heap.o obj-$(CONFIG_ION_TEGRA) += tegra/ +obj-$(CONFIG_ION_ROCKCHIP) += rockchip/ diff --git a/drivers/gpu/ion/ion.c b/drivers/gpu/ion/ion.c old mode 100644 new mode 100755 index 37b23af0550b..b0fafdacb58c --- a/drivers/gpu/ion/ion.c +++ b/drivers/gpu/ion/ion.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "ion_priv.h" #define DEBUG @@ -904,10 +905,26 @@ err: return ret; } +static long ion_share_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) +{ + struct ion_buffer *buffer = filp->private_data; + struct pmem_region region; + + region.offset = buffer->priv_phys; + region.len = buffer->size; + + if (copy_to_user((void __user *)arg, ®ion, + sizeof(struct pmem_region))) + return -EFAULT; + + return 0; +} + static const struct file_operations ion_share_fops = { .owner = THIS_MODULE, .release = ion_share_release, .mmap = ion_share_mmap, + .unlocked_ioctl = ion_share_ioctl, }; static int ion_ioctl_share(struct file *parent, struct ion_client *client, diff --git a/drivers/gpu/ion/rockchip/Makefile b/drivers/gpu/ion/rockchip/Makefile new file mode 100644 index 000000000000..5451bfd6551c --- /dev/null +++ b/drivers/gpu/ion/rockchip/Makefile @@ -0,0 +1 @@ +obj-y += rockchip_ion.o diff --git a/drivers/gpu/ion/rockchip/rockchip_ion.c b/drivers/gpu/ion/rockchip/rockchip_ion.c new file mode 100755 index 000000000000..20d3126d1268 --- /dev/null +++ b/drivers/gpu/ion/rockchip/rockchip_ion.c @@ -0,0 +1,94 @@ +/* + * drivers/gpu/rockchip/rockchip_ion.c + * + * Copyright (C) 2011 Google, 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 +#include +#include +#include +#include "../ion_priv.h" + +static int num_heaps; +static struct ion_heap **heaps; + +static int rockchip_ion_probe(struct platform_device *pdev) +{ + struct ion_device *idev; + struct ion_platform_data *pdata = pdev->dev.platform_data; + int err; + int i; + + num_heaps = pdata->nr; + heaps = kzalloc(sizeof(struct ion_heap *) * pdata->nr, GFP_KERNEL); + + idev = ion_device_create(NULL); + if (IS_ERR_OR_NULL(idev)) { + kfree(heaps); + return PTR_ERR(idev); + } + + /* create the heaps as specified in the board file */ + for (i = 0; i < num_heaps; i++) { + struct ion_platform_heap *heap_data = &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]); + } + platform_set_drvdata(pdev, idev); + return 0; +err: + for (i = 0; i < num_heaps; i++) { + if (heaps[i]) + ion_heap_destroy(heaps[i]); + } + kfree(heaps); + return err; +} + +static int rockchip_ion_remove(struct platform_device *pdev) +{ + struct ion_device *idev = platform_get_drvdata(pdev); + int i; + + ion_device_destroy(idev); + for (i = 0; i < num_heaps; i++) + ion_heap_destroy(heaps[i]); + kfree(heaps); + return 0; +} + +static struct platform_driver ion_driver = { + .probe = rockchip_ion_probe, + .remove = rockchip_ion_remove, + .driver = { .name = "ion-rockchip" } +}; + +static int __init ion_init(void) +{ + return platform_driver_register(&ion_driver); +} + +static void __exit ion_exit(void) +{ + platform_driver_unregister(&ion_driver); +} + +module_init(ion_init); +module_exit(ion_exit); + -- 2.34.1