xref: /openbmc/linux/drivers/gpu/drm/tegra/gem.h (revision 7a2eb736)
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/drmP.h>
15 #include <drm/drm_gem.h>
16 
17 #define TEGRA_BO_BOTTOM_UP (1 << 0)
18 
19 enum tegra_bo_tiling_mode {
20 	TEGRA_BO_TILING_MODE_PITCH,
21 	TEGRA_BO_TILING_MODE_TILED,
22 	TEGRA_BO_TILING_MODE_BLOCK,
23 };
24 
25 struct tegra_bo_tiling {
26 	enum tegra_bo_tiling_mode mode;
27 	unsigned long value;
28 };
29 
30 struct tegra_bo {
31 	struct drm_gem_object gem;
32 	struct host1x_bo base;
33 	unsigned long flags;
34 	struct sg_table *sgt;
35 	dma_addr_t paddr;
36 	void *vaddr;
37 
38 	struct drm_mm_node *mm;
39 	unsigned long num_pages;
40 	struct page **pages;
41 	/* size of IOMMU mapping */
42 	size_t size;
43 
44 	struct tegra_bo_tiling tiling;
45 };
46 
47 static inline struct tegra_bo *to_tegra_bo(struct drm_gem_object *gem)
48 {
49 	return container_of(gem, struct tegra_bo, gem);
50 }
51 
52 static inline struct tegra_bo *host1x_to_tegra_bo(struct host1x_bo *bo)
53 {
54 	return container_of(bo, struct tegra_bo, base);
55 }
56 
57 struct tegra_bo *tegra_bo_create(struct drm_device *drm, size_t size,
58 				 unsigned long flags);
59 struct tegra_bo *tegra_bo_create_with_handle(struct drm_file *file,
60 					     struct drm_device *drm,
61 					     size_t size,
62 					     unsigned long flags,
63 					     u32 *handle);
64 void tegra_bo_free_object(struct drm_gem_object *gem);
65 int tegra_bo_dumb_create(struct drm_file *file, struct drm_device *drm,
66 			 struct drm_mode_create_dumb *args);
67 
68 extern const struct vm_operations_struct tegra_bo_vm_ops;
69 
70 int __tegra_gem_mmap(struct drm_gem_object *gem, struct vm_area_struct *vma);
71 int tegra_drm_mmap(struct file *file, struct vm_area_struct *vma);
72 
73 struct dma_buf *tegra_gem_prime_export(struct drm_device *drm,
74 				       struct drm_gem_object *gem,
75 				       int flags);
76 struct drm_gem_object *tegra_gem_prime_import(struct drm_device *drm,
77 					      struct dma_buf *buf);
78 
79 #endif
80