1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2dee8268fSThierry Reding /* 3dee8268fSThierry Reding * Tegra host1x GEM implementation 4dee8268fSThierry Reding * 5dee8268fSThierry Reding * Copyright (c) 2012-2013, NVIDIA Corporation. 6dee8268fSThierry Reding */ 7dee8268fSThierry Reding 8dee8268fSThierry Reding #ifndef __HOST1X_GEM_H 9dee8268fSThierry Reding #define __HOST1X_GEM_H 10dee8268fSThierry Reding 11dee8268fSThierry Reding #include <linux/host1x.h> 12dee8268fSThierry Reding 13dee8268fSThierry Reding #include <drm/drm.h> 14d9fc9413SDaniel Vetter #include <drm/drm_gem.h> 15dee8268fSThierry Reding 16c134f019SThierry Reding #define TEGRA_BO_BOTTOM_UP (1 << 0) 17c134f019SThierry Reding 18c134f019SThierry Reding enum tegra_bo_tiling_mode { 19c134f019SThierry Reding TEGRA_BO_TILING_MODE_PITCH, 20c134f019SThierry Reding TEGRA_BO_TILING_MODE_TILED, 21c134f019SThierry Reding TEGRA_BO_TILING_MODE_BLOCK, 22c134f019SThierry Reding }; 23c134f019SThierry Reding 24*7b6f8467SThierry Reding enum tegra_bo_sector_layout { 25*7b6f8467SThierry Reding TEGRA_BO_SECTOR_LAYOUT_TEGRA, 26*7b6f8467SThierry Reding TEGRA_BO_SECTOR_LAYOUT_GPU, 27*7b6f8467SThierry Reding }; 28*7b6f8467SThierry Reding 29c134f019SThierry Reding struct tegra_bo_tiling { 30c134f019SThierry Reding enum tegra_bo_tiling_mode mode; 31c134f019SThierry Reding unsigned long value; 32*7b6f8467SThierry Reding enum tegra_bo_sector_layout sector_layout; 33c134f019SThierry Reding }; 34773af77fSThierry Reding 35dee8268fSThierry Reding struct tegra_bo { 36dee8268fSThierry Reding struct drm_gem_object gem; 37dee8268fSThierry Reding struct host1x_bo base; 38773af77fSThierry Reding unsigned long flags; 393800391dSThierry Reding struct sg_table *sgt; 407e3c53a0SThierry Reding dma_addr_t iova; 41dee8268fSThierry Reding void *vaddr; 42c134f019SThierry Reding 43df06b759SThierry Reding struct drm_mm_node *mm; 44df06b759SThierry Reding unsigned long num_pages; 45df06b759SThierry Reding struct page **pages; 46df06b759SThierry Reding /* size of IOMMU mapping */ 47df06b759SThierry Reding size_t size; 48df06b759SThierry Reding 49c134f019SThierry Reding struct tegra_bo_tiling tiling; 50dee8268fSThierry Reding }; 51dee8268fSThierry Reding 52dee8268fSThierry Reding static inline struct tegra_bo *to_tegra_bo(struct drm_gem_object *gem) 53dee8268fSThierry Reding { 54dee8268fSThierry Reding return container_of(gem, struct tegra_bo, gem); 55dee8268fSThierry Reding } 56dee8268fSThierry Reding 57368f622cSDmitry Osipenko static inline struct tegra_bo *host1x_to_tegra_bo(struct host1x_bo *bo) 58368f622cSDmitry Osipenko { 59368f622cSDmitry Osipenko return container_of(bo, struct tegra_bo, base); 60368f622cSDmitry Osipenko } 61368f622cSDmitry Osipenko 6271c38629SThierry Reding struct tegra_bo *tegra_bo_create(struct drm_device *drm, size_t size, 63773af77fSThierry Reding unsigned long flags); 64dee8268fSThierry Reding struct tegra_bo *tegra_bo_create_with_handle(struct drm_file *file, 65dee8268fSThierry Reding struct drm_device *drm, 6671c38629SThierry Reding size_t size, 67773af77fSThierry Reding unsigned long flags, 6871c38629SThierry Reding u32 *handle); 69dee8268fSThierry Reding void tegra_bo_free_object(struct drm_gem_object *gem); 70dee8268fSThierry Reding int tegra_bo_dumb_create(struct drm_file *file, struct drm_device *drm, 71dee8268fSThierry Reding struct drm_mode_create_dumb *args); 72dee8268fSThierry Reding 73dee8268fSThierry Reding extern const struct vm_operations_struct tegra_bo_vm_ops; 74dee8268fSThierry Reding 7504c07466SThierry Reding int __tegra_gem_mmap(struct drm_gem_object *gem, struct vm_area_struct *vma); 76b6d7974dSThierry Reding int tegra_drm_mmap(struct file *file, struct vm_area_struct *vma); 77b6d7974dSThierry Reding 78e4fa8457SDaniel Vetter struct dma_buf *tegra_gem_prime_export(struct drm_gem_object *gem, 793800391dSThierry Reding int flags); 803800391dSThierry Reding struct drm_gem_object *tegra_gem_prime_import(struct drm_device *drm, 813800391dSThierry Reding struct dma_buf *buf); 823800391dSThierry Reding 83dee8268fSThierry Reding #endif 84