1
2
3
4
5
6
7
8
9#include <linux/reservation.h>
10#include <drm/drmP.h>
11#include <drm/drm_encoder.h>
12#include <drm/drm_gem_cma_helper.h>
13
14
15
16
17enum vc4_kernel_bo_type {
18
19
20
21 VC4_BO_TYPE_KERNEL,
22 VC4_BO_TYPE_V3D,
23 VC4_BO_TYPE_V3D_SHADER,
24 VC4_BO_TYPE_DUMB,
25 VC4_BO_TYPE_BIN,
26 VC4_BO_TYPE_RCL,
27 VC4_BO_TYPE_BCL,
28 VC4_BO_TYPE_KERNEL_CACHE,
29 VC4_BO_TYPE_COUNT
30};
31
32struct vc4_dev {
33 struct drm_device *dev;
34
35 struct vc4_hdmi *hdmi;
36 struct vc4_hvs *hvs;
37 struct vc4_v3d *v3d;
38 struct vc4_dpi *dpi;
39 struct vc4_dsi *dsi1;
40 struct vc4_vec *vec;
41
42 struct drm_fbdev_cma *fbdev;
43
44 struct vc4_hang_state *hang_state;
45
46
47
48
49
50 struct vc4_bo_cache {
51
52
53
54
55 struct list_head *size_list;
56 uint32_t size_list_size;
57
58
59
60
61
62 struct list_head time_list;
63 struct work_struct time_work;
64 struct timer_list time_timer;
65 } bo_cache;
66
67 u32 num_labels;
68 struct vc4_label {
69 const char *name;
70 u32 num_allocated;
71 u32 size_allocated;
72 } *bo_labels;
73
74
75 struct mutex bo_lock;
76
77 uint64_t dma_fence_context;
78
79
80
81
82 uint64_t emit_seqno;
83
84
85
86
87 uint64_t finished_seqno;
88
89
90
91
92
93 struct list_head bin_job_list;
94
95
96
97
98
99
100 struct list_head render_job_list;
101
102
103
104
105 struct list_head job_done_list;
106
107
108
109 spinlock_t job_lock;
110 wait_queue_head_t job_wait_queue;
111 struct work_struct job_done_work;
112
113
114
115
116 struct list_head seqno_cb_list;
117
118
119
120
121
122 struct vc4_bo *bin_bo;
123
124
125 uint32_t bin_alloc_size;
126
127
128
129
130 uint32_t bin_alloc_used;
131
132
133 uint32_t bin_alloc_overflow;
134
135 struct work_struct overflow_mem_work;
136
137 int power_refcount;
138
139
140 struct mutex power_lock;
141
142 struct {
143 struct timer_list timer;
144 struct work_struct reset_work;
145 } hangcheck;
146
147 struct semaphore async_modeset;
148};
149
150static inline struct vc4_dev *
151to_vc4_dev(struct drm_device *dev)
152{
153 return (struct vc4_dev *)dev->dev_private;
154}
155
156struct vc4_bo {
157 struct drm_gem_cma_object base;
158
159
160 uint64_t seqno;
161
162
163
164
165
166
167 uint64_t write_seqno;
168
169 bool t_format;
170
171
172
173
174 struct list_head unref_head;
175
176
177 unsigned long free_time;
178
179
180 struct list_head size_head;
181
182
183
184
185 struct vc4_validated_shader_info *validated_shader;
186
187
188 struct reservation_object *resv;
189 struct reservation_object _resv;
190
191
192
193
194 int label;
195};
196
197static inline struct vc4_bo *
198to_vc4_bo(struct drm_gem_object *bo)
199{
200 return (struct vc4_bo *)bo;
201}
202
203struct vc4_fence {
204 struct dma_fence base;
205 struct drm_device *dev;
206
207 uint64_t seqno;
208};
209
210static inline struct vc4_fence *
211to_vc4_fence(struct dma_fence *fence)
212{
213 return (struct vc4_fence *)fence;
214}
215
216struct vc4_seqno_cb {
217 struct work_struct work;
218 uint64_t seqno;
219 void (*func)(struct vc4_seqno_cb *cb);
220};
221
222struct vc4_v3d {
223 struct vc4_dev *vc4;
224 struct platform_device *pdev;
225 void __iomem *regs;
226 struct clk *clk;
227};
228
229struct vc4_hvs {
230 struct platform_device *pdev;
231 void __iomem *regs;
232 u32 __iomem *dlist;
233
234
235
236
237 struct drm_mm dlist_mm;
238
239 struct drm_mm lbm_mm;
240 spinlock_t mm_lock;
241
242 struct drm_mm_node mitchell_netravali_filter;
243};
244
245struct vc4_plane {
246 struct drm_plane base;
247};
248
249static inline struct vc4_plane *
250to_vc4_plane(struct drm_plane *plane)
251{
252 return (struct vc4_plane *)plane;
253}
254
255enum vc4_encoder_type {
256 VC4_ENCODER_TYPE_NONE,
257 VC4_ENCODER_TYPE_HDMI,
258 VC4_ENCODER_TYPE_VEC,
259 VC4_ENCODER_TYPE_DSI0,
260 VC4_ENCODER_TYPE_DSI1,
261 VC4_ENCODER_TYPE_SMI,
262 VC4_ENCODER_TYPE_DPI,
263};
264
265struct vc4_encoder {
266 struct drm_encoder base;
267 enum vc4_encoder_type type;
268 u32 clock_select;
269};
270
271static inline struct vc4_encoder *
272to_vc4_encoder(struct drm_encoder *encoder)
273{
274 return container_of(encoder, struct vc4_encoder, base);
275}
276
277#define V3D_READ(offset) readl(vc4->v3d->regs + offset)
278#define V3D_WRITE(offset, val) writel(val, vc4->v3d->regs + offset)
279#define HVS_READ(offset) readl(vc4->hvs->regs + offset)
280#define HVS_WRITE(offset, val) writel(val, vc4->hvs->regs + offset)
281
282struct vc4_exec_info {
283
284 uint64_t seqno;
285
286
287 uint64_t bin_dep_seqno;
288
289 struct dma_fence *fence;
290
291
292
293
294 uint32_t last_ct0ca, last_ct1ca;
295
296
297 struct drm_vc4_submit_cl *args;
298
299
300
301
302 struct drm_gem_cma_object **bo;
303 uint32_t bo_count;
304
305
306
307
308
309 struct drm_gem_cma_object *rcl_write_bo[4];
310 uint32_t rcl_write_bo_count;
311
312
313 struct list_head head;
314
315
316
317
318 struct list_head unref_list;
319
320
321
322
323 uint32_t bo_index[2];
324
325
326
327
328 struct drm_gem_cma_object *exec_bo;
329
330
331
332
333
334
335
336 struct vc4_shader_state {
337 uint32_t addr;
338
339
340
341 uint32_t max_index;
342 } *shader_state;
343
344
345 uint32_t shader_state_size;
346
347 uint32_t shader_state_count;
348
349 bool found_tile_binning_mode_config_packet;
350 bool found_start_tile_binning_packet;
351 bool found_increment_semaphore_packet;
352 bool found_flush;
353 uint8_t bin_tiles_x, bin_tiles_y;
354
355
356
357 uint32_t tile_alloc_offset;
358
359 uint32_t bin_slots;
360
361
362
363
364
365 uint32_t ct0ca, ct0ea;
366 uint32_t ct1ca, ct1ea;
367
368
369 void *bin_u;
370
371
372
373
374
375
376 void *shader_rec_u;
377 void *shader_rec_v;
378 uint32_t shader_rec_p;
379 uint32_t shader_rec_size;
380
381
382
383
384 void *uniforms_u;
385 void *uniforms_v;
386 uint32_t uniforms_p;
387 uint32_t uniforms_size;
388};
389
390static inline struct vc4_exec_info *
391vc4_first_bin_job(struct vc4_dev *vc4)
392{
393 return list_first_entry_or_null(&vc4->bin_job_list,
394 struct vc4_exec_info, head);
395}
396
397static inline struct vc4_exec_info *
398vc4_first_render_job(struct vc4_dev *vc4)
399{
400 return list_first_entry_or_null(&vc4->render_job_list,
401 struct vc4_exec_info, head);
402}
403
404static inline struct vc4_exec_info *
405vc4_last_render_job(struct vc4_dev *vc4)
406{
407 if (list_empty(&vc4->render_job_list))
408 return NULL;
409 return list_last_entry(&vc4->render_job_list,
410 struct vc4_exec_info, head);
411}
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427struct vc4_texture_sample_info {
428 bool is_direct;
429 uint32_t p_offset[4];
430};
431
432
433
434
435
436
437
438
439
440
441
442struct vc4_validated_shader_info {
443 uint32_t uniforms_size;
444 uint32_t uniforms_src_size;
445 uint32_t num_texture_samples;
446 struct vc4_texture_sample_info *texture_samples;
447
448 uint32_t num_uniform_addr_offsets;
449 uint32_t *uniform_addr_offsets;
450
451 bool is_threaded;
452};
453
454
455
456
457
458
459
460
461
462#define _wait_for(COND, MS, W) ({ \
463 unsigned long timeout__ = jiffies + msecs_to_jiffies(MS) + 1; \
464 int ret__ = 0; \
465 while (!(COND)) { \
466 if (time_after(jiffies, timeout__)) { \
467 if (!(COND)) \
468 ret__ = -ETIMEDOUT; \
469 break; \
470 } \
471 if (W && drm_can_sleep()) { \
472 msleep(W); \
473 } else { \
474 cpu_relax(); \
475 } \
476 } \
477 ret__; \
478})
479
480#define wait_for(COND, MS) _wait_for(COND, MS, 1)
481
482
483struct drm_gem_object *vc4_create_object(struct drm_device *dev, size_t size);
484void vc4_free_object(struct drm_gem_object *gem_obj);
485struct vc4_bo *vc4_bo_create(struct drm_device *dev, size_t size,
486 bool from_cache, enum vc4_kernel_bo_type type);
487int vc4_dumb_create(struct drm_file *file_priv,
488 struct drm_device *dev,
489 struct drm_mode_create_dumb *args);
490struct dma_buf *vc4_prime_export(struct drm_device *dev,
491 struct drm_gem_object *obj, int flags);
492int vc4_create_bo_ioctl(struct drm_device *dev, void *data,
493 struct drm_file *file_priv);
494int vc4_create_shader_bo_ioctl(struct drm_device *dev, void *data,
495 struct drm_file *file_priv);
496int vc4_mmap_bo_ioctl(struct drm_device *dev, void *data,
497 struct drm_file *file_priv);
498int vc4_set_tiling_ioctl(struct drm_device *dev, void *data,
499 struct drm_file *file_priv);
500int vc4_get_tiling_ioctl(struct drm_device *dev, void *data,
501 struct drm_file *file_priv);
502int vc4_get_hang_state_ioctl(struct drm_device *dev, void *data,
503 struct drm_file *file_priv);
504int vc4_label_bo_ioctl(struct drm_device *dev, void *data,
505 struct drm_file *file_priv);
506int vc4_mmap(struct file *filp, struct vm_area_struct *vma);
507struct reservation_object *vc4_prime_res_obj(struct drm_gem_object *obj);
508int vc4_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma);
509struct drm_gem_object *vc4_prime_import_sg_table(struct drm_device *dev,
510 struct dma_buf_attachment *attach,
511 struct sg_table *sgt);
512void *vc4_prime_vmap(struct drm_gem_object *obj);
513int vc4_bo_cache_init(struct drm_device *dev);
514void vc4_bo_cache_destroy(struct drm_device *dev);
515int vc4_bo_stats_debugfs(struct seq_file *m, void *arg);
516
517
518extern struct platform_driver vc4_crtc_driver;
519int vc4_crtc_debugfs_regs(struct seq_file *m, void *arg);
520bool vc4_crtc_get_scanoutpos(struct drm_device *dev, unsigned int crtc_id,
521 bool in_vblank_irq, int *vpos, int *hpos,
522 ktime_t *stime, ktime_t *etime,
523 const struct drm_display_mode *mode);
524
525
526int vc4_debugfs_init(struct drm_minor *minor);
527
528
529void __iomem *vc4_ioremap_regs(struct platform_device *dev, int index);
530
531
532extern struct platform_driver vc4_dpi_driver;
533int vc4_dpi_debugfs_regs(struct seq_file *m, void *unused);
534
535
536extern struct platform_driver vc4_dsi_driver;
537int vc4_dsi_debugfs_regs(struct seq_file *m, void *unused);
538
539
540extern const struct dma_fence_ops vc4_fence_ops;
541
542
543void vc4_gem_init(struct drm_device *dev);
544void vc4_gem_destroy(struct drm_device *dev);
545int vc4_submit_cl_ioctl(struct drm_device *dev, void *data,
546 struct drm_file *file_priv);
547int vc4_wait_seqno_ioctl(struct drm_device *dev, void *data,
548 struct drm_file *file_priv);
549int vc4_wait_bo_ioctl(struct drm_device *dev, void *data,
550 struct drm_file *file_priv);
551void vc4_submit_next_bin_job(struct drm_device *dev);
552void vc4_submit_next_render_job(struct drm_device *dev);
553void vc4_move_job_to_render(struct drm_device *dev, struct vc4_exec_info *exec);
554int vc4_wait_for_seqno(struct drm_device *dev, uint64_t seqno,
555 uint64_t timeout_ns, bool interruptible);
556void vc4_job_handle_completed(struct vc4_dev *vc4);
557int vc4_queue_seqno_cb(struct drm_device *dev,
558 struct vc4_seqno_cb *cb, uint64_t seqno,
559 void (*func)(struct vc4_seqno_cb *cb));
560
561
562extern struct platform_driver vc4_hdmi_driver;
563int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused);
564
565
566extern struct platform_driver vc4_vec_driver;
567int vc4_vec_debugfs_regs(struct seq_file *m, void *unused);
568
569
570irqreturn_t vc4_irq(int irq, void *arg);
571void vc4_irq_preinstall(struct drm_device *dev);
572int vc4_irq_postinstall(struct drm_device *dev);
573void vc4_irq_uninstall(struct drm_device *dev);
574void vc4_irq_reset(struct drm_device *dev);
575
576
577extern struct platform_driver vc4_hvs_driver;
578void vc4_hvs_dump_state(struct drm_device *dev);
579int vc4_hvs_debugfs_regs(struct seq_file *m, void *unused);
580
581
582int vc4_kms_load(struct drm_device *dev);
583
584
585struct drm_plane *vc4_plane_init(struct drm_device *dev,
586 enum drm_plane_type type);
587u32 vc4_plane_write_dlist(struct drm_plane *plane, u32 __iomem *dlist);
588u32 vc4_plane_dlist_size(const struct drm_plane_state *state);
589void vc4_plane_async_set_fb(struct drm_plane *plane,
590 struct drm_framebuffer *fb);
591
592
593extern struct platform_driver vc4_v3d_driver;
594int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused);
595int vc4_v3d_debugfs_regs(struct seq_file *m, void *unused);
596int vc4_v3d_get_bin_slot(struct vc4_dev *vc4);
597
598
599int
600vc4_validate_bin_cl(struct drm_device *dev,
601 void *validated,
602 void *unvalidated,
603 struct vc4_exec_info *exec);
604
605int
606vc4_validate_shader_recs(struct drm_device *dev, struct vc4_exec_info *exec);
607
608struct drm_gem_cma_object *vc4_use_bo(struct vc4_exec_info *exec,
609 uint32_t hindex);
610
611int vc4_get_rcl(struct drm_device *dev, struct vc4_exec_info *exec);
612
613bool vc4_check_tex_size(struct vc4_exec_info *exec,
614 struct drm_gem_cma_object *fbo,
615 uint32_t offset, uint8_t tiling_format,
616 uint32_t width, uint32_t height, uint8_t cpp);
617
618
619struct vc4_validated_shader_info *
620vc4_validate_shader(struct drm_gem_cma_object *shader_obj);
621