exynos_drm_buf.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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_gem.h"
  29. #include "exynos_drm_buf.h"
  30. static int lowlevel_buffer_allocate(struct drm_device *dev,
  31. struct exynos_drm_gem_buf *buffer)
  32. {
  33. DRM_DEBUG_KMS("%s\n", __FILE__);
  34. buffer->kvaddr = dma_alloc_writecombine(dev->dev, buffer->size,
  35. &buffer->dma_addr, GFP_KERNEL);
  36. if (!buffer->kvaddr) {
  37. DRM_ERROR("failed to allocate buffer.\n");
  38. return -ENOMEM;
  39. }
  40. DRM_DEBUG_KMS("vaddr(0x%lx), dma_addr(0x%lx), size(0x%lx)\n",
  41. (unsigned long)buffer->kvaddr,
  42. (unsigned long)buffer->dma_addr,
  43. buffer->size);
  44. return 0;
  45. }
  46. static void lowlevel_buffer_deallocate(struct drm_device *dev,
  47. struct exynos_drm_gem_buf *buffer)
  48. {
  49. DRM_DEBUG_KMS("%s.\n", __FILE__);
  50. if (buffer->dma_addr && buffer->size)
  51. dma_free_writecombine(dev->dev, buffer->size, buffer->kvaddr,
  52. (dma_addr_t)buffer->dma_addr);
  53. else
  54. DRM_DEBUG_KMS("buffer data are invalid.\n");
  55. }
  56. struct exynos_drm_gem_buf *exynos_drm_buf_create(struct drm_device *dev,
  57. unsigned int size)
  58. {
  59. struct exynos_drm_gem_buf *buffer;
  60. DRM_DEBUG_KMS("%s.\n", __FILE__);
  61. DRM_DEBUG_KMS("desired size = 0x%x\n", size);
  62. buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
  63. if (!buffer) {
  64. DRM_ERROR("failed to allocate exynos_drm_gem_buf.\n");
  65. return NULL;
  66. }
  67. buffer->size = size;
  68. /*
  69. * allocate memory region with size and set the memory information
  70. * to vaddr and dma_addr of a buffer object.
  71. */
  72. if (lowlevel_buffer_allocate(dev, buffer) < 0) {
  73. kfree(buffer);
  74. return NULL;
  75. }
  76. return buffer;
  77. }
  78. void exynos_drm_buf_destroy(struct drm_device *dev,
  79. struct exynos_drm_gem_buf *buffer)
  80. {
  81. DRM_DEBUG_KMS("%s.\n", __FILE__);
  82. if (!buffer) {
  83. DRM_DEBUG_KMS("buffer is null.\n");
  84. return;
  85. }
  86. lowlevel_buffer_deallocate(dev, buffer);
  87. kfree(buffer);
  88. buffer = NULL;
  89. }
  90. MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
  91. MODULE_DESCRIPTION("Samsung SoC DRM Buffer Management Module");
  92. MODULE_LICENSE("GPL");