xref: /linux/drivers/gpu/drm/vc4/vc4_drv.h (revision 5a20ff8bf3d455855d445594152cc6a7760a3793)
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>
9fd6d6d80SSam Ravnborg #include <linux/refcount.h>
10fd6d6d80SSam Ravnborg #include <linux/uaccess.h>
11fd6d6d80SSam Ravnborg 
12fd6d6d80SSam Ravnborg #include <drm/drm_atomic.h>
13fd6d6d80SSam Ravnborg #include <drm/drm_debugfs.h>
14fd6d6d80SSam Ravnborg #include <drm/drm_device.h>
159338203cSLaurent Pinchart #include <drm/drm_encoder.h>
16b7e8e25bSMasahiro Yamada #include <drm/drm_gem_cma_helper.h>
17fd6d6d80SSam Ravnborg #include <drm/drm_mm.h>
18fd6d6d80SSam Ravnborg #include <drm/drm_modeset_lock.h>
199338203cSLaurent Pinchart 
2065101d8cSBoris Brezillon #include "uapi/drm/vc4_drm.h"
2165101d8cSBoris Brezillon 
22fd6d6d80SSam Ravnborg struct drm_device;
23fd6d6d80SSam Ravnborg struct drm_gem_object;
24fd6d6d80SSam Ravnborg 
25f3099462SEric Anholt /* Don't forget to update vc4_bo.c: bo_type_names[] when adding to
26f3099462SEric Anholt  * this.
27f3099462SEric Anholt  */
28f3099462SEric Anholt enum vc4_kernel_bo_type {
29f3099462SEric Anholt 	/* Any kernel allocation (gem_create_object hook) before it
30f3099462SEric Anholt 	 * gets another type set.
31f3099462SEric Anholt 	 */
32f3099462SEric Anholt 	VC4_BO_TYPE_KERNEL,
33f3099462SEric Anholt 	VC4_BO_TYPE_V3D,
34f3099462SEric Anholt 	VC4_BO_TYPE_V3D_SHADER,
35f3099462SEric Anholt 	VC4_BO_TYPE_DUMB,
36f3099462SEric Anholt 	VC4_BO_TYPE_BIN,
37f3099462SEric Anholt 	VC4_BO_TYPE_RCL,
38f3099462SEric Anholt 	VC4_BO_TYPE_BCL,
39f3099462SEric Anholt 	VC4_BO_TYPE_KERNEL_CACHE,
40f3099462SEric Anholt 	VC4_BO_TYPE_COUNT
41f3099462SEric Anholt };
42f3099462SEric Anholt 
4365101d8cSBoris Brezillon /* Performance monitor object. The perform lifetime is controlled by userspace
4465101d8cSBoris Brezillon  * using perfmon related ioctls. A perfmon can be attached to a submit_cl
4565101d8cSBoris Brezillon  * request, and when this is the case, HW perf counters will be activated just
4665101d8cSBoris Brezillon  * before the submit_cl is submitted to the GPU and disabled when the job is
4765101d8cSBoris Brezillon  * done. This way, only events related to a specific job will be counted.
4865101d8cSBoris Brezillon  */
4965101d8cSBoris Brezillon struct vc4_perfmon {
5065101d8cSBoris Brezillon 	/* Tracks the number of users of the perfmon, when this counter reaches
5165101d8cSBoris Brezillon 	 * zero the perfmon is destroyed.
5265101d8cSBoris Brezillon 	 */
5365101d8cSBoris Brezillon 	refcount_t refcnt;
5465101d8cSBoris Brezillon 
5565101d8cSBoris Brezillon 	/* Number of counters activated in this perfmon instance
5665101d8cSBoris Brezillon 	 * (should be less than DRM_VC4_MAX_PERF_COUNTERS).
5765101d8cSBoris Brezillon 	 */
5865101d8cSBoris Brezillon 	u8 ncounters;
5965101d8cSBoris Brezillon 
6065101d8cSBoris Brezillon 	/* Events counted by the HW perf counters. */
6165101d8cSBoris Brezillon 	u8 events[DRM_VC4_MAX_PERF_COUNTERS];
6265101d8cSBoris Brezillon 
6365101d8cSBoris Brezillon 	/* Storage for counter values. Counters are incremented by the HW
6465101d8cSBoris Brezillon 	 * perf counter values every time the perfmon is attached to a GPU job.
6565101d8cSBoris Brezillon 	 * This way, perfmon users don't have to retrieve the results after
6665101d8cSBoris Brezillon 	 * each job if they want to track events covering several submissions.
6765101d8cSBoris Brezillon 	 * Note that counter values can't be reset, but you can fake a reset by
6865101d8cSBoris Brezillon 	 * destroying the perfmon and creating a new one.
6965101d8cSBoris Brezillon 	 */
705b2adbddSGustavo A. R. Silva 	u64 counters[];
7165101d8cSBoris Brezillon };
7265101d8cSBoris Brezillon 
73c8b75bcaSEric Anholt struct vc4_dev {
74c8b75bcaSEric Anholt 	struct drm_device *dev;
75c8b75bcaSEric Anholt 
76c8b75bcaSEric Anholt 	struct vc4_hdmi *hdmi;
77c8b75bcaSEric Anholt 	struct vc4_hvs *hvs;
78d3f5168aSEric Anholt 	struct vc4_v3d *v3d;
7908302c35SEric Anholt 	struct vc4_dpi *dpi;
804078f575SEric Anholt 	struct vc4_dsi *dsi1;
81e4b81f8cSBoris Brezillon 	struct vc4_vec *vec;
82008095e0SBoris Brezillon 	struct vc4_txp *txp;
8348666d56SDerek Foreman 
8421461365SEric Anholt 	struct vc4_hang_state *hang_state;
8521461365SEric Anholt 
86c826a6e1SEric Anholt 	/* The kernel-space BO cache.  Tracks buffers that have been
87c826a6e1SEric Anholt 	 * unreferenced by all other users (refcounts of 0!) but not
88c826a6e1SEric Anholt 	 * yet freed, so we can do cheap allocations.
89c826a6e1SEric Anholt 	 */
90c826a6e1SEric Anholt 	struct vc4_bo_cache {
91c826a6e1SEric Anholt 		/* Array of list heads for entries in the BO cache,
92c826a6e1SEric Anholt 		 * based on number of pages, so we can do O(1) lookups
93c826a6e1SEric Anholt 		 * in the cache when allocating.
94c826a6e1SEric Anholt 		 */
95c826a6e1SEric Anholt 		struct list_head *size_list;
96c826a6e1SEric Anholt 		uint32_t size_list_size;
97c826a6e1SEric Anholt 
98c826a6e1SEric Anholt 		/* List of all BOs in the cache, ordered by age, so we
99c826a6e1SEric Anholt 		 * can do O(1) lookups when trying to free old
100c826a6e1SEric Anholt 		 * buffers.
101c826a6e1SEric Anholt 		 */
102c826a6e1SEric Anholt 		struct list_head time_list;
103c826a6e1SEric Anholt 		struct work_struct time_work;
104c826a6e1SEric Anholt 		struct timer_list time_timer;
105c826a6e1SEric Anholt 	} bo_cache;
106c826a6e1SEric Anholt 
107f3099462SEric Anholt 	u32 num_labels;
108f3099462SEric Anholt 	struct vc4_label {
109f3099462SEric Anholt 		const char *name;
110c826a6e1SEric Anholt 		u32 num_allocated;
111c826a6e1SEric Anholt 		u32 size_allocated;
112f3099462SEric Anholt 	} *bo_labels;
113c826a6e1SEric Anholt 
114f3099462SEric Anholt 	/* Protects bo_cache and bo_labels. */
115c826a6e1SEric Anholt 	struct mutex bo_lock;
116d5b1a78aSEric Anholt 
117b9f19259SBoris Brezillon 	/* Purgeable BO pool. All BOs in this pool can have their memory
118b9f19259SBoris Brezillon 	 * reclaimed if the driver is unable to allocate new BOs. We also
119b9f19259SBoris Brezillon 	 * keep stats related to the purge mechanism here.
120b9f19259SBoris Brezillon 	 */
121b9f19259SBoris Brezillon 	struct {
122b9f19259SBoris Brezillon 		struct list_head list;
123b9f19259SBoris Brezillon 		unsigned int num;
124b9f19259SBoris Brezillon 		size_t size;
125b9f19259SBoris Brezillon 		unsigned int purged_num;
126b9f19259SBoris Brezillon 		size_t purged_size;
127b9f19259SBoris Brezillon 		struct mutex lock;
128b9f19259SBoris Brezillon 	} purgeable;
129b9f19259SBoris Brezillon 
130cdec4d36SEric Anholt 	uint64_t dma_fence_context;
131cdec4d36SEric Anholt 
132ca26d28bSVarad Gautam 	/* Sequence number for the last job queued in bin_job_list.
133d5b1a78aSEric Anholt 	 * Starts at 0 (no jobs emitted).
134d5b1a78aSEric Anholt 	 */
135d5b1a78aSEric Anholt 	uint64_t emit_seqno;
136d5b1a78aSEric Anholt 
137d5b1a78aSEric Anholt 	/* Sequence number for the last completed job on the GPU.
138d5b1a78aSEric Anholt 	 * Starts at 0 (no jobs completed).
139d5b1a78aSEric Anholt 	 */
140d5b1a78aSEric Anholt 	uint64_t finished_seqno;
141d5b1a78aSEric Anholt 
142ca26d28bSVarad Gautam 	/* List of all struct vc4_exec_info for jobs to be executed in
143ca26d28bSVarad Gautam 	 * the binner.  The first job in the list is the one currently
144ca26d28bSVarad Gautam 	 * programmed into ct0ca for execution.
145d5b1a78aSEric Anholt 	 */
146ca26d28bSVarad Gautam 	struct list_head bin_job_list;
147ca26d28bSVarad Gautam 
148ca26d28bSVarad Gautam 	/* List of all struct vc4_exec_info for jobs that have
149ca26d28bSVarad Gautam 	 * completed binning and are ready for rendering.  The first
150ca26d28bSVarad Gautam 	 * job in the list is the one currently programmed into ct1ca
151ca26d28bSVarad Gautam 	 * for execution.
152ca26d28bSVarad Gautam 	 */
153ca26d28bSVarad Gautam 	struct list_head render_job_list;
154ca26d28bSVarad Gautam 
155d5b1a78aSEric Anholt 	/* List of the finished vc4_exec_infos waiting to be freed by
156d5b1a78aSEric Anholt 	 * job_done_work.
157d5b1a78aSEric Anholt 	 */
158d5b1a78aSEric Anholt 	struct list_head job_done_list;
159d5b1a78aSEric Anholt 	/* Spinlock used to synchronize the job_list and seqno
160d5b1a78aSEric Anholt 	 * accesses between the IRQ handler and GEM ioctls.
161d5b1a78aSEric Anholt 	 */
162d5b1a78aSEric Anholt 	spinlock_t job_lock;
163d5b1a78aSEric Anholt 	wait_queue_head_t job_wait_queue;
164d5b1a78aSEric Anholt 	struct work_struct job_done_work;
165d5b1a78aSEric Anholt 
16665101d8cSBoris Brezillon 	/* Used to track the active perfmon if any. Access to this field is
16765101d8cSBoris Brezillon 	 * protected by job_lock.
16865101d8cSBoris Brezillon 	 */
16965101d8cSBoris Brezillon 	struct vc4_perfmon *active_perfmon;
17065101d8cSBoris Brezillon 
171b501baccSEric Anholt 	/* List of struct vc4_seqno_cb for callbacks to be made from a
172b501baccSEric Anholt 	 * workqueue when the given seqno is passed.
173b501baccSEric Anholt 	 */
174b501baccSEric Anholt 	struct list_head seqno_cb_list;
175b501baccSEric Anholt 
176553c942fSEric Anholt 	/* The memory used for storing binner tile alloc, tile state,
177553c942fSEric Anholt 	 * and overflow memory allocations.  This is freed when V3D
178553c942fSEric Anholt 	 * powers down.
179d5b1a78aSEric Anholt 	 */
180553c942fSEric Anholt 	struct vc4_bo *bin_bo;
181553c942fSEric Anholt 
182553c942fSEric Anholt 	/* Size of blocks allocated within bin_bo. */
183553c942fSEric Anholt 	uint32_t bin_alloc_size;
184553c942fSEric Anholt 
185553c942fSEric Anholt 	/* Bitmask of the bin_alloc_size chunks in bin_bo that are
186553c942fSEric Anholt 	 * used.
187553c942fSEric Anholt 	 */
188553c942fSEric Anholt 	uint32_t bin_alloc_used;
189553c942fSEric Anholt 
190553c942fSEric Anholt 	/* Bitmask of the current bin_alloc used for overflow memory. */
191553c942fSEric Anholt 	uint32_t bin_alloc_overflow;
192553c942fSEric Anholt 
193531a1b62SBoris Brezillon 	/* Incremented when an underrun error happened after an atomic commit.
194531a1b62SBoris Brezillon 	 * This is particularly useful to detect when a specific modeset is too
195531a1b62SBoris Brezillon 	 * demanding in term of memory or HVS bandwidth which is hard to guess
196531a1b62SBoris Brezillon 	 * at atomic check time.
197531a1b62SBoris Brezillon 	 */
198531a1b62SBoris Brezillon 	atomic_t underrun;
199531a1b62SBoris Brezillon 
200d5b1a78aSEric Anholt 	struct work_struct overflow_mem_work;
201d5b1a78aSEric Anholt 
20236cb6253SEric Anholt 	int power_refcount;
20336cb6253SEric Anholt 
2046b5c029dSPaul Kocialkowski 	/* Set to true when the load tracker is active. */
2056b5c029dSPaul Kocialkowski 	bool load_tracker_enabled;
2066b5c029dSPaul Kocialkowski 
20736cb6253SEric Anholt 	/* Mutex controlling the power refcount. */
20836cb6253SEric Anholt 	struct mutex power_lock;
20936cb6253SEric Anholt 
210d5b1a78aSEric Anholt 	struct {
211d5b1a78aSEric Anholt 		struct timer_list timer;
212d5b1a78aSEric Anholt 		struct work_struct reset_work;
213d5b1a78aSEric Anholt 	} hangcheck;
214d5b1a78aSEric Anholt 
215d5b1a78aSEric Anholt 	struct semaphore async_modeset;
216766cc6b1SStefan Schake 
217766cc6b1SStefan Schake 	struct drm_modeset_lock ctm_state_lock;
218766cc6b1SStefan Schake 	struct drm_private_obj ctm_manager;
2194686da83SBoris Brezillon 	struct drm_private_obj load_tracker;
220c9be804cSEric Anholt 
221c9be804cSEric Anholt 	/* List of vc4_debugfs_info_entry for adding to debugfs once
222c9be804cSEric Anholt 	 * the minor is available (after drm_dev_register()).
223c9be804cSEric Anholt 	 */
224c9be804cSEric Anholt 	struct list_head debugfs_list;
22535c8b4b2SPaul Kocialkowski 
22635c8b4b2SPaul Kocialkowski 	/* Mutex for binner bo allocation. */
22735c8b4b2SPaul Kocialkowski 	struct mutex bin_bo_lock;
22835c8b4b2SPaul Kocialkowski 	/* Reference count for our binner bo. */
22935c8b4b2SPaul Kocialkowski 	struct kref bin_bo_kref;
230c8b75bcaSEric Anholt };
231c8b75bcaSEric Anholt 
232c8b75bcaSEric Anholt static inline struct vc4_dev *
233c8b75bcaSEric Anholt to_vc4_dev(struct drm_device *dev)
234c8b75bcaSEric Anholt {
235c8b75bcaSEric Anholt 	return (struct vc4_dev *)dev->dev_private;
236c8b75bcaSEric Anholt }
237c8b75bcaSEric Anholt 
238c8b75bcaSEric Anholt struct vc4_bo {
239c8b75bcaSEric Anholt 	struct drm_gem_cma_object base;
240c826a6e1SEric Anholt 
2417edabee0SEric Anholt 	/* seqno of the last job to render using this BO. */
242d5b1a78aSEric Anholt 	uint64_t seqno;
243d5b1a78aSEric Anholt 
2447edabee0SEric Anholt 	/* seqno of the last job to use the RCL to write to this BO.
2457edabee0SEric Anholt 	 *
2467edabee0SEric Anholt 	 * Note that this doesn't include binner overflow memory
2477edabee0SEric Anholt 	 * writes.
2487edabee0SEric Anholt 	 */
2497edabee0SEric Anholt 	uint64_t write_seqno;
2507edabee0SEric Anholt 
25183753117SEric Anholt 	bool t_format;
25283753117SEric Anholt 
253c826a6e1SEric Anholt 	/* List entry for the BO's position in either
254c826a6e1SEric Anholt 	 * vc4_exec_info->unref_list or vc4_dev->bo_cache.time_list
255c826a6e1SEric Anholt 	 */
256c826a6e1SEric Anholt 	struct list_head unref_head;
257c826a6e1SEric Anholt 
258c826a6e1SEric Anholt 	/* Time in jiffies when the BO was put in vc4->bo_cache. */
259c826a6e1SEric Anholt 	unsigned long free_time;
260c826a6e1SEric Anholt 
261c826a6e1SEric Anholt 	/* List entry for the BO's position in vc4_dev->bo_cache.size_list */
262c826a6e1SEric Anholt 	struct list_head size_head;
263463873d5SEric Anholt 
264463873d5SEric Anholt 	/* Struct for shader validation state, if created by
265463873d5SEric Anholt 	 * DRM_IOCTL_VC4_CREATE_SHADER_BO.
266463873d5SEric Anholt 	 */
267463873d5SEric Anholt 	struct vc4_validated_shader_info *validated_shader;
268cdec4d36SEric Anholt 
269f3099462SEric Anholt 	/* One of enum vc4_kernel_bo_type, or VC4_BO_TYPE_COUNT + i
270f3099462SEric Anholt 	 * for user-allocated labels.
271f3099462SEric Anholt 	 */
272f3099462SEric Anholt 	int label;
273b9f19259SBoris Brezillon 
274b9f19259SBoris Brezillon 	/* Count the number of active users. This is needed to determine
275b9f19259SBoris Brezillon 	 * whether we can move the BO to the purgeable list or not (when the BO
276b9f19259SBoris Brezillon 	 * is used by the GPU or the display engine we can't purge it).
277b9f19259SBoris Brezillon 	 */
278b9f19259SBoris Brezillon 	refcount_t usecnt;
279b9f19259SBoris Brezillon 
280b9f19259SBoris Brezillon 	/* Store purgeable/purged state here */
281b9f19259SBoris Brezillon 	u32 madv;
282b9f19259SBoris Brezillon 	struct mutex madv_lock;
283c8b75bcaSEric Anholt };
284c8b75bcaSEric Anholt 
285c8b75bcaSEric Anholt static inline struct vc4_bo *
286c8b75bcaSEric Anholt to_vc4_bo(struct drm_gem_object *bo)
287c8b75bcaSEric Anholt {
288c8b75bcaSEric Anholt 	return (struct vc4_bo *)bo;
289c8b75bcaSEric Anholt }
290c8b75bcaSEric Anholt 
291cdec4d36SEric Anholt struct vc4_fence {
292cdec4d36SEric Anholt 	struct dma_fence base;
293cdec4d36SEric Anholt 	struct drm_device *dev;
294cdec4d36SEric Anholt 	/* vc4 seqno for signaled() test */
295cdec4d36SEric Anholt 	uint64_t seqno;
296cdec4d36SEric Anholt };
297cdec4d36SEric Anholt 
298cdec4d36SEric Anholt static inline struct vc4_fence *
299cdec4d36SEric Anholt to_vc4_fence(struct dma_fence *fence)
300cdec4d36SEric Anholt {
301cdec4d36SEric Anholt 	return (struct vc4_fence *)fence;
302cdec4d36SEric Anholt }
303cdec4d36SEric Anholt 
304b501baccSEric Anholt struct vc4_seqno_cb {
305b501baccSEric Anholt 	struct work_struct work;
306b501baccSEric Anholt 	uint64_t seqno;
307b501baccSEric Anholt 	void (*func)(struct vc4_seqno_cb *cb);
308b501baccSEric Anholt };
309b501baccSEric Anholt 
310d3f5168aSEric Anholt struct vc4_v3d {
311001bdb55SEric Anholt 	struct vc4_dev *vc4;
312d3f5168aSEric Anholt 	struct platform_device *pdev;
313d3f5168aSEric Anholt 	void __iomem *regs;
314b72a2816SEric Anholt 	struct clk *clk;
3153051719aSEric Anholt 	struct debugfs_regset32 regset;
316d3f5168aSEric Anholt };
317d3f5168aSEric Anholt 
318c8b75bcaSEric Anholt struct vc4_hvs {
319c8b75bcaSEric Anholt 	struct platform_device *pdev;
320c8b75bcaSEric Anholt 	void __iomem *regs;
321d8dbf44fSEric Anholt 	u32 __iomem *dlist;
322d8dbf44fSEric Anholt 
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;
3323051719aSEric Anholt 	struct debugfs_regset32 regset;
333c8b75bcaSEric Anholt };
334c8b75bcaSEric Anholt 
335c8b75bcaSEric Anholt struct vc4_plane {
336c8b75bcaSEric Anholt 	struct drm_plane base;
337c8b75bcaSEric Anholt };
338c8b75bcaSEric Anholt 
339c8b75bcaSEric Anholt static inline struct vc4_plane *
340c8b75bcaSEric Anholt to_vc4_plane(struct drm_plane *plane)
341c8b75bcaSEric Anholt {
342c8b75bcaSEric Anholt 	return (struct vc4_plane *)plane;
343c8b75bcaSEric Anholt }
344c8b75bcaSEric Anholt 
34582364698SStefan Schake enum vc4_scaling_mode {
34682364698SStefan Schake 	VC4_SCALING_NONE,
34782364698SStefan Schake 	VC4_SCALING_TPZ,
34882364698SStefan Schake 	VC4_SCALING_PPF,
34982364698SStefan Schake };
35082364698SStefan Schake 
35182364698SStefan Schake struct vc4_plane_state {
35282364698SStefan Schake 	struct drm_plane_state base;
35382364698SStefan Schake 	/* System memory copy of the display list for this element, computed
35482364698SStefan Schake 	 * at atomic_check time.
35582364698SStefan Schake 	 */
35682364698SStefan Schake 	u32 *dlist;
35782364698SStefan Schake 	u32 dlist_size; /* Number of dwords allocated for the display list */
35882364698SStefan Schake 	u32 dlist_count; /* Number of used dwords in the display list. */
35982364698SStefan Schake 
36082364698SStefan Schake 	/* Offset in the dlist to various words, for pageflip or
36182364698SStefan Schake 	 * cursor updates.
36282364698SStefan Schake 	 */
36382364698SStefan Schake 	u32 pos0_offset;
36482364698SStefan Schake 	u32 pos2_offset;
36582364698SStefan Schake 	u32 ptr0_offset;
3660a038c1cSBoris Brezillon 	u32 lbm_offset;
36782364698SStefan Schake 
36882364698SStefan Schake 	/* Offset where the plane's dlist was last stored in the
36982364698SStefan Schake 	 * hardware at vc4_crtc_atomic_flush() time.
37082364698SStefan Schake 	 */
37182364698SStefan Schake 	u32 __iomem *hw_dlist;
37282364698SStefan Schake 
37382364698SStefan Schake 	/* Clipped coordinates of the plane on the display. */
37482364698SStefan Schake 	int crtc_x, crtc_y, crtc_w, crtc_h;
37582364698SStefan Schake 	/* Clipped area being scanned from in the FB. */
37682364698SStefan Schake 	u32 src_x, src_y;
37782364698SStefan Schake 
37882364698SStefan Schake 	u32 src_w[2], src_h[2];
37982364698SStefan Schake 
38082364698SStefan Schake 	/* Scaling selection for the RGB/Y plane and the Cb/Cr planes. */
38182364698SStefan Schake 	enum vc4_scaling_mode x_scaling[2], y_scaling[2];
38282364698SStefan Schake 	bool is_unity;
38382364698SStefan Schake 	bool is_yuv;
38482364698SStefan Schake 
38582364698SStefan Schake 	/* Offset to start scanning out from the start of the plane's
38682364698SStefan Schake 	 * BO.
38782364698SStefan Schake 	 */
38882364698SStefan Schake 	u32 offsets[3];
38982364698SStefan Schake 
39082364698SStefan Schake 	/* Our allocation in LBM for temporary storage during scaling. */
39182364698SStefan Schake 	struct drm_mm_node lbm;
39282364698SStefan Schake 
39382364698SStefan Schake 	/* Set when the plane has per-pixel alpha content or does not cover
39482364698SStefan Schake 	 * the entire screen. This is a hint to the CRTC that it might need
39582364698SStefan Schake 	 * to enable background color fill.
39682364698SStefan Schake 	 */
39782364698SStefan Schake 	bool needs_bg_fill;
3988d938449SBoris Brezillon 
3998d938449SBoris Brezillon 	/* Mark the dlist as initialized. Useful to avoid initializing it twice
4008d938449SBoris Brezillon 	 * when async update is not possible.
4018d938449SBoris Brezillon 	 */
4028d938449SBoris Brezillon 	bool dlist_initialized;
4034686da83SBoris Brezillon 
4044686da83SBoris Brezillon 	/* Load of this plane on the HVS block. The load is expressed in HVS
4054686da83SBoris Brezillon 	 * cycles/sec.
4064686da83SBoris Brezillon 	 */
4074686da83SBoris Brezillon 	u64 hvs_load;
4084686da83SBoris Brezillon 
4094686da83SBoris Brezillon 	/* Memory bandwidth needed for this plane. This is expressed in
4104686da83SBoris Brezillon 	 * bytes/sec.
4114686da83SBoris Brezillon 	 */
4124686da83SBoris Brezillon 	u64 membus_load;
41382364698SStefan Schake };
41482364698SStefan Schake 
41582364698SStefan Schake static inline struct vc4_plane_state *
41682364698SStefan Schake to_vc4_plane_state(struct drm_plane_state *state)
41782364698SStefan Schake {
41882364698SStefan Schake 	return (struct vc4_plane_state *)state;
41982364698SStefan Schake }
42082364698SStefan Schake 
421c8b75bcaSEric Anholt enum vc4_encoder_type {
422ab8df60eSBoris Brezillon 	VC4_ENCODER_TYPE_NONE,
423c8b75bcaSEric Anholt 	VC4_ENCODER_TYPE_HDMI,
424c8b75bcaSEric Anholt 	VC4_ENCODER_TYPE_VEC,
425c8b75bcaSEric Anholt 	VC4_ENCODER_TYPE_DSI0,
426c8b75bcaSEric Anholt 	VC4_ENCODER_TYPE_DSI1,
427c8b75bcaSEric Anholt 	VC4_ENCODER_TYPE_SMI,
428c8b75bcaSEric Anholt 	VC4_ENCODER_TYPE_DPI,
429c8b75bcaSEric Anholt };
430c8b75bcaSEric Anholt 
431c8b75bcaSEric Anholt struct vc4_encoder {
432c8b75bcaSEric Anholt 	struct drm_encoder base;
433c8b75bcaSEric Anholt 	enum vc4_encoder_type type;
434c8b75bcaSEric Anholt 	u32 clock_select;
435c8b75bcaSEric Anholt };
436c8b75bcaSEric Anholt 
437c8b75bcaSEric Anholt static inline struct vc4_encoder *
438c8b75bcaSEric Anholt to_vc4_encoder(struct drm_encoder *encoder)
439c8b75bcaSEric Anholt {
440c8b75bcaSEric Anholt 	return container_of(encoder, struct vc4_encoder, base);
441c8b75bcaSEric Anholt }
442c8b75bcaSEric Anholt 
44379271807SStefan Schake struct vc4_crtc_data {
44479271807SStefan Schake 	/* Which channel of the HVS this pixelvalve sources from. */
44579271807SStefan Schake 	int hvs_channel;
446*5a20ff8bSMaxime Ripard };
447*5a20ff8bSMaxime Ripard 
448*5a20ff8bSMaxime Ripard struct vc4_pv_data {
449*5a20ff8bSMaxime Ripard 	struct vc4_crtc_data	base;
45079271807SStefan Schake 
45179271807SStefan Schake 	enum vc4_encoder_type encoder_types[4];
452c9be804cSEric Anholt 	const char *debugfs_name;
453*5a20ff8bSMaxime Ripard 
45479271807SStefan Schake };
45579271807SStefan Schake 
45679271807SStefan Schake struct vc4_crtc {
45779271807SStefan Schake 	struct drm_crtc base;
4583051719aSEric Anholt 	struct platform_device *pdev;
45979271807SStefan Schake 	const struct vc4_crtc_data *data;
46079271807SStefan Schake 	void __iomem *regs;
46179271807SStefan Schake 
46279271807SStefan Schake 	/* Timestamp at start of vblank irq - unaffected by lock delays. */
46379271807SStefan Schake 	ktime_t t_vblank;
46479271807SStefan Schake 
46579271807SStefan Schake 	/* Which HVS channel we're using for our CRTC. */
46679271807SStefan Schake 	int channel;
46779271807SStefan Schake 
46879271807SStefan Schake 	u8 lut_r[256];
46979271807SStefan Schake 	u8 lut_g[256];
47079271807SStefan Schake 	u8 lut_b[256];
47179271807SStefan Schake 	/* Size in pixels of the COB memory allocated to this CRTC. */
47279271807SStefan Schake 	u32 cob_size;
47379271807SStefan Schake 
47479271807SStefan Schake 	struct drm_pending_vblank_event *event;
4753051719aSEric Anholt 
4763051719aSEric Anholt 	struct debugfs_regset32 regset;
47779271807SStefan Schake };
47879271807SStefan Schake 
47979271807SStefan Schake static inline struct vc4_crtc *
48079271807SStefan Schake to_vc4_crtc(struct drm_crtc *crtc)
48179271807SStefan Schake {
48279271807SStefan Schake 	return (struct vc4_crtc *)crtc;
48379271807SStefan Schake }
48479271807SStefan Schake 
485*5a20ff8bSMaxime Ripard static inline const struct vc4_crtc_data *
486*5a20ff8bSMaxime Ripard vc4_crtc_to_vc4_crtc_data(const struct vc4_crtc *crtc)
487*5a20ff8bSMaxime Ripard {
488*5a20ff8bSMaxime Ripard 	return crtc->data;
489*5a20ff8bSMaxime Ripard }
490*5a20ff8bSMaxime Ripard 
491*5a20ff8bSMaxime Ripard static inline const struct vc4_pv_data *
492*5a20ff8bSMaxime Ripard vc4_crtc_to_vc4_pv_data(const struct vc4_crtc *crtc)
493*5a20ff8bSMaxime Ripard {
494*5a20ff8bSMaxime Ripard 	const struct vc4_crtc_data *data = vc4_crtc_to_vc4_crtc_data(crtc);
495*5a20ff8bSMaxime Ripard 
496*5a20ff8bSMaxime Ripard 	return container_of(data, struct vc4_pv_data, base);
497*5a20ff8bSMaxime Ripard }
498*5a20ff8bSMaxime Ripard 
499ae44a527SMaxime Ripard struct vc4_crtc_state {
500ae44a527SMaxime Ripard 	struct drm_crtc_state base;
501ae44a527SMaxime Ripard 	/* Dlist area for this CRTC configuration. */
502ae44a527SMaxime Ripard 	struct drm_mm_node mm;
503ae44a527SMaxime Ripard 	bool feed_txp;
504ae44a527SMaxime Ripard 	bool txp_armed;
505ae44a527SMaxime Ripard 
506ae44a527SMaxime Ripard 	struct {
507ae44a527SMaxime Ripard 		unsigned int left;
508ae44a527SMaxime Ripard 		unsigned int right;
509ae44a527SMaxime Ripard 		unsigned int top;
510ae44a527SMaxime Ripard 		unsigned int bottom;
511ae44a527SMaxime Ripard 	} margins;
512ae44a527SMaxime Ripard };
513ae44a527SMaxime Ripard 
514ae44a527SMaxime Ripard static inline struct vc4_crtc_state *
515ae44a527SMaxime Ripard to_vc4_crtc_state(struct drm_crtc_state *crtc_state)
516ae44a527SMaxime Ripard {
517ae44a527SMaxime Ripard 	return (struct vc4_crtc_state *)crtc_state;
518ae44a527SMaxime Ripard }
519ae44a527SMaxime Ripard 
520d3f5168aSEric Anholt #define V3D_READ(offset) readl(vc4->v3d->regs + offset)
521d3f5168aSEric Anholt #define V3D_WRITE(offset, val) writel(val, vc4->v3d->regs + offset)
522c8b75bcaSEric Anholt #define HVS_READ(offset) readl(vc4->hvs->regs + offset)
523c8b75bcaSEric Anholt #define HVS_WRITE(offset, val) writel(val, vc4->hvs->regs + offset)
524c8b75bcaSEric Anholt 
5253051719aSEric Anholt #define VC4_REG32(reg) { .name = #reg, .offset = reg }
5263051719aSEric Anholt 
527d5b1a78aSEric Anholt struct vc4_exec_info {
528d5b1a78aSEric Anholt 	/* Sequence number for this bin/render job. */
529d5b1a78aSEric Anholt 	uint64_t seqno;
530d5b1a78aSEric Anholt 
5317edabee0SEric Anholt 	/* Latest write_seqno of any BO that binning depends on. */
5327edabee0SEric Anholt 	uint64_t bin_dep_seqno;
5337edabee0SEric Anholt 
534cdec4d36SEric Anholt 	struct dma_fence *fence;
535cdec4d36SEric Anholt 
536c4ce60dcSEric Anholt 	/* Last current addresses the hardware was processing when the
537c4ce60dcSEric Anholt 	 * hangcheck timer checked on us.
538c4ce60dcSEric Anholt 	 */
539c4ce60dcSEric Anholt 	uint32_t last_ct0ca, last_ct1ca;
540c4ce60dcSEric Anholt 
541d5b1a78aSEric Anholt 	/* Kernel-space copy of the ioctl arguments */
542d5b1a78aSEric Anholt 	struct drm_vc4_submit_cl *args;
543d5b1a78aSEric Anholt 
544d5b1a78aSEric Anholt 	/* This is the array of BOs that were looked up at the start of exec.
545d5b1a78aSEric Anholt 	 * Command validation will use indices into this array.
546d5b1a78aSEric Anholt 	 */
547d5b1a78aSEric Anholt 	struct drm_gem_cma_object **bo;
548d5b1a78aSEric Anholt 	uint32_t bo_count;
549d5b1a78aSEric Anholt 
5507edabee0SEric Anholt 	/* List of BOs that are being written by the RCL.  Other than
5517edabee0SEric Anholt 	 * the binner temporary storage, this is all the BOs written
5527edabee0SEric Anholt 	 * by the job.
5537edabee0SEric Anholt 	 */
5547edabee0SEric Anholt 	struct drm_gem_cma_object *rcl_write_bo[4];
5557edabee0SEric Anholt 	uint32_t rcl_write_bo_count;
5567edabee0SEric Anholt 
557d5b1a78aSEric Anholt 	/* Pointers for our position in vc4->job_list */
558d5b1a78aSEric Anholt 	struct list_head head;
559d5b1a78aSEric Anholt 
560d5b1a78aSEric Anholt 	/* List of other BOs used in the job that need to be released
561d5b1a78aSEric Anholt 	 * once the job is complete.
562d5b1a78aSEric Anholt 	 */
563d5b1a78aSEric Anholt 	struct list_head unref_list;
564d5b1a78aSEric Anholt 
565d5b1a78aSEric Anholt 	/* Current unvalidated indices into @bo loaded by the non-hardware
566d5b1a78aSEric Anholt 	 * VC4_PACKET_GEM_HANDLES.
567d5b1a78aSEric Anholt 	 */
568d5b1a78aSEric Anholt 	uint32_t bo_index[2];
569d5b1a78aSEric Anholt 
570d5b1a78aSEric Anholt 	/* This is the BO where we store the validated command lists, shader
571d5b1a78aSEric Anholt 	 * records, and uniforms.
572d5b1a78aSEric Anholt 	 */
573d5b1a78aSEric Anholt 	struct drm_gem_cma_object *exec_bo;
574d5b1a78aSEric Anholt 
575d5b1a78aSEric Anholt 	/**
576d5b1a78aSEric Anholt 	 * This tracks the per-shader-record state (packet 64) that
577d5b1a78aSEric Anholt 	 * determines the length of the shader record and the offset
578d5b1a78aSEric Anholt 	 * it's expected to be found at.  It gets read in from the
579d5b1a78aSEric Anholt 	 * command lists.
580d5b1a78aSEric Anholt 	 */
581d5b1a78aSEric Anholt 	struct vc4_shader_state {
582d5b1a78aSEric Anholt 		uint32_t addr;
583d5b1a78aSEric Anholt 		/* Maximum vertex index referenced by any primitive using this
584d5b1a78aSEric Anholt 		 * shader state.
585d5b1a78aSEric Anholt 		 */
586d5b1a78aSEric Anholt 		uint32_t max_index;
587d5b1a78aSEric Anholt 	} *shader_state;
588d5b1a78aSEric Anholt 
589d5b1a78aSEric Anholt 	/** How many shader states the user declared they were using. */
590d5b1a78aSEric Anholt 	uint32_t shader_state_size;
591d5b1a78aSEric Anholt 	/** How many shader state records the validator has seen. */
592d5b1a78aSEric Anholt 	uint32_t shader_state_count;
593d5b1a78aSEric Anholt 
594d5b1a78aSEric Anholt 	bool found_tile_binning_mode_config_packet;
595d5b1a78aSEric Anholt 	bool found_start_tile_binning_packet;
596d5b1a78aSEric Anholt 	bool found_increment_semaphore_packet;
597d5b1a78aSEric Anholt 	bool found_flush;
598d5b1a78aSEric Anholt 	uint8_t bin_tiles_x, bin_tiles_y;
599553c942fSEric Anholt 	/* Physical address of the start of the tile alloc array
600553c942fSEric Anholt 	 * (where each tile's binned CL will start)
601553c942fSEric Anholt 	 */
602d5b1a78aSEric Anholt 	uint32_t tile_alloc_offset;
603553c942fSEric Anholt 	/* Bitmask of which binner slots are freed when this job completes. */
604553c942fSEric Anholt 	uint32_t bin_slots;
605d5b1a78aSEric Anholt 
606d5b1a78aSEric Anholt 	/**
607d5b1a78aSEric Anholt 	 * Computed addresses pointing into exec_bo where we start the
608d5b1a78aSEric Anholt 	 * bin thread (ct0) and render thread (ct1).
609d5b1a78aSEric Anholt 	 */
610d5b1a78aSEric Anholt 	uint32_t ct0ca, ct0ea;
611d5b1a78aSEric Anholt 	uint32_t ct1ca, ct1ea;
612d5b1a78aSEric Anholt 
613d5b1a78aSEric Anholt 	/* Pointer to the unvalidated bin CL (if present). */
614d5b1a78aSEric Anholt 	void *bin_u;
615d5b1a78aSEric Anholt 
616d5b1a78aSEric Anholt 	/* Pointers to the shader recs.  These paddr gets incremented as CL
617d5b1a78aSEric Anholt 	 * packets are relocated in validate_gl_shader_state, and the vaddrs
618d5b1a78aSEric Anholt 	 * (u and v) get incremented and size decremented as the shader recs
619d5b1a78aSEric Anholt 	 * themselves are validated.
620d5b1a78aSEric Anholt 	 */
621d5b1a78aSEric Anholt 	void *shader_rec_u;
622d5b1a78aSEric Anholt 	void *shader_rec_v;
623d5b1a78aSEric Anholt 	uint32_t shader_rec_p;
624d5b1a78aSEric Anholt 	uint32_t shader_rec_size;
625d5b1a78aSEric Anholt 
626d5b1a78aSEric Anholt 	/* Pointers to the uniform data.  These pointers are incremented, and
627d5b1a78aSEric Anholt 	 * size decremented, as each batch of uniforms is uploaded.
628d5b1a78aSEric Anholt 	 */
629d5b1a78aSEric Anholt 	void *uniforms_u;
630d5b1a78aSEric Anholt 	void *uniforms_v;
631d5b1a78aSEric Anholt 	uint32_t uniforms_p;
632d5b1a78aSEric Anholt 	uint32_t uniforms_size;
63365101d8cSBoris Brezillon 
63465101d8cSBoris Brezillon 	/* Pointer to a performance monitor object if the user requested it,
63565101d8cSBoris Brezillon 	 * NULL otherwise.
63665101d8cSBoris Brezillon 	 */
63765101d8cSBoris Brezillon 	struct vc4_perfmon *perfmon;
63835c8b4b2SPaul Kocialkowski 
63935c8b4b2SPaul Kocialkowski 	/* Whether the exec has taken a reference to the binner BO, which should
64035c8b4b2SPaul Kocialkowski 	 * happen with a VC4_PACKET_TILE_BINNING_MODE_CONFIG packet.
64135c8b4b2SPaul Kocialkowski 	 */
64235c8b4b2SPaul Kocialkowski 	bool bin_bo_used;
64365101d8cSBoris Brezillon };
64465101d8cSBoris Brezillon 
64565101d8cSBoris Brezillon /* Per-open file private data. Any driver-specific resource that has to be
64665101d8cSBoris Brezillon  * released when the DRM file is closed should be placed here.
64765101d8cSBoris Brezillon  */
64865101d8cSBoris Brezillon struct vc4_file {
64965101d8cSBoris Brezillon 	struct {
65065101d8cSBoris Brezillon 		struct idr idr;
65165101d8cSBoris Brezillon 		struct mutex lock;
65265101d8cSBoris Brezillon 	} perfmon;
65335c8b4b2SPaul Kocialkowski 
65435c8b4b2SPaul Kocialkowski 	bool bin_bo_used;
655d5b1a78aSEric Anholt };
656d5b1a78aSEric Anholt 
657d5b1a78aSEric Anholt static inline struct vc4_exec_info *
658ca26d28bSVarad Gautam vc4_first_bin_job(struct vc4_dev *vc4)
659d5b1a78aSEric Anholt {
66057b9f569SMasahiro Yamada 	return list_first_entry_or_null(&vc4->bin_job_list,
66157b9f569SMasahiro Yamada 					struct vc4_exec_info, head);
662ca26d28bSVarad Gautam }
663ca26d28bSVarad Gautam 
664ca26d28bSVarad Gautam static inline struct vc4_exec_info *
665ca26d28bSVarad Gautam vc4_first_render_job(struct vc4_dev *vc4)
666ca26d28bSVarad Gautam {
66757b9f569SMasahiro Yamada 	return list_first_entry_or_null(&vc4->render_job_list,
668ca26d28bSVarad Gautam 					struct vc4_exec_info, head);
669d5b1a78aSEric Anholt }
670d5b1a78aSEric Anholt 
6719326e6f2SEric Anholt static inline struct vc4_exec_info *
6729326e6f2SEric Anholt vc4_last_render_job(struct vc4_dev *vc4)
6739326e6f2SEric Anholt {
6749326e6f2SEric Anholt 	if (list_empty(&vc4->render_job_list))
6759326e6f2SEric Anholt 		return NULL;
6769326e6f2SEric Anholt 	return list_last_entry(&vc4->render_job_list,
6779326e6f2SEric Anholt 			       struct vc4_exec_info, head);
6789326e6f2SEric Anholt }
6799326e6f2SEric Anholt 
680c8b75bcaSEric Anholt /**
681463873d5SEric Anholt  * struct vc4_texture_sample_info - saves the offsets into the UBO for texture
682463873d5SEric Anholt  * setup parameters.
683463873d5SEric Anholt  *
684463873d5SEric Anholt  * This will be used at draw time to relocate the reference to the texture
685463873d5SEric Anholt  * contents in p0, and validate that the offset combined with
686463873d5SEric Anholt  * width/height/stride/etc. from p1 and p2/p3 doesn't sample outside the BO.
687463873d5SEric Anholt  * Note that the hardware treats unprovided config parameters as 0, so not all
688463873d5SEric Anholt  * of them need to be set up for every texure sample, and we'll store ~0 as
689463873d5SEric Anholt  * the offset to mark the unused ones.
690463873d5SEric Anholt  *
691463873d5SEric Anholt  * See the VC4 3D architecture guide page 41 ("Texture and Memory Lookup Unit
692463873d5SEric Anholt  * Setup") for definitions of the texture parameters.
693463873d5SEric Anholt  */
694463873d5SEric Anholt struct vc4_texture_sample_info {
695463873d5SEric Anholt 	bool is_direct;
696463873d5SEric Anholt 	uint32_t p_offset[4];
697463873d5SEric Anholt };
698463873d5SEric Anholt 
699463873d5SEric Anholt /**
700463873d5SEric Anholt  * struct vc4_validated_shader_info - information about validated shaders that
701463873d5SEric Anholt  * needs to be used from command list validation.
702463873d5SEric Anholt  *
703463873d5SEric Anholt  * For a given shader, each time a shader state record references it, we need
704463873d5SEric Anholt  * to verify that the shader doesn't read more uniforms than the shader state
705463873d5SEric Anholt  * record's uniform BO pointer can provide, and we need to apply relocations
706463873d5SEric Anholt  * and validate the shader state record's uniforms that define the texture
707463873d5SEric Anholt  * samples.
708463873d5SEric Anholt  */
709463873d5SEric Anholt struct vc4_validated_shader_info {
710463873d5SEric Anholt 	uint32_t uniforms_size;
711463873d5SEric Anholt 	uint32_t uniforms_src_size;
712463873d5SEric Anholt 	uint32_t num_texture_samples;
713463873d5SEric Anholt 	struct vc4_texture_sample_info *texture_samples;
7146d45c81dSEric Anholt 
7156d45c81dSEric Anholt 	uint32_t num_uniform_addr_offsets;
7166d45c81dSEric Anholt 	uint32_t *uniform_addr_offsets;
717c778cc5dSJonas Pfeil 
718c778cc5dSJonas Pfeil 	bool is_threaded;
719463873d5SEric Anholt };
720463873d5SEric Anholt 
721463873d5SEric Anholt /**
7227f2a09ecSJames Hughes  * __wait_for - magic wait macro
723c8b75bcaSEric Anholt  *
7247f2a09ecSJames Hughes  * Macro to help avoid open coding check/wait/timeout patterns. Note that it's
7257f2a09ecSJames Hughes  * important that we check the condition again after having timed out, since the
7267f2a09ecSJames Hughes  * timeout could be due to preemption or similar and we've never had a chance to
7277f2a09ecSJames Hughes  * check the condition before the timeout.
728c8b75bcaSEric Anholt  */
7297f2a09ecSJames Hughes #define __wait_for(OP, COND, US, Wmin, Wmax) ({ \
7307f2a09ecSJames Hughes 	const ktime_t end__ = ktime_add_ns(ktime_get_raw(), 1000ll * (US)); \
7317f2a09ecSJames Hughes 	long wait__ = (Wmin); /* recommended min for usleep is 10 us */	\
7327f2a09ecSJames Hughes 	int ret__;							\
7337f2a09ecSJames Hughes 	might_sleep();							\
7347f2a09ecSJames Hughes 	for (;;) {							\
7357f2a09ecSJames Hughes 		const bool expired__ = ktime_after(ktime_get_raw(), end__); \
7367f2a09ecSJames Hughes 		OP;							\
7377f2a09ecSJames Hughes 		/* Guarantee COND check prior to timeout */		\
7387f2a09ecSJames Hughes 		barrier();						\
7397f2a09ecSJames Hughes 		if (COND) {						\
7407f2a09ecSJames Hughes 			ret__ = 0;					\
7417f2a09ecSJames Hughes 			break;						\
7427f2a09ecSJames Hughes 		}							\
7437f2a09ecSJames Hughes 		if (expired__) {					\
744c8b75bcaSEric Anholt 			ret__ = -ETIMEDOUT;				\
745c8b75bcaSEric Anholt 			break;						\
746c8b75bcaSEric Anholt 		}							\
7477f2a09ecSJames Hughes 		usleep_range(wait__, wait__ * 2);			\
7487f2a09ecSJames Hughes 		if (wait__ < (Wmax))					\
7497f2a09ecSJames Hughes 			wait__ <<= 1;					\
750c8b75bcaSEric Anholt 	}								\
751c8b75bcaSEric Anholt 	ret__;								\
752c8b75bcaSEric Anholt })
753c8b75bcaSEric Anholt 
7547f2a09ecSJames Hughes #define _wait_for(COND, US, Wmin, Wmax)	__wait_for(, (COND), (US), (Wmin), \
7557f2a09ecSJames Hughes 						   (Wmax))
7567f2a09ecSJames Hughes #define wait_for(COND, MS)		_wait_for((COND), (MS) * 1000, 10, 1000)
757c8b75bcaSEric Anholt 
758c8b75bcaSEric Anholt /* vc4_bo.c */
759c826a6e1SEric Anholt struct drm_gem_object *vc4_create_object(struct drm_device *dev, size_t size);
760c8b75bcaSEric Anholt void vc4_free_object(struct drm_gem_object *gem_obj);
761c826a6e1SEric Anholt struct vc4_bo *vc4_bo_create(struct drm_device *dev, size_t size,
762f3099462SEric Anholt 			     bool from_cache, enum vc4_kernel_bo_type type);
763c8b75bcaSEric Anholt int vc4_dumb_create(struct drm_file *file_priv,
764c8b75bcaSEric Anholt 		    struct drm_device *dev,
765c8b75bcaSEric Anholt 		    struct drm_mode_create_dumb *args);
766e4fa8457SDaniel Vetter struct dma_buf *vc4_prime_export(struct drm_gem_object *obj, int flags);
767d5bc60f6SEric Anholt int vc4_create_bo_ioctl(struct drm_device *dev, void *data,
768d5bc60f6SEric Anholt 			struct drm_file *file_priv);
769463873d5SEric Anholt int vc4_create_shader_bo_ioctl(struct drm_device *dev, void *data,
770463873d5SEric Anholt 			       struct drm_file *file_priv);
771d5bc60f6SEric Anholt int vc4_mmap_bo_ioctl(struct drm_device *dev, void *data,
772d5bc60f6SEric Anholt 		      struct drm_file *file_priv);
77383753117SEric Anholt int vc4_set_tiling_ioctl(struct drm_device *dev, void *data,
77483753117SEric Anholt 			 struct drm_file *file_priv);
77583753117SEric Anholt int vc4_get_tiling_ioctl(struct drm_device *dev, void *data,
77683753117SEric Anholt 			 struct drm_file *file_priv);
77721461365SEric Anholt int vc4_get_hang_state_ioctl(struct drm_device *dev, void *data,
77821461365SEric Anholt 			     struct drm_file *file_priv);
779f3099462SEric Anholt int vc4_label_bo_ioctl(struct drm_device *dev, void *data,
780f3099462SEric Anholt 		       struct drm_file *file_priv);
781abd7dbe9SSouptick Joarder vm_fault_t vc4_fault(struct vm_fault *vmf);
782463873d5SEric Anholt int vc4_mmap(struct file *filp, struct vm_area_struct *vma);
783463873d5SEric Anholt int vc4_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma);
784cdec4d36SEric Anholt struct drm_gem_object *vc4_prime_import_sg_table(struct drm_device *dev,
785cdec4d36SEric Anholt 						 struct dma_buf_attachment *attach,
786cdec4d36SEric Anholt 						 struct sg_table *sgt);
787463873d5SEric Anholt void *vc4_prime_vmap(struct drm_gem_object *obj);
788f3099462SEric Anholt int vc4_bo_cache_init(struct drm_device *dev);
789c826a6e1SEric Anholt void vc4_bo_cache_destroy(struct drm_device *dev);
790b9f19259SBoris Brezillon int vc4_bo_inc_usecnt(struct vc4_bo *bo);
791b9f19259SBoris Brezillon void vc4_bo_dec_usecnt(struct vc4_bo *bo);
792b9f19259SBoris Brezillon void vc4_bo_add_to_purgeable_pool(struct vc4_bo *bo);
793b9f19259SBoris Brezillon void vc4_bo_remove_from_purgeable_pool(struct vc4_bo *bo);
794c8b75bcaSEric Anholt 
795c8b75bcaSEric Anholt /* vc4_crtc.c */
796c8b75bcaSEric Anholt extern struct platform_driver vc4_crtc_driver;
797bdd96472SMaxime Ripard void vc4_crtc_destroy(struct drm_crtc *crtc);
798bdd96472SMaxime Ripard int vc4_page_flip(struct drm_crtc *crtc,
799bdd96472SMaxime Ripard 		  struct drm_framebuffer *fb,
800bdd96472SMaxime Ripard 		  struct drm_pending_vblank_event *event,
801bdd96472SMaxime Ripard 		  uint32_t flags,
802bdd96472SMaxime Ripard 		  struct drm_modeset_acquire_ctx *ctx);
803bdd96472SMaxime Ripard struct drm_crtc_state *vc4_crtc_duplicate_state(struct drm_crtc *crtc);
804bdd96472SMaxime Ripard void vc4_crtc_destroy_state(struct drm_crtc *crtc,
805bdd96472SMaxime Ripard 			    struct drm_crtc_state *state);
806bdd96472SMaxime Ripard void vc4_crtc_reset(struct drm_crtc *crtc);
807008095e0SBoris Brezillon void vc4_crtc_handle_vblank(struct vc4_crtc *crtc);
808008095e0SBoris Brezillon void vc4_crtc_txp_armed(struct drm_crtc_state *state);
809666e7358SBoris Brezillon void vc4_crtc_get_margins(struct drm_crtc_state *state,
810666e7358SBoris Brezillon 			  unsigned int *right, unsigned int *left,
811666e7358SBoris Brezillon 			  unsigned int *top, unsigned int *bottom);
812c8b75bcaSEric Anholt 
813c8b75bcaSEric Anholt /* vc4_debugfs.c */
8147ce84471SWambui Karuga void vc4_debugfs_init(struct drm_minor *minor);
815c9be804cSEric Anholt #ifdef CONFIG_DEBUG_FS
816c9be804cSEric Anholt void vc4_debugfs_add_file(struct drm_device *drm,
817c9be804cSEric Anholt 			  const char *filename,
818c9be804cSEric Anholt 			  int (*show)(struct seq_file*, void*),
819c9be804cSEric Anholt 			  void *data);
820c9be804cSEric Anholt void vc4_debugfs_add_regset32(struct drm_device *drm,
821c9be804cSEric Anholt 			      const char *filename,
822c9be804cSEric Anholt 			      struct debugfs_regset32 *regset);
823c9be804cSEric Anholt #else
824c9be804cSEric Anholt static inline void vc4_debugfs_add_file(struct drm_device *drm,
825c9be804cSEric Anholt 					const char *filename,
826c9be804cSEric Anholt 					int (*show)(struct seq_file*, void*),
827c9be804cSEric Anholt 					void *data)
828c9be804cSEric Anholt {
829c9be804cSEric Anholt }
830c9be804cSEric Anholt 
831c9be804cSEric Anholt static inline void vc4_debugfs_add_regset32(struct drm_device *drm,
832c9be804cSEric Anholt 					    const char *filename,
833c9be804cSEric Anholt 					    struct debugfs_regset32 *regset)
834c9be804cSEric Anholt {
835c9be804cSEric Anholt }
836c9be804cSEric Anholt #endif
837c8b75bcaSEric Anholt 
838c8b75bcaSEric Anholt /* vc4_drv.c */
839c8b75bcaSEric Anholt void __iomem *vc4_ioremap_regs(struct platform_device *dev, int index);
840c8b75bcaSEric Anholt 
84108302c35SEric Anholt /* vc4_dpi.c */
84208302c35SEric Anholt extern struct platform_driver vc4_dpi_driver;
84308302c35SEric Anholt 
8444078f575SEric Anholt /* vc4_dsi.c */
8454078f575SEric Anholt extern struct platform_driver vc4_dsi_driver;
8464078f575SEric Anholt 
847cdec4d36SEric Anholt /* vc4_fence.c */
848cdec4d36SEric Anholt extern const struct dma_fence_ops vc4_fence_ops;
849cdec4d36SEric Anholt 
850d5b1a78aSEric Anholt /* vc4_gem.c */
851d5b1a78aSEric Anholt void vc4_gem_init(struct drm_device *dev);
852d5b1a78aSEric Anholt void vc4_gem_destroy(struct drm_device *dev);
853d5b1a78aSEric Anholt int vc4_submit_cl_ioctl(struct drm_device *dev, void *data,
854d5b1a78aSEric Anholt 			struct drm_file *file_priv);
855d5b1a78aSEric Anholt int vc4_wait_seqno_ioctl(struct drm_device *dev, void *data,
856d5b1a78aSEric Anholt 			 struct drm_file *file_priv);
857d5b1a78aSEric Anholt int vc4_wait_bo_ioctl(struct drm_device *dev, void *data,
858d5b1a78aSEric Anholt 		      struct drm_file *file_priv);
859ca26d28bSVarad Gautam void vc4_submit_next_bin_job(struct drm_device *dev);
860ca26d28bSVarad Gautam void vc4_submit_next_render_job(struct drm_device *dev);
861ca26d28bSVarad Gautam void vc4_move_job_to_render(struct drm_device *dev, struct vc4_exec_info *exec);
862d5b1a78aSEric Anholt int vc4_wait_for_seqno(struct drm_device *dev, uint64_t seqno,
863d5b1a78aSEric Anholt 		       uint64_t timeout_ns, bool interruptible);
864d5b1a78aSEric Anholt void vc4_job_handle_completed(struct vc4_dev *vc4);
865b501baccSEric Anholt int vc4_queue_seqno_cb(struct drm_device *dev,
866b501baccSEric Anholt 		       struct vc4_seqno_cb *cb, uint64_t seqno,
867b501baccSEric Anholt 		       void (*func)(struct vc4_seqno_cb *cb));
868b9f19259SBoris Brezillon int vc4_gem_madvise_ioctl(struct drm_device *dev, void *data,
869b9f19259SBoris Brezillon 			  struct drm_file *file_priv);
870d5b1a78aSEric Anholt 
871c8b75bcaSEric Anholt /* vc4_hdmi.c */
872c8b75bcaSEric Anholt extern struct platform_driver vc4_hdmi_driver;
873c8b75bcaSEric Anholt 
8749a8d5e4aSBoris Brezillon /* vc4_vec.c */
875e4b81f8cSBoris Brezillon extern struct platform_driver vc4_vec_driver;
876e4b81f8cSBoris Brezillon 
877008095e0SBoris Brezillon /* vc4_txp.c */
878008095e0SBoris Brezillon extern struct platform_driver vc4_txp_driver;
879008095e0SBoris Brezillon 
880d5b1a78aSEric Anholt /* vc4_irq.c */
881d5b1a78aSEric Anholt irqreturn_t vc4_irq(int irq, void *arg);
882d5b1a78aSEric Anholt void vc4_irq_preinstall(struct drm_device *dev);
883d5b1a78aSEric Anholt int vc4_irq_postinstall(struct drm_device *dev);
884d5b1a78aSEric Anholt void vc4_irq_uninstall(struct drm_device *dev);
885d5b1a78aSEric Anholt void vc4_irq_reset(struct drm_device *dev);
886d5b1a78aSEric Anholt 
887c8b75bcaSEric Anholt /* vc4_hvs.c */
888c8b75bcaSEric Anholt extern struct platform_driver vc4_hvs_driver;
8898175287bSMaxime Ripard int vc4_hvs_atomic_check(struct drm_crtc *crtc, struct drm_crtc_state *state);
8908175287bSMaxime Ripard void vc4_hvs_atomic_enable(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
8918175287bSMaxime Ripard void vc4_hvs_atomic_disable(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
8928175287bSMaxime Ripard void vc4_hvs_atomic_flush(struct drm_crtc *crtc, struct drm_crtc_state *state);
8938175287bSMaxime Ripard void vc4_hvs_mode_set_nofb(struct drm_crtc *crtc);
894c8b75bcaSEric Anholt void vc4_hvs_dump_state(struct drm_device *dev);
895531a1b62SBoris Brezillon void vc4_hvs_unmask_underrun(struct drm_device *dev, int channel);
896531a1b62SBoris Brezillon void vc4_hvs_mask_underrun(struct drm_device *dev, int channel);
897c8b75bcaSEric Anholt 
898c8b75bcaSEric Anholt /* vc4_kms.c */
899c8b75bcaSEric Anholt int vc4_kms_load(struct drm_device *dev);
900c8b75bcaSEric Anholt 
901c8b75bcaSEric Anholt /* vc4_plane.c */
902c8b75bcaSEric Anholt struct drm_plane *vc4_plane_init(struct drm_device *dev,
903c8b75bcaSEric Anholt 				 enum drm_plane_type type);
9040c2a50f1SMaxime Ripard int vc4_plane_create_additional_planes(struct drm_device *dev);
905c8b75bcaSEric Anholt u32 vc4_plane_write_dlist(struct drm_plane *plane, u32 __iomem *dlist);
9062f196b7cSDaniel Vetter u32 vc4_plane_dlist_size(const struct drm_plane_state *state);
907b501baccSEric Anholt void vc4_plane_async_set_fb(struct drm_plane *plane,
908b501baccSEric Anholt 			    struct drm_framebuffer *fb);
909463873d5SEric Anholt 
910d3f5168aSEric Anholt /* vc4_v3d.c */
911d3f5168aSEric Anholt extern struct platform_driver vc4_v3d_driver;
912ffc26740SEric Anholt extern const struct of_device_id vc4_v3d_dt_match[];
913553c942fSEric Anholt int vc4_v3d_get_bin_slot(struct vc4_dev *vc4);
91435c8b4b2SPaul Kocialkowski int vc4_v3d_bin_bo_get(struct vc4_dev *vc4, bool *used);
91535c8b4b2SPaul Kocialkowski void vc4_v3d_bin_bo_put(struct vc4_dev *vc4);
916cb74f6eeSEric Anholt int vc4_v3d_pm_get(struct vc4_dev *vc4);
917cb74f6eeSEric Anholt void vc4_v3d_pm_put(struct vc4_dev *vc4);
918d5b1a78aSEric Anholt 
919d5b1a78aSEric Anholt /* vc4_validate.c */
920d5b1a78aSEric Anholt int
921d5b1a78aSEric Anholt vc4_validate_bin_cl(struct drm_device *dev,
922d5b1a78aSEric Anholt 		    void *validated,
923d5b1a78aSEric Anholt 		    void *unvalidated,
924d5b1a78aSEric Anholt 		    struct vc4_exec_info *exec);
925d5b1a78aSEric Anholt 
926d5b1a78aSEric Anholt int
927d5b1a78aSEric Anholt vc4_validate_shader_recs(struct drm_device *dev, struct vc4_exec_info *exec);
928d5b1a78aSEric Anholt 
929d5b1a78aSEric Anholt struct drm_gem_cma_object *vc4_use_bo(struct vc4_exec_info *exec,
930d5b1a78aSEric Anholt 				      uint32_t hindex);
931d5b1a78aSEric Anholt 
932d5b1a78aSEric Anholt int vc4_get_rcl(struct drm_device *dev, struct vc4_exec_info *exec);
933d5b1a78aSEric Anholt 
934d5b1a78aSEric Anholt bool vc4_check_tex_size(struct vc4_exec_info *exec,
935d5b1a78aSEric Anholt 			struct drm_gem_cma_object *fbo,
936d5b1a78aSEric Anholt 			uint32_t offset, uint8_t tiling_format,
937d5b1a78aSEric Anholt 			uint32_t width, uint32_t height, uint8_t cpp);
938d3f5168aSEric Anholt 
939463873d5SEric Anholt /* vc4_validate_shader.c */
940463873d5SEric Anholt struct vc4_validated_shader_info *
941463873d5SEric Anholt vc4_validate_shader(struct drm_gem_cma_object *shader_obj);
94265101d8cSBoris Brezillon 
94365101d8cSBoris Brezillon /* vc4_perfmon.c */
94465101d8cSBoris Brezillon void vc4_perfmon_get(struct vc4_perfmon *perfmon);
94565101d8cSBoris Brezillon void vc4_perfmon_put(struct vc4_perfmon *perfmon);
94665101d8cSBoris Brezillon void vc4_perfmon_start(struct vc4_dev *vc4, struct vc4_perfmon *perfmon);
94765101d8cSBoris Brezillon void vc4_perfmon_stop(struct vc4_dev *vc4, struct vc4_perfmon *perfmon,
94865101d8cSBoris Brezillon 		      bool capture);
94965101d8cSBoris Brezillon struct vc4_perfmon *vc4_perfmon_find(struct vc4_file *vc4file, int id);
95065101d8cSBoris Brezillon void vc4_perfmon_open_file(struct vc4_file *vc4file);
95165101d8cSBoris Brezillon void vc4_perfmon_close_file(struct vc4_file *vc4file);
95265101d8cSBoris Brezillon int vc4_perfmon_create_ioctl(struct drm_device *dev, void *data,
95365101d8cSBoris Brezillon 			     struct drm_file *file_priv);
95465101d8cSBoris Brezillon int vc4_perfmon_destroy_ioctl(struct drm_device *dev, void *data,
95565101d8cSBoris Brezillon 			      struct drm_file *file_priv);
95665101d8cSBoris Brezillon int vc4_perfmon_get_values_ioctl(struct drm_device *dev, void *data,
95765101d8cSBoris Brezillon 				 struct drm_file *file_priv);
9586a88752cSMaxime Ripard 
9596a88752cSMaxime Ripard #endif /* _VC4_DRV_H_ */
960