exynos_drm_gem.h 5.7 KB

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