exynos_drm_gem.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. * *userptr: user space address.
  35. * @dma_addr: bus address(accessed by dma) to allocated memory region.
  36. * - this address could be physical address without IOMMU and
  37. * device address with IOMMU.
  38. * @write: whether pages will be written to by the caller.
  39. * @pages: Array of backing pages.
  40. * @sgt: sg table to transfer page data.
  41. * @size: size of allocated memory region.
  42. * @pfnmap: indicate whether memory region from userptr is mmaped with
  43. * VM_PFNMAP or not.
  44. */
  45. struct exynos_drm_gem_buf {
  46. void __iomem *kvaddr;
  47. unsigned long userptr;
  48. dma_addr_t dma_addr;
  49. struct dma_attrs dma_attrs;
  50. unsigned int write;
  51. struct page **pages;
  52. struct sg_table *sgt;
  53. unsigned long size;
  54. bool pfnmap;
  55. };
  56. /*
  57. * exynos drm buffer structure.
  58. *
  59. * @base: a gem object.
  60. * - a new handle to this gem object would be created
  61. * by drm_gem_handle_create().
  62. * @buffer: a pointer to exynos_drm_gem_buffer object.
  63. * - contain the information to memory region allocated
  64. * by user request or at framebuffer creation.
  65. * continuous memory region allocated by user request
  66. * or at framebuffer creation.
  67. * @size: size requested from user, in bytes and this size is aligned
  68. * in page unit.
  69. * @vma: a pointer to vm_area.
  70. * @flags: indicate memory type to allocated buffer and cache attruibute.
  71. *
  72. * P.S. this object would be transfered to user as kms_bo.handle so
  73. * user can access the buffer through kms_bo.handle.
  74. */
  75. struct exynos_drm_gem_obj {
  76. struct drm_gem_object base;
  77. struct exynos_drm_gem_buf *buffer;
  78. unsigned long size;
  79. struct vm_area_struct *vma;
  80. unsigned int flags;
  81. };
  82. struct page **exynos_gem_get_pages(struct drm_gem_object *obj, gfp_t gfpmask);
  83. /* destroy a buffer with gem object */
  84. void exynos_drm_gem_destroy(struct exynos_drm_gem_obj *exynos_gem_obj);
  85. /* create a private gem object and initialize it. */
  86. struct exynos_drm_gem_obj *exynos_drm_gem_init(struct drm_device *dev,
  87. unsigned long size);
  88. /* create a new buffer with gem object */
  89. struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_device *dev,
  90. unsigned int flags,
  91. unsigned long size);
  92. /*
  93. * request gem object creation and buffer allocation as the size
  94. * that it is calculated with framebuffer information such as width,
  95. * height and bpp.
  96. */
  97. int exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data,
  98. struct drm_file *file_priv);
  99. /*
  100. * get 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 increased.
  103. */
  104. dma_addr_t *exynos_drm_gem_get_dma_addr(struct drm_device *dev,
  105. unsigned int gem_handle,
  106. struct drm_file *filp);
  107. /*
  108. * put dma address from gem handle and this function could be used for
  109. * other drivers such as 2d/3d acceleration drivers.
  110. * with this function call, gem object reference count would be decreased.
  111. */
  112. void exynos_drm_gem_put_dma_addr(struct drm_device *dev,
  113. unsigned int gem_handle,
  114. struct drm_file *filp);
  115. /* get buffer offset to map to user space. */
  116. int exynos_drm_gem_map_offset_ioctl(struct drm_device *dev, void *data,
  117. struct drm_file *file_priv);
  118. /*
  119. * mmap the physically continuous memory that a gem object contains
  120. * to user space.
  121. */
  122. int exynos_drm_gem_mmap_ioctl(struct drm_device *dev, void *data,
  123. struct drm_file *file_priv);
  124. /* map user space allocated by malloc to pages. */
  125. int exynos_drm_gem_userptr_ioctl(struct drm_device *dev, void *data,
  126. struct drm_file *file_priv);
  127. /* get buffer information to memory region allocated by gem. */
  128. int exynos_drm_gem_get_ioctl(struct drm_device *dev, void *data,
  129. struct drm_file *file_priv);
  130. /* initialize gem object. */
  131. int exynos_drm_gem_init_object(struct drm_gem_object *obj);
  132. /* free gem object. */
  133. void exynos_drm_gem_free_object(struct drm_gem_object *gem_obj);
  134. /* create memory region for drm framebuffer. */
  135. int exynos_drm_gem_dumb_create(struct drm_file *file_priv,
  136. struct drm_device *dev,
  137. struct drm_mode_create_dumb *args);
  138. /* map memory region for drm framebuffer to user space. */
  139. int exynos_drm_gem_dumb_map_offset(struct drm_file *file_priv,
  140. struct drm_device *dev, uint32_t handle,
  141. uint64_t *offset);
  142. /*
  143. * destroy memory region allocated.
  144. * - a gem handle and physical memory region pointed by a gem object
  145. * would be released by drm_gem_handle_delete().
  146. */
  147. int exynos_drm_gem_dumb_destroy(struct drm_file *file_priv,
  148. struct drm_device *dev,
  149. unsigned int handle);
  150. /* page fault handler and mmap fault address(virtual) to physical memory. */
  151. int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
  152. /* set vm_flags and we can change the vm attribute to other one at here. */
  153. int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
  154. static inline int vma_is_io(struct vm_area_struct *vma)
  155. {
  156. return !!(vma->vm_flags & (VM_IO | VM_PFNMAP));
  157. }
  158. /* get a copy of a virtual memory region. */
  159. struct vm_area_struct *exynos_gem_get_vma(struct vm_area_struct *vma);
  160. /* release a userspace virtual memory area. */
  161. void exynos_gem_put_vma(struct vm_area_struct *vma);
  162. /* get pages from user space. */
  163. int exynos_gem_get_pages_from_userptr(unsigned long start,
  164. unsigned int npages,
  165. struct page **pages,
  166. struct vm_area_struct *vma);
  167. /* drop the reference to pages. */
  168. void exynos_gem_put_pages_to_userptr(struct page **pages,
  169. unsigned int npages,
  170. struct vm_area_struct *vma);
  171. /* map sgt with dma region. */
  172. int exynos_gem_map_sgt_with_dma(struct drm_device *drm_dev,
  173. struct sg_table *sgt,
  174. enum dma_data_direction dir);
  175. /* unmap sgt from dma region. */
  176. void exynos_gem_unmap_sgt_from_dma(struct drm_device *drm_dev,
  177. struct sg_table *sgt,
  178. enum dma_data_direction dir);
  179. #endif