add ion(kernel allocator) for gralloc
authorkfx <kfx@rock-chips.com>
Wed, 14 Dec 2011 04:58:55 +0000 (12:58 +0800)
committerkfx <kfx@rock-chips.com>
Wed, 14 Dec 2011 04:58:55 +0000 (12:58 +0800)
arch/arm/mach-rk29/board-rk29-ddr3sdk.c
drivers/gpu/ion/Kconfig
drivers/gpu/ion/Makefile [changed mode: 0644->0755]
drivers/gpu/ion/ion.c [changed mode: 0644->0755]
drivers/gpu/ion/rockchip/Makefile [new file with mode: 0644]
drivers/gpu/ion/rockchip/rockchip_ion.c [new file with mode: 0755]

index 3a17560f22eaeeeff6da01617b7b1d0b19a53d80..0d9b9c83e02669a0ed19c95e4c20a89c83d34c0f 100755 (executable)
@@ -27,6 +27,7 @@
 #ifdef CONFIG_USB_ANDROID
 #include <linux/usb/android_composite.h>
 #endif
+#include <linux/ion.h>
 
 #include <mach/hardware.h>
 #include <asm/setup.h>
@@ -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,
index 5b48b4e85e73e9996b11ac72fe489529fab66b16..9ae4672d0890ce33bd474ffcf742fe9bb9c91e18 100644 (file)
@@ -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.
old mode 100644 (file)
new mode 100755 (executable)
index 73fe3fa..92eb439
@@ -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/
old mode 100644 (file)
new mode 100755 (executable)
index 37b23af..b0fafda
@@ -29,6 +29,7 @@
 #include <linux/seq_file.h>
 #include <linux/uaccess.h>
 #include <linux/debugfs.h>
+#include <linux/android_pmem.h>
 
 #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, &region,
+                               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 (file)
index 0000000..5451bfd
--- /dev/null
@@ -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 (executable)
index 0000000..20d3126
--- /dev/null
@@ -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 <linux/err.h>
+#include <linux/ion.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#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);
+