exynos_drm_gem.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. unsigned long dma_attrs;
  49. struct page **pages;
  50. struct sg_table *sgt;
  51. };
  52. /* destroy a buffer with gem object */
  53. void exynos_drm_gem_destroy(struct exynos_drm_gem *exynos_gem);
  54. /* create a new buffer with gem object */
  55. struct exynos_drm_gem *exynos_drm_gem_create(struct drm_device *dev,
  56. unsigned int flags,
  57. unsigned long size);
  58. /*
  59. * request gem object creation and buffer allocation as the size
  60. * that it is calculated with framebuffer information such as width,
  61. * height and bpp.
  62. */
  63. int exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data,
  64. struct drm_file *file_priv);
  65. /* get fake-offset of gem object that can be used with mmap. */
  66. int exynos_drm_gem_map_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. /* get buffer information to memory region allocated by gem. */
  85. int exynos_drm_gem_get_ioctl(struct drm_device *dev, void *data,
  86. struct drm_file *file_priv);
  87. /* get buffer size to gem handle. */
  88. unsigned long exynos_drm_gem_get_size(struct drm_device *dev,
  89. unsigned int gem_handle,
  90. struct drm_file *file_priv);
  91. /* free gem object. */
  92. void exynos_drm_gem_free_object(struct drm_gem_object *obj);
  93. /* create memory region for drm framebuffer. */
  94. int exynos_drm_gem_dumb_create(struct drm_file *file_priv,
  95. struct drm_device *dev,
  96. struct drm_mode_create_dumb *args);
  97. /* map memory region for drm framebuffer to user space. */
  98. int exynos_drm_gem_dumb_map_offset(struct drm_file *file_priv,
  99. struct drm_device *dev, uint32_t handle,
  100. uint64_t *offset);
  101. /* page fault handler and mmap fault address(virtual) to physical memory. */
  102. int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
  103. /* set vm_flags and we can change the vm attribute to other one at here. */
  104. int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
  105. /* low-level interface prime helpers */
  106. struct sg_table *exynos_drm_gem_prime_get_sg_table(struct drm_gem_object *obj);
  107. struct drm_gem_object *
  108. exynos_drm_gem_prime_import_sg_table(struct drm_device *dev,
  109. struct dma_buf_attachment *attach,
  110. struct sg_table *sgt);
  111. void *exynos_drm_gem_prime_vmap(struct drm_gem_object *obj);
  112. void exynos_drm_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
  113. int exynos_drm_gem_prime_mmap(struct drm_gem_object *obj,
  114. struct vm_area_struct *vma);
  115. #endif