exynos_drm_gem.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. *
  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_obj {
  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. };
  51. struct page **exynos_gem_get_pages(struct drm_gem_object *obj, gfp_t gfpmask);
  52. /* destroy a buffer with gem object */
  53. void exynos_drm_gem_destroy(struct exynos_drm_gem_obj *exynos_gem_obj);
  54. /* create a private gem object and initialize it. */
  55. struct exynos_drm_gem_obj *exynos_drm_gem_init(struct drm_device *dev,
  56. unsigned long size);
  57. /* create a new buffer with gem object */
  58. struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_device *dev,
  59. unsigned int flags,
  60. unsigned long size);
  61. /*
  62. * request gem object creation and buffer allocation as the size
  63. * that it is calculated with framebuffer information such as width,
  64. * height and bpp.
  65. */
  66. int exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data,
  67. struct drm_file *file_priv);
  68. /*
  69. * get dma address from gem handle and this function could be used for
  70. * other drivers such as 2d/3d acceleration drivers.
  71. * with this function call, gem object reference count would be increased.
  72. */
  73. dma_addr_t *exynos_drm_gem_get_dma_addr(struct drm_device *dev,
  74. unsigned int gem_handle,
  75. struct drm_file *filp);
  76. /*
  77. * put dma address from gem handle and this function could be used for
  78. * other drivers such as 2d/3d acceleration drivers.
  79. * with this function call, gem object reference count would be decreased.
  80. */
  81. void exynos_drm_gem_put_dma_addr(struct drm_device *dev,
  82. unsigned int gem_handle,
  83. struct drm_file *filp);
  84. /* map user space allocated by malloc to pages. */
  85. int exynos_drm_gem_userptr_ioctl(struct drm_device *dev, void *data,
  86. struct drm_file *file_priv);
  87. /* get buffer information to memory region allocated by gem. */
  88. int exynos_drm_gem_get_ioctl(struct drm_device *dev, void *data,
  89. struct drm_file *file_priv);
  90. /* get buffer size to gem handle. */
  91. unsigned long exynos_drm_gem_get_size(struct drm_device *dev,
  92. unsigned int gem_handle,
  93. struct drm_file *file_priv);
  94. /* free gem object. */
  95. void exynos_drm_gem_free_object(struct drm_gem_object *gem_obj);
  96. /* create memory region for drm framebuffer. */
  97. int exynos_drm_gem_dumb_create(struct drm_file *file_priv,
  98. struct drm_device *dev,
  99. struct drm_mode_create_dumb *args);
  100. /* map memory region for drm framebuffer to user space. */
  101. int exynos_drm_gem_dumb_map_offset(struct drm_file *file_priv,
  102. struct drm_device *dev, uint32_t handle,
  103. uint64_t *offset);
  104. /* page fault handler and mmap fault address(virtual) to physical memory. */
  105. int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
  106. /* set vm_flags and we can change the vm attribute to other one at here. */
  107. int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
  108. static inline int vma_is_io(struct vm_area_struct *vma)
  109. {
  110. return !!(vma->vm_flags & (VM_IO | VM_PFNMAP));
  111. }
  112. /* get a copy of a virtual memory region. */
  113. struct vm_area_struct *exynos_gem_get_vma(struct vm_area_struct *vma);
  114. /* release a userspace virtual memory area. */
  115. void exynos_gem_put_vma(struct vm_area_struct *vma);
  116. /* get pages from user space. */
  117. int exynos_gem_get_pages_from_userptr(unsigned long start,
  118. unsigned int npages,
  119. struct page **pages,
  120. struct vm_area_struct *vma);
  121. /* drop the reference to pages. */
  122. void exynos_gem_put_pages_to_userptr(struct page **pages,
  123. unsigned int npages,
  124. struct vm_area_struct *vma);
  125. /* map sgt with dma region. */
  126. int exynos_gem_map_sgt_with_dma(struct drm_device *drm_dev,
  127. struct sg_table *sgt,
  128. enum dma_data_direction dir);
  129. /* unmap sgt from dma region. */
  130. void exynos_gem_unmap_sgt_from_dma(struct drm_device *drm_dev,
  131. struct sg_table *sgt,
  132. enum dma_data_direction dir);
  133. /* low-level interface prime helpers */
  134. struct sg_table *exynos_drm_gem_prime_get_sg_table(struct drm_gem_object *obj);
  135. struct drm_gem_object *
  136. exynos_drm_gem_prime_import_sg_table(struct drm_device *dev,
  137. struct dma_buf_attachment *attach,
  138. struct sg_table *sgt);
  139. void *exynos_drm_gem_prime_vmap(struct drm_gem_object *obj);
  140. void exynos_drm_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
  141. #endif