exynos_drm_gem.h 5.7 KB

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