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