tegra_ion.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #include <linux/err.h>
  17. #include <linux/ion.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/slab.h>
  20. #include "../ion_priv.h"
  21. struct ion_device *idev;
  22. struct ion_mapper *tegra_user_mapper;
  23. int num_heaps;
  24. struct ion_heap **heaps;
  25. int tegra_ion_probe(struct platform_device *pdev)
  26. {
  27. struct ion_platform_data *pdata = pdev->dev.platform_data;
  28. int err;
  29. int i;
  30. num_heaps = pdata->nr;
  31. heaps = kzalloc(sizeof(struct ion_heap *) * pdata->nr, GFP_KERNEL);
  32. idev = ion_device_create(NULL);
  33. if (IS_ERR_OR_NULL(idev)) {
  34. kfree(heaps);
  35. return PTR_ERR(idev);
  36. }
  37. /* create the heaps as specified in the board file */
  38. for (i = 0; i < num_heaps; i++) {
  39. struct ion_platform_heap *heap_data = &pdata->heaps[i];
  40. heaps[i] = ion_heap_create(heap_data);
  41. if (IS_ERR_OR_NULL(heaps[i])) {
  42. err = PTR_ERR(heaps[i]);
  43. goto err;
  44. }
  45. ion_device_add_heap(idev, heaps[i]);
  46. }
  47. platform_set_drvdata(pdev, idev);
  48. return 0;
  49. err:
  50. for (i = 0; i < num_heaps; i++) {
  51. if (heaps[i])
  52. ion_heap_destroy(heaps[i]);
  53. }
  54. kfree(heaps);
  55. return err;
  56. }
  57. int tegra_ion_remove(struct platform_device *pdev)
  58. {
  59. struct ion_device *idev = platform_get_drvdata(pdev);
  60. int i;
  61. ion_device_destroy(idev);
  62. for (i = 0; i < num_heaps; i++)
  63. ion_heap_destroy(heaps[i]);
  64. kfree(heaps);
  65. return 0;
  66. }
  67. static struct platform_driver ion_driver = {
  68. .probe = tegra_ion_probe,
  69. .remove = tegra_ion_remove,
  70. .driver = { .name = "ion-tegra" }
  71. };
  72. static int __init ion_init(void)
  73. {
  74. return platform_driver_register(&ion_driver);
  75. }
  76. static void __exit ion_exit(void)
  77. {
  78. platform_driver_unregister(&ion_driver);
  79. }
  80. module_init(ion_init);
  81. module_exit(ion_exit);