2 * drivers/gpu/tegra/tegra_ion.c
4 * Copyright (C) 2011 Google, Inc.
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 #include <linux/err.h>
18 #include <linux/module.h>
19 #include <linux/platform_device.h>
20 #include <linux/slab.h>
22 #include "../ion_priv.h"
24 static struct ion_device *idev;
26 static struct ion_heap **heaps;
28 static int tegra_ion_probe(struct platform_device *pdev)
30 struct ion_platform_data *pdata = pdev->dev.platform_data;
34 num_heaps = pdata->nr;
36 heaps = devm_kzalloc(&pdev->dev,
37 sizeof(struct ion_heap *) * pdata->nr,
40 idev = ion_device_create(NULL);
41 if (IS_ERR_OR_NULL(idev))
44 /* create the heaps as specified in the board file */
45 for (i = 0; i < num_heaps; i++) {
46 struct ion_platform_heap *heap_data = &pdata->heaps[i];
48 heaps[i] = ion_heap_create(heap_data);
49 if (IS_ERR_OR_NULL(heaps[i])) {
50 err = PTR_ERR(heaps[i]);
53 ion_device_add_heap(idev, heaps[i]);
55 platform_set_drvdata(pdev, idev);
58 for (i = 0; i < num_heaps; ++i)
59 ion_heap_destroy(heaps[i]);
63 static int tegra_ion_remove(struct platform_device *pdev)
65 struct ion_device *idev = platform_get_drvdata(pdev);
68 ion_device_destroy(idev);
69 for (i = 0; i < num_heaps; i++)
70 ion_heap_destroy(heaps[i]);
74 static struct platform_driver ion_driver = {
75 .probe = tegra_ion_probe,
76 .remove = tegra_ion_remove,
77 .driver = { .name = "ion-tegra" }
80 module_platform_driver(ion_driver);