xref: /linux-6.15/drivers/gpu/drm/msm/msm_gpu.h (revision d4843012)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2013 Red Hat
4  * Author: Rob Clark <[email protected]>
5  */
6 
7 #ifndef __MSM_GPU_H__
8 #define __MSM_GPU_H__
9 
10 #include <linux/adreno-smmu-priv.h>
11 #include <linux/clk.h>
12 #include <linux/devfreq.h>
13 #include <linux/interconnect.h>
14 #include <linux/pm_opp.h>
15 #include <linux/regulator/consumer.h>
16 
17 #include "msm_drv.h"
18 #include "msm_fence.h"
19 #include "msm_ringbuffer.h"
20 #include "msm_gem.h"
21 
22 struct msm_gem_submit;
23 struct msm_gpu_perfcntr;
24 struct msm_gpu_state;
25 struct msm_file_private;
26 
27 struct msm_gpu_config {
28 	const char *ioname;
29 	unsigned int nr_rings;
30 };
31 
32 /* So far, with hardware that I've seen to date, we can have:
33  *  + zero, one, or two z180 2d cores
34  *  + a3xx or a2xx 3d core, which share a common CP (the firmware
35  *    for the CP seems to implement some different PM4 packet types
36  *    but the basics of cmdstream submission are the same)
37  *
38  * Which means that the eventual complete "class" hierarchy, once
39  * support for all past and present hw is in place, becomes:
40  *  + msm_gpu
41  *    + adreno_gpu
42  *      + a3xx_gpu
43  *      + a2xx_gpu
44  *    + z180_gpu
45  */
46 struct msm_gpu_funcs {
47 	int (*get_param)(struct msm_gpu *gpu, struct msm_file_private *ctx,
48 			 uint32_t param, uint64_t *value, uint32_t *len);
49 	int (*set_param)(struct msm_gpu *gpu, struct msm_file_private *ctx,
50 			 uint32_t param, uint64_t value, uint32_t len);
51 	int (*hw_init)(struct msm_gpu *gpu);
52 	int (*pm_suspend)(struct msm_gpu *gpu);
53 	int (*pm_resume)(struct msm_gpu *gpu);
54 	void (*submit)(struct msm_gpu *gpu, struct msm_gem_submit *submit);
55 	void (*flush)(struct msm_gpu *gpu, struct msm_ringbuffer *ring);
56 	irqreturn_t (*irq)(struct msm_gpu *irq);
57 	struct msm_ringbuffer *(*active_ring)(struct msm_gpu *gpu);
58 	void (*recover)(struct msm_gpu *gpu);
59 	void (*destroy)(struct msm_gpu *gpu);
60 #if defined(CONFIG_DEBUG_FS) || defined(CONFIG_DEV_COREDUMP)
61 	/* show GPU status in debugfs: */
62 	void (*show)(struct msm_gpu *gpu, struct msm_gpu_state *state,
63 			struct drm_printer *p);
64 	/* for generation specific debugfs: */
65 	void (*debugfs_init)(struct msm_gpu *gpu, struct drm_minor *minor);
66 #endif
67 	/* note: gpu_busy() can assume that we have been pm_resumed */
68 	u64 (*gpu_busy)(struct msm_gpu *gpu, unsigned long *out_sample_rate);
69 	struct msm_gpu_state *(*gpu_state_get)(struct msm_gpu *gpu);
70 	int (*gpu_state_put)(struct msm_gpu_state *state);
71 	unsigned long (*gpu_get_freq)(struct msm_gpu *gpu);
72 	/* note: gpu_set_freq() can assume that we have been pm_resumed */
73 	void (*gpu_set_freq)(struct msm_gpu *gpu, struct dev_pm_opp *opp,
74 			     bool suspended);
75 	struct msm_gem_address_space *(*create_address_space)
76 		(struct msm_gpu *gpu, struct platform_device *pdev);
77 	struct msm_gem_address_space *(*create_private_address_space)
78 		(struct msm_gpu *gpu);
79 	uint32_t (*get_rptr)(struct msm_gpu *gpu, struct msm_ringbuffer *ring);
80 
81 	/**
82 	 * progress: Has the GPU made progress?
83 	 *
84 	 * Return true if GPU position in cmdstream has advanced (or changed)
85 	 * since the last call.  To avoid false negatives, this should account
86 	 * for cmdstream that is buffered in this FIFO upstream of the CP fw.
87 	 */
88 	bool (*progress)(struct msm_gpu *gpu, struct msm_ringbuffer *ring);
89 };
90 
91 /* Additional state for iommu faults: */
92 struct msm_gpu_fault_info {
93 	u64 ttbr0;
94 	unsigned long iova;
95 	int flags;
96 	const char *type;
97 	const char *block;
98 };
99 
100 /**
101  * struct msm_gpu_devfreq - devfreq related state
102  */
103 struct msm_gpu_devfreq {
104 	/** devfreq: devfreq instance */
105 	struct devfreq *devfreq;
106 
107 	/** lock: lock for "suspended", "busy_cycles", and "time" */
108 	struct mutex lock;
109 
110 	/**
111 	 * idle_freq:
112 	 *
113 	 * Shadow frequency used while the GPU is idle.  From the PoV of
114 	 * the devfreq governor, we are continuing to sample busyness and
115 	 * adjust frequency while the GPU is idle, but we use this shadow
116 	 * value as the GPU is actually clamped to minimum frequency while
117 	 * it is inactive.
118 	 */
119 	unsigned long idle_freq;
120 
121 	/**
122 	 * boost_constraint:
123 	 *
124 	 * A PM QoS constraint to boost min freq for a period of time
125 	 * until the boost expires.
126 	 */
127 	struct dev_pm_qos_request boost_freq;
128 
129 	/**
130 	 * busy_cycles: Last busy counter value, for calculating elapsed busy
131 	 * cycles since last sampling period.
132 	 */
133 	u64 busy_cycles;
134 
135 	/** time: Time of last sampling period. */
136 	ktime_t time;
137 
138 	/** idle_time: Time of last transition to idle: */
139 	ktime_t idle_time;
140 
141 	/**
142 	 * idle_work:
143 	 *
144 	 * Used to delay clamping to idle freq on active->idle transition.
145 	 */
146 	struct msm_hrtimer_work idle_work;
147 
148 	/**
149 	 * boost_work:
150 	 *
151 	 * Used to reset the boost_constraint after the boost period has
152 	 * elapsed
153 	 */
154 	struct msm_hrtimer_work boost_work;
155 
156 	/** suspended: tracks if we're suspended */
157 	bool suspended;
158 };
159 
160 struct msm_gpu {
161 	const char *name;
162 	struct drm_device *dev;
163 	struct platform_device *pdev;
164 	const struct msm_gpu_funcs *funcs;
165 
166 	struct adreno_smmu_priv adreno_smmu;
167 
168 	/* performance counters (hw & sw): */
169 	spinlock_t perf_lock;
170 	bool perfcntr_active;
171 	struct {
172 		bool active;
173 		ktime_t time;
174 	} last_sample;
175 	uint32_t totaltime, activetime;    /* sw counters */
176 	uint32_t last_cntrs[5];            /* hw counters */
177 	const struct msm_gpu_perfcntr *perfcntrs;
178 	uint32_t num_perfcntrs;
179 
180 	struct msm_ringbuffer *rb[MSM_GPU_MAX_RINGS];
181 	int nr_rings;
182 
183 	/**
184 	 * sysprof_active:
185 	 *
186 	 * The count of contexts that have enabled system profiling.
187 	 */
188 	refcount_t sysprof_active;
189 
190 	/**
191 	 * cur_ctx_seqno:
192 	 *
193 	 * The ctx->seqno value of the last context to submit rendering,
194 	 * and the one with current pgtables installed (for generations
195 	 * that support per-context pgtables).  Tracked by seqno rather
196 	 * than pointer value to avoid dangling pointers, and cases where
197 	 * a ctx can be freed and a new one created with the same address.
198 	 */
199 	int cur_ctx_seqno;
200 
201 	/**
202 	 * lock:
203 	 *
204 	 * General lock for serializing all the gpu things.
205 	 *
206 	 * TODO move to per-ring locking where feasible (ie. submit/retire
207 	 * path, etc)
208 	 */
209 	struct mutex lock;
210 
211 	/**
212 	 * active_submits:
213 	 *
214 	 * The number of submitted but not yet retired submits, used to
215 	 * determine transitions between active and idle.
216 	 *
217 	 * Protected by active_lock
218 	 */
219 	int active_submits;
220 
221 	/** lock: protects active_submits and idle/active transitions */
222 	struct mutex active_lock;
223 
224 	/* does gpu need hw_init? */
225 	bool needs_hw_init;
226 
227 	/**
228 	 * global_faults: number of GPU hangs not attributed to a particular
229 	 * address space
230 	 */
231 	int global_faults;
232 
233 	void __iomem *mmio;
234 	int irq;
235 
236 	struct msm_gem_address_space *aspace;
237 
238 	/* Power Control: */
239 	struct regulator *gpu_reg, *gpu_cx;
240 	struct clk_bulk_data *grp_clks;
241 	int nr_clocks;
242 	struct clk *ebi1_clk, *core_clk, *rbbmtimer_clk;
243 	uint32_t fast_rate;
244 
245 	/* Hang and Inactivity Detection:
246 	 */
247 #define DRM_MSM_INACTIVE_PERIOD   66 /* in ms (roughly four frames) */
248 
249 #define DRM_MSM_HANGCHECK_DEFAULT_PERIOD 500 /* in ms */
250 #define DRM_MSM_HANGCHECK_PROGRESS_RETRIES 3
251 	struct timer_list hangcheck_timer;
252 
253 	/* Fault info for most recent iova fault: */
254 	struct msm_gpu_fault_info fault_info;
255 
256 	/* work for handling GPU ioval faults: */
257 	struct kthread_work fault_work;
258 
259 	/* work for handling GPU recovery: */
260 	struct kthread_work recover_work;
261 
262 	/** retire_event: notified when submits are retired: */
263 	wait_queue_head_t retire_event;
264 
265 	/* work for handling active-list retiring: */
266 	struct kthread_work retire_work;
267 
268 	/* worker for retire/recover: */
269 	struct kthread_worker *worker;
270 
271 	struct drm_gem_object *memptrs_bo;
272 
273 	struct msm_gpu_devfreq devfreq;
274 
275 	uint32_t suspend_count;
276 
277 	struct msm_gpu_state *crashstate;
278 
279 	/* True if the hardware supports expanded apriv (a650 and newer) */
280 	bool hw_apriv;
281 
282 	struct thermal_cooling_device *cooling;
283 };
284 
285 static inline struct msm_gpu *dev_to_gpu(struct device *dev)
286 {
287 	struct adreno_smmu_priv *adreno_smmu = dev_get_drvdata(dev);
288 
289 	if (!adreno_smmu)
290 		return NULL;
291 
292 	return container_of(adreno_smmu, struct msm_gpu, adreno_smmu);
293 }
294 
295 /* It turns out that all targets use the same ringbuffer size */
296 #define MSM_GPU_RINGBUFFER_SZ SZ_32K
297 #define MSM_GPU_RINGBUFFER_BLKSIZE 32
298 
299 #define MSM_GPU_RB_CNTL_DEFAULT \
300 		(AXXX_CP_RB_CNTL_BUFSZ(ilog2(MSM_GPU_RINGBUFFER_SZ / 8)) | \
301 		AXXX_CP_RB_CNTL_BLKSZ(ilog2(MSM_GPU_RINGBUFFER_BLKSIZE / 8)))
302 
303 static inline bool msm_gpu_active(struct msm_gpu *gpu)
304 {
305 	int i;
306 
307 	for (i = 0; i < gpu->nr_rings; i++) {
308 		struct msm_ringbuffer *ring = gpu->rb[i];
309 
310 		if (fence_after(ring->fctx->last_fence, ring->memptrs->fence))
311 			return true;
312 	}
313 
314 	return false;
315 }
316 
317 /* Perf-Counters:
318  * The select_reg and select_val are just there for the benefit of the child
319  * class that actually enables the perf counter..  but msm_gpu base class
320  * will handle sampling/displaying the counters.
321  */
322 
323 struct msm_gpu_perfcntr {
324 	uint32_t select_reg;
325 	uint32_t sample_reg;
326 	uint32_t select_val;
327 	const char *name;
328 };
329 
330 /*
331  * The number of priority levels provided by drm gpu scheduler.  The
332  * DRM_SCHED_PRIORITY_KERNEL priority level is treated specially in some
333  * cases, so we don't use it (no need for kernel generated jobs).
334  */
335 #define NR_SCHED_PRIORITIES (1 + DRM_SCHED_PRIORITY_HIGH - DRM_SCHED_PRIORITY_MIN)
336 
337 /**
338  * struct msm_file_private - per-drm_file context
339  *
340  * @queuelock:    synchronizes access to submitqueues list
341  * @submitqueues: list of &msm_gpu_submitqueue created by userspace
342  * @queueid:      counter incremented each time a submitqueue is created,
343  *                used to assign &msm_gpu_submitqueue.id
344  * @aspace:       the per-process GPU address-space
345  * @ref:          reference count
346  * @seqno:        unique per process seqno
347  */
348 struct msm_file_private {
349 	rwlock_t queuelock;
350 	struct list_head submitqueues;
351 	int queueid;
352 	struct msm_gem_address_space *aspace;
353 	struct kref ref;
354 	int seqno;
355 
356 	/**
357 	 * sysprof:
358 	 *
359 	 * The value of MSM_PARAM_SYSPROF set by userspace.  This is
360 	 * intended to be used by system profiling tools like Mesa's
361 	 * pps-producer (perfetto), and restricted to CAP_SYS_ADMIN.
362 	 *
363 	 * Setting a value of 1 will preserve performance counters across
364 	 * context switches.  Setting a value of 2 will in addition
365 	 * suppress suspend.  (Performance counters lose state across
366 	 * power collapse, which is undesirable for profiling in some
367 	 * cases.)
368 	 *
369 	 * The value automatically reverts to zero when the drm device
370 	 * file is closed.
371 	 */
372 	int sysprof;
373 
374 	/**
375 	 * comm: Overridden task comm, see MSM_PARAM_COMM
376 	 *
377 	 * Accessed under msm_gpu::lock
378 	 */
379 	char *comm;
380 
381 	/**
382 	 * cmdline: Overridden task cmdline, see MSM_PARAM_CMDLINE
383 	 *
384 	 * Accessed under msm_gpu::lock
385 	 */
386 	char *cmdline;
387 
388 	/**
389 	 * elapsed:
390 	 *
391 	 * The total (cumulative) elapsed time GPU was busy with rendering
392 	 * from this context in ns.
393 	 */
394 	uint64_t elapsed_ns;
395 
396 	/**
397 	 * cycles:
398 	 *
399 	 * The total (cumulative) GPU cycles elapsed attributed to this
400 	 * context.
401 	 */
402 	uint64_t cycles;
403 
404 	/**
405 	 * entities:
406 	 *
407 	 * Table of per-priority-level sched entities used by submitqueues
408 	 * associated with this &drm_file.  Because some userspace apps
409 	 * make assumptions about rendering from multiple gl contexts
410 	 * (of the same priority) within the process happening in FIFO
411 	 * order without requiring any fencing beyond MakeCurrent(), we
412 	 * create at most one &drm_sched_entity per-process per-priority-
413 	 * level.
414 	 */
415 	struct drm_sched_entity *entities[NR_SCHED_PRIORITIES * MSM_GPU_MAX_RINGS];
416 };
417 
418 /**
419  * msm_gpu_convert_priority - Map userspace priority to ring # and sched priority
420  *
421  * @gpu:        the gpu instance
422  * @prio:       the userspace priority level
423  * @ring_nr:    [out] the ringbuffer the userspace priority maps to
424  * @sched_prio: [out] the gpu scheduler priority level which the userspace
425  *              priority maps to
426  *
427  * With drm/scheduler providing it's own level of prioritization, our total
428  * number of available priority levels is (nr_rings * NR_SCHED_PRIORITIES).
429  * Each ring is associated with it's own scheduler instance.  However, our
430  * UABI is that lower numerical values are higher priority.  So mapping the
431  * single userspace priority level into ring_nr and sched_prio takes some
432  * care.  The userspace provided priority (when a submitqueue is created)
433  * is mapped to ring nr and scheduler priority as such:
434  *
435  *   ring_nr    = userspace_prio / NR_SCHED_PRIORITIES
436  *   sched_prio = NR_SCHED_PRIORITIES -
437  *                (userspace_prio % NR_SCHED_PRIORITIES) - 1
438  *
439  * This allows generations without preemption (nr_rings==1) to have some
440  * amount of prioritization, and provides more priority levels for gens
441  * that do have preemption.
442  */
443 static inline int msm_gpu_convert_priority(struct msm_gpu *gpu, int prio,
444 		unsigned *ring_nr, enum drm_sched_priority *sched_prio)
445 {
446 	unsigned rn, sp;
447 
448 	rn = div_u64_rem(prio, NR_SCHED_PRIORITIES, &sp);
449 
450 	/* invert sched priority to map to higher-numeric-is-higher-
451 	 * priority convention
452 	 */
453 	sp = NR_SCHED_PRIORITIES - sp - 1;
454 
455 	if (rn >= gpu->nr_rings)
456 		return -EINVAL;
457 
458 	*ring_nr = rn;
459 	*sched_prio = sp;
460 
461 	return 0;
462 }
463 
464 /**
465  * struct msm_gpu_submitqueues - Userspace created context.
466  *
467  * A submitqueue is associated with a gl context or vk queue (or equiv)
468  * in userspace.
469  *
470  * @id:        userspace id for the submitqueue, unique within the drm_file
471  * @flags:     userspace flags for the submitqueue, specified at creation
472  *             (currently unusued)
473  * @ring_nr:   the ringbuffer used by this submitqueue, which is determined
474  *             by the submitqueue's priority
475  * @faults:    the number of GPU hangs associated with this submitqueue
476  * @last_fence: the sequence number of the last allocated fence (for error
477  *             checking)
478  * @ctx:       the per-drm_file context associated with the submitqueue (ie.
479  *             which set of pgtables do submits jobs associated with the
480  *             submitqueue use)
481  * @node:      node in the context's list of submitqueues
482  * @fence_idr: maps fence-id to dma_fence for userspace visible fence
483  *             seqno, protected by submitqueue lock
484  * @idr_lock:  for serializing access to fence_idr
485  * @lock:      submitqueue lock for serializing submits on a queue
486  * @ref:       reference count
487  * @entity:    the submit job-queue
488  */
489 struct msm_gpu_submitqueue {
490 	int id;
491 	u32 flags;
492 	u32 ring_nr;
493 	int faults;
494 	uint32_t last_fence;
495 	struct msm_file_private *ctx;
496 	struct list_head node;
497 	struct idr fence_idr;
498 	struct mutex idr_lock;
499 	struct mutex lock;
500 	struct kref ref;
501 	struct drm_sched_entity *entity;
502 };
503 
504 struct msm_gpu_state_bo {
505 	u64 iova;
506 	size_t size;
507 	void *data;
508 	bool encoded;
509 	char name[32];
510 };
511 
512 struct msm_gpu_state {
513 	struct kref ref;
514 	struct timespec64 time;
515 
516 	struct {
517 		u64 iova;
518 		u32 fence;
519 		u32 seqno;
520 		u32 rptr;
521 		u32 wptr;
522 		void *data;
523 		int data_size;
524 		bool encoded;
525 	} ring[MSM_GPU_MAX_RINGS];
526 
527 	int nr_registers;
528 	u32 *registers;
529 
530 	u32 rbbm_status;
531 
532 	char *comm;
533 	char *cmd;
534 
535 	struct msm_gpu_fault_info fault_info;
536 
537 	int nr_bos;
538 	struct msm_gpu_state_bo *bos;
539 };
540 
541 static inline void gpu_write(struct msm_gpu *gpu, u32 reg, u32 data)
542 {
543 	msm_writel(data, gpu->mmio + (reg << 2));
544 }
545 
546 static inline u32 gpu_read(struct msm_gpu *gpu, u32 reg)
547 {
548 	return msm_readl(gpu->mmio + (reg << 2));
549 }
550 
551 static inline void gpu_rmw(struct msm_gpu *gpu, u32 reg, u32 mask, u32 or)
552 {
553 	msm_rmw(gpu->mmio + (reg << 2), mask, or);
554 }
555 
556 static inline u64 gpu_read64(struct msm_gpu *gpu, u32 reg)
557 {
558 	u64 val;
559 
560 	/*
561 	 * Why not a readq here? Two reasons: 1) many of the LO registers are
562 	 * not quad word aligned and 2) the GPU hardware designers have a bit
563 	 * of a history of putting registers where they fit, especially in
564 	 * spins. The longer a GPU family goes the higher the chance that
565 	 * we'll get burned.  We could do a series of validity checks if we
566 	 * wanted to, but really is a readq() that much better? Nah.
567 	 */
568 
569 	/*
570 	 * For some lo/hi registers (like perfcounters), the hi value is latched
571 	 * when the lo is read, so make sure to read the lo first to trigger
572 	 * that
573 	 */
574 	val = (u64) msm_readl(gpu->mmio + (reg << 2));
575 	val |= ((u64) msm_readl(gpu->mmio + ((reg + 1) << 2)) << 32);
576 
577 	return val;
578 }
579 
580 static inline void gpu_write64(struct msm_gpu *gpu, u32 reg, u64 val)
581 {
582 	/* Why not a writeq here? Read the screed above */
583 	msm_writel(lower_32_bits(val), gpu->mmio + (reg << 2));
584 	msm_writel(upper_32_bits(val), gpu->mmio + ((reg + 1) << 2));
585 }
586 
587 int msm_gpu_pm_suspend(struct msm_gpu *gpu);
588 int msm_gpu_pm_resume(struct msm_gpu *gpu);
589 
590 void msm_gpu_show_fdinfo(struct msm_gpu *gpu, struct msm_file_private *ctx,
591 			 struct drm_printer *p);
592 
593 int msm_submitqueue_init(struct drm_device *drm, struct msm_file_private *ctx);
594 struct msm_gpu_submitqueue *msm_submitqueue_get(struct msm_file_private *ctx,
595 		u32 id);
596 int msm_submitqueue_create(struct drm_device *drm,
597 		struct msm_file_private *ctx,
598 		u32 prio, u32 flags, u32 *id);
599 int msm_submitqueue_query(struct drm_device *drm, struct msm_file_private *ctx,
600 		struct drm_msm_submitqueue_query *args);
601 int msm_submitqueue_remove(struct msm_file_private *ctx, u32 id);
602 void msm_submitqueue_close(struct msm_file_private *ctx);
603 
604 void msm_submitqueue_destroy(struct kref *kref);
605 
606 int msm_file_private_set_sysprof(struct msm_file_private *ctx,
607 				 struct msm_gpu *gpu, int sysprof);
608 void __msm_file_private_destroy(struct kref *kref);
609 
610 static inline void msm_file_private_put(struct msm_file_private *ctx)
611 {
612 	kref_put(&ctx->ref, __msm_file_private_destroy);
613 }
614 
615 static inline struct msm_file_private *msm_file_private_get(
616 	struct msm_file_private *ctx)
617 {
618 	kref_get(&ctx->ref);
619 	return ctx;
620 }
621 
622 void msm_devfreq_init(struct msm_gpu *gpu);
623 void msm_devfreq_cleanup(struct msm_gpu *gpu);
624 void msm_devfreq_resume(struct msm_gpu *gpu);
625 void msm_devfreq_suspend(struct msm_gpu *gpu);
626 void msm_devfreq_boost(struct msm_gpu *gpu, unsigned factor);
627 void msm_devfreq_active(struct msm_gpu *gpu);
628 void msm_devfreq_idle(struct msm_gpu *gpu);
629 
630 int msm_gpu_hw_init(struct msm_gpu *gpu);
631 
632 void msm_gpu_perfcntr_start(struct msm_gpu *gpu);
633 void msm_gpu_perfcntr_stop(struct msm_gpu *gpu);
634 int msm_gpu_perfcntr_sample(struct msm_gpu *gpu, uint32_t *activetime,
635 		uint32_t *totaltime, uint32_t ncntrs, uint32_t *cntrs);
636 
637 void msm_gpu_retire(struct msm_gpu *gpu);
638 void msm_gpu_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit);
639 
640 int msm_gpu_init(struct drm_device *drm, struct platform_device *pdev,
641 		struct msm_gpu *gpu, const struct msm_gpu_funcs *funcs,
642 		const char *name, struct msm_gpu_config *config);
643 
644 struct msm_gem_address_space *
645 msm_gpu_create_private_address_space(struct msm_gpu *gpu, struct task_struct *task);
646 
647 void msm_gpu_cleanup(struct msm_gpu *gpu);
648 
649 struct msm_gpu *adreno_load_gpu(struct drm_device *dev);
650 void __init adreno_register(void);
651 void __exit adreno_unregister(void);
652 
653 static inline void msm_submitqueue_put(struct msm_gpu_submitqueue *queue)
654 {
655 	if (queue)
656 		kref_put(&queue->ref, msm_submitqueue_destroy);
657 }
658 
659 static inline struct msm_gpu_state *msm_gpu_crashstate_get(struct msm_gpu *gpu)
660 {
661 	struct msm_gpu_state *state = NULL;
662 
663 	mutex_lock(&gpu->lock);
664 
665 	if (gpu->crashstate) {
666 		kref_get(&gpu->crashstate->ref);
667 		state = gpu->crashstate;
668 	}
669 
670 	mutex_unlock(&gpu->lock);
671 
672 	return state;
673 }
674 
675 static inline void msm_gpu_crashstate_put(struct msm_gpu *gpu)
676 {
677 	mutex_lock(&gpu->lock);
678 
679 	if (gpu->crashstate) {
680 		if (gpu->funcs->gpu_state_put(gpu->crashstate))
681 			gpu->crashstate = NULL;
682 	}
683 
684 	mutex_unlock(&gpu->lock);
685 }
686 
687 /*
688  * Simple macro to semi-cleanly add the MAP_PRIV flag for targets that can
689  * support expanded privileges
690  */
691 #define check_apriv(gpu, flags) \
692 	(((gpu)->hw_apriv ? MSM_BO_MAP_PRIV : 0) | (flags))
693 
694 
695 #endif /* __MSM_GPU_H__ */
696