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