xref: /linux/drivers/gpu/drm/v3d/v3d_drv.h (revision 570f7e331f5febb30f1384817463c7e42b65ca7d)
1 // SPDX-License-Identifier: GPL-2.0+
2 /* Copyright (C) 2015-2018 Broadcom */
3 
4 #include <linux/delay.h>
5 #include <linux/mutex.h>
6 #include <linux/pm_runtime.h>
7 #include <linux/spinlock_types.h>
8 #include <linux/workqueue.h>
9 
10 #include <drm/drm_device.h>
11 #include <drm/drm_exec.h>
12 #include <drm/drm_gem.h>
13 #include <drm/drm_gem_shmem_helper.h>
14 #include <drm/gpu_scheduler.h>
15 
16 #include "v3d_performance_counters.h"
17 
18 #include "uapi/drm/v3d_drm.h"
19 
20 struct clk;
21 struct platform_device;
22 struct reset_control;
23 
24 #define V3D_MMU_PAGE_SHIFT 12
25 #define V3D_PAGE_FACTOR (PAGE_SIZE >> V3D_MMU_PAGE_SHIFT)
26 
27 #define V3D_MAX_QUEUES (V3D_CPU + 1)
28 
29 static inline char *v3d_queue_to_string(enum v3d_queue queue)
30 {
31 	switch (queue) {
32 	case V3D_BIN: return "bin";
33 	case V3D_RENDER: return "render";
34 	case V3D_TFU: return "tfu";
35 	case V3D_CSD: return "csd";
36 	case V3D_CACHE_CLEAN: return "cache_clean";
37 	case V3D_CPU: return "cpu";
38 	}
39 	return "UNKNOWN";
40 }
41 
42 struct v3d_stats {
43 	struct kref refcount;
44 
45 	u64 start_ns;
46 	u64 enabled_ns;
47 	u64 jobs_completed;
48 
49 	/*
50 	 * This seqcount is used to protect the access to the GPU stats
51 	 * variables. It must be used as, while we are reading the stats,
52 	 * IRQs can happen and the stats can be updated.
53 	 *
54 	 * However, we use the raw seqcount helpers to interact with this lock
55 	 * to avoid false positives from lockdep, which is unable to detect that
56 	 * our readers are never from irq or softirq context, and that, for CPU
57 	 * job queues, even the write side never is.
58 	 */
59 	seqcount_t lock;
60 
61 	atomic_t reset_counter;
62 };
63 
64 struct v3d_queue_state {
65 	struct drm_gpu_scheduler sched;
66 
67 	u64 fence_context;
68 	u64 emit_seqno;
69 
70 	/* Stores the GPU stats for this queue in the global context. */
71 	struct v3d_stats *stats;
72 
73 	/* Currently active job for this queue */
74 	struct v3d_job *active_job;
75 	spinlock_t queue_lock;
76 };
77 
78 /* Performance monitor object
79  *
80  * The performance monitor (perfmon) lifetime is controlled by userspace using
81  * perfmon related ioctls. A perfmon can be attached to a CL or CSD submission
82  * request, and when it is, HW performance counters will be activated just
83  * before the job is submitted to the GPU and disabled when the job is done.
84  * This way, only events related to a specific submission will be counted.
85  */
86 struct v3d_perfmon {
87 	/* Tracks the number of users of the perfmon, when this counter reaches
88 	 * zero the perfmon is destroyed.
89 	 */
90 	refcount_t refcnt;
91 
92 	/* Number of counters activated in this perfmon instance
93 	 * (should be less than DRM_V3D_MAX_PERF_COUNTERS).
94 	 */
95 	u8 ncounters;
96 
97 	/* Events counted by the HW perf counters. */
98 	u8 counters[DRM_V3D_MAX_PERF_COUNTERS];
99 
100 	/* Storage for counter values. Counters are incremented by the
101 	 * HW perf counter values every time the perfmon is attached
102 	 * to a GPU job.  This way, perfmon users don't have to
103 	 * retrieve the results after each job if they want to track
104 	 * events covering several submissions.  Note that counter
105 	 * values can't be reset, but you can fake a reset by
106 	 * destroying the perfmon and creating a new one.
107 	 */
108 	u64 values[] __counted_by(ncounters);
109 };
110 
111 enum v3d_gen {
112 	V3D_GEN_33 = 33,
113 	V3D_GEN_41 = 41,
114 	V3D_GEN_42 = 42,
115 	V3D_GEN_71 = 71,
116 };
117 
118 enum v3d_irq {
119 	V3D_CORE_IRQ,
120 	V3D_HUB_IRQ,
121 	V3D_MAX_IRQS,
122 };
123 
124 struct v3d_dev {
125 	struct drm_device drm;
126 
127 	/* Short representation (e.g. 33, 41) of the V3D tech version */
128 	enum v3d_gen ver;
129 
130 	/* Short representation (e.g. 5, 6) of the V3D tech revision */
131 	int rev;
132 
133 	bool single_irq_line;
134 
135 	int irq[V3D_MAX_IRQS];
136 
137 	struct v3d_perfmon_info perfmon_info;
138 
139 	void __iomem *hub_regs;
140 	void __iomem *core_regs[3];
141 	void __iomem *bridge_regs;
142 	void __iomem *gca_regs;
143 	void __iomem *sms_regs;
144 	struct clk *clk;
145 	struct reset_control *reset;
146 
147 	/* Virtual and DMA addresses of the single shared page table. */
148 	volatile u32 *pt;
149 	dma_addr_t pt_paddr;
150 
151 	/* Virtual and DMA addresses of the MMU's scratch page.  When
152 	 * a read or write is invalid in the MMU, it will be
153 	 * redirected here.
154 	 */
155 	void *mmu_scratch;
156 	dma_addr_t mmu_scratch_paddr;
157 	/* virtual address bits from V3D to the MMU. */
158 	int va_width;
159 
160 	/* Number of V3D cores. */
161 	u32 cores;
162 
163 	/* Allocator managing the address space.  All units are in
164 	 * number of pages.
165 	 */
166 	struct drm_mm mm;
167 	spinlock_t mm_lock;
168 
169 	struct work_struct overflow_mem_work;
170 
171 	struct v3d_queue_state queue[V3D_MAX_QUEUES];
172 
173 	/*
174 	 * Tracks the performance monitor state and consistency.
175 	 *
176 	 * When a non-global perfmon is attached to a job, the scheduler must
177 	 * not run any other job on the HW concurrently (otherwise, the
178 	 * counters would be polluted by unrelated work).
179 	 */
180 	struct {
181 		/* Protects @active. */
182 		spinlock_t lock;
183 
184 		/* Perfmon currently programmed in HW (or NULL if none). */
185 		struct v3d_perfmon *active;
186 
187 		/* Finished fence of the most recently submitted job that
188 		 * opened a serialization window (i.e. a job with a non-global
189 		 * perfmon attached).
190 		 */
191 		struct dma_fence *fence;
192 
193 		/* Finished fence of the most recently submitted job on each HW
194 		 * queue. Used so that a new perfmon-carrying job can depend on
195 		 * every job currently in-flight across all queues.
196 		 */
197 		struct dma_fence *last_hw_fence[V3D_MAX_QUEUES];
198 	} perfmon_state;
199 
200 	/* Protects bo_stats */
201 	struct mutex bo_lock;
202 
203 	/* Lock taken when resetting the GPU, to keep multiple
204 	 * processes from trying to park the scheduler threads and
205 	 * reset at once.
206 	 */
207 	struct mutex reset_lock;
208 
209 	/* Ordered workqueue shared by every queue's scheduler timeout work.
210 	 * V3D reset is global to all queues, so the timeout handlers must not
211 	 * run concurrently.
212 	 */
213 	struct workqueue_struct *reset_wq;
214 
215 	/* Lock taken when creating and pushing the GPU scheduler
216 	 * jobs, to keep the sched-fence seqnos in order.
217 	 */
218 	struct mutex sched_lock;
219 
220 	/* Lock taken during a cache clean and when initiating an L2
221 	 * flush, to keep L2 flushes from interfering with the
222 	 * synchronous L2 cleans.
223 	 */
224 	struct mutex cache_clean_lock;
225 
226 	struct {
227 		u32 num_allocated;
228 		u32 pages_allocated;
229 	} bo_stats;
230 
231 	/* To support a performance analysis tool in user space, we require
232 	 * a single, globally configured performance monitor (perfmon) for
233 	 * all jobs.
234 	 */
235 	struct v3d_perfmon *global_perfmon;
236 
237 	/* Global reset counter incremented on each GPU reset. */
238 	atomic_t reset_counter;
239 };
240 
241 static inline struct v3d_dev *
242 to_v3d_dev(struct drm_device *dev)
243 {
244 	return container_of(dev, struct v3d_dev, drm);
245 }
246 
247 static inline bool
248 v3d_has_csd(struct v3d_dev *v3d)
249 {
250 	return v3d->ver >= V3D_GEN_41;
251 }
252 
253 #define v3d_to_pdev(v3d) to_platform_device((v3d)->drm.dev)
254 
255 /* The per-fd struct, which tracks the MMU mappings. */
256 struct v3d_file_priv {
257 	struct v3d_dev *v3d;
258 
259 	struct xarray perfmons;
260 
261 	struct drm_sched_entity sched_entity[V3D_MAX_QUEUES];
262 
263 	/* Stores the GPU stats for a specific queue for this fd. */
264 	struct v3d_stats *stats[V3D_MAX_QUEUES];
265 };
266 
267 struct v3d_bo {
268 	struct drm_gem_shmem_object base;
269 
270 	struct drm_mm_node node;
271 
272 	/* List entry for the BO's position in
273 	 * v3d_render_job->unref_list
274 	 */
275 	struct list_head unref_head;
276 
277 	void *vaddr;
278 };
279 
280 static inline struct v3d_bo *
281 to_v3d_bo(struct drm_gem_object *bo)
282 {
283 	return (struct v3d_bo *)bo;
284 }
285 
286 struct v3d_fence {
287 	struct dma_fence base;
288 	struct drm_device *dev;
289 	/* v3d seqno for signaled() test */
290 	u64 seqno;
291 	enum v3d_queue queue;
292 };
293 
294 static inline struct v3d_fence *
295 to_v3d_fence(struct dma_fence *fence)
296 {
297 	return (struct v3d_fence *)fence;
298 }
299 
300 #define V3D_READ(offset) readl(v3d->hub_regs + offset)
301 #define V3D_WRITE(offset, val) writel(val, v3d->hub_regs + offset)
302 
303 #define V3D_BRIDGE_READ(offset) readl(v3d->bridge_regs + offset)
304 #define V3D_BRIDGE_WRITE(offset, val) writel(val, v3d->bridge_regs + offset)
305 
306 #define V3D_GCA_READ(offset) readl(v3d->gca_regs + offset)
307 #define V3D_GCA_WRITE(offset, val) writel(val, v3d->gca_regs + offset)
308 
309 #define V3D_SMS_IDLE				0x0
310 #define V3D_SMS_ISOLATING_FOR_RESET		0xa
311 #define V3D_SMS_RESETTING			0xb
312 #define V3D_SMS_ISOLATING_FOR_POWER_OFF	0xc
313 #define V3D_SMS_POWER_OFF_STATE		0xd
314 
315 #define V3D_SMS_READ(offset) readl(v3d->sms_regs + (offset))
316 #define V3D_SMS_WRITE(offset, val) writel(val, v3d->sms_regs + (offset))
317 
318 #define V3D_CORE_READ(core, offset) readl(v3d->core_regs[core] + offset)
319 #define V3D_CORE_WRITE(core, offset, val) writel(val, v3d->core_regs[core] + offset)
320 
321 #define V3D_MAX_JOBS_PER_SUBMISSION 3
322 
323 /* Per-ioctl submission context */
324 struct v3d_submit {
325 	struct v3d_dev *v3d;
326 
327 	struct drm_file *file_priv;
328 
329 	/* DRM exec context for this submission. */
330 	struct drm_exec exec;
331 
332 	/* Ordered array of jobs forming the submission chain. Jobs are
333 	 * appended via v3d_submit_add_job(), then chained and pushed to
334 	 * the scheduler by v3d_submit_jobs().
335 	 */
336 	struct v3d_job *jobs[V3D_MAX_JOBS_PER_SUBMISSION];
337 
338 	/* Number of jobs currently in @jobs. */
339 	u32 job_count;
340 };
341 
342 struct v3d_job {
343 	struct drm_sched_job base;
344 
345 	struct kref refcount;
346 
347 	struct v3d_dev *v3d;
348 
349 	/* The queue that the job was submitted on. */
350 	enum v3d_queue queue;
351 
352 	/* This is the array of BOs that were looked up at the start
353 	 * of submission.
354 	 */
355 	struct drm_gem_object **bo;
356 	u32 bo_count;
357 
358 	/* v3d fence to be signaled by IRQ handler when the job is complete. */
359 	struct dma_fence *irq_fence;
360 
361 	/* scheduler fence for when the job is considered complete and
362 	 * the BO reservations can be released.
363 	 */
364 	struct dma_fence *done_fence;
365 
366 	/* Pointer to a performance monitor object if the user requested it,
367 	 * NULL otherwise.
368 	 */
369 	struct v3d_perfmon *perfmon;
370 
371 	/* File descriptor of the process that submitted the job that could be used
372 	 * to collect per-process information about the GPU.
373 	 */
374 	struct v3d_file_priv *file_priv;
375 
376 	/* Pointers to this job's per-fd and global queue stats. */
377 	struct v3d_stats *client_stats;
378 	struct v3d_stats *global_stats;
379 
380 	/* Callback for the freeing of the job on refcount going to 0. */
381 	void (*free)(struct kref *ref);
382 
383 	bool has_pm_ref;
384 
385 	/* Whether the job needs implicit dependencies, i.e. must wait for
386 	 * other contexts still writing its BOs.
387 	 */
388 	bool has_implicit_dep;
389 };
390 
391 struct v3d_bin_job {
392 	struct v3d_job base;
393 
394 	/* GPU virtual addresses of the start/end of the CL job. */
395 	u32 start, end;
396 
397 	u32 timedout_ctca, timedout_ctra;
398 
399 	/* Corresponding render job, for attaching our overflow memory. */
400 	struct v3d_render_job *render;
401 
402 	/* Submitted tile memory allocation start/size, tile state. */
403 	u32 qma, qms, qts;
404 };
405 
406 struct v3d_render_job {
407 	struct v3d_job base;
408 
409 	/* GPU virtual addresses of the start/end of the CL job. */
410 	u32 start, end;
411 
412 	u32 timedout_ctca, timedout_ctra;
413 
414 	/* List of overflow BOs used in the job that need to be
415 	 * released once the job is complete.
416 	 */
417 	struct list_head unref_list;
418 };
419 
420 struct v3d_tfu_job {
421 	struct v3d_job base;
422 
423 	struct drm_v3d_submit_tfu args;
424 };
425 
426 struct v3d_csd_job {
427 	struct v3d_job base;
428 
429 	u32 timedout_batches;
430 
431 	struct drm_v3d_submit_csd args;
432 };
433 
434 enum v3d_cpu_job_type {
435 	V3D_CPU_JOB_TYPE_INDIRECT_CSD = 1,
436 	V3D_CPU_JOB_TYPE_TIMESTAMP_QUERY,
437 	V3D_CPU_JOB_TYPE_RESET_TIMESTAMP_QUERY,
438 	V3D_CPU_JOB_TYPE_COPY_TIMESTAMP_QUERY,
439 	V3D_CPU_JOB_TYPE_RESET_PERFORMANCE_QUERY,
440 	V3D_CPU_JOB_TYPE_COPY_PERFORMANCE_QUERY,
441 };
442 
443 struct v3d_timestamp_query {
444 	/* Offset of this query in the timestamp BO for its value. */
445 	u32 offset;
446 
447 	/* Syncobj that indicates the timestamp availability */
448 	struct drm_syncobj *syncobj;
449 };
450 
451 struct v3d_performance_query {
452 	/* Performance monitor IDs for this query */
453 	u32 *kperfmon_ids;
454 
455 	/* Syncobj that indicates the query availability */
456 	struct drm_syncobj *syncobj;
457 };
458 
459 struct v3d_indirect_csd_info {
460 	/* Indirect CSD */
461 	struct v3d_csd_job *job;
462 
463 	/* Indirect CSD args, stashed by the extension parser and later used
464 	 * to create the CSD job from them.
465 	 */
466 	struct drm_v3d_submit_csd args;
467 
468 	/* Offset within the BO where the workgroup counts are stored */
469 	u32 offset;
470 
471 	/* Workgroups size */
472 	u32 wg_size;
473 
474 	/* Indices of the uniforms with the workgroup dispatch counts
475 	 * in the uniform stream.
476 	 */
477 	u32 wg_uniform_offsets[3];
478 
479 	/* Indirect BO */
480 	struct drm_gem_object *indirect;
481 };
482 
483 struct v3d_timestamp_query_info {
484 	struct v3d_timestamp_query *queries;
485 
486 	u32 count;
487 };
488 
489 struct v3d_performance_query_info {
490 	struct v3d_performance_query *queries;
491 
492 	/* Number of performance queries */
493 	u32 count;
494 
495 	/* Number of performance monitors related to that query pool */
496 	u32 nperfmons;
497 
498 	/* Number of performance counters related to that query pool */
499 	u32 ncounters;
500 };
501 
502 struct v3d_copy_query_results_info {
503 	/* Define if should write to buffer using 64 or 32 bits */
504 	bool do_64bit;
505 
506 	/* Define if it can write to buffer even if the query is not available */
507 	bool do_partial;
508 
509 	/* Define if it should write availability bit to buffer */
510 	bool availability_bit;
511 
512 	/* Offset of the copy buffer in the BO */
513 	u32 offset;
514 
515 	/* Stride of the copy buffer in the BO */
516 	u32 stride;
517 };
518 
519 struct v3d_cpu_job {
520 	struct v3d_job base;
521 
522 	enum v3d_cpu_job_type job_type;
523 
524 	struct v3d_indirect_csd_info indirect_csd;
525 
526 	struct v3d_timestamp_query_info timestamp_query;
527 
528 	struct v3d_copy_query_results_info copy;
529 
530 	struct v3d_performance_query_info performance_query;
531 };
532 
533 typedef void (*v3d_cpu_job_fn)(struct v3d_cpu_job *);
534 
535 struct v3d_submit_outsync {
536 	struct drm_syncobj *syncobj;
537 };
538 
539 struct v3d_submit_ext {
540 	u32 flags;
541 	u32 wait_stage;
542 
543 	u32 in_sync_count;
544 	u64 in_syncs;
545 
546 	u32 out_sync_count;
547 	struct v3d_submit_outsync *out_syncs;
548 };
549 
550 /**
551  * __wait_for - magic wait macro
552  *
553  * Macro to help avoid open coding check/wait/timeout patterns. Note that it's
554  * important that we check the condition again after having timed out, since the
555  * timeout could be due to preemption or similar and we've never had a chance to
556  * check the condition before the timeout.
557  */
558 #define __wait_for(OP, COND, US, Wmin, Wmax) ({ \
559 	const ktime_t end__ = ktime_add_ns(ktime_get_raw(), 1000ll * (US)); \
560 	long wait__ = (Wmin); /* recommended min for usleep is 10 us */	\
561 	int ret__;							\
562 	might_sleep();							\
563 	for (;;) {							\
564 		const bool expired__ = ktime_after(ktime_get_raw(), end__); \
565 		OP;							\
566 		/* Guarantee COND check prior to timeout */		\
567 		barrier();						\
568 		if (COND) {						\
569 			ret__ = 0;					\
570 			break;						\
571 		}							\
572 		if (expired__) {					\
573 			ret__ = -ETIMEDOUT;				\
574 			break;						\
575 		}							\
576 		usleep_range(wait__, wait__ * 2);			\
577 		if (wait__ < (Wmax))					\
578 			wait__ <<= 1;					\
579 	}								\
580 	ret__;								\
581 })
582 
583 #define _wait_for(COND, US, Wmin, Wmax)	__wait_for(, (COND), (US), (Wmin), \
584 						   (Wmax))
585 #define wait_for(COND, MS)		_wait_for((COND), (MS) * 1000, 10, 1000)
586 
587 static inline unsigned long nsecs_to_jiffies_timeout(const u64 n)
588 {
589 	/* nsecs_to_jiffies64() does not guard against overflow */
590 	if ((NSEC_PER_SEC % HZ) != 0 &&
591 	    div_u64(n, NSEC_PER_SEC) >= MAX_JIFFY_OFFSET / HZ)
592 		return MAX_JIFFY_OFFSET;
593 
594 	return min_t(u64, MAX_JIFFY_OFFSET, nsecs_to_jiffies64(n) + 1);
595 }
596 
597 /* v3d_bo.c */
598 struct drm_gem_object *v3d_create_object(struct drm_device *dev, size_t size);
599 void v3d_free_object(struct drm_gem_object *gem_obj);
600 struct v3d_bo *v3d_bo_create(struct drm_device *dev, struct drm_file *file_priv,
601 			     size_t size);
602 void v3d_get_bo_vaddr(struct v3d_bo *bo);
603 void v3d_put_bo_vaddr(struct v3d_bo *bo);
604 int v3d_create_bo_ioctl(struct drm_device *dev, void *data,
605 			struct drm_file *file_priv);
606 int v3d_mmap_bo_ioctl(struct drm_device *dev, void *data,
607 		      struct drm_file *file_priv);
608 int v3d_get_bo_offset_ioctl(struct drm_device *dev, void *data,
609 			    struct drm_file *file_priv);
610 int v3d_wait_bo_ioctl(struct drm_device *dev, void *data,
611 		      struct drm_file *file_priv);
612 struct drm_gem_object *v3d_prime_import_sg_table(struct drm_device *dev,
613 						 struct dma_buf_attachment *attach,
614 						 struct sg_table *sgt);
615 
616 /* v3d_debugfs.c */
617 void v3d_debugfs_init(struct drm_minor *minor);
618 
619 /* v3d_drv.c */
620 void v3d_get_stats(const struct v3d_stats *stats, u64 timestamp,
621 		   u64 *active_runtime, u64 *jobs_completed);
622 
623 /* v3d_fence.c */
624 extern const struct dma_fence_ops v3d_fence_ops;
625 struct dma_fence *v3d_fence_create(struct v3d_dev *v3d, enum v3d_queue q);
626 
627 /* v3d_gem.c */
628 extern bool super_pages;
629 void v3d_init_hw_state(struct v3d_dev *v3d);
630 int v3d_gem_init(struct drm_device *dev);
631 void v3d_gem_destroy(struct drm_device *dev);
632 void v3d_idle_axi(struct v3d_dev *v3d, int core);
633 void v3d_idle_gca(struct v3d_dev *v3d);
634 void v3d_reset_sms(struct v3d_dev *v3d);
635 void v3d_reset(struct v3d_dev *v3d);
636 void v3d_invalidate_caches(struct v3d_dev *v3d);
637 void v3d_clean_caches(struct v3d_dev *v3d);
638 
639 /* v3d_submit.c */
640 void v3d_job_cleanup(struct v3d_job *job);
641 void v3d_job_put(struct v3d_job *job);
642 int v3d_submit_cl_ioctl(struct drm_device *dev, void *data,
643 			struct drm_file *file_priv);
644 int v3d_submit_tfu_ioctl(struct drm_device *dev, void *data,
645 			 struct drm_file *file_priv);
646 int v3d_submit_csd_ioctl(struct drm_device *dev, void *data,
647 			 struct drm_file *file_priv);
648 int v3d_submit_cpu_ioctl(struct drm_device *dev, void *data,
649 			 struct drm_file *file_priv);
650 
651 /* v3d_irq.c */
652 int v3d_irq_init(struct v3d_dev *v3d);
653 void v3d_irq_enable(struct v3d_dev *v3d);
654 void v3d_irq_disable(struct v3d_dev *v3d);
655 void v3d_irq_reset(struct v3d_dev *v3d);
656 
657 /* v3d_mmu.c */
658 int v3d_mmu_flush_all(struct v3d_dev *v3d);
659 int v3d_mmu_set_page_table(struct v3d_dev *v3d);
660 void v3d_mmu_insert_ptes(struct v3d_bo *bo);
661 void v3d_mmu_remove_ptes(struct v3d_bo *bo);
662 
663 /* v3d_power.c */
664 int v3d_power_suspend(struct device *dev);
665 int v3d_power_resume(struct device *dev);
666 
667 static __always_inline int v3d_pm_runtime_get(struct v3d_dev *v3d)
668 {
669 	return pm_runtime_resume_and_get(v3d->drm.dev);
670 }
671 
672 static __always_inline int v3d_pm_runtime_put(struct v3d_dev *v3d)
673 {
674 	return pm_runtime_put_autosuspend(v3d->drm.dev);
675 }
676 
677 /* v3d_sched.c */
678 void v3d_timestamp_query_info_free(struct v3d_timestamp_query_info *query_info,
679 				   unsigned int count);
680 void v3d_performance_query_info_free(struct v3d_performance_query_info *query_info,
681 				     unsigned int count);
682 struct v3d_stats *v3d_stats_alloc(void);
683 void v3d_stats_release(struct kref *refcount);
684 void v3d_job_update_stats(struct v3d_job *job);
685 int v3d_sched_init(struct v3d_dev *v3d);
686 void v3d_sched_fini(struct v3d_dev *v3d);
687 
688 static inline struct v3d_stats *v3d_stats_get(struct v3d_stats *stats)
689 {
690 	kref_get(&stats->refcount);
691 	return stats;
692 }
693 
694 static inline void v3d_stats_put(struct v3d_stats *stats)
695 {
696 	kref_put(&stats->refcount, v3d_stats_release);
697 }
698 
699 /* v3d_perfmon.c */
700 void v3d_perfmon_init(struct v3d_dev *v3d);
701 void v3d_perfmon_get(struct v3d_perfmon *perfmon);
702 void v3d_perfmon_put(struct v3d_perfmon *perfmon);
703 void v3d_perfmon_start(struct v3d_dev *v3d, struct v3d_perfmon *perfmon);
704 void v3d_perfmon_stop(struct v3d_dev *v3d, struct v3d_perfmon *perfmon,
705 		      bool capture);
706 void v3d_perfmon_stop_locked(struct v3d_dev *v3d, struct v3d_perfmon *perfmon,
707 			     bool capture);
708 void v3d_perfmon_suspend(struct v3d_dev *v3d);
709 void v3d_perfmon_resume(struct v3d_dev *v3d);
710 struct v3d_perfmon *v3d_perfmon_find(struct v3d_file_priv *v3d_priv, int id);
711 void v3d_perfmon_open_file(struct v3d_file_priv *v3d_priv);
712 void v3d_perfmon_close_file(struct v3d_file_priv *v3d_priv);
713 int v3d_perfmon_create_ioctl(struct drm_device *dev, void *data,
714 			     struct drm_file *file_priv);
715 int v3d_perfmon_destroy_ioctl(struct drm_device *dev, void *data,
716 			      struct drm_file *file_priv);
717 int v3d_perfmon_get_values_ioctl(struct drm_device *dev, void *data,
718 				 struct drm_file *file_priv);
719 int v3d_perfmon_get_counter_ioctl(struct drm_device *dev, void *data,
720 				  struct drm_file *file_priv);
721 int v3d_perfmon_set_global_ioctl(struct drm_device *dev, void *data,
722 				 struct drm_file *file_priv);
723 
724 /* v3d_sysfs.c */
725 int v3d_sysfs_init(struct device *dev);
726 void v3d_sysfs_destroy(struct device *dev);
727