xref: /linux/drivers/gpu/drm/tegra/gem.h (revision df06b759f2cf4690fa9991edb1504ba39932b2bb)
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 
41*df06b759SThierry Reding 	struct drm_mm_node *mm;
42*df06b759SThierry Reding 	unsigned long num_pages;
43*df06b759SThierry Reding 	struct page **pages;
44*df06b759SThierry Reding 	/* size of IOMMU mapping */
45*df06b759SThierry Reding 	size_t size;
46*df06b759SThierry 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 
55773af77fSThierry Reding struct tegra_bo *tegra_bo_create(struct drm_device *drm, unsigned int size,
56773af77fSThierry Reding 				 unsigned long flags);
57dee8268fSThierry Reding struct tegra_bo *tegra_bo_create_with_handle(struct drm_file *file,
58dee8268fSThierry Reding 					     struct drm_device *drm,
59dee8268fSThierry Reding 					     unsigned int size,
60773af77fSThierry Reding 					     unsigned long flags,
61dee8268fSThierry Reding 					     unsigned int *handle);
62dee8268fSThierry Reding void tegra_bo_free_object(struct drm_gem_object *gem);
63dee8268fSThierry Reding int tegra_bo_dumb_create(struct drm_file *file, struct drm_device *drm,
64dee8268fSThierry Reding 			 struct drm_mode_create_dumb *args);
65dee8268fSThierry Reding int tegra_bo_dumb_map_offset(struct drm_file *file, struct drm_device *drm,
66dee8268fSThierry Reding 			     uint32_t handle, uint64_t *offset);
67dee8268fSThierry Reding 
68dee8268fSThierry Reding int tegra_drm_mmap(struct file *file, struct vm_area_struct *vma);
69dee8268fSThierry Reding 
70dee8268fSThierry Reding extern const struct vm_operations_struct tegra_bo_vm_ops;
71dee8268fSThierry Reding 
723800391dSThierry Reding struct dma_buf *tegra_gem_prime_export(struct drm_device *drm,
733800391dSThierry Reding 				       struct drm_gem_object *gem,
743800391dSThierry Reding 				       int flags);
753800391dSThierry Reding struct drm_gem_object *tegra_gem_prime_import(struct drm_device *drm,
763800391dSThierry Reding 					      struct dma_buf *buf);
773800391dSThierry Reding 
78dee8268fSThierry Reding #endif
79