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