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