xref: /linux/drivers/gpu/drm/vc4/vc4_drv.h (revision 6cf61bf49c9bdb9ba2d33be812d90dd406326c6c)
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 
8fd6d6d80SSam Ravnborg #include <linux/delay.h>
973289afeSVille Syrjälä #include <linux/of.h>
10fd6d6d80SSam Ravnborg #include <linux/refcount.h>
11fd6d6d80SSam Ravnborg #include <linux/uaccess.h>
12fd6d6d80SSam Ravnborg 
13fd6d6d80SSam Ravnborg #include <drm/drm_atomic.h>
14fd6d6d80SSam Ravnborg #include <drm/drm_debugfs.h>
15fd6d6d80SSam Ravnborg #include <drm/drm_device.h>
169338203cSLaurent Pinchart #include <drm/drm_encoder.h>
17b7e8e25bSMasahiro Yamada #include <drm/drm_gem_cma_helper.h>
181c80be48SMaxime Ripard #include <drm/drm_managed.h>
19fd6d6d80SSam Ravnborg #include <drm/drm_mm.h>
20fd6d6d80SSam Ravnborg #include <drm/drm_modeset_lock.h>
219338203cSLaurent Pinchart 
2265101d8cSBoris Brezillon #include "uapi/drm/vc4_drm.h"
2365101d8cSBoris Brezillon 
24fd6d6d80SSam Ravnborg struct drm_device;
25fd6d6d80SSam Ravnborg struct drm_gem_object;
26fd6d6d80SSam Ravnborg 
27f3099462SEric Anholt /* Don't forget to update vc4_bo.c: bo_type_names[] when adding to
28f3099462SEric Anholt  * this.
29f3099462SEric Anholt  */
30f3099462SEric Anholt enum vc4_kernel_bo_type {
31f3099462SEric Anholt 	/* Any kernel allocation (gem_create_object hook) before it
32f3099462SEric Anholt 	 * gets another type set.
33f3099462SEric Anholt 	 */
34f3099462SEric Anholt 	VC4_BO_TYPE_KERNEL,
35f3099462SEric Anholt 	VC4_BO_TYPE_V3D,
36f3099462SEric Anholt 	VC4_BO_TYPE_V3D_SHADER,
37f3099462SEric Anholt 	VC4_BO_TYPE_DUMB,
38f3099462SEric Anholt 	VC4_BO_TYPE_BIN,
39f3099462SEric Anholt 	VC4_BO_TYPE_RCL,
40f3099462SEric Anholt 	VC4_BO_TYPE_BCL,
41f3099462SEric Anholt 	VC4_BO_TYPE_KERNEL_CACHE,
42f3099462SEric Anholt 	VC4_BO_TYPE_COUNT
43f3099462SEric Anholt };
44f3099462SEric Anholt 
4565101d8cSBoris Brezillon /* Performance monitor object. The perform lifetime is controlled by userspace
4665101d8cSBoris Brezillon  * using perfmon related ioctls. A perfmon can be attached to a submit_cl
4765101d8cSBoris Brezillon  * request, and when this is the case, HW perf counters will be activated just
4865101d8cSBoris Brezillon  * before the submit_cl is submitted to the GPU and disabled when the job is
4965101d8cSBoris Brezillon  * done. This way, only events related to a specific job will be counted.
5065101d8cSBoris Brezillon  */
5165101d8cSBoris Brezillon struct vc4_perfmon {
5230f8c74cSMaxime Ripard 	struct vc4_dev *dev;
5330f8c74cSMaxime Ripard 
5465101d8cSBoris Brezillon 	/* Tracks the number of users of the perfmon, when this counter reaches
5565101d8cSBoris Brezillon 	 * zero the perfmon is destroyed.
5665101d8cSBoris Brezillon 	 */
5765101d8cSBoris Brezillon 	refcount_t refcnt;
5865101d8cSBoris Brezillon 
5965101d8cSBoris Brezillon 	/* Number of counters activated in this perfmon instance
6065101d8cSBoris Brezillon 	 * (should be less than DRM_VC4_MAX_PERF_COUNTERS).
6165101d8cSBoris Brezillon 	 */
6265101d8cSBoris Brezillon 	u8 ncounters;
6365101d8cSBoris Brezillon 
6465101d8cSBoris Brezillon 	/* Events counted by the HW perf counters. */
6565101d8cSBoris Brezillon 	u8 events[DRM_VC4_MAX_PERF_COUNTERS];
6665101d8cSBoris Brezillon 
6765101d8cSBoris Brezillon 	/* Storage for counter values. Counters are incremented by the HW
6865101d8cSBoris Brezillon 	 * perf counter values every time the perfmon is attached to a GPU job.
6965101d8cSBoris Brezillon 	 * This way, perfmon users don't have to retrieve the results after
7065101d8cSBoris Brezillon 	 * each job if they want to track events covering several submissions.
7165101d8cSBoris Brezillon 	 * Note that counter values can't be reset, but you can fake a reset by
7265101d8cSBoris Brezillon 	 * destroying the perfmon and creating a new one.
7365101d8cSBoris Brezillon 	 */
745b2adbddSGustavo A. R. Silva 	u64 counters[];
7565101d8cSBoris Brezillon };
7665101d8cSBoris Brezillon 
77c8b75bcaSEric Anholt struct vc4_dev {
7884d7d472SMaxime Ripard 	struct drm_device base;
79*6cf61bf4SMaxime Ripard 	struct device *dev;
80c8b75bcaSEric Anholt 
811cbc91ebSMaxime Ripard 	bool is_vc5;
821cbc91ebSMaxime Ripard 
835226711eSThomas Zimmermann 	unsigned int irq;
845226711eSThomas Zimmermann 
85c8b75bcaSEric Anholt 	struct vc4_hvs *hvs;
86d3f5168aSEric Anholt 	struct vc4_v3d *v3d;
8708302c35SEric Anholt 	struct vc4_dpi *dpi;
88e4b81f8cSBoris Brezillon 	struct vc4_vec *vec;
89008095e0SBoris Brezillon 	struct vc4_txp *txp;
9048666d56SDerek Foreman 
9121461365SEric Anholt 	struct vc4_hang_state *hang_state;
9221461365SEric Anholt 
93c826a6e1SEric Anholt 	/* The kernel-space BO cache.  Tracks buffers that have been
94c826a6e1SEric Anholt 	 * unreferenced by all other users (refcounts of 0!) but not
95c826a6e1SEric Anholt 	 * yet freed, so we can do cheap allocations.
96c826a6e1SEric Anholt 	 */
97c826a6e1SEric Anholt 	struct vc4_bo_cache {
98c826a6e1SEric Anholt 		/* Array of list heads for entries in the BO cache,
99c826a6e1SEric Anholt 		 * based on number of pages, so we can do O(1) lookups
100c826a6e1SEric Anholt 		 * in the cache when allocating.
101c826a6e1SEric Anholt 		 */
102c826a6e1SEric Anholt 		struct list_head *size_list;
103c826a6e1SEric Anholt 		uint32_t size_list_size;
104c826a6e1SEric Anholt 
105c826a6e1SEric Anholt 		/* List of all BOs in the cache, ordered by age, so we
106c826a6e1SEric Anholt 		 * can do O(1) lookups when trying to free old
107c826a6e1SEric Anholt 		 * buffers.
108c826a6e1SEric Anholt 		 */
109c826a6e1SEric Anholt 		struct list_head time_list;
110c826a6e1SEric Anholt 		struct work_struct time_work;
111c826a6e1SEric Anholt 		struct timer_list time_timer;
112c826a6e1SEric Anholt 	} bo_cache;
113c826a6e1SEric Anholt 
114f3099462SEric Anholt 	u32 num_labels;
115f3099462SEric Anholt 	struct vc4_label {
116f3099462SEric Anholt 		const char *name;
117c826a6e1SEric Anholt 		u32 num_allocated;
118c826a6e1SEric Anholt 		u32 size_allocated;
119f3099462SEric Anholt 	} *bo_labels;
120c826a6e1SEric Anholt 
121f3099462SEric Anholt 	/* Protects bo_cache and bo_labels. */
122c826a6e1SEric Anholt 	struct mutex bo_lock;
123d5b1a78aSEric Anholt 
124b9f19259SBoris Brezillon 	/* Purgeable BO pool. All BOs in this pool can have their memory
125b9f19259SBoris Brezillon 	 * reclaimed if the driver is unable to allocate new BOs. We also
126b9f19259SBoris Brezillon 	 * keep stats related to the purge mechanism here.
127b9f19259SBoris Brezillon 	 */
128b9f19259SBoris Brezillon 	struct {
129b9f19259SBoris Brezillon 		struct list_head list;
130b9f19259SBoris Brezillon 		unsigned int num;
131b9f19259SBoris Brezillon 		size_t size;
132b9f19259SBoris Brezillon 		unsigned int purged_num;
133b9f19259SBoris Brezillon 		size_t purged_size;
134b9f19259SBoris Brezillon 		struct mutex lock;
135b9f19259SBoris Brezillon 	} purgeable;
136b9f19259SBoris Brezillon 
137cdec4d36SEric Anholt 	uint64_t dma_fence_context;
138cdec4d36SEric Anholt 
139ca26d28bSVarad Gautam 	/* Sequence number for the last job queued in bin_job_list.
140d5b1a78aSEric Anholt 	 * Starts at 0 (no jobs emitted).
141d5b1a78aSEric Anholt 	 */
142d5b1a78aSEric Anholt 	uint64_t emit_seqno;
143d5b1a78aSEric Anholt 
144d5b1a78aSEric Anholt 	/* Sequence number for the last completed job on the GPU.
145d5b1a78aSEric Anholt 	 * Starts at 0 (no jobs completed).
146d5b1a78aSEric Anholt 	 */
147d5b1a78aSEric Anholt 	uint64_t finished_seqno;
148d5b1a78aSEric Anholt 
149ca26d28bSVarad Gautam 	/* List of all struct vc4_exec_info for jobs to be executed in
150ca26d28bSVarad Gautam 	 * the binner.  The first job in the list is the one currently
151ca26d28bSVarad Gautam 	 * programmed into ct0ca for execution.
152d5b1a78aSEric Anholt 	 */
153ca26d28bSVarad Gautam 	struct list_head bin_job_list;
154ca26d28bSVarad Gautam 
155ca26d28bSVarad Gautam 	/* List of all struct vc4_exec_info for jobs that have
156ca26d28bSVarad Gautam 	 * completed binning and are ready for rendering.  The first
157ca26d28bSVarad Gautam 	 * job in the list is the one currently programmed into ct1ca
158ca26d28bSVarad Gautam 	 * for execution.
159ca26d28bSVarad Gautam 	 */
160ca26d28bSVarad Gautam 	struct list_head render_job_list;
161ca26d28bSVarad Gautam 
162d5b1a78aSEric Anholt 	/* List of the finished vc4_exec_infos waiting to be freed by
163d5b1a78aSEric Anholt 	 * job_done_work.
164d5b1a78aSEric Anholt 	 */
165d5b1a78aSEric Anholt 	struct list_head job_done_list;
166d5b1a78aSEric Anholt 	/* Spinlock used to synchronize the job_list and seqno
167d5b1a78aSEric Anholt 	 * accesses between the IRQ handler and GEM ioctls.
168d5b1a78aSEric Anholt 	 */
169d5b1a78aSEric Anholt 	spinlock_t job_lock;
170d5b1a78aSEric Anholt 	wait_queue_head_t job_wait_queue;
171d5b1a78aSEric Anholt 	struct work_struct job_done_work;
172d5b1a78aSEric Anholt 
17365101d8cSBoris Brezillon 	/* Used to track the active perfmon if any. Access to this field is
17465101d8cSBoris Brezillon 	 * protected by job_lock.
17565101d8cSBoris Brezillon 	 */
17665101d8cSBoris Brezillon 	struct vc4_perfmon *active_perfmon;
17765101d8cSBoris Brezillon 
178b501baccSEric Anholt 	/* List of struct vc4_seqno_cb for callbacks to be made from a
179b501baccSEric Anholt 	 * workqueue when the given seqno is passed.
180b501baccSEric Anholt 	 */
181b501baccSEric Anholt 	struct list_head seqno_cb_list;
182b501baccSEric Anholt 
183553c942fSEric Anholt 	/* The memory used for storing binner tile alloc, tile state,
184553c942fSEric Anholt 	 * and overflow memory allocations.  This is freed when V3D
185553c942fSEric Anholt 	 * powers down.
186d5b1a78aSEric Anholt 	 */
187553c942fSEric Anholt 	struct vc4_bo *bin_bo;
188553c942fSEric Anholt 
189553c942fSEric Anholt 	/* Size of blocks allocated within bin_bo. */
190553c942fSEric Anholt 	uint32_t bin_alloc_size;
191553c942fSEric Anholt 
192553c942fSEric Anholt 	/* Bitmask of the bin_alloc_size chunks in bin_bo that are
193553c942fSEric Anholt 	 * used.
194553c942fSEric Anholt 	 */
195553c942fSEric Anholt 	uint32_t bin_alloc_used;
196553c942fSEric Anholt 
197553c942fSEric Anholt 	/* Bitmask of the current bin_alloc used for overflow memory. */
198553c942fSEric Anholt 	uint32_t bin_alloc_overflow;
199553c942fSEric Anholt 
200531a1b62SBoris Brezillon 	/* Incremented when an underrun error happened after an atomic commit.
201531a1b62SBoris Brezillon 	 * This is particularly useful to detect when a specific modeset is too
202531a1b62SBoris Brezillon 	 * demanding in term of memory or HVS bandwidth which is hard to guess
203531a1b62SBoris Brezillon 	 * at atomic check time.
204531a1b62SBoris Brezillon 	 */
205531a1b62SBoris Brezillon 	atomic_t underrun;
206531a1b62SBoris Brezillon 
207d5b1a78aSEric Anholt 	struct work_struct overflow_mem_work;
208d5b1a78aSEric Anholt 
20936cb6253SEric Anholt 	int power_refcount;
21036cb6253SEric Anholt 
2116b5c029dSPaul Kocialkowski 	/* Set to true when the load tracker is active. */
2126b5c029dSPaul Kocialkowski 	bool load_tracker_enabled;
2136b5c029dSPaul Kocialkowski 
21436cb6253SEric Anholt 	/* Mutex controlling the power refcount. */
21536cb6253SEric Anholt 	struct mutex power_lock;
21636cb6253SEric Anholt 
217d5b1a78aSEric Anholt 	struct {
218d5b1a78aSEric Anholt 		struct timer_list timer;
219d5b1a78aSEric Anholt 		struct work_struct reset_work;
220d5b1a78aSEric Anholt 	} hangcheck;
221d5b1a78aSEric Anholt 
222766cc6b1SStefan Schake 	struct drm_modeset_lock ctm_state_lock;
223766cc6b1SStefan Schake 	struct drm_private_obj ctm_manager;
224f2df84e0SMaxime Ripard 	struct drm_private_obj hvs_channels;
2254686da83SBoris Brezillon 	struct drm_private_obj load_tracker;
226c9be804cSEric Anholt 
227c9be804cSEric Anholt 	/* List of vc4_debugfs_info_entry for adding to debugfs once
228c9be804cSEric Anholt 	 * the minor is available (after drm_dev_register()).
229c9be804cSEric Anholt 	 */
230c9be804cSEric Anholt 	struct list_head debugfs_list;
23135c8b4b2SPaul Kocialkowski 
23235c8b4b2SPaul Kocialkowski 	/* Mutex for binner bo allocation. */
23335c8b4b2SPaul Kocialkowski 	struct mutex bin_bo_lock;
23435c8b4b2SPaul Kocialkowski 	/* Reference count for our binner bo. */
23535c8b4b2SPaul Kocialkowski 	struct kref bin_bo_kref;
236c8b75bcaSEric Anholt };
237c8b75bcaSEric Anholt 
238c8b75bcaSEric Anholt static inline struct vc4_dev *
239c8b75bcaSEric Anholt to_vc4_dev(struct drm_device *dev)
240c8b75bcaSEric Anholt {
24184d7d472SMaxime Ripard 	return container_of(dev, struct vc4_dev, base);
242c8b75bcaSEric Anholt }
243c8b75bcaSEric Anholt 
244c8b75bcaSEric Anholt struct vc4_bo {
245c8b75bcaSEric Anholt 	struct drm_gem_cma_object base;
246c826a6e1SEric Anholt 
2477edabee0SEric Anholt 	/* seqno of the last job to render using this BO. */
248d5b1a78aSEric Anholt 	uint64_t seqno;
249d5b1a78aSEric Anholt 
2507edabee0SEric Anholt 	/* seqno of the last job to use the RCL to write to this BO.
2517edabee0SEric Anholt 	 *
2527edabee0SEric Anholt 	 * Note that this doesn't include binner overflow memory
2537edabee0SEric Anholt 	 * writes.
2547edabee0SEric Anholt 	 */
2557edabee0SEric Anholt 	uint64_t write_seqno;
2567edabee0SEric Anholt 
25783753117SEric Anholt 	bool t_format;
25883753117SEric Anholt 
259c826a6e1SEric Anholt 	/* List entry for the BO's position in either
260c826a6e1SEric Anholt 	 * vc4_exec_info->unref_list or vc4_dev->bo_cache.time_list
261c826a6e1SEric Anholt 	 */
262c826a6e1SEric Anholt 	struct list_head unref_head;
263c826a6e1SEric Anholt 
264c826a6e1SEric Anholt 	/* Time in jiffies when the BO was put in vc4->bo_cache. */
265c826a6e1SEric Anholt 	unsigned long free_time;
266c826a6e1SEric Anholt 
267c826a6e1SEric Anholt 	/* List entry for the BO's position in vc4_dev->bo_cache.size_list */
268c826a6e1SEric Anholt 	struct list_head size_head;
269463873d5SEric Anholt 
270463873d5SEric Anholt 	/* Struct for shader validation state, if created by
271463873d5SEric Anholt 	 * DRM_IOCTL_VC4_CREATE_SHADER_BO.
272463873d5SEric Anholt 	 */
273463873d5SEric Anholt 	struct vc4_validated_shader_info *validated_shader;
274cdec4d36SEric Anholt 
275f3099462SEric Anholt 	/* One of enum vc4_kernel_bo_type, or VC4_BO_TYPE_COUNT + i
276f3099462SEric Anholt 	 * for user-allocated labels.
277f3099462SEric Anholt 	 */
278f3099462SEric Anholt 	int label;
279b9f19259SBoris Brezillon 
280b9f19259SBoris Brezillon 	/* Count the number of active users. This is needed to determine
281b9f19259SBoris Brezillon 	 * whether we can move the BO to the purgeable list or not (when the BO
282b9f19259SBoris Brezillon 	 * is used by the GPU or the display engine we can't purge it).
283b9f19259SBoris Brezillon 	 */
284b9f19259SBoris Brezillon 	refcount_t usecnt;
285b9f19259SBoris Brezillon 
286b9f19259SBoris Brezillon 	/* Store purgeable/purged state here */
287b9f19259SBoris Brezillon 	u32 madv;
288b9f19259SBoris Brezillon 	struct mutex madv_lock;
289c8b75bcaSEric Anholt };
290c8b75bcaSEric Anholt 
291c8b75bcaSEric Anholt static inline struct vc4_bo *
292c8b75bcaSEric Anholt to_vc4_bo(struct drm_gem_object *bo)
293c8b75bcaSEric Anholt {
2945066f42cSMaxime Ripard 	return container_of(to_drm_gem_cma_obj(bo), struct vc4_bo, base);
295c8b75bcaSEric Anholt }
296c8b75bcaSEric Anholt 
297cdec4d36SEric Anholt struct vc4_fence {
298cdec4d36SEric Anholt 	struct dma_fence base;
299cdec4d36SEric Anholt 	struct drm_device *dev;
300cdec4d36SEric Anholt 	/* vc4 seqno for signaled() test */
301cdec4d36SEric Anholt 	uint64_t seqno;
302cdec4d36SEric Anholt };
303cdec4d36SEric Anholt 
304cdec4d36SEric Anholt static inline struct vc4_fence *
305cdec4d36SEric Anholt to_vc4_fence(struct dma_fence *fence)
306cdec4d36SEric Anholt {
3075066f42cSMaxime Ripard 	return container_of(fence, struct vc4_fence, base);
308cdec4d36SEric Anholt }
309cdec4d36SEric Anholt 
310b501baccSEric Anholt struct vc4_seqno_cb {
311b501baccSEric Anholt 	struct work_struct work;
312b501baccSEric Anholt 	uint64_t seqno;
313b501baccSEric Anholt 	void (*func)(struct vc4_seqno_cb *cb);
314b501baccSEric Anholt };
315b501baccSEric Anholt 
316d3f5168aSEric Anholt struct vc4_v3d {
317001bdb55SEric Anholt 	struct vc4_dev *vc4;
318d3f5168aSEric Anholt 	struct platform_device *pdev;
319d3f5168aSEric Anholt 	void __iomem *regs;
320b72a2816SEric Anholt 	struct clk *clk;
3213051719aSEric Anholt 	struct debugfs_regset32 regset;
322d3f5168aSEric Anholt };
323d3f5168aSEric Anholt 
324c8b75bcaSEric Anholt struct vc4_hvs {
3251cbc91ebSMaxime Ripard 	struct vc4_dev *vc4;
326c8b75bcaSEric Anholt 	struct platform_device *pdev;
327c8b75bcaSEric Anholt 	void __iomem *regs;
328d8dbf44fSEric Anholt 	u32 __iomem *dlist;
329d8dbf44fSEric Anholt 
330d7d96c00SMaxime Ripard 	struct clk *core_clk;
331d7d96c00SMaxime Ripard 
332d8dbf44fSEric Anholt 	/* Memory manager for CRTCs to allocate space in the display
333d8dbf44fSEric Anholt 	 * list.  Units are dwords.
334d8dbf44fSEric Anholt 	 */
335d8dbf44fSEric Anholt 	struct drm_mm dlist_mm;
33621af94cfSEric Anholt 	/* Memory manager for the LBM memory used by HVS scaling. */
33721af94cfSEric Anholt 	struct drm_mm lbm_mm;
338d8dbf44fSEric Anholt 	spinlock_t mm_lock;
33921af94cfSEric Anholt 
34021af94cfSEric Anholt 	struct drm_mm_node mitchell_netravali_filter;
341c54619b0SDave Stevenson 
3423051719aSEric Anholt 	struct debugfs_regset32 regset;
343c8b75bcaSEric Anholt };
344c8b75bcaSEric Anholt 
345c8b75bcaSEric Anholt struct vc4_plane {
346c8b75bcaSEric Anholt 	struct drm_plane base;
347c8b75bcaSEric Anholt };
348c8b75bcaSEric Anholt 
349c8b75bcaSEric Anholt static inline struct vc4_plane *
350c8b75bcaSEric Anholt to_vc4_plane(struct drm_plane *plane)
351c8b75bcaSEric Anholt {
3525066f42cSMaxime Ripard 	return container_of(plane, struct vc4_plane, base);
353c8b75bcaSEric Anholt }
354c8b75bcaSEric Anholt 
35582364698SStefan Schake enum vc4_scaling_mode {
35682364698SStefan Schake 	VC4_SCALING_NONE,
35782364698SStefan Schake 	VC4_SCALING_TPZ,
35882364698SStefan Schake 	VC4_SCALING_PPF,
35982364698SStefan Schake };
36082364698SStefan Schake 
36182364698SStefan Schake struct vc4_plane_state {
36282364698SStefan Schake 	struct drm_plane_state base;
36382364698SStefan Schake 	/* System memory copy of the display list for this element, computed
36482364698SStefan Schake 	 * at atomic_check time.
36582364698SStefan Schake 	 */
36682364698SStefan Schake 	u32 *dlist;
36782364698SStefan Schake 	u32 dlist_size; /* Number of dwords allocated for the display list */
36882364698SStefan Schake 	u32 dlist_count; /* Number of used dwords in the display list. */
36982364698SStefan Schake 
37082364698SStefan Schake 	/* Offset in the dlist to various words, for pageflip or
37182364698SStefan Schake 	 * cursor updates.
37282364698SStefan Schake 	 */
37382364698SStefan Schake 	u32 pos0_offset;
37482364698SStefan Schake 	u32 pos2_offset;
37582364698SStefan Schake 	u32 ptr0_offset;
3760a038c1cSBoris Brezillon 	u32 lbm_offset;
37782364698SStefan Schake 
37882364698SStefan Schake 	/* Offset where the plane's dlist was last stored in the
37982364698SStefan Schake 	 * hardware at vc4_crtc_atomic_flush() time.
38082364698SStefan Schake 	 */
38182364698SStefan Schake 	u32 __iomem *hw_dlist;
38282364698SStefan Schake 
38382364698SStefan Schake 	/* Clipped coordinates of the plane on the display. */
38482364698SStefan Schake 	int crtc_x, crtc_y, crtc_w, crtc_h;
38582364698SStefan Schake 	/* Clipped area being scanned from in the FB. */
38682364698SStefan Schake 	u32 src_x, src_y;
38782364698SStefan Schake 
38882364698SStefan Schake 	u32 src_w[2], src_h[2];
38982364698SStefan Schake 
39082364698SStefan Schake 	/* Scaling selection for the RGB/Y plane and the Cb/Cr planes. */
39182364698SStefan Schake 	enum vc4_scaling_mode x_scaling[2], y_scaling[2];
39282364698SStefan Schake 	bool is_unity;
39382364698SStefan Schake 	bool is_yuv;
39482364698SStefan Schake 
39582364698SStefan Schake 	/* Offset to start scanning out from the start of the plane's
39682364698SStefan Schake 	 * BO.
39782364698SStefan Schake 	 */
39882364698SStefan Schake 	u32 offsets[3];
39982364698SStefan Schake 
40082364698SStefan Schake 	/* Our allocation in LBM for temporary storage during scaling. */
40182364698SStefan Schake 	struct drm_mm_node lbm;
40282364698SStefan Schake 
40382364698SStefan Schake 	/* Set when the plane has per-pixel alpha content or does not cover
40482364698SStefan Schake 	 * the entire screen. This is a hint to the CRTC that it might need
40582364698SStefan Schake 	 * to enable background color fill.
40682364698SStefan Schake 	 */
40782364698SStefan Schake 	bool needs_bg_fill;
4088d938449SBoris Brezillon 
4098d938449SBoris Brezillon 	/* Mark the dlist as initialized. Useful to avoid initializing it twice
4108d938449SBoris Brezillon 	 * when async update is not possible.
4118d938449SBoris Brezillon 	 */
4128d938449SBoris Brezillon 	bool dlist_initialized;
4134686da83SBoris Brezillon 
4144686da83SBoris Brezillon 	/* Load of this plane on the HVS block. The load is expressed in HVS
4154686da83SBoris Brezillon 	 * cycles/sec.
4164686da83SBoris Brezillon 	 */
4174686da83SBoris Brezillon 	u64 hvs_load;
4184686da83SBoris Brezillon 
4194686da83SBoris Brezillon 	/* Memory bandwidth needed for this plane. This is expressed in
4204686da83SBoris Brezillon 	 * bytes/sec.
4214686da83SBoris Brezillon 	 */
4224686da83SBoris Brezillon 	u64 membus_load;
42382364698SStefan Schake };
42482364698SStefan Schake 
42582364698SStefan Schake static inline struct vc4_plane_state *
42682364698SStefan Schake to_vc4_plane_state(struct drm_plane_state *state)
42782364698SStefan Schake {
4285066f42cSMaxime Ripard 	return container_of(state, struct vc4_plane_state, base);
42982364698SStefan Schake }
43082364698SStefan Schake 
431c8b75bcaSEric Anholt enum vc4_encoder_type {
432ab8df60eSBoris Brezillon 	VC4_ENCODER_TYPE_NONE,
433ed024b22SMaxime Ripard 	VC4_ENCODER_TYPE_HDMI0,
434aa2fd1caSMaxime Ripard 	VC4_ENCODER_TYPE_HDMI1,
435c8b75bcaSEric Anholt 	VC4_ENCODER_TYPE_VEC,
436c8b75bcaSEric Anholt 	VC4_ENCODER_TYPE_DSI0,
437c8b75bcaSEric Anholt 	VC4_ENCODER_TYPE_DSI1,
438c8b75bcaSEric Anholt 	VC4_ENCODER_TYPE_SMI,
439c8b75bcaSEric Anholt 	VC4_ENCODER_TYPE_DPI,
440c8b75bcaSEric Anholt };
441c8b75bcaSEric Anholt 
442c8b75bcaSEric Anholt struct vc4_encoder {
443c8b75bcaSEric Anholt 	struct drm_encoder base;
444c8b75bcaSEric Anholt 	enum vc4_encoder_type type;
445c8b75bcaSEric Anholt 	u32 clock_select;
446792c3132SMaxime Ripard 
4478d914746SMaxime Ripard 	void (*pre_crtc_configure)(struct drm_encoder *encoder, struct drm_atomic_state *state);
4488d914746SMaxime Ripard 	void (*pre_crtc_enable)(struct drm_encoder *encoder, struct drm_atomic_state *state);
4498d914746SMaxime Ripard 	void (*post_crtc_enable)(struct drm_encoder *encoder, struct drm_atomic_state *state);
450792c3132SMaxime Ripard 
4518d914746SMaxime Ripard 	void (*post_crtc_disable)(struct drm_encoder *encoder, struct drm_atomic_state *state);
4528d914746SMaxime Ripard 	void (*post_crtc_powerdown)(struct drm_encoder *encoder, struct drm_atomic_state *state);
453c8b75bcaSEric Anholt };
454c8b75bcaSEric Anholt 
455c8b75bcaSEric Anholt static inline struct vc4_encoder *
456c8b75bcaSEric Anholt to_vc4_encoder(struct drm_encoder *encoder)
457c8b75bcaSEric Anholt {
458c8b75bcaSEric Anholt 	return container_of(encoder, struct vc4_encoder, base);
459c8b75bcaSEric Anholt }
460c8b75bcaSEric Anholt 
46179271807SStefan Schake struct vc4_crtc_data {
46287ebcd42SMaxime Ripard 	/* Bitmask of channels (FIFOs) of the HVS that the output can source from */
46387ebcd42SMaxime Ripard 	unsigned int hvs_available_channels;
46487ebcd42SMaxime Ripard 
4658ebb2cf0SMaxime Ripard 	/* Which output of the HVS this pixelvalve sources from. */
4668ebb2cf0SMaxime Ripard 	int hvs_output;
4675a20ff8bSMaxime Ripard };
4685a20ff8bSMaxime Ripard 
4695a20ff8bSMaxime Ripard struct vc4_pv_data {
4705a20ff8bSMaxime Ripard 	struct vc4_crtc_data	base;
47179271807SStefan Schake 
472649abf2fSMaxime Ripard 	/* Depth of the PixelValve FIFO in bytes */
473649abf2fSMaxime Ripard 	unsigned int fifo_depth;
474649abf2fSMaxime Ripard 
475644df22fSMaxime Ripard 	/* Number of pixels output per clock period */
476644df22fSMaxime Ripard 	u8 pixels_per_clock;
477644df22fSMaxime Ripard 
47879271807SStefan Schake 	enum vc4_encoder_type encoder_types[4];
479c9be804cSEric Anholt 	const char *debugfs_name;
4805a20ff8bSMaxime Ripard 
48179271807SStefan Schake };
48279271807SStefan Schake 
48379271807SStefan Schake struct vc4_crtc {
48479271807SStefan Schake 	struct drm_crtc base;
4853051719aSEric Anholt 	struct platform_device *pdev;
48679271807SStefan Schake 	const struct vc4_crtc_data *data;
48779271807SStefan Schake 	void __iomem *regs;
48879271807SStefan Schake 
48979271807SStefan Schake 	/* Timestamp at start of vblank irq - unaffected by lock delays. */
49079271807SStefan Schake 	ktime_t t_vblank;
49179271807SStefan Schake 
49279271807SStefan Schake 	u8 lut_r[256];
49379271807SStefan Schake 	u8 lut_g[256];
49479271807SStefan Schake 	u8 lut_b[256];
49579271807SStefan Schake 
49679271807SStefan Schake 	struct drm_pending_vblank_event *event;
4973051719aSEric Anholt 
4983051719aSEric Anholt 	struct debugfs_regset32 regset;
499a16c6640SMaxime Ripard 
500a16c6640SMaxime Ripard 	/**
501a16c6640SMaxime Ripard 	 * @feeds_txp: True if the CRTC feeds our writeback controller.
502a16c6640SMaxime Ripard 	 */
503a16c6640SMaxime Ripard 	bool feeds_txp;
5040c250c15SMaxime Ripard 
5050c250c15SMaxime Ripard 	/**
5060c250c15SMaxime Ripard 	 * @irq_lock: Spinlock protecting the resources shared between
5070c250c15SMaxime Ripard 	 * the atomic code and our vblank handler.
5080c250c15SMaxime Ripard 	 */
5090c250c15SMaxime Ripard 	spinlock_t irq_lock;
5100c250c15SMaxime Ripard 
5110c250c15SMaxime Ripard 	/**
5120c250c15SMaxime Ripard 	 * @current_dlist: Start offset of the display list currently
5130c250c15SMaxime Ripard 	 * set in the HVS for that CRTC. Protected by @irq_lock, and
5140c250c15SMaxime Ripard 	 * copied in vc4_hvs_update_dlist() for the CRTC interrupt
5150c250c15SMaxime Ripard 	 * handler to have access to that value.
5160c250c15SMaxime Ripard 	 */
5170c250c15SMaxime Ripard 	unsigned int current_dlist;
518eeb6ab46SMaxime Ripard 
519eeb6ab46SMaxime Ripard 	/**
520eeb6ab46SMaxime Ripard 	 * @current_hvs_channel: HVS channel currently assigned to the
521eeb6ab46SMaxime Ripard 	 * CRTC. Protected by @irq_lock, and copied in
522eeb6ab46SMaxime Ripard 	 * vc4_hvs_atomic_begin() for the CRTC interrupt handler to have
523eeb6ab46SMaxime Ripard 	 * access to that value.
524eeb6ab46SMaxime Ripard 	 */
525eeb6ab46SMaxime Ripard 	unsigned int current_hvs_channel;
52679271807SStefan Schake };
52779271807SStefan Schake 
52879271807SStefan Schake static inline struct vc4_crtc *
52979271807SStefan Schake to_vc4_crtc(struct drm_crtc *crtc)
53079271807SStefan Schake {
5315066f42cSMaxime Ripard 	return container_of(crtc, struct vc4_crtc, base);
53279271807SStefan Schake }
53379271807SStefan Schake 
5345a20ff8bSMaxime Ripard static inline const struct vc4_crtc_data *
5355a20ff8bSMaxime Ripard vc4_crtc_to_vc4_crtc_data(const struct vc4_crtc *crtc)
5365a20ff8bSMaxime Ripard {
5375a20ff8bSMaxime Ripard 	return crtc->data;
5385a20ff8bSMaxime Ripard }
5395a20ff8bSMaxime Ripard 
5405a20ff8bSMaxime Ripard static inline const struct vc4_pv_data *
5415a20ff8bSMaxime Ripard vc4_crtc_to_vc4_pv_data(const struct vc4_crtc *crtc)
5425a20ff8bSMaxime Ripard {
5435a20ff8bSMaxime Ripard 	const struct vc4_crtc_data *data = vc4_crtc_to_vc4_crtc_data(crtc);
5445a20ff8bSMaxime Ripard 
5455a20ff8bSMaxime Ripard 	return container_of(data, struct vc4_pv_data, base);
5465a20ff8bSMaxime Ripard }
5475a20ff8bSMaxime Ripard 
548d0229c36SMaxime Ripard struct drm_encoder *vc4_get_crtc_encoder(struct drm_crtc *crtc,
54994c1adc4SMaxime Ripard 					 struct drm_crtc_state *state);
550d0229c36SMaxime Ripard 
551ae44a527SMaxime Ripard struct vc4_crtc_state {
552ae44a527SMaxime Ripard 	struct drm_crtc_state base;
553ae44a527SMaxime Ripard 	/* Dlist area for this CRTC configuration. */
554ae44a527SMaxime Ripard 	struct drm_mm_node mm;
555ae44a527SMaxime Ripard 	bool txp_armed;
55687ebcd42SMaxime Ripard 	unsigned int assigned_channel;
557ae44a527SMaxime Ripard 
558ae44a527SMaxime Ripard 	struct {
559ae44a527SMaxime Ripard 		unsigned int left;
560ae44a527SMaxime Ripard 		unsigned int right;
561ae44a527SMaxime Ripard 		unsigned int top;
562ae44a527SMaxime Ripard 		unsigned int bottom;
563ae44a527SMaxime Ripard 	} margins;
5642820526dSMaxime Ripard 
56516e10105SMaxime Ripard 	unsigned long hvs_load;
56616e10105SMaxime Ripard 
5672820526dSMaxime Ripard 	/* Transitional state below, only valid during atomic commits */
5682820526dSMaxime Ripard 	bool update_muxing;
569ae44a527SMaxime Ripard };
570ae44a527SMaxime Ripard 
5718ba0b6d1SMaxime Ripard #define VC4_HVS_CHANNEL_DISABLED ((unsigned int)-1)
5728ba0b6d1SMaxime Ripard 
573ae44a527SMaxime Ripard static inline struct vc4_crtc_state *
574ae44a527SMaxime Ripard to_vc4_crtc_state(struct drm_crtc_state *crtc_state)
575ae44a527SMaxime Ripard {
5765066f42cSMaxime Ripard 	return container_of(crtc_state, struct vc4_crtc_state, base);
577ae44a527SMaxime Ripard }
578ae44a527SMaxime Ripard 
579d3f5168aSEric Anholt #define V3D_READ(offset) readl(vc4->v3d->regs + offset)
580d3f5168aSEric Anholt #define V3D_WRITE(offset, val) writel(val, vc4->v3d->regs + offset)
5813454f01aSMaxime Ripard #define HVS_READ(offset) readl(hvs->regs + offset)
5823454f01aSMaxime Ripard #define HVS_WRITE(offset, val) writel(val, hvs->regs + offset)
583c8b75bcaSEric Anholt 
5843051719aSEric Anholt #define VC4_REG32(reg) { .name = #reg, .offset = reg }
5853051719aSEric Anholt 
586d5b1a78aSEric Anholt struct vc4_exec_info {
58730f8c74cSMaxime Ripard 	struct vc4_dev *dev;
58830f8c74cSMaxime Ripard 
589d5b1a78aSEric Anholt 	/* Sequence number for this bin/render job. */
590d5b1a78aSEric Anholt 	uint64_t seqno;
591d5b1a78aSEric Anholt 
5927edabee0SEric Anholt 	/* Latest write_seqno of any BO that binning depends on. */
5937edabee0SEric Anholt 	uint64_t bin_dep_seqno;
5947edabee0SEric Anholt 
595cdec4d36SEric Anholt 	struct dma_fence *fence;
596cdec4d36SEric Anholt 
597c4ce60dcSEric Anholt 	/* Last current addresses the hardware was processing when the
598c4ce60dcSEric Anholt 	 * hangcheck timer checked on us.
599c4ce60dcSEric Anholt 	 */
600c4ce60dcSEric Anholt 	uint32_t last_ct0ca, last_ct1ca;
601c4ce60dcSEric Anholt 
602d5b1a78aSEric Anholt 	/* Kernel-space copy of the ioctl arguments */
603d5b1a78aSEric Anholt 	struct drm_vc4_submit_cl *args;
604d5b1a78aSEric Anholt 
605d5b1a78aSEric Anholt 	/* This is the array of BOs that were looked up at the start of exec.
606d5b1a78aSEric Anholt 	 * Command validation will use indices into this array.
607d5b1a78aSEric Anholt 	 */
608d5b1a78aSEric Anholt 	struct drm_gem_cma_object **bo;
609d5b1a78aSEric Anholt 	uint32_t bo_count;
610d5b1a78aSEric Anholt 
6117edabee0SEric Anholt 	/* List of BOs that are being written by the RCL.  Other than
6127edabee0SEric Anholt 	 * the binner temporary storage, this is all the BOs written
6137edabee0SEric Anholt 	 * by the job.
6147edabee0SEric Anholt 	 */
6157edabee0SEric Anholt 	struct drm_gem_cma_object *rcl_write_bo[4];
6167edabee0SEric Anholt 	uint32_t rcl_write_bo_count;
6177edabee0SEric Anholt 
618d5b1a78aSEric Anholt 	/* Pointers for our position in vc4->job_list */
619d5b1a78aSEric Anholt 	struct list_head head;
620d5b1a78aSEric Anholt 
621d5b1a78aSEric Anholt 	/* List of other BOs used in the job that need to be released
622d5b1a78aSEric Anholt 	 * once the job is complete.
623d5b1a78aSEric Anholt 	 */
624d5b1a78aSEric Anholt 	struct list_head unref_list;
625d5b1a78aSEric Anholt 
626d5b1a78aSEric Anholt 	/* Current unvalidated indices into @bo loaded by the non-hardware
627d5b1a78aSEric Anholt 	 * VC4_PACKET_GEM_HANDLES.
628d5b1a78aSEric Anholt 	 */
629d5b1a78aSEric Anholt 	uint32_t bo_index[2];
630d5b1a78aSEric Anholt 
631d5b1a78aSEric Anholt 	/* This is the BO where we store the validated command lists, shader
632d5b1a78aSEric Anholt 	 * records, and uniforms.
633d5b1a78aSEric Anholt 	 */
634d5b1a78aSEric Anholt 	struct drm_gem_cma_object *exec_bo;
635d5b1a78aSEric Anholt 
636d5b1a78aSEric Anholt 	/**
637d5b1a78aSEric Anholt 	 * This tracks the per-shader-record state (packet 64) that
638d5b1a78aSEric Anholt 	 * determines the length of the shader record and the offset
639d5b1a78aSEric Anholt 	 * it's expected to be found at.  It gets read in from the
640d5b1a78aSEric Anholt 	 * command lists.
641d5b1a78aSEric Anholt 	 */
642d5b1a78aSEric Anholt 	struct vc4_shader_state {
643d5b1a78aSEric Anholt 		uint32_t addr;
644d5b1a78aSEric Anholt 		/* Maximum vertex index referenced by any primitive using this
645d5b1a78aSEric Anholt 		 * shader state.
646d5b1a78aSEric Anholt 		 */
647d5b1a78aSEric Anholt 		uint32_t max_index;
648d5b1a78aSEric Anholt 	} *shader_state;
649d5b1a78aSEric Anholt 
650d5b1a78aSEric Anholt 	/** How many shader states the user declared they were using. */
651d5b1a78aSEric Anholt 	uint32_t shader_state_size;
652d5b1a78aSEric Anholt 	/** How many shader state records the validator has seen. */
653d5b1a78aSEric Anholt 	uint32_t shader_state_count;
654d5b1a78aSEric Anholt 
655d5b1a78aSEric Anholt 	bool found_tile_binning_mode_config_packet;
656d5b1a78aSEric Anholt 	bool found_start_tile_binning_packet;
657d5b1a78aSEric Anholt 	bool found_increment_semaphore_packet;
658d5b1a78aSEric Anholt 	bool found_flush;
659d5b1a78aSEric Anholt 	uint8_t bin_tiles_x, bin_tiles_y;
660553c942fSEric Anholt 	/* Physical address of the start of the tile alloc array
661553c942fSEric Anholt 	 * (where each tile's binned CL will start)
662553c942fSEric Anholt 	 */
663d5b1a78aSEric Anholt 	uint32_t tile_alloc_offset;
664553c942fSEric Anholt 	/* Bitmask of which binner slots are freed when this job completes. */
665553c942fSEric Anholt 	uint32_t bin_slots;
666d5b1a78aSEric Anholt 
667d5b1a78aSEric Anholt 	/**
668d5b1a78aSEric Anholt 	 * Computed addresses pointing into exec_bo where we start the
669d5b1a78aSEric Anholt 	 * bin thread (ct0) and render thread (ct1).
670d5b1a78aSEric Anholt 	 */
671d5b1a78aSEric Anholt 	uint32_t ct0ca, ct0ea;
672d5b1a78aSEric Anholt 	uint32_t ct1ca, ct1ea;
673d5b1a78aSEric Anholt 
674d5b1a78aSEric Anholt 	/* Pointer to the unvalidated bin CL (if present). */
675d5b1a78aSEric Anholt 	void *bin_u;
676d5b1a78aSEric Anholt 
677d5b1a78aSEric Anholt 	/* Pointers to the shader recs.  These paddr gets incremented as CL
678d5b1a78aSEric Anholt 	 * packets are relocated in validate_gl_shader_state, and the vaddrs
679d5b1a78aSEric Anholt 	 * (u and v) get incremented and size decremented as the shader recs
680d5b1a78aSEric Anholt 	 * themselves are validated.
681d5b1a78aSEric Anholt 	 */
682d5b1a78aSEric Anholt 	void *shader_rec_u;
683d5b1a78aSEric Anholt 	void *shader_rec_v;
684d5b1a78aSEric Anholt 	uint32_t shader_rec_p;
685d5b1a78aSEric Anholt 	uint32_t shader_rec_size;
686d5b1a78aSEric Anholt 
687d5b1a78aSEric Anholt 	/* Pointers to the uniform data.  These pointers are incremented, and
688d5b1a78aSEric Anholt 	 * size decremented, as each batch of uniforms is uploaded.
689d5b1a78aSEric Anholt 	 */
690d5b1a78aSEric Anholt 	void *uniforms_u;
691d5b1a78aSEric Anholt 	void *uniforms_v;
692d5b1a78aSEric Anholt 	uint32_t uniforms_p;
693d5b1a78aSEric Anholt 	uint32_t uniforms_size;
69465101d8cSBoris Brezillon 
69565101d8cSBoris Brezillon 	/* Pointer to a performance monitor object if the user requested it,
69665101d8cSBoris Brezillon 	 * NULL otherwise.
69765101d8cSBoris Brezillon 	 */
69865101d8cSBoris Brezillon 	struct vc4_perfmon *perfmon;
69935c8b4b2SPaul Kocialkowski 
70035c8b4b2SPaul Kocialkowski 	/* Whether the exec has taken a reference to the binner BO, which should
70135c8b4b2SPaul Kocialkowski 	 * happen with a VC4_PACKET_TILE_BINNING_MODE_CONFIG packet.
70235c8b4b2SPaul Kocialkowski 	 */
70335c8b4b2SPaul Kocialkowski 	bool bin_bo_used;
70465101d8cSBoris Brezillon };
70565101d8cSBoris Brezillon 
70665101d8cSBoris Brezillon /* Per-open file private data. Any driver-specific resource that has to be
70765101d8cSBoris Brezillon  * released when the DRM file is closed should be placed here.
70865101d8cSBoris Brezillon  */
70965101d8cSBoris Brezillon struct vc4_file {
71030f8c74cSMaxime Ripard 	struct vc4_dev *dev;
71130f8c74cSMaxime Ripard 
71265101d8cSBoris Brezillon 	struct {
71365101d8cSBoris Brezillon 		struct idr idr;
71465101d8cSBoris Brezillon 		struct mutex lock;
71565101d8cSBoris Brezillon 	} perfmon;
71635c8b4b2SPaul Kocialkowski 
71735c8b4b2SPaul Kocialkowski 	bool bin_bo_used;
718d5b1a78aSEric Anholt };
719d5b1a78aSEric Anholt 
720d5b1a78aSEric Anholt static inline struct vc4_exec_info *
721ca26d28bSVarad Gautam vc4_first_bin_job(struct vc4_dev *vc4)
722d5b1a78aSEric Anholt {
72357b9f569SMasahiro Yamada 	return list_first_entry_or_null(&vc4->bin_job_list,
72457b9f569SMasahiro Yamada 					struct vc4_exec_info, head);
725ca26d28bSVarad Gautam }
726ca26d28bSVarad Gautam 
727ca26d28bSVarad Gautam static inline struct vc4_exec_info *
728ca26d28bSVarad Gautam vc4_first_render_job(struct vc4_dev *vc4)
729ca26d28bSVarad Gautam {
73057b9f569SMasahiro Yamada 	return list_first_entry_or_null(&vc4->render_job_list,
731ca26d28bSVarad Gautam 					struct vc4_exec_info, head);
732d5b1a78aSEric Anholt }
733d5b1a78aSEric Anholt 
7349326e6f2SEric Anholt static inline struct vc4_exec_info *
7359326e6f2SEric Anholt vc4_last_render_job(struct vc4_dev *vc4)
7369326e6f2SEric Anholt {
7379326e6f2SEric Anholt 	if (list_empty(&vc4->render_job_list))
7389326e6f2SEric Anholt 		return NULL;
7399326e6f2SEric Anholt 	return list_last_entry(&vc4->render_job_list,
7409326e6f2SEric Anholt 			       struct vc4_exec_info, head);
7419326e6f2SEric Anholt }
7429326e6f2SEric Anholt 
743c8b75bcaSEric Anholt /**
744463873d5SEric Anholt  * struct vc4_texture_sample_info - saves the offsets into the UBO for texture
745463873d5SEric Anholt  * setup parameters.
746463873d5SEric Anholt  *
747463873d5SEric Anholt  * This will be used at draw time to relocate the reference to the texture
748463873d5SEric Anholt  * contents in p0, and validate that the offset combined with
749463873d5SEric Anholt  * width/height/stride/etc. from p1 and p2/p3 doesn't sample outside the BO.
750463873d5SEric Anholt  * Note that the hardware treats unprovided config parameters as 0, so not all
751463873d5SEric Anholt  * of them need to be set up for every texure sample, and we'll store ~0 as
752463873d5SEric Anholt  * the offset to mark the unused ones.
753463873d5SEric Anholt  *
754463873d5SEric Anholt  * See the VC4 3D architecture guide page 41 ("Texture and Memory Lookup Unit
755463873d5SEric Anholt  * Setup") for definitions of the texture parameters.
756463873d5SEric Anholt  */
757463873d5SEric Anholt struct vc4_texture_sample_info {
758463873d5SEric Anholt 	bool is_direct;
759463873d5SEric Anholt 	uint32_t p_offset[4];
760463873d5SEric Anholt };
761463873d5SEric Anholt 
762463873d5SEric Anholt /**
763463873d5SEric Anholt  * struct vc4_validated_shader_info - information about validated shaders that
764463873d5SEric Anholt  * needs to be used from command list validation.
765463873d5SEric Anholt  *
766463873d5SEric Anholt  * For a given shader, each time a shader state record references it, we need
767463873d5SEric Anholt  * to verify that the shader doesn't read more uniforms than the shader state
768463873d5SEric Anholt  * record's uniform BO pointer can provide, and we need to apply relocations
769463873d5SEric Anholt  * and validate the shader state record's uniforms that define the texture
770463873d5SEric Anholt  * samples.
771463873d5SEric Anholt  */
772463873d5SEric Anholt struct vc4_validated_shader_info {
773463873d5SEric Anholt 	uint32_t uniforms_size;
774463873d5SEric Anholt 	uint32_t uniforms_src_size;
775463873d5SEric Anholt 	uint32_t num_texture_samples;
776463873d5SEric Anholt 	struct vc4_texture_sample_info *texture_samples;
7776d45c81dSEric Anholt 
7786d45c81dSEric Anholt 	uint32_t num_uniform_addr_offsets;
7796d45c81dSEric Anholt 	uint32_t *uniform_addr_offsets;
780c778cc5dSJonas Pfeil 
781c778cc5dSJonas Pfeil 	bool is_threaded;
782463873d5SEric Anholt };
783463873d5SEric Anholt 
784463873d5SEric Anholt /**
7857f2a09ecSJames Hughes  * __wait_for - magic wait macro
786c8b75bcaSEric Anholt  *
7877f2a09ecSJames Hughes  * Macro to help avoid open coding check/wait/timeout patterns. Note that it's
7887f2a09ecSJames Hughes  * important that we check the condition again after having timed out, since the
7897f2a09ecSJames Hughes  * timeout could be due to preemption or similar and we've never had a chance to
7907f2a09ecSJames Hughes  * check the condition before the timeout.
791c8b75bcaSEric Anholt  */
7927f2a09ecSJames Hughes #define __wait_for(OP, COND, US, Wmin, Wmax) ({ \
7937f2a09ecSJames Hughes 	const ktime_t end__ = ktime_add_ns(ktime_get_raw(), 1000ll * (US)); \
7947f2a09ecSJames Hughes 	long wait__ = (Wmin); /* recommended min for usleep is 10 us */	\
7957f2a09ecSJames Hughes 	int ret__;							\
7967f2a09ecSJames Hughes 	might_sleep();							\
7977f2a09ecSJames Hughes 	for (;;) {							\
7987f2a09ecSJames Hughes 		const bool expired__ = ktime_after(ktime_get_raw(), end__); \
7997f2a09ecSJames Hughes 		OP;							\
8007f2a09ecSJames Hughes 		/* Guarantee COND check prior to timeout */		\
8017f2a09ecSJames Hughes 		barrier();						\
8027f2a09ecSJames Hughes 		if (COND) {						\
8037f2a09ecSJames Hughes 			ret__ = 0;					\
8047f2a09ecSJames Hughes 			break;						\
8057f2a09ecSJames Hughes 		}							\
8067f2a09ecSJames Hughes 		if (expired__) {					\
807c8b75bcaSEric Anholt 			ret__ = -ETIMEDOUT;				\
808c8b75bcaSEric Anholt 			break;						\
809c8b75bcaSEric Anholt 		}							\
8107f2a09ecSJames Hughes 		usleep_range(wait__, wait__ * 2);			\
8117f2a09ecSJames Hughes 		if (wait__ < (Wmax))					\
8127f2a09ecSJames Hughes 			wait__ <<= 1;					\
813c8b75bcaSEric Anholt 	}								\
814c8b75bcaSEric Anholt 	ret__;								\
815c8b75bcaSEric Anholt })
816c8b75bcaSEric Anholt 
8177f2a09ecSJames Hughes #define _wait_for(COND, US, Wmin, Wmax)	__wait_for(, (COND), (US), (Wmin), \
8187f2a09ecSJames Hughes 						   (Wmax))
8197f2a09ecSJames Hughes #define wait_for(COND, MS)		_wait_for((COND), (MS) * 1000, 10, 1000)
820c8b75bcaSEric Anholt 
821c8b75bcaSEric Anholt /* vc4_bo.c */
822c826a6e1SEric Anholt struct drm_gem_object *vc4_create_object(struct drm_device *dev, size_t size);
823c826a6e1SEric Anholt struct vc4_bo *vc4_bo_create(struct drm_device *dev, size_t size,
824f3099462SEric Anholt 			     bool from_cache, enum vc4_kernel_bo_type type);
825dd2dfd44SMaxime Ripard int vc4_bo_dumb_create(struct drm_file *file_priv,
826c8b75bcaSEric Anholt 		       struct drm_device *dev,
827c8b75bcaSEric Anholt 		       struct drm_mode_create_dumb *args);
828d5bc60f6SEric Anholt int vc4_create_bo_ioctl(struct drm_device *dev, void *data,
829d5bc60f6SEric Anholt 			struct drm_file *file_priv);
830463873d5SEric Anholt int vc4_create_shader_bo_ioctl(struct drm_device *dev, void *data,
831463873d5SEric Anholt 			       struct drm_file *file_priv);
832d5bc60f6SEric Anholt int vc4_mmap_bo_ioctl(struct drm_device *dev, void *data,
833d5bc60f6SEric Anholt 		      struct drm_file *file_priv);
83483753117SEric Anholt int vc4_set_tiling_ioctl(struct drm_device *dev, void *data,
83583753117SEric Anholt 			 struct drm_file *file_priv);
83683753117SEric Anholt int vc4_get_tiling_ioctl(struct drm_device *dev, void *data,
83783753117SEric Anholt 			 struct drm_file *file_priv);
83821461365SEric Anholt int vc4_get_hang_state_ioctl(struct drm_device *dev, void *data,
83921461365SEric Anholt 			     struct drm_file *file_priv);
840f3099462SEric Anholt int vc4_label_bo_ioctl(struct drm_device *dev, void *data,
841f3099462SEric Anholt 		       struct drm_file *file_priv);
842f3099462SEric Anholt int vc4_bo_cache_init(struct drm_device *dev);
843b9f19259SBoris Brezillon int vc4_bo_inc_usecnt(struct vc4_bo *bo);
844b9f19259SBoris Brezillon void vc4_bo_dec_usecnt(struct vc4_bo *bo);
845b9f19259SBoris Brezillon void vc4_bo_add_to_purgeable_pool(struct vc4_bo *bo);
846b9f19259SBoris Brezillon void vc4_bo_remove_from_purgeable_pool(struct vc4_bo *bo);
847c8b75bcaSEric Anholt 
848c8b75bcaSEric Anholt /* vc4_crtc.c */
849c8b75bcaSEric Anholt extern struct platform_driver vc4_crtc_driver;
850875a4d53SMaxime Ripard int vc4_crtc_disable_at_boot(struct drm_crtc *crtc);
8515fefc601SMaxime Ripard int vc4_crtc_init(struct drm_device *drm, struct vc4_crtc *vc4_crtc,
8525fefc601SMaxime Ripard 		  const struct drm_crtc_funcs *crtc_funcs,
8535fefc601SMaxime Ripard 		  const struct drm_crtc_helper_funcs *crtc_helper_funcs);
854bdd96472SMaxime Ripard void vc4_crtc_destroy(struct drm_crtc *crtc);
855bdd96472SMaxime Ripard int vc4_page_flip(struct drm_crtc *crtc,
856bdd96472SMaxime Ripard 		  struct drm_framebuffer *fb,
857bdd96472SMaxime Ripard 		  struct drm_pending_vblank_event *event,
858bdd96472SMaxime Ripard 		  uint32_t flags,
859bdd96472SMaxime Ripard 		  struct drm_modeset_acquire_ctx *ctx);
860bdd96472SMaxime Ripard struct drm_crtc_state *vc4_crtc_duplicate_state(struct drm_crtc *crtc);
861bdd96472SMaxime Ripard void vc4_crtc_destroy_state(struct drm_crtc *crtc,
862bdd96472SMaxime Ripard 			    struct drm_crtc_state *state);
863bdd96472SMaxime Ripard void vc4_crtc_reset(struct drm_crtc *crtc);
864008095e0SBoris Brezillon void vc4_crtc_handle_vblank(struct vc4_crtc *crtc);
865666e7358SBoris Brezillon void vc4_crtc_get_margins(struct drm_crtc_state *state,
866e590c2b0SDan Carpenter 			  unsigned int *left, unsigned int *right,
867666e7358SBoris Brezillon 			  unsigned int *top, unsigned int *bottom);
868c8b75bcaSEric Anholt 
869c8b75bcaSEric Anholt /* vc4_debugfs.c */
8707ce84471SWambui Karuga void vc4_debugfs_init(struct drm_minor *minor);
871c9be804cSEric Anholt #ifdef CONFIG_DEBUG_FS
872c9be804cSEric Anholt void vc4_debugfs_add_file(struct drm_device *drm,
873c9be804cSEric Anholt 			  const char *filename,
874c9be804cSEric Anholt 			  int (*show)(struct seq_file*, void*),
875c9be804cSEric Anholt 			  void *data);
876c9be804cSEric Anholt void vc4_debugfs_add_regset32(struct drm_device *drm,
877c9be804cSEric Anholt 			      const char *filename,
878c9be804cSEric Anholt 			      struct debugfs_regset32 *regset);
879c9be804cSEric Anholt #else
880c9be804cSEric Anholt static inline void vc4_debugfs_add_file(struct drm_device *drm,
881c9be804cSEric Anholt 					const char *filename,
882c9be804cSEric Anholt 					int (*show)(struct seq_file*, void*),
883c9be804cSEric Anholt 					void *data)
884c9be804cSEric Anholt {
885c9be804cSEric Anholt }
886c9be804cSEric Anholt 
887c9be804cSEric Anholt static inline void vc4_debugfs_add_regset32(struct drm_device *drm,
888c9be804cSEric Anholt 					    const char *filename,
889c9be804cSEric Anholt 					    struct debugfs_regset32 *regset)
890c9be804cSEric Anholt {
891c9be804cSEric Anholt }
892c9be804cSEric Anholt #endif
893c8b75bcaSEric Anholt 
894c8b75bcaSEric Anholt /* vc4_drv.c */
895c8b75bcaSEric Anholt void __iomem *vc4_ioremap_regs(struct platform_device *dev, int index);
8963d763742SMaxime Ripard int vc4_dumb_fixup_args(struct drm_mode_create_dumb *args);
897c8b75bcaSEric Anholt 
89808302c35SEric Anholt /* vc4_dpi.c */
89908302c35SEric Anholt extern struct platform_driver vc4_dpi_driver;
90008302c35SEric Anholt 
9014078f575SEric Anholt /* vc4_dsi.c */
9024078f575SEric Anholt extern struct platform_driver vc4_dsi_driver;
9034078f575SEric Anholt 
904cdec4d36SEric Anholt /* vc4_fence.c */
905cdec4d36SEric Anholt extern const struct dma_fence_ops vc4_fence_ops;
906cdec4d36SEric Anholt 
907d5b1a78aSEric Anholt /* vc4_gem.c */
908171a072bSMaxime Ripard int vc4_gem_init(struct drm_device *dev);
909d5b1a78aSEric Anholt int vc4_submit_cl_ioctl(struct drm_device *dev, void *data,
910d5b1a78aSEric Anholt 			struct drm_file *file_priv);
911d5b1a78aSEric Anholt int vc4_wait_seqno_ioctl(struct drm_device *dev, void *data,
912d5b1a78aSEric Anholt 			 struct drm_file *file_priv);
913d5b1a78aSEric Anholt int vc4_wait_bo_ioctl(struct drm_device *dev, void *data,
914d5b1a78aSEric Anholt 		      struct drm_file *file_priv);
915ca26d28bSVarad Gautam void vc4_submit_next_bin_job(struct drm_device *dev);
916ca26d28bSVarad Gautam void vc4_submit_next_render_job(struct drm_device *dev);
917ca26d28bSVarad Gautam void vc4_move_job_to_render(struct drm_device *dev, struct vc4_exec_info *exec);
918d5b1a78aSEric Anholt int vc4_wait_for_seqno(struct drm_device *dev, uint64_t seqno,
919d5b1a78aSEric Anholt 		       uint64_t timeout_ns, bool interruptible);
920d5b1a78aSEric Anholt void vc4_job_handle_completed(struct vc4_dev *vc4);
921b501baccSEric Anholt int vc4_queue_seqno_cb(struct drm_device *dev,
922b501baccSEric Anholt 		       struct vc4_seqno_cb *cb, uint64_t seqno,
923b501baccSEric Anholt 		       void (*func)(struct vc4_seqno_cb *cb));
924b9f19259SBoris Brezillon int vc4_gem_madvise_ioctl(struct drm_device *dev, void *data,
925b9f19259SBoris Brezillon 			  struct drm_file *file_priv);
926d5b1a78aSEric Anholt 
927c8b75bcaSEric Anholt /* vc4_hdmi.c */
928c8b75bcaSEric Anholt extern struct platform_driver vc4_hdmi_driver;
929c8b75bcaSEric Anholt 
9309a8d5e4aSBoris Brezillon /* vc4_vec.c */
931e4b81f8cSBoris Brezillon extern struct platform_driver vc4_vec_driver;
932e4b81f8cSBoris Brezillon 
933008095e0SBoris Brezillon /* vc4_txp.c */
934008095e0SBoris Brezillon extern struct platform_driver vc4_txp_driver;
935008095e0SBoris Brezillon 
936d5b1a78aSEric Anholt /* vc4_irq.c */
9375226711eSThomas Zimmermann void vc4_irq_enable(struct drm_device *dev);
9385226711eSThomas Zimmermann void vc4_irq_disable(struct drm_device *dev);
9395226711eSThomas Zimmermann int vc4_irq_install(struct drm_device *dev, int irq);
940d5b1a78aSEric Anholt void vc4_irq_uninstall(struct drm_device *dev);
941d5b1a78aSEric Anholt void vc4_irq_reset(struct drm_device *dev);
942d5b1a78aSEric Anholt 
943c8b75bcaSEric Anholt /* vc4_hvs.c */
944c8b75bcaSEric Anholt extern struct platform_driver vc4_hvs_driver;
9453454f01aSMaxime Ripard void vc4_hvs_stop_channel(struct vc4_hvs *hvs, unsigned int output);
9463454f01aSMaxime Ripard int vc4_hvs_get_fifo_from_output(struct vc4_hvs *hvs, unsigned int output);
9473454f01aSMaxime Ripard u8 vc4_hvs_get_fifo_frame_count(struct vc4_hvs *hvs, unsigned int fifo);
948ee6965c8SMaxime Ripard int vc4_hvs_atomic_check(struct drm_crtc *crtc, struct drm_atomic_state *state);
949eeb6ab46SMaxime Ripard void vc4_hvs_atomic_begin(struct drm_crtc *crtc, struct drm_atomic_state *state);
950ee6965c8SMaxime Ripard void vc4_hvs_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_state *state);
951ee6965c8SMaxime Ripard void vc4_hvs_atomic_disable(struct drm_crtc *crtc, struct drm_atomic_state *state);
952ee6965c8SMaxime Ripard void vc4_hvs_atomic_flush(struct drm_crtc *crtc, struct drm_atomic_state *state);
9533454f01aSMaxime Ripard void vc4_hvs_dump_state(struct vc4_hvs *hvs);
9543454f01aSMaxime Ripard void vc4_hvs_unmask_underrun(struct vc4_hvs *hvs, int channel);
9553454f01aSMaxime Ripard void vc4_hvs_mask_underrun(struct vc4_hvs *hvs, int channel);
956c8b75bcaSEric Anholt 
957c8b75bcaSEric Anholt /* vc4_kms.c */
958c8b75bcaSEric Anholt int vc4_kms_load(struct drm_device *dev);
959c8b75bcaSEric Anholt 
960c8b75bcaSEric Anholt /* vc4_plane.c */
961c8b75bcaSEric Anholt struct drm_plane *vc4_plane_init(struct drm_device *dev,
962c8b75bcaSEric Anholt 				 enum drm_plane_type type);
9630c2a50f1SMaxime Ripard int vc4_plane_create_additional_planes(struct drm_device *dev);
964c8b75bcaSEric Anholt u32 vc4_plane_write_dlist(struct drm_plane *plane, u32 __iomem *dlist);
9652f196b7cSDaniel Vetter u32 vc4_plane_dlist_size(const struct drm_plane_state *state);
966b501baccSEric Anholt void vc4_plane_async_set_fb(struct drm_plane *plane,
967b501baccSEric Anholt 			    struct drm_framebuffer *fb);
968463873d5SEric Anholt 
969d3f5168aSEric Anholt /* vc4_v3d.c */
970d3f5168aSEric Anholt extern struct platform_driver vc4_v3d_driver;
971ffc26740SEric Anholt extern const struct of_device_id vc4_v3d_dt_match[];
972553c942fSEric Anholt int vc4_v3d_get_bin_slot(struct vc4_dev *vc4);
97335c8b4b2SPaul Kocialkowski int vc4_v3d_bin_bo_get(struct vc4_dev *vc4, bool *used);
97435c8b4b2SPaul Kocialkowski void vc4_v3d_bin_bo_put(struct vc4_dev *vc4);
975cb74f6eeSEric Anholt int vc4_v3d_pm_get(struct vc4_dev *vc4);
976cb74f6eeSEric Anholt void vc4_v3d_pm_put(struct vc4_dev *vc4);
977d5b1a78aSEric Anholt 
978d5b1a78aSEric Anholt /* vc4_validate.c */
979d5b1a78aSEric Anholt int
980d5b1a78aSEric Anholt vc4_validate_bin_cl(struct drm_device *dev,
981d5b1a78aSEric Anholt 		    void *validated,
982d5b1a78aSEric Anholt 		    void *unvalidated,
983d5b1a78aSEric Anholt 		    struct vc4_exec_info *exec);
984d5b1a78aSEric Anholt 
985d5b1a78aSEric Anholt int
986d5b1a78aSEric Anholt vc4_validate_shader_recs(struct drm_device *dev, struct vc4_exec_info *exec);
987d5b1a78aSEric Anholt 
988d5b1a78aSEric Anholt struct drm_gem_cma_object *vc4_use_bo(struct vc4_exec_info *exec,
989d5b1a78aSEric Anholt 				      uint32_t hindex);
990d5b1a78aSEric Anholt 
991d5b1a78aSEric Anholt int vc4_get_rcl(struct drm_device *dev, struct vc4_exec_info *exec);
992d5b1a78aSEric Anholt 
993d5b1a78aSEric Anholt bool vc4_check_tex_size(struct vc4_exec_info *exec,
994d5b1a78aSEric Anholt 			struct drm_gem_cma_object *fbo,
995d5b1a78aSEric Anholt 			uint32_t offset, uint8_t tiling_format,
996d5b1a78aSEric Anholt 			uint32_t width, uint32_t height, uint8_t cpp);
997d3f5168aSEric Anholt 
998463873d5SEric Anholt /* vc4_validate_shader.c */
999463873d5SEric Anholt struct vc4_validated_shader_info *
1000463873d5SEric Anholt vc4_validate_shader(struct drm_gem_cma_object *shader_obj);
100165101d8cSBoris Brezillon 
100265101d8cSBoris Brezillon /* vc4_perfmon.c */
100365101d8cSBoris Brezillon void vc4_perfmon_get(struct vc4_perfmon *perfmon);
100465101d8cSBoris Brezillon void vc4_perfmon_put(struct vc4_perfmon *perfmon);
100565101d8cSBoris Brezillon void vc4_perfmon_start(struct vc4_dev *vc4, struct vc4_perfmon *perfmon);
100665101d8cSBoris Brezillon void vc4_perfmon_stop(struct vc4_dev *vc4, struct vc4_perfmon *perfmon,
100765101d8cSBoris Brezillon 		      bool capture);
100865101d8cSBoris Brezillon struct vc4_perfmon *vc4_perfmon_find(struct vc4_file *vc4file, int id);
100965101d8cSBoris Brezillon void vc4_perfmon_open_file(struct vc4_file *vc4file);
101065101d8cSBoris Brezillon void vc4_perfmon_close_file(struct vc4_file *vc4file);
101165101d8cSBoris Brezillon int vc4_perfmon_create_ioctl(struct drm_device *dev, void *data,
101265101d8cSBoris Brezillon 			     struct drm_file *file_priv);
101365101d8cSBoris Brezillon int vc4_perfmon_destroy_ioctl(struct drm_device *dev, void *data,
101465101d8cSBoris Brezillon 			      struct drm_file *file_priv);
101565101d8cSBoris Brezillon int vc4_perfmon_get_values_ioctl(struct drm_device *dev, void *data,
101665101d8cSBoris Brezillon 				 struct drm_file *file_priv);
10176a88752cSMaxime Ripard 
10186a88752cSMaxime Ripard #endif /* _VC4_DRV_H_ */
1019