Skip to content

Commit

Permalink
gpu: ion: Add platform driver for msm ion
Browse files Browse the repository at this point in the history
Add platform driver for msm specific ion devices

Signed-off-by: Laura Abbott <[email protected]>
  • Loading branch information
labbott authored and TomGiordano committed Mar 31, 2012
1 parent edaf7c7 commit 6ddff29
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 0 deletions.
5 changes: 5 additions & 0 deletions drivers/gpu/ion/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ config ION_TEGRA
help
Choose this option if you wish to use ion on an nVidia Tegra.

config ION_MSM
tristate "Ion for MSM"
depends on ARCH_MSM && ION
help
Choose this option if you wish to use ion on an MSM target.
1 change: 1 addition & 0 deletions drivers/gpu/ion/Makefile
Original file line number Diff line number Diff line change
@@ -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_MSM) += msm/
1 change: 1 addition & 0 deletions drivers/gpu/ion/msm/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
obj-y += msm_ion.o
106 changes: 106 additions & 0 deletions drivers/gpu/ion/msm/msm_ion.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* 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"

struct ion_device *idev;
int num_heaps;
struct ion_heap **heaps;

struct ion_client *msm_ion_client_create(unsigned int heap_mask,
const char *name)
{
return ion_client_create(idev, heap_mask, name);
}

static int msm_ion_probe(struct platform_device *pdev)
{
struct ion_platform_data *pdata = pdev->dev.platform_data;
int err;
int i;

num_heaps = pdata->nr;

heaps = kcalloc(pdata->nr, sizeof(struct ion_heap *), GFP_KERNEL);

if (!heaps) {
err = -ENOMEM;
goto out;
}

idev = ion_device_create(NULL);
if (IS_ERR_OR_NULL(idev)) {
err = PTR_ERR(idev);
goto freeheaps;
}

/* 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 heapdestroy;
}
ion_device_add_heap(idev, heaps[i]);
}
platform_set_drvdata(pdev, idev);
return 0;

heapdestroy:
for (i = 0; i < num_heaps; i++) {
if (!IS_ERR_OR_NULL(heaps[i]))
ion_heap_destroy(heaps[i]);
}
freeheaps:
kfree(heaps);
out:
return err;
}

static int msm_ion_remove(struct platform_device *pdev)
{
struct ion_device *idev = platform_get_drvdata(pdev);
int i;

for (i = 0; i < num_heaps; i++)
ion_heap_destroy(heaps[i]);

ion_device_destroy(idev);
kfree(heaps);
return 0;
}

static struct platform_driver msm_ion_driver = {
.probe = msm_ion_probe,
.remove = msm_ion_remove,
.driver = { .name = "ion-msm" }
};

static int __init msm_ion_init(void)
{
return platform_driver_register(&msm_ion_driver);
}

static void __exit msm_ion_exit(void)
{
platform_driver_unregister(&msm_ion_driver);
}

module_init(msm_ion_init);
module_exit(msm_ion_exit);

11 changes: 11 additions & 0 deletions include/linux/ion.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ struct ion_platform_data {
struct ion_client *ion_client_create(struct ion_device *dev,
unsigned int heap_mask, const char *name);

/**
* msm_ion_client_create - allocate a client using the ion_device specified in
* drivers/gpu/ion/msm/msm_ion.c
*
* heap_mask and name are the same as ion_client_create, return values
* are the same as ion_client_create.
*/

struct ion_client *msm_ion_client_create(unsigned int heap_mask,
const char *name);

/**
* ion_client_destroy() - free's a client and all it's handles
* @client: the client
Expand Down

0 comments on commit 6ddff29

Please sign in to comment.