exynos_drm_gem.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* exynos_drm_gem.h
  2. *
  3. * Copyright (c) 2011 Samsung Electronics Co., Ltd.
  4. * Authoer: 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. #ifndef _EXYNOS_DRM_GEM_H_
  26. #define _EXYNOS_DRM_GEM_H_
  27. #define to_exynos_gem_obj(x) container_of(x,\
  28. struct exynos_drm_gem_obj, base)
  29. #define IS_NONCONTIG_BUFFER(f) (f & EXYNOS_BO_NONCONTIG)
  30. /*
  31. * exynos drm gem buffer structure.
  32. *
  33. * @kvaddr: kernel virtual address to allocated memory region.
  34. * @dma_addr: bus address(accessed by dma) to allocated memory region.
  35. * - this address could be physical address without IOMMU and
  36. * device address with IOMMU.
  37. * @sgt: sg table to transfer page data.
  38. * @pages: contain all pages to allocated memory region.
  39. * @page_size: could be 4K, 64K or 1MB.
  40. * @size: size of allocated memory region.
  41. */
  42. struct exynos_drm_gem_buf {
  43. void __iomem *kvaddr;
  44. dma_addr_t dma_addr;
  45. struct sg_table *sgt;
  46. struct page **pages;
  47. unsigned long page_size;
  48. unsigned long size;
  49. };
  50. /*
  51. * exynos drm buffer structure.
  52. *
  53. * @base: a gem object.
  54. * - a new handle to this gem object would be created
  55. * by drm_gem_handle_create().
  56. * @buffer: a pointer to exynos_drm_gem_buffer object.
  57. * - contain the information to memory region allocated
  58. * by user request or at framebuffer creation.
  59. * continuous memory region allocated by user request
  60. * or at framebuffer creation.
  61. * @size: size requested from user, in bytes and this size is aligned
  62. * in page unit.
  63. * @flags: indicate memory type to allocated buffer and cache attruibute.
  64. *
  65. * P.S. this object would be transfered to user as kms_bo.handle so
  66. * user can access the buffer through kms_bo.handle.
  67. */
  68. struct exynos_drm_gem_obj {
  69. struct drm_gem_object base;
  70. struct exynos_drm_gem_buf *buffer;
  71. unsigned long size;
  72. unsigned int flags;
  73. };
  74. struct page **exynos_gem_get_pages(struct drm_gem_object *obj, gfp_t gfpmask);
  75. /* destroy a buffer with gem object */
  76. void exynos_drm_gem_destroy(struct exynos_drm_gem_obj *exynos_gem_obj);
  77. /* create a private gem object and initialize it. */
  78. struct exynos_drm_gem_obj *exynos_drm_gem_init(struct drm_device *dev,
  79. unsigned long size);
  80. /* create a new buffer with gem object */
  81. struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_device *dev,
  82. unsigned int flags,
  83. unsigned long size);
  84. /*
  85. * request gem object creation and buffer allocation as the size
  86. * that it is calculated with framebuffer information such as width,
  87. * height and bpp.
  88. */
  89. int exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data,
  90. struct drm_file *file_priv);
  91. /*
  92. * get dma address from gem handle and this function could be used for
  93. * other drivers such as 2d/3d acceleration drivers.
  94. * with this function call, gem object reference count would be increased.
  95. */
  96. void *exynos_drm_gem_get_dma_addr(struct drm_device *dev,
  97. unsigned int gem_handle,
  98. struct drm_file *file_priv);
  99. /*
  100. * put dma address from gem handle and this function could be used for
  101. * other drivers such as 2d/3d acceleration drivers.
  102. * with this function call, gem object reference count would be decreased.
  103. */
  104. void exynos_drm_gem_put_dma_addr(struct drm_device *dev,
  105. unsigned int gem_handle,
  106. struct drm_file *file_priv);
  107. /* get buffer offset to map to user space. */
  108. int exynos_drm_gem_map_offset_ioctl(struct drm_device *dev, void *data,
  109. struct drm_file *file_priv);
  110. /*
  111. * mmap the physically continuous memory that a gem object contains
  112. * to user space.
  113. */
  114. int exynos_drm_gem_mmap_ioctl(struct drm_device *dev, void *data,
  115. struct drm_file *file_priv);
  116. /* get buffer information to memory region allocated by gem. */
  117. int exynos_drm_gem_get_ioctl(struct drm_device *dev, void *data,
  118. struct drm_file *file_priv);
  119. /* initialize gem object. */
  120. int exynos_drm_gem_init_object(struct drm_gem_object *obj);
  121. /* free gem object. */
  122. void exynos_drm_gem_free_object(struct drm_gem_object *gem_obj);
  123. /* create memory region for drm framebuffer. */
  124. int exynos_drm_gem_dumb_create(struct drm_file *file_priv,
  125. struct drm_device *dev,
  126. struct drm_mode_create_dumb *args);
  127. /* map memory region for drm framebuffer to user space. */
  128. int exynos_drm_gem_dumb_map_offset(struct drm_file *file_priv,
  129. struct drm_device *dev, uint32_t handle,
  130. uint64_t *offset);
  131. /*
  132. * destroy memory region allocated.
  133. * - a gem handle and physical memory region pointed by a gem object
  134. * would be released by drm_gem_handle_delete().
  135. */
  136. int exynos_drm_gem_dumb_destroy(struct drm_file *file_priv,
  137. struct drm_device *dev,
  138. unsigned int handle);
  139. /* page fault handler and mmap fault address(virtual) to physical memory. */
  140. int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
  141. /* set vm_flags and we can change the vm attribute to other one at here. */
  142. int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
  143. #endif