exynos_drm_gem.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /* exynos_drm_gem.h
  2. *
  3. * Copyright (c) 2011 Samsung Electronics Co., Ltd.
  4. * Authoer: Inki Dae <inki.dae@samsung.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. */
  11. #ifndef _EXYNOS_DRM_GEM_H_
  12. #define _EXYNOS_DRM_GEM_H_
  13. #define to_exynos_gem_obj(x) container_of(x,\
  14. struct exynos_drm_gem_obj, base)
  15. #define IS_NONCONTIG_BUFFER(f) (f & EXYNOS_BO_NONCONTIG)
  16. /*
  17. * exynos drm gem buffer structure.
  18. *
  19. * @kvaddr: kernel virtual address to allocated memory region.
  20. * *userptr: user space address.
  21. * @dma_addr: bus address(accessed by dma) to allocated memory region.
  22. * - this address could be physical address without IOMMU and
  23. * device address with IOMMU.
  24. * @write: whether pages will be written to by the caller.
  25. * @pages: Array of backing pages.
  26. * @sgt: sg table to transfer page data.
  27. * @size: size of allocated memory region.
  28. * @pfnmap: indicate whether memory region from userptr is mmaped with
  29. * VM_PFNMAP or not.
  30. */
  31. struct exynos_drm_gem_buf {
  32. void __iomem *kvaddr;
  33. unsigned long userptr;
  34. dma_addr_t dma_addr;
  35. struct dma_attrs dma_attrs;
  36. unsigned int write;
  37. struct page **pages;
  38. struct sg_table *sgt;
  39. unsigned long size;
  40. bool pfnmap;
  41. };
  42. /*
  43. * exynos drm buffer structure.
  44. *
  45. * @base: a gem object.
  46. * - a new handle to this gem object would be created
  47. * by drm_gem_handle_create().
  48. * @buffer: a pointer to exynos_drm_gem_buffer object.
  49. * - contain the information to memory region allocated
  50. * by user request or at framebuffer creation.
  51. * continuous memory region allocated by user request
  52. * or at framebuffer creation.
  53. * @size: size requested from user, in bytes and this size is aligned
  54. * in page unit.
  55. * @vma: a pointer to vm_area.
  56. * @flags: indicate memory type to allocated buffer and cache attruibute.
  57. *
  58. * P.S. this object would be transfered to user as kms_bo.handle so
  59. * user can access the buffer through kms_bo.handle.
  60. */
  61. struct exynos_drm_gem_obj {
  62. struct drm_gem_object base;
  63. struct exynos_drm_gem_buf *buffer;
  64. unsigned long size;
  65. struct vm_area_struct *vma;
  66. unsigned int flags;
  67. };
  68. struct page **exynos_gem_get_pages(struct drm_gem_object *obj, gfp_t gfpmask);
  69. /* destroy a buffer with gem object */
  70. void exynos_drm_gem_destroy(struct exynos_drm_gem_obj *exynos_gem_obj);
  71. /* create a private gem object and initialize it. */
  72. struct exynos_drm_gem_obj *exynos_drm_gem_init(struct drm_device *dev,
  73. unsigned long size);
  74. /* create a new buffer with gem object */
  75. struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_device *dev,
  76. unsigned int flags,
  77. unsigned long size);
  78. /*
  79. * request gem object creation and buffer allocation as the size
  80. * that it is calculated with framebuffer information such as width,
  81. * height and bpp.
  82. */
  83. int exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data,
  84. struct drm_file *file_priv);
  85. /*
  86. * get dma address from gem handle and this function could be used for
  87. * other drivers such as 2d/3d acceleration drivers.
  88. * with this function call, gem object reference count would be increased.
  89. */
  90. dma_addr_t *exynos_drm_gem_get_dma_addr(struct drm_device *dev,
  91. unsigned int gem_handle,
  92. struct drm_file *filp);
  93. /*
  94. * put dma address from gem handle and this function could be used for
  95. * other drivers such as 2d/3d acceleration drivers.
  96. * with this function call, gem object reference count would be decreased.
  97. */
  98. void exynos_drm_gem_put_dma_addr(struct drm_device *dev,
  99. unsigned int gem_handle,
  100. struct drm_file *filp);
  101. /* get buffer offset to map to user space. */
  102. int exynos_drm_gem_map_offset_ioctl(struct drm_device *dev, void *data,
  103. struct drm_file *file_priv);
  104. /*
  105. * mmap the physically continuous memory that a gem object contains
  106. * to user space.
  107. */
  108. int exynos_drm_gem_mmap_ioctl(struct drm_device *dev, void *data,
  109. struct drm_file *file_priv);
  110. /* map user space allocated by malloc to pages. */
  111. int exynos_drm_gem_userptr_ioctl(struct drm_device *dev, void *data,
  112. struct drm_file *file_priv);
  113. /* get buffer information to memory region allocated by gem. */
  114. int exynos_drm_gem_get_ioctl(struct drm_device *dev, void *data,
  115. struct drm_file *file_priv);
  116. /* get buffer size to gem handle. */
  117. unsigned long exynos_drm_gem_get_size(struct drm_device *dev,
  118. unsigned int gem_handle,
  119. struct drm_file *file_priv);
  120. /* initialize gem object. */
  121. int exynos_drm_gem_init_object(struct drm_gem_object *obj);
  122. /* free gem object. */
  123. void exynos_drm_gem_free_object(struct drm_gem_object *gem_obj);
  124. /* create memory region for drm framebuffer. */
  125. int exynos_drm_gem_dumb_create(struct drm_file *file_priv,
  126. struct drm_device *dev,
  127. struct drm_mode_create_dumb *args);
  128. /* map memory region for drm framebuffer to user space. */
  129. int exynos_drm_gem_dumb_map_offset(struct drm_file *file_priv,
  130. struct drm_device *dev, uint32_t handle,
  131. uint64_t *offset);
  132. /*
  133. * destroy memory region allocated.
  134. * - a gem handle and physical memory region pointed by a gem object
  135. * would be released by drm_gem_handle_delete().
  136. */
  137. int exynos_drm_gem_dumb_destroy(struct drm_file *file_priv,
  138. struct drm_device *dev,
  139. unsigned int handle);
  140. /* page fault handler and mmap fault address(virtual) to physical memory. */
  141. int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
  142. /* set vm_flags and we can change the vm attribute to other one at here. */
  143. int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
  144. static inline int vma_is_io(struct vm_area_struct *vma)
  145. {
  146. return !!(vma->vm_flags & (VM_IO | VM_PFNMAP));
  147. }
  148. /* get a copy of a virtual memory region. */
  149. struct vm_area_struct *exynos_gem_get_vma(struct vm_area_struct *vma);
  150. /* release a userspace virtual memory area. */
  151. void exynos_gem_put_vma(struct vm_area_struct *vma);
  152. /* get pages from user space. */
  153. int exynos_gem_get_pages_from_userptr(unsigned long start,
  154. unsigned int npages,
  155. struct page **pages,
  156. struct vm_area_struct *vma);
  157. /* drop the reference to pages. */
  158. void exynos_gem_put_pages_to_userptr(struct page **pages,
  159. unsigned int npages,
  160. struct vm_area_struct *vma);
  161. /* map sgt with dma region. */
  162. int exynos_gem_map_sgt_with_dma(struct drm_device *drm_dev,
  163. struct sg_table *sgt,
  164. enum dma_data_direction dir);
  165. /* unmap sgt from dma region. */
  166. void exynos_gem_unmap_sgt_from_dma(struct drm_device *drm_dev,
  167. struct sg_table *sgt,
  168. enum dma_data_direction dir);
  169. #endif