tegra_ion.c revision d4ed510a4ce84b656891f617e22d4a79a99af0c1
1/* 2 * drivers/gpu/tegra/tegra_ion.c 3 * 4 * Copyright (C) 2011 Google, Inc. 5 * 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. 9 * 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. 14 * 15 */ 16 17#include <linux/err.h> 18#include <linux/platform_device.h> 19#include <linux/slab.h> 20#include "../ion.h" 21#include "../ion_priv.h" 22 23struct ion_device *idev; 24struct ion_mapper *tegra_user_mapper; 25int num_heaps; 26struct ion_heap **heaps; 27 28int tegra_ion_probe(struct platform_device *pdev) 29{ 30 struct ion_platform_data *pdata = pdev->dev.platform_data; 31 int err; 32 int i; 33 34 num_heaps = pdata->nr; 35 36 heaps = kzalloc(sizeof(struct ion_heap *) * pdata->nr, GFP_KERNEL); 37 38 idev = ion_device_create(NULL); 39 if (IS_ERR_OR_NULL(idev)) { 40 kfree(heaps); 41 return PTR_ERR(idev); 42 } 43 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]; 47 48 heaps[i] = ion_heap_create(heap_data); 49 if (IS_ERR_OR_NULL(heaps[i])) { 50 err = PTR_ERR(heaps[i]); 51 goto err; 52 } 53 ion_device_add_heap(idev, heaps[i]); 54 } 55 platform_set_drvdata(pdev, idev); 56 return 0; 57err: 58 for (i = 0; i < num_heaps; i++) { 59 if (heaps[i]) 60 ion_heap_destroy(heaps[i]); 61 } 62 kfree(heaps); 63 return err; 64} 65 66int tegra_ion_remove(struct platform_device *pdev) 67{ 68 struct ion_device *idev = platform_get_drvdata(pdev); 69 int i; 70 71 ion_device_destroy(idev); 72 for (i = 0; i < num_heaps; i++) 73 ion_heap_destroy(heaps[i]); 74 kfree(heaps); 75 return 0; 76} 77 78static struct platform_driver ion_driver = { 79 .probe = tegra_ion_probe, 80 .remove = tegra_ion_remove, 81 .driver = { .name = "ion-tegra" } 82}; 83 84module_platform_driver(ion_driver); 85 86