1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2c8b75bcaSEric Anholt /*
3c8b75bcaSEric Anholt * Copyright (C) 2015 Broadcom
4c8b75bcaSEric Anholt */
56a88752cSMaxime Ripard #ifndef _VC4_DRV_H_
66a88752cSMaxime Ripard #define _VC4_DRV_H_
7c8b75bcaSEric Anholt
8*33d5ae6cSJani Nikula #include <linux/debugfs.h>
9fd6d6d80SSam Ravnborg #include <linux/delay.h>
1073289afeSVille Syrjälä #include <linux/of.h>
11fd6d6d80SSam Ravnborg #include <linux/refcount.h>
12fd6d6d80SSam Ravnborg #include <linux/uaccess.h>
13fd6d6d80SSam Ravnborg
14fd6d6d80SSam Ravnborg #include <drm/drm_atomic.h>
15fd6d6d80SSam Ravnborg #include <drm/drm_debugfs.h>
16fd6d6d80SSam Ravnborg #include <drm/drm_device.h>
179338203cSLaurent Pinchart #include <drm/drm_encoder.h>
184a83c26aSDanilo Krummrich #include <drm/drm_gem_dma_helper.h>
191c80be48SMaxime Ripard #include <drm/drm_managed.h>
20fd6d6d80SSam Ravnborg #include <drm/drm_mm.h>
21fd6d6d80SSam Ravnborg #include <drm/drm_modeset_lock.h>
229338203cSLaurent Pinchart
23da43ff04SMaxime Ripard #include <kunit/test-bug.h>
24da43ff04SMaxime Ripard
2565101d8cSBoris Brezillon #include "uapi/drm/vc4_drm.h"
2665101d8cSBoris Brezillon
27fd6d6d80SSam Ravnborg struct drm_device;
28fd6d6d80SSam Ravnborg struct drm_gem_object;
29fd6d6d80SSam Ravnborg
30f759f5b5SMaxime Ripard extern const struct drm_driver vc4_drm_driver;
31f759f5b5SMaxime Ripard extern const struct drm_driver vc5_drm_driver;
32f759f5b5SMaxime Ripard
33f3099462SEric Anholt /* Don't forget to update vc4_bo.c: bo_type_names[] when adding to
34f3099462SEric Anholt * this.
35f3099462SEric Anholt */
36f3099462SEric Anholt enum vc4_kernel_bo_type {
37f3099462SEric Anholt /* Any kernel allocation (gem_create_object hook) before it
38f3099462SEric Anholt * gets another type set.
39f3099462SEric Anholt */
40f3099462SEric Anholt VC4_BO_TYPE_KERNEL,
41f3099462SEric Anholt VC4_BO_TYPE_V3D,
42f3099462SEric Anholt VC4_BO_TYPE_V3D_SHADER,
43f3099462SEric Anholt VC4_BO_TYPE_DUMB,
44f3099462SEric Anholt VC4_BO_TYPE_BIN,
45f3099462SEric Anholt VC4_BO_TYPE_RCL,
46f3099462SEric Anholt VC4_BO_TYPE_BCL,
47f3099462SEric Anholt VC4_BO_TYPE_KERNEL_CACHE,
48f3099462SEric Anholt VC4_BO_TYPE_COUNT
49f3099462SEric Anholt };
50f3099462SEric Anholt
5165101d8cSBoris Brezillon /* Performance monitor object. The perform lifetime is controlled by userspace
5265101d8cSBoris Brezillon * using perfmon related ioctls. A perfmon can be attached to a submit_cl
5365101d8cSBoris Brezillon * request, and when this is the case, HW perf counters will be activated just
5465101d8cSBoris Brezillon * before the submit_cl is submitted to the GPU and disabled when the job is
5565101d8cSBoris Brezillon * done. This way, only events related to a specific job will be counted.
5665101d8cSBoris Brezillon */
5765101d8cSBoris Brezillon struct vc4_perfmon {
5830f8c74cSMaxime Ripard struct vc4_dev *dev;
5930f8c74cSMaxime Ripard
6065101d8cSBoris Brezillon /* Tracks the number of users of the perfmon, when this counter reaches
6165101d8cSBoris Brezillon * zero the perfmon is destroyed.
6265101d8cSBoris Brezillon */
6365101d8cSBoris Brezillon refcount_t refcnt;
6465101d8cSBoris Brezillon
6565101d8cSBoris Brezillon /* Number of counters activated in this perfmon instance
6665101d8cSBoris Brezillon * (should be less than DRM_VC4_MAX_PERF_COUNTERS).
6765101d8cSBoris Brezillon */
6865101d8cSBoris Brezillon u8 ncounters;
6965101d8cSBoris Brezillon
7065101d8cSBoris Brezillon /* Events counted by the HW perf counters. */
7165101d8cSBoris Brezillon u8 events[DRM_VC4_MAX_PERF_COUNTERS];
7265101d8cSBoris Brezillon
7365101d8cSBoris Brezillon /* Storage for counter values. Counters are incremented by the HW
7465101d8cSBoris Brezillon * perf counter values every time the perfmon is attached to a GPU job.
7565101d8cSBoris Brezillon * This way, perfmon users don't have to retrieve the results after
7665101d8cSBoris Brezillon * each job if they want to track events covering several submissions.
7765101d8cSBoris Brezillon * Note that counter values can't be reset, but you can fake a reset by
7865101d8cSBoris Brezillon * destroying the perfmon and creating a new one.
7965101d8cSBoris Brezillon */
80b16cc13bSKees Cook u64 counters[] __counted_by(ncounters);
8165101d8cSBoris Brezillon };
8265101d8cSBoris Brezillon
83c8b75bcaSEric Anholt struct vc4_dev {
8484d7d472SMaxime Ripard struct drm_device base;
856cf61bf4SMaxime Ripard struct device *dev;
86c8b75bcaSEric Anholt
871cbc91ebSMaxime Ripard bool is_vc5;
881cbc91ebSMaxime Ripard
895226711eSThomas Zimmermann unsigned int irq;
905226711eSThomas Zimmermann
91c8b75bcaSEric Anholt struct vc4_hvs *hvs;
92d3f5168aSEric Anholt struct vc4_v3d *v3d;
9348666d56SDerek Foreman
9421461365SEric Anholt struct vc4_hang_state *hang_state;
9521461365SEric Anholt
96c826a6e1SEric Anholt /* The kernel-space BO cache. Tracks buffers that have been
97c826a6e1SEric Anholt * unreferenced by all other users (refcounts of 0!) but not
98c826a6e1SEric Anholt * yet freed, so we can do cheap allocations.
99c826a6e1SEric Anholt */
100c826a6e1SEric Anholt struct vc4_bo_cache {
101c826a6e1SEric Anholt /* Array of list heads for entries in the BO cache,
102c826a6e1SEric Anholt * based on number of pages, so we can do O(1) lookups
103c826a6e1SEric Anholt * in the cache when allocating.
104c826a6e1SEric Anholt */
105c826a6e1SEric Anholt struct list_head *size_list;
106c826a6e1SEric Anholt uint32_t size_list_size;
107c826a6e1SEric Anholt
108c826a6e1SEric Anholt /* List of all BOs in the cache, ordered by age, so we
109c826a6e1SEric Anholt * can do O(1) lookups when trying to free old
110c826a6e1SEric Anholt * buffers.
111c826a6e1SEric Anholt */
112c826a6e1SEric Anholt struct list_head time_list;
113c826a6e1SEric Anholt struct work_struct time_work;
114c826a6e1SEric Anholt struct timer_list time_timer;
115c826a6e1SEric Anholt } bo_cache;
116c826a6e1SEric Anholt
117f3099462SEric Anholt u32 num_labels;
118f3099462SEric Anholt struct vc4_label {
119f3099462SEric Anholt const char *name;
120c826a6e1SEric Anholt u32 num_allocated;
121c826a6e1SEric Anholt u32 size_allocated;
122f3099462SEric Anholt } *bo_labels;
123c826a6e1SEric Anholt
124f3099462SEric Anholt /* Protects bo_cache and bo_labels. */
125c826a6e1SEric Anholt struct mutex bo_lock;
126d5b1a78aSEric Anholt
127b9f19259SBoris Brezillon /* Purgeable BO pool. All BOs in this pool can have their memory
128b9f19259SBoris Brezillon * reclaimed if the driver is unable to allocate new BOs. We also
129b9f19259SBoris Brezillon * keep stats related to the purge mechanism here.
130b9f19259SBoris Brezillon */
131b9f19259SBoris Brezillon struct {
132b9f19259SBoris Brezillon struct list_head list;
133b9f19259SBoris Brezillon unsigned int num;
134b9f19259SBoris Brezillon size_t size;
135b9f19259SBoris Brezillon unsigned int purged_num;
136b9f19259SBoris Brezillon size_t purged_size;
137b9f19259SBoris Brezillon struct mutex lock;
138b9f19259SBoris Brezillon } purgeable;
139b9f19259SBoris Brezillon
140cdec4d36SEric Anholt uint64_t dma_fence_context;
141cdec4d36SEric Anholt
142ca26d28bSVarad Gautam /* Sequence number for the last job queued in bin_job_list.
143d5b1a78aSEric Anholt * Starts at 0 (no jobs emitted).
144d5b1a78aSEric Anholt */
145d5b1a78aSEric Anholt uint64_t emit_seqno;
146d5b1a78aSEric Anholt
147d5b1a78aSEric Anholt /* Sequence number for the last completed job on the GPU.
148d5b1a78aSEric Anholt * Starts at 0 (no jobs completed).
149d5b1a78aSEric Anholt */
150d5b1a78aSEric Anholt uint64_t finished_seqno;
151d5b1a78aSEric Anholt
152ca26d28bSVarad Gautam /* List of all struct vc4_exec_info for jobs to be executed in
153ca26d28bSVarad Gautam * the binner. The first job in the list is the one currently
154ca26d28bSVarad Gautam * programmed into ct0ca for execution.
155d5b1a78aSEric Anholt */
156ca26d28bSVarad Gautam struct list_head bin_job_list;
157ca26d28bSVarad Gautam
158ca26d28bSVarad Gautam /* List of all struct vc4_exec_info for jobs that have
159ca26d28bSVarad Gautam * completed binning and are ready for rendering. The first
160ca26d28bSVarad Gautam * job in the list is the one currently programmed into ct1ca
161ca26d28bSVarad Gautam * for execution.
162ca26d28bSVarad Gautam */
163ca26d28bSVarad Gautam struct list_head render_job_list;
164ca26d28bSVarad Gautam
165d5b1a78aSEric Anholt /* List of the finished vc4_exec_infos waiting to be freed by
166d5b1a78aSEric Anholt * job_done_work.
167d5b1a78aSEric Anholt */
168d5b1a78aSEric Anholt struct list_head job_done_list;
169d5b1a78aSEric Anholt /* Spinlock used to synchronize the job_list and seqno
170d5b1a78aSEric Anholt * accesses between the IRQ handler and GEM ioctls.
171d5b1a78aSEric Anholt */
172d5b1a78aSEric Anholt spinlock_t job_lock;
173d5b1a78aSEric Anholt wait_queue_head_t job_wait_queue;
174d5b1a78aSEric Anholt struct work_struct job_done_work;
175d5b1a78aSEric Anholt
17665101d8cSBoris Brezillon /* Used to track the active perfmon if any. Access to this field is
17765101d8cSBoris Brezillon * protected by job_lock.
17865101d8cSBoris Brezillon */
17965101d8cSBoris Brezillon struct vc4_perfmon *active_perfmon;
18065101d8cSBoris Brezillon
181b501baccSEric Anholt /* List of struct vc4_seqno_cb for callbacks to be made from a
182b501baccSEric Anholt * workqueue when the given seqno is passed.
183b501baccSEric Anholt */
184b501baccSEric Anholt struct list_head seqno_cb_list;
185b501baccSEric Anholt
186553c942fSEric Anholt /* The memory used for storing binner tile alloc, tile state,
187553c942fSEric Anholt * and overflow memory allocations. This is freed when V3D
188553c942fSEric Anholt * powers down.
189d5b1a78aSEric Anholt */
190553c942fSEric Anholt struct vc4_bo *bin_bo;
191553c942fSEric Anholt
192553c942fSEric Anholt /* Size of blocks allocated within bin_bo. */
193553c942fSEric Anholt uint32_t bin_alloc_size;
194553c942fSEric Anholt
195553c942fSEric Anholt /* Bitmask of the bin_alloc_size chunks in bin_bo that are
196553c942fSEric Anholt * used.
197553c942fSEric Anholt */
198553c942fSEric Anholt uint32_t bin_alloc_used;
199553c942fSEric Anholt
200553c942fSEric Anholt /* Bitmask of the current bin_alloc used for overflow memory. */
201553c942fSEric Anholt uint32_t bin_alloc_overflow;
202553c942fSEric Anholt
203531a1b62SBoris Brezillon /* Incremented when an underrun error happened after an atomic commit.
204531a1b62SBoris Brezillon * This is particularly useful to detect when a specific modeset is too
205531a1b62SBoris Brezillon * demanding in term of memory or HVS bandwidth which is hard to guess
206531a1b62SBoris Brezillon * at atomic check time.
207531a1b62SBoris Brezillon */
208531a1b62SBoris Brezillon atomic_t underrun;
209531a1b62SBoris Brezillon
210d5b1a78aSEric Anholt struct work_struct overflow_mem_work;
211d5b1a78aSEric Anholt
21236cb6253SEric Anholt int power_refcount;
21336cb6253SEric Anholt
2146b5c029dSPaul Kocialkowski /* Set to true when the load tracker is active. */
2156b5c029dSPaul Kocialkowski bool load_tracker_enabled;
2166b5c029dSPaul Kocialkowski
21736cb6253SEric Anholt /* Mutex controlling the power refcount. */
21836cb6253SEric Anholt struct mutex power_lock;
21936cb6253SEric Anholt
220d5b1a78aSEric Anholt struct {
221d5b1a78aSEric Anholt struct timer_list timer;
222d5b1a78aSEric Anholt struct work_struct reset_work;
223d5b1a78aSEric Anholt } hangcheck;
224d5b1a78aSEric Anholt
225766cc6b1SStefan Schake struct drm_modeset_lock ctm_state_lock;
226766cc6b1SStefan Schake struct drm_private_obj ctm_manager;
227f2df84e0SMaxime Ripard struct drm_private_obj hvs_channels;
2284686da83SBoris Brezillon struct drm_private_obj load_tracker;
229c9be804cSEric Anholt
23035c8b4b2SPaul Kocialkowski /* Mutex for binner bo allocation. */
23135c8b4b2SPaul Kocialkowski struct mutex bin_bo_lock;
23235c8b4b2SPaul Kocialkowski /* Reference count for our binner bo. */
23335c8b4b2SPaul Kocialkowski struct kref bin_bo_kref;
234c8b75bcaSEric Anholt };
235c8b75bcaSEric Anholt
2365a46e490SMaxime Ripard #define to_vc4_dev(_dev) \
2375a46e490SMaxime Ripard container_of_const(_dev, struct vc4_dev, base)
238c8b75bcaSEric Anholt
239c8b75bcaSEric Anholt struct vc4_bo {
2404a83c26aSDanilo Krummrich struct drm_gem_dma_object base;
241c826a6e1SEric Anholt
2427edabee0SEric Anholt /* seqno of the last job to render using this BO. */
243d5b1a78aSEric Anholt uint64_t seqno;
244d5b1a78aSEric Anholt
2457edabee0SEric Anholt /* seqno of the last job to use the RCL to write to this BO.
2467edabee0SEric Anholt *
2477edabee0SEric Anholt * Note that this doesn't include binner overflow memory
2487edabee0SEric Anholt * writes.
2497edabee0SEric Anholt */
2507edabee0SEric Anholt uint64_t write_seqno;
2517edabee0SEric Anholt
25283753117SEric Anholt bool t_format;
25383753117SEric Anholt
254c826a6e1SEric Anholt /* List entry for the BO's position in either
255c826a6e1SEric Anholt * vc4_exec_info->unref_list or vc4_dev->bo_cache.time_list
256c826a6e1SEric Anholt */
257c826a6e1SEric Anholt struct list_head unref_head;
258c826a6e1SEric Anholt
259c826a6e1SEric Anholt /* Time in jiffies when the BO was put in vc4->bo_cache. */
260c826a6e1SEric Anholt unsigned long free_time;
261c826a6e1SEric Anholt
262c826a6e1SEric Anholt /* List entry for the BO's position in vc4_dev->bo_cache.size_list */
263c826a6e1SEric Anholt struct list_head size_head;
264463873d5SEric Anholt
265463873d5SEric Anholt /* Struct for shader validation state, if created by
266463873d5SEric Anholt * DRM_IOCTL_VC4_CREATE_SHADER_BO.
267463873d5SEric Anholt */
268463873d5SEric Anholt struct vc4_validated_shader_info *validated_shader;
269cdec4d36SEric Anholt
270f3099462SEric Anholt /* One of enum vc4_kernel_bo_type, or VC4_BO_TYPE_COUNT + i
271f3099462SEric Anholt * for user-allocated labels.
272f3099462SEric Anholt */
273f3099462SEric Anholt int label;
274b9f19259SBoris Brezillon
275b9f19259SBoris Brezillon /* Count the number of active users. This is needed to determine
276b9f19259SBoris Brezillon * whether we can move the BO to the purgeable list or not (when the BO
277b9f19259SBoris Brezillon * is used by the GPU or the display engine we can't purge it).
278b9f19259SBoris Brezillon */
279b9f19259SBoris Brezillon refcount_t usecnt;
280b9f19259SBoris Brezillon
281b9f19259SBoris Brezillon /* Store purgeable/purged state here */
282b9f19259SBoris Brezillon u32 madv;
283b9f19259SBoris Brezillon struct mutex madv_lock;
284c8b75bcaSEric Anholt };
285c8b75bcaSEric Anholt
2865a46e490SMaxime Ripard #define to_vc4_bo(_bo) \
2875a46e490SMaxime Ripard container_of_const(to_drm_gem_dma_obj(_bo), struct vc4_bo, base)
288c8b75bcaSEric Anholt
289cdec4d36SEric Anholt struct vc4_fence {
290cdec4d36SEric Anholt struct dma_fence base;
291cdec4d36SEric Anholt struct drm_device *dev;
292cdec4d36SEric Anholt /* vc4 seqno for signaled() test */
293cdec4d36SEric Anholt uint64_t seqno;
294cdec4d36SEric Anholt };
295cdec4d36SEric Anholt
2965a46e490SMaxime Ripard #define to_vc4_fence(_fence) \
2975a46e490SMaxime Ripard container_of_const(_fence, struct vc4_fence, base)
298cdec4d36SEric Anholt
299b501baccSEric Anholt struct vc4_seqno_cb {
300b501baccSEric Anholt struct work_struct work;
301b501baccSEric Anholt uint64_t seqno;
302b501baccSEric Anholt void (*func)(struct vc4_seqno_cb *cb);
303b501baccSEric Anholt };
304b501baccSEric Anholt
305d3f5168aSEric Anholt struct vc4_v3d {
306001bdb55SEric Anholt struct vc4_dev *vc4;
307d3f5168aSEric Anholt struct platform_device *pdev;
308d3f5168aSEric Anholt void __iomem *regs;
309b72a2816SEric Anholt struct clk *clk;
3103051719aSEric Anholt struct debugfs_regset32 regset;
311d3f5168aSEric Anholt };
312d3f5168aSEric Anholt
313c8b75bcaSEric Anholt struct vc4_hvs {
3141cbc91ebSMaxime Ripard struct vc4_dev *vc4;
315c8b75bcaSEric Anholt struct platform_device *pdev;
316c8b75bcaSEric Anholt void __iomem *regs;
317d8dbf44fSEric Anholt u32 __iomem *dlist;
318d8dbf44fSEric Anholt
319d7d96c00SMaxime Ripard struct clk *core_clk;
320d7d96c00SMaxime Ripard
3212a001ca0SMaxime Ripard unsigned long max_core_rate;
3222a001ca0SMaxime Ripard
323d8dbf44fSEric Anholt /* Memory manager for CRTCs to allocate space in the display
324d8dbf44fSEric Anholt * list. Units are dwords.
325d8dbf44fSEric Anholt */
326d8dbf44fSEric Anholt struct drm_mm dlist_mm;
32721af94cfSEric Anholt /* Memory manager for the LBM memory used by HVS scaling. */
32821af94cfSEric Anholt struct drm_mm lbm_mm;
329d8dbf44fSEric Anholt spinlock_t mm_lock;
33021af94cfSEric Anholt
33121af94cfSEric Anholt struct drm_mm_node mitchell_netravali_filter;
332c54619b0SDave Stevenson
3333051719aSEric Anholt struct debugfs_regset32 regset;
3342a001ca0SMaxime Ripard
3352a001ca0SMaxime Ripard /*
3362a001ca0SMaxime Ripard * Even if HDMI0 on the RPi4 can output modes requiring a pixel
3372a001ca0SMaxime Ripard * rate higher than 297MHz, it needs some adjustments in the
3382a001ca0SMaxime Ripard * config.txt file to be able to do so and thus won't always be
3392a001ca0SMaxime Ripard * available.
3402a001ca0SMaxime Ripard */
3412a001ca0SMaxime Ripard bool vc5_hdmi_enable_hdmi_20;
342f09e172dSDom Cobley
343f09e172dSDom Cobley /*
344f09e172dSDom Cobley * 4096x2160@60 requires a core overclock to work, so register
345f09e172dSDom Cobley * whether that is sufficient.
346f09e172dSDom Cobley */
347f09e172dSDom Cobley bool vc5_hdmi_enable_4096by2160;
348c8b75bcaSEric Anholt };
349c8b75bcaSEric Anholt
3503c5cb5ecSMaxime Ripard #define HVS_NUM_CHANNELS 3
3513c5cb5ecSMaxime Ripard
3523c5cb5ecSMaxime Ripard struct vc4_hvs_state {
3533c5cb5ecSMaxime Ripard struct drm_private_state base;
3543c5cb5ecSMaxime Ripard unsigned long core_clock_rate;
3553c5cb5ecSMaxime Ripard
3563c5cb5ecSMaxime Ripard struct {
3573c5cb5ecSMaxime Ripard unsigned in_use: 1;
3583c5cb5ecSMaxime Ripard unsigned long fifo_load;
3593c5cb5ecSMaxime Ripard struct drm_crtc_commit *pending_commit;
3603c5cb5ecSMaxime Ripard } fifo_state[HVS_NUM_CHANNELS];
3613c5cb5ecSMaxime Ripard };
3623c5cb5ecSMaxime Ripard
3635a46e490SMaxime Ripard #define to_vc4_hvs_state(_state) \
3645a46e490SMaxime Ripard container_of_const(_state, struct vc4_hvs_state, base)
3653c5cb5ecSMaxime Ripard
3663c5cb5ecSMaxime Ripard struct vc4_hvs_state *vc4_hvs_get_global_state(struct drm_atomic_state *state);
3673c5cb5ecSMaxime Ripard struct vc4_hvs_state *vc4_hvs_get_old_global_state(const struct drm_atomic_state *state);
3683c5cb5ecSMaxime Ripard struct vc4_hvs_state *vc4_hvs_get_new_global_state(const struct drm_atomic_state *state);
3693c5cb5ecSMaxime Ripard
370c8b75bcaSEric Anholt struct vc4_plane {
371c8b75bcaSEric Anholt struct drm_plane base;
372c8b75bcaSEric Anholt };
373c8b75bcaSEric Anholt
3745a46e490SMaxime Ripard #define to_vc4_plane(_plane) \
3755a46e490SMaxime Ripard container_of_const(_plane, struct vc4_plane, base)
376c8b75bcaSEric Anholt
37782364698SStefan Schake enum vc4_scaling_mode {
37882364698SStefan Schake VC4_SCALING_NONE,
37982364698SStefan Schake VC4_SCALING_TPZ,
38082364698SStefan Schake VC4_SCALING_PPF,
38182364698SStefan Schake };
38282364698SStefan Schake
38382364698SStefan Schake struct vc4_plane_state {
38482364698SStefan Schake struct drm_plane_state base;
38582364698SStefan Schake /* System memory copy of the display list for this element, computed
38682364698SStefan Schake * at atomic_check time.
38782364698SStefan Schake */
38882364698SStefan Schake u32 *dlist;
38982364698SStefan Schake u32 dlist_size; /* Number of dwords allocated for the display list */
39082364698SStefan Schake u32 dlist_count; /* Number of used dwords in the display list. */
39182364698SStefan Schake
39282364698SStefan Schake /* Offset in the dlist to various words, for pageflip or
39382364698SStefan Schake * cursor updates.
39482364698SStefan Schake */
39582364698SStefan Schake u32 pos0_offset;
39682364698SStefan Schake u32 pos2_offset;
39782364698SStefan Schake u32 ptr0_offset;
3980a038c1cSBoris Brezillon u32 lbm_offset;
39982364698SStefan Schake
40082364698SStefan Schake /* Offset where the plane's dlist was last stored in the
40182364698SStefan Schake * hardware at vc4_crtc_atomic_flush() time.
40282364698SStefan Schake */
40382364698SStefan Schake u32 __iomem *hw_dlist;
40482364698SStefan Schake
40582364698SStefan Schake /* Clipped coordinates of the plane on the display. */
40682364698SStefan Schake int crtc_x, crtc_y, crtc_w, crtc_h;
40782364698SStefan Schake /* Clipped area being scanned from in the FB. */
40882364698SStefan Schake u32 src_x, src_y;
40982364698SStefan Schake
41082364698SStefan Schake u32 src_w[2], src_h[2];
41182364698SStefan Schake
41282364698SStefan Schake /* Scaling selection for the RGB/Y plane and the Cb/Cr planes. */
41382364698SStefan Schake enum vc4_scaling_mode x_scaling[2], y_scaling[2];
41482364698SStefan Schake bool is_unity;
41582364698SStefan Schake bool is_yuv;
41682364698SStefan Schake
41782364698SStefan Schake /* Offset to start scanning out from the start of the plane's
41882364698SStefan Schake * BO.
41982364698SStefan Schake */
42082364698SStefan Schake u32 offsets[3];
42182364698SStefan Schake
42282364698SStefan Schake /* Our allocation in LBM for temporary storage during scaling. */
42382364698SStefan Schake struct drm_mm_node lbm;
42482364698SStefan Schake
42582364698SStefan Schake /* Set when the plane has per-pixel alpha content or does not cover
42682364698SStefan Schake * the entire screen. This is a hint to the CRTC that it might need
42782364698SStefan Schake * to enable background color fill.
42882364698SStefan Schake */
42982364698SStefan Schake bool needs_bg_fill;
4308d938449SBoris Brezillon
4318d938449SBoris Brezillon /* Mark the dlist as initialized. Useful to avoid initializing it twice
4328d938449SBoris Brezillon * when async update is not possible.
4338d938449SBoris Brezillon */
4348d938449SBoris Brezillon bool dlist_initialized;
4354686da83SBoris Brezillon
4364686da83SBoris Brezillon /* Load of this plane on the HVS block. The load is expressed in HVS
4374686da83SBoris Brezillon * cycles/sec.
4384686da83SBoris Brezillon */
4394686da83SBoris Brezillon u64 hvs_load;
4404686da83SBoris Brezillon
4414686da83SBoris Brezillon /* Memory bandwidth needed for this plane. This is expressed in
4424686da83SBoris Brezillon * bytes/sec.
4434686da83SBoris Brezillon */
4444686da83SBoris Brezillon u64 membus_load;
44582364698SStefan Schake };
44682364698SStefan Schake
4475a46e490SMaxime Ripard #define to_vc4_plane_state(_state) \
4485a46e490SMaxime Ripard container_of_const(_state, struct vc4_plane_state, base)
44982364698SStefan Schake
450c8b75bcaSEric Anholt enum vc4_encoder_type {
451ab8df60eSBoris Brezillon VC4_ENCODER_TYPE_NONE,
452ed024b22SMaxime Ripard VC4_ENCODER_TYPE_HDMI0,
453aa2fd1caSMaxime Ripard VC4_ENCODER_TYPE_HDMI1,
454c8b75bcaSEric Anholt VC4_ENCODER_TYPE_VEC,
455c8b75bcaSEric Anholt VC4_ENCODER_TYPE_DSI0,
456c8b75bcaSEric Anholt VC4_ENCODER_TYPE_DSI1,
457c8b75bcaSEric Anholt VC4_ENCODER_TYPE_SMI,
458c8b75bcaSEric Anholt VC4_ENCODER_TYPE_DPI,
459b998eb4fSMaxime Ripard VC4_ENCODER_TYPE_TXP,
460c8b75bcaSEric Anholt };
461c8b75bcaSEric Anholt
462c8b75bcaSEric Anholt struct vc4_encoder {
463c8b75bcaSEric Anholt struct drm_encoder base;
464c8b75bcaSEric Anholt enum vc4_encoder_type type;
465c8b75bcaSEric Anholt u32 clock_select;
466792c3132SMaxime Ripard
4678d914746SMaxime Ripard void (*pre_crtc_configure)(struct drm_encoder *encoder, struct drm_atomic_state *state);
4688d914746SMaxime Ripard void (*pre_crtc_enable)(struct drm_encoder *encoder, struct drm_atomic_state *state);
4698d914746SMaxime Ripard void (*post_crtc_enable)(struct drm_encoder *encoder, struct drm_atomic_state *state);
470792c3132SMaxime Ripard
4718d914746SMaxime Ripard void (*post_crtc_disable)(struct drm_encoder *encoder, struct drm_atomic_state *state);
4728d914746SMaxime Ripard void (*post_crtc_powerdown)(struct drm_encoder *encoder, struct drm_atomic_state *state);
473c8b75bcaSEric Anholt };
474c8b75bcaSEric Anholt
4755a46e490SMaxime Ripard #define to_vc4_encoder(_encoder) \
4765a46e490SMaxime Ripard container_of_const(_encoder, struct vc4_encoder, base)
477c8b75bcaSEric Anholt
4780656ce12SMaxime Ripard static inline
vc4_find_encoder_by_type(struct drm_device * drm,enum vc4_encoder_type type)4790656ce12SMaxime Ripard struct drm_encoder *vc4_find_encoder_by_type(struct drm_device *drm,
4800656ce12SMaxime Ripard enum vc4_encoder_type type)
4810656ce12SMaxime Ripard {
4820656ce12SMaxime Ripard struct drm_encoder *encoder;
4830656ce12SMaxime Ripard
4840656ce12SMaxime Ripard drm_for_each_encoder(encoder, drm) {
4850656ce12SMaxime Ripard struct vc4_encoder *vc4_encoder = to_vc4_encoder(encoder);
4860656ce12SMaxime Ripard
4870656ce12SMaxime Ripard if (vc4_encoder->type == type)
4880656ce12SMaxime Ripard return encoder;
4890656ce12SMaxime Ripard }
4900656ce12SMaxime Ripard
4910656ce12SMaxime Ripard return NULL;
4920656ce12SMaxime Ripard }
4930656ce12SMaxime Ripard
49479271807SStefan Schake struct vc4_crtc_data {
4959a49bf09SMaxime Ripard const char *name;
4969a49bf09SMaxime Ripard
4976bad4774SMaxime Ripard const char *debugfs_name;
4986bad4774SMaxime Ripard
49987ebcd42SMaxime Ripard /* Bitmask of channels (FIFOs) of the HVS that the output can source from */
50087ebcd42SMaxime Ripard unsigned int hvs_available_channels;
50187ebcd42SMaxime Ripard
5028ebb2cf0SMaxime Ripard /* Which output of the HVS this pixelvalve sources from. */
5038ebb2cf0SMaxime Ripard int hvs_output;
5045a20ff8bSMaxime Ripard };
5055a20ff8bSMaxime Ripard
506f759f5b5SMaxime Ripard extern const struct vc4_crtc_data vc4_txp_crtc_data;
507f759f5b5SMaxime Ripard
5085a20ff8bSMaxime Ripard struct vc4_pv_data {
5095a20ff8bSMaxime Ripard struct vc4_crtc_data base;
51079271807SStefan Schake
511649abf2fSMaxime Ripard /* Depth of the PixelValve FIFO in bytes */
512649abf2fSMaxime Ripard unsigned int fifo_depth;
513649abf2fSMaxime Ripard
514644df22fSMaxime Ripard /* Number of pixels output per clock period */
515644df22fSMaxime Ripard u8 pixels_per_clock;
516644df22fSMaxime Ripard
51779271807SStefan Schake enum vc4_encoder_type encoder_types[4];
51879271807SStefan Schake };
51979271807SStefan Schake
520f759f5b5SMaxime Ripard extern const struct vc4_pv_data bcm2835_pv0_data;
521f759f5b5SMaxime Ripard extern const struct vc4_pv_data bcm2835_pv1_data;
522f759f5b5SMaxime Ripard extern const struct vc4_pv_data bcm2835_pv2_data;
523f759f5b5SMaxime Ripard extern const struct vc4_pv_data bcm2711_pv0_data;
524f759f5b5SMaxime Ripard extern const struct vc4_pv_data bcm2711_pv1_data;
525f759f5b5SMaxime Ripard extern const struct vc4_pv_data bcm2711_pv2_data;
526f759f5b5SMaxime Ripard extern const struct vc4_pv_data bcm2711_pv3_data;
527f759f5b5SMaxime Ripard extern const struct vc4_pv_data bcm2711_pv4_data;
528f759f5b5SMaxime Ripard
52979271807SStefan Schake struct vc4_crtc {
53079271807SStefan Schake struct drm_crtc base;
5313051719aSEric Anholt struct platform_device *pdev;
53279271807SStefan Schake const struct vc4_crtc_data *data;
53379271807SStefan Schake void __iomem *regs;
53479271807SStefan Schake
53579271807SStefan Schake /* Timestamp at start of vblank irq - unaffected by lock delays. */
53679271807SStefan Schake ktime_t t_vblank;
53779271807SStefan Schake
53879271807SStefan Schake u8 lut_r[256];
53979271807SStefan Schake u8 lut_g[256];
54079271807SStefan Schake u8 lut_b[256];
54179271807SStefan Schake
54279271807SStefan Schake struct drm_pending_vblank_event *event;
5433051719aSEric Anholt
5443051719aSEric Anholt struct debugfs_regset32 regset;
545a16c6640SMaxime Ripard
546a16c6640SMaxime Ripard /**
547a16c6640SMaxime Ripard * @feeds_txp: True if the CRTC feeds our writeback controller.
548a16c6640SMaxime Ripard */
549a16c6640SMaxime Ripard bool feeds_txp;
5500c250c15SMaxime Ripard
5510c250c15SMaxime Ripard /**
5520c250c15SMaxime Ripard * @irq_lock: Spinlock protecting the resources shared between
5530c250c15SMaxime Ripard * the atomic code and our vblank handler.
5540c250c15SMaxime Ripard */
5550c250c15SMaxime Ripard spinlock_t irq_lock;
5560c250c15SMaxime Ripard
5570c250c15SMaxime Ripard /**
5580c250c15SMaxime Ripard * @current_dlist: Start offset of the display list currently
5590c250c15SMaxime Ripard * set in the HVS for that CRTC. Protected by @irq_lock, and
5600c250c15SMaxime Ripard * copied in vc4_hvs_update_dlist() for the CRTC interrupt
5610c250c15SMaxime Ripard * handler to have access to that value.
5620c250c15SMaxime Ripard */
5630c250c15SMaxime Ripard unsigned int current_dlist;
564eeb6ab46SMaxime Ripard
565eeb6ab46SMaxime Ripard /**
566eeb6ab46SMaxime Ripard * @current_hvs_channel: HVS channel currently assigned to the
567eeb6ab46SMaxime Ripard * CRTC. Protected by @irq_lock, and copied in
568eeb6ab46SMaxime Ripard * vc4_hvs_atomic_begin() for the CRTC interrupt handler to have
569eeb6ab46SMaxime Ripard * access to that value.
570eeb6ab46SMaxime Ripard */
571eeb6ab46SMaxime Ripard unsigned int current_hvs_channel;
57279271807SStefan Schake };
57379271807SStefan Schake
5745a46e490SMaxime Ripard #define to_vc4_crtc(_crtc) \
5755a46e490SMaxime Ripard container_of_const(_crtc, struct vc4_crtc, base)
57679271807SStefan Schake
5775a20ff8bSMaxime Ripard static inline const struct vc4_crtc_data *
vc4_crtc_to_vc4_crtc_data(const struct vc4_crtc * crtc)5785a20ff8bSMaxime Ripard vc4_crtc_to_vc4_crtc_data(const struct vc4_crtc *crtc)
5795a20ff8bSMaxime Ripard {
5805a20ff8bSMaxime Ripard return crtc->data;
5815a20ff8bSMaxime Ripard }
5825a20ff8bSMaxime Ripard
5835a20ff8bSMaxime Ripard static inline const struct vc4_pv_data *
vc4_crtc_to_vc4_pv_data(const struct vc4_crtc * crtc)5845a20ff8bSMaxime Ripard vc4_crtc_to_vc4_pv_data(const struct vc4_crtc *crtc)
5855a20ff8bSMaxime Ripard {
5865a20ff8bSMaxime Ripard const struct vc4_crtc_data *data = vc4_crtc_to_vc4_crtc_data(crtc);
5875a20ff8bSMaxime Ripard
5885a46e490SMaxime Ripard return container_of_const(data, struct vc4_pv_data, base);
5895a20ff8bSMaxime Ripard }
5905a20ff8bSMaxime Ripard
591d0229c36SMaxime Ripard struct drm_encoder *vc4_get_crtc_encoder(struct drm_crtc *crtc,
59294c1adc4SMaxime Ripard struct drm_crtc_state *state);
593d0229c36SMaxime Ripard
594ae44a527SMaxime Ripard struct vc4_crtc_state {
595ae44a527SMaxime Ripard struct drm_crtc_state base;
596ae44a527SMaxime Ripard /* Dlist area for this CRTC configuration. */
597ae44a527SMaxime Ripard struct drm_mm_node mm;
598ae44a527SMaxime Ripard bool txp_armed;
59987ebcd42SMaxime Ripard unsigned int assigned_channel;
600ae44a527SMaxime Ripard
601ae44a527SMaxime Ripard struct {
602ae44a527SMaxime Ripard unsigned int left;
603ae44a527SMaxime Ripard unsigned int right;
604ae44a527SMaxime Ripard unsigned int top;
605ae44a527SMaxime Ripard unsigned int bottom;
606ae44a527SMaxime Ripard } margins;
6072820526dSMaxime Ripard
60816e10105SMaxime Ripard unsigned long hvs_load;
60916e10105SMaxime Ripard
6102820526dSMaxime Ripard /* Transitional state below, only valid during atomic commits */
6112820526dSMaxime Ripard bool update_muxing;
612ae44a527SMaxime Ripard };
613ae44a527SMaxime Ripard
6148ba0b6d1SMaxime Ripard #define VC4_HVS_CHANNEL_DISABLED ((unsigned int)-1)
6158ba0b6d1SMaxime Ripard
6165a46e490SMaxime Ripard #define to_vc4_crtc_state(_state) \
6175a46e490SMaxime Ripard container_of_const(_state, struct vc4_crtc_state, base)
618ae44a527SMaxime Ripard
619da43ff04SMaxime Ripard #define V3D_READ(offset) \
620da43ff04SMaxime Ripard ({ \
621da43ff04SMaxime Ripard kunit_fail_current_test("Accessing a register in a unit test!\n"); \
622da43ff04SMaxime Ripard readl(vc4->v3d->regs + (offset)); \
623da43ff04SMaxime Ripard })
624da43ff04SMaxime Ripard
625da43ff04SMaxime Ripard #define V3D_WRITE(offset, val) \
626da43ff04SMaxime Ripard do { \
627da43ff04SMaxime Ripard kunit_fail_current_test("Accessing a register in a unit test!\n"); \
628da43ff04SMaxime Ripard writel(val, vc4->v3d->regs + (offset)); \
629da43ff04SMaxime Ripard } while (0)
630da43ff04SMaxime Ripard
631da43ff04SMaxime Ripard #define HVS_READ(offset) \
632da43ff04SMaxime Ripard ({ \
633da43ff04SMaxime Ripard kunit_fail_current_test("Accessing a register in a unit test!\n"); \
634da43ff04SMaxime Ripard readl(hvs->regs + (offset)); \
635da43ff04SMaxime Ripard })
636da43ff04SMaxime Ripard
637da43ff04SMaxime Ripard #define HVS_WRITE(offset, val) \
638da43ff04SMaxime Ripard do { \
639da43ff04SMaxime Ripard kunit_fail_current_test("Accessing a register in a unit test!\n"); \
640da43ff04SMaxime Ripard writel(val, hvs->regs + (offset)); \
641da43ff04SMaxime Ripard } while (0)
642c8b75bcaSEric Anholt
6433051719aSEric Anholt #define VC4_REG32(reg) { .name = #reg, .offset = reg }
6443051719aSEric Anholt
645d5b1a78aSEric Anholt struct vc4_exec_info {
64630f8c74cSMaxime Ripard struct vc4_dev *dev;
64730f8c74cSMaxime Ripard
648d5b1a78aSEric Anholt /* Sequence number for this bin/render job. */
649d5b1a78aSEric Anholt uint64_t seqno;
650d5b1a78aSEric Anholt
6517edabee0SEric Anholt /* Latest write_seqno of any BO that binning depends on. */
6527edabee0SEric Anholt uint64_t bin_dep_seqno;
6537edabee0SEric Anholt
654cdec4d36SEric Anholt struct dma_fence *fence;
655cdec4d36SEric Anholt
656c4ce60dcSEric Anholt /* Last current addresses the hardware was processing when the
657c4ce60dcSEric Anholt * hangcheck timer checked on us.
658c4ce60dcSEric Anholt */
659c4ce60dcSEric Anholt uint32_t last_ct0ca, last_ct1ca;
660c4ce60dcSEric Anholt
661d5b1a78aSEric Anholt /* Kernel-space copy of the ioctl arguments */
662d5b1a78aSEric Anholt struct drm_vc4_submit_cl *args;
663d5b1a78aSEric Anholt
664d5b1a78aSEric Anholt /* This is the array of BOs that were looked up at the start of exec.
665d5b1a78aSEric Anholt * Command validation will use indices into this array.
666d5b1a78aSEric Anholt */
66747c07e46SMaíra Canal struct drm_gem_object **bo;
668d5b1a78aSEric Anholt uint32_t bo_count;
669d5b1a78aSEric Anholt
6707edabee0SEric Anholt /* List of BOs that are being written by the RCL. Other than
6717edabee0SEric Anholt * the binner temporary storage, this is all the BOs written
6727edabee0SEric Anholt * by the job.
6737edabee0SEric Anholt */
6744a83c26aSDanilo Krummrich struct drm_gem_dma_object *rcl_write_bo[4];
6757edabee0SEric Anholt uint32_t rcl_write_bo_count;
6767edabee0SEric Anholt
677d5b1a78aSEric Anholt /* Pointers for our position in vc4->job_list */
678d5b1a78aSEric Anholt struct list_head head;
679d5b1a78aSEric Anholt
680d5b1a78aSEric Anholt /* List of other BOs used in the job that need to be released
681d5b1a78aSEric Anholt * once the job is complete.
682d5b1a78aSEric Anholt */
683d5b1a78aSEric Anholt struct list_head unref_list;
684d5b1a78aSEric Anholt
685d5b1a78aSEric Anholt /* Current unvalidated indices into @bo loaded by the non-hardware
686d5b1a78aSEric Anholt * VC4_PACKET_GEM_HANDLES.
687d5b1a78aSEric Anholt */
688d5b1a78aSEric Anholt uint32_t bo_index[2];
689d5b1a78aSEric Anholt
690d5b1a78aSEric Anholt /* This is the BO where we store the validated command lists, shader
691d5b1a78aSEric Anholt * records, and uniforms.
692d5b1a78aSEric Anholt */
6934a83c26aSDanilo Krummrich struct drm_gem_dma_object *exec_bo;
694d5b1a78aSEric Anholt
695d5b1a78aSEric Anholt /**
696d5b1a78aSEric Anholt * This tracks the per-shader-record state (packet 64) that
697d5b1a78aSEric Anholt * determines the length of the shader record and the offset
698d5b1a78aSEric Anholt * it's expected to be found at. It gets read in from the
699d5b1a78aSEric Anholt * command lists.
700d5b1a78aSEric Anholt */
701d5b1a78aSEric Anholt struct vc4_shader_state {
702d5b1a78aSEric Anholt uint32_t addr;
703d5b1a78aSEric Anholt /* Maximum vertex index referenced by any primitive using this
704d5b1a78aSEric Anholt * shader state.
705d5b1a78aSEric Anholt */
706d5b1a78aSEric Anholt uint32_t max_index;
707d5b1a78aSEric Anholt } *shader_state;
708d5b1a78aSEric Anholt
709d5b1a78aSEric Anholt /** How many shader states the user declared they were using. */
710d5b1a78aSEric Anholt uint32_t shader_state_size;
711d5b1a78aSEric Anholt /** How many shader state records the validator has seen. */
712d5b1a78aSEric Anholt uint32_t shader_state_count;
713d5b1a78aSEric Anholt
714d5b1a78aSEric Anholt bool found_tile_binning_mode_config_packet;
715d5b1a78aSEric Anholt bool found_start_tile_binning_packet;
716d5b1a78aSEric Anholt bool found_increment_semaphore_packet;
717d5b1a78aSEric Anholt bool found_flush;
718d5b1a78aSEric Anholt uint8_t bin_tiles_x, bin_tiles_y;
719553c942fSEric Anholt /* Physical address of the start of the tile alloc array
720553c942fSEric Anholt * (where each tile's binned CL will start)
721553c942fSEric Anholt */
722d5b1a78aSEric Anholt uint32_t tile_alloc_offset;
723553c942fSEric Anholt /* Bitmask of which binner slots are freed when this job completes. */
724553c942fSEric Anholt uint32_t bin_slots;
725d5b1a78aSEric Anholt
726d5b1a78aSEric Anholt /**
727d5b1a78aSEric Anholt * Computed addresses pointing into exec_bo where we start the
728d5b1a78aSEric Anholt * bin thread (ct0) and render thread (ct1).
729d5b1a78aSEric Anholt */
730d5b1a78aSEric Anholt uint32_t ct0ca, ct0ea;
731d5b1a78aSEric Anholt uint32_t ct1ca, ct1ea;
732d5b1a78aSEric Anholt
733d5b1a78aSEric Anholt /* Pointer to the unvalidated bin CL (if present). */
734d5b1a78aSEric Anholt void *bin_u;
735d5b1a78aSEric Anholt
736d5b1a78aSEric Anholt /* Pointers to the shader recs. These paddr gets incremented as CL
737d5b1a78aSEric Anholt * packets are relocated in validate_gl_shader_state, and the vaddrs
738d5b1a78aSEric Anholt * (u and v) get incremented and size decremented as the shader recs
739d5b1a78aSEric Anholt * themselves are validated.
740d5b1a78aSEric Anholt */
741d5b1a78aSEric Anholt void *shader_rec_u;
742d5b1a78aSEric Anholt void *shader_rec_v;
743d5b1a78aSEric Anholt uint32_t shader_rec_p;
744d5b1a78aSEric Anholt uint32_t shader_rec_size;
745d5b1a78aSEric Anholt
746d5b1a78aSEric Anholt /* Pointers to the uniform data. These pointers are incremented, and
747d5b1a78aSEric Anholt * size decremented, as each batch of uniforms is uploaded.
748d5b1a78aSEric Anholt */
749d5b1a78aSEric Anholt void *uniforms_u;
750d5b1a78aSEric Anholt void *uniforms_v;
751d5b1a78aSEric Anholt uint32_t uniforms_p;
752d5b1a78aSEric Anholt uint32_t uniforms_size;
75365101d8cSBoris Brezillon
75465101d8cSBoris Brezillon /* Pointer to a performance monitor object if the user requested it,
75565101d8cSBoris Brezillon * NULL otherwise.
75665101d8cSBoris Brezillon */
75765101d8cSBoris Brezillon struct vc4_perfmon *perfmon;
75835c8b4b2SPaul Kocialkowski
75935c8b4b2SPaul Kocialkowski /* Whether the exec has taken a reference to the binner BO, which should
76035c8b4b2SPaul Kocialkowski * happen with a VC4_PACKET_TILE_BINNING_MODE_CONFIG packet.
76135c8b4b2SPaul Kocialkowski */
76235c8b4b2SPaul Kocialkowski bool bin_bo_used;
76365101d8cSBoris Brezillon };
76465101d8cSBoris Brezillon
76565101d8cSBoris Brezillon /* Per-open file private data. Any driver-specific resource that has to be
76665101d8cSBoris Brezillon * released when the DRM file is closed should be placed here.
76765101d8cSBoris Brezillon */
76865101d8cSBoris Brezillon struct vc4_file {
76930f8c74cSMaxime Ripard struct vc4_dev *dev;
77030f8c74cSMaxime Ripard
77165101d8cSBoris Brezillon struct {
77265101d8cSBoris Brezillon struct idr idr;
77365101d8cSBoris Brezillon struct mutex lock;
77465101d8cSBoris Brezillon } perfmon;
77535c8b4b2SPaul Kocialkowski
77635c8b4b2SPaul Kocialkowski bool bin_bo_used;
777d5b1a78aSEric Anholt };
778d5b1a78aSEric Anholt
779d5b1a78aSEric Anholt static inline struct vc4_exec_info *
vc4_first_bin_job(struct vc4_dev * vc4)780ca26d28bSVarad Gautam vc4_first_bin_job(struct vc4_dev *vc4)
781d5b1a78aSEric Anholt {
78257b9f569SMasahiro Yamada return list_first_entry_or_null(&vc4->bin_job_list,
78357b9f569SMasahiro Yamada struct vc4_exec_info, head);
784ca26d28bSVarad Gautam }
785ca26d28bSVarad Gautam
786ca26d28bSVarad Gautam static inline struct vc4_exec_info *
vc4_first_render_job(struct vc4_dev * vc4)787ca26d28bSVarad Gautam vc4_first_render_job(struct vc4_dev *vc4)
788ca26d28bSVarad Gautam {
78957b9f569SMasahiro Yamada return list_first_entry_or_null(&vc4->render_job_list,
790ca26d28bSVarad Gautam struct vc4_exec_info, head);
791d5b1a78aSEric Anholt }
792d5b1a78aSEric Anholt
7939326e6f2SEric Anholt static inline struct vc4_exec_info *
vc4_last_render_job(struct vc4_dev * vc4)7949326e6f2SEric Anholt vc4_last_render_job(struct vc4_dev *vc4)
7959326e6f2SEric Anholt {
7969326e6f2SEric Anholt if (list_empty(&vc4->render_job_list))
7979326e6f2SEric Anholt return NULL;
7989326e6f2SEric Anholt return list_last_entry(&vc4->render_job_list,
7999326e6f2SEric Anholt struct vc4_exec_info, head);
8009326e6f2SEric Anholt }
8019326e6f2SEric Anholt
802c8b75bcaSEric Anholt /**
803463873d5SEric Anholt * struct vc4_texture_sample_info - saves the offsets into the UBO for texture
804463873d5SEric Anholt * setup parameters.
805463873d5SEric Anholt *
806463873d5SEric Anholt * This will be used at draw time to relocate the reference to the texture
807463873d5SEric Anholt * contents in p0, and validate that the offset combined with
808463873d5SEric Anholt * width/height/stride/etc. from p1 and p2/p3 doesn't sample outside the BO.
809463873d5SEric Anholt * Note that the hardware treats unprovided config parameters as 0, so not all
810463873d5SEric Anholt * of them need to be set up for every texure sample, and we'll store ~0 as
811463873d5SEric Anholt * the offset to mark the unused ones.
812463873d5SEric Anholt *
813463873d5SEric Anholt * See the VC4 3D architecture guide page 41 ("Texture and Memory Lookup Unit
814463873d5SEric Anholt * Setup") for definitions of the texture parameters.
815463873d5SEric Anholt */
816463873d5SEric Anholt struct vc4_texture_sample_info {
817463873d5SEric Anholt bool is_direct;
818463873d5SEric Anholt uint32_t p_offset[4];
819463873d5SEric Anholt };
820463873d5SEric Anholt
821463873d5SEric Anholt /**
822463873d5SEric Anholt * struct vc4_validated_shader_info - information about validated shaders that
823463873d5SEric Anholt * needs to be used from command list validation.
824463873d5SEric Anholt *
825463873d5SEric Anholt * For a given shader, each time a shader state record references it, we need
826463873d5SEric Anholt * to verify that the shader doesn't read more uniforms than the shader state
827463873d5SEric Anholt * record's uniform BO pointer can provide, and we need to apply relocations
828463873d5SEric Anholt * and validate the shader state record's uniforms that define the texture
829463873d5SEric Anholt * samples.
830463873d5SEric Anholt */
831463873d5SEric Anholt struct vc4_validated_shader_info {
832463873d5SEric Anholt uint32_t uniforms_size;
833463873d5SEric Anholt uint32_t uniforms_src_size;
834463873d5SEric Anholt uint32_t num_texture_samples;
835463873d5SEric Anholt struct vc4_texture_sample_info *texture_samples;
8366d45c81dSEric Anholt
8376d45c81dSEric Anholt uint32_t num_uniform_addr_offsets;
8386d45c81dSEric Anholt uint32_t *uniform_addr_offsets;
839c778cc5dSJonas Pfeil
840c778cc5dSJonas Pfeil bool is_threaded;
841463873d5SEric Anholt };
842463873d5SEric Anholt
843463873d5SEric Anholt /**
8447f2a09ecSJames Hughes * __wait_for - magic wait macro
845c8b75bcaSEric Anholt *
8467f2a09ecSJames Hughes * Macro to help avoid open coding check/wait/timeout patterns. Note that it's
8477f2a09ecSJames Hughes * important that we check the condition again after having timed out, since the
8487f2a09ecSJames Hughes * timeout could be due to preemption or similar and we've never had a chance to
8497f2a09ecSJames Hughes * check the condition before the timeout.
850c8b75bcaSEric Anholt */
8517f2a09ecSJames Hughes #define __wait_for(OP, COND, US, Wmin, Wmax) ({ \
8527f2a09ecSJames Hughes const ktime_t end__ = ktime_add_ns(ktime_get_raw(), 1000ll * (US)); \
8537f2a09ecSJames Hughes long wait__ = (Wmin); /* recommended min for usleep is 10 us */ \
8547f2a09ecSJames Hughes int ret__; \
8557f2a09ecSJames Hughes might_sleep(); \
8567f2a09ecSJames Hughes for (;;) { \
8577f2a09ecSJames Hughes const bool expired__ = ktime_after(ktime_get_raw(), end__); \
8587f2a09ecSJames Hughes OP; \
8597f2a09ecSJames Hughes /* Guarantee COND check prior to timeout */ \
8607f2a09ecSJames Hughes barrier(); \
8617f2a09ecSJames Hughes if (COND) { \
8627f2a09ecSJames Hughes ret__ = 0; \
8637f2a09ecSJames Hughes break; \
8647f2a09ecSJames Hughes } \
8657f2a09ecSJames Hughes if (expired__) { \
866c8b75bcaSEric Anholt ret__ = -ETIMEDOUT; \
867c8b75bcaSEric Anholt break; \
868c8b75bcaSEric Anholt } \
8697f2a09ecSJames Hughes usleep_range(wait__, wait__ * 2); \
8707f2a09ecSJames Hughes if (wait__ < (Wmax)) \
8717f2a09ecSJames Hughes wait__ <<= 1; \
872c8b75bcaSEric Anholt } \
873c8b75bcaSEric Anholt ret__; \
874c8b75bcaSEric Anholt })
875c8b75bcaSEric Anholt
8767f2a09ecSJames Hughes #define _wait_for(COND, US, Wmin, Wmax) __wait_for(, (COND), (US), (Wmin), \
8777f2a09ecSJames Hughes (Wmax))
8787f2a09ecSJames Hughes #define wait_for(COND, MS) _wait_for((COND), (MS) * 1000, 10, 1000)
879c8b75bcaSEric Anholt
880c8b75bcaSEric Anholt /* vc4_bo.c */
881c826a6e1SEric Anholt struct drm_gem_object *vc4_create_object(struct drm_device *dev, size_t size);
882c826a6e1SEric Anholt struct vc4_bo *vc4_bo_create(struct drm_device *dev, size_t size,
883f3099462SEric Anholt bool from_cache, enum vc4_kernel_bo_type type);
884dd2dfd44SMaxime Ripard int vc4_bo_dumb_create(struct drm_file *file_priv,
885c8b75bcaSEric Anholt struct drm_device *dev,
886c8b75bcaSEric Anholt struct drm_mode_create_dumb *args);
887d5bc60f6SEric Anholt int vc4_create_bo_ioctl(struct drm_device *dev, void *data,
888d5bc60f6SEric Anholt struct drm_file *file_priv);
889463873d5SEric Anholt int vc4_create_shader_bo_ioctl(struct drm_device *dev, void *data,
890463873d5SEric Anholt struct drm_file *file_priv);
891d5bc60f6SEric Anholt int vc4_mmap_bo_ioctl(struct drm_device *dev, void *data,
892d5bc60f6SEric Anholt struct drm_file *file_priv);
89383753117SEric Anholt int vc4_set_tiling_ioctl(struct drm_device *dev, void *data,
89483753117SEric Anholt struct drm_file *file_priv);
89583753117SEric Anholt int vc4_get_tiling_ioctl(struct drm_device *dev, void *data,
89683753117SEric Anholt struct drm_file *file_priv);
89721461365SEric Anholt int vc4_get_hang_state_ioctl(struct drm_device *dev, void *data,
89821461365SEric Anholt struct drm_file *file_priv);
899f3099462SEric Anholt int vc4_label_bo_ioctl(struct drm_device *dev, void *data,
900f3099462SEric Anholt struct drm_file *file_priv);
901f3099462SEric Anholt int vc4_bo_cache_init(struct drm_device *dev);
902b9f19259SBoris Brezillon int vc4_bo_inc_usecnt(struct vc4_bo *bo);
903b9f19259SBoris Brezillon void vc4_bo_dec_usecnt(struct vc4_bo *bo);
904b9f19259SBoris Brezillon void vc4_bo_add_to_purgeable_pool(struct vc4_bo *bo);
905b9f19259SBoris Brezillon void vc4_bo_remove_from_purgeable_pool(struct vc4_bo *bo);
906445b287eSMaxime Ripard int vc4_bo_debugfs_init(struct drm_minor *minor);
907c8b75bcaSEric Anholt
908c8b75bcaSEric Anholt /* vc4_crtc.c */
909c8b75bcaSEric Anholt extern struct platform_driver vc4_crtc_driver;
910875a4d53SMaxime Ripard int vc4_crtc_disable_at_boot(struct drm_crtc *crtc);
911ee33ac27SMaxime Ripard int __vc4_crtc_init(struct drm_device *drm, struct platform_device *pdev,
912ee33ac27SMaxime Ripard struct vc4_crtc *vc4_crtc, const struct vc4_crtc_data *data,
913ee33ac27SMaxime Ripard struct drm_plane *primary_plane,
914ee33ac27SMaxime Ripard const struct drm_crtc_funcs *crtc_funcs,
915ee33ac27SMaxime Ripard const struct drm_crtc_helper_funcs *crtc_helper_funcs,
916ee33ac27SMaxime Ripard bool feeds_txp);
9173f98076fSMaxime Ripard int vc4_crtc_init(struct drm_device *drm, struct platform_device *pdev,
9183f98076fSMaxime Ripard struct vc4_crtc *vc4_crtc, const struct vc4_crtc_data *data,
9195fefc601SMaxime Ripard const struct drm_crtc_funcs *crtc_funcs,
9203f98076fSMaxime Ripard const struct drm_crtc_helper_funcs *crtc_helper_funcs,
9213f98076fSMaxime Ripard bool feeds_txp);
922bdd96472SMaxime Ripard int vc4_page_flip(struct drm_crtc *crtc,
923bdd96472SMaxime Ripard struct drm_framebuffer *fb,
924bdd96472SMaxime Ripard struct drm_pending_vblank_event *event,
925bdd96472SMaxime Ripard uint32_t flags,
926bdd96472SMaxime Ripard struct drm_modeset_acquire_ctx *ctx);
927f759f5b5SMaxime Ripard int vc4_crtc_atomic_check(struct drm_crtc *crtc,
928f759f5b5SMaxime Ripard struct drm_atomic_state *state);
929bdd96472SMaxime Ripard struct drm_crtc_state *vc4_crtc_duplicate_state(struct drm_crtc *crtc);
930bdd96472SMaxime Ripard void vc4_crtc_destroy_state(struct drm_crtc *crtc,
931bdd96472SMaxime Ripard struct drm_crtc_state *state);
932bdd96472SMaxime Ripard void vc4_crtc_reset(struct drm_crtc *crtc);
933008095e0SBoris Brezillon void vc4_crtc_handle_vblank(struct vc4_crtc *crtc);
93468e4a69aSMaxime Ripard void vc4_crtc_send_vblank(struct drm_crtc *crtc);
935445b287eSMaxime Ripard int vc4_crtc_late_register(struct drm_crtc *crtc);
936666e7358SBoris Brezillon void vc4_crtc_get_margins(struct drm_crtc_state *state,
937e590c2b0SDan Carpenter unsigned int *left, unsigned int *right,
938666e7358SBoris Brezillon unsigned int *top, unsigned int *bottom);
939c8b75bcaSEric Anholt
940c8b75bcaSEric Anholt /* vc4_debugfs.c */
9417ce84471SWambui Karuga void vc4_debugfs_init(struct drm_minor *minor);
942c9be804cSEric Anholt #ifdef CONFIG_DEBUG_FS
943f2ede40eSMaíra Canal void vc4_debugfs_add_regset32(struct drm_device *drm,
944c9be804cSEric Anholt const char *filename,
945c9be804cSEric Anholt struct debugfs_regset32 *regset);
946c9be804cSEric Anholt #else
947c9be804cSEric Anholt
vc4_debugfs_add_regset32(struct drm_device * drm,const char * filename,struct debugfs_regset32 * regset)948f2ede40eSMaíra Canal static inline void vc4_debugfs_add_regset32(struct drm_device *drm,
949c9be804cSEric Anholt const char *filename,
950c9be804cSEric Anholt struct debugfs_regset32 *regset)
951f2ede40eSMaíra Canal {}
952c9be804cSEric Anholt #endif
953c8b75bcaSEric Anholt
954c8b75bcaSEric Anholt /* vc4_drv.c */
955c8b75bcaSEric Anholt void __iomem *vc4_ioremap_regs(struct platform_device *dev, int index);
9563d763742SMaxime Ripard int vc4_dumb_fixup_args(struct drm_mode_create_dumb *args);
957c8b75bcaSEric Anholt
95808302c35SEric Anholt /* vc4_dpi.c */
95908302c35SEric Anholt extern struct platform_driver vc4_dpi_driver;
96008302c35SEric Anholt
9614078f575SEric Anholt /* vc4_dsi.c */
9624078f575SEric Anholt extern struct platform_driver vc4_dsi_driver;
9634078f575SEric Anholt
964cdec4d36SEric Anholt /* vc4_fence.c */
965cdec4d36SEric Anholt extern const struct dma_fence_ops vc4_fence_ops;
966cdec4d36SEric Anholt
967d5b1a78aSEric Anholt /* vc4_gem.c */
968171a072bSMaxime Ripard int vc4_gem_init(struct drm_device *dev);
969d5b1a78aSEric Anholt int vc4_submit_cl_ioctl(struct drm_device *dev, void *data,
970d5b1a78aSEric Anholt struct drm_file *file_priv);
971d5b1a78aSEric Anholt int vc4_wait_seqno_ioctl(struct drm_device *dev, void *data,
972d5b1a78aSEric Anholt struct drm_file *file_priv);
973d5b1a78aSEric Anholt int vc4_wait_bo_ioctl(struct drm_device *dev, void *data,
974d5b1a78aSEric Anholt struct drm_file *file_priv);
975ca26d28bSVarad Gautam void vc4_submit_next_bin_job(struct drm_device *dev);
976ca26d28bSVarad Gautam void vc4_submit_next_render_job(struct drm_device *dev);
977ca26d28bSVarad Gautam void vc4_move_job_to_render(struct drm_device *dev, struct vc4_exec_info *exec);
978d5b1a78aSEric Anholt int vc4_wait_for_seqno(struct drm_device *dev, uint64_t seqno,
979d5b1a78aSEric Anholt uint64_t timeout_ns, bool interruptible);
980d5b1a78aSEric Anholt void vc4_job_handle_completed(struct vc4_dev *vc4);
981b501baccSEric Anholt int vc4_queue_seqno_cb(struct drm_device *dev,
982b501baccSEric Anholt struct vc4_seqno_cb *cb, uint64_t seqno,
983b501baccSEric Anholt void (*func)(struct vc4_seqno_cb *cb));
984b9f19259SBoris Brezillon int vc4_gem_madvise_ioctl(struct drm_device *dev, void *data,
985b9f19259SBoris Brezillon struct drm_file *file_priv);
986d5b1a78aSEric Anholt
987c8b75bcaSEric Anholt /* vc4_hdmi.c */
988c8b75bcaSEric Anholt extern struct platform_driver vc4_hdmi_driver;
989c8b75bcaSEric Anholt
9909a8d5e4aSBoris Brezillon /* vc4_vec.c */
991e4b81f8cSBoris Brezillon extern struct platform_driver vc4_vec_driver;
992e4b81f8cSBoris Brezillon
993008095e0SBoris Brezillon /* vc4_txp.c */
994008095e0SBoris Brezillon extern struct platform_driver vc4_txp_driver;
995008095e0SBoris Brezillon
996d5b1a78aSEric Anholt /* vc4_irq.c */
9975226711eSThomas Zimmermann void vc4_irq_enable(struct drm_device *dev);
9985226711eSThomas Zimmermann void vc4_irq_disable(struct drm_device *dev);
9995226711eSThomas Zimmermann int vc4_irq_install(struct drm_device *dev, int irq);
1000d5b1a78aSEric Anholt void vc4_irq_uninstall(struct drm_device *dev);
1001d5b1a78aSEric Anholt void vc4_irq_reset(struct drm_device *dev);
1002d5b1a78aSEric Anholt
1003c8b75bcaSEric Anholt /* vc4_hvs.c */
1004c8b75bcaSEric Anholt extern struct platform_driver vc4_hvs_driver;
1005640dbcc9SMaxime Ripard struct vc4_hvs *__vc4_hvs_alloc(struct vc4_dev *vc4, struct platform_device *pdev);
10063454f01aSMaxime Ripard void vc4_hvs_stop_channel(struct vc4_hvs *hvs, unsigned int output);
10073454f01aSMaxime Ripard int vc4_hvs_get_fifo_from_output(struct vc4_hvs *hvs, unsigned int output);
10083454f01aSMaxime Ripard u8 vc4_hvs_get_fifo_frame_count(struct vc4_hvs *hvs, unsigned int fifo);
1009ee6965c8SMaxime Ripard int vc4_hvs_atomic_check(struct drm_crtc *crtc, struct drm_atomic_state *state);
1010eeb6ab46SMaxime Ripard void vc4_hvs_atomic_begin(struct drm_crtc *crtc, struct drm_atomic_state *state);
1011ee6965c8SMaxime Ripard void vc4_hvs_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_state *state);
1012ee6965c8SMaxime Ripard void vc4_hvs_atomic_disable(struct drm_crtc *crtc, struct drm_atomic_state *state);
1013ee6965c8SMaxime Ripard void vc4_hvs_atomic_flush(struct drm_crtc *crtc, struct drm_atomic_state *state);
10143454f01aSMaxime Ripard void vc4_hvs_dump_state(struct vc4_hvs *hvs);
10153454f01aSMaxime Ripard void vc4_hvs_unmask_underrun(struct vc4_hvs *hvs, int channel);
10163454f01aSMaxime Ripard void vc4_hvs_mask_underrun(struct vc4_hvs *hvs, int channel);
1017445b287eSMaxime Ripard int vc4_hvs_debugfs_init(struct drm_minor *minor);
1018c8b75bcaSEric Anholt
1019c8b75bcaSEric Anholt /* vc4_kms.c */
1020c8b75bcaSEric Anholt int vc4_kms_load(struct drm_device *dev);
1021c8b75bcaSEric Anholt
1022c8b75bcaSEric Anholt /* vc4_plane.c */
1023c8b75bcaSEric Anholt struct drm_plane *vc4_plane_init(struct drm_device *dev,
102477c5fb12SMaxime Ripard enum drm_plane_type type,
102577c5fb12SMaxime Ripard uint32_t possible_crtcs);
10260c2a50f1SMaxime Ripard int vc4_plane_create_additional_planes(struct drm_device *dev);
1027c8b75bcaSEric Anholt u32 vc4_plane_write_dlist(struct drm_plane *plane, u32 __iomem *dlist);
10282f196b7cSDaniel Vetter u32 vc4_plane_dlist_size(const struct drm_plane_state *state);
1029b501baccSEric Anholt void vc4_plane_async_set_fb(struct drm_plane *plane,
1030b501baccSEric Anholt struct drm_framebuffer *fb);
1031463873d5SEric Anholt
1032d3f5168aSEric Anholt /* vc4_v3d.c */
1033d3f5168aSEric Anholt extern struct platform_driver vc4_v3d_driver;
1034ffc26740SEric Anholt extern const struct of_device_id vc4_v3d_dt_match[];
1035553c942fSEric Anholt int vc4_v3d_get_bin_slot(struct vc4_dev *vc4);
103635c8b4b2SPaul Kocialkowski int vc4_v3d_bin_bo_get(struct vc4_dev *vc4, bool *used);
103735c8b4b2SPaul Kocialkowski void vc4_v3d_bin_bo_put(struct vc4_dev *vc4);
1038cb74f6eeSEric Anholt int vc4_v3d_pm_get(struct vc4_dev *vc4);
1039cb74f6eeSEric Anholt void vc4_v3d_pm_put(struct vc4_dev *vc4);
1040445b287eSMaxime Ripard int vc4_v3d_debugfs_init(struct drm_minor *minor);
1041d5b1a78aSEric Anholt
1042d5b1a78aSEric Anholt /* vc4_validate.c */
1043d5b1a78aSEric Anholt int
1044d5b1a78aSEric Anholt vc4_validate_bin_cl(struct drm_device *dev,
1045d5b1a78aSEric Anholt void *validated,
1046d5b1a78aSEric Anholt void *unvalidated,
1047d5b1a78aSEric Anholt struct vc4_exec_info *exec);
1048d5b1a78aSEric Anholt
1049d5b1a78aSEric Anholt int
1050d5b1a78aSEric Anholt vc4_validate_shader_recs(struct drm_device *dev, struct vc4_exec_info *exec);
1051d5b1a78aSEric Anholt
10524a83c26aSDanilo Krummrich struct drm_gem_dma_object *vc4_use_bo(struct vc4_exec_info *exec,
1053d5b1a78aSEric Anholt uint32_t hindex);
1054d5b1a78aSEric Anholt
1055d5b1a78aSEric Anholt int vc4_get_rcl(struct drm_device *dev, struct vc4_exec_info *exec);
1056d5b1a78aSEric Anholt
1057d5b1a78aSEric Anholt bool vc4_check_tex_size(struct vc4_exec_info *exec,
10584a83c26aSDanilo Krummrich struct drm_gem_dma_object *fbo,
1059d5b1a78aSEric Anholt uint32_t offset, uint8_t tiling_format,
1060d5b1a78aSEric Anholt uint32_t width, uint32_t height, uint8_t cpp);
1061d3f5168aSEric Anholt
1062463873d5SEric Anholt /* vc4_validate_shader.c */
1063463873d5SEric Anholt struct vc4_validated_shader_info *
10644a83c26aSDanilo Krummrich vc4_validate_shader(struct drm_gem_dma_object *shader_obj);
106565101d8cSBoris Brezillon
106665101d8cSBoris Brezillon /* vc4_perfmon.c */
106765101d8cSBoris Brezillon void vc4_perfmon_get(struct vc4_perfmon *perfmon);
106865101d8cSBoris Brezillon void vc4_perfmon_put(struct vc4_perfmon *perfmon);
106965101d8cSBoris Brezillon void vc4_perfmon_start(struct vc4_dev *vc4, struct vc4_perfmon *perfmon);
107065101d8cSBoris Brezillon void vc4_perfmon_stop(struct vc4_dev *vc4, struct vc4_perfmon *perfmon,
107165101d8cSBoris Brezillon bool capture);
107265101d8cSBoris Brezillon struct vc4_perfmon *vc4_perfmon_find(struct vc4_file *vc4file, int id);
107365101d8cSBoris Brezillon void vc4_perfmon_open_file(struct vc4_file *vc4file);
107465101d8cSBoris Brezillon void vc4_perfmon_close_file(struct vc4_file *vc4file);
107565101d8cSBoris Brezillon int vc4_perfmon_create_ioctl(struct drm_device *dev, void *data,
107665101d8cSBoris Brezillon struct drm_file *file_priv);
107765101d8cSBoris Brezillon int vc4_perfmon_destroy_ioctl(struct drm_device *dev, void *data,
107865101d8cSBoris Brezillon struct drm_file *file_priv);
107965101d8cSBoris Brezillon int vc4_perfmon_get_values_ioctl(struct drm_device *dev, void *data,
108065101d8cSBoris Brezillon struct drm_file *file_priv);
10816a88752cSMaxime Ripard
10826a88752cSMaxime Ripard #endif /* _VC4_DRV_H_ */
1083