]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/gpu/drm/vc4/vc4_drv.h
drm/vc4: drop use of drmP.h
[linux.git] / drivers / gpu / drm / vc4 / vc4_drv.h
1 /*
2  * Copyright (C) 2015 Broadcom
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  */
8
9 #include <linux/delay.h>
10 #include <linux/refcount.h>
11 #include <linux/uaccess.h>
12
13 #include <drm/drm_atomic.h>
14 #include <drm/drm_debugfs.h>
15 #include <drm/drm_device.h>
16 #include <drm/drm_encoder.h>
17 #include <drm/drm_gem_cma_helper.h>
18 #include <drm/drm_mm.h>
19 #include <drm/drm_modeset_lock.h>
20
21 #include "uapi/drm/vc4_drm.h"
22
23 struct drm_device;
24 struct drm_gem_object;
25
26 /* Don't forget to update vc4_bo.c: bo_type_names[] when adding to
27  * this.
28  */
29 enum vc4_kernel_bo_type {
30         /* Any kernel allocation (gem_create_object hook) before it
31          * gets another type set.
32          */
33         VC4_BO_TYPE_KERNEL,
34         VC4_BO_TYPE_V3D,
35         VC4_BO_TYPE_V3D_SHADER,
36         VC4_BO_TYPE_DUMB,
37         VC4_BO_TYPE_BIN,
38         VC4_BO_TYPE_RCL,
39         VC4_BO_TYPE_BCL,
40         VC4_BO_TYPE_KERNEL_CACHE,
41         VC4_BO_TYPE_COUNT
42 };
43
44 /* Performance monitor object. The perform lifetime is controlled by userspace
45  * using perfmon related ioctls. A perfmon can be attached to a submit_cl
46  * request, and when this is the case, HW perf counters will be activated just
47  * before the submit_cl is submitted to the GPU and disabled when the job is
48  * done. This way, only events related to a specific job will be counted.
49  */
50 struct vc4_perfmon {
51         /* Tracks the number of users of the perfmon, when this counter reaches
52          * zero the perfmon is destroyed.
53          */
54         refcount_t refcnt;
55
56         /* Number of counters activated in this perfmon instance
57          * (should be less than DRM_VC4_MAX_PERF_COUNTERS).
58          */
59         u8 ncounters;
60
61         /* Events counted by the HW perf counters. */
62         u8 events[DRM_VC4_MAX_PERF_COUNTERS];
63
64         /* Storage for counter values. Counters are incremented by the HW
65          * perf counter values every time the perfmon is attached to a GPU job.
66          * This way, perfmon users don't have to retrieve the results after
67          * each job if they want to track events covering several submissions.
68          * Note that counter values can't be reset, but you can fake a reset by
69          * destroying the perfmon and creating a new one.
70          */
71         u64 counters[0];
72 };
73
74 struct vc4_dev {
75         struct drm_device *dev;
76
77         struct vc4_hdmi *hdmi;
78         struct vc4_hvs *hvs;
79         struct vc4_v3d *v3d;
80         struct vc4_dpi *dpi;
81         struct vc4_dsi *dsi1;
82         struct vc4_vec *vec;
83         struct vc4_txp *txp;
84
85         struct vc4_hang_state *hang_state;
86
87         /* The kernel-space BO cache.  Tracks buffers that have been
88          * unreferenced by all other users (refcounts of 0!) but not
89          * yet freed, so we can do cheap allocations.
90          */
91         struct vc4_bo_cache {
92                 /* Array of list heads for entries in the BO cache,
93                  * based on number of pages, so we can do O(1) lookups
94                  * in the cache when allocating.
95                  */
96                 struct list_head *size_list;
97                 uint32_t size_list_size;
98
99                 /* List of all BOs in the cache, ordered by age, so we
100                  * can do O(1) lookups when trying to free old
101                  * buffers.
102                  */
103                 struct list_head time_list;
104                 struct work_struct time_work;
105                 struct timer_list time_timer;
106         } bo_cache;
107
108         u32 num_labels;
109         struct vc4_label {
110                 const char *name;
111                 u32 num_allocated;
112                 u32 size_allocated;
113         } *bo_labels;
114
115         /* Protects bo_cache and bo_labels. */
116         struct mutex bo_lock;
117
118         /* Purgeable BO pool. All BOs in this pool can have their memory
119          * reclaimed if the driver is unable to allocate new BOs. We also
120          * keep stats related to the purge mechanism here.
121          */
122         struct {
123                 struct list_head list;
124                 unsigned int num;
125                 size_t size;
126                 unsigned int purged_num;
127                 size_t purged_size;
128                 struct mutex lock;
129         } purgeable;
130
131         uint64_t dma_fence_context;
132
133         /* Sequence number for the last job queued in bin_job_list.
134          * Starts at 0 (no jobs emitted).
135          */
136         uint64_t emit_seqno;
137
138         /* Sequence number for the last completed job on the GPU.
139          * Starts at 0 (no jobs completed).
140          */
141         uint64_t finished_seqno;
142
143         /* List of all struct vc4_exec_info for jobs to be executed in
144          * the binner.  The first job in the list is the one currently
145          * programmed into ct0ca for execution.
146          */
147         struct list_head bin_job_list;
148
149         /* List of all struct vc4_exec_info for jobs that have
150          * completed binning and are ready for rendering.  The first
151          * job in the list is the one currently programmed into ct1ca
152          * for execution.
153          */
154         struct list_head render_job_list;
155
156         /* List of the finished vc4_exec_infos waiting to be freed by
157          * job_done_work.
158          */
159         struct list_head job_done_list;
160         /* Spinlock used to synchronize the job_list and seqno
161          * accesses between the IRQ handler and GEM ioctls.
162          */
163         spinlock_t job_lock;
164         wait_queue_head_t job_wait_queue;
165         struct work_struct job_done_work;
166
167         /* Used to track the active perfmon if any. Access to this field is
168          * protected by job_lock.
169          */
170         struct vc4_perfmon *active_perfmon;
171
172         /* List of struct vc4_seqno_cb for callbacks to be made from a
173          * workqueue when the given seqno is passed.
174          */
175         struct list_head seqno_cb_list;
176
177         /* The memory used for storing binner tile alloc, tile state,
178          * and overflow memory allocations.  This is freed when V3D
179          * powers down.
180          */
181         struct vc4_bo *bin_bo;
182
183         /* Size of blocks allocated within bin_bo. */
184         uint32_t bin_alloc_size;
185
186         /* Bitmask of the bin_alloc_size chunks in bin_bo that are
187          * used.
188          */
189         uint32_t bin_alloc_used;
190
191         /* Bitmask of the current bin_alloc used for overflow memory. */
192         uint32_t bin_alloc_overflow;
193
194         /* Incremented when an underrun error happened after an atomic commit.
195          * This is particularly useful to detect when a specific modeset is too
196          * demanding in term of memory or HVS bandwidth which is hard to guess
197          * at atomic check time.
198          */
199         atomic_t underrun;
200
201         struct work_struct overflow_mem_work;
202
203         int power_refcount;
204
205         /* Set to true when the load tracker is active. */
206         bool load_tracker_enabled;
207
208         /* Mutex controlling the power refcount. */
209         struct mutex power_lock;
210
211         struct {
212                 struct timer_list timer;
213                 struct work_struct reset_work;
214         } hangcheck;
215
216         struct semaphore async_modeset;
217
218         struct drm_modeset_lock ctm_state_lock;
219         struct drm_private_obj ctm_manager;
220         struct drm_private_obj load_tracker;
221
222         /* List of vc4_debugfs_info_entry for adding to debugfs once
223          * the minor is available (after drm_dev_register()).
224          */
225         struct list_head debugfs_list;
226
227         /* Mutex for binner bo allocation. */
228         struct mutex bin_bo_lock;
229         /* Reference count for our binner bo. */
230         struct kref bin_bo_kref;
231 };
232
233 static inline struct vc4_dev *
234 to_vc4_dev(struct drm_device *dev)
235 {
236         return (struct vc4_dev *)dev->dev_private;
237 }
238
239 struct vc4_bo {
240         struct drm_gem_cma_object base;
241
242         /* seqno of the last job to render using this BO. */
243         uint64_t seqno;
244
245         /* seqno of the last job to use the RCL to write to this BO.
246          *
247          * Note that this doesn't include binner overflow memory
248          * writes.
249          */
250         uint64_t write_seqno;
251
252         bool t_format;
253
254         /* List entry for the BO's position in either
255          * vc4_exec_info->unref_list or vc4_dev->bo_cache.time_list
256          */
257         struct list_head unref_head;
258
259         /* Time in jiffies when the BO was put in vc4->bo_cache. */
260         unsigned long free_time;
261
262         /* List entry for the BO's position in vc4_dev->bo_cache.size_list */
263         struct list_head size_head;
264
265         /* Struct for shader validation state, if created by
266          * DRM_IOCTL_VC4_CREATE_SHADER_BO.
267          */
268         struct vc4_validated_shader_info *validated_shader;
269
270         /* One of enum vc4_kernel_bo_type, or VC4_BO_TYPE_COUNT + i
271          * for user-allocated labels.
272          */
273         int label;
274
275         /* Count the number of active users. This is needed to determine
276          * whether we can move the BO to the purgeable list or not (when the BO
277          * is used by the GPU or the display engine we can't purge it).
278          */
279         refcount_t usecnt;
280
281         /* Store purgeable/purged state here */
282         u32 madv;
283         struct mutex madv_lock;
284 };
285
286 static inline struct vc4_bo *
287 to_vc4_bo(struct drm_gem_object *bo)
288 {
289         return (struct vc4_bo *)bo;
290 }
291
292 struct vc4_fence {
293         struct dma_fence base;
294         struct drm_device *dev;
295         /* vc4 seqno for signaled() test */
296         uint64_t seqno;
297 };
298
299 static inline struct vc4_fence *
300 to_vc4_fence(struct dma_fence *fence)
301 {
302         return (struct vc4_fence *)fence;
303 }
304
305 struct vc4_seqno_cb {
306         struct work_struct work;
307         uint64_t seqno;
308         void (*func)(struct vc4_seqno_cb *cb);
309 };
310
311 struct vc4_v3d {
312         struct vc4_dev *vc4;
313         struct platform_device *pdev;
314         void __iomem *regs;
315         struct clk *clk;
316         struct debugfs_regset32 regset;
317 };
318
319 struct vc4_hvs {
320         struct platform_device *pdev;
321         void __iomem *regs;
322         u32 __iomem *dlist;
323
324         /* Memory manager for CRTCs to allocate space in the display
325          * list.  Units are dwords.
326          */
327         struct drm_mm dlist_mm;
328         /* Memory manager for the LBM memory used by HVS scaling. */
329         struct drm_mm lbm_mm;
330         spinlock_t mm_lock;
331
332         struct drm_mm_node mitchell_netravali_filter;
333         struct debugfs_regset32 regset;
334 };
335
336 struct vc4_plane {
337         struct drm_plane base;
338 };
339
340 static inline struct vc4_plane *
341 to_vc4_plane(struct drm_plane *plane)
342 {
343         return (struct vc4_plane *)plane;
344 }
345
346 enum vc4_scaling_mode {
347         VC4_SCALING_NONE,
348         VC4_SCALING_TPZ,
349         VC4_SCALING_PPF,
350 };
351
352 struct vc4_plane_state {
353         struct drm_plane_state base;
354         /* System memory copy of the display list for this element, computed
355          * at atomic_check time.
356          */
357         u32 *dlist;
358         u32 dlist_size; /* Number of dwords allocated for the display list */
359         u32 dlist_count; /* Number of used dwords in the display list. */
360
361         /* Offset in the dlist to various words, for pageflip or
362          * cursor updates.
363          */
364         u32 pos0_offset;
365         u32 pos2_offset;
366         u32 ptr0_offset;
367         u32 lbm_offset;
368
369         /* Offset where the plane's dlist was last stored in the
370          * hardware at vc4_crtc_atomic_flush() time.
371          */
372         u32 __iomem *hw_dlist;
373
374         /* Clipped coordinates of the plane on the display. */
375         int crtc_x, crtc_y, crtc_w, crtc_h;
376         /* Clipped area being scanned from in the FB. */
377         u32 src_x, src_y;
378
379         u32 src_w[2], src_h[2];
380
381         /* Scaling selection for the RGB/Y plane and the Cb/Cr planes. */
382         enum vc4_scaling_mode x_scaling[2], y_scaling[2];
383         bool is_unity;
384         bool is_yuv;
385
386         /* Offset to start scanning out from the start of the plane's
387          * BO.
388          */
389         u32 offsets[3];
390
391         /* Our allocation in LBM for temporary storage during scaling. */
392         struct drm_mm_node lbm;
393
394         /* Set when the plane has per-pixel alpha content or does not cover
395          * the entire screen. This is a hint to the CRTC that it might need
396          * to enable background color fill.
397          */
398         bool needs_bg_fill;
399
400         /* Mark the dlist as initialized. Useful to avoid initializing it twice
401          * when async update is not possible.
402          */
403         bool dlist_initialized;
404
405         /* Load of this plane on the HVS block. The load is expressed in HVS
406          * cycles/sec.
407          */
408         u64 hvs_load;
409
410         /* Memory bandwidth needed for this plane. This is expressed in
411          * bytes/sec.
412          */
413         u64 membus_load;
414 };
415
416 static inline struct vc4_plane_state *
417 to_vc4_plane_state(struct drm_plane_state *state)
418 {
419         return (struct vc4_plane_state *)state;
420 }
421
422 enum vc4_encoder_type {
423         VC4_ENCODER_TYPE_NONE,
424         VC4_ENCODER_TYPE_HDMI,
425         VC4_ENCODER_TYPE_VEC,
426         VC4_ENCODER_TYPE_DSI0,
427         VC4_ENCODER_TYPE_DSI1,
428         VC4_ENCODER_TYPE_SMI,
429         VC4_ENCODER_TYPE_DPI,
430 };
431
432 struct vc4_encoder {
433         struct drm_encoder base;
434         enum vc4_encoder_type type;
435         u32 clock_select;
436 };
437
438 static inline struct vc4_encoder *
439 to_vc4_encoder(struct drm_encoder *encoder)
440 {
441         return container_of(encoder, struct vc4_encoder, base);
442 }
443
444 struct vc4_crtc_data {
445         /* Which channel of the HVS this pixelvalve sources from. */
446         int hvs_channel;
447
448         enum vc4_encoder_type encoder_types[4];
449         const char *debugfs_name;
450 };
451
452 struct vc4_crtc {
453         struct drm_crtc base;
454         struct platform_device *pdev;
455         const struct vc4_crtc_data *data;
456         void __iomem *regs;
457
458         /* Timestamp at start of vblank irq - unaffected by lock delays. */
459         ktime_t t_vblank;
460
461         /* Which HVS channel we're using for our CRTC. */
462         int channel;
463
464         u8 lut_r[256];
465         u8 lut_g[256];
466         u8 lut_b[256];
467         /* Size in pixels of the COB memory allocated to this CRTC. */
468         u32 cob_size;
469
470         struct drm_pending_vblank_event *event;
471
472         struct debugfs_regset32 regset;
473 };
474
475 static inline struct vc4_crtc *
476 to_vc4_crtc(struct drm_crtc *crtc)
477 {
478         return (struct vc4_crtc *)crtc;
479 }
480
481 #define V3D_READ(offset) readl(vc4->v3d->regs + offset)
482 #define V3D_WRITE(offset, val) writel(val, vc4->v3d->regs + offset)
483 #define HVS_READ(offset) readl(vc4->hvs->regs + offset)
484 #define HVS_WRITE(offset, val) writel(val, vc4->hvs->regs + offset)
485
486 #define VC4_REG32(reg) { .name = #reg, .offset = reg }
487
488 struct vc4_exec_info {
489         /* Sequence number for this bin/render job. */
490         uint64_t seqno;
491
492         /* Latest write_seqno of any BO that binning depends on. */
493         uint64_t bin_dep_seqno;
494
495         struct dma_fence *fence;
496
497         /* Last current addresses the hardware was processing when the
498          * hangcheck timer checked on us.
499          */
500         uint32_t last_ct0ca, last_ct1ca;
501
502         /* Kernel-space copy of the ioctl arguments */
503         struct drm_vc4_submit_cl *args;
504
505         /* This is the array of BOs that were looked up at the start of exec.
506          * Command validation will use indices into this array.
507          */
508         struct drm_gem_cma_object **bo;
509         uint32_t bo_count;
510
511         /* List of BOs that are being written by the RCL.  Other than
512          * the binner temporary storage, this is all the BOs written
513          * by the job.
514          */
515         struct drm_gem_cma_object *rcl_write_bo[4];
516         uint32_t rcl_write_bo_count;
517
518         /* Pointers for our position in vc4->job_list */
519         struct list_head head;
520
521         /* List of other BOs used in the job that need to be released
522          * once the job is complete.
523          */
524         struct list_head unref_list;
525
526         /* Current unvalidated indices into @bo loaded by the non-hardware
527          * VC4_PACKET_GEM_HANDLES.
528          */
529         uint32_t bo_index[2];
530
531         /* This is the BO where we store the validated command lists, shader
532          * records, and uniforms.
533          */
534         struct drm_gem_cma_object *exec_bo;
535
536         /**
537          * This tracks the per-shader-record state (packet 64) that
538          * determines the length of the shader record and the offset
539          * it's expected to be found at.  It gets read in from the
540          * command lists.
541          */
542         struct vc4_shader_state {
543                 uint32_t addr;
544                 /* Maximum vertex index referenced by any primitive using this
545                  * shader state.
546                  */
547                 uint32_t max_index;
548         } *shader_state;
549
550         /** How many shader states the user declared they were using. */
551         uint32_t shader_state_size;
552         /** How many shader state records the validator has seen. */
553         uint32_t shader_state_count;
554
555         bool found_tile_binning_mode_config_packet;
556         bool found_start_tile_binning_packet;
557         bool found_increment_semaphore_packet;
558         bool found_flush;
559         uint8_t bin_tiles_x, bin_tiles_y;
560         /* Physical address of the start of the tile alloc array
561          * (where each tile's binned CL will start)
562          */
563         uint32_t tile_alloc_offset;
564         /* Bitmask of which binner slots are freed when this job completes. */
565         uint32_t bin_slots;
566
567         /**
568          * Computed addresses pointing into exec_bo where we start the
569          * bin thread (ct0) and render thread (ct1).
570          */
571         uint32_t ct0ca, ct0ea;
572         uint32_t ct1ca, ct1ea;
573
574         /* Pointer to the unvalidated bin CL (if present). */
575         void *bin_u;
576
577         /* Pointers to the shader recs.  These paddr gets incremented as CL
578          * packets are relocated in validate_gl_shader_state, and the vaddrs
579          * (u and v) get incremented and size decremented as the shader recs
580          * themselves are validated.
581          */
582         void *shader_rec_u;
583         void *shader_rec_v;
584         uint32_t shader_rec_p;
585         uint32_t shader_rec_size;
586
587         /* Pointers to the uniform data.  These pointers are incremented, and
588          * size decremented, as each batch of uniforms is uploaded.
589          */
590         void *uniforms_u;
591         void *uniforms_v;
592         uint32_t uniforms_p;
593         uint32_t uniforms_size;
594
595         /* Pointer to a performance monitor object if the user requested it,
596          * NULL otherwise.
597          */
598         struct vc4_perfmon *perfmon;
599
600         /* Whether the exec has taken a reference to the binner BO, which should
601          * happen with a VC4_PACKET_TILE_BINNING_MODE_CONFIG packet.
602          */
603         bool bin_bo_used;
604 };
605
606 /* Per-open file private data. Any driver-specific resource that has to be
607  * released when the DRM file is closed should be placed here.
608  */
609 struct vc4_file {
610         struct {
611                 struct idr idr;
612                 struct mutex lock;
613         } perfmon;
614
615         bool bin_bo_used;
616 };
617
618 static inline struct vc4_exec_info *
619 vc4_first_bin_job(struct vc4_dev *vc4)
620 {
621         return list_first_entry_or_null(&vc4->bin_job_list,
622                                         struct vc4_exec_info, head);
623 }
624
625 static inline struct vc4_exec_info *
626 vc4_first_render_job(struct vc4_dev *vc4)
627 {
628         return list_first_entry_or_null(&vc4->render_job_list,
629                                         struct vc4_exec_info, head);
630 }
631
632 static inline struct vc4_exec_info *
633 vc4_last_render_job(struct vc4_dev *vc4)
634 {
635         if (list_empty(&vc4->render_job_list))
636                 return NULL;
637         return list_last_entry(&vc4->render_job_list,
638                                struct vc4_exec_info, head);
639 }
640
641 /**
642  * struct vc4_texture_sample_info - saves the offsets into the UBO for texture
643  * setup parameters.
644  *
645  * This will be used at draw time to relocate the reference to the texture
646  * contents in p0, and validate that the offset combined with
647  * width/height/stride/etc. from p1 and p2/p3 doesn't sample outside the BO.
648  * Note that the hardware treats unprovided config parameters as 0, so not all
649  * of them need to be set up for every texure sample, and we'll store ~0 as
650  * the offset to mark the unused ones.
651  *
652  * See the VC4 3D architecture guide page 41 ("Texture and Memory Lookup Unit
653  * Setup") for definitions of the texture parameters.
654  */
655 struct vc4_texture_sample_info {
656         bool is_direct;
657         uint32_t p_offset[4];
658 };
659
660 /**
661  * struct vc4_validated_shader_info - information about validated shaders that
662  * needs to be used from command list validation.
663  *
664  * For a given shader, each time a shader state record references it, we need
665  * to verify that the shader doesn't read more uniforms than the shader state
666  * record's uniform BO pointer can provide, and we need to apply relocations
667  * and validate the shader state record's uniforms that define the texture
668  * samples.
669  */
670 struct vc4_validated_shader_info {
671         uint32_t uniforms_size;
672         uint32_t uniforms_src_size;
673         uint32_t num_texture_samples;
674         struct vc4_texture_sample_info *texture_samples;
675
676         uint32_t num_uniform_addr_offsets;
677         uint32_t *uniform_addr_offsets;
678
679         bool is_threaded;
680 };
681
682 /**
683  * _wait_for - magic (register) wait macro
684  *
685  * Does the right thing for modeset paths when run under kdgb or similar atomic
686  * contexts. Note that it's important that we check the condition again after
687  * having timed out, since the timeout could be due to preemption or similar and
688  * we've never had a chance to check the condition before the timeout.
689  */
690 #define _wait_for(COND, MS, W) ({ \
691         unsigned long timeout__ = jiffies + msecs_to_jiffies(MS) + 1;   \
692         int ret__ = 0;                                                  \
693         while (!(COND)) {                                               \
694                 if (time_after(jiffies, timeout__)) {                   \
695                         if (!(COND))                                    \
696                                 ret__ = -ETIMEDOUT;                     \
697                         break;                                          \
698                 }                                                       \
699                 if (W && drm_can_sleep())  {                            \
700                         msleep(W);                                      \
701                 } else {                                                \
702                         cpu_relax();                                    \
703                 }                                                       \
704         }                                                               \
705         ret__;                                                          \
706 })
707
708 #define wait_for(COND, MS) _wait_for(COND, MS, 1)
709
710 /* vc4_bo.c */
711 struct drm_gem_object *vc4_create_object(struct drm_device *dev, size_t size);
712 void vc4_free_object(struct drm_gem_object *gem_obj);
713 struct vc4_bo *vc4_bo_create(struct drm_device *dev, size_t size,
714                              bool from_cache, enum vc4_kernel_bo_type type);
715 int vc4_dumb_create(struct drm_file *file_priv,
716                     struct drm_device *dev,
717                     struct drm_mode_create_dumb *args);
718 struct dma_buf *vc4_prime_export(struct drm_gem_object *obj, int flags);
719 int vc4_create_bo_ioctl(struct drm_device *dev, void *data,
720                         struct drm_file *file_priv);
721 int vc4_create_shader_bo_ioctl(struct drm_device *dev, void *data,
722                                struct drm_file *file_priv);
723 int vc4_mmap_bo_ioctl(struct drm_device *dev, void *data,
724                       struct drm_file *file_priv);
725 int vc4_set_tiling_ioctl(struct drm_device *dev, void *data,
726                          struct drm_file *file_priv);
727 int vc4_get_tiling_ioctl(struct drm_device *dev, void *data,
728                          struct drm_file *file_priv);
729 int vc4_get_hang_state_ioctl(struct drm_device *dev, void *data,
730                              struct drm_file *file_priv);
731 int vc4_label_bo_ioctl(struct drm_device *dev, void *data,
732                        struct drm_file *file_priv);
733 vm_fault_t vc4_fault(struct vm_fault *vmf);
734 int vc4_mmap(struct file *filp, struct vm_area_struct *vma);
735 int vc4_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma);
736 struct drm_gem_object *vc4_prime_import_sg_table(struct drm_device *dev,
737                                                  struct dma_buf_attachment *attach,
738                                                  struct sg_table *sgt);
739 void *vc4_prime_vmap(struct drm_gem_object *obj);
740 int vc4_bo_cache_init(struct drm_device *dev);
741 void vc4_bo_cache_destroy(struct drm_device *dev);
742 int vc4_bo_inc_usecnt(struct vc4_bo *bo);
743 void vc4_bo_dec_usecnt(struct vc4_bo *bo);
744 void vc4_bo_add_to_purgeable_pool(struct vc4_bo *bo);
745 void vc4_bo_remove_from_purgeable_pool(struct vc4_bo *bo);
746
747 /* vc4_crtc.c */
748 extern struct platform_driver vc4_crtc_driver;
749 bool vc4_crtc_get_scanoutpos(struct drm_device *dev, unsigned int crtc_id,
750                              bool in_vblank_irq, int *vpos, int *hpos,
751                              ktime_t *stime, ktime_t *etime,
752                              const struct drm_display_mode *mode);
753 void vc4_crtc_handle_vblank(struct vc4_crtc *crtc);
754 void vc4_crtc_txp_armed(struct drm_crtc_state *state);
755 void vc4_crtc_get_margins(struct drm_crtc_state *state,
756                           unsigned int *right, unsigned int *left,
757                           unsigned int *top, unsigned int *bottom);
758
759 /* vc4_debugfs.c */
760 int vc4_debugfs_init(struct drm_minor *minor);
761 #ifdef CONFIG_DEBUG_FS
762 void vc4_debugfs_add_file(struct drm_device *drm,
763                           const char *filename,
764                           int (*show)(struct seq_file*, void*),
765                           void *data);
766 void vc4_debugfs_add_regset32(struct drm_device *drm,
767                               const char *filename,
768                               struct debugfs_regset32 *regset);
769 #else
770 static inline void vc4_debugfs_add_file(struct drm_device *drm,
771                                         const char *filename,
772                                         int (*show)(struct seq_file*, void*),
773                                         void *data)
774 {
775 }
776
777 static inline void vc4_debugfs_add_regset32(struct drm_device *drm,
778                                             const char *filename,
779                                             struct debugfs_regset32 *regset)
780 {
781 }
782 #endif
783
784 /* vc4_drv.c */
785 void __iomem *vc4_ioremap_regs(struct platform_device *dev, int index);
786
787 /* vc4_dpi.c */
788 extern struct platform_driver vc4_dpi_driver;
789
790 /* vc4_dsi.c */
791 extern struct platform_driver vc4_dsi_driver;
792
793 /* vc4_fence.c */
794 extern const struct dma_fence_ops vc4_fence_ops;
795
796 /* vc4_gem.c */
797 void vc4_gem_init(struct drm_device *dev);
798 void vc4_gem_destroy(struct drm_device *dev);
799 int vc4_submit_cl_ioctl(struct drm_device *dev, void *data,
800                         struct drm_file *file_priv);
801 int vc4_wait_seqno_ioctl(struct drm_device *dev, void *data,
802                          struct drm_file *file_priv);
803 int vc4_wait_bo_ioctl(struct drm_device *dev, void *data,
804                       struct drm_file *file_priv);
805 void vc4_submit_next_bin_job(struct drm_device *dev);
806 void vc4_submit_next_render_job(struct drm_device *dev);
807 void vc4_move_job_to_render(struct drm_device *dev, struct vc4_exec_info *exec);
808 int vc4_wait_for_seqno(struct drm_device *dev, uint64_t seqno,
809                        uint64_t timeout_ns, bool interruptible);
810 void vc4_job_handle_completed(struct vc4_dev *vc4);
811 int vc4_queue_seqno_cb(struct drm_device *dev,
812                        struct vc4_seqno_cb *cb, uint64_t seqno,
813                        void (*func)(struct vc4_seqno_cb *cb));
814 int vc4_gem_madvise_ioctl(struct drm_device *dev, void *data,
815                           struct drm_file *file_priv);
816
817 /* vc4_hdmi.c */
818 extern struct platform_driver vc4_hdmi_driver;
819
820 /* vc4_vec.c */
821 extern struct platform_driver vc4_vec_driver;
822
823 /* vc4_txp.c */
824 extern struct platform_driver vc4_txp_driver;
825
826 /* vc4_irq.c */
827 irqreturn_t vc4_irq(int irq, void *arg);
828 void vc4_irq_preinstall(struct drm_device *dev);
829 int vc4_irq_postinstall(struct drm_device *dev);
830 void vc4_irq_uninstall(struct drm_device *dev);
831 void vc4_irq_reset(struct drm_device *dev);
832
833 /* vc4_hvs.c */
834 extern struct platform_driver vc4_hvs_driver;
835 void vc4_hvs_dump_state(struct drm_device *dev);
836 void vc4_hvs_unmask_underrun(struct drm_device *dev, int channel);
837 void vc4_hvs_mask_underrun(struct drm_device *dev, int channel);
838
839 /* vc4_kms.c */
840 int vc4_kms_load(struct drm_device *dev);
841
842 /* vc4_plane.c */
843 struct drm_plane *vc4_plane_init(struct drm_device *dev,
844                                  enum drm_plane_type type);
845 u32 vc4_plane_write_dlist(struct drm_plane *plane, u32 __iomem *dlist);
846 u32 vc4_plane_dlist_size(const struct drm_plane_state *state);
847 void vc4_plane_async_set_fb(struct drm_plane *plane,
848                             struct drm_framebuffer *fb);
849
850 /* vc4_v3d.c */
851 extern struct platform_driver vc4_v3d_driver;
852 extern const struct of_device_id vc4_v3d_dt_match[];
853 int vc4_v3d_get_bin_slot(struct vc4_dev *vc4);
854 int vc4_v3d_bin_bo_get(struct vc4_dev *vc4, bool *used);
855 void vc4_v3d_bin_bo_put(struct vc4_dev *vc4);
856 int vc4_v3d_pm_get(struct vc4_dev *vc4);
857 void vc4_v3d_pm_put(struct vc4_dev *vc4);
858
859 /* vc4_validate.c */
860 int
861 vc4_validate_bin_cl(struct drm_device *dev,
862                     void *validated,
863                     void *unvalidated,
864                     struct vc4_exec_info *exec);
865
866 int
867 vc4_validate_shader_recs(struct drm_device *dev, struct vc4_exec_info *exec);
868
869 struct drm_gem_cma_object *vc4_use_bo(struct vc4_exec_info *exec,
870                                       uint32_t hindex);
871
872 int vc4_get_rcl(struct drm_device *dev, struct vc4_exec_info *exec);
873
874 bool vc4_check_tex_size(struct vc4_exec_info *exec,
875                         struct drm_gem_cma_object *fbo,
876                         uint32_t offset, uint8_t tiling_format,
877                         uint32_t width, uint32_t height, uint8_t cpp);
878
879 /* vc4_validate_shader.c */
880 struct vc4_validated_shader_info *
881 vc4_validate_shader(struct drm_gem_cma_object *shader_obj);
882
883 /* vc4_perfmon.c */
884 void vc4_perfmon_get(struct vc4_perfmon *perfmon);
885 void vc4_perfmon_put(struct vc4_perfmon *perfmon);
886 void vc4_perfmon_start(struct vc4_dev *vc4, struct vc4_perfmon *perfmon);
887 void vc4_perfmon_stop(struct vc4_dev *vc4, struct vc4_perfmon *perfmon,
888                       bool capture);
889 struct vc4_perfmon *vc4_perfmon_find(struct vc4_file *vc4file, int id);
890 void vc4_perfmon_open_file(struct vc4_file *vc4file);
891 void vc4_perfmon_close_file(struct vc4_file *vc4file);
892 int vc4_perfmon_create_ioctl(struct drm_device *dev, void *data,
893                              struct drm_file *file_priv);
894 int vc4_perfmon_destroy_ioctl(struct drm_device *dev, void *data,
895                               struct drm_file *file_priv);
896 int vc4_perfmon_get_values_ioctl(struct drm_device *dev, void *data,
897                                  struct drm_file *file_priv);