drm_gem_cma_helper.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __DRM_GEM_CMA_HELPER_H__
  3. #define __DRM_GEM_CMA_HELPER_H__
  4. #include <drm/drmP.h>
  5. #include <drm/drm_gem.h>
  6. /**
  7. * struct drm_gem_cma_object - GEM object backed by CMA memory allocations
  8. * @base: base GEM object
  9. * @paddr: physical address of the backing memory
  10. * @sgt: scatter/gather table for imported PRIME buffers
  11. * @vaddr: kernel virtual address of the backing memory
  12. */
  13. struct drm_gem_cma_object {
  14. struct drm_gem_object base;
  15. dma_addr_t paddr;
  16. struct sg_table *sgt;
  17. /* For objects with DMA memory allocated by GEM CMA */
  18. void *vaddr;
  19. };
  20. static inline struct drm_gem_cma_object *
  21. to_drm_gem_cma_obj(struct drm_gem_object *gem_obj)
  22. {
  23. return container_of(gem_obj, struct drm_gem_cma_object, base);
  24. }
  25. #ifndef CONFIG_MMU
  26. #define DRM_GEM_CMA_UNMAPPED_AREA_FOPS \
  27. .get_unmapped_area = drm_gem_cma_get_unmapped_area,
  28. #else
  29. #define DRM_GEM_CMA_UNMAPPED_AREA_FOPS
  30. #endif
  31. /**
  32. * DEFINE_DRM_GEM_CMA_FOPS() - macro to generate file operations for CMA drivers
  33. * @name: name for the generated structure
  34. *
  35. * This macro autogenerates a suitable &struct file_operations for CMA based
  36. * drivers, which can be assigned to &drm_driver.fops. Note that this structure
  37. * cannot be shared between drivers, because it contains a reference to the
  38. * current module using THIS_MODULE.
  39. *
  40. * Note that the declaration is already marked as static - if you need a
  41. * non-static version of this you're probably doing it wrong and will break the
  42. * THIS_MODULE reference by accident.
  43. */
  44. #define DEFINE_DRM_GEM_CMA_FOPS(name) \
  45. static const struct file_operations name = {\
  46. .owner = THIS_MODULE,\
  47. .open = drm_open,\
  48. .release = drm_release,\
  49. .unlocked_ioctl = drm_ioctl,\
  50. .compat_ioctl = drm_compat_ioctl,\
  51. .poll = drm_poll,\
  52. .read = drm_read,\
  53. .llseek = noop_llseek,\
  54. .mmap = drm_gem_cma_mmap,\
  55. DRM_GEM_CMA_UNMAPPED_AREA_FOPS \
  56. }
  57. /* free GEM object */
  58. void drm_gem_cma_free_object(struct drm_gem_object *gem_obj);
  59. /* create memory region for DRM framebuffer */
  60. int drm_gem_cma_dumb_create_internal(struct drm_file *file_priv,
  61. struct drm_device *drm,
  62. struct drm_mode_create_dumb *args);
  63. /* create memory region for DRM framebuffer */
  64. int drm_gem_cma_dumb_create(struct drm_file *file_priv,
  65. struct drm_device *drm,
  66. struct drm_mode_create_dumb *args);
  67. /* set vm_flags and we can change the VM attribute to other one at here */
  68. int drm_gem_cma_mmap(struct file *filp, struct vm_area_struct *vma);
  69. /* allocate physical memory */
  70. struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm,
  71. size_t size);
  72. extern const struct vm_operations_struct drm_gem_cma_vm_ops;
  73. #ifndef CONFIG_MMU
  74. unsigned long drm_gem_cma_get_unmapped_area(struct file *filp,
  75. unsigned long addr,
  76. unsigned long len,
  77. unsigned long pgoff,
  78. unsigned long flags);
  79. #endif
  80. #ifdef CONFIG_DEBUG_FS
  81. void drm_gem_cma_describe(struct drm_gem_cma_object *obj, struct seq_file *m);
  82. #endif
  83. struct sg_table *drm_gem_cma_prime_get_sg_table(struct drm_gem_object *obj);
  84. struct drm_gem_object *
  85. drm_gem_cma_prime_import_sg_table(struct drm_device *dev,
  86. struct dma_buf_attachment *attach,
  87. struct sg_table *sgt);
  88. int drm_gem_cma_prime_mmap(struct drm_gem_object *obj,
  89. struct vm_area_struct *vma);
  90. void *drm_gem_cma_prime_vmap(struct drm_gem_object *obj);
  91. void drm_gem_cma_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
  92. #endif /* __DRM_GEM_CMA_HELPER_H__ */