exynos_drm_gem.h 7.1 KB

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