Linux Audio

Check our new training course

Embedded Linux training

Mar 31-Apr 8, 2025
Register
Loading...
v5.14.15
  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 "msm_drv.h"
 13
 14/* Make all GEM related WARN_ON()s ratelimited.. when things go wrong they
 15 * tend to go wrong 1000s of times in a short timespan.
 16 */
 17#define GEM_WARN_ON(x)  WARN_RATELIMIT(x, "%s", __stringify(x))
 18
 19/* Additional internal-use only BO flags: */
 20#define MSM_BO_STOLEN        0x10000000    /* try to use stolen/splash memory */
 21#define MSM_BO_MAP_PRIV      0x20000000    /* use IOMMU_PRIV when mapping */
 22
 23struct msm_gem_address_space {
 24	const char *name;
 25	/* NOTE: mm managed at the page level, size is in # of pages
 26	 * and position mm_node->start is in # of pages:
 27	 */
 28	struct drm_mm mm;
 29	spinlock_t lock; /* Protects drm_mm node allocation/removal */
 30	struct msm_mmu *mmu;
 31	struct kref kref;
 32
 33	/* For address spaces associated with a specific process, this
 34	 * will be non-NULL:
 35	 */
 36	struct pid *pid;
 
 
 
 
 
 
 
 
 
 37};
 38
 
 
 
 
 
 
 
 
 
 
 
 39struct msm_gem_vma {
 40	struct drm_mm_node node;
 41	uint64_t iova;
 42	struct msm_gem_address_space *aspace;
 43	struct list_head list;    /* node in msm_gem_object::vmas */
 44	bool mapped;
 45	int inuse;
 46};
 47
 
 
 
 
 
 
 
 48struct msm_gem_object {
 49	struct drm_gem_object base;
 50
 51	uint32_t flags;
 52
 53	/**
 54	 * Advice: are the backing pages purgeable?
 
 
 55	 */
 56	uint8_t madv;
 57
 58	/**
 59	 * Is object on inactive_dontneed list (ie. counted in priv->shrinkable_count)?
 60	 */
 61	bool dontneed : 1;
 62
 63	/**
 64	 * Is object evictable (ie. counted in priv->evictable_count)?
 65	 */
 66	bool evictable : 1;
 67
 68	/**
 69	 * count of active vmap'ing
 70	 */
 71	uint8_t vmap_count;
 72
 73	/**
 74	 * Node in list of all objects (mainly for debugfs, protected by
 75	 * priv->obj_lock
 76	 */
 77	struct list_head node;
 78
 79	/**
 80	 * An object is either:
 81	 *  inactive - on priv->inactive_dontneed or priv->inactive_willneed
 82	 *     (depending on purgeability status)
 83	 *  active   - on one one of the gpu's active_list..  well, at
 84	 *     least for now we don't have (I don't think) hw sync between
 85	 *     2d and 3d one devices which have both, meaning we need to
 86	 *     block on submit if a bo is already on other ring
 87	 */
 88	struct list_head mm_list;
 89
 90	/* Transiently in the process of submit ioctl, objects associated
 91	 * with the submit are on submit->bo_list.. this only lasts for
 92	 * the duration of the ioctl, so one bo can never be on multiple
 93	 * submit lists.
 94	 */
 95	struct list_head submit_entry;
 96
 97	struct page **pages;
 98	struct sg_table *sgt;
 99	void *vaddr;
100
101	struct list_head vmas;    /* list of msm_gem_vma */
102
103	/* For physically contiguous buffers.  Used when we don't have
104	 * an IOMMU.  Also used for stolen/splashscreen buffer.
105	 */
106	struct drm_mm_node *vram_node;
107
108	char name[32]; /* Identifier to print for the debugfs files */
109
110	int active_count;
 
 
 
 
 
 
 
 
111	int pin_count;
112};
113#define to_msm_bo(x) container_of(x, struct msm_gem_object, base)
114
115int msm_gem_mmap_obj(struct drm_gem_object *obj,
116			struct vm_area_struct *vma);
117int msm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
118uint64_t msm_gem_mmap_offset(struct drm_gem_object *obj);
 
 
 
 
 
119int msm_gem_get_iova(struct drm_gem_object *obj,
120		struct msm_gem_address_space *aspace, uint64_t *iova);
 
 
121int msm_gem_get_and_pin_iova_range(struct drm_gem_object *obj,
122		struct msm_gem_address_space *aspace, uint64_t *iova,
123		u64 range_start, u64 range_end);
124int msm_gem_get_and_pin_iova_locked(struct drm_gem_object *obj,
125		struct msm_gem_address_space *aspace, uint64_t *iova);
126int msm_gem_get_and_pin_iova(struct drm_gem_object *obj,
127		struct msm_gem_address_space *aspace, uint64_t *iova);
128uint64_t msm_gem_iova(struct drm_gem_object *obj,
129		struct msm_gem_address_space *aspace);
130void msm_gem_unpin_iova_locked(struct drm_gem_object *obj,
131		struct msm_gem_address_space *aspace);
132void msm_gem_unpin_iova(struct drm_gem_object *obj,
133		struct msm_gem_address_space *aspace);
134struct page **msm_gem_get_pages(struct drm_gem_object *obj);
135void msm_gem_put_pages(struct drm_gem_object *obj);
 
136int msm_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
137		struct drm_mode_create_dumb *args);
138int msm_gem_dumb_map_offset(struct drm_file *file, struct drm_device *dev,
139		uint32_t handle, uint64_t *offset);
140void *msm_gem_get_vaddr_locked(struct drm_gem_object *obj);
141void *msm_gem_get_vaddr(struct drm_gem_object *obj);
142void *msm_gem_get_vaddr_active(struct drm_gem_object *obj);
143void msm_gem_put_vaddr_locked(struct drm_gem_object *obj);
144void msm_gem_put_vaddr(struct drm_gem_object *obj);
145int msm_gem_madvise(struct drm_gem_object *obj, unsigned madv);
146int msm_gem_sync_object(struct drm_gem_object *obj,
147		struct msm_fence_context *fctx, bool exclusive);
148void msm_gem_active_get(struct drm_gem_object *obj, struct msm_gpu *gpu);
149void msm_gem_active_put(struct drm_gem_object *obj);
150int msm_gem_cpu_prep(struct drm_gem_object *obj, uint32_t op, ktime_t *timeout);
151int msm_gem_cpu_fini(struct drm_gem_object *obj);
152void msm_gem_free_object(struct drm_gem_object *obj);
153int msm_gem_new_handle(struct drm_device *dev, struct drm_file *file,
154		uint32_t size, uint32_t flags, uint32_t *handle, char *name);
155struct drm_gem_object *msm_gem_new(struct drm_device *dev,
156		uint32_t size, uint32_t flags);
157struct drm_gem_object *msm_gem_new_locked(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_new_locked(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, bool locked);
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 bool __must_check
192msm_gem_trylock(struct drm_gem_object *obj)
193{
194	return dma_resv_trylock(obj->resv);
195}
196
197static inline int
198msm_gem_lock_interruptible(struct drm_gem_object *obj)
199{
200	return dma_resv_lock_interruptible(obj->resv, NULL);
201}
202
203static inline void
204msm_gem_unlock(struct drm_gem_object *obj)
205{
206	dma_resv_unlock(obj->resv);
207}
208
209static inline bool
210msm_gem_is_locked(struct drm_gem_object *obj)
211{
212	return dma_resv_is_locked(obj->resv);
213}
214
215static inline bool is_active(struct msm_gem_object *msm_obj)
216{
217	GEM_WARN_ON(!msm_gem_is_locked(&msm_obj->base));
218	return msm_obj->active_count;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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	GEM_WARN_ON(!msm_gem_is_locked(&msm_obj->base));
236	return (msm_obj->vmap_count == 0) && msm_obj->vaddr;
237}
238
239static inline void mark_purgeable(struct msm_gem_object *msm_obj)
240{
241	struct msm_drm_private *priv = msm_obj->base.dev->dev_private;
242
243	GEM_WARN_ON(!mutex_is_locked(&priv->mm_lock));
244
245	if (is_unpurgeable(msm_obj))
246		return;
247
248	if (GEM_WARN_ON(msm_obj->dontneed))
249		return;
250
251	priv->shrinkable_count += msm_obj->base.size >> PAGE_SHIFT;
252	msm_obj->dontneed = true;
253}
254
255static inline void mark_unpurgeable(struct msm_gem_object *msm_obj)
256{
257	struct msm_drm_private *priv = msm_obj->base.dev->dev_private;
258
259	GEM_WARN_ON(!mutex_is_locked(&priv->mm_lock));
260
261	if (is_unpurgeable(msm_obj))
262		return;
263
264	if (GEM_WARN_ON(!msm_obj->dontneed))
265		return;
266
267	priv->shrinkable_count -= msm_obj->base.size >> PAGE_SHIFT;
268	GEM_WARN_ON(priv->shrinkable_count < 0);
269	msm_obj->dontneed = false;
270}
271
272static inline bool is_unevictable(struct msm_gem_object *msm_obj)
273{
274	return is_unpurgeable(msm_obj) || msm_obj->vaddr;
275}
276
277static inline void mark_evictable(struct msm_gem_object *msm_obj)
278{
279	struct msm_drm_private *priv = msm_obj->base.dev->dev_private;
280
281	WARN_ON(!mutex_is_locked(&priv->mm_lock));
282
283	if (is_unevictable(msm_obj))
284		return;
285
286	if (WARN_ON(msm_obj->evictable))
287		return;
288
289	priv->evictable_count += msm_obj->base.size >> PAGE_SHIFT;
290	msm_obj->evictable = true;
291}
292
293static inline void mark_unevictable(struct msm_gem_object *msm_obj)
294{
295	struct msm_drm_private *priv = msm_obj->base.dev->dev_private;
296
297	WARN_ON(!mutex_is_locked(&priv->mm_lock));
298
299	if (is_unevictable(msm_obj))
300		return;
301
302	if (WARN_ON(!msm_obj->evictable))
303		return;
304
305	priv->evictable_count -= msm_obj->base.size >> PAGE_SHIFT;
306	WARN_ON(priv->evictable_count < 0);
307	msm_obj->evictable = false;
308}
309
310void msm_gem_purge(struct drm_gem_object *obj);
311void msm_gem_evict(struct drm_gem_object *obj);
312void msm_gem_vunmap(struct drm_gem_object *obj);
313
314/* Created per submit-ioctl, to track bo's and cmdstream bufs, etc,
315 * associated with the cmdstream submission for synchronization (and
316 * make it easier to unwind when things go wrong, etc).  This only
317 * lasts for the duration of the submit-ioctl.
318 */
319struct msm_gem_submit {
 
320	struct kref ref;
321	struct drm_device *dev;
322	struct msm_gpu *gpu;
323	struct msm_gem_address_space *aspace;
324	struct list_head node;   /* node in ring submit list */
325	struct list_head bo_list;
326	struct ww_acquire_ctx ticket;
327	uint32_t seqno;		/* Sequence number of the submit on the ring */
328	struct dma_fence *fence;
 
 
 
 
 
 
 
 
 
 
 
329	struct msm_gpu_submitqueue *queue;
330	struct pid *pid;    /* submitting process */
331	bool fault_dumped;  /* Limit devcoredump dumping to one per submit */
332	bool valid;         /* true if no cmdstream patching needed */
333	bool in_rb;         /* "sudo" mode, copy cmds into RB */
334	struct msm_ringbuffer *ring;
335	struct msm_file_private *ctx;
336	unsigned int nr_cmds;
337	unsigned int nr_bos;
338	u32 ident;	   /* A "identifier" for the submit for logging */
339	struct {
340		uint32_t type;
341		uint32_t size;  /* in dwords */
342		uint64_t iova;
343		uint32_t offset;/* in dwords */
344		uint32_t idx;   /* cmdstream buffer idx in bos[] */
345		uint32_t nr_relocs;
346		struct drm_msm_gem_submit_reloc *relocs;
347	} *cmd;  /* array of size nr_cmds */
348	struct {
349		uint32_t flags;
350		union {
351			struct msm_gem_object *obj;
352			uint32_t handle;
353		};
354		uint64_t iova;
355	} bos[];
356};
357
 
 
 
 
 
358void __msm_gem_submit_destroy(struct kref *kref);
359
360static inline void msm_gem_submit_get(struct msm_gem_submit *submit)
361{
362	kref_get(&submit->ref);
363}
364
365static inline void msm_gem_submit_put(struct msm_gem_submit *submit)
366{
367	kref_put(&submit->ref, __msm_gem_submit_destroy);
368}
 
 
369
370/* helper to determine of a buffer in submit should be dumped, used for both
371 * devcoredump and debugfs cmdstream dumping:
372 */
373static inline bool
374should_dump(struct msm_gem_submit *submit, int idx)
375{
376	extern bool rd_full;
377	return rd_full || (submit->bos[idx].flags & MSM_SUBMIT_BO_DUMP);
378}
379
380#endif /* __MSM_GEM_H__ */
v6.9.4
  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(struct drm_gem_object *obj);
144void msm_gem_unpin_pages(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__ */