Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / gpu / drm / etnaviv / etnaviv_gem.h
blob98e60df882b688bf16edfff1930f26553e353748
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Copyright (C) 2015-2018 Etnaviv Project
4 */
6 #ifndef __ETNAVIV_GEM_H__
7 #define __ETNAVIV_GEM_H__
9 #include <linux/dma-resv.h>
10 #include "etnaviv_cmdbuf.h"
11 #include "etnaviv_drv.h"
13 struct dma_fence;
14 struct etnaviv_gem_ops;
15 struct etnaviv_gem_object;
17 struct etnaviv_gem_userptr {
18 uintptr_t ptr;
19 struct mm_struct *mm;
20 bool ro;
23 struct etnaviv_vram_mapping {
24 struct list_head obj_node;
25 struct list_head scan_node;
26 struct list_head mmu_node;
27 struct etnaviv_gem_object *object;
28 struct etnaviv_iommu_context *context;
29 struct drm_mm_node vram_node;
30 unsigned int use;
31 u32 iova;
34 struct etnaviv_gem_object {
35 struct drm_gem_object base;
36 const struct etnaviv_gem_ops *ops;
37 struct mutex lock;
39 u32 flags;
41 struct list_head gem_node;
42 struct etnaviv_gpu *gpu; /* non-null if active */
43 atomic_t gpu_active;
44 u32 access;
46 struct page **pages;
47 struct sg_table *sgt;
48 void *vaddr;
50 struct list_head vram_list;
52 /* cache maintenance */
53 u32 last_cpu_prep_op;
55 struct etnaviv_gem_userptr userptr;
58 static inline
59 struct etnaviv_gem_object *to_etnaviv_bo(struct drm_gem_object *obj)
61 return container_of(obj, struct etnaviv_gem_object, base);
64 struct etnaviv_gem_ops {
65 int (*get_pages)(struct etnaviv_gem_object *);
66 void (*release)(struct etnaviv_gem_object *);
67 void *(*vmap)(struct etnaviv_gem_object *);
68 int (*mmap)(struct etnaviv_gem_object *, struct vm_area_struct *);
71 static inline bool is_active(struct etnaviv_gem_object *etnaviv_obj)
73 return atomic_read(&etnaviv_obj->gpu_active) != 0;
76 #define MAX_CMDS 4
78 struct etnaviv_gem_submit_bo {
79 u32 flags;
80 u64 va;
81 struct etnaviv_gem_object *obj;
82 struct etnaviv_vram_mapping *mapping;
83 struct dma_fence *excl;
84 unsigned int nr_shared;
85 struct dma_fence **shared;
88 /* Created per submit-ioctl, to track bo's and cmdstream bufs, etc,
89 * associated with the cmdstream submission for synchronization (and
90 * make it easier to unwind when things go wrong, etc).
92 struct etnaviv_gem_submit {
93 struct drm_sched_job sched_job;
94 struct kref refcount;
95 struct etnaviv_file_private *ctx;
96 struct etnaviv_gpu *gpu;
97 struct etnaviv_iommu_context *mmu_context, *prev_mmu_context;
98 struct dma_fence *out_fence, *in_fence;
99 int out_fence_id;
100 struct list_head node; /* GPU active submit list */
101 struct etnaviv_cmdbuf cmdbuf;
102 bool runtime_resumed;
103 u32 exec_state;
104 u32 flags;
105 unsigned int nr_pmrs;
106 struct etnaviv_perfmon_request *pmrs;
107 unsigned int nr_bos;
108 struct etnaviv_gem_submit_bo bos[];
109 /* No new members here, the previous one is variable-length! */
112 void etnaviv_submit_put(struct etnaviv_gem_submit * submit);
114 int etnaviv_gem_wait_bo(struct etnaviv_gpu *gpu, struct drm_gem_object *obj,
115 struct drm_etnaviv_timespec *timeout);
116 int etnaviv_gem_new_private(struct drm_device *dev, size_t size, u32 flags,
117 const struct etnaviv_gem_ops *ops, struct etnaviv_gem_object **res);
118 void etnaviv_gem_obj_add(struct drm_device *dev, struct drm_gem_object *obj);
119 struct page **etnaviv_gem_get_pages(struct etnaviv_gem_object *obj);
120 void etnaviv_gem_put_pages(struct etnaviv_gem_object *obj);
122 struct etnaviv_vram_mapping *etnaviv_gem_mapping_get(
123 struct drm_gem_object *obj, struct etnaviv_iommu_context *mmu_context,
124 u64 va);
125 void etnaviv_gem_mapping_unreference(struct etnaviv_vram_mapping *mapping);
127 #endif /* __ETNAVIV_GEM_H__ */