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