exynos_drm_gem.h 6.0 KB

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