exynos_drm_gem.h 5.9 KB

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