1dee8268fSThierry Reding /* 2dee8268fSThierry Reding * Tegra host1x GEM implementation 3dee8268fSThierry Reding * 4dee8268fSThierry Reding * Copyright (c) 2012-2013, NVIDIA Corporation. 5dee8268fSThierry Reding * 69a2ac2dcSThierry Reding * This program is free software; you can redistribute it and/or modify 79a2ac2dcSThierry Reding * it under the terms of the GNU General Public License version 2 as 89a2ac2dcSThierry Reding * published by the Free Software Foundation. 9dee8268fSThierry Reding */ 10dee8268fSThierry Reding 11dee8268fSThierry Reding #ifndef __HOST1X_GEM_H 12dee8268fSThierry Reding #define __HOST1X_GEM_H 13dee8268fSThierry Reding 14dee8268fSThierry Reding #include <linux/host1x.h> 15dee8268fSThierry Reding 16dee8268fSThierry Reding #include <drm/drm.h> 17dee8268fSThierry Reding #include <drm/drmP.h> 18d9fc9413SDaniel Vetter #include <drm/drm_gem.h> 19dee8268fSThierry Reding 20c134f019SThierry Reding #define TEGRA_BO_BOTTOM_UP (1 << 0) 21c134f019SThierry Reding 22c134f019SThierry Reding enum tegra_bo_tiling_mode { 23c134f019SThierry Reding TEGRA_BO_TILING_MODE_PITCH, 24c134f019SThierry Reding TEGRA_BO_TILING_MODE_TILED, 25c134f019SThierry Reding TEGRA_BO_TILING_MODE_BLOCK, 26c134f019SThierry Reding }; 27c134f019SThierry Reding 28c134f019SThierry Reding struct tegra_bo_tiling { 29c134f019SThierry Reding enum tegra_bo_tiling_mode mode; 30c134f019SThierry Reding unsigned long value; 31c134f019SThierry Reding }; 32773af77fSThierry Reding 33dee8268fSThierry Reding struct tegra_bo { 34dee8268fSThierry Reding struct drm_gem_object gem; 35dee8268fSThierry Reding struct host1x_bo base; 36773af77fSThierry Reding unsigned long flags; 373800391dSThierry Reding struct sg_table *sgt; 38dee8268fSThierry Reding dma_addr_t paddr; 39dee8268fSThierry Reding void *vaddr; 40c134f019SThierry Reding 41df06b759SThierry Reding struct drm_mm_node *mm; 42df06b759SThierry Reding unsigned long num_pages; 43df06b759SThierry Reding struct page **pages; 44df06b759SThierry Reding /* size of IOMMU mapping */ 45df06b759SThierry Reding size_t size; 46df06b759SThierry Reding 47c134f019SThierry Reding struct tegra_bo_tiling tiling; 48dee8268fSThierry Reding }; 49dee8268fSThierry Reding 50dee8268fSThierry Reding static inline struct tegra_bo *to_tegra_bo(struct drm_gem_object *gem) 51dee8268fSThierry Reding { 52dee8268fSThierry Reding return container_of(gem, struct tegra_bo, gem); 53dee8268fSThierry Reding } 54dee8268fSThierry Reding 55368f622cSDmitry Osipenko static inline struct tegra_bo *host1x_to_tegra_bo(struct host1x_bo *bo) 56368f622cSDmitry Osipenko { 57368f622cSDmitry Osipenko return container_of(bo, struct tegra_bo, base); 58368f622cSDmitry Osipenko } 59368f622cSDmitry Osipenko 6071c38629SThierry Reding struct tegra_bo *tegra_bo_create(struct drm_device *drm, size_t size, 61773af77fSThierry Reding unsigned long flags); 62dee8268fSThierry Reding struct tegra_bo *tegra_bo_create_with_handle(struct drm_file *file, 63dee8268fSThierry Reding struct drm_device *drm, 6471c38629SThierry Reding size_t size, 65773af77fSThierry Reding unsigned long flags, 6671c38629SThierry Reding u32 *handle); 67dee8268fSThierry Reding void tegra_bo_free_object(struct drm_gem_object *gem); 68dee8268fSThierry Reding int tegra_bo_dumb_create(struct drm_file *file, struct drm_device *drm, 69dee8268fSThierry Reding struct drm_mode_create_dumb *args); 70dee8268fSThierry Reding 71dee8268fSThierry Reding extern const struct vm_operations_struct tegra_bo_vm_ops; 72dee8268fSThierry Reding 73*04c07466SThierry Reding int __tegra_gem_mmap(struct drm_gem_object *gem, struct vm_area_struct *vma); 74b6d7974dSThierry Reding int tegra_drm_mmap(struct file *file, struct vm_area_struct *vma); 75b6d7974dSThierry Reding 763800391dSThierry Reding struct dma_buf *tegra_gem_prime_export(struct drm_device *drm, 773800391dSThierry Reding struct drm_gem_object *gem, 783800391dSThierry Reding int flags); 793800391dSThierry Reding struct drm_gem_object *tegra_gem_prime_import(struct drm_device *drm, 803800391dSThierry Reding struct dma_buf *buf); 813800391dSThierry Reding 82dee8268fSThierry Reding #endif 83