drm_gem_cma_helper.h 3.5 KB

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