• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 struct tegra_bo {
36 	struct drm_gem_object gem;
37 	struct host1x_bo base;
38 	unsigned long flags;
39 	struct sg_table *sgt;
40 	dma_addr_t iova;
41 	void *vaddr;
42 
43 	struct drm_mm_node *mm;
44 	unsigned long num_pages;
45 	struct page **pages;
46 	/* size of IOMMU mapping */
47 	size_t size;
48 
49 	struct tegra_bo_tiling tiling;
50 };
51 
to_tegra_bo(struct drm_gem_object * gem)52 static inline struct tegra_bo *to_tegra_bo(struct drm_gem_object *gem)
53 {
54 	return container_of(gem, struct tegra_bo, gem);
55 }
56 
host1x_to_tegra_bo(struct host1x_bo * bo)57 static inline struct tegra_bo *host1x_to_tegra_bo(struct host1x_bo *bo)
58 {
59 	return container_of(bo, struct tegra_bo, base);
60 }
61 
62 struct tegra_bo *tegra_bo_create(struct drm_device *drm, size_t size,
63 				 unsigned long flags);
64 struct tegra_bo *tegra_bo_create_with_handle(struct drm_file *file,
65 					     struct drm_device *drm,
66 					     size_t size,
67 					     unsigned long flags,
68 					     u32 *handle);
69 void tegra_bo_free_object(struct drm_gem_object *gem);
70 int tegra_bo_dumb_create(struct drm_file *file, struct drm_device *drm,
71 			 struct drm_mode_create_dumb *args);
72 
73 extern const struct vm_operations_struct tegra_bo_vm_ops;
74 
75 int __tegra_gem_mmap(struct drm_gem_object *gem, struct vm_area_struct *vma);
76 int tegra_drm_mmap(struct file *file, struct vm_area_struct *vma);
77 
78 struct dma_buf *tegra_gem_prime_export(struct drm_gem_object *gem,
79 				       int flags);
80 struct drm_gem_object *tegra_gem_prime_import(struct drm_device *drm,
81 					      struct dma_buf *buf);
82 
83 struct host1x_bo *tegra_gem_lookup(struct drm_file *file, u32 handle);
84 
85 #endif
86