exynos_drm_buf.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* exynos_drm_buf.c
  2. *
  3. * Copyright (c) 2011 Samsung Electronics Co., Ltd.
  4. * Author: Inki Dae <inki.dae@samsung.com>
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the next
  14. * paragraph) shall be included in all copies or substantial portions of the
  15. * Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  21. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  22. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  23. * OTHER DEALINGS IN THE SOFTWARE.
  24. */
  25. #include "drmP.h"
  26. #include "drm.h"
  27. #include "exynos_drm_drv.h"
  28. #include "exynos_drm_buf.h"
  29. static DEFINE_MUTEX(exynos_drm_buf_lock);
  30. static int lowlevel_buffer_allocate(struct drm_device *dev,
  31. struct exynos_drm_buf_entry *entry)
  32. {
  33. DRM_DEBUG_KMS("%s\n", __FILE__);
  34. entry->vaddr = dma_alloc_writecombine(dev->dev, entry->size,
  35. (dma_addr_t *)&entry->paddr, GFP_KERNEL);
  36. if (!entry->paddr) {
  37. DRM_ERROR("failed to allocate buffer.\n");
  38. return -ENOMEM;
  39. }
  40. DRM_DEBUG_KMS("allocated : vaddr(0x%x), paddr(0x%x), size(0x%x)\n",
  41. (unsigned int)entry->vaddr, entry->paddr, entry->size);
  42. return 0;
  43. }
  44. static void lowlevel_buffer_deallocate(struct drm_device *dev,
  45. struct exynos_drm_buf_entry *entry)
  46. {
  47. DRM_DEBUG_KMS("%s.\n", __FILE__);
  48. if (entry->paddr && entry->vaddr && entry->size)
  49. dma_free_writecombine(dev->dev, entry->size, entry->vaddr,
  50. entry->paddr);
  51. else
  52. DRM_DEBUG_KMS("entry data is null.\n");
  53. }
  54. struct exynos_drm_buf_entry *exynos_drm_buf_create(struct drm_device *dev,
  55. unsigned int size)
  56. {
  57. struct exynos_drm_buf_entry *entry;
  58. DRM_DEBUG_KMS("%s.\n", __FILE__);
  59. entry = kzalloc(sizeof(*entry), GFP_KERNEL);
  60. if (!entry) {
  61. DRM_ERROR("failed to allocate exynos_drm_buf_entry.\n");
  62. return ERR_PTR(-ENOMEM);
  63. }
  64. entry->size = size;
  65. /*
  66. * allocate memory region with size and set the memory information
  67. * to vaddr and paddr of a entry object.
  68. */
  69. if (lowlevel_buffer_allocate(dev, entry) < 0) {
  70. kfree(entry);
  71. entry = NULL;
  72. return ERR_PTR(-ENOMEM);
  73. }
  74. return entry;
  75. }
  76. void exynos_drm_buf_destroy(struct drm_device *dev,
  77. struct exynos_drm_buf_entry *entry)
  78. {
  79. DRM_DEBUG_KMS("%s.\n", __FILE__);
  80. if (!entry) {
  81. DRM_DEBUG_KMS("entry is null.\n");
  82. return;
  83. }
  84. lowlevel_buffer_deallocate(dev, entry);
  85. kfree(entry);
  86. entry = NULL;
  87. }
  88. MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
  89. MODULE_DESCRIPTION("Samsung SoC DRM Buffer Management Module");
  90. MODULE_LICENSE("GPL");