mtk_drm_gem.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (c) 2015 MediaTek Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #ifndef _MTK_DRM_GEM_H_
  14. #define _MTK_DRM_GEM_H_
  15. #include <drm/drm_gem.h>
  16. #if defined(CONFIG_MTK_IOMMU_V2)
  17. #include "ion_drv.h"
  18. #include "ion_priv.h"
  19. #include <soc/mediatek/smi.h>
  20. #include "mtk_iommu_ext.h"
  21. #include "pseudo_m4u.h"
  22. #endif
  23. /*
  24. * mtk drm buffer structure.
  25. *
  26. * @base: a gem object.
  27. * - a new handle to this gem object would be created
  28. * by drm_gem_handle_create().
  29. * @cookie: the return value of dma_alloc_attrs(), keep it for dma_free_attrs()
  30. * @kvaddr: kernel virtual address of gem buffer.
  31. * @dma_addr: dma address of gem buffer.
  32. * @dma_attrs: dma attributes of gem buffer.
  33. *
  34. * P.S. this object would be transferred to user as kms_bo.handle so
  35. * user can access the buffer through kms_bo.handle.
  36. */
  37. struct mtk_drm_gem_obj {
  38. struct drm_gem_object base;
  39. void *cookie;
  40. void *kvaddr;
  41. dma_addr_t dma_addr;
  42. size_t size;
  43. unsigned long dma_attrs;
  44. struct sg_table *sg;
  45. #if defined(CONFIG_MTK_IOMMU_V2)
  46. struct ion_handle *handle;
  47. #endif
  48. bool sec;
  49. bool is_dumb;
  50. };
  51. #define to_mtk_gem_obj(x) container_of(x, struct mtk_drm_gem_obj, base)
  52. void mtk_drm_gem_free_object(struct drm_gem_object *gem);
  53. struct mtk_drm_gem_obj *mtk_drm_gem_create(struct drm_device *dev, size_t size,
  54. bool alloc_kmap);
  55. int mtk_drm_gem_dumb_create(struct drm_file *file_priv, struct drm_device *dev,
  56. struct drm_mode_create_dumb *args);
  57. int mtk_drm_gem_dumb_map_offset(struct drm_file *file_priv,
  58. struct drm_device *dev, uint32_t handle,
  59. uint64_t *offset);
  60. int mtk_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
  61. int mtk_drm_gem_mmap_buf(struct drm_gem_object *obj,
  62. struct vm_area_struct *vma);
  63. #if defined(CONFIG_MTK_IOMMU_V2)
  64. struct ion_client *mtk_drm_gem_ion_create_client(const char *name);
  65. void mtk_drm_gem_ion_destroy_client(struct ion_client *client);
  66. void mtk_drm_gem_ion_free_handle(struct ion_client *client,
  67. struct ion_handle *handle, const char *name, int line);
  68. struct ion_handle *mtk_drm_gem_ion_import_handle(struct ion_client *client,
  69. int fd);
  70. #endif
  71. struct drm_gem_object *
  72. mtk_gem_prime_import(struct drm_device *dev, struct dma_buf *dma_buf);
  73. struct sg_table *mtk_gem_prime_get_sg_table(struct drm_gem_object *obj);
  74. struct drm_gem_object *
  75. mtk_gem_prime_import_sg_table(struct drm_device *dev,
  76. struct dma_buf_attachment *attach,
  77. struct sg_table *sg);
  78. /*
  79. * request gem object creation and buffer allocation as the size
  80. * that it is calculated with framebuffer information such as width,
  81. * height and bpp.
  82. */
  83. int mtk_gem_create_ioctl(struct drm_device *dev, void *data,
  84. struct drm_file *file_priv);
  85. /* get buffer offset to map to user space. */
  86. int mtk_gem_map_offset_ioctl(struct drm_device *dev, void *data,
  87. struct drm_file *file_priv);
  88. /* submit buffer and return fence */
  89. int mtk_gem_submit_ioctl(struct drm_device *dev, void *data,
  90. struct drm_file *file_priv);
  91. int mtk_drm_sec_hnd_to_gem_hnd(struct drm_device *dev, void *data,
  92. struct drm_file *file_priv);
  93. struct mtk_drm_gem_obj *mtk_drm_fb_gem_insert(struct drm_device *dev,
  94. size_t size, phys_addr_t fb_base,
  95. unsigned int vramsize);
  96. void mtk_drm_fb_gem_release(struct drm_device *dev);
  97. #endif