gem.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Tegra host1x GEM implementation
  4. *
  5. * Copyright (c) 2012-2013, NVIDIA Corporation.
  6. */
  7. #ifndef __HOST1X_GEM_H
  8. #define __HOST1X_GEM_H
  9. #include <linux/host1x.h>
  10. #include <drm/drm.h>
  11. #include <drm/drm_gem.h>
  12. #define TEGRA_BO_BOTTOM_UP (1 << 0)
  13. enum tegra_bo_tiling_mode {
  14. TEGRA_BO_TILING_MODE_PITCH,
  15. TEGRA_BO_TILING_MODE_TILED,
  16. TEGRA_BO_TILING_MODE_BLOCK,
  17. };
  18. enum tegra_bo_sector_layout {
  19. TEGRA_BO_SECTOR_LAYOUT_TEGRA,
  20. TEGRA_BO_SECTOR_LAYOUT_GPU,
  21. };
  22. struct tegra_bo_tiling {
  23. enum tegra_bo_tiling_mode mode;
  24. unsigned long value;
  25. enum tegra_bo_sector_layout sector_layout;
  26. };
  27. /*
  28. * How memory is referenced within a tegra_bo:
  29. *
  30. * Buffer source | Mapping API(*) | Fields
  31. * ---------------+-----------------+---------------
  32. * Allocated here | DMA API | iova (IOVA mapped to drm->dev), vaddr (CPU VA)
  33. *
  34. * Allocated here | IOMMU API | pages/num_pages (Phys. memory), sgt (Mapped to drm->dev),
  35. * | iova/size (Mapped to domain)
  36. *
  37. * Imported | DMA API | dma_buf (Imported dma_buf)
  38. *
  39. * Imported | IOMMU API | dma_buf (Imported dma_buf),
  40. * | gem->import_attach (Attachment on drm->dev),
  41. * | sgt (Mapped to drm->dev)
  42. * | iova/size (Mapped to domain)
  43. *
  44. * (*) If tegra->domain is set, i.e. TegraDRM IOMMU domain is directly managed through IOMMU API,
  45. * this is IOMMU API. Otherwise DMA API.
  46. */
  47. struct tegra_bo {
  48. struct drm_gem_object gem;
  49. struct host1x_bo base;
  50. unsigned long flags;
  51. struct sg_table *sgt;
  52. dma_addr_t iova;
  53. void *vaddr;
  54. struct dma_buf *dma_buf;
  55. struct drm_mm_node *mm;
  56. unsigned long num_pages;
  57. struct page **pages;
  58. /* size of IOMMU mapping */
  59. size_t size;
  60. struct tegra_bo_tiling tiling;
  61. };
  62. static inline struct tegra_bo *to_tegra_bo(struct drm_gem_object *gem)
  63. {
  64. return container_of(gem, struct tegra_bo, gem);
  65. }
  66. static inline struct tegra_bo *host1x_to_tegra_bo(struct host1x_bo *bo)
  67. {
  68. return container_of(bo, struct tegra_bo, base);
  69. }
  70. struct tegra_bo *tegra_bo_create(struct drm_device *drm, size_t size,
  71. unsigned long flags);
  72. struct tegra_bo *tegra_bo_create_with_handle(struct drm_file *file,
  73. struct drm_device *drm,
  74. size_t size,
  75. unsigned long flags,
  76. u32 *handle);
  77. void tegra_bo_free_object(struct drm_gem_object *gem);
  78. int tegra_bo_dumb_create(struct drm_file *file, struct drm_device *drm,
  79. struct drm_mode_create_dumb *args);
  80. extern const struct vm_operations_struct tegra_bo_vm_ops;
  81. int __tegra_gem_mmap(struct drm_gem_object *gem, struct vm_area_struct *vma);
  82. int tegra_drm_mmap(struct file *file, struct vm_area_struct *vma);
  83. struct dma_buf *tegra_gem_prime_export(struct drm_gem_object *gem,
  84. int flags);
  85. struct drm_gem_object *tegra_gem_prime_import(struct drm_device *drm,
  86. struct dma_buf *buf);
  87. struct host1x_bo *tegra_gem_lookup(struct drm_file *file, u32 handle);
  88. #endif