Linux Audio

Check our new training course

Loading...
v6.13.7
  1/* SPDX-License-Identifier: GPL-2.0-only */
  2/*
  3 * Copyright (C) 2013 Red Hat
  4 * Author: Rob Clark <robdclark@gmail.com>
  5 */
  6
  7#ifndef __MSM_GEM_H__
  8#define __MSM_GEM_H__
  9
 10#include <linux/kref.h>
 11#include <linux/dma-resv.h>
 12#include "drm/drm_exec.h"
 13#include "drm/gpu_scheduler.h"
 14#include "msm_drv.h"
 15
 16/* Make all GEM related WARN_ON()s ratelimited.. when things go wrong they
 17 * tend to go wrong 1000s of times in a short timespan.
 18 */
 19#define GEM_WARN_ON(x)  WARN_RATELIMIT(x, "%s", __stringify(x))
 20
 21/* Additional internal-use only BO flags: */
 22#define MSM_BO_STOLEN        0x10000000    /* try to use stolen/splash memory */
 23#define MSM_BO_MAP_PRIV      0x20000000    /* use IOMMU_PRIV when mapping */
 24
 25struct msm_gem_address_space {
 26	const char *name;
 27	/* NOTE: mm managed at the page level, size is in # of pages
 28	 * and position mm_node->start is in # of pages:
 29	 */
 30	struct drm_mm mm;
 31	spinlock_t lock; /* Protects drm_mm node allocation/removal */
 32	struct msm_mmu *mmu;
 33	struct kref kref;
 34
 35	/* For address spaces associated with a specific process, this
 36	 * will be non-NULL:
 37	 */
 38	struct pid *pid;
 39
 40	/* @faults: the number of GPU hangs associated with this address space */
 41	int faults;
 42
 43	/** @va_start: lowest possible address to allocate */
 44	uint64_t va_start;
 45
 46	/** @va_size: the size of the address space (in bytes) */
 47	uint64_t va_size;
 48};
 49
 50struct msm_gem_address_space *
 51msm_gem_address_space_get(struct msm_gem_address_space *aspace);
 52
 53void msm_gem_address_space_put(struct msm_gem_address_space *aspace);
 54
 55struct msm_gem_address_space *
 56msm_gem_address_space_create(struct msm_mmu *mmu, const char *name,
 57		u64 va_start, u64 size);
 58
 59struct msm_fence_context;
 60
 61struct msm_gem_vma {
 62	struct drm_mm_node node;
 63	uint64_t iova;
 64	struct msm_gem_address_space *aspace;
 65	struct list_head list;    /* node in msm_gem_object::vmas */
 66	bool mapped;
 
 
 
 
 67};
 68
 69struct msm_gem_vma *msm_gem_vma_new(struct msm_gem_address_space *aspace);
 70int msm_gem_vma_init(struct msm_gem_vma *vma, int size,
 71		u64 range_start, u64 range_end);
 72void msm_gem_vma_purge(struct msm_gem_vma *vma);
 73int msm_gem_vma_map(struct msm_gem_vma *vma, int prot, struct sg_table *sgt, int size);
 74void msm_gem_vma_close(struct msm_gem_vma *vma);
 
 
 
 
 
 
 
 75
 76struct msm_gem_object {
 77	struct drm_gem_object base;
 78
 79	uint32_t flags;
 80
 81	/**
 82	 * madv: are the backing pages purgeable?
 83	 *
 84	 * Protected by obj lock and LRU lock
 85	 */
 86	uint8_t madv;
 87
 88	/**
 89	 * count of active vmap'ing
 90	 */
 91	uint8_t vmap_count;
 92
 93	/**
 94	 * Node in list of all objects (mainly for debugfs, protected by
 95	 * priv->obj_lock
 96	 */
 97	struct list_head node;
 98
 99	struct page **pages;
100	struct sg_table *sgt;
101	void *vaddr;
102
103	struct list_head vmas;    /* list of msm_gem_vma */
104
105	/* For physically contiguous buffers.  Used when we don't have
106	 * an IOMMU.  Also used for stolen/splashscreen buffer.
107	 */
108	struct drm_mm_node *vram_node;
109
110	char name[32]; /* Identifier to print for the debugfs files */
111
112	/* userspace metadata backchannel */
113	void *metadata;
114	u32 metadata_size;
115
116	/**
117	 * pin_count: Number of times the pages are pinned
118	 *
119	 * Protected by LRU lock.
120	 */
121	int pin_count;
122};
123#define to_msm_bo(x) container_of(x, struct msm_gem_object, base)
124
125uint64_t msm_gem_mmap_offset(struct drm_gem_object *obj);
126int msm_gem_pin_vma_locked(struct drm_gem_object *obj, struct msm_gem_vma *vma);
127void msm_gem_unpin_locked(struct drm_gem_object *obj);
128void msm_gem_unpin_active(struct drm_gem_object *obj);
129struct msm_gem_vma *msm_gem_get_vma_locked(struct drm_gem_object *obj,
130					   struct msm_gem_address_space *aspace);
131int msm_gem_get_iova(struct drm_gem_object *obj,
132		struct msm_gem_address_space *aspace, uint64_t *iova);
133int msm_gem_set_iova(struct drm_gem_object *obj,
134		struct msm_gem_address_space *aspace, uint64_t iova);
135int msm_gem_get_and_pin_iova_range(struct drm_gem_object *obj,
136		struct msm_gem_address_space *aspace, uint64_t *iova,
137		u64 range_start, u64 range_end);
138int msm_gem_get_and_pin_iova(struct drm_gem_object *obj,
139		struct msm_gem_address_space *aspace, uint64_t *iova);
140void msm_gem_unpin_iova(struct drm_gem_object *obj,
141		struct msm_gem_address_space *aspace);
142void msm_gem_pin_obj_locked(struct drm_gem_object *obj);
143struct page **msm_gem_pin_pages_locked(struct drm_gem_object *obj);
144void msm_gem_unpin_pages_locked(struct drm_gem_object *obj);
145int msm_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
146		struct drm_mode_create_dumb *args);
147int msm_gem_dumb_map_offset(struct drm_file *file, struct drm_device *dev,
148		uint32_t handle, uint64_t *offset);
149void *msm_gem_get_vaddr_locked(struct drm_gem_object *obj);
150void *msm_gem_get_vaddr(struct drm_gem_object *obj);
151void *msm_gem_get_vaddr_active(struct drm_gem_object *obj);
152void msm_gem_put_vaddr_locked(struct drm_gem_object *obj);
153void msm_gem_put_vaddr(struct drm_gem_object *obj);
154int msm_gem_madvise(struct drm_gem_object *obj, unsigned madv);
155bool msm_gem_active(struct drm_gem_object *obj);
156int msm_gem_cpu_prep(struct drm_gem_object *obj, uint32_t op, ktime_t *timeout);
157int msm_gem_cpu_fini(struct drm_gem_object *obj);
158int msm_gem_new_handle(struct drm_device *dev, struct drm_file *file,
159		uint32_t size, uint32_t flags, uint32_t *handle, char *name);
160struct drm_gem_object *msm_gem_new(struct drm_device *dev,
161		uint32_t size, uint32_t flags);
162void *msm_gem_kernel_new(struct drm_device *dev, uint32_t size,
163		uint32_t flags, struct msm_gem_address_space *aspace,
164		struct drm_gem_object **bo, uint64_t *iova);
165void msm_gem_kernel_put(struct drm_gem_object *bo,
166		struct msm_gem_address_space *aspace);
167struct drm_gem_object *msm_gem_import(struct drm_device *dev,
168		struct dma_buf *dmabuf, struct sg_table *sgt);
169__printf(2, 3)
170void msm_gem_object_set_name(struct drm_gem_object *bo, const char *fmt, ...);
171
172#ifdef CONFIG_DEBUG_FS
173struct msm_gem_stats {
174	struct {
175		unsigned count;
176		size_t size;
177	} all, active, resident, purgeable, purged;
178};
179
180void msm_gem_describe(struct drm_gem_object *obj, struct seq_file *m,
181		struct msm_gem_stats *stats);
182void msm_gem_describe_objects(struct list_head *list, struct seq_file *m);
183#endif
184
185static inline void
186msm_gem_lock(struct drm_gem_object *obj)
187{
188	dma_resv_lock(obj->resv, NULL);
189}
190
191static inline int
192msm_gem_lock_interruptible(struct drm_gem_object *obj)
193{
194	return dma_resv_lock_interruptible(obj->resv, NULL);
195}
196
197static inline void
198msm_gem_unlock(struct drm_gem_object *obj)
199{
200	dma_resv_unlock(obj->resv);
201}
202
203static inline void
204msm_gem_assert_locked(struct drm_gem_object *obj)
205{
206	/*
207	 * Destroying the object is a special case.. msm_gem_free_object()
208	 * calls many things that WARN_ON if the obj lock is not held.  But
209	 * acquiring the obj lock in msm_gem_free_object() can cause a
210	 * locking order inversion between reservation_ww_class_mutex and
211	 * fs_reclaim.
212	 *
213	 * This deadlock is not actually possible, because no one should
214	 * be already holding the lock when msm_gem_free_object() is called.
215	 * Unfortunately lockdep is not aware of this detail.  So when the
216	 * refcount drops to zero, we pretend it is already locked.
217	 */
218	lockdep_assert_once(
219		(kref_read(&obj->refcount) == 0) ||
220		(lockdep_is_held(&obj->resv->lock.base) != LOCK_STATE_NOT_HELD)
221	);
222}
223
224/* imported/exported objects are not purgeable: */
225static inline bool is_unpurgeable(struct msm_gem_object *msm_obj)
226{
227	return msm_obj->base.import_attach || msm_obj->pin_count;
228}
229
230static inline bool is_purgeable(struct msm_gem_object *msm_obj)
231{
232	return (msm_obj->madv == MSM_MADV_DONTNEED) && msm_obj->sgt &&
233			!is_unpurgeable(msm_obj);
234}
235
236static inline bool is_vunmapable(struct msm_gem_object *msm_obj)
237{
238	msm_gem_assert_locked(&msm_obj->base);
239	return (msm_obj->vmap_count == 0) && msm_obj->vaddr;
240}
241
242static inline bool is_unevictable(struct msm_gem_object *msm_obj)
243{
244	return is_unpurgeable(msm_obj) || msm_obj->vaddr;
245}
246
247void msm_gem_purge(struct drm_gem_object *obj);
248void msm_gem_evict(struct drm_gem_object *obj);
249void msm_gem_vunmap(struct drm_gem_object *obj);
250
251/* Created per submit-ioctl, to track bo's and cmdstream bufs, etc,
252 * associated with the cmdstream submission for synchronization (and
253 * make it easier to unwind when things go wrong, etc).
254 */
255struct msm_gem_submit {
256	struct drm_sched_job base;
257	struct kref ref;
258	struct drm_device *dev;
259	struct msm_gpu *gpu;
260	struct msm_gem_address_space *aspace;
261	struct list_head node;   /* node in ring submit list */
262	struct drm_exec exec;
263	uint32_t seqno;		/* Sequence number of the submit on the ring */
264
265	/* Hw fence, which is created when the scheduler executes the job, and
266	 * is signaled when the hw finishes (via seqno write from cmdstream)
267	 */
268	struct dma_fence *hw_fence;
269
270	/* Userspace visible fence, which is signaled by the scheduler after
271	 * the hw_fence is signaled.
272	 */
273	struct dma_fence *user_fence;
274
275	int fence_id;       /* key into queue->fence_idr */
276	struct msm_gpu_submitqueue *queue;
277	struct pid *pid;    /* submitting process */
278	bool bos_pinned : 1;
279	bool fault_dumped:1;/* Limit devcoredump dumping to one per submit */
280	bool in_rb : 1;     /* "sudo" mode, copy cmds into RB */
281	struct msm_ringbuffer *ring;
282	unsigned int nr_cmds;
283	unsigned int nr_bos;
284	u32 ident;	   /* A "identifier" for the submit for logging */
285	struct {
286		uint32_t type;
287		uint32_t size;  /* in dwords */
288		uint64_t iova;
289		uint32_t offset;/* in dwords */
290		uint32_t idx;   /* cmdstream buffer idx in bos[] */
291		uint32_t nr_relocs;
292		struct drm_msm_gem_submit_reloc *relocs;
293	} *cmd;  /* array of size nr_cmds */
294	struct {
 
 
 
 
 
295		uint32_t flags;
296		union {
297			struct drm_gem_object *obj;
298			uint32_t handle;
299		};
300		uint64_t iova;
 
301	} bos[];
302};
303
304static inline struct msm_gem_submit *to_msm_submit(struct drm_sched_job *job)
305{
306	return container_of(job, struct msm_gem_submit, base);
307}
308
309void __msm_gem_submit_destroy(struct kref *kref);
310
311static inline void msm_gem_submit_get(struct msm_gem_submit *submit)
312{
313	kref_get(&submit->ref);
314}
315
316static inline void msm_gem_submit_put(struct msm_gem_submit *submit)
317{
318	kref_put(&submit->ref, __msm_gem_submit_destroy);
319}
320
321void msm_submit_retire(struct msm_gem_submit *submit);
322
323/* helper to determine of a buffer in submit should be dumped, used for both
324 * devcoredump and debugfs cmdstream dumping:
325 */
326static inline bool
327should_dump(struct msm_gem_submit *submit, int idx)
328{
329	extern bool rd_full;
330	return rd_full || (submit->bos[idx].flags & MSM_SUBMIT_BO_DUMP);
331}
332
333#endif /* __MSM_GEM_H__ */
v6.2
  1/* SPDX-License-Identifier: GPL-2.0-only */
  2/*
  3 * Copyright (C) 2013 Red Hat
  4 * Author: Rob Clark <robdclark@gmail.com>
  5 */
  6
  7#ifndef __MSM_GEM_H__
  8#define __MSM_GEM_H__
  9
 10#include <linux/kref.h>
 11#include <linux/dma-resv.h>
 
 12#include "drm/gpu_scheduler.h"
 13#include "msm_drv.h"
 14
 15/* Make all GEM related WARN_ON()s ratelimited.. when things go wrong they
 16 * tend to go wrong 1000s of times in a short timespan.
 17 */
 18#define GEM_WARN_ON(x)  WARN_RATELIMIT(x, "%s", __stringify(x))
 19
 20/* Additional internal-use only BO flags: */
 21#define MSM_BO_STOLEN        0x10000000    /* try to use stolen/splash memory */
 22#define MSM_BO_MAP_PRIV      0x20000000    /* use IOMMU_PRIV when mapping */
 23
 24struct msm_gem_address_space {
 25	const char *name;
 26	/* NOTE: mm managed at the page level, size is in # of pages
 27	 * and position mm_node->start is in # of pages:
 28	 */
 29	struct drm_mm mm;
 30	spinlock_t lock; /* Protects drm_mm node allocation/removal */
 31	struct msm_mmu *mmu;
 32	struct kref kref;
 33
 34	/* For address spaces associated with a specific process, this
 35	 * will be non-NULL:
 36	 */
 37	struct pid *pid;
 38
 39	/* @faults: the number of GPU hangs associated with this address space */
 40	int faults;
 41
 42	/** @va_start: lowest possible address to allocate */
 43	uint64_t va_start;
 44
 45	/** @va_size: the size of the address space (in bytes) */
 46	uint64_t va_size;
 47};
 48
 49struct msm_gem_address_space *
 50msm_gem_address_space_get(struct msm_gem_address_space *aspace);
 51
 52void msm_gem_address_space_put(struct msm_gem_address_space *aspace);
 53
 54struct msm_gem_address_space *
 55msm_gem_address_space_create(struct msm_mmu *mmu, const char *name,
 56		u64 va_start, u64 size);
 57
 58struct msm_fence_context;
 59
 60struct msm_gem_vma {
 61	struct drm_mm_node node;
 62	uint64_t iova;
 63	struct msm_gem_address_space *aspace;
 64	struct list_head list;    /* node in msm_gem_object::vmas */
 65	bool mapped;
 66	int inuse;
 67	uint32_t fence_mask;
 68	uint32_t fence[MSM_GPU_MAX_RINGS];
 69	struct msm_fence_context *fctx[MSM_GPU_MAX_RINGS];
 70};
 71
 72int msm_gem_init_vma(struct msm_gem_address_space *aspace,
 73		struct msm_gem_vma *vma, int size,
 74		u64 range_start, u64 range_end);
 75bool msm_gem_vma_inuse(struct msm_gem_vma *vma);
 76void msm_gem_purge_vma(struct msm_gem_address_space *aspace,
 77		struct msm_gem_vma *vma);
 78void msm_gem_unpin_vma(struct msm_gem_vma *vma);
 79void msm_gem_unpin_vma_fenced(struct msm_gem_vma *vma, struct msm_fence_context *fctx);
 80int msm_gem_map_vma(struct msm_gem_address_space *aspace,
 81		struct msm_gem_vma *vma, int prot,
 82		struct sg_table *sgt, int size);
 83void msm_gem_close_vma(struct msm_gem_address_space *aspace,
 84		struct msm_gem_vma *vma);
 85
 86struct msm_gem_object {
 87	struct drm_gem_object base;
 88
 89	uint32_t flags;
 90
 91	/**
 92	 * Advice: are the backing pages purgeable?
 
 
 93	 */
 94	uint8_t madv;
 95
 96	/**
 97	 * count of active vmap'ing
 98	 */
 99	uint8_t vmap_count;
100
101	/**
102	 * Node in list of all objects (mainly for debugfs, protected by
103	 * priv->obj_lock
104	 */
105	struct list_head node;
106
107	struct page **pages;
108	struct sg_table *sgt;
109	void *vaddr;
110
111	struct list_head vmas;    /* list of msm_gem_vma */
112
113	/* For physically contiguous buffers.  Used when we don't have
114	 * an IOMMU.  Also used for stolen/splashscreen buffer.
115	 */
116	struct drm_mm_node *vram_node;
117
118	char name[32]; /* Identifier to print for the debugfs files */
119
 
 
 
 
 
 
 
 
 
120	int pin_count;
121};
122#define to_msm_bo(x) container_of(x, struct msm_gem_object, base)
123
124uint64_t msm_gem_mmap_offset(struct drm_gem_object *obj);
125int msm_gem_pin_vma_locked(struct drm_gem_object *obj, struct msm_gem_vma *vma);
126void msm_gem_unpin_locked(struct drm_gem_object *obj);
 
127struct msm_gem_vma *msm_gem_get_vma_locked(struct drm_gem_object *obj,
128					   struct msm_gem_address_space *aspace);
129int msm_gem_get_iova(struct drm_gem_object *obj,
130		struct msm_gem_address_space *aspace, uint64_t *iova);
131int msm_gem_set_iova(struct drm_gem_object *obj,
132		struct msm_gem_address_space *aspace, uint64_t iova);
133int msm_gem_get_and_pin_iova_range(struct drm_gem_object *obj,
134		struct msm_gem_address_space *aspace, uint64_t *iova,
135		u64 range_start, u64 range_end);
136int msm_gem_get_and_pin_iova(struct drm_gem_object *obj,
137		struct msm_gem_address_space *aspace, uint64_t *iova);
138void msm_gem_unpin_iova(struct drm_gem_object *obj,
139		struct msm_gem_address_space *aspace);
140struct page **msm_gem_pin_pages(struct drm_gem_object *obj);
141void msm_gem_unpin_pages(struct drm_gem_object *obj);
 
142int msm_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
143		struct drm_mode_create_dumb *args);
144int msm_gem_dumb_map_offset(struct drm_file *file, struct drm_device *dev,
145		uint32_t handle, uint64_t *offset);
146void *msm_gem_get_vaddr_locked(struct drm_gem_object *obj);
147void *msm_gem_get_vaddr(struct drm_gem_object *obj);
148void *msm_gem_get_vaddr_active(struct drm_gem_object *obj);
149void msm_gem_put_vaddr_locked(struct drm_gem_object *obj);
150void msm_gem_put_vaddr(struct drm_gem_object *obj);
151int msm_gem_madvise(struct drm_gem_object *obj, unsigned madv);
152bool msm_gem_active(struct drm_gem_object *obj);
153int msm_gem_cpu_prep(struct drm_gem_object *obj, uint32_t op, ktime_t *timeout);
154int msm_gem_cpu_fini(struct drm_gem_object *obj);
155int msm_gem_new_handle(struct drm_device *dev, struct drm_file *file,
156		uint32_t size, uint32_t flags, uint32_t *handle, char *name);
157struct drm_gem_object *msm_gem_new(struct drm_device *dev,
158		uint32_t size, uint32_t flags);
159void *msm_gem_kernel_new(struct drm_device *dev, uint32_t size,
160		uint32_t flags, struct msm_gem_address_space *aspace,
161		struct drm_gem_object **bo, uint64_t *iova);
162void msm_gem_kernel_put(struct drm_gem_object *bo,
163		struct msm_gem_address_space *aspace);
164struct drm_gem_object *msm_gem_import(struct drm_device *dev,
165		struct dma_buf *dmabuf, struct sg_table *sgt);
166__printf(2, 3)
167void msm_gem_object_set_name(struct drm_gem_object *bo, const char *fmt, ...);
168
169#ifdef CONFIG_DEBUG_FS
170struct msm_gem_stats {
171	struct {
172		unsigned count;
173		size_t size;
174	} all, active, resident, purgeable, purged;
175};
176
177void msm_gem_describe(struct drm_gem_object *obj, struct seq_file *m,
178		struct msm_gem_stats *stats);
179void msm_gem_describe_objects(struct list_head *list, struct seq_file *m);
180#endif
181
182static inline void
183msm_gem_lock(struct drm_gem_object *obj)
184{
185	dma_resv_lock(obj->resv, NULL);
186}
187
188static inline int
189msm_gem_lock_interruptible(struct drm_gem_object *obj)
190{
191	return dma_resv_lock_interruptible(obj->resv, NULL);
192}
193
194static inline void
195msm_gem_unlock(struct drm_gem_object *obj)
196{
197	dma_resv_unlock(obj->resv);
198}
199
200static inline void
201msm_gem_assert_locked(struct drm_gem_object *obj)
202{
203	/*
204	 * Destroying the object is a special case.. msm_gem_free_object()
205	 * calls many things that WARN_ON if the obj lock is not held.  But
206	 * acquiring the obj lock in msm_gem_free_object() can cause a
207	 * locking order inversion between reservation_ww_class_mutex and
208	 * fs_reclaim.
209	 *
210	 * This deadlock is not actually possible, because no one should
211	 * be already holding the lock when msm_gem_free_object() is called.
212	 * Unfortunately lockdep is not aware of this detail.  So when the
213	 * refcount drops to zero, we pretend it is already locked.
214	 */
215	lockdep_assert_once(
216		(kref_read(&obj->refcount) == 0) ||
217		(lockdep_is_held(&obj->resv->lock.base) != LOCK_STATE_NOT_HELD)
218	);
219}
220
221/* imported/exported objects are not purgeable: */
222static inline bool is_unpurgeable(struct msm_gem_object *msm_obj)
223{
224	return msm_obj->base.import_attach || msm_obj->pin_count;
225}
226
227static inline bool is_purgeable(struct msm_gem_object *msm_obj)
228{
229	return (msm_obj->madv == MSM_MADV_DONTNEED) && msm_obj->sgt &&
230			!is_unpurgeable(msm_obj);
231}
232
233static inline bool is_vunmapable(struct msm_gem_object *msm_obj)
234{
235	msm_gem_assert_locked(&msm_obj->base);
236	return (msm_obj->vmap_count == 0) && msm_obj->vaddr;
237}
238
239static inline bool is_unevictable(struct msm_gem_object *msm_obj)
240{
241	return is_unpurgeable(msm_obj) || msm_obj->vaddr;
242}
243
244void msm_gem_purge(struct drm_gem_object *obj);
245void msm_gem_evict(struct drm_gem_object *obj);
246void msm_gem_vunmap(struct drm_gem_object *obj);
247
248/* Created per submit-ioctl, to track bo's and cmdstream bufs, etc,
249 * associated with the cmdstream submission for synchronization (and
250 * make it easier to unwind when things go wrong, etc).
251 */
252struct msm_gem_submit {
253	struct drm_sched_job base;
254	struct kref ref;
255	struct drm_device *dev;
256	struct msm_gpu *gpu;
257	struct msm_gem_address_space *aspace;
258	struct list_head node;   /* node in ring submit list */
259	struct ww_acquire_ctx ticket;
260	uint32_t seqno;		/* Sequence number of the submit on the ring */
261
262	/* Hw fence, which is created when the scheduler executes the job, and
263	 * is signaled when the hw finishes (via seqno write from cmdstream)
264	 */
265	struct dma_fence *hw_fence;
266
267	/* Userspace visible fence, which is signaled by the scheduler after
268	 * the hw_fence is signaled.
269	 */
270	struct dma_fence *user_fence;
271
272	int fence_id;       /* key into queue->fence_idr */
273	struct msm_gpu_submitqueue *queue;
274	struct pid *pid;    /* submitting process */
275	bool fault_dumped;  /* Limit devcoredump dumping to one per submit */
276	bool valid;         /* true if no cmdstream patching needed */
277	bool in_rb;         /* "sudo" mode, copy cmds into RB */
278	struct msm_ringbuffer *ring;
279	unsigned int nr_cmds;
280	unsigned int nr_bos;
281	u32 ident;	   /* A "identifier" for the submit for logging */
282	struct {
283		uint32_t type;
284		uint32_t size;  /* in dwords */
285		uint64_t iova;
286		uint32_t offset;/* in dwords */
287		uint32_t idx;   /* cmdstream buffer idx in bos[] */
288		uint32_t nr_relocs;
289		struct drm_msm_gem_submit_reloc *relocs;
290	} *cmd;  /* array of size nr_cmds */
291	struct {
292/* make sure these don't conflict w/ MSM_SUBMIT_BO_x */
293#define BO_VALID	0x8000	/* is current addr in cmdstream correct/valid? */
294#define BO_LOCKED	0x4000	/* obj lock is held */
295#define BO_OBJ_PINNED	0x2000	/* obj (pages) is pinned and on active list */
296#define BO_VMA_PINNED	0x1000	/* vma (virtual address) is pinned */
297		uint32_t flags;
298		union {
299			struct msm_gem_object *obj;
300			uint32_t handle;
301		};
302		uint64_t iova;
303		struct msm_gem_vma *vma;
304	} bos[];
305};
306
307static inline struct msm_gem_submit *to_msm_submit(struct drm_sched_job *job)
308{
309	return container_of(job, struct msm_gem_submit, base);
310}
311
312void __msm_gem_submit_destroy(struct kref *kref);
313
314static inline void msm_gem_submit_get(struct msm_gem_submit *submit)
315{
316	kref_get(&submit->ref);
317}
318
319static inline void msm_gem_submit_put(struct msm_gem_submit *submit)
320{
321	kref_put(&submit->ref, __msm_gem_submit_destroy);
322}
323
324void msm_submit_retire(struct msm_gem_submit *submit);
325
326/* helper to determine of a buffer in submit should be dumped, used for both
327 * devcoredump and debugfs cmdstream dumping:
328 */
329static inline bool
330should_dump(struct msm_gem_submit *submit, int idx)
331{
332	extern bool rd_full;
333	return rd_full || (submit->bos[idx].flags & MSM_SUBMIT_BO_DUMP);
334}
335
336#endif /* __MSM_GEM_H__ */